xstate 4.17.0 → 4.19.1
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 +71 -0
- package/README.md +9 -9
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/State.d.ts +9 -1
- package/es/State.js +17 -2
- package/es/StateNode.d.ts +1 -0
- package/es/StateNode.js +11 -2
- package/es/devTools.js +2 -3
- package/es/model.d.ts +2 -2
- package/es/types.d.ts +8 -2
- package/lib/State.d.ts +9 -1
- package/lib/State.js +11 -2
- package/lib/StateNode.d.ts +1 -0
- package/lib/StateNode.js +9 -1
- package/lib/devTools.js +1 -2
- package/lib/model.d.ts +2 -2
- package/lib/types.d.ts +8 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,76 @@
|
|
|
1
1
|
# xstate
|
|
2
2
|
|
|
3
|
+
## 4.19.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`64ab1150`](https://github.com/davidkpiano/xstate/commit/64ab1150e0a383202f4af1d586b28e081009c929) [#2173](https://github.com/davidkpiano/xstate/pull/2173) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with tags not being set correctly after sending an event to a machine that didn't result in selecting any transitions.
|
|
8
|
+
|
|
9
|
+
## 4.19.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [`4f2f626d`](https://github.com/davidkpiano/xstate/commit/4f2f626dc84f45bb18ded6dd9aad3b6f6a2190b1) [#2143](https://github.com/davidkpiano/xstate/pull/2143) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Tags can now be added to state node configs under the `.tags` property:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
const machine = createMachine({
|
|
17
|
+
initial: 'green',
|
|
18
|
+
states: {
|
|
19
|
+
green: {
|
|
20
|
+
tags: 'go' // single tag
|
|
21
|
+
},
|
|
22
|
+
yellow: {
|
|
23
|
+
tags: 'go'
|
|
24
|
+
},
|
|
25
|
+
red: {
|
|
26
|
+
tags: ['stop', 'other'] // multiple tags
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
You can query whether a state has a tag via `state.hasTag(tag)`:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const canGo = state.hasTag('go');
|
|
36
|
+
// => `true` if in 'green' or 'red' state
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- [`a61d01ce`](https://github.com/davidkpiano/xstate/commit/a61d01cefab5734adf9bfb167291f5b0ba712684) [#2125](https://github.com/davidkpiano/xstate/pull/2125) Thanks [@VanTanev](https://github.com/VanTanev)! - In callback invokes, the types of `callback` and `onReceive` are properly scoped to the machine TEvent.
|
|
42
|
+
|
|
43
|
+
## 4.18.0
|
|
44
|
+
|
|
45
|
+
### Minor Changes
|
|
46
|
+
|
|
47
|
+
- [`d0939ec6`](https://github.com/davidkpiano/xstate/commit/d0939ec60161c34b053cecdaeb277606b5982375) [#2046](https://github.com/davidkpiano/xstate/pull/2046) Thanks [@SimeonC](https://github.com/SimeonC)! - Allow machines to communicate with the inspector even in production builds.
|
|
48
|
+
|
|
49
|
+
* [`e37fffef`](https://github.com/davidkpiano/xstate/commit/e37fffefb742f45765945c02727edfbd5e2f9d47) [#2079](https://github.com/davidkpiano/xstate/pull/2079) Thanks [@davidkpiano](https://github.com/davidkpiano)! - There is now support for "combinatorial machines" (state machines that only have one state):
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
const testMachine = createMachine({
|
|
53
|
+
context: { value: 42 },
|
|
54
|
+
on: {
|
|
55
|
+
INC: {
|
|
56
|
+
actions: assign({ value: ctx => ctx.value + 1 })
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
These machines omit the `initial` and `state` properties, as the entire machine is treated as a single state.
|
|
63
|
+
|
|
64
|
+
### Patch Changes
|
|
65
|
+
|
|
66
|
+
- [`6a9247d4`](https://github.com/davidkpiano/xstate/commit/6a9247d4d3a39e6c8c4724d3368a13fcdef10907) [#2102](https://github.com/davidkpiano/xstate/pull/2102) Thanks [@VanTanev](https://github.com/VanTanev)! - Provide a convenience type for getting the `Interpreter` type based on the `StateMachine` type by transferring all generic parameters onto it. It can be used like this: `InterpreterFrom<typeof machine>`
|
|
67
|
+
|
|
68
|
+
## 4.17.1
|
|
69
|
+
|
|
70
|
+
### Patch Changes
|
|
71
|
+
|
|
72
|
+
- [`33302814`](https://github.com/davidkpiano/xstate/commit/33302814c38587d0044afd2ae61a4ff4779416c6) [#2041](https://github.com/davidkpiano/xstate/pull/2041) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with creatorless models not being correctly matched by `createMachine`'s overload responsible for using model-induced types.
|
|
73
|
+
|
|
3
74
|
## 4.17.0
|
|
4
75
|
|
|
5
76
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -33,11 +33,11 @@ npm install xstate
|
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
```js
|
|
36
|
-
import {
|
|
36
|
+
import { createMachine, interpret } from 'xstate';
|
|
37
37
|
|
|
38
38
|
// Stateless machine definition
|
|
39
39
|
// machine.transition(...) is a pure function used by the interpreter.
|
|
40
|
-
const toggleMachine =
|
|
40
|
+
const toggleMachine = createMachine({
|
|
41
41
|
id: 'toggle',
|
|
42
42
|
initial: 'inactive',
|
|
43
43
|
states: {
|
|
@@ -48,7 +48,7 @@ const toggleMachine = Machine({
|
|
|
48
48
|
|
|
49
49
|
// Machine instance with internal state
|
|
50
50
|
const toggleService = interpret(toggleMachine)
|
|
51
|
-
.onTransition(state => console.log(state.value))
|
|
51
|
+
.onTransition((state) => console.log(state.value))
|
|
52
52
|
.start();
|
|
53
53
|
// => 'inactive'
|
|
54
54
|
|
|
@@ -90,9 +90,9 @@ Read [📽 the slides](http://slides.com/davidkhourshid/finite-state-machines) (
|
|
|
90
90
|
<img src="https://imgur.com/rqqmkJh.png" alt="Light Machine" width="300" />
|
|
91
91
|
|
|
92
92
|
```js
|
|
93
|
-
import {
|
|
93
|
+
import { createMachine } from 'xstate';
|
|
94
94
|
|
|
95
|
-
const lightMachine =
|
|
95
|
+
const lightMachine = createMachine({
|
|
96
96
|
id: 'light',
|
|
97
97
|
initial: 'green',
|
|
98
98
|
states: {
|
|
@@ -126,7 +126,7 @@ const nextState = lightMachine.transition(currentState, 'TIMER').value;
|
|
|
126
126
|
<img src="https://imgur.com/GDZAeB9.png" alt="Hierarchical Light Machine" width="300" />
|
|
127
127
|
|
|
128
128
|
```js
|
|
129
|
-
import {
|
|
129
|
+
import { createMachine } from 'xstate';
|
|
130
130
|
|
|
131
131
|
const pedestrianStates = {
|
|
132
132
|
initial: 'walk',
|
|
@@ -145,7 +145,7 @@ const pedestrianStates = {
|
|
|
145
145
|
}
|
|
146
146
|
};
|
|
147
147
|
|
|
148
|
-
const lightMachine =
|
|
148
|
+
const lightMachine = createMachine({
|
|
149
149
|
id: 'light',
|
|
150
150
|
initial: 'green',
|
|
151
151
|
states: {
|
|
@@ -203,7 +203,7 @@ lightMachine.transition({ red: 'stop' }, 'TIMER').value;
|
|
|
203
203
|
<img src="https://imgur.com/GKd4HwR.png" width="300" alt="Parallel state machine" />
|
|
204
204
|
|
|
205
205
|
```js
|
|
206
|
-
const wordMachine =
|
|
206
|
+
const wordMachine = createMachine({
|
|
207
207
|
id: 'word',
|
|
208
208
|
type: 'parallel',
|
|
209
209
|
states: {
|
|
@@ -289,7 +289,7 @@ const nextState = wordMachine.transition(
|
|
|
289
289
|
<img src="https://imgur.com/I4QsQsz.png" width="300" alt="Machine with history state" />
|
|
290
290
|
|
|
291
291
|
```js
|
|
292
|
-
const paymentMachine =
|
|
292
|
+
const paymentMachine = createMachine({
|
|
293
293
|
id: 'payment',
|
|
294
294
|
initial: 'method',
|
|
295
295
|
states: {
|
|
@@ -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,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(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(o(arguments[e]));return t}!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var a={};function u(t){return Object.keys(t)}function c(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:d(t)?h(t):"string"!=typeof t?t:h(function(t,e){try{return d(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}(t,e));var n}function h(t){if(1===t.length)return t[0];for(var e={},n=e,i=0;i<t.length-1;i++)i===t.length-2?n[t[i]]=t[i+1]:(n[t[i]]={},n=n[t[i]]);return e}function f(t,e,n){var i,o;if(p(t))return t(e,n.data);var s={};try{for(var a=r(Object.keys(t)),u=a.next();!u.done;u=a.next()){var c=u.value,h=t[c];p(h)?s[c]=h(e,n.data):s[c]=h}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=a.return)&&o.call(a)}finally{if(i)throw i.error}}return s}function l(t){return t instanceof Promise||!(null===t||!p(t)&&"object"!=typeof t||!p(t.then))}function d(t){return Array.isArray(t)}function p(t){return"function"==typeof t}function v(t){return"string"==typeof t}function y(t){try{return"subscribe"in t&&p(t.subscribe)}catch(t){return!1}}var m="function"==typeof Symbol&&Symbol.observable||"@@observable";function b(t){try{return"__xstatenode"in t}catch(t){return!1}}var w,x=(w=0,function(){return(++w).toString(16)});function g(t,e){return v(t)||"number"==typeof t?i({type:t},e):t}function S(t,e){if(!v(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=g(t);return i({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function E(t){return u(t.states).map((function(e){return t.states[e]}))}function _(t){return e=s(new Set(t.map((function(t){return t.ownEvents})))),(n=[]).concat.apply(n,s(e));var e,n}function O(t,e){return"compound"===e.type?E(e).some((function(e){return"final"===e.type&&(n=t,i=e,Array.isArray(n)?n.some((function(t){return t===i})):n instanceof Set&&n.has(i));var n,i})):"parallel"===e.type&&E(e).every((function(e){return O(t,e)}))}var T=e.Start,I=e.Stop,L=(e.Raise,e.Send),k=e.Cancel,P=(e.NullEvent,e.Assign,e.After,e.DoneState,e.Log),C=e.Init,j=(e.Invoke,e.ErrorExecution,e.ErrorPlatform),N=e.ErrorCustom,D=e.Update,M=(e.Choose,e.Pure,S({type:C}));function z(t,n){var i=e.DoneInvoke+"."+t,r={type:i,data:n,toString:function(){return i}};return r}function A(t,n){var i=e.ErrorPlatform+"."+t,r={type:i,data:n,toString:function(){return i}};return r}var R=function(){function t(t){var e=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=t.meta||{},this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,Object.defineProperty(this,"nextEvents",{get:function(){return _(e.configuration)}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:M,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var i=M;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(i.map((function(i){return n.toStrings(t[i],e).map((function(t){return i+e+t}))}))))},t.prototype.toJSON=function(){this.configuration,this.transitions;return function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}(this,["configuration","transitions"])},t.prototype.matches=function(t){return function t(e,n,i){void 0===i&&(i=".");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}(),V={deferEvents:!1},J=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=i(i({},V),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),q=[],U=function(t,e){q.push(t);var n=e(t);return q.pop(),n};var $=new Map,F=0,X=function(){return"x:"+F++},B=function(t,e){return $.set(t,e),t},G=function(t){return $.get(t)},H=function(t){$.delete(t)};function K(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}var Q,W={sync:!1,autoForward:!1};(Q=t.InterpreterStatus||(t.InterpreterStatus={}))[Q.NotStarted=0]="NotStarted",Q[Q.Running=1]="Running",Q[Q.Stopped=2]="Stopped";var Y=function(){function o(e,r){var s=this;void 0===r&&(r=o.defaultOptions),this.machine=e,this.scheduler=new J,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if(d(e))return s.batch(e),s.state;var i=S(g(e,n));if(s.status===t.InterpreterStatus.Stopped)return s.state;if(s.status!==t.InterpreterStatus.Running&&!s.options.deferEvents)throw new Error('Event "'+i.name+'" was sent to uninitialized service "'+s.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: '+JSON.stringify(i.data));return s.scheduler.schedule((function(){s.forward(i);var t=s.nextState(i);s.update(t,i)})),s._state},this.sendTo=function(t,e){var r,o=s.parent&&(e===n.Parent||s.parent.id===e),a=o?s.parent:v(e)?s.children.get(e)||G(e):(r=e)&&"function"==typeof r.send?e:void 0;if(a)"machine"in a?a.send(i(i({},t),{name:t.name===N?""+A(s.id):t.name,origin:s.sessionId})):a.send(t.data);else if(!o)throw new Error("Unable to send event to child '"+e+"' from service '"+s.id+"'.")};var a=i(i({},o.defaultOptions),r),u=a.clock,c=a.logger,h=a.parent,f=a.id,l=void 0!==f?f:e.id;this.id=l,this.logger=c,this.clock=u,this.parent=h,this.options=a,this.scheduler=new J({deferEvents:this.options.deferEvents}),this.sessionId=X()}return Object.defineProperty(o.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:U(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),o.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}}},o.prototype.update=function(t,e){var n,i,o,s,a,u,c,h,l=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){l.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var d=r(this.eventListeners),p=d.next();!p.done;p=d.next()){(0,p.value)(t.event)}}catch(t){n={error:t}}finally{try{p&&!p.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}try{for(var v=r(this.listeners),y=v.next();!y.done;y=v.next()){(0,y.value)(t,t.event)}}catch(t){o={error:t}}finally{try{y&&!y.done&&(s=v.return)&&s.call(v)}finally{if(o)throw o.error}}try{for(var m=r(this.contextListeners),b=m.next();!b.done;b=m.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=m.return)&&u.call(m)}finally{if(a)throw a.error}}var w=O(t.configuration||[],this.machine);if(this.state.configuration&&w){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===l.machine})),g=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)(z(this.id,g))}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}this.stop()}},o.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},o.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)}}},o.prototype.onEvent=function(t){return this.eventListeners.add(t),this},o.prototype.onSend=function(t){return this.sendListeners.add(t),this},o.prototype.onChange=function(t){return this.contextListeners.add(t),this},o.prototype.onStop=function(t){return this.stopListeners.add(t),this},o.prototype.onDone=function(t){return this.doneListeners.add(t),this},o.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},o.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;B(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var i=void 0===e?this.initialState:U(this,(function(){return!v(t=e)&&"value"in t&&"history"in t?n.machine.resolveState(e):n.machine.resolveState(R.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(i,M)})),this},o.prototype.stop=function(){var e,n,i,o,s,a,c,h,f,l,d=this;try{for(var v=r(this.listeners),y=v.next();!y.done;y=v.next()){var m=y.value;this.listeners.delete(m)}}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=r(this.stopListeners),w=b.next();!w.done;w=b.next()){(m=w.value)(),this.stopListeners.delete(m)}}catch(t){i={error:t}}finally{try{w&&!w.done&&(o=b.return)&&o.call(b)}finally{if(i)throw i.error}}try{for(var x=r(this.contextListeners),g=x.next();!g.done;g=x.next()){m=g.value;this.contextListeners.delete(m)}}catch(t){s={error:t}}finally{try{g&&!g.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()){m=E.value;this.doneListeners.delete(m)}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}if(!this.initialized)return this;this.state.configuration.forEach((function(t){var e,n;try{for(var i=r(t.definition.exit),o=i.next();!o.done;o=i.next()){var s=o.value;d.exec(s,d.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){p(t.stop)&&t.stop()}));try{for(var _=r(u(this.delayedEventsMap)),O=_.next();!O.done;O=_.next()){var T=O.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(t){f={error:t}}finally{try{O&&!O.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,H(this.sessionId),this},o.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,o,a=n.state,u=!1,c=[],h=function(t){var e=S(t);n.forward(e),a=U(n,(function(){return n.machine.transition(a,e)})),c.push.apply(c,s(a.actions.map((function(t){return n=a,r=(e=t).exec,i(i({},e),{exec:void 0!==r?function(){return r(n.context,n.event,{action:e,state:n,_event:n._event})}:void 0});var e,n,r})))),u=u||!!a.changed};try{for(var f=r(e),l=f.next();!l.done;l=f.next()){h(l.value)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(o=f.return)&&o.call(f)}finally{if(t)throw t.error}}a.changed=u,a.actions=c,n.update(a,S(e[e.length-1]))}))},o.prototype.sender=function(t){return this.send.bind(this,t)},o.prototype.nextState=function(t){var e=this,n=S(t);if(0===n.name.indexOf(j)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(j)})))throw n.data.data;return U(this,(function(){return e.machine.transition(e.state,n)}))},o.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}}},o.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)},o.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},o.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 L: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 k:this.cancel(t.sendId);break;case T: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,v=this.machine.options.services?this.machine.options.services[d.type]:void 0,m=h.id,w=h.data,x="autoForward"in h?h.autoForward:!!h.forward;if(!v)return;var g=w?f(w,o,s):void 0,S=p(v)?v(o,s.data,{data:g,src:d}):v;l(S)?this.spawnPromise(Promise.resolve(S),m):p(S)?this.spawnCallback(S,m):y(S)?this.spawnObservable(S,m):b(S)&&this.spawnMachine(g?S.withContext(g):S,{id:m,autoForward:x})}else this.spawnActivity(h);break;case I:this.stopChild(t.activity.id);break;case P:var E=t.label,_=t.value;E?this.logger(E,_):this.logger(_)}},o.prototype.removeChild=function(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]},o.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),p(e.stop)&&e.stop())},o.prototype.spawn=function(t,e,n){if(l(t))return this.spawnPromise(Promise.resolve(t),e);if(p(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(r=t)&&"id"in r)return this.spawnActor(t);if(y(t))return this.spawnObservable(t,e);if(b(t))return this.spawnMachine(t,i(i({},n),{id:e}));throw new Error('Unable to spawn entity "'+e+'" of type "'+typeof t+'".');var r},o.prototype.spawnMachine=function(t,e){var n=this;void 0===e&&(e={});var r=new o(t,i(i({},this.options),{parent:this,id:e.id||t.id})),s=i(i({},W),e);s.sync&&r.onTransition((function(t){n.send(D,{state:t,id:r.id})}));var a=r;return this.children.set(r.id,a),s.autoForward&&this.forwardTo.add(r.id),r.onDone((function(t){n.removeChild(r.id),n.send(S(t,{origin:r.id}))})).start(),a},o.prototype.spawnPromise=function(t,e){var n=this,i=!1;t.then((function(t){i||(n.removeChild(e),n.send(S(z(e,t),{origin:e})))}),(function(t){if(!i){n.removeChild(e);var r=A(e,t);try{n.send(S(r,{origin:e}))}catch(t){n.devTools&&n.devTools.send(r,n.state),n.machine.strict&&n.stop()}}}));var r={id:e,send:function(){},subscribe:function(e,n,i){var r=function(t,e,n){if("object"==typeof t)return t;var i=function(){};return{next:t,error:e||i,complete:n||i}}(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(){i=!0},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},o.prototype.spawnCallback=function(t,e){var n,i=this,r=!1,o=new Set,s=new Set;try{n=t((function(t){s.forEach((function(e){return e(t)})),r||i.send(S(t,{origin:e}))}),(function(t){o.add(t)}))}catch(t){this.send(A(e,t))}if(l(n))return this.spawnPromise(n,e);var a={id:e,send:function(t){return o.forEach((function(e){return e(t)}))},subscribe:function(t){return s.add(t),{unsubscribe:function(){s.delete(t)}}},stop:function(){r=!0,p(n)&&n()},toJSON:function(){return{id:e}}};return this.children.set(e,a),a},o.prototype.spawnObservable=function(t,e){var n=this,i=t.subscribe((function(t){n.send(S(t,{origin:e}))}),(function(t){n.removeChild(e),n.send(S(A(e,t),{origin:e}))}),(function(){n.removeChild(e),n.send(S(z(e),{origin:e}))})),r={id:e,send:function(){},subscribe:function(e,n,i){return t.subscribe(e,n,i)},stop:function(){return i.unsubscribe()},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},o.prototype.spawnActor=function(t){return this.children.set(t.id,t),t},o.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)}},o.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,toJSON:function(){return{id:t}}})},o.prototype.attachDev=function(){var t=K();if(this.options.devTools&&t&&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)}},o.prototype.toJSON=function(){return{id:this.id}},o.prototype[m]=function(){return this},o.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),o.interpret=Z,o}();function Z(t,e){return new Y(t,e)}t.Interpreter=Y,t.interpret=Z,t.spawn=function(t,e){var n=function(t){return v(t)?i(i({},W),{name:t}):i(i(i({},W),{name:x()}),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(){}}},toJSON:function(){return{id:t}}}}(e);return i.deferred=!0,b(t)&&(i.state=U(void 0,(function(){return(n?t.withContext(n):t).initialState}))),i}(t,n.name)}(q[q.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(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(o(arguments[e]));return t}!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var a={};function u(t){return Object.keys(t)}function c(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:d(t)?h(t):"string"!=typeof t?t:h(function(t,e){try{return d(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}(t,e));var n}function h(t){if(1===t.length)return t[0];for(var e={},n=e,i=0;i<t.length-1;i++)i===t.length-2?n[t[i]]=t[i+1]:(n[t[i]]={},n=n[t[i]]);return e}function f(t,e,n){var i,o;if(p(t))return t(e,n.data);var s={};try{for(var a=r(Object.keys(t)),u=a.next();!u.done;u=a.next()){var c=u.value,h=t[c];p(h)?s[c]=h(e,n.data):s[c]=h}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=a.return)&&o.call(a)}finally{if(i)throw i.error}}return s}function l(t){return t instanceof Promise||!(null===t||!p(t)&&"object"!=typeof t||!p(t.then))}function d(t){return Array.isArray(t)}function p(t){return"function"==typeof t}function v(t){return"string"==typeof t}function y(t){try{return"subscribe"in t&&p(t.subscribe)}catch(t){return!1}}var m="function"==typeof Symbol&&Symbol.observable||"@@observable";function w(t){try{return"__xstatenode"in t}catch(t){return!1}}var x,b=(x=0,function(){return(++x).toString(16)});function g(t,e){return v(t)||"number"==typeof t?i({type:t},e):t}function S(t,e){if(!v(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=g(t);return i({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function E(t){return u(t.states).map((function(e){return t.states[e]}))}function _(t){return e=s(new Set(t.map((function(t){return t.ownEvents})))),(n=[]).concat.apply(n,s(e));var e,n}function O(t,e){return"compound"===e.type?E(e).some((function(e){return"final"===e.type&&(n=t,i=e,Array.isArray(n)?n.some((function(t){return t===i})):n instanceof Set&&n.has(i));var n,i})):"parallel"===e.type&&E(e).every((function(e){return O(t,e)}))}var T=e.Start,I=e.Stop,L=(e.Raise,e.Send),k=e.Cancel,P=(e.NullEvent,e.Assign,e.After,e.DoneState,e.Log),C=e.Init,j=(e.Invoke,e.ErrorExecution,e.ErrorPlatform),N=e.ErrorCustom,D=e.Update,M=(e.Choose,e.Pure,S({type:C}));function A(t,n){var i=e.DoneInvoke+"."+t,r={type:i,data:n,toString:function(){return i}};return r}function z(t,n){var i=e.ErrorPlatform+"."+t,r={type:i,data:n,toString:function(){return i}};return r}var R=function(){function t(t){var e,n=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=t.meta||{},this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=t.tags)&&void 0!==e?e:new Set,Object.defineProperty(this,"nextEvents",{get:function(){return _(n.configuration)}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:M,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var i=M;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(i.map((function(i){return n.toStrings(t[i],e).map((function(t){return i+e+t}))}))))},t.prototype.toJSON=function(){this.configuration,this.transitions;var t=this.tags,e=function(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}(this,["configuration","transitions","tags"]);return i(i({},e),{tags:Array.from(t)})},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}(),V={deferEvents:!1},J=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=i(i({},V),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),q=[],U=function(t,e){q.push(t);var n=e(t);return q.pop(),n};var $=new Map,F=0,X=function(){return"x:"+F++},B=function(t,e){return $.set(t,e),t},G=function(t){return $.get(t)},H=function(t){$.delete(t)};function K(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Q(t){if(K()){var e=function(){var t=K();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}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 o(e,r){var s=this;void 0===r&&(r=o.defaultOptions),this.machine=e,this.scheduler=new J,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if(d(e))return s.batch(e),s.state;var i=S(g(e,n));if(s.status===t.InterpreterStatus.Stopped)return s.state;if(s.status!==t.InterpreterStatus.Running&&!s.options.deferEvents)throw new Error('Event "'+i.name+'" was sent to uninitialized service "'+s.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: '+JSON.stringify(i.data));return s.scheduler.schedule((function(){s.forward(i);var t=s.nextState(i);s.update(t,i)})),s._state},this.sendTo=function(t,e){var r,o=s.parent&&(e===n.Parent||s.parent.id===e),a=o?s.parent:v(e)?s.children.get(e)||G(e):(r=e)&&"function"==typeof r.send?e:void 0;if(a)"machine"in a?a.send(i(i({},t),{name:t.name===N?""+z(s.id):t.name,origin:s.sessionId})):a.send(t.data);else if(!o)throw new Error("Unable to send event to child '"+e+"' from service '"+s.id+"'.")};var a=i(i({},o.defaultOptions),r),u=a.clock,c=a.logger,h=a.parent,f=a.id,l=void 0!==f?f:e.id;this.id=l,this.logger=c,this.clock=u,this.parent=h,this.options=a,this.scheduler=new J({deferEvents:this.options.deferEvents}),this.sessionId=X()}return Object.defineProperty(o.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:U(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),o.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}}},o.prototype.update=function(t,e){var n,i,o,s,a,u,c,h,l=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){l.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var d=r(this.eventListeners),p=d.next();!p.done;p=d.next()){(0,p.value)(t.event)}}catch(t){n={error:t}}finally{try{p&&!p.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}try{for(var v=r(this.listeners),y=v.next();!y.done;y=v.next()){(0,y.value)(t,t.event)}}catch(t){o={error:t}}finally{try{y&&!y.done&&(s=v.return)&&s.call(v)}finally{if(o)throw o.error}}try{for(var m=r(this.contextListeners),w=m.next();!w.done;w=m.next()){(0,w.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){a={error:t}}finally{try{w&&!w.done&&(u=m.return)&&u.call(m)}finally{if(a)throw a.error}}var x=O(t.configuration||[],this.machine);if(this.state.configuration&&x){var b=t.configuration.find((function(t){return"final"===t.type&&t.parent===l.machine})),g=b&&b.doneData?f(b.doneData,t.context,e):void 0;try{for(var S=r(this.doneListeners),E=S.next();!E.done;E=S.next()){(0,E.value)(A(this.id,g))}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}this.stop()}},o.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},o.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)}}},o.prototype.onEvent=function(t){return this.eventListeners.add(t),this},o.prototype.onSend=function(t){return this.sendListeners.add(t),this},o.prototype.onChange=function(t){return this.contextListeners.add(t),this},o.prototype.onStop=function(t){return this.stopListeners.add(t),this},o.prototype.onDone=function(t){return this.doneListeners.add(t),this},o.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},o.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;B(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var i=void 0===e?this.initialState:U(this,(function(){return!v(t=e)&&"value"in t&&"history"in t?n.machine.resolveState(e):n.machine.resolveState(R.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(i,M)})),this},o.prototype.stop=function(){var e,n,i,o,s,a,c,h,f,l,d=this;try{for(var v=r(this.listeners),y=v.next();!y.done;y=v.next()){var m=y.value;this.listeners.delete(m)}}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 w=r(this.stopListeners),x=w.next();!x.done;x=w.next()){(m=x.value)(),this.stopListeners.delete(m)}}catch(t){i={error:t}}finally{try{x&&!x.done&&(o=w.return)&&o.call(w)}finally{if(i)throw i.error}}try{for(var b=r(this.contextListeners),g=b.next();!g.done;g=b.next()){m=g.value;this.contextListeners.delete(m)}}catch(t){s={error:t}}finally{try{g&&!g.done&&(a=b.return)&&a.call(b)}finally{if(s)throw s.error}}try{for(var S=r(this.doneListeners),E=S.next();!E.done;E=S.next()){m=E.value;this.doneListeners.delete(m)}}catch(t){c={error:t}}finally{try{E&&!E.done&&(h=S.return)&&h.call(S)}finally{if(c)throw c.error}}if(!this.initialized)return this;this.state.configuration.forEach((function(t){var e,n;try{for(var i=r(t.definition.exit),o=i.next();!o.done;o=i.next()){var s=o.value;d.exec(s,d.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){p(t.stop)&&t.stop()}));try{for(var _=r(u(this.delayedEventsMap)),O=_.next();!O.done;O=_.next()){var T=O.value;this.clock.clearTimeout(this.delayedEventsMap[T])}}catch(t){f={error:t}}finally{try{O&&!O.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,H(this.sessionId),this},o.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,o,a=n.state,u=!1,c=[],h=function(t){var e=S(t);n.forward(e),a=U(n,(function(){return n.machine.transition(a,e)})),c.push.apply(c,s(a.actions.map((function(t){return n=a,r=(e=t).exec,i(i({},e),{exec:void 0!==r?function(){return r(n.context,n.event,{action:e,state:n,_event:n._event})}:void 0});var e,n,r})))),u=u||!!a.changed};try{for(var f=r(e),l=f.next();!l.done;l=f.next()){h(l.value)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(o=f.return)&&o.call(f)}finally{if(t)throw t.error}}a.changed=u,a.actions=c,n.update(a,S(e[e.length-1]))}))},o.prototype.sender=function(t){return this.send.bind(this,t)},o.prototype.nextState=function(t){var e=this,n=S(t);if(0===n.name.indexOf(j)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(j)})))throw n.data.data;return U(this,(function(){return e.machine.transition(e.state,n)}))},o.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}}},o.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)},o.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},o.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 L: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 k:this.cancel(t.sendId);break;case T: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,v=this.machine.options.services?this.machine.options.services[d.type]:void 0,m=h.id,x=h.data,b="autoForward"in h?h.autoForward:!!h.forward;if(!v)return;var g=x?f(x,o,s):void 0,S=p(v)?v(o,s.data,{data:g,src:d}):v;l(S)?this.spawnPromise(Promise.resolve(S),m):p(S)?this.spawnCallback(S,m):y(S)?this.spawnObservable(S,m):w(S)&&this.spawnMachine(g?S.withContext(g):S,{id:m,autoForward:b})}else this.spawnActivity(h);break;case I:this.stopChild(t.activity.id);break;case P:var E=t.label,_=t.value;E?this.logger(E,_):this.logger(_)}},o.prototype.removeChild=function(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]},o.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),p(e.stop)&&e.stop())},o.prototype.spawn=function(t,e,n){if(l(t))return this.spawnPromise(Promise.resolve(t),e);if(p(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(r=t)&&"id"in r)return this.spawnActor(t);if(y(t))return this.spawnObservable(t,e);if(w(t))return this.spawnMachine(t,i(i({},n),{id:e}));throw new Error('Unable to spawn entity "'+e+'" of type "'+typeof t+'".');var r},o.prototype.spawnMachine=function(t,e){var n=this;void 0===e&&(e={});var r=new o(t,i(i({},this.options),{parent:this,id:e.id||t.id})),s=i(i({},Y),e);s.sync&&r.onTransition((function(t){n.send(D,{state:t,id:r.id})}));var a=r;return this.children.set(r.id,a),s.autoForward&&this.forwardTo.add(r.id),r.onDone((function(t){n.removeChild(r.id),n.send(S(t,{origin:r.id}))})).start(),a},o.prototype.spawnPromise=function(t,e){var n=this,i=!1;t.then((function(t){i||(n.removeChild(e),n.send(S(A(e,t),{origin:e})))}),(function(t){if(!i){n.removeChild(e);var r=z(e,t);try{n.send(S(r,{origin:e}))}catch(t){n.devTools&&n.devTools.send(r,n.state),n.machine.strict&&n.stop()}}}));var r={id:e,send:function(){},subscribe:function(e,n,i){var r=function(t,e,n){if("object"==typeof t)return t;var i=function(){};return{next:t,error:e||i,complete:n||i}}(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(){i=!0},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},o.prototype.spawnCallback=function(t,e){var n,i=this,r=!1,o=new Set,s=new Set;try{n=t((function(t){s.forEach((function(e){return e(t)})),r||i.send(S(t,{origin:e}))}),(function(t){o.add(t)}))}catch(t){this.send(z(e,t))}if(l(n))return this.spawnPromise(n,e);var a={id:e,send:function(t){return o.forEach((function(e){return e(t)}))},subscribe:function(t){return s.add(t),{unsubscribe:function(){s.delete(t)}}},stop:function(){r=!0,p(n)&&n()},toJSON:function(){return{id:e}}};return this.children.set(e,a),a},o.prototype.spawnObservable=function(t,e){var n=this,i=t.subscribe((function(t){n.send(S(t,{origin:e}))}),(function(t){n.removeChild(e),n.send(S(z(e,t),{origin:e}))}),(function(){n.removeChild(e),n.send(S(A(e),{origin:e}))})),r={id:e,send:function(){},subscribe:function(e,n,i){return t.subscribe(e,n,i)},stop:function(){return i.unsubscribe()},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},o.prototype.spawnActor=function(t){return this.children.set(t.id,t),t},o.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)}},o.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,toJSON:function(){return{id:t}}})},o.prototype.attachDev=function(){var t=K();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(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)}Q(this)}},o.prototype.toJSON=function(){return{id:this.id}},o.prototype[m]=function(){return this},o.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),o.interpret=tt,o}();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:b()}),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(){}}},toJSON:function(){return{id:t}}}}(e);return i.deferred=!0,w(t)&&(i.state=U(void 0,(function(){return(n?t.withContext(n):t).initialState}))),i}(t,n.name)}(q[q.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/dist/xstate.js
CHANGED
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
13
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
14
|
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function n(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return a}function o(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(i(arguments[e]));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 N(i)?!!N(r)&&i===r:N(r)?r in i:s(r).every((function(t){return t in i&&c(r[t],i[t])}))}function u(t){try{return N(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 E(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:E(t)?l(t):"string"!=typeof t?t:l(h(t,e));var n}function l(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function d(t,e){for(var n={},r=s(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function p(t,e,n){var i,o,a={};try{for(var c=r(s(t)),u=c.next();!u.done;u=c.next()){var h=u.value,f=t[h];n(f)&&(a[h]=e(f,h,t))}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(i)throw i.error}}return a}var v=function(t){return function(e){var n,i,o=e;try{for(var a=r(t),s=a.next();!s.done;s=a.next()){o=o[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return o}};function y(t){return t?N(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(t))}function m(t){return E(t)?t:[t]}function x(t){return void 0===t?[]:m(t)}function S(t,e,n){var i,o;if(T(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];T(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||!T(t)&&"object"!=typeof t||!T(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=(N(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:_(t,r)}}}))}function E(t){return Array.isArray(t)}function T(t){return"function"==typeof t}function N(t){return"string"==typeof t}function O(t,e){if(t)return N(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:T(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}function A(t){try{return"subscribe"in t&&T(t.subscribe)}catch(t){return!1}}var P="function"==typeof Symbol&&Symbol.observable||"@@observable";function k(t){try{return"__xstatenode"in t}catch(t){return!1}}var I,j,C,V=(I=0,function(){return(++I).toString(16)});function L(t,n){return N(t)||"number"==typeof t?e({type:t},n):t}function D(t,n){if(!N(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var r=L(t);return e({name:r.type,data:r,$$type:"scxml",type:"external"},n)}function M(t,n){return 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 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 z(t){return"string"==typeof t?{type:t}:t}(j=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",j.Stop="xstate.stop",j.Raise="xstate.raise",j.Send="xstate.send",j.Cancel="xstate.cancel",j.NullEvent="",j.Assign="xstate.assign",j.After="xstate.after",j.DoneState="done.state",j.DoneInvoke="done.invoke",j.Log="xstate.log",j.Init="xstate.init",j.Invoke="xstate.invoke",j.ErrorExecution="error.execution",j.ErrorCommunication="error.communication",j.ErrorPlatform="error.platform",j.ErrorCustom="xstate.error",j.Update="xstate.update",j.Pure="xstate.pure",j.Choose="xstate.choose",(C=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",C.Internal="#_internal";var 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 J(t){var e=[t];return F(t)?e:e.concat(g(U(t).map(J)))}function B(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 x=(s=void 0,r(U(E))),S=x.next();!S.done;S=x.next()){var w=S.value;"history"!==w.type&&(l.has(w)||(l.add(w),f.get(w)?f.get(w).forEach((function(t){return l.add(t)})):w.initialStateNodes.forEach((function(t){return l.add(t)}))))}}catch(t){s={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}finally{if(s)throw s.error}}}else f.get(E)?f.get(E).forEach((function(t){return l.add(t)})):E.initialStateNodes.forEach((function(t){return l.add(t)}))}}catch(t){o={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(o)throw o.error}}try{for(var b=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(B([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=D({type:nt});function ht(t,e){return e&&e[t]||void 0}function ft(t,n){var r;if(N(t)||"number"==typeof t){var i=ht(t,n);r=T(i)?{type:t,exec:i}:i||{type:t,exec:void 0}}else if(T(t))r={type:t.name||t.toString(),exec:t};else{if(T(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 Object.defineProperty(r,"toString",{value:function(){return r.type},enumerable:!1,configurable:!0}),r}var lt=function(t,e){return t?(E(t)?t:[t]).map((function(t){return ft(t,e)})):[]};function dt(t){var n=ft(t);return e(e({id:N(t)?t:n.id},n),{type:n.type})}function pt(e){return N(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:T(t)?t:L(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:T(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 xt=function(t){return{type:Y,sendId:t}};function St(e){var n=dt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function wt(e){var n=T(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,o,a,c,u){var h=i(b(u,(function(t){return t.type===tt})),2),f=h[0],l=h[1],d=f.length?function(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(T(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]=T(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}(a,c,f,o):a;return[g(l.map((function(r){var i;switch(r.type){case Q:return{type:Q,_event:D(r.event)};case W:return function(t,n,r,i){var o,a={_event:r},s=D(T(t.event)?t.event(n,r.data,a):t.event);if(N(t.delay)){var c=i&&i[t.delay];o=T(c)?c(n,r.data,a):c}else o=T(t.delay)?t.delay(n,r.data,a):t.delay;var u=T(t.to)?t.to(n,r.data,a):t.to;return e(e({},t),{to:u,_event:s,event:s.data,delay:o})}(r,d,c,n.options.delays);case et:return function(t,n,r){return e(e({},t),{value:N(t.expr)?t.expr:t.expr(n,r.data,{_event:r})})}(r,d,c);case st:if(!(s=null===(i=r.conds.find((function(t){var e=O(t.cond,n.options.guards);return!e||R(n,e,d,c,o)})))||void 0===i?void 0:i.actions))return[];var a=At(n,o,d,c,lt(x(s),n.options.actions));return d=a[1],a[0];case ct:var s;if(!(s=r.get(d,c.data)))return[];a=At(n,o,d,c,lt(x(s),n.options.actions));return d=a[1],a[0];case K:return function(e,n,r){var i=T(e.activity)?e.activity(n,r.data):e.activity,o="string"==typeof i?{id:i}:i;return{type:t.ActionTypes.Stop,activity:o}}(r,d,c);default:return ft(r,n.options.actions)}}))),d]}var Pt=function(){function t(t){var e=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=t.meta||{},this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,Object.defineProperty(this,"nextEvents",{get:function(){return t=e.configuration,g(o(new Set(t.map((function(t){return t.ownEvents})))));var t}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:ut,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var 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="."),N(t))return[t];var r=s(t);return r.concat.apply(r,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;return n(this,["configuration","transitions"])},t.prototype.matches=function(t){return c(t,this.value)},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(){}}},toJSON:function(){return{id:t}}}}function Ct(t,e,n){var r=jt(e);return r.deferred=!0,k(t)&&(r.state=It(void 0,(function(){return(n?t.withContext(n):t).initialState}))),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={},Mt=function(t){return"#"===t[0]},Rt=function(){function a(t,n,i){var c,u=this;void 0===i&&(i=void 0),this.config=t,this.context=i,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.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],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:u,_key:n});return Object.assign(u.idMap,e(((r={})[i.id]=i,r),i.idMap)),i})):Dt;var h=0;!function t(e){var n,i;e.order=h++;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=x(this.config.entry||this.config.onEntry).map((function(t){return ft(t)})),this.onExit=x(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=x(this.config.invoke).map((function(t,n){var r,i;if(k(t))return u.machine.options.services=e(((r={})[t.id]=t,r),u.machine.options.services),Lt({src:t.id,id:t.id});if(N(t.src))return Lt(e(e({},t),{id:t.id||t.src,src:t.src}));if(k(t.src)||T(t.src)){var o=u.id+":invocation["+n+"]";return u.machine.options.services=e(((i={})[o]=t.src,i),u.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=x(this.config.activities).concat(this.invoke).map((function(t){return dt(t)})),this.transition=this.transition.bind(this)}return a.prototype._init=function(){this.__cache.transitions||J(this).forEach((function(t){return t.on}))},a.prototype.withConfig=function(t,n){void 0===n&&(n=this.context);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)},n)},a.prototype.withContext=function(t){return new a(this.config,this.options,t)},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(T(e)?t.id+":delay["+n+"]":e,t.id);return t.onEntry.push(vt(r,{delay:e})),t.onExit.push(xt(r)),r};return(E(n)?n.map((function(t,n){var i=r(t.delay,n);return e(e({},t),{event:i})})):g(s(n).map((function(t,i){var o=n[t],a=N(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=r(s,i);return x(a).map((function(t){return e(e({},t),{event:c,delay:s})}))})))).map((function(n){var r=n.delay;return e(e({},t.formatTransition(n)),{delay:r})}))},a.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof Pt?t.value:f(t,this.delimiter);if(N(r)){var i=this.getStateNode(r).initial;return void 0!==i?this.getStateNodes(((e={})[r]=i,e)):[this.states[r]]}var o=s(r);return o.map((function(t){return n.getStateNode(t)})).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(B([],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 N(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,i,a,s=this,u=e.name,h=[],l=[];try{for(var d=r(this.getCandidates(u)),p=d.next();!p.done;p=d.next()){var y=p.value,m=y.cond,x=y.in,S=t.context,w=!x||(N(x)&&Mt(x)?t.matches(f(this.getStateNodeById(x).path,this.delimiter)):c(f(x,this.delimiter),v(this.path.slice(0,-2))(t.value))),b=!1;try{b=!m||R(this.machine,m,S,e,t)}catch(t){throw new Error("Unable to evaluate guard '"+(m.name||m.type)+"' in transition for event '"+u+"' in state node '"+this.id+"':\n"+t.message)}if(b&&w){void 0!==y.target&&(l=y.target),h.push.apply(h,o(y.actions)),a=y;break}}}catch(t){n={error:t}}finally{try{p&&!p.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}if(a){if(!l.length)return{transitions:[a],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:h};var _=g(l.map((function(e){return s.getRelativeStateNodes(e,t.historyValue)}))),E=!!a.internal;return{transitions:[a],entrySet:E?[]:g(_.map((function(t){return s.nodesFromChild(t)}))),exitSet:E?[]:[this],configuration:_,source:t,actions:h}}},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=B([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?B(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 x=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?S(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(t.activities.map((function(t){return St(t)})),t.onEntry)}))).concat(x.map(pt)),g(Array.from(b).map((function(t){return o(t.onExit,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,i,a=D(e);if(t instanceof Pt)r=void 0===n?t:this.resolveState(Pt.from(t,n));else{var s=N(t)?this.resolve(l(this.getResolvedPath(t))):this.resolve(t),c=n||this.machine.context;r=this.resolveState(Pt.from(s,c))}if(this.strict&&!this.events.includes(a.name)&&(i=a.name,!/^(done|error)\./.test(i)))throw new Error("Machine '"+this.id+"' does not accept event '"+a.name+"'");var u=this._transition(r.value,r,a)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:r,actions:[]},h=B([],this.getStateNodes(r.value)),f=u.configuration.length?B(h,u.configuration):h;return u.configuration=o(f),this.resolveTransition(u,r,a)},a.prototype.resolveRaisedTransition=function(t,e,n){var r,i=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(r=t.actions).unshift.apply(r,o(i)),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?$(this.machine,l):void 0,p=o?o.historyValue?o.historyValue:n.source?this.machine.historyValue(o.value):void 0:void 0,v=o?o.context:c,y=this.getActions(n,v,a,o),g=o?e({},o.activities):{};try{for(var m=r(y),x=m.next();!x.done;x=m.next()){var w=x.value;w.type===G?g[w.activity.id||w.activity.type]=w:w.type===K&&(g[w.activity.id||w.activity.type]=!1)}}catch(t){u={error:t}}finally{try{x&&!x.done&&(h=m.return)&&h.call(m)}finally{if(u)throw u.error}}var E,T,O=i(At(this,o,v,a,y),2),A=O[0],P=O[1],k=i(b(A,(function(e){return e.type===Q||e.type===W&&e.to===t.SpecialTargets.Internal})),2),I=k[0],j=k[1],C=A.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=z(t.src),a=null===(i=null==e?void 0:e.options.services)||void 0===i?void 0:i[o.type],s=t.data?S(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,P,a),t}),o?e({},o.children):{}),V=d?n.configuration:o?o.configuration:[],L=V.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{}),D=H(V,this),M=new Pt({value:d||o.value,context:P,_event:a,_sessionid:o?o._sessionid:null,historyValue:d?p?(E=p,T=d,{current:T,states:_(E,T)}):void 0:o?o.historyValue:void 0,history:!d||n.source?o:void 0,actions:d?j:[],activities:d?g:o?o.activities:{},meta:d?L:o?o.meta:void 0,events:[],configuration:V,transitions:n.transitions,children:C,done:D}),R=v!==P;M.changed=a.name===at||R;var F=M.history;if(F&&delete F.history,!d)return M;var U=M;if(!D)for((this._transient||l.some((function(t){return t._transient})))&&(U=this.resolveRaisedTransition(U,{type:Z},a));I.length;){var J=I.shift();U=this.resolveRaisedTransition(U,J._event,a)}var B=U.changed||(F?!!U.actions.length||R||typeof F.value!=typeof U.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(N(e)||N(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])}))}(U.value,F.value):void 0);return U.changed=B,U.history=F,U},a.prototype.getStateNode=function(t){if(Mt(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=Mt(t)?t.slice("#".length):t;if(e===this.id)return this;var n=this.machine.idMap[e];if(!n)throw new Error("Child state node '#"+e+"' does not exist on machine '"+this.id+"'");return n},a.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&Mt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=h(t,this.delimiter).slice(),n=this;e.length;){var r=e.shift();if(!r.length)break;n=n.getStateNode(r)}return n},a.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||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(N(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(Mt(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)}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=N(e.target)&&Mt(e.target)?l(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!1,configurable:!0}),a.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(a.prototype,"initialStateNodes",{get:function(){var t=this;return F(this)?[this]:"compound"!==this.type||this.initial?g(y(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!1,configurable:!0}),a.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=i(t),n=e[0],r=e.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+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=N(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 N(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(!N(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 x(t)}(t.target),i="internal"in t?t.internal:!r||r.some((function(t){return N(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(r),s=e(e({},t),{actions:lt(x(t.actions)),cond:O(t.cond,o),target:a,source:this,internal:i,eventType:t.event,toJSON:function(){return e(e({},s),{target:s.target?s.target.map((function(t){return"#"+t.id})):void 0,source:"#"+n.id})}});return s},a.prototype.formatTransitions=function(){var t,e,i,a=this;if(this.config.on)if(Array.isArray(this.config.on))i=this.config.on;else{var c=this.config.on,u=c["*"],h=void 0===u?[]:u,f=n(c,["*"]);i=g(s(f).map((function(t){return M(t,f[t])})).concat(M("*",h)))}else i=[];var l=this.config.always?M("",this.config.always):[],d=this.config.onDone?M(String(Et(this.id)),this.config.onDone):[],p=g(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o(M(String(Tt(t.id)),t.onDone))),t.onError&&e.push.apply(e,o(M(String(Nt(t.id)),t.onError))),e}))),v=this.after,y=g(o(d,p,i,l).map((function(t){return x(t).map((function(t){return a.formatTransition(t)}))})));try{for(var m=r(v),S=m.next();!S.done;S=m.next()){var w=S.value;y.push(w)}}catch(e){t={error:e}}finally{try{S&&!S.done&&(e=m.return)&&e.call(m)}finally{if(t)throw t.error}}return y},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,Jt=0,Bt=function(){return"x:"+Jt++},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}var Gt,Kt={sync:!1,autoForward:!1};(Gt=t.InterpreterStatus||(t.InterpreterStatus={}))[Gt.NotStarted=0]="NotStarted",Gt[Gt.Running=1]="Running",Gt[Gt.Stopped=2]="Stopped";var Qt=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(E(e))return o.batch(e),o.state;var r=D(L(e,n));if(o.status===t.InterpreterStatus.Stopped)return o.state;if(o.status!==t.InterpreterStatus.Running&&!o.options.deferEvents)throw new Error('Event "'+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:N(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=Bt()}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 x=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),w=x&&x.doneData?S(x.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!N(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 x=r(this.contextListeners),S=x.next();!S.done;S=x.next()){y=S.value;this.contextListeners.delete(y)}}catch(t){a={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}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){T(t.stop)&&t.stop()}));try{for(var _=r(s(this.delayedEventsMap)),E=_.next();!E.done;E=_.next()){var N=E.value;this.clock.clearTimeout(this.delayedEventsMap[N])}}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 i=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,a,s=i.state,c=!1,u=[],h=function(t){var n=D(t);i.forward(n),s=It(i,(function(){return i.machine.transition(s,n)})),u.push.apply(u,o(s.actions.map((function(t){return r=s,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||!!s.changed};try{for(var f=r(n),l=f.next();!l.done;l=f.next()){h(l.value)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(t)throw t.error}}s.changed=c,s.actions=u,i.update(s,D(n[n.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=D(t);if(0===n.name.indexOf(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=T(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=z(u.src),f=this.machine.options.services?this.machine.options.services[h.type]:void 0,l=u.id,d=u.data,p="autoForward"in u?u.autoForward:!!u.forward;if(!f)return;var v=d?S(d,i,o):void 0,y=T(f)?f(i,o.data,{data:v,src:h}):f;w(y)?this.spawnPromise(Promise.resolve(y),l):T(y)?this.spawnCallback(y,l):A(y)?this.spawnObservable(y,l):k(y)&&this.spawnMachine(v?y.withContext(v):y,{id:l,autoForward:p})}else this.spawnActivity(u);break;case K:this.stopChild(e.activity.id);break;case et:var g=e.label,m=e.value;g?this.logger(g,m):this.logger(m)}},n.prototype.removeChild=function(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]},n.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),T(e.stop)&&e.stop())},n.prototype.spawn=function(t,n,r){if(w(t))return this.spawnPromise(Promise.resolve(t),n);if(T(t))return this.spawnCallback(t,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(i=t)&&"id"in i)return this.spawnActor(t);if(A(t))return this.spawnObservable(t,n);if(k(t))return this.spawnMachine(t,e(e({},r),{id:n}));throw new Error('Unable to spawn entity "'+n+'" of type "'+typeof t+'".');var i},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({},Kt),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(D(t,{origin:o.id}))})).start(),s},n.prototype.spawnPromise=function(t,e){var n=this,r=!1;t.then((function(t){r||(n.removeChild(e),n.send(D(Tt(e,t),{origin:e})))}),(function(t){if(!r){n.removeChild(e);var i=Nt(e,t);try{n.send(D(i,{origin:e}))}catch(t){n.devTools&&n.devTools.send(i,n.state),n.machine.strict&&n.stop()}}}));var i={id:e,send:function(){},subscribe:function(e,n,r){var i=function(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}(e,n,r),o=!1;return t.then((function(t){o||(i.next(t),o||i.complete())}),(function(t){o||i.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){r=!0},toJSON:function(){return{id:e}}};return this.children.set(e,i),i},n.prototype.spawnCallback=function(t,e){var n,r=this,i=!1,o=new Set,a=new Set;try{n=t((function(t){a.forEach((function(e){return e(t)})),i||r.send(D(t,{origin:e}))}),(function(t){o.add(t)}))}catch(t){this.send(Nt(e,t))}if(w(n))return this.spawnPromise(n,e);var s={id:e,send:function(t){return o.forEach((function(e){return e(t)}))},subscribe:function(t){return a.add(t),{unsubscribe:function(){a.delete(t)}}},stop:function(){i=!0,T(n)&&n()},toJSON:function(){return{id:e}}};return this.children.set(e,s),s},n.prototype.spawnObservable=function(t,e){var n=this,r=t.subscribe((function(t){n.send(D(t,{origin:e}))}),(function(t){n.removeChild(e),n.send(D(Nt(e,t),{origin:e}))}),(function(){n.removeChild(e),n.send(D(Tt(e),{origin:e}))})),i={id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return r.unsubscribe()},toJSON:function(){return{id:e}}};return this.children.set(e,i),i},n.prototype.spawnActor=function(t){return this.children.set(t.id,t),t},n.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},n.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,toJSON:function(){return{id:t}}})},n.prototype.attachDev=function(){var t=Ht();if(this.options.devTools&&t&&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)}},n.prototype.toJSON=function(){return{id:this.id}},n.prototype[P]=function(){return this},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=Wt,n}();function Wt(t,e){return new Qt(t,e)}var Yt={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:xt,start:St,stop:wt,assign:bt,after:_t,done:Et,respond:function(t,n){return vt(t,e(e({},n),{to:function(t,e,n){return n._event.origin}}))},forwardTo:Ot,escalate:function(n,r){return yt((function(t,e,r){return{type:ot,data:T(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=Qt,t.Machine=function(t,e,n){void 0===n&&(n=t.context);var r="function"==typeof n?n():n;return new Rt(t,e,r)},t.State=Pt,t.StateNode=Rt,t.actions=Yt,t.assign=bt,t.createMachine=function(t,e){var n="function"==typeof t.context?t.context():t.context;return new Rt(t,e,n)},t.createSchema=function(t){return t},t.doneInvoke=Tt,t.forwardTo=Ot,t.interpret=Wt,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 N(t)?e(e({},Kt),{name:t}):e(e(e({},Kt),{name:V()}),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(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(i(arguments[e]));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 N(i)?!!N(r)&&i===r:N(r)?r in i:s(r).every((function(t){return t in i&&c(r[t],i[t])}))}function u(t){try{return N(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 E(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:E(t)?l(t):"string"!=typeof t?t:l(h(t,e));var n}function l(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function d(t,e){for(var n={},r=s(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function v(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 p=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?N(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(t))}function m(t){return E(t)?t:[t]}function x(t){return void 0===t?[]:m(t)}function S(t,e,n){var i,o;if(T(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];T(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||!T(t)&&"object"!=typeof t||!T(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=(N(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:_(t,r)}}}))}function E(t){return Array.isArray(t)}function T(t){return"function"==typeof t}function N(t){return"string"==typeof t}function O(t,e){if(t)return N(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:T(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}function A(t){try{return"subscribe"in t&&T(t.subscribe)}catch(t){return!1}}var P="function"==typeof Symbol&&Symbol.observable||"@@observable";function k(t){try{return"__xstatenode"in t}catch(t){return!1}}var I,j,C,V=(I=0,function(){return(++I).toString(16)});function L(t,n){return N(t)||"number"==typeof t?e({type:t},n):t}function D(t,n){if(!N(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var r=L(t);return e({name:r.type,data:r,$$type:"scxml",type:"external"},n)}function M(t,n){return 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 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 z(t){return"string"==typeof t?{type:t}:t}(j=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",j.Stop="xstate.stop",j.Raise="xstate.raise",j.Send="xstate.send",j.Cancel="xstate.cancel",j.NullEvent="",j.Assign="xstate.assign",j.After="xstate.after",j.DoneState="done.state",j.DoneInvoke="done.invoke",j.Log="xstate.log",j.Init="xstate.init",j.Invoke="xstate.invoke",j.ErrorExecution="error.execution",j.ErrorCommunication="error.communication",j.ErrorPlatform="error.platform",j.ErrorCustom="xstate.error",j.Update="xstate.update",j.Pure="xstate.pure",j.Choose="xstate.choose",(C=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",C.Internal="#_internal";var 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 J(t){var e=[t];return F(t)?e:e.concat(g(U(t).map(J)))}function B(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),v=d.next();!v.done;v=d.next())for(var p=(E=v.value).parent;p&&!l.has(p);)l.add(p),p=p.parent}catch(t){n={error:t}}finally{try{v&&!v.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 x=(s=void 0,r(U(E))),S=x.next();!S.done;S=x.next()){var w=S.value;"history"!==w.type&&(l.has(w)||(l.add(w),f.get(w)?f.get(w).forEach((function(t){return l.add(t)})):w.initialStateNodes.forEach((function(t){return l.add(t)}))))}}catch(t){s={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}finally{if(s)throw s.error}}}else f.get(E)?f.get(E).forEach((function(t){return l.add(t)})):E.initialStateNodes.forEach((function(t){return l.add(t)}))}}catch(t){o={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(o)throw o.error}}try{for(var b=r(l),_=b.next();!_.done;_=b.next()){var E;for(p=(E=_.value).parent;p&&!l.has(p);)l.add(p),p=p.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(B([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=D({type:nt});function ht(t,e){return e&&e[t]||void 0}function ft(t,n){var r;if(N(t)||"number"==typeof t){var i=ht(t,n);r=T(i)?{type:t,exec:i}:i||{type:t,exec:void 0}}else if(T(t))r={type:t.name||t.toString(),exec:t};else{if(T(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 Object.defineProperty(r,"toString",{value:function(){return r.type},enumerable:!1,configurable:!0}),r}var lt=function(t,e){return t?(E(t)?t:[t]).map((function(t){return ft(t,e)})):[]};function dt(t){var n=ft(t);return e(e({id:N(t)?t:n.id},n),{type:n.type})}function vt(e){return N(e)?{type:Q,event:e}:pt(e,{to:t.SpecialTargets.Internal})}function pt(t,e){return{to:e?e.to:void 0,type:W,event:T(t)?t:L(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:T(t)?t.name:u(t)}}function yt(n,r){return pt(n,e(e({},r),{to:t.SpecialTargets.Parent}))}function gt(){return yt(at)}var mt=function(t,e){return{context:t,event:e}};var xt=function(t){return{type:Y,sendId:t}};function St(e){var n=dt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function wt(e){var n=T(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 pt((function(t,e){return e}),e(e({},n),{to:t}))}function At(n,o,a,c,u){var h=i(b(u,(function(t){return t.type===tt})),2),f=h[0],l=h[1],d=f.length?function(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(T(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,v=c[d];h[d]=T(v)?v(t,e.data,u):v}}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}(a,c,f,o):a;return[g(l.map((function(r){var i;switch(r.type){case Q:return{type:Q,_event:D(r.event)};case W:return function(t,n,r,i){var o,a={_event:r},s=D(T(t.event)?t.event(n,r.data,a):t.event);if(N(t.delay)){var c=i&&i[t.delay];o=T(c)?c(n,r.data,a):c}else o=T(t.delay)?t.delay(n,r.data,a):t.delay;var u=T(t.to)?t.to(n,r.data,a):t.to;return e(e({},t),{to:u,_event:s,event:s.data,delay:o})}(r,d,c,n.options.delays);case et:return function(t,n,r){return e(e({},t),{value:N(t.expr)?t.expr:t.expr(n,r.data,{_event:r})})}(r,d,c);case st:if(!(s=null===(i=r.conds.find((function(t){var e=O(t.cond,n.options.guards);return!e||R(n,e,d,c,o)})))||void 0===i?void 0:i.actions))return[];var a=At(n,o,d,c,lt(x(s),n.options.actions));return d=a[1],a[0];case ct:var s;if(!(s=r.get(d,c.data)))return[];a=At(n,o,d,c,lt(x(s),n.options.actions));return d=a[1],a[0];case K:return function(e,n,r){var i=T(e.activity)?e.activity(n,r.data):e.activity,o="string"==typeof i?{id:i}:i;return{type:t.ActionTypes.Stop,activity:o}}(r,d,c);default:return ft(r,n.options.actions)}}))),d]}var Pt=function(){function t(t){var e,n=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=t.meta||{},this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=t.tags)&&void 0!==e?e:new Set,Object.defineProperty(this,"nextEvents",{get:function(){return t=n.configuration,g(o(new Set(t.map((function(t){return t.ownEvents})))));var t}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:ut,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var 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="."),N(t))return[t];var r=s(t);return r.concat.apply(r,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,r=n(this,["configuration","transitions","tags"]);return e(e({},r),{tags:Array.from(t)})},t.prototype.matches=function(t){return c(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(){}}},toJSON:function(){return{id:t}}}}function Ct(t,e,n){var r=jt(e);return r.deferred=!0,k(t)&&(r.state=It(void 0,(function(){return(n?t.withContext(n):t).initialState}))),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={},Mt=function(t){return"#"===t[0]},Rt=function(){function a(t,n,i){var c,u=this;void 0===i&&(i=void 0),this.config=t,this.context=i,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},n),this.parent=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],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:u,_key:n});return Object.assign(u.idMap,e(((r={})[i.id]=i,r),i.idMap)),i})):Dt;var h=0;!function t(e){var n,i;e.order=h++;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=x(this.config.entry||this.config.onEntry).map((function(t){return ft(t)})),this.onExit=x(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=x(this.config.invoke).map((function(t,n){var r,i;if(k(t))return u.machine.options.services=e(((r={})[t.id]=t,r),u.machine.options.services),Lt({src:t.id,id:t.id});if(N(t.src))return Lt(e(e({},t),{id:t.id||t.src,src:t.src}));if(k(t.src)||T(t.src)){var o=u.id+":invocation["+n+"]";return u.machine.options.services=e(((i={})[o]=t.src,i),u.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=x(this.config.activities).concat(this.invoke).map((function(t){return dt(t)})),this.transition=this.transition.bind(this),this.tags=x(this.config.tags)}return a.prototype._init=function(){this.__cache.transitions||J(this).forEach((function(t){return t.on}))},a.prototype.withConfig=function(t,n){void 0===n&&(n=this.context);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)},n)},a.prototype.withContext=function(t){return new a(this.config,this.options,t)},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(T(e)?t.id+":delay["+n+"]":e,t.id);return t.onEntry.push(pt(r,{delay:e})),t.onExit.push(xt(r)),r};return(E(n)?n.map((function(t,n){var i=r(t.delay,n);return e(e({},t),{event:i})})):g(s(n).map((function(t,i){var o=n[t],a=N(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=r(s,i);return x(a).map((function(t){return e(e({},t),{event:c,delay:s})}))})))).map((function(n){var r=n.delay;return e(e({},t.formatTransition(n)),{delay:r})}))},a.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof Pt?t.value:f(t,this.delimiter);if(N(r)){var i=this.getStateNode(r).initial;return void 0!==i?this.getStateNodes(((e={})[r]=i,e)):[this.states[r]]}var o=s(r);return o.map((function(t){return n.getStateNode(t)})).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(B([],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]})),v=g(d.map((function(t){return t.transitions})));if(!d.some((function(t){return t.transitions.length>0})))return this.next(e,n);var p=g(d.map((function(t){return t.entrySet}))),y=g(s(a).map((function(t){return a[t].configuration})));return{transitions:v,entrySet:p,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 N(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,i,a,s=this,u=e.name,h=[],l=[];try{for(var d=r(this.getCandidates(u)),v=d.next();!v.done;v=d.next()){var y=v.value,m=y.cond,x=y.in,S=t.context,w=!x||(N(x)&&Mt(x)?t.matches(f(this.getStateNodeById(x).path,this.delimiter)):c(f(x,this.delimiter),p(this.path.slice(0,-2))(t.value))),b=!1;try{b=!m||R(this.machine,m,S,e,t)}catch(t){throw new Error("Unable to evaluate guard '"+(m.name||m.type)+"' in transition for event '"+u+"' in state node '"+this.id+"':\n"+t.message)}if(b&&w){void 0!==y.target&&(l=y.target),h.push.apply(h,o(y.actions)),a=y;break}}}catch(t){n={error:t}}finally{try{v&&!v.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}if(a){if(!l.length)return{transitions:[a],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:h};var _=g(l.map((function(e){return s.getRelativeStateNodes(e,t.historyValue)}))),E=!!a.internal;return{transitions:[a],entrySet:E?[]:g(_.map((function(t){return s.nodesFromChild(t)}))),exitSet:E?[]:[this],configuration:_,source:t,actions:h}}},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=B([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?B(f,t.configuration):f;try{for(var d=r(l),v=d.next();!v.done;v=d.next()){X(f,m=v.value)||t.entrySet.push(m)}}catch(t){s={error:t}}finally{try{v&&!v.done&&(c=d.return)&&c.call(d)}finally{if(s)throw s.error}}try{for(var p=r(f),y=p.next();!y.done;y=p.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=p.return)&&h.call(p)}finally{if(u)throw u.error}}t.source||(t.exitSet=[],t.entrySet.push(this));var x=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?S(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(t.activities.map((function(t){return St(t)})),t.onEntry)}))).concat(x.map(vt)),g(Array.from(b).map((function(t){return o(t.onExit,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,i,a=D(e);if(t instanceof Pt)r=void 0===n?t:this.resolveState(Pt.from(t,n));else{var s=N(t)?this.resolve(l(this.getResolvedPath(t))):this.resolve(t),c=n||this.machine.context;r=this.resolveState(Pt.from(s,c))}if(this.strict&&!this.events.includes(a.name)&&(i=a.name,!/^(done|error)\./.test(i)))throw new Error("Machine '"+this.id+"' does not accept event '"+a.name+"'");var u=this._transition(r.value,r,a)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:r,actions:[]},h=B([],this.getStateNodes(r.value)),f=u.configuration.length?B(h,u.configuration):h;return u.configuration=o(f),this.resolveTransition(u,r,a)},a.prototype.resolveRaisedTransition=function(t,e,n){var r,i=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(r=t.actions).unshift.apply(r,o(i)),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?$(this.machine,l):void 0,v=o?o.historyValue?o.historyValue:n.source?this.machine.historyValue(o.value):void 0:void 0,p=o?o.context:c,y=this.getActions(n,p,a,o),m=o?e({},o.activities):{};try{for(var x=r(y),w=x.next();!w.done;w=x.next()){var E=w.value;E.type===G?m[E.activity.id||E.activity.type]=E:E.type===K&&(m[E.activity.id||E.activity.type]=!1)}}catch(t){u={error:t}}finally{try{w&&!w.done&&(h=x.return)&&h.call(x)}finally{if(u)throw u.error}}var T,O,A=i(At(this,o,p,a,y),2),P=A[0],k=A[1],I=i(b(P,(function(e){return e.type===Q||e.type===W&&e.to===t.SpecialTargets.Internal})),2),j=I[0],C=I[1],V=P.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=z(t.src),a=null===(i=null==e?void 0:e.options.services)||void 0===i?void 0:i[o.type],s=t.data?S(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,k,a),t}),o?e({},o.children):{}),L=d?n.configuration:o?o.configuration:[],D=L.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{}),M=H(L,this),R=new Pt({value:d||o.value,context:k,_event:a,_sessionid:o?o._sessionid:null,historyValue:d?v?(T=v,O=d,{current:O,states:_(T,O)}):void 0:o?o.historyValue:void 0,history:!d||n.source?o:void 0,actions:d?C:[],activities:d?m:o?o.activities:{},meta:d?D:o?o.meta:void 0,events:[],configuration:L,transitions:n.transitions,children:V,done:M,tags:null==o?void 0:o.tags}),F=p!==k;R.changed=a.name===at||F;var U=R.history;if(U&&delete U.history,!d)return R;var J=R;if(!M)for((this._transient||l.some((function(t){return t._transient})))&&(J=this.resolveRaisedTransition(J,{type:Z},a));j.length;){var B=j.shift();J=this.resolveRaisedTransition(J,B._event,a)}var q=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(N(e)||N(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=q,J.history=U,J.tags=new Set(g(J.configuration.map((function(t){return t.tags})))),J},a.prototype.getStateNode=function(t){if(Mt(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=Mt(t)?t.slice("#".length):t;if(e===this.id)return this;var n=this.machine.idMap[e];if(!n)throw new Error("Child state node '#"+e+"' does not exist on machine '"+this.id+"'");return n},a.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&Mt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=h(t,this.delimiter).slice(),n=this;e.length;){var r=e.shift();if(!r.length)break;n=n.getStateNode(r)}return n},a.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||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(N(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(Mt(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=v(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=N(e.target)&&Mt(e.target)?l(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!1,configurable:!0}),a.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(a.prototype,"initialStateNodes",{get:function(){var t=this;return F(this)?[this]:"compound"!==this.type||this.initial?g(y(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!1,configurable:!0}),a.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=i(t),n=e[0],r=e.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+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:v(this.states,(function(e,n){if(!t)return e.historyValue();var r=N(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 N(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(!N(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 x(t)}(t.target),i="internal"in t?t.internal:!r||r.some((function(t){return N(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(r),s=e(e({},t),{actions:lt(x(t.actions)),cond:O(t.cond,o),target:a,source:this,internal:i,eventType:t.event,toJSON:function(){return e(e({},s),{target:s.target?s.target.map((function(t){return"#"+t.id})):void 0,source:"#"+n.id})}});return s},a.prototype.formatTransitions=function(){var t,e,i,a=this;if(this.config.on)if(Array.isArray(this.config.on))i=this.config.on;else{var c=this.config.on,u=c["*"],h=void 0===u?[]:u,f=n(c,["*"]);i=g(s(f).map((function(t){return M(t,f[t])})).concat(M("*",h)))}else i=[];var l=this.config.always?M("",this.config.always):[],d=this.config.onDone?M(String(Et(this.id)),this.config.onDone):[],v=g(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o(M(String(Tt(t.id)),t.onDone))),t.onError&&e.push.apply(e,o(M(String(Nt(t.id)),t.onError))),e}))),p=this.after,y=g(o(d,v,i,l).map((function(t){return x(t).map((function(t){return a.formatTransition(t)}))})));try{for(var m=r(p),S=m.next();!S.done;S=m.next()){var w=S.value;y.push(w)}}catch(e){t={error:e}}finally{try{S&&!S.done&&(e=m.return)&&e.call(m)}finally{if(t)throw t.error}}return y},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,Jt=0,Bt=function(){return"x:"+Jt++},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)}}var Kt,Qt={sync:!1,autoForward:!1};(Kt=t.InterpreterStatus||(t.InterpreterStatus={}))[Kt.NotStarted=0]="NotStarted",Kt[Kt.Running=1]="Running",Kt[Kt.Stopped=2]="Stopped";var Wt=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(E(e))return o.batch(e),o.state;var r=D(L(e,n));if(o.status===t.InterpreterStatus.Stopped)return o.state;if(o.status!==t.InterpreterStatus.Running&&!o.options.deferEvents)throw new Error('Event "'+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:N(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=Bt()}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 v=r(this.listeners),p=v.next();!p.done;p=v.next()){(0,p.value)(t,t.event)}}catch(t){o={error:t}}finally{try{p&&!p.done&&(a=v.return)&&a.call(v)}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 x=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),w=x&&x.doneData?S(x.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!N(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 v=r(this.listeners),p=v.next();!p.done;p=v.next()){var y=p.value;this.listeners.delete(y)}}catch(t){e={error:t}}finally{try{p&&!p.done&&(n=v.return)&&n.call(v)}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 x=r(this.contextListeners),S=x.next();!S.done;S=x.next()){y=S.value;this.contextListeners.delete(y)}}catch(t){a={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}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){T(t.stop)&&t.stop()}));try{for(var _=r(s(this.delayedEventsMap)),E=_.next();!E.done;E=_.next()){var N=E.value;this.clock.clearTimeout(this.delayedEventsMap[N])}}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 i=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,a,s=i.state,c=!1,u=[],h=function(t){var n=D(t);i.forward(n),s=It(i,(function(){return i.machine.transition(s,n)})),u.push.apply(u,o(s.actions.map((function(t){return r=s,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||!!s.changed};try{for(var f=r(n),l=f.next();!l.done;l=f.next()){h(l.value)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(t)throw t.error}}s.changed=c,s.actions=u,i.update(s,D(n[n.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=D(t);if(0===n.name.indexOf(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=T(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=z(u.src),f=this.machine.options.services?this.machine.options.services[h.type]:void 0,l=u.id,d=u.data,v="autoForward"in u?u.autoForward:!!u.forward;if(!f)return;var p=d?S(d,i,o):void 0,y=T(f)?f(i,o.data,{data:p,src:h}):f;w(y)?this.spawnPromise(Promise.resolve(y),l):T(y)?this.spawnCallback(y,l):A(y)?this.spawnObservable(y,l):k(y)&&this.spawnMachine(p?y.withContext(p):y,{id:l,autoForward:v})}else this.spawnActivity(u);break;case K:this.stopChild(e.activity.id);break;case et:var g=e.label,m=e.value;g?this.logger(g,m):this.logger(m)}},n.prototype.removeChild=function(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]},n.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),T(e.stop)&&e.stop())},n.prototype.spawn=function(t,n,r){if(w(t))return this.spawnPromise(Promise.resolve(t),n);if(T(t))return this.spawnCallback(t,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(i=t)&&"id"in i)return this.spawnActor(t);if(A(t))return this.spawnObservable(t,n);if(k(t))return this.spawnMachine(t,e(e({},r),{id:n}));throw new Error('Unable to spawn entity "'+n+'" of type "'+typeof t+'".');var i},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({},Qt),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(D(t,{origin:o.id}))})).start(),s},n.prototype.spawnPromise=function(t,e){var n=this,r=!1;t.then((function(t){r||(n.removeChild(e),n.send(D(Tt(e,t),{origin:e})))}),(function(t){if(!r){n.removeChild(e);var i=Nt(e,t);try{n.send(D(i,{origin:e}))}catch(t){n.devTools&&n.devTools.send(i,n.state),n.machine.strict&&n.stop()}}}));var i={id:e,send:function(){},subscribe:function(e,n,r){var i=function(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}(e,n,r),o=!1;return t.then((function(t){o||(i.next(t),o||i.complete())}),(function(t){o||i.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){r=!0},toJSON:function(){return{id:e}}};return this.children.set(e,i),i},n.prototype.spawnCallback=function(t,e){var n,r=this,i=!1,o=new Set,a=new Set;try{n=t((function(t){a.forEach((function(e){return e(t)})),i||r.send(D(t,{origin:e}))}),(function(t){o.add(t)}))}catch(t){this.send(Nt(e,t))}if(w(n))return this.spawnPromise(n,e);var s={id:e,send:function(t){return o.forEach((function(e){return e(t)}))},subscribe:function(t){return a.add(t),{unsubscribe:function(){a.delete(t)}}},stop:function(){i=!0,T(n)&&n()},toJSON:function(){return{id:e}}};return this.children.set(e,s),s},n.prototype.spawnObservable=function(t,e){var n=this,r=t.subscribe((function(t){n.send(D(t,{origin:e}))}),(function(t){n.removeChild(e),n.send(D(Nt(e,t),{origin:e}))}),(function(){n.removeChild(e),n.send(D(Tt(e),{origin:e}))})),i={id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return r.unsubscribe()},toJSON:function(){return{id:e}}};return this.children.set(e,i),i},n.prototype.spawnActor=function(t){return this.children.set(t.id,t),t},n.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},n.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,toJSON:function(){return{id:t}}})},n.prototype.attachDev=function(){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.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=Yt,n}();function Yt(t,e){return new Wt(t,e)}var Zt={raise:vt,send:pt,sendParent:yt,sendUpdate:gt,log:function(t,e){return void 0===t&&(t=mt),{type:et,label:e,expr:t}},cancel:xt,start:St,stop:wt,assign:bt,after:_t,done:Et,respond:function(t,n){return pt(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:T(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=Wt,t.Machine=function(t,e,n){void 0===n&&(n=t.context);var r="function"==typeof n?n():n;return new Rt(t,e,r)},t.State=Pt,t.StateNode=Rt,t.actions=Zt,t.assign=bt,t.createMachine=function(t,e){var n="function"==typeof t.context?t.context():t.context;return new Rt(t,e,n)},t.createSchema=function(t){return t},t.doneInvoke=Tt,t.forwardTo=Ot,t.interpret=Yt,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=pt,t.sendParent=yt,t.sendUpdate=gt,t.spawn=function(t,n){var r=function(t){return N(t)?e(e({},Qt),{name:t}):e(e(e({},Qt),{name:V()}),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})}));
|
package/dist/xstate.web.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const t={};function e(t){return Object.keys(t)}function i(t,n
|
|
1
|
+
const t={};function e(t){return Object.keys(t)}function i(t,s,n="."){const r=o(t,n),a=o(s,n);return S(a)?!!S(r)&&a===r:S(r)?r in a:e(r).every(t=>t in a&&i(r[t],a[t]))}function s(t){try{return S(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 n(t,e){try{return m(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(m(t))return r(t);if("string"!=typeof t)return t;return r(n(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 s={},n=e(t);for(let e=0;e<n.length;e++){const o=n[e];s[o]=i(t[o],o,t,e)}return s}function c(t,i,s){const n={};for(const o of e(t)){const e=t[o];s(e)&&(n[o]=i(e,o,t))}return n}const h=t=>e=>{let i=e;for(const e of t)i=i[e];return i};function d(t){if(!t)return[[]];if(S(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 m(t)?t:[t]}function f(t){return void 0===t?[]:l(t)}function p(t,e,i){if(b(t))return t(e,i.data);const s={};for(const n of Object.keys(t)){const o=t[n];b(o)?s[n]=o(e,i.data):s[n]=o}return s}function g(t){return t instanceof Promise||!(null===t||!b(t)&&"object"!=typeof t||!b(t.then))}function v(t,e){const[i,s]=[[],[]];for(const n of t)e(n)?i.push(n):s.push(n);return[i,s]}function y(t,e){return a(t.states,(t,i)=>{if(!t)return;const s=(S(e)?void 0:e[i])||(t?t.current:void 0);return s?{current:s,states:y(t,s)}:void 0})}function m(t){return Array.isArray(t)}function b(t){return"function"==typeof t}function S(t){return"string"==typeof t}function w(t,e){if(t)return S(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:b(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}function x(t){try{return"subscribe"in t&&b(t.subscribe)}catch(t){return!1}}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 S(t)||"number"==typeof t?Object.assign({type:t},e):t}function N(t,e){if(!S(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,s,n){const{guards:o}=t.options,r={state:n,cond:e,_event:s};if("xstate.guard"===e.type)return e.predicate(i,s.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,s.data,r)}function k(t){return"string"==typeof t?{type:t}:t}function P(t,s){let n;for(const o of e(t))i(o,s)&&(!n||s.length>n.length)&&(n=o);return t[n]}
|
|
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 C(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 V,I;!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"}(V||(V={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(I||(I={}));const L=t=>"atomic"===t.type||"final"===t.type;function D(t){return e(t.states).map(e=>t.states[e])}function A(t){const e=[t];return L(t)?e:e.concat(u(D(t).map(A)))}function R(t,e){const i=M(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=M(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 M(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function z(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(L(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,M(R([t],e)))}function F(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&&F(t,e)):"parallel"===e.type&&D(e).every(e=>J(t,e))}const U=V.Start,B=V.Stop,q=V.Raise,X=V.Send,H=V.Cancel,G=V.NullEvent,K=V.Assign,Q=(V.After,V.DoneState,V.Log),W=V.Init,Y=V.Invoke,Z=(V.ErrorExecution,V.ErrorPlatform),tt=V.ErrorCustom,et=V.Update,it=V.Choose,nt=V.Pure,st=N({type:W});function ot(t,e){return e&&e[t]||void 0}function rt(t,e){let i;if(S(t)||"number"==typeof t){const n=ot(t,e);i=b(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(b(t))i={type:t.name||t.toString(),exec:t};else{const n=ot(t.type,e);if(b(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 Object.defineProperty(i,"toString",{value:()=>i.type,enumerable:!1,configurable:!0}),i}const at=(t,e)=>{if(!t)return[];return(m(t)?t:[t]).map(t=>rt(t,e))};function ct(t){const e=rt(t);return Object.assign(Object.assign({id:S(t)?t:e.id},e),{type:e.type})}function ht(t){return S(t)?{type:q,event:t}:dt(t,{to:I.Internal})}function dt(t,e){return{to:e?e.to:void 0,type:X,event:b(t)?t:E(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:b(t)?t.name:n(t)}}function ut(t,e){return dt(t,Object.assign(Object.assign({},e),{to:I.Parent}))}function lt(){return ut(et)}const ft=(t,e)=>({context:t,event:e});const pt=t=>({type:H,sendId:t});function gt(t){const e=ct(t);return{type:V.Start,activity:e,exec:void 0}}function vt(t){const e=b(t)?t:ct(t);return{type:V.Stop,activity:e,exec:void 0}}const yt=t=>({type:K,assignment:t});function mt(t,e){const i=e?"#"+e:"";return`${V.After}(${t})${i}`}function bt(t,e){const i=`${V.DoneState}.${t}`,n={type:i,data:e,toString:()=>i};return n}function St(t,e){const i=`${V.DoneInvoke}.${t}`,n={type:i,data:e,toString:()=>i};return n}function wt(t,e){const i=`${V.ErrorPlatform}.${t}`,n={type:i,data:e,toString:()=>i};return n}function xt(t,e){return dt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function Ot(t,i,n,s,o){const[r,a]=v(o,t=>t.type===K);let c=r.length?function(t,i,n,s){return t?n.reduce((t,n)=>{const{assignment:o}=n,r={state:s,action:n,_event:i};let a={};if(b(o))a=o(t,i.data,r);else for(const n of e(o)){const e=o[n];a[n]=b(e)?e(t,i.data,r):e}return Object.assign({},t,a)},t):t}(n,s,r,i):n;return[u(a.map(e=>{var n;switch(e.type){case q:return{type:q,_event:N(e.event)};case X:return function(t,e,i,n){const s={_event:i},o=N(b(t.event)?t.event(e,i.data,s):t.event);let r;if(S(t.delay)){const o=n&&n[t.delay];r=b(o)?o(e,i.data,s):o}else r=b(t.delay)?t.delay(e,i.data,s):t.delay;const a=b(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})}(e,c,s,t.options.delays);case Q:return((t,e,i)=>Object.assign(Object.assign({},t),{value:S(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}))(e,c,s);case it:{const o=null===(n=e.conds.find(e=>{const n=w(e.cond,t.options.guards);return!n||$(t,n,c,s,i)}))||void 0===n?void 0:n.actions;if(!o)return[];const r=Ot(t,i,c,s,at(f(o),t.options.actions));return c=r[1],r[0]}case nt:{const n=e.get(c,s.data);if(!n)return[];const o=Ot(t,i,c,s,at(f(n),t.options.actions));return c=o[1],o[0]}case B:return function(t,e,i){const n=b(t.activity)?t.activity(e,i.data):t.activity,s="string"==typeof n?{id:n}:n;return{type:V.Stop,activity:s}}(e,c,s);default:return rt(e,t.options.actions)}})),c]}function _t(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 jt{constructor(e){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=e.meta||{},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,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,u([...new Set(t.map(t=>t.ownEvents))]);var t}})}static from(t,e){if(t instanceof jt)return t.context!==e?new jt({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 jt({value:t,context:e,_event:st,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new jt(t)}static inert(t,e){if(t instanceof jt){if(!t.actions.length)return t;const i=st;return new jt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return jt.from(t,e)}toStrings(t=this.value,i="."){if(S(t))return[t];const n=e(t);return n.concat(...n.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){return C(this,["configuration","transitions"])}matches(t){return i(t,this.value)}}const Et=[],Nt=(t,e)=>{Et.push(t);const i=e(t);return Et.pop(),i};function Tt(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),toJSON:()=>({id:t})}}function $t(t,e,i){const n=Tt(e);return n.deferred=!0,_(t)&&(n.state=Nt(void 0,()=>(i?t.withContext(i):t).initialState)),n}function kt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Pt(t){return Object.assign(Object.assign({type:Y},t),{toJSON(){const e=C(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:Y,src:kt(t.src)})}})}const Ct={},Vt=t=>"#"===t[0];class It{constructor(t,i,n){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.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 It(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Ct;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=>rt(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>rt(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(S(t.src))return Pt(Object.assign(Object.assign({},t),{id:t.id||t.src,src:t.src}));if(_(t.src)||b(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=>ct(t)),this.transition=this.transition.bind(this)}_init(){this.__cache.transitions||A(this).forEach(t=>t.on)}withConfig(t,e=this.context){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new It(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)},e)}withContext(t){return new It(this.config,this.options,t)}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states: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=mt(b(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(dt(i,{delay:t})),this.onExit.push(pt(i)),i};return(m(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=S(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 jt?t.value:o(t,this.delimiter);if(S(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this.states[i]]}const n=e(i);return n.map(t=>this.getStateNode(t)).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(R([],this.getStateNodes(t.value)));return new jt(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 S(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||(S(u)&&Vt(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=R([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?R(s,t.configuration):s;for(const e of o)F(s,e)||t.entrySet.push(e);for(const e of s)F(o,e)&&!F(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(bt(n.id,n.doneData),bt(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(bt(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=>gt(t)),...t.onEntry])).concat(r.map(ht)),u(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>vt(t))]))];return at(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 jt)s=void 0===i?t:this.resolveState(jt.from(t,i));else{const e=S(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),n=i||this.machine.context;s=this.resolveState(jt.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=R([],this.getStateNodes(s.value)),h=a.configuration.length?R(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=st,s=this.machine.context){const{configuration:o}=t,r=!i||t.transitions.length>0?z(this.machine,o):void 0,a=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,c=i?i.context:s,h=this.getActions(t,c,n,i),d=i?Object.assign({},i.activities):{};for(const t of h)t.type===U?d[t.activity.id||t.activity.type]=t:t.type===B&&(d[t.activity.id||t.activity.type]=!1);const[u,l]=Ot(this,i,c,n,h),[f,g]=v(u,t=>t.type===q||t.type===X&&t.to===I.Internal),m=u.filter(t=>{var e;return t.type===U&&(null===(e=t.activity)||void 0===e?void 0:e.type)===Y}).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?$t(r,t.id,a):Tt(t.id);return c.meta=t,c}(e.activity,this.machine,l,n),t),i?Object.assign({},i.children):{}),b=r?t.configuration:i?i.configuration:[],w=b.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{}),x=J(b,this),O=new jt({value:r||i.value,context:l,_event:n,_sessionid:i?i._sessionid:null,historyValue:r?a?(_=a,j=r,{current:j,states:y(_,j)}):void 0:i?i.historyValue:void 0,history:!r||t.source?i:void 0,actions:r?g:[],activities:r?d:i?i.activities:{},meta:r?w:i?i.meta:void 0,events:[],configuration:b,transitions:t.transitions,children:m,done:x});var _,j;const E=c!==l;O.changed=n.name===et||E;const{history:N}=O;if(N&&delete N.history,!r)return O;let T=O;if(!x){for((this._transient||o.some(t=>t._transient))&&(T=this.resolveRaisedTransition(T,{type:G},n));f.length;){const t=f.shift();T=this.resolveRaisedTransition(T,t._event,n)}}const $=T.changed||(N?!!T.actions.length||E||typeof N.value!=typeof T.value||!function t(i,n){if(i===n)return!0;if(void 0===i||void 0===n)return!1;if(S(i)||S(n))return i===n;const s=e(i),o=e(n);return s.length===o.length&&s.every(e=>t(i[e],n[e]))}(T.value,N.value):void 0);return T.changed=$,T.history=N,T}getStateNode(t){if(Vt(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=Vt(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&&Vt(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||Ct;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Ct);case"compound":if(S(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):Ct):this.initialStateValue||{};default:return t||Ct}}getResolvedPath(t){if(Vt(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||Ct,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=L(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)}get initialState(){this._init();const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=S(e.target)&&Vt(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(L(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=S(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 S(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(!S(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=>S(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:at(f(t.actions)),cond:w(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=C(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(bt(this.id)),this.config.onDone):[],s=u(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...T(String(St(t.id)),t.onDone)),t.onError&&e.push(...T(String(wt(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 Lt(t,e,i=t.context){const n="function"==typeof i?i():i;return new It(t,e,n)}function Dt(t,e){const i="function"==typeof t.context?t.context():t.context;return new It(t,e,i)}const At={deferEvents:!1};class Rt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},At),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const Mt=new Map;let zt=0;const Ft={bookId:()=>"x:"+zt++,register:(t,e)=>(Mt.set(t,e),t),get:t=>Mt.get(t),free(t){Mt.delete(t)}};function Jt(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}const Ut={sync:!1,autoForward:!1};var Bt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Bt||(Bt={}));class qt{constructor(t,e=qt.defaultOptions){this.machine=t,this.scheduler=new Rt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=Bt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(m(t))return this.batch(t),this.state;const i=N(E(t,e));if(this.status===Bt.Stopped)return this.state;if(this.status!==Bt.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===I.Parent||this.parent.id===e),n=i?this.parent:S(e)?this.children.get(e)||Ft.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===tt?""+wt(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({},qt.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 Rt({deferEvents:this.options.deferEvents}),this.sessionId=Ft.bookId()}get initialState(){return this._initialState?this._initialState:Nt(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(St(this.id,n));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===Bt.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===Bt.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===Bt.Running)return this;Ft.register(this.sessionId,this),this.initialized=!0,this.status=Bt.Running;const e=void 0===t?this.initialState:Nt(this,()=>{return!S(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState(jt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,st)}),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=>{b(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=Bt.Stopped,Ft.free(this.sessionId),this}batch(t){if(this.status===Bt.NotStarted&&this.options.deferEvents);else if(this.status!==Bt.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=Nt(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>_t(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(Z)&&!this.state.nextEvents.some(t=>0===t.indexOf(Z)))throw e.data.data;return Nt(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||ot(t.type,i),r=b(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 X:const e=t;if("number"==typeof e.delay)return void this.defer(e);e.to?this.sendTo(e._event,e.to):this.send(e._event);break;case H:this.cancel(t.sendId);break;case U:{const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===V.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,h=b(i)?i(n,s.data,{data:c,src:t}):i;g(h)?this.spawnPromise(Promise.resolve(h),o):b(h)?this.spawnCallback(h,o):x(h)?this.spawnObservable(h,o):_(h)&&this.spawnMachine(c?h.withContext(c):h,{id:o,autoForward:a})}else this.spawnActivity(e);break}case B:this.stopChild(t.activity.id);break;case Q:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}removeChild(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),b(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(b(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(n=t)&&"id"in n)return this.spawnActor(t);if(x(t))return this.spawnObservable(t,e);if(_(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var n}spawnMachine(t,e={}){const i=new qt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Ut),e);n.sync&&i.onTransition(t=>{this.send(et,{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}spawnPromise(t,e){let i=!1;t.then(t=>{i||(this.removeChild(e),this.send(N(St(e,t),{origin:e})))},t=>{if(!i){this.removeChild(e);const i=wt(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 n={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=function(t,e,i){if("object"==typeof t)return t;const n=()=>{};return{next:t,error:e||n,complete:i||n}}(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:()=>{i=!0},toJSON:()=>({id:e})};return this.children.set(e,n),n}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set,o=t=>{s.forEach(e=>e(t)),i||this.send(N(t,{origin:e}))};let r;try{r=t(o,t=>{n.add(t)})}catch(t){this.send(wt(e,t))}if(g(r))return this.spawnPromise(r,e);const a={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>(s.add(t),{unsubscribe:()=>{s.delete(t)}}),stop:()=>{i=!0,b(r)&&r()},toJSON:()=>({id:e})};return this.children.set(e,a),a}spawnObservable(t,e){const i=t.subscribe(t=>{this.send(N(t,{origin:e}))},t=>{this.removeChild(e),this.send(N(wt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(N(St(e),{origin:e}))}),n={id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>i.unsubscribe(),toJSON:()=>({id:e})};return this.children.set(e,n),n}spawnActor(t){return this.children.set(t.id,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,toJSON:()=>({id:t})})}attachDev(){const t=Jt();if(this.options.devTools&&t&&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)}}toJSON(){return{id:this.id}}[O](){return this}}qt.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),qt.interpret=Ht;function Xt(t,e){const i=(t=>S(t)?Object.assign(Object.assign({},Ut),{name:t}):Object.assign(Object.assign(Object.assign({},Ut),{name:j()}),t))(e);return(e=>e?e.spawn(t,i.name,i):$t(t,i.name))(Et[Et.length-1])}function Ht(t,e){return new qt(t,e)}function Gt(t,e,i){const n=jt.from(t,t instanceof jt?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function Kt(t){return t}const Qt={raise:ht,send:dt,sendParent:ut,sendUpdate:lt,log:function(t=ft,e){return{type:Q,label:e,expr:t}},cancel:pt,start:gt,stop:vt,assign:yt,after:mt,done:bt,respond:function(t,e){return dt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:xt,escalate:function(t,e){return ut((e,i,n)=>({type:tt,data:b(t)?t(e,i,n):t}),Object.assign(Object.assign({},e),{to:I.Parent}))},choose:function(t){return{type:V.Choose,conds:t}},pure:function(t){return{type:V.Pure,get:t}}};export{V as ActionTypes,qt as Interpreter,Bt as InterpreterStatus,Lt as Machine,I as SpecialTargets,jt as State,It as StateNode,Qt as actions,yt as assign,Dt as createMachine,Kt as createSchema,St as doneInvoke,xt as forwardTo,Ht as interpret,P as mapState,Gt as matchState,i as matchesState,dt as send,ut as sendParent,lt as sendUpdate,Xt as spawn};
|
|
15
|
+
***************************************************************************** */function C(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(i[s[n]]=t[s[n]])}return i}var V,I;!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"}(V||(V={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(I||(I={}));const L=t=>"atomic"===t.type||"final"===t.type;function D(t){return e(t.states).map(e=>t.states[e])}function A(t){const e=[t];return L(t)?e:e.concat(u(D(t).map(A)))}function R(t,e){const i=M(new Set(t)),s=new Set(e);for(const t of s){let e=t.parent;for(;e&&!s.has(e);)s.add(e),e=e.parent}const n=M(s);for(const t of s)if("compound"!==t.type||n.get(t)&&n.get(t).length){if("parallel"===t.type)for(const e of D(t))"history"!==e.type&&(s.has(e)||(s.add(e),i.get(e)?i.get(e).forEach(t=>s.add(t)):e.initialStateNodes.forEach(t=>s.add(t))))}else i.get(t)?i.get(t).forEach(t=>s.add(t)):t.initialStateNodes.forEach(t=>s.add(t));for(const t of s){let e=t.parent;for(;e&&!s.has(e);)s.add(e),e=e.parent}return s}function M(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function z(t,e){return function t(e,i){const s=i.get(e);if(!s)return{};if("compound"===e.type){const t=s[0];if(!t)return{};if(L(t))return t.key}const n={};return s.forEach(e=>{n[e.key]=t(e,i)}),n}(t,M(R([t],e)))}function F(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&&F(t,e)):"parallel"===e.type&&D(e).every(e=>J(t,e))}const U=V.Start,B=V.Stop,q=V.Raise,X=V.Send,H=V.Cancel,G=V.NullEvent,K=V.Assign,Q=(V.After,V.DoneState,V.Log),W=V.Init,Y=V.Invoke,Z=(V.ErrorExecution,V.ErrorPlatform),tt=V.ErrorCustom,et=V.Update,it=V.Choose,st=V.Pure,nt=N({type:W});function ot(t,e){return e&&e[t]||void 0}function rt(t,e){let i;if(S(t)||"number"==typeof t){const s=ot(t,e);i=b(s)?{type:t,exec:s}:s||{type:t,exec:void 0}}else if(b(t))i={type:t.name||t.toString(),exec:t};else{const s=ot(t.type,e);if(b(s))i=Object.assign(Object.assign({},t),{exec:s});else if(s){const e=s.type||t.type;i=Object.assign(Object.assign(Object.assign({},s),t),{type:e})}else i=t}return Object.defineProperty(i,"toString",{value:()=>i.type,enumerable:!1,configurable:!0}),i}const at=(t,e)=>{if(!t)return[];return(m(t)?t:[t]).map(t=>rt(t,e))};function ct(t){const e=rt(t);return Object.assign(Object.assign({id:S(t)?t:e.id},e),{type:e.type})}function ht(t){return S(t)?{type:q,event:t}:dt(t,{to:I.Internal})}function dt(t,e){return{to:e?e.to:void 0,type:X,event:b(t)?t:E(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:b(t)?t.name:s(t)}}function ut(t,e){return dt(t,Object.assign(Object.assign({},e),{to:I.Parent}))}function lt(){return ut(et)}const ft=(t,e)=>({context:t,event:e});const pt=t=>({type:H,sendId:t});function gt(t){const e=ct(t);return{type:V.Start,activity:e,exec:void 0}}function vt(t){const e=b(t)?t:ct(t);return{type:V.Stop,activity:e,exec:void 0}}const yt=t=>({type:K,assignment:t});function mt(t,e){const i=e?"#"+e:"";return`${V.After}(${t})${i}`}function bt(t,e){const i=`${V.DoneState}.${t}`,s={type:i,data:e,toString:()=>i};return s}function St(t,e){const i=`${V.DoneInvoke}.${t}`,s={type:i,data:e,toString:()=>i};return s}function wt(t,e){const i=`${V.ErrorPlatform}.${t}`,s={type:i,data:e,toString:()=>i};return s}function xt(t,e){return dt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function Ot(t,i,s,n,o){const[r,a]=v(o,t=>t.type===K);let c=r.length?function(t,i,s,n){return t?s.reduce((t,s)=>{const{assignment:o}=s,r={state:n,action:s,_event:i};let a={};if(b(o))a=o(t,i.data,r);else for(const s of e(o)){const e=o[s];a[s]=b(e)?e(t,i.data,r):e}return Object.assign({},t,a)},t):t}(s,n,r,i):s;return[u(a.map(e=>{var s;switch(e.type){case q:return{type:q,_event:N(e.event)};case X:return function(t,e,i,s){const n={_event:i},o=N(b(t.event)?t.event(e,i.data,n):t.event);let r;if(S(t.delay)){const o=s&&s[t.delay];r=b(o)?o(e,i.data,n):o}else r=b(t.delay)?t.delay(e,i.data,n):t.delay;const a=b(t.to)?t.to(e,i.data,n):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}(e,c,n,t.options.delays);case Q:return((t,e,i)=>Object.assign(Object.assign({},t),{value:S(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}))(e,c,n);case it:{const o=null===(s=e.conds.find(e=>{const s=w(e.cond,t.options.guards);return!s||$(t,s,c,n,i)}))||void 0===s?void 0:s.actions;if(!o)return[];const r=Ot(t,i,c,n,at(f(o),t.options.actions));return c=r[1],r[0]}case st:{const s=e.get(c,n.data);if(!s)return[];const o=Ot(t,i,c,n,at(f(s),t.options.actions));return c=o[1],o[0]}case B:return function(t,e,i){const s=b(t.activity)?t.activity(e,i.data):t.activity,n="string"==typeof s?{id:s}:s;return{type:V.Stop,activity:n}}(e,c,n);default:return rt(e,t.options.actions)}})),c]}function _t(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 jt{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=e.meta||{},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=e.tags)&&void 0!==i?i:new Set,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,u([...new Set(t.map(t=>t.ownEvents))]);var t}})}static from(t,e){if(t instanceof jt)return t.context!==e?new jt({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 jt({value:t,context:e,_event:nt,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new jt(t)}static inert(t,e){if(t instanceof jt){if(!t.actions.length)return t;const i=nt;return new jt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return jt.from(t,e)}toStrings(t=this.value,i="."){if(S(t))return[t];const s=e(t);return s.concat(...s.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){const{configuration:t,transitions:e,tags:i}=this,s=C(this,["configuration","transitions","tags"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return i(t,this.value)}hasTag(t){return this.tags.has(t)}}const Et=[],Nt=(t,e)=>{Et.push(t);const i=e(t);return Et.pop(),i};function Tt(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),toJSON:()=>({id:t})}}function $t(t,e,i){const s=Tt(e);return s.deferred=!0,_(t)&&(s.state=Nt(void 0,()=>(i?t.withContext(i):t).initialState)),s}function kt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Pt(t){return Object.assign(Object.assign({type:Y},t),{toJSON(){const e=C(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:Y,src:kt(t.src)})}})}const Ct={},Vt=t=>"#"===t[0];class It{constructor(t,i,s){var n;this.config=t,this.context=s,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},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!==(n=this.config.schema)&&void 0!==n?n:{},this.initial=this.config.initial,this.states=this.config.states?a(this.config.states,(t,e)=>{const i=new It(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Ct;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=>rt(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>rt(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(S(t.src))return Pt(Object.assign(Object.assign({},t),{id:t.id||t.src,src:t.src}));if(_(t.src)||b(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=>ct(t)),this.transition=this.transition.bind(this),this.tags=f(this.config.tags)}_init(){this.__cache.transitions||A(this).forEach(t=>t.on)}withConfig(t,e=this.context){const{actions:i,activities:s,guards:n,services:o,delays:r}=this.options;return new It(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},s),t.activities),guards:Object.assign(Object.assign({},n),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},e)}withContext(t){return new It(this.config,this.options,t)}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states: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 s=i.eventType===t;return e?s:s||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const i=(t,e)=>{const i=mt(b(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(dt(i,{delay:t})),this.onExit.push(pt(i)),i};return(m(t)?t.map((t,e)=>{const s=i(t.delay,e);return Object.assign(Object.assign({},t),{event:s})}):u(e(t).map((e,s)=>{const n=t[e],o=S(n)?{target:n}:n,r=isNaN(+e)?e:+e,a=i(r,s);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 jt?t.value:o(t,this.delimiter);if(S(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this.states[i]]}const s=e(i);return s.map(t=>this.getStateNode(t)).concat(s.reduce((t,e)=>{const s=this.getStateNode(e).getStateNodes(i[e]);return t.concat(s)},[]))}handles(t){const e=s(t);return this.events.includes(e)}resolveState(t){const e=Array.from(R([],this.getStateNodes(t.value)));return new jt(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e,done:J(e,this)}))}transitionLeafNode(t,e,i){const s=this.getStateNode(t).next(e,i);return s&&s.transitions.length?s:this.next(e,i)}transitionCompoundNode(t,i,s){const n=e(t),o=this.getStateNode(n[0])._transition(t[n[0]],i,s);return o&&o.transitions.length?o:this.next(i,s)}transitionParallelNode(t,i,s){const n={};for(const o of e(t)){const e=t[o];if(!e)continue;const r=this.getStateNode(o)._transition(e,i,s);r&&(n[o]=r)}const o=e(n).map(t=>n[t]),r=u(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,s);const a=u(o.map(t=>t.entrySet)),c=u(e(n).map(t=>n[t].configuration));return{transitions:r,entrySet:a,exitSet:u(o.map(t=>t.exitSet)),configuration:c,source:i,actions:u(e(n).map(t=>n[t].actions))}}_transition(t,i,s){return S(t)?this.transitionLeafNode(t,i,s):1===e(t).length?this.transitionCompoundNode(t,i,s):this.transitionParallelNode(t,i,s)}next(t,e){const s=e.name,n=[];let r,a=[];for(const c of this.getCandidates(s)){const{cond:d,in:u}=c,l=t.context,f=!u||(S(u)&&Vt(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 '${s}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==c.target&&(a=c.target),n.push(...c.actions),r=c;break}}if(!r)return;if(!a.length)return{transitions:[r],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:n};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:n}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,s){const n=R([],s?this.getStateNodes(s.value):[this]),o=t.configuration.length?R(n,t.configuration):n;for(const e of o)F(n,e)||t.entrySet.push(e);for(const e of n)F(o,e)&&!F(t.exitSet,e.parent)||t.exitSet.push(e);t.source||(t.exitSet=[],t.entrySet.push(this));const r=u(t.entrySet.map(s=>{const n=[];if("final"!==s.type)return n;const o=s.parent;if(!o.parent)return n;n.push(bt(s.id,s.doneData),bt(o.id,s.doneData?p(s.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&D(r).every(e=>J(t.configuration,e))&&n.push(bt(r.id)),n}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,d]=[u(Array.from(a).map(t=>[...t.activities.map(t=>gt(t)),...t.onEntry])).concat(r.map(ht)),u(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>vt(t))]))];return at(d.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const s=N(e);let n;if(t instanceof jt)n=void 0===i?t:this.resolveState(jt.from(t,i));else{const e=S(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),s=i||this.machine.context;n=this.resolveState(jt.from(e,s))}if(this.strict&&!this.events.includes(s.name)&&(o=s.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${s.name}'`);var o;const a=this._transition(n.value,n,s)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:n,actions:[]},c=R([],this.getStateNodes(n.value)),h=a.configuration.length?R(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,n,s)}resolveRaisedTransition(t,e,i){const s=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...s),t}resolveTransition(t,i,s=nt,n=this.machine.context){const{configuration:o}=t,r=!i||t.transitions.length>0?z(this.machine,o):void 0,a=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,c=i?i.context:n,h=this.getActions(t,c,s,i),d=i?Object.assign({},i.activities):{};for(const t of h)t.type===U?d[t.activity.id||t.activity.type]=t:t.type===B&&(d[t.activity.id||t.activity.type]=!1);const[l,f]=Ot(this,i,c,s,h),[g,m]=v(l,t=>t.type===q||t.type===X&&t.to===I.Internal),b=l.filter(t=>{var e;return t.type===U&&(null===(e=t.activity)||void 0===e?void 0:e.type)===Y}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,s){var n;const o=k(t.src),r=null===(n=null==e?void 0:e.options.services)||void 0===n?void 0:n[o.type],a=t.data?p(t.data,i,s):void 0,c=r?$t(r,t.id,a):Tt(t.id);return c.meta=t,c}(e.activity,this.machine,f,s),t),i?Object.assign({},i.children):{}),w=r?t.configuration:i?i.configuration:[],x=w.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{}),O=J(w,this),_=new jt({value:r||i.value,context:f,_event:s,_sessionid:i?i._sessionid:null,historyValue:r?a?(j=a,E=r,{current:E,states:y(j,E)}):void 0:i?i.historyValue:void 0,history:!r||t.source?i:void 0,actions:r?m:[],activities:r?d:i?i.activities:{},meta:r?x:i?i.meta:void 0,events:[],configuration:w,transitions:t.transitions,children:b,done:O,tags:null==i?void 0:i.tags});var j,E;const N=c!==f;_.changed=s.name===et||N;const{history:T}=_;if(T&&delete T.history,!r)return _;let $=_;if(!O){for((this._transient||o.some(t=>t._transient))&&($=this.resolveRaisedTransition($,{type:G},s));g.length;){const t=g.shift();$=this.resolveRaisedTransition($,t._event,s)}}const P=$.changed||(T?!!$.actions.length||N||typeof T.value!=typeof $.value||!function t(i,s){if(i===s)return!0;if(void 0===i||void 0===s)return!1;if(S(i)||S(s))return i===s;const n=e(i),o=e(s);return n.length===o.length&&n.every(e=>t(i[e],s[e]))}($.value,T.value):void 0);return $.changed=P,$.history=T,$.tags=new Set(u($.configuration.map(t=>t.tags))),$}getStateNode(t){if(Vt(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=Vt(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&&Vt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=n(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||Ct;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Ct);case"compound":if(S(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):Ct):this.initialStateValue||{};default:return t||Ct}}getResolvedPath(t){if(Vt(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return n(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||Ct,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=L(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=S(e.target)&&Vt(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(L(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 s=this.getStateNode(e);if("history"===s.type)return s.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(e(this.states).length)return{current:t||this.initialStateValue,states:c(this.states,(e,i)=>{if(!t)return e.historyValue();const s=S(t)?void 0:t[i];return e.historyValue(s||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?u(d(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(s=e.path,n="states",t=>{let e=t;for(const t of s)e=e[n][t];return e})(t).current;var s,n;return S(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 s of e(t)){const e=t[s];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(!S(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=>S(t)&&t[0]===this.delimiter),{guards:s}=this.machine.options,n=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:at(f(t.actions)),cond:w(t.cond,s),target:n,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,s="*",n=i[s],o=void 0===n?[]:n,r=C(i,[s+""]);t=u(e(r).map(t=>T(t,r[t])).concat(T("*",o)))}else t=[];const i=this.config.always?T("",this.config.always):[],s=this.config.onDone?T(String(bt(this.id)),this.config.onDone):[],n=u(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...T(String(St(t.id)),t.onDone)),t.onError&&e.push(...T(String(wt(t.id)),t.onError)),e})),o=this.after,r=u([...s,...n,...t,...i].map(t=>f(t).map(t=>this.formatTransition(t))));for(const t of o)r.push(t);return r}}function Lt(t,e,i=t.context){const s="function"==typeof i?i():i;return new It(t,e,s)}function Dt(t,e){const i="function"==typeof t.context?t.context():t.context;return new It(t,e,i)}const At={deferEvents:!1};class Rt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},At),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const Mt=new Map;let zt=0;const Ft={bookId:()=>"x:"+zt++,register:(t,e)=>(Mt.set(t,e),t),get:t=>Mt.get(t),free(t){Mt.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)}const Bt={sync:!1,autoForward:!1};var qt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(qt||(qt={}));class Xt{constructor(t,e=Xt.defaultOptions){this.machine=t,this.scheduler=new Rt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=qt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(m(t))return this.batch(t),this.state;const i=N(E(t,e));if(this.status===qt.Stopped)return this.state;if(this.status!==qt.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===I.Parent||this.parent.id===e),s=i?this.parent:S(e)?this.children.get(e)||Ft.get(e):(n=e)&&"function"==typeof n.send?e:void 0;var n;if(s)"machine"in s?s.send(Object.assign(Object.assign({},t),{name:t.name===tt?""+wt(this.id):t.name,origin:this.sessionId})):s.send(t.data);else if(!i)throw new Error(`Unable to send event to child '${e}' from service '${this.id}'.`)};const i=Object.assign(Object.assign({},Xt.defaultOptions),e),{clock:s,logger:n,parent:o,id:r}=i,a=void 0!==r?r:t.id;this.id=a,this.logger=n,this.clock=s,this.parent=o,this.options=i,this.scheduler=new Rt({deferEvents:this.options.deferEvents}),this.sessionId=Ft.bookId()}get initialState(){return this._initialState?this._initialState:Nt(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),s=i&&i.doneData?p(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(St(this.id,s));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===qt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>{}};let s,n=i;return"function"==typeof t?s=t:(s=t.next.bind(t),n=t.complete.bind(t)),this.listeners.add(s),this.status===qt.Running&&s(this.state),n&&this.onDone(n),{unsubscribe:()=>{s&&this.listeners.delete(s),n&&this.doneListeners.delete(n)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this.status===qt.Running)return this;Ft.register(this.sessionId,this),this.initialized=!0,this.status=qt.Running;const e=void 0===t?this.initialState:Nt(this,()=>{return!S(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState(jt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,nt)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);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=>{b(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=qt.Stopped,Ft.free(this.sessionId),this}batch(t){if(this.status===qt.NotStarted&&this.options.deferEvents);else if(this.status!==qt.Running)throw new Error(`${t.length} event(s) were sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.`);this.scheduler.schedule(()=>{let e=this.state,i=!1;const s=[];for(const n of t){const t=N(n);this.forward(t),e=Nt(this,()=>this.machine.transition(e,t)),s.push(...e.actions.map(t=>_t(t,e))),i=i||!!e.changed}e.changed=i,e.actions=s,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(Z)&&!this.state.nextEvents.some(t=>0===t.indexOf(Z)))throw e.data.data;return Nt(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:s,_event:n}=e,o=t.exec||ot(t.type,i),r=b(o)?o:o?o.exec:t.exec;if(r)try{return r(s,n.data,{action:t,state:this.state,_event:n})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case X:const e=t;if("number"==typeof e.delay)return void this.defer(e);e.to?this.sendTo(e._event,e.to):this.send(e._event);break;case H:this.cancel(t.sendId);break;case U:{const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===V.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,s,n):void 0,h=b(i)?i(s,n.data,{data:c,src:t}):i;g(h)?this.spawnPromise(Promise.resolve(h),o):b(h)?this.spawnCallback(h,o):x(h)?this.spawnObservable(h,o):_(h)&&this.spawnMachine(c?h.withContext(c):h,{id:o,autoForward:a})}else this.spawnActivity(e);break}case B:this.stopChild(t.activity.id);break;case Q:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}removeChild(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),b(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(b(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);if(x(t))return this.spawnObservable(t,e);if(_(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var s}spawnMachine(t,e={}){const i=new Xt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),s=Object.assign(Object.assign({},Bt),e);s.sync&&i.onTransition(t=>{this.send(et,{state:t,id:i.id})});const n=i;return this.children.set(i.id,n),s.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(N(t,{origin:i.id}))}).start(),n}spawnPromise(t,e){let i=!1;t.then(t=>{i||(this.removeChild(e),this.send(N(St(e,t),{origin:e})))},t=>{if(!i){this.removeChild(e);const i=wt(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,s)=>{const n=function(t,e,i){if("object"==typeof t)return t;const s=()=>{};return{next:t,error:e||s,complete:i||s}}(e,i,s);let o=!1;return t.then(t=>{o||(n.next(t),o||n.complete())},t=>{o||n.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{i=!0},toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const s=new Set,n=new Set,o=t=>{n.forEach(e=>e(t)),i||this.send(N(t,{origin:e}))};let r;try{r=t(o,t=>{s.add(t)})}catch(t){this.send(wt(e,t))}if(g(r))return this.spawnPromise(r,e);const a={id:e,send:t=>s.forEach(e=>e(t)),subscribe:t=>(n.add(t),{unsubscribe:()=>{n.delete(t)}}),stop:()=>{i=!0,b(r)&&r()},toJSON:()=>({id:e})};return this.children.set(e,a),a}spawnObservable(t,e){const i=t.subscribe(t=>{this.send(N(t,{origin:e}))},t=>{this.removeChild(e),this.send(N(wt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(N(St(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,s)=>t.subscribe(e,i,s),stop:()=>i.unsubscribe(),toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnActor(t){return this.children.set(t.id,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,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}}Xt.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),Xt.interpret=Gt;function Ht(t,e){const i=(t=>S(t)?Object.assign(Object.assign({},Bt),{name:t}):Object.assign(Object.assign(Object.assign({},Bt),{name:j()}),t))(e);return(e=>e?e.spawn(t,i.name,i):$t(t,i.name))(Et[Et.length-1])}function Gt(t,e){return new Xt(t,e)}function Kt(t,e,i){const s=jt.from(t,t instanceof jt?t.context:void 0);for(const[t,i]of e)if(s.matches(t))return i(s);return i(s)}function Qt(t){return t}const Wt={raise:ht,send:dt,sendParent:ut,sendUpdate:lt,log:function(t=ft,e){return{type:Q,label:e,expr:t}},cancel:pt,start:gt,stop:vt,assign:yt,after:mt,done:bt,respond:function(t,e){return dt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:xt,escalate:function(t,e){return ut((e,i,s)=>({type:tt,data:b(t)?t(e,i,s):t}),Object.assign(Object.assign({},e),{to:I.Parent}))},choose:function(t){return{type:V.Choose,conds:t}},pure:function(t){return{type:V.Pure,get:t}}};export{V as ActionTypes,Xt as Interpreter,qt as InterpreterStatus,Lt as Machine,I as SpecialTargets,jt as State,It as StateNode,Wt as actions,yt as assign,Dt as createMachine,Qt as createSchema,St as doneInvoke,xt as forwardTo,Gt as interpret,P as mapState,Kt as matchState,i as matchesState,dt as send,ut as sendParent,lt as sendUpdate,Ht as spawn};
|
package/es/State.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
50
50
|
* An object mapping actor IDs to spawned actors/invoked services.
|
|
51
51
|
*/
|
|
52
52
|
children: Record<string, ActorRef<any>>;
|
|
53
|
+
tags: Set<string>;
|
|
53
54
|
/**
|
|
54
55
|
* Creates a new State instance for the given `stateValue` and `context`.
|
|
55
56
|
* @param stateValue
|
|
@@ -86,7 +87,9 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
86
87
|
* @param delimiter The character(s) that separate each subpath in the string state node path.
|
|
87
88
|
*/
|
|
88
89
|
toStrings(stateValue?: StateValue, delimiter?: string): string[];
|
|
89
|
-
toJSON(): Pick<this, Exclude<keyof this, "configuration" | "transitions"
|
|
90
|
+
toJSON(): Pick<this, Exclude<keyof this, "configuration" | "transitions" | "tags">> & {
|
|
91
|
+
tags: string[];
|
|
92
|
+
};
|
|
90
93
|
/**
|
|
91
94
|
* Whether the current state value is a subset of the given parent state value.
|
|
92
95
|
* @param parentStateValue
|
|
@@ -97,5 +100,10 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
97
100
|
} extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate> & {
|
|
98
101
|
value: TSV;
|
|
99
102
|
};
|
|
103
|
+
/**
|
|
104
|
+
* Whether the current state configuration has a state node with the specified `tag`.
|
|
105
|
+
* @param tag
|
|
106
|
+
*/
|
|
107
|
+
hasTag(tag: string): boolean;
|
|
100
108
|
}
|
|
101
109
|
//# sourceMappingURL=State.d.ts.map
|
package/es/State.js
CHANGED
|
@@ -68,6 +68,8 @@ function () {
|
|
|
68
68
|
function State(config) {
|
|
69
69
|
var _this = this;
|
|
70
70
|
|
|
71
|
+
var _a;
|
|
72
|
+
|
|
71
73
|
this.actions = [];
|
|
72
74
|
this.activities = EMPTY_ACTIVITY_MAP;
|
|
73
75
|
this.meta = {};
|
|
@@ -89,6 +91,7 @@ function () {
|
|
|
89
91
|
this.transitions = config.transitions;
|
|
90
92
|
this.children = config.children;
|
|
91
93
|
this.done = !!config.done;
|
|
94
|
+
this.tags = (_a = config.tags) !== null && _a !== void 0 ? _a : new Set();
|
|
92
95
|
Object.defineProperty(this, 'nextEvents', {
|
|
93
96
|
get: function () {
|
|
94
97
|
return nextEvents(_this.configuration);
|
|
@@ -215,9 +218,12 @@ function () {
|
|
|
215
218
|
var _a = this,
|
|
216
219
|
configuration = _a.configuration,
|
|
217
220
|
transitions = _a.transitions,
|
|
218
|
-
|
|
221
|
+
tags = _a.tags,
|
|
222
|
+
jsonValues = __rest(_a, ["configuration", "transitions", "tags"]);
|
|
219
223
|
|
|
220
|
-
return jsonValues
|
|
224
|
+
return __assign(__assign({}, jsonValues), {
|
|
225
|
+
tags: Array.from(tags)
|
|
226
|
+
});
|
|
221
227
|
};
|
|
222
228
|
/**
|
|
223
229
|
* Whether the current state value is a subset of the given parent state value.
|
|
@@ -228,6 +234,15 @@ function () {
|
|
|
228
234
|
State.prototype.matches = function (parentStateValue) {
|
|
229
235
|
return matchesState(parentStateValue, this.value);
|
|
230
236
|
};
|
|
237
|
+
/**
|
|
238
|
+
* Whether the current state configuration has a state node with the specified `tag`.
|
|
239
|
+
* @param tag
|
|
240
|
+
*/
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
State.prototype.hasTag = function (tag) {
|
|
244
|
+
return this.tags.has(tag);
|
|
245
|
+
};
|
|
231
246
|
|
|
232
247
|
return State;
|
|
233
248
|
}();
|
package/es/StateNode.d.ts
CHANGED
package/es/StateNode.js
CHANGED
|
@@ -78,6 +78,7 @@ function () {
|
|
|
78
78
|
delayedTransitions: undefined
|
|
79
79
|
};
|
|
80
80
|
this.idMap = {};
|
|
81
|
+
this.tags = [];
|
|
81
82
|
this.options = Object.assign(createDefaultOptions(), options);
|
|
82
83
|
this.parent = this.options._parent;
|
|
83
84
|
this.key = this.config.key || this.options._key || this.config.id || '(machine)';
|
|
@@ -183,7 +184,8 @@ function () {
|
|
|
183
184
|
this.activities = toArray(this.config.activities).concat(this.invoke).map(function (activity) {
|
|
184
185
|
return toActivityDefinition(activity);
|
|
185
186
|
});
|
|
186
|
-
this.transition = this.transition.bind(this);
|
|
187
|
+
this.transition = this.transition.bind(this);
|
|
188
|
+
this.tags = toArray(this.config.tags); // TODO: this is the real fix for initialization once
|
|
187
189
|
// state node getters are deprecated
|
|
188
190
|
// if (!this.parent) {
|
|
189
191
|
// this._init();
|
|
@@ -924,7 +926,8 @@ function () {
|
|
|
924
926
|
configuration: resolvedConfiguration,
|
|
925
927
|
transitions: stateTransition.transitions,
|
|
926
928
|
children: children,
|
|
927
|
-
done: isDone
|
|
929
|
+
done: isDone,
|
|
930
|
+
tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags
|
|
928
931
|
});
|
|
929
932
|
var didUpdateContext = currentContext !== updatedContext;
|
|
930
933
|
nextState.changed = _event.name === update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks
|
|
@@ -963,6 +966,9 @@ function () {
|
|
|
963
966
|
maybeNextState.changed = changed; // Preserve original history after raised events
|
|
964
967
|
|
|
965
968
|
maybeNextState.history = history;
|
|
969
|
+
maybeNextState.tags = new Set(flatten(maybeNextState.configuration.map(function (sn) {
|
|
970
|
+
return sn.tags;
|
|
971
|
+
})));
|
|
966
972
|
return maybeNextState;
|
|
967
973
|
};
|
|
968
974
|
/**
|
|
@@ -1122,6 +1128,9 @@ function () {
|
|
|
1122
1128
|
}
|
|
1123
1129
|
|
|
1124
1130
|
initialStateValue = isLeafNode(this.states[this.initial]) ? this.initial : (_a = {}, _a[this.initial] = this.states[this.initial].initialStateValue, _a);
|
|
1131
|
+
} else {
|
|
1132
|
+
// The finite state value of a machine without child states is just an empty object
|
|
1133
|
+
initialStateValue = {};
|
|
1125
1134
|
}
|
|
1126
1135
|
|
|
1127
1136
|
this.__cache.initialStateValue = initialStateValue;
|
package/es/devTools.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
|
|
3
2
|
function getGlobal() {
|
|
4
3
|
if (typeof self !== 'undefined') {
|
|
5
4
|
return self;
|
|
@@ -27,7 +26,7 @@ function getDevTools() {
|
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
function registerService(service) {
|
|
30
|
-
if (
|
|
29
|
+
if (!getGlobal()) {
|
|
31
30
|
return;
|
|
32
31
|
}
|
|
33
32
|
|
package/es/model.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ declare type Compute<A extends any> = {
|
|
|
5
5
|
[K in keyof A]: A[K];
|
|
6
6
|
} & unknown;
|
|
7
7
|
declare type Prop<T, K> = K extends keyof T ? T[K] : never;
|
|
8
|
-
export interface Model<TContext, TEvent extends EventObject, TModelCreators =
|
|
8
|
+
export interface Model<TContext, TEvent extends EventObject, TModelCreators = void> {
|
|
9
9
|
initialContext: TContext;
|
|
10
10
|
assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, ExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, ExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, ExtractEvent<TEvent, TEventType>>;
|
|
11
11
|
events: Prop<TModelCreators, 'events'>;
|
|
@@ -33,7 +33,7 @@ declare type FinalModelCreators<Self> = {
|
|
|
33
33
|
declare type EventFromEventCreators<EventCreators> = {
|
|
34
34
|
[K in keyof EventCreators]: EventCreators[K] extends AnyFunction ? ReturnType<EventCreators[K]> : never;
|
|
35
35
|
}[keyof EventCreators];
|
|
36
|
-
export declare function createModel<TContext, TEvent extends EventObject>(initialContext: TContext): Model<TContext, TEvent,
|
|
36
|
+
export declare function createModel<TContext, TEvent extends EventObject>(initialContext: TContext): Model<TContext, TEvent, void>;
|
|
37
37
|
export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<EventFromEventCreators<Prop<TFinalModelCreators, 'events'>>, EventObject>, TFinalModelCreators>;
|
|
38
38
|
export {};
|
|
39
39
|
//# sourceMappingURL=model.d.ts.map
|
package/es/types.d.ts
CHANGED
|
@@ -134,7 +134,7 @@ export interface PayloadSender<TEvent extends EventObject> {
|
|
|
134
134
|
<K extends TEvent['type']>(eventType: K, payload: NeverIfEmpty<ExtractExtraParameters<TEvent, K>>): void;
|
|
135
135
|
}
|
|
136
136
|
export declare type Receiver<TEvent extends EventObject> = (listener: (event: TEvent) => void) => void;
|
|
137
|
-
export declare type InvokeCallback = (callback: Sender<
|
|
137
|
+
export declare type InvokeCallback<TEvent extends EventObject = AnyEventObject> = (callback: Sender<TEvent>, onReceive: Receiver<TEvent>) => any;
|
|
138
138
|
export interface InvokeMeta {
|
|
139
139
|
data: any;
|
|
140
140
|
src: InvokeSourceDefinition;
|
|
@@ -152,7 +152,7 @@ export interface InvokeMeta {
|
|
|
152
152
|
* @param context The current machine `context`
|
|
153
153
|
* @param event The event that invoked the service
|
|
154
154
|
*/
|
|
155
|
-
export declare type InvokeCreator<TContext, TEvent = AnyEventObject, TFinalContext = any> = (context: TContext, event: TEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any> | Subscribable<any> | InvokeCallback
|
|
155
|
+
export declare type InvokeCreator<TContext, TEvent extends EventObject = AnyEventObject, TFinalContext = any> = (context: TContext, event: TEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any> | Subscribable<any> | InvokeCallback<TEvent>;
|
|
156
156
|
export interface InvokeDefinition<TContext, TEvent extends EventObject> extends ActivityDefinition<TContext, TEvent> {
|
|
157
157
|
/**
|
|
158
158
|
* The source of the machine to be invoked, or the machine itself.
|
|
@@ -380,6 +380,10 @@ export interface StateNodeConfig<TContext, TStateSchema extends StateSchema, TEv
|
|
|
380
380
|
* The order this state node appears. Corresponds to the implicit SCXML document order.
|
|
381
381
|
*/
|
|
382
382
|
order?: number;
|
|
383
|
+
/**
|
|
384
|
+
* The tags for this state node, which are accumulated into the `state.tags` property.
|
|
385
|
+
*/
|
|
386
|
+
tags?: SingleOrArray<string>;
|
|
383
387
|
}
|
|
384
388
|
export interface StateNodeDefinition<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> {
|
|
385
389
|
id: string;
|
|
@@ -761,6 +765,7 @@ export interface StateConfig<TContext, TEvent extends EventObject> {
|
|
|
761
765
|
transitions: Array<TransitionDefinition<TContext, TEvent>>;
|
|
762
766
|
children: Record<string, ActorRef<any>>;
|
|
763
767
|
done?: boolean;
|
|
768
|
+
tags?: Set<string>;
|
|
764
769
|
}
|
|
765
770
|
export interface StateSchema<TC = any> {
|
|
766
771
|
meta?: any;
|
|
@@ -887,5 +892,6 @@ export declare type ActorRefFrom<T extends StateMachine<any, any, any>> = T exte
|
|
|
887
892
|
state: State<TContext, TEvent, any, TTypestate>;
|
|
888
893
|
} : never;
|
|
889
894
|
export declare type AnyInterpreter = Interpreter<any, any, any, any>;
|
|
895
|
+
export declare type InterpreterFrom<T extends StateMachine<any, any, any, any>> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : never;
|
|
890
896
|
export {};
|
|
891
897
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/State.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
50
50
|
* An object mapping actor IDs to spawned actors/invoked services.
|
|
51
51
|
*/
|
|
52
52
|
children: Record<string, ActorRef<any>>;
|
|
53
|
+
tags: Set<string>;
|
|
53
54
|
/**
|
|
54
55
|
* Creates a new State instance for the given `stateValue` and `context`.
|
|
55
56
|
* @param stateValue
|
|
@@ -86,7 +87,9 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
86
87
|
* @param delimiter The character(s) that separate each subpath in the string state node path.
|
|
87
88
|
*/
|
|
88
89
|
toStrings(stateValue?: StateValue, delimiter?: string): string[];
|
|
89
|
-
toJSON(): Pick<this, Exclude<keyof this, "configuration" | "transitions"
|
|
90
|
+
toJSON(): Pick<this, Exclude<keyof this, "configuration" | "transitions" | "tags">> & {
|
|
91
|
+
tags: string[];
|
|
92
|
+
};
|
|
90
93
|
/**
|
|
91
94
|
* Whether the current state value is a subset of the given parent state value.
|
|
92
95
|
* @param parentStateValue
|
|
@@ -97,5 +100,10 @@ export declare class State<TContext, TEvent extends EventObject = EventObject, T
|
|
|
97
100
|
} extends TTypestate ? TTypestate : never : never)['context'], TEvent, TStateSchema, TTypestate> & {
|
|
98
101
|
value: TSV;
|
|
99
102
|
};
|
|
103
|
+
/**
|
|
104
|
+
* Whether the current state configuration has a state node with the specified `tag`.
|
|
105
|
+
* @param tag
|
|
106
|
+
*/
|
|
107
|
+
hasTag(tag: string): boolean;
|
|
100
108
|
}
|
|
101
109
|
//# sourceMappingURL=State.d.ts.map
|
package/lib/State.js
CHANGED
|
@@ -99,6 +99,7 @@ var State = /** @class */ (function () {
|
|
|
99
99
|
*/
|
|
100
100
|
function State(config) {
|
|
101
101
|
var _this = this;
|
|
102
|
+
var _a;
|
|
102
103
|
this.actions = [];
|
|
103
104
|
this.activities = constants_1.EMPTY_ACTIVITY_MAP;
|
|
104
105
|
this.meta = {};
|
|
@@ -120,6 +121,7 @@ var State = /** @class */ (function () {
|
|
|
120
121
|
this.transitions = config.transitions;
|
|
121
122
|
this.children = config.children;
|
|
122
123
|
this.done = !!config.done;
|
|
124
|
+
this.tags = (_a = config.tags) !== null && _a !== void 0 ? _a : new Set();
|
|
123
125
|
Object.defineProperty(this, 'nextEvents', {
|
|
124
126
|
get: function () {
|
|
125
127
|
return stateUtils_1.nextEvents(_this.configuration);
|
|
@@ -220,8 +222,8 @@ var State = /** @class */ (function () {
|
|
|
220
222
|
})));
|
|
221
223
|
};
|
|
222
224
|
State.prototype.toJSON = function () {
|
|
223
|
-
var _a = this, configuration = _a.configuration, transitions = _a.transitions, jsonValues = __rest(_a, ["configuration", "transitions"]);
|
|
224
|
-
return jsonValues;
|
|
225
|
+
var _a = this, configuration = _a.configuration, transitions = _a.transitions, tags = _a.tags, jsonValues = __rest(_a, ["configuration", "transitions", "tags"]);
|
|
226
|
+
return __assign(__assign({}, jsonValues), { tags: Array.from(tags) });
|
|
225
227
|
};
|
|
226
228
|
/**
|
|
227
229
|
* Whether the current state value is a subset of the given parent state value.
|
|
@@ -230,6 +232,13 @@ var State = /** @class */ (function () {
|
|
|
230
232
|
State.prototype.matches = function (parentStateValue) {
|
|
231
233
|
return utils_1.matchesState(parentStateValue, this.value);
|
|
232
234
|
};
|
|
235
|
+
/**
|
|
236
|
+
* Whether the current state configuration has a state node with the specified `tag`.
|
|
237
|
+
* @param tag
|
|
238
|
+
*/
|
|
239
|
+
State.prototype.hasTag = function (tag) {
|
|
240
|
+
return this.tags.has(tag);
|
|
241
|
+
};
|
|
233
242
|
return State;
|
|
234
243
|
}());
|
|
235
244
|
exports.State = State;
|
package/lib/StateNode.d.ts
CHANGED
package/lib/StateNode.js
CHANGED
|
@@ -121,6 +121,7 @@ var StateNode = /** @class */ (function () {
|
|
|
121
121
|
delayedTransitions: undefined
|
|
122
122
|
};
|
|
123
123
|
this.idMap = {};
|
|
124
|
+
this.tags = [];
|
|
124
125
|
this.options = Object.assign(createDefaultOptions(), options);
|
|
125
126
|
this.parent = this.options._parent;
|
|
126
127
|
this.key =
|
|
@@ -233,6 +234,7 @@ var StateNode = /** @class */ (function () {
|
|
|
233
234
|
.concat(this.invoke)
|
|
234
235
|
.map(function (activity) { return actions_1.toActivityDefinition(activity); });
|
|
235
236
|
this.transition = this.transition.bind(this);
|
|
237
|
+
this.tags = utils_1.toArray(this.config.tags);
|
|
236
238
|
// TODO: this is the real fix for initialization once
|
|
237
239
|
// state node getters are deprecated
|
|
238
240
|
// if (!this.parent) {
|
|
@@ -851,7 +853,8 @@ var StateNode = /** @class */ (function () {
|
|
|
851
853
|
configuration: resolvedConfiguration,
|
|
852
854
|
transitions: stateTransition.transitions,
|
|
853
855
|
children: children,
|
|
854
|
-
done: isDone
|
|
856
|
+
done: isDone,
|
|
857
|
+
tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags
|
|
855
858
|
});
|
|
856
859
|
var didUpdateContext = currentContext !== updatedContext;
|
|
857
860
|
nextState.changed = _event.name === actionTypes.update || didUpdateContext;
|
|
@@ -890,6 +893,7 @@ var StateNode = /** @class */ (function () {
|
|
|
890
893
|
maybeNextState.changed = changed;
|
|
891
894
|
// Preserve original history after raised events
|
|
892
895
|
maybeNextState.history = history;
|
|
896
|
+
maybeNextState.tags = new Set(utils_1.flatten(maybeNextState.configuration.map(function (sn) { return sn.tags; })));
|
|
893
897
|
return maybeNextState;
|
|
894
898
|
};
|
|
895
899
|
/**
|
|
@@ -1021,6 +1025,10 @@ var StateNode = /** @class */ (function () {
|
|
|
1021
1025
|
_a[this.initial] = this.states[this.initial].initialStateValue,
|
|
1022
1026
|
_a));
|
|
1023
1027
|
}
|
|
1028
|
+
else {
|
|
1029
|
+
// The finite state value of a machine without child states is just an empty object
|
|
1030
|
+
initialStateValue = {};
|
|
1031
|
+
}
|
|
1024
1032
|
this.__cache.initialStateValue = initialStateValue;
|
|
1025
1033
|
return this.__cache.initialStateValue;
|
|
1026
1034
|
},
|
package/lib/devTools.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.registerService = exports.getGlobal = void 0;
|
|
4
|
-
var environment_1 = require("./environment");
|
|
5
4
|
// From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
|
|
6
5
|
function getGlobal() {
|
|
7
6
|
if (typeof self !== 'undefined') {
|
|
@@ -24,7 +23,7 @@ function getDevTools() {
|
|
|
24
23
|
return undefined;
|
|
25
24
|
}
|
|
26
25
|
function registerService(service) {
|
|
27
|
-
if (
|
|
26
|
+
if (!getGlobal()) {
|
|
28
27
|
return;
|
|
29
28
|
}
|
|
30
29
|
var devTools = getDevTools();
|
package/lib/model.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ declare type Compute<A extends any> = {
|
|
|
5
5
|
[K in keyof A]: A[K];
|
|
6
6
|
} & unknown;
|
|
7
7
|
declare type Prop<T, K> = K extends keyof T ? T[K] : never;
|
|
8
|
-
export interface Model<TContext, TEvent extends EventObject, TModelCreators =
|
|
8
|
+
export interface Model<TContext, TEvent extends EventObject, TModelCreators = void> {
|
|
9
9
|
initialContext: TContext;
|
|
10
10
|
assign: <TEventType extends TEvent['type'] = TEvent['type']>(assigner: Assigner<TContext, ExtractEvent<TEvent, TEventType>> | PropertyAssigner<TContext, ExtractEvent<TEvent, TEventType>>, eventType?: TEventType) => AssignAction<TContext, ExtractEvent<TEvent, TEventType>>;
|
|
11
11
|
events: Prop<TModelCreators, 'events'>;
|
|
@@ -33,7 +33,7 @@ declare type FinalModelCreators<Self> = {
|
|
|
33
33
|
declare type EventFromEventCreators<EventCreators> = {
|
|
34
34
|
[K in keyof EventCreators]: EventCreators[K] extends AnyFunction ? ReturnType<EventCreators[K]> : never;
|
|
35
35
|
}[keyof EventCreators];
|
|
36
|
-
export declare function createModel<TContext, TEvent extends EventObject>(initialContext: TContext): Model<TContext, TEvent,
|
|
36
|
+
export declare function createModel<TContext, TEvent extends EventObject>(initialContext: TContext): Model<TContext, TEvent, void>;
|
|
37
37
|
export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<EventFromEventCreators<Prop<TFinalModelCreators, 'events'>>, EventObject>, TFinalModelCreators>;
|
|
38
38
|
export {};
|
|
39
39
|
//# sourceMappingURL=model.d.ts.map
|
package/lib/types.d.ts
CHANGED
|
@@ -134,7 +134,7 @@ export interface PayloadSender<TEvent extends EventObject> {
|
|
|
134
134
|
<K extends TEvent['type']>(eventType: K, payload: NeverIfEmpty<ExtractExtraParameters<TEvent, K>>): void;
|
|
135
135
|
}
|
|
136
136
|
export declare type Receiver<TEvent extends EventObject> = (listener: (event: TEvent) => void) => void;
|
|
137
|
-
export declare type InvokeCallback = (callback: Sender<
|
|
137
|
+
export declare type InvokeCallback<TEvent extends EventObject = AnyEventObject> = (callback: Sender<TEvent>, onReceive: Receiver<TEvent>) => any;
|
|
138
138
|
export interface InvokeMeta {
|
|
139
139
|
data: any;
|
|
140
140
|
src: InvokeSourceDefinition;
|
|
@@ -152,7 +152,7 @@ export interface InvokeMeta {
|
|
|
152
152
|
* @param context The current machine `context`
|
|
153
153
|
* @param event The event that invoked the service
|
|
154
154
|
*/
|
|
155
|
-
export declare type InvokeCreator<TContext, TEvent = AnyEventObject, TFinalContext = any> = (context: TContext, event: TEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any> | Subscribable<any> | InvokeCallback
|
|
155
|
+
export declare type InvokeCreator<TContext, TEvent extends EventObject = AnyEventObject, TFinalContext = any> = (context: TContext, event: TEvent, meta: InvokeMeta) => PromiseLike<TFinalContext> | StateMachine<TFinalContext, any, any> | Subscribable<any> | InvokeCallback<TEvent>;
|
|
156
156
|
export interface InvokeDefinition<TContext, TEvent extends EventObject> extends ActivityDefinition<TContext, TEvent> {
|
|
157
157
|
/**
|
|
158
158
|
* The source of the machine to be invoked, or the machine itself.
|
|
@@ -380,6 +380,10 @@ export interface StateNodeConfig<TContext, TStateSchema extends StateSchema, TEv
|
|
|
380
380
|
* The order this state node appears. Corresponds to the implicit SCXML document order.
|
|
381
381
|
*/
|
|
382
382
|
order?: number;
|
|
383
|
+
/**
|
|
384
|
+
* The tags for this state node, which are accumulated into the `state.tags` property.
|
|
385
|
+
*/
|
|
386
|
+
tags?: SingleOrArray<string>;
|
|
383
387
|
}
|
|
384
388
|
export interface StateNodeDefinition<TContext, TStateSchema extends StateSchema, TEvent extends EventObject> {
|
|
385
389
|
id: string;
|
|
@@ -761,6 +765,7 @@ export interface StateConfig<TContext, TEvent extends EventObject> {
|
|
|
761
765
|
transitions: Array<TransitionDefinition<TContext, TEvent>>;
|
|
762
766
|
children: Record<string, ActorRef<any>>;
|
|
763
767
|
done?: boolean;
|
|
768
|
+
tags?: Set<string>;
|
|
764
769
|
}
|
|
765
770
|
export interface StateSchema<TC = any> {
|
|
766
771
|
meta?: any;
|
|
@@ -887,5 +892,6 @@ export declare type ActorRefFrom<T extends StateMachine<any, any, any>> = T exte
|
|
|
887
892
|
state: State<TContext, TEvent, any, TTypestate>;
|
|
888
893
|
} : never;
|
|
889
894
|
export declare type AnyInterpreter = Interpreter<any, any, any, any>;
|
|
895
|
+
export declare type InterpreterFrom<T extends StateMachine<any, any, any, any>> = T extends StateMachine<infer TContext, infer TStateSchema, infer TEvent, infer TTypestate> ? Interpreter<TContext, TStateSchema, TEvent, TTypestate> : never;
|
|
890
896
|
export {};
|
|
891
897
|
//# sourceMappingURL=types.d.ts.map
|