xstate 4.7.7 → 4.9.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 +63 -0
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +2 -2
- package/es/State.js +3 -1
- package/es/StateNode.d.ts +1 -2
- package/es/StateNode.js +41 -77
- package/es/actionTypes.d.ts +1 -0
- package/es/actionTypes.js +2 -1
- package/es/actions.d.ts +7 -3
- package/es/actions.js +86 -7
- package/es/index.d.ts +3 -1
- package/es/index.js +4 -2
- package/es/interpreter.d.ts +4 -3
- package/es/interpreter.js +24 -14
- package/es/json.d.ts +31 -0
- package/es/registry.js +1 -3
- package/es/types.d.ts +31 -14
- package/es/types.js +1 -0
- package/es/utils.d.ts +3 -2
- package/es/utils.js +24 -7
- package/lib/State.js +2 -1
- package/lib/StateNode.d.ts +1 -2
- package/lib/StateNode.js +27 -67
- package/lib/actionTypes.d.ts +1 -0
- package/lib/actionTypes.js +1 -0
- package/lib/actions.d.ts +7 -3
- package/lib/actions.js +81 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +3 -1
- package/lib/interpreter.d.ts +4 -3
- package/lib/interpreter.js +16 -8
- package/lib/json.d.ts +31 -0
- package/lib/json.js +84 -0
- package/lib/scxml.js +132 -57
- package/lib/types.d.ts +31 -14
- package/lib/types.js +1 -0
- package/lib/utils.d.ts +3 -2
- package/lib/utils.js +22 -4
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
1
|
# xstate
|
|
2
2
|
|
|
3
|
+
## 4.9.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`8a97785`](https://github.com/davidkpiano/xstate/commit/8a97785055faaeb1b36040dd4dc04e3b90fa9ec2) [#1137](https://github.com/davidkpiano/xstate/pull/1137) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Added docs for the `choose()` and `pure()` action creators, as well as exporting the `pure()` action creator in the `actions` object.
|
|
8
|
+
|
|
9
|
+
* [`e65dee9`](https://github.com/davidkpiano/xstate/commit/e65dee928fea60df1e9f83c82fed8102dfed0000) [#1131](https://github.com/davidkpiano/xstate/pull/1131) Thanks [@wKovacs64](https://github.com/wKovacs64)! - Include the new `choose` action in the `actions` export from the `xstate` core package. This was missed in v4.9.0.
|
|
10
|
+
|
|
11
|
+
## 4.9.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [`f3ff150`](https://github.com/davidkpiano/xstate/commit/f3ff150f7c50f402704d25cdc053b76836e447e3) [#1103](https://github.com/davidkpiano/xstate/pull/1103) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Simplify the `TransitionConfigArray` and `TransitionConfigMap` types in order to fix excessively deep type instantiation TypeScript reports. This addresses [#1015](https://github.com/davidkpiano/xstate/issues/1015).
|
|
16
|
+
|
|
17
|
+
* [`6c47b66`](https://github.com/davidkpiano/xstate/commit/6c47b66c3289ff161dc96d9b246873f55c9e18f2) [#1076](https://github.com/davidkpiano/xstate/pull/1076) Thanks [@Andarist](https://github.com/Andarist)! - Added support for conditional actions. It's possible now to have actions executed based on conditions using following:
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
entry: [
|
|
21
|
+
choose([
|
|
22
|
+
{ cond: ctx => ctx > 100, actions: raise('TOGGLE') },
|
|
23
|
+
{
|
|
24
|
+
cond: 'hasMagicBottle',
|
|
25
|
+
actions: [assign(ctx => ({ counter: ctx.counter + 1 }))]
|
|
26
|
+
},
|
|
27
|
+
{ actions: ['fallbackAction'] }
|
|
28
|
+
])
|
|
29
|
+
];
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
It works very similar to the if-else syntax where only the first matched condition is causing associated actions to be executed and the last ones can be unconditional (serving as a general fallback, just like else branch).
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- [`1a129f0`](https://github.com/davidkpiano/xstate/commit/1a129f0f35995981c160d756a570df76396bfdbd) [#1073](https://github.com/davidkpiano/xstate/pull/1073) Thanks [@Andarist](https://github.com/Andarist)! - Cleanup internal structures upon receiving termination events from spawned actors.
|
|
37
|
+
|
|
38
|
+
* [`e88aa18`](https://github.com/davidkpiano/xstate/commit/e88aa18431629e1061b74dfd4a961b910e274e0b) [#1085](https://github.com/davidkpiano/xstate/pull/1085) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with data expressions of root's final nodes being called twice.
|
|
39
|
+
|
|
40
|
+
- [`88b17b2`](https://github.com/davidkpiano/xstate/commit/88b17b2476ff9a0fbe810df9d00db32c2241cd6e) [#1090](https://github.com/davidkpiano/xstate/pull/1090) Thanks [@rjdestigter](https://github.com/rjdestigter)! - This change carries forward the typestate type information encoded in the arguments of the following functions and assures that the return type also has the same typestate type information:
|
|
41
|
+
|
|
42
|
+
- Cloned state machine returned by `.withConfig`.
|
|
43
|
+
- `.state` getter defined for services.
|
|
44
|
+
- `start` method of services.
|
|
45
|
+
|
|
46
|
+
* [`d5f622f`](https://github.com/davidkpiano/xstate/commit/d5f622f68f4065a2615b5a4a1caae6b508b4840e) [#1069](https://github.com/davidkpiano/xstate/pull/1069) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Loosened event type for `SendAction<TContext, AnyEventObject>`
|
|
47
|
+
|
|
48
|
+
## 4.8.0
|
|
49
|
+
|
|
50
|
+
### Minor Changes
|
|
51
|
+
|
|
52
|
+
- [`55aa589`](https://github.com/davidkpiano/xstate/commit/55aa589648a9afbd153e8b8e74cbf2e0ebf573fb) [#960](https://github.com/davidkpiano/xstate/pull/960) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The machine can now be safely JSON-serialized, using `JSON.stringify(machine)`. The shape of this serialization is defined in `machine.schema.json` and reflected in `machine.definition`.
|
|
53
|
+
|
|
54
|
+
Note that `onEntry` and `onExit` have been deprecated in the definition in favor of `entry` and `exit`.
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- [`1ae31c1`](https://github.com/davidkpiano/xstate/commit/1ae31c17dc81fb63e699b4b9bf1cf4ead023001d) [#1023](https://github.com/davidkpiano/xstate/pull/1023) Thanks [@Andarist](https://github.com/Andarist)! - Fixed memory leak - `State` objects had been retained in closures.
|
|
59
|
+
|
|
60
|
+
## 4.7.8
|
|
61
|
+
|
|
62
|
+
### Patch Changes
|
|
63
|
+
|
|
64
|
+
- [`520580b`](https://github.com/davidkpiano/xstate/commit/520580b4af597f7c83c329757ae972278c2d4494) [#967](https://github.com/davidkpiano/xstate/pull/967) Thanks [@andrewgordstewart](https://github.com/andrewgordstewart)! - Add context & event types to InvokeConfig
|
|
65
|
+
|
|
3
66
|
## 4.7.7
|
|
4
67
|
|
|
5
68
|
### Patch Changes
|
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
|
|
13
13
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
14
|
and limitations under the License.
|
|
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&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}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"}(e||(e={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(n||(n={}));var a=".",u={};function c(t){return Object.keys(t)}function h(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:p(t)?f(t):"string"!=typeof t?t:f(function(t,e){try{return p(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}(t,e));var n}function f(t){if(1===t.length)return t[0];for(var e={},n=e,i=0;i<t.length-1;i++)i===t.length-2?n[t[i]]=t[i+1]:(n[t[i]]={},n=n[t[i]]);return e}function l(t,e,n){var i,o;if(v(t))return t(e,n.data);var s={};try{for(var a=r(c(t)),u=a.next();!u.done;u=a.next()){var h=u.value,f=t[h];v(f)?s[h]=f(e,n.data):s[h]=f}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=a.return)&&o.call(a)}finally{if(i)throw i.error}}return s}function d(t){return t instanceof Promise||!(null===t||!v(t)&&"object"!=typeof t||!v(t.then))}function p(t){return Array.isArray(t)}function v(t){return"function"==typeof t}function y(t){return"string"==typeof t}function w(t){try{return"subscribe"in t&&v(t.subscribe)}catch(t){return!1}}var b="function"==typeof Symbol&&Symbol.observable||"@@observable";function x(t){try{return"__xstatenode"in t}catch(t){return!1}}var m,g=(m=0,function(){return(++m).toString(16)});function S(t,e){return y(t)||"number"==typeof t?i({type:t},e):t}function E(t,e){if(!y(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var n=S(t);return i({name:n.type,data:n,$$type:"scxml",type:"external"},e)}function _(t){return c(t.states).map((function(e){return t.states[e]}))}function O(t){return e=s(new Set(t.map((function(t){return t.ownEvents})))),(n=[]).concat.apply(n,s(e));var e,n}function T(t,e){return"compound"===e.type?_(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).every((function(e){return T(t,e)}))}var L=e.Start,k=e.Stop,P=(e.Raise,e.Send),I=e.Cancel,N=(e.NullEvent,e.Assign,e.After,e.DoneState,e.Log),j=e.Init,M=(e.Invoke,e.ErrorExecution,e.ErrorPlatform),D=e.ErrorCustom,A=e.Update,C=(e.Pure,E({type:j}));function R(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 V=function(){function t(t){this.actions=[],this.activities=u,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||u,this.meta=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 O(t.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:C,_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=C;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="."),y(t))return[t];var i=c(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=a);var r=h(e,i),o=h(n,i);return y(o)?!!y(r)&&o===r:y(r)?r in o:c(r).every((function(e){return e in o&&t(r[e],o[e])}))}(t,this.value)},t}(),J={deferEvents:!1},q=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=i(i({},J),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}();function U(t){try{return"function"==typeof t.send}catch(t){return!1}}var $,F,X=new Map,B=0,G={bookId:function(){return"x:"+B++},register:function(t,e){return X.set(t,e),t},get:function(t){return X.get(t)},free:function(t){X.delete(t)}},H={sync:!1,autoForward:!1},K=($=[],function(t,e){t&&$.push(t);var n=e(t||$[$.length-1]);return t&&$.pop(),n});!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(F||(F={}));var Q=function(){function t(e,r){var o=this;void 0===r&&(r=t.defaultOptions),this.machine=e,this.scheduler=new q,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this._status=F.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(t,e){if(p(t))return o.batch(t),o.state;var n=E(S(t,e));if(o._status===F.Stopped)return o.state;if(o._status===F.NotStarted&&o.options.deferEvents);else if(o._status!==F.Running)throw new Error('Event "'+n.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(n.data));return o.scheduler.schedule((function(){o.forward(n);var t=o.nextState(n);o.update(t,n)})),o._state},this.sendTo=function(t,e){var r=o.parent&&(e===n.Parent||o.parent.id===e),s=r?o.parent:U(e)?e:o.children.get(e)||G.get(e);if(s)"machine"in s?s.send(i(i({},t),{name:t.name===D?""+z(o.id):t.name,origin:o.sessionId})):s.send(t.data);else if(!r)throw new Error("Unable to send event to child '"+e+"' from service '"+o.id+"'.")};var s=i(i({},t.defaultOptions),r),a=s.clock,u=s.logger,c=s.parent,h=s.id,f=void 0!==h?h:e.id;this.id=f,this.logger=u,this.clock=a,this.parent=c,this.options=s,this.scheduler=new q({deferEvents:this.options.deferEvents}),this.sessionId=G.bookId()}return Object.defineProperty(t.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:K(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),t.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}}},t.prototype.update=function(t,e){var n,i,o,s,a,u,c,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),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 w=r(this.contextListeners),b=w.next();!b.done;b=w.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=w.return)&&u.call(w)}finally{if(a)throw a.error}}var x=T(t.configuration||[],this.machine);if(this.state.configuration&&x){var m=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),g=m&&m.data?l(m.data,t.context,e):void 0;try{for(var S=r(this.doneListeners),E=S.next();!E.done;E=S.next()){(0,E.value)(R(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()}},t.prototype.onTransition=function(t){return this.listeners.add(t),this._status===F.Running&&t(this.state,this.state.event),this},t.prototype.subscribe=function(t,e,n){var i,r=this;if(!t)return{unsubscribe:function(){}};var o=n;return"function"==typeof t?i=t:(i=t.next.bind(t),o=t.complete.bind(t)),this.listeners.add(i),this._status===F.Running&&i(this.state),o&&this.onDone(o),{unsubscribe:function(){i&&r.listeners.delete(i),o&&r.doneListeners.delete(o)}}},t.prototype.onEvent=function(t){return this.eventListeners.add(t),this},t.prototype.onSend=function(t){return this.sendListeners.add(t),this},t.prototype.onChange=function(t){return this.contextListeners.add(t),this},t.prototype.onStop=function(t){return this.stopListeners.add(t),this},t.prototype.onDone=function(t){return this.doneListeners.add(t),this},t.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},t.prototype.start=function(t){var e=this;if(this._status===F.Running)return this;G.register(this.sessionId,this),this.initialized=!0,this._status=F.Running;var n=void 0===t?this.initialState:K(this,(function(){return!y(n=t)&&"value"in n&&"history"in n?e.machine.resolveState(t):e.machine.resolveState(V.from(t,e.machine.context));var n}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){e.update(n,C)})),this},t.prototype.stop=function(){var t,e,n,i,o,s,a,u,h,f;try{for(var l=r(this.listeners),d=l.next();!d.done;d=l.next()){var p=d.value;this.listeners.delete(p)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(e=l.return)&&e.call(l)}finally{if(t)throw t.error}}try{for(var y=r(this.stopListeners),w=y.next();!w.done;w=y.next()){(p=w.value)(),this.stopListeners.delete(p)}}catch(t){n={error:t}}finally{try{w&&!w.done&&(i=y.return)&&i.call(y)}finally{if(n)throw n.error}}try{for(var b=r(this.contextListeners),x=b.next();!x.done;x=b.next()){p=x.value;this.contextListeners.delete(p)}}catch(t){o={error:t}}finally{try{x&&!x.done&&(s=b.return)&&s.call(b)}finally{if(o)throw o.error}}try{for(var m=r(this.doneListeners),g=m.next();!g.done;g=m.next()){p=g.value;this.doneListeners.delete(p)}}catch(t){a={error:t}}finally{try{g&&!g.done&&(u=m.return)&&u.call(m)}finally{if(a)throw a.error}}this.children.forEach((function(t){v(t.stop)&&t.stop()}));try{for(var S=r(c(this.delayedEventsMap)),E=S.next();!E.done;E=S.next()){var _=E.value;this.clock.clearTimeout(this.delayedEventsMap[_])}}catch(t){h={error:t}}finally{try{E&&!E.done&&(f=S.return)&&f.call(S)}finally{if(h)throw h.error}}return this.scheduler.clear(),this.initialized=!1,this._status=F.Stopped,G.free(this.sessionId),this},t.prototype.batch=function(t){var e=this;if(this._status===F.NotStarted&&this.options.deferEvents);else if(this._status!==F.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((function(){var n,o,a=e.state,u=!1,c=[],h=function(t){var n=E(t);e.forward(n),a=K(e,(function(){return e.machine.transition(a,n)})),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(t),l=f.next();!l.done;l=f.next()){h(l.value)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(o=f.return)&&o.call(f)}finally{if(n)throw n.error}}a.changed=u,a.actions=c,e.update(a,E(t[t.length-1]))}))},t.prototype.sender=function(t){return this.send.bind(this,t)},t.prototype.nextState=function(t){var e=this,n=E(t);if(0===n.name.indexOf(M)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(M)})))throw n.data.data;return K(this,(function(){return e.machine.transition(e.state,n)}))},t.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}}},t.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)},t.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},t.prototype.exec=function(t,n,i){var r=n.context,o=n._event,s=function(t,e){return e&&e[t]||void 0}(t.type,i)||t.exec,a=v(s)?s:s?s.exec:t.exec;if(a)try{return a(r,o.data,{action:t,state:this.state,_event:o})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case P:var u=t;if("number"==typeof u.delay)return void this.defer(u);u.to?this.sendTo(u._event,u.to):this.send(u._event);break;case I:this.cancel(t.sendId);break;case L:var c=t.activity;if(!this.state.activities[c.type])break;if(c.type===e.Invoke){var h=this.machine.options.services?this.machine.options.services[c.src]:void 0,f=c.id,p=c.data,y="autoForward"in c?c.autoForward:!!c.forward;if(!h)return;var b=v(h)?h(r,o.data):h;d(b)?this.state.children[f]=this.spawnPromise(Promise.resolve(b),f):v(b)?this.state.children[f]=this.spawnCallback(b,f):w(b)?this.state.children[f]=this.spawnObservable(b,f):x(b)&&(this.state.children[f]=this.spawnMachine(p?b.withContext(l(p,r,o)):b,{id:f,autoForward:y}))}else this.spawnActivity(c);break;case k:this.stopChild(t.activity.id);break;case N:var m=t.label,g=t.value;m?this.logger(m,g):this.logger(g)}},t.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t],v(e.stop)&&e.stop())},t.prototype.spawn=function(t,e,n){if(d(t))return this.spawnPromise(Promise.resolve(t),e);if(v(t))return this.spawnCallback(t,e);if(U(t))return this.spawnActor(t);if(w(t))return this.spawnObservable(t,e);if(x(t))return this.spawnMachine(t,i(i({},n),{id:e}));throw new Error('Unable to spawn entity "'+e+'" of type "'+typeof t+'".')},t.prototype.spawnMachine=function(e,n){var r=this;void 0===n&&(n={});var o=new t(e,i(i({},this.options),{parent:this,id:n.id||e.id})),s=i(i({},H),n);s.sync&&o.onTransition((function(t){r.send(A,{state:t,id:o.id})})),o.onDone((function(t){r.send(E(t,{origin:o.id}))})).start();var a=o;return this.children.set(o.id,a),s.autoForward&&this.forwardTo.add(o.id),a},t.prototype.spawnPromise=function(t,e){var n=this,i=!1;t.then((function(t){i||n.send(E(R(e,t),{origin:e}))}),(function(t){if(!i){var r=z(e,t);try{n.send(E(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=!1;return t.then((function(t){r||(e&&e(t),r||i&&i())}),(function(t){r||n(t)})),{unsubscribe:function(){return r=!0}}},stop:function(){i=!0},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},t.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(t)}),(function(t){o.add(t)}))}catch(t){this.send(z(e,t))}if(d(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,v(n)&&n()},toJSON:function(){return{id:e}}};return this.children.set(e,a),a},t.prototype.spawnObservable=function(t,e){var n=this,i=t.subscribe((function(t){n.send(E(t,{origin:e}))}),(function(t){n.send(E(z(e,t),{origin:e}))}),(function(){n.send(E(R(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},t.prototype.spawnActor=function(t){return this.children.set(t.id,t),t},t.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)}},t.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}}})},t.prototype.attachDev=function(){if(this.options.devTools&&"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){var t="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=window.__REDUX_DEVTOOLS_EXTENSION__.connect(i(i({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},t),{features:i({jump:!1,skip:!1},t?t.features:void 0)}),this.machine),this.devTools.init(this.state)}},t.prototype.toJSON=function(){return{id:this.id}},t.prototype[b]=function(){return this},t.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(e,n){return t.setTimeout.call(null,e,n)},clearTimeout:function(e){return t.clearTimeout.call(null,e)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"==typeof window?global:window),t.interpret=Z,t}(),W=function(t){return void 0===t&&(t="null"),{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:t}}}},Y=function(t){return y(t)?i(i({},H),{name:t}):i(i(i({},H),{name:g()}),t)};function Z(t,e){return new Q(t,e)}t.Interpreter=Q,t.interpret=Z,t.spawn=function(t,e){var n=Y(e);return K(void 0,(function(e){return e?e.spawn(t,n.name,n):W(n.name)}))},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&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}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(u(t)),c=a.next();!c.done;c=a.next()){var h=c.value,f=t[h];p(f)?s[h]=f(e,n.data):s[h]=f}}catch(t){i={error:t}}finally{try{c&&!c.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 w="function"==typeof Symbol&&Symbol.observable||"@@observable";function m(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,L=e.Stop,k=(e.Raise,e.Send),P=e.Cancel,C=(e.NullEvent,e.Assign,e.After,e.DoneState,e.Log),I=e.Init,N=(e.Invoke,e.ErrorExecution,e.ErrorPlatform),j=e.ErrorCustom,M=e.Update,D=(e.Choose,e.Pure,S({type:I}));function A(t,n){var i=e.DoneInvoke+"."+t,r={type:i,data:n,toString:function(){return i}};return r}function R(t,n){var i=e.ErrorPlatform+"."+t,r={type:i,data:n,toString:function(){return i}};return r}var z=function(){function t(t){var e=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:D,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var i=D;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}();function q(t){try{return"function"==typeof t.send}catch(t){return!1}}var U,$,F=new Map,X=0,B=function(){return"x:"+X++},G=function(t,e){return F.set(t,e),t},H=function(t){return F.get(t)},K=function(t){F.delete(t)},Q={sync:!1,autoForward:!1},W=(U=[],function(t,e){t&&U.push(t);var n=e(t||U[U.length-1]);return t&&U.pop(),n});!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}($||($={}));var Y=function(){function t(e,r){var o=this;void 0===r&&(r=t.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=$.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(t,e){if(d(t))return o.batch(t),o.state;var n=S(g(t,e));if(o._status===$.Stopped)return o.state;if(o._status===$.NotStarted&&o.options.deferEvents);else if(o._status!==$.Running)throw new Error('Event "'+n.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(n.data));return o.scheduler.schedule((function(){o.forward(n);var t=o.nextState(n);o.update(t,n)})),o._state},this.sendTo=function(t,e){var r=o.parent&&(e===n.Parent||o.parent.id===e),s=r?o.parent:q(e)?e:o.children.get(e)||H(e);if(s)"machine"in s?s.send(i(i({},t),{name:t.name===j?""+R(o.id):t.name,origin:o.sessionId})):s.send(t.data);else if(!r)throw new Error("Unable to send event to child '"+e+"' from service '"+o.id+"'.")};var s=i(i({},t.defaultOptions),r),a=s.clock,u=s.logger,c=s.parent,h=s.id,f=void 0!==h?h:e.id;this.id=f,this.logger=u,this.clock=a,this.parent=c,this.options=s,this.scheduler=new J({deferEvents:this.options.deferEvents}),this.sessionId=B()}return Object.defineProperty(t.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:W(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),t.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}}},t.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.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 w=r(this.contextListeners),m=w.next();!m.done;m=w.next()){(0,m.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){a={error:t}}finally{try{m&&!m.done&&(u=w.return)&&u.call(w)}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.data?f(b.data,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()}},t.prototype.onTransition=function(t){return this.listeners.add(t),this._status===$.Running&&t(this.state,this.state.event),this},t.prototype.subscribe=function(t,e,n){var i,r=this;if(!t)return{unsubscribe:function(){}};var o=n;return"function"==typeof t?i=t:(i=t.next.bind(t),o=t.complete.bind(t)),this.listeners.add(i),this._status===$.Running&&i(this.state),o&&this.onDone(o),{unsubscribe:function(){i&&r.listeners.delete(i),o&&r.doneListeners.delete(o)}}},t.prototype.onEvent=function(t){return this.eventListeners.add(t),this},t.prototype.onSend=function(t){return this.sendListeners.add(t),this},t.prototype.onChange=function(t){return this.contextListeners.add(t),this},t.prototype.onStop=function(t){return this.stopListeners.add(t),this},t.prototype.onDone=function(t){return this.doneListeners.add(t),this},t.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},t.prototype.start=function(t){var e=this;if(this._status===$.Running)return this;G(this.sessionId,this),this.initialized=!0,this._status=$.Running;var n=void 0===t?this.initialState:W(this,(function(){return!v(n=t)&&"value"in n&&"history"in n?e.machine.resolveState(t):e.machine.resolveState(z.from(t,e.machine.context));var n}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){e.update(n,D)})),this},t.prototype.stop=function(){var t,e,n,i,o,s,a,c,h,f;try{for(var l=r(this.listeners),d=l.next();!d.done;d=l.next()){var v=d.value;this.listeners.delete(v)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(e=l.return)&&e.call(l)}finally{if(t)throw t.error}}try{for(var y=r(this.stopListeners),w=y.next();!w.done;w=y.next()){(v=w.value)(),this.stopListeners.delete(v)}}catch(t){n={error:t}}finally{try{w&&!w.done&&(i=y.return)&&i.call(y)}finally{if(n)throw n.error}}try{for(var m=r(this.contextListeners),x=m.next();!x.done;x=m.next()){v=x.value;this.contextListeners.delete(v)}}catch(t){o={error:t}}finally{try{x&&!x.done&&(s=m.return)&&s.call(m)}finally{if(o)throw o.error}}try{for(var b=r(this.doneListeners),g=b.next();!g.done;g=b.next()){v=g.value;this.doneListeners.delete(v)}}catch(t){a={error:t}}finally{try{g&&!g.done&&(c=b.return)&&c.call(b)}finally{if(a)throw a.error}}this.children.forEach((function(t){p(t.stop)&&t.stop()}));try{for(var S=r(u(this.delayedEventsMap)),E=S.next();!E.done;E=S.next()){var _=E.value;this.clock.clearTimeout(this.delayedEventsMap[_])}}catch(t){h={error:t}}finally{try{E&&!E.done&&(f=S.return)&&f.call(S)}finally{if(h)throw h.error}}return this.scheduler.clear(),this.initialized=!1,this._status=$.Stopped,K(this.sessionId),this},t.prototype.batch=function(t){var e=this;if(this._status===$.NotStarted&&this.options.deferEvents);else if(this._status!==$.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((function(){var n,o,a=e.state,u=!1,c=[],h=function(t){var n=S(t);e.forward(n),a=W(e,(function(){return e.machine.transition(a,n)})),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(t),l=f.next();!l.done;l=f.next()){h(l.value)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(o=f.return)&&o.call(f)}finally{if(n)throw n.error}}a.changed=u,a.actions=c,e.update(a,S(t[t.length-1]))}))},t.prototype.sender=function(t){return this.send.bind(this,t)},t.prototype.nextState=function(t){var e=this,n=S(t);if(0===n.name.indexOf(N)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(N)})))throw n.data.data;return W(this,(function(){return e.machine.transition(e.state,n)}))},t.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}}},t.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)},t.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},t.prototype.exec=function(t,n,i){var r=n.context,o=n._event,s=function(t,e){return e&&e[t]||void 0}(t.type,i)||t.exec,a=p(s)?s:s?s.exec:t.exec;if(a)try{return a(r,o.data,{action:t,state:this.state,_event:o})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case k:var u=t;if("number"==typeof u.delay)return void this.defer(u);u.to?this.sendTo(u._event,u.to):this.send(u._event);break;case P:this.cancel(t.sendId);break;case T:var c=t.activity;if(!this.state.activities[c.type])break;if(c.type===e.Invoke){var h=this.machine.options.services?this.machine.options.services[c.src]:void 0,d=c.id,v=c.data,w="autoForward"in c?c.autoForward:!!c.forward;if(!h)return;var x=p(h)?h(r,o.data):h;l(x)?this.state.children[d]=this.spawnPromise(Promise.resolve(x),d):p(x)?this.state.children[d]=this.spawnCallback(x,d):y(x)?this.state.children[d]=this.spawnObservable(x,d):m(x)&&(this.state.children[d]=this.spawnMachine(v?x.withContext(f(v,r,o)):x,{id:d,autoForward:w}))}else this.spawnActivity(c);break;case L:this.stopChild(t.activity.id);break;case C:var b=t.label,g=t.value;b?this.logger(b,g):this.logger(g)}},t.prototype.removeChild=function(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]},t.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),p(e.stop)&&e.stop())},t.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(q(t))return this.spawnActor(t);if(y(t))return this.spawnObservable(t,e);if(m(t))return this.spawnMachine(t,i(i({},n),{id:e}));throw new Error('Unable to spawn entity "'+e+'" of type "'+typeof t+'".')},t.prototype.spawnMachine=function(e,n){var r=this;void 0===n&&(n={});var o=new t(e,i(i({},this.options),{parent:this,id:n.id||e.id})),s=i(i({},Q),n);s.sync&&o.onTransition((function(t){r.send(M,{state:t,id:o.id})}));var a=o;return this.children.set(o.id,a),s.autoForward&&this.forwardTo.add(o.id),o.onDone((function(t){r.removeChild(o.id),r.send(S(t,{origin:o.id}))})).start(),a},t.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=R(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=!1;return t.then((function(t){r||(e&&e(t),r||i&&i())}),(function(t){r||n(t)})),{unsubscribe:function(){return r=!0}}},stop:function(){i=!0},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},t.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(t)}),(function(t){o.add(t)}))}catch(t){this.send(R(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},t.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(R(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},t.prototype.spawnActor=function(t){return this.children.set(t.id,t),t},t.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)}},t.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}}})},t.prototype.attachDev=function(){if(this.options.devTools&&"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){var t="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=window.__REDUX_DEVTOOLS_EXTENSION__.connect(i(i({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},t),{features:i({jump:!1,skip:!1},t?t.features:void 0)}),this.machine),this.devTools.init(this.state)}},t.prototype.toJSON=function(){return{id:this.id}},t.prototype[w]=function(){return this},t.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(e,n){return t.setTimeout.call(null,e,n)},clearTimeout:function(e){return t.clearTimeout.call(null,e)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"==typeof window?global:window),t.interpret=Z,t}();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({},Q),{name:t}):i(i(i({},Q),{name:b()}),t)}(e);return W(void 0,(function(e){return e?e.spawn(t,n.name,n):(void 0===(i=n.name)&&(i="null"),{id:i,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:i}}});var i}))},Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/dist/xstate.js
CHANGED
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
|
|
13
13
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
14
|
and limitations under the License.
|
|
15
|
-
***************************************************************************** */var e=function(){return(e=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 n(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}function i(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function r(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,r,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)a.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return a}function o(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(r(arguments[e]));return t}var a=".",s={},c="xstate.guard",u="";function h(t){return Object.keys(t)}function f(t,e,n){void 0===n&&(n=a);var i=p(t,n),r=p(e,n);return A(r)?!!A(i)&&r===i:A(i)?i in r:h(i).every((function(t){return t in r&&f(i[t],r[t])}))}function l(t){try{return A(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 d(t,e){try{return O(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}function p(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:O(t)?v(t):"string"!=typeof t?t:v(d(t,e));var n}function v(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 y(t,e){for(var n={},i=h(t),r=0;r<i.length;r++){var o=i[r];n[o]=e(t[o],o,t,r)}return n}function g(t,e,n){var r,o,a={};try{for(var s=i(h(t)),c=s.next();!c.done;c=s.next()){var u=c.value,f=t[u];n(f)&&(a[u]=e(f,u,t))}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}return a}var m=function(t){return function(e){var n,r,o=e;try{for(var a=i(t),s=a.next();!s.done;s=a.next()){o=o[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return o}};function x(t){return t?A(t)?[[t]]:S(h(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?x(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function S(t){var e;return(e=[]).concat.apply(e,o(t))}function w(t){return O(t)?t:[t]}function b(t){return void 0===t?[]:w(t)}function _(t,e,n){var r,o;if(P(t))return t(e,n.data);var a={};try{for(var s=i(h(t)),c=s.next();!c.done;c=s.next()){var u=c.value,f=t[u];P(f)?a[u]=f(e,n.data):a[u]=f}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}return a}function E(t){return t instanceof Promise||!(null===t||!P(t)&&"object"!=typeof t||!P(t.then))}function T(t,e){var n,o,a=r([[],[]],2),s=a[0],c=a[1];try{for(var u=i(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 N(t,e){return y(t.states,(function(t,n){if(t){var i=(A(e)?void 0:e[n])||(t?t.current:void 0);if(i)return{current:i,states:N(t,i)}}}))}function O(t){return Array.isArray(t)}function P(t){return"function"==typeof t}function A(t){return"string"==typeof t}function k(t,e){if(t)return A(t)?{type:c,name:t,predicate:e?e[t]:void 0}:P(t)?{type:c,name:t.name,predicate:t}:t}function V(t){try{return"subscribe"in t&&P(t.subscribe)}catch(t){return!1}}var I="function"==typeof Symbol&&Symbol.observable||"@@observable";function j(t){try{return"__xstatenode"in t}catch(t){return!1}}var L,C,M,R=(L=0,function(){return(++L).toString(16)});function D(t,n){return A(t)||"number"==typeof t?e({type:t},n):t}function F(t,n){if(!A(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var i=D(t);return e({name:i.type,data:i,$$type:"scxml",type:"external"},n)}function U(t,n){return w(n).map((function(n){return void 0===n||"string"==typeof n||j(n)?{target:n,event:t}:e(e({},n),{event:t})}))}(C=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",C.Stop="xstate.stop",C.Raise="xstate.raise",C.Send="xstate.send",C.Cancel="xstate.cancel",C.NullEvent="",C.Assign="xstate.assign",C.After="xstate.after",C.DoneState="done.state",C.DoneInvoke="done.invoke",C.Log="xstate.log",C.Init="xstate.init",C.Invoke="xstate.invoke",C.ErrorExecution="error.execution",C.ErrorCommunication="error.communication",C.ErrorPlatform="error.platform",C.ErrorCustom="xstate.error",C.Update="xstate.update",C.Pure="xstate.pure",(M=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",M.Internal="#_internal";var z=function(t){return"atomic"===t.type||"final"===t.type};function J(t){return h(t.states).map((function(e){return t.states[e]}))}function B(t){var e=[t];return z(t)?e:e.concat(S(J(t).map(B)))}function q(t,e){var n,r,o,a,s,c,u,h,f=$(new Set(t)),l=new Set(e);try{for(var d=i(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&&(r=d.return)&&r.call(d)}finally{if(n)throw n.error}}var y=$(l);try{for(var g=i(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,i(J(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=i(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 $(t){var e,n,r=new Map;try{for(var o=i(t),a=o.next();!a.done;a=o.next()){var s=a.value;r.has(s)||r.set(s,[]),s.parent&&(r.has(s.parent)||r.set(s.parent,[]),r.get(s.parent).push(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return r}function X(t,e){return function t(e,n){var i=n.get(e);if(!i)return{};if("compound"===e.type){var r=i[0];if(!r)return{};if(z(r))return r.key}var o={};return i.forEach((function(e){o[e.key]=t(e,n)})),o}(t,$(q([t],e)))}function G(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?J(e).some((function(e){return"final"===e.type&&G(t,e)})):"parallel"===e.type&&J(e).every((function(e){return H(t,e)}))}var K=t.ActionTypes.Start,Q=t.ActionTypes.Stop,W=t.ActionTypes.Raise,Y=t.ActionTypes.Send,Z=t.ActionTypes.Cancel,tt=t.ActionTypes.NullEvent,et=t.ActionTypes.Assign,nt=(t.ActionTypes.After,t.ActionTypes.DoneState,t.ActionTypes.Log),it=t.ActionTypes.Init,rt=t.ActionTypes.Invoke,ot=(t.ActionTypes.ErrorExecution,t.ActionTypes.ErrorPlatform),at=t.ActionTypes.ErrorCustom,st=t.ActionTypes.Update,ct=t.ActionTypes.Pure,ut=F({type:it});function ht(t,e){return e&&e[t]||void 0}function ft(t,i){var r;if(A(t)||"number"==typeof t){var o=ht(t,i);r=P(o)?{type:t,exec:o}:o||{type:t,exec:void 0}}else if(P(t))r={type:t.name||t.toString(),exec:t};else{if(P(o=ht(t.type,i)))r=e(e({},t),{exec:o});else if(o){var a=t.type,s=n(t,["type"]);r=e(e({type:a},o),s)}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?(O(t)?t:[t]).map((function(t){return ft(t,e)})):[]};function dt(t){var n=ft(t);return e(e({id:A(t)?t:n.id},n),{type:n.type})}function pt(e){return A(e)?{type:W,event:e}:vt(e,{to:t.SpecialTargets.Internal})}function vt(t,e){return{to:e?e.to:void 0,type:Y,event:P(t)?t:D(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:P(t)?t.name:l(t)}}function yt(n,i){return vt(n,e(e({},i),{to:t.SpecialTargets.Parent}))}function gt(){return yt(st)}var mt=function(t,e){return{context:t,event:e}};var xt=function(t){return{type:Z,sendId:t}};function St(e){var n=dt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function wt(e){var n=dt(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}var bt=function(t){return{type:et,assignment:t}};function _t(e,n){var i=n?"#"+n:"";return t.ActionTypes.After+"("+e+")"+i}function Et(e,n){var i=t.ActionTypes.DoneState+"."+e,r={type:i,data:n,toString:function(){return i}};return r}function Tt(e,n){var i=t.ActionTypes.DoneInvoke+"."+e,r={type:i,data:n,toString:function(){return i}};return r}function Nt(e,n){var i=t.ActionTypes.ErrorPlatform+"."+e,r={type:i,data:n,toString:function(){return i}};return r}function Ot(t,n){return vt((function(t,e){return e}),e(e({},n),{to:t}))}var Pt=function(){function t(t){this.actions=[],this.activities=s,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||s,this.meta=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=t.configuration,S(o(new Set(e.map((function(t){return t.ownEvents})))));var e}})}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 i=ut;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="."),A(t))return[t];var i=h(t);return i.concat.apply(i,o(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 n(this,["configuration","transitions"])},t.prototype.matches=function(t){return f(t,this.value)},t}();function At(t){try{return"function"==typeof t.send}catch(t){return!1}}var kt="",Vt={},It=function(t){return"#"===t[0]},jt=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},Lt=function(){function s(t,n,r){var c=this;this.config=t,this.context=r,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.options=Object.assign(jt(),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:a),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&&h(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.initial=this.config.initial,this.states=this.config.states?y(this.config.states,(function(t,n){var i,r=new s(t,{_parent:c,_key:n});return Object.assign(c.idMap,e(((i={})[r.id]=r,i),r.idMap)),r})):Vt;var u=0;!function t(e){var n,r;e.order=u++;try{for(var o=i(J(e)),a=o.next();!a.done;a=o.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some((function(t){return t.event===kt})):kt in this.config.on),this.strict=!!this.config.strict,this.onEntry=b(this.config.entry||this.config.onEntry).map((function(t){return ft(t)})),this.onExit=b(this.config.exit||this.config.onExit).map((function(t){return ft(t)})),this.meta=this.config.meta,this.data="final"===this.type?this.config.data:void 0,this.invoke=b(this.config.invoke).map((function(t,n){var i,r;if(j(t))return c.machine.options.services=e(((i={})[t.id]=t,i),c.machine.options.services),{type:rt,src:t.id,id:t.id};if("string"!=typeof t.src){var o=c.id+":invocation["+n+"]";return c.machine.options.services=e(((r={})[o]=t.src,r),c.machine.options.services),e(e({type:rt,id:o},t),{src:o})}return e(e({},t),{type:rt,id:t.id||t.src,src:t.src})})),this.activities=b(this.config.activities).concat(this.invoke).map((function(t){return dt(t)})),this.transition=this.transition.bind(this)}return s.prototype._init=function(){this.__cache.transitions||B(this).forEach((function(t){return t.on}))},s.prototype.withConfig=function(t,n){void 0===n&&(n=this.context);var i=this.options,r=i.actions,o=i.activities,a=i.guards,c=i.services,u=i.delays;return new s(this.config,{actions:e(e({},r),t.actions),activities:e(e({},o),t.activities),guards:e(e({},a),t.guards),services:e(e({},c),t.services),delays:e(e({},u),t.delays)},n)},s.prototype.withContext=function(t){return new s(this.config,this.options,t)},Object.defineProperty(s.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,type:this.type,initial:this.initial,history:this.history,states:y(this.states,(function(t){return t.definition})),on:this.on,transitions:this.transitions,onEntry:this.onEntry,onExit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.data,invoke:this.invoke}},enumerable:!0,configurable:!0}),s.prototype.toJSON=function(){return this.definition},Object.defineProperty(s.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:!0,configurable:!0}),Object.defineProperty(s.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!0,configurable:!0}),s.prototype.getCandidates=function(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];var e=t===kt,n=this.transitions.filter((function(n){var i=n.eventType===t;return e?i:i||"*"===n.eventType}));return this.__cache.candidates[t]=n,n},s.prototype.getDelayedTransitions=function(){var t=this,n=this.config.after;if(!n)return[];var i=function(e,n){var i=_t(P(e)?t.id+":delay["+n+"]":e,t.id);return t.onEntry.push(vt(i,{delay:e})),t.onExit.push(xt(i)),i};return(O(n)?n.map((function(t,n){var r=i(t.delay,n);return e(e({},t),{event:r})})):S(h(n).map((function(t,r){var o=n[t],a=A(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=i(s,r);return b(a).map((function(t){return e(e({},t),{event:c,delay:s})}))})))).map((function(n){var i=n.delay;return e(e({},t.formatTransition(n)),{delay:i})}))},s.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var i=t instanceof Pt?t.value:p(t,this.delimiter);if(A(i)){var r=this.getStateNode(i).initial;return void 0!==r?this.getStateNodes(((e={})[i]=r,e)):[this.states[i]]}var o=h(i);return o.map((function(t){return n.getStateNode(t)})).concat(o.reduce((function(t,e){var r=n.getStateNode(e).getStateNodes(i[e]);return t.concat(r)}),[]))},s.prototype.handles=function(t){var e=l(t);return this.events.includes(e)},s.prototype.resolveState=function(t){var n=Array.from(q([],this.getStateNodes(t.value)));return new Pt(e(e({},t),{value:this.resolve(t.value),configuration:n}))},s.prototype.transitionLeafNode=function(t,e,n){var i=this.getStateNode(t).next(e,n);return i&&i.transitions.length?i:this.next(e,n)},s.prototype.transitionCompoundNode=function(t,e,n){var i=h(t),r=this.getStateNode(i[0])._transition(t[i[0]],e,n);return r&&r.transitions.length?r:this.next(e,n)},s.prototype.transitionParallelNode=function(t,e,n){var r,o,a={};try{for(var s=i(h(t)),c=s.next();!c.done;c=s.next()){var u=c.value,f=t[u];if(f){var l=this.getStateNode(u)._transition(f,e,n);l&&(a[u]=l)}}}catch(t){r={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(r)throw r.error}}var d=h(a).map((function(t){return a[t]})),p=S(d.map((function(t){return t.transitions})));if(!d.some((function(t){return t.transitions.length>0})))return this.next(e,n);var v=S(d.map((function(t){return t.entrySet}))),y=S(h(a).map((function(t){return a[t].configuration})));return{transitions:p,entrySet:v,exitSet:S(d.map((function(t){return t.exitSet}))),configuration:y,source:e,actions:S(h(a).map((function(t){return a[t].actions})))}},s.prototype._transition=function(t,e,n){return A(t)?this.transitionLeafNode(t,e,n):1===h(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},s.prototype.next=function(t,e){var n,r,a,s=this,c=e.name,u=[],h=[];try{for(var l=i(this.getCandidates(c)),d=l.next();!d.done;d=l.next()){var v=d.value,y=v.cond,g=v.in,x=t.context,w=!g||(A(g)&&It(g)?t.matches(p(this.getStateNodeById(g).path,this.delimiter)):f(p(g,this.delimiter),m(this.path.slice(0,-2))(t.value))),b=!1;try{b=!y||this.evaluateGuard(y,x,e,t)}catch(t){throw new Error("Unable to evaluate guard '"+(y.name||y.type)+"' in transition for event '"+c+"' in state node '"+this.id+"':\n"+t.message)}if(b&&w){void 0!==v.target&&(h=v.target),u.push.apply(u,o(v.actions)),a=v;break}}}catch(t){n={error:t}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}if(a){if(!h.length)return{transitions:[a],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:u};var _=S(h.map((function(e){return s.getRelativeStateNodes(e,t.historyValue)}))),E=!!a.internal;return{transitions:[a],entrySet:E?[]:S(_.map((function(t){return s.nodesFromChild(t)}))),exitSet:E?[]:[this],configuration:_,source:t,actions:u}}},s.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},s.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},s.prototype.evaluateGuard=function(t,e,n,i){var r=this.machine.options.guards,o={state:i,cond:t,_event:n};if(t.type===c)return t.predicate(e,n.data,o);var a=r[t.type];if(!a)throw new Error("Guard '"+t.type+"' is not implemented on machine '"+this.machine.id+"'.");return a(e,n.data,o)},s.prototype.getActions=function(t,e,n,a){var s,c,u,h,f=q([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?q(f,t.configuration):f;try{for(var d=i(l),p=d.next();!p.done;p=d.next()){G(f,g=p.value)||t.entrySet.push(g)}}catch(t){s={error:t}}finally{try{p&&!p.done&&(c=d.return)&&c.call(d)}finally{if(s)throw s.error}}try{for(var v=i(f),y=v.next();!y.done;y=v.next()){var g;G(l,g=y.value)&&!G(t.exitSet,g.parent)||t.exitSet.push(g)}}catch(t){u={error:t}}finally{try{y&&!y.done&&(h=v.return)&&h.call(v)}finally{if(u)throw u.error}}t.source||(t.exitSet=[],t.entrySet.push(this));var m=S(t.entrySet.map((function(i){var r=[];if("final"!==i.type)return r;var o=i.parent;if(r.push(Et(i.id,i.data),Et(o.id,i.data?_(i.data,e,n):void 0)),o.parent){var a=o.parent;"parallel"===a.type&&J(a).every((function(e){return H(t.configuration,e)}))&&r.push(Et(a.id,a.data))}return r})));t.exitSet.sort((function(t,e){return e.order-t.order})),t.entrySet.sort((function(t,e){return t.order-e.order}));var x=new Set(t.entrySet),w=new Set(t.exitSet),b=r([S(Array.from(x).map((function(t){return o(t.activities.map((function(t){return St(t)})),t.onEntry)}))).concat(m.map(pt)),S(Array.from(w).map((function(t){return o(t.onExit,t.activities.map((function(t){return wt(t)})))})))],2),E=b[0],T=b[1];return lt(T.concat(t.actions).concat(E),this.machine.options.actions)},s.prototype.transition=function(t,e,n){void 0===t&&(t=this.initialState);var i,r,a=F(e);if(t instanceof Pt)i=void 0===n?t:this.resolveState(Pt.from(t,n));else{var s=A(t)?this.resolve(v(this.getResolvedPath(t))):this.resolve(t),c=n||this.machine.context;i=this.resolveState(Pt.from(s,c))}if(this.strict&&!this.events.includes(a.name)&&(r=a.name,!/^(done|error)\./.test(r)))throw new Error("Machine '"+this.id+"' does not accept event '"+a.name+"'");var u=this._transition(i.value,i,a)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:i,actions:[]},h=q([],this.getStateNodes(i.value)),f=u.configuration.length?q(h,u.configuration):h;return u.configuration=o(f),this.resolveTransition(u,i,a)},s.prototype.resolveRaisedTransition=function(t,e,n){var i,r=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(i=t.actions).unshift.apply(i,o(r)),t},s.prototype.resolveTransition=function(n,o,a,s){var c,u,f=this;void 0===a&&(a=ut),void 0===s&&(s=this.machine.context);var l=n.configuration,d=!o||n.transitions.length>0?X(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:s,y=this.getActions(n,v,a,o),g=o?e({},o.activities):{};try{for(var m=i(y),x=m.next();!x.done;x=m.next()){var w=x.value;w.type===K?g[w.activity.type]=w:w.type===Q&&(g[w.activity.type]=!1)}}catch(t){c={error:t}}finally{try{x&&!x.done&&(u=m.return)&&u.call(m)}finally{if(c)throw c.error}}var b,_,E=r(T(y,(function(t){return t.type===et})),2),O=E[0],k=E[1],V=O.length?function(t,e,n,r){return t?n.reduce((function(t,n){var o,a,s=n.assignment,c={state:r,action:n,_event:e},u={};if(P(s))u=s(t,e.data,c);else try{for(var f=i(h(s)),l=f.next();!l.done;l=f.next()){var d=l.value,p=s[d];u[d]=P(p)?p(t,e.data,c):p}}catch(t){o={error:t}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(o)throw o.error}}return Object.assign({},t,u)}),t):t}(v,a,O,o):v,I=S(k.map((function(t){switch(t.type){case W:return function(t){return{type:W,_event:F(t.event)}}(t);case Y:return function(t,n,i,r){var o,a={_event:i},s=F(P(t.event)?t.event(n,i.data,a):t.event);if(A(t.delay)){var c=r&&r[t.delay];o=P(c)?c(n,i.data,a):c}else o=P(t.delay)?t.delay(n,i.data,a):t.delay;var u=P(t.to)?t.to(n,i.data,a):t.to;return e(e({},t),{to:u,_event:s,event:s.data,delay:o})}(t,V,a,f.machine.options.delays);case nt:return function(t,n,i){return e(e({},t),{value:A(t.expr)?t.expr:t.expr(n,i.data,{_event:i})})}(t,V,a);case ct:return t.get(V,a.data)||[];default:return ft(t,f.options.actions)}}))),j=r(T(I,(function(e){return e.type===W||e.type===Y&&e.to===t.SpecialTargets.Internal})),2),L=j[0],C=j[1],M=I.filter((function(t){return t.type===K&&t.activity.type===rt})).reduce((function(t,e){var n,i,r;return t[e.activity.id]=(n=e.activity,(r={id:i=n.id,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:i}}}).meta=n,r),t}),o?e({},o.children):{}),R=d?n.configuration:o?o.configuration:[],D=R.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{}),U=H(R,this),z=new Pt({value:d||o.value,context:V,_event:a,_sessionid:o?o._sessionid:null,historyValue:d?p?(b=p,_=d,{current:_,states:N(b,_)}):void 0:o?o.historyValue:void 0,history:!d||n.source?o:void 0,actions:d?C:[],activities:d?g:o?o.activities:{},meta:d?D:o?o.meta:void 0,events:[],configuration:R,transitions:n.transitions,children:M,done:U});z.changed=a.name===st||!!O.length;var J=z.history;if(J&&delete J.history,!d)return z;var B=z;if(!U)for((this._transient||l.some((function(t){return t._transient})))&&(B=this.resolveRaisedTransition(B,{type:tt},a));L.length;){var q=L.shift();B=this.resolveRaisedTransition(B,q._event,a)}var $=B.changed||(J?!!B.actions.length||!!O.length||typeof J.value!=typeof B.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(A(e)||A(n))return e===n;var i=h(e),r=h(n);return i.length===r.length&&i.every((function(i){return t(e[i],n[i])}))}(B.value,J.value):void 0);return B.changed=$,B.historyValue=z.historyValue,B.history=J,B},s.prototype.getStateNode=function(t){if(It(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error("Unable to retrieve child state '"+t+"' from '"+this.id+"'; no child states exist.");var e=this.states[t];if(!e)throw new Error("Child state '"+t+"' does not exist on '"+this.id+"'");return e},s.prototype.getStateNodeById=function(t){var e=It(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},s.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&It(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=d(t,this.delimiter).slice(),n=this;e.length;){var i=e.shift();if(!i.length)break;n=n.getStateNode(i)}return n},s.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||Vt;switch(this.type){case"parallel":return y(this.initialStateValue,(function(e,i){return e?n.getStateNode(i).resolve(t[i]||e):Vt}));case"compound":if(A(t)){var i=this.getStateNode(t);return"parallel"===i.type||"compound"===i.type?((e={})[t]=i.initialStateValue,e):t}return h(t).length?y(t,(function(t,e){return t?n.getStateNode(e).resolve(t):Vt})):this.initialStateValue||{};default:return t||Vt}},s.prototype.getResolvedPath=function(t){if(It(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return d(t,this.delimiter)},Object.defineProperty(s.prototype,"initialStateValue",{get:function(){var t,e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;if("parallel"===this.type)e=g(this.states,(function(t){return t.initialStateValue||Vt}),(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=z(this.states[this.initial])?this.initial:((t={})[this.initial]=this.states[this.initial].initialStateValue,t)}return this.__cache.initialStateValue=e,this.__cache.initialStateValue},enumerable:!0,configurable:!0}),s.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(s.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:!0,configurable:!0}),Object.defineProperty(s.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=A(e.target)&&It(e.target)?v(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!0,configurable:!0}),s.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(s.prototype,"initialStateNodes",{get:function(){var t=this;return z(this)?[this]:"compound"!==this.type||this.initial?S(x(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!0,configurable:!0}),s.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=r(t),n=e[0],i=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(i)},s.prototype.historyValue=function(t){if(h(this.states).length)return{current:t||this.initialStateValue,states:g(this.states,(function(e,n){if(!t)return e.historyValue();var i=A(t)?void 0:t[n];return e.historyValue(i||e.initialStateValue)}),(function(t){return!t.history}))}},s.prototype.resolveHistory=function(t){var e=this;if("history"!==this.type)return[this];var n=this.parent;if(!t){var r=this.target;return r?S(x(r).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var o,a,s=(o=n.path,a="states",function(t){var e,n,r=t;try{for(var s=i(o),c=s.next();!c.done;c=s.next()){var u=c.value;r=r[a][u]}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return r})(t).current;return A(s)?[n.getStateNode(s)]:S(x(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(s.prototype,"stateIds",{get:function(){var t=this,e=S(h(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!0,configurable:!0}),Object.defineProperty(s.prototype,"events",{get:function(){var t,e,n,r;if(this.__cache.events)return this.__cache.events;var o=this.states,a=new Set(this.ownEvents);if(o)try{for(var s=i(h(o)),c=s.next();!c.done;c=s.next()){var u=o[c.value];if(u.states)try{for(var f=(n=void 0,i(u.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&&(r=f.return)&&r.call(f)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{c&&!c.done&&(e=s.return)&&e.call(s)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(a)},enumerable:!0,configurable:!0}),Object.defineProperty(s.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:!0,configurable:!0}),s.prototype.resolveTarget=function(t){var e=this;if(void 0!==t)return t.map((function(t){if(!A(t))return t;var n=t[0]===e.delimiter;if(n&&!e.parent)return e.getStateNodeByPath(t.slice(1));var i=n?e.key+t:t;if(!e.parent)return e.getStateNodeByPath(i);try{return e.parent.getStateNodeByPath(i)}catch(t){throw new Error("Invalid transition definition for state node '"+e.id+"':\n"+t.message)}}))},s.prototype.formatTransition=function(t){var n=this,i=function(t){if(void 0!==t&&t!==u)return b(t)}(t.target),r="internal"in t?t.internal:!i||i.some((function(t){return A(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(i);return e(e({},t),{actions:lt(b(t.actions)),cond:k(t.cond,o),target:a,source:this,internal:r,eventType:t.event})},s.prototype.formatTransitions=function(){var t,e,r,a=this;if(this.config.on)if(Array.isArray(this.config.on))r=this.config.on;else{var s=this.config.on,c=s["*"],u=void 0===c?[]:c,f=n(s,["*"]);r=S(h(f).map((function(t){return U(t,f[t])})).concat(U("*",u)))}else r=[];var l=this.config.onDone?U(String(Et(this.id)),this.config.onDone):[],d=S(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o(U(String(Tt(t.id)),t.onDone))),t.onError&&e.push.apply(e,o(U(String(Nt(t.id)),t.onError))),e}))),p=this.after,v=S(o(l,d,r).map((function(t){return b(t).map((function(t){return a.formatTransition(t)}))})));try{for(var y=i(p),g=y.next();!g.done;g=y.next()){var m=g.value;v.push(m)}}catch(e){t={error:e}}finally{try{g&&!g.done&&(e=y.return)&&e.call(y)}finally{if(t)throw t.error}}return v},s}();var Ct,Mt,Rt={deferEvents:!1},Dt=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=e(e({},Rt),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}(),Ft=new Map,Ut=0,zt={bookId:function(){return"x:"+Ut++},register:function(t,e){return Ft.set(t,e),t},get:function(t){return Ft.get(t)},free:function(t){Ft.delete(t)}},Jt={sync:!1,autoForward:!1},Bt=(Ct=[],function(t,e){t&&Ct.push(t);var n=e(t||Ct[Ct.length-1]);return t&&Ct.pop(),n});!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Mt||(Mt={}));var qt=function(){function n(i,r){var o=this;void 0===r&&(r=n.defaultOptions),this.machine=i,this.scheduler=new Dt,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=Mt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(t,e){if(O(t))return o.batch(t),o.state;var n=F(D(t,e));if(o._status===Mt.Stopped)return o.state;if(o._status===Mt.NotStarted&&o.options.deferEvents);else if(o._status!==Mt.Running)throw new Error('Event "'+n.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(n.data));return o.scheduler.schedule((function(){o.forward(n);var t=o.nextState(n);o.update(t,n)})),o._state},this.sendTo=function(n,i){var r=o.parent&&(i===t.SpecialTargets.Parent||o.parent.id===i),a=r?o.parent:At(i)?i:o.children.get(i)||zt.get(i);if(a)"machine"in a?a.send(e(e({},n),{name:n.name===at?""+Nt(o.id):n.name,origin:o.sessionId})):a.send(n.data);else if(!r)throw new Error("Unable to send event to child '"+i+"' from service '"+o.id+"'.")};var a=e(e({},n.defaultOptions),r),s=a.clock,c=a.logger,u=a.parent,h=a.id,f=void 0!==h?h:i.id;this.id=f,this.logger=c,this.clock=s,this.parent=u,this.options=a,this.scheduler=new Dt({deferEvents:this.options.deferEvents}),this.sessionId=zt.bookId()}return Object.defineProperty(n.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:Bt(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),n.prototype.execute=function(t,e){var n,r;try{for(var o=i(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&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},n.prototype.update=function(t,e){var n,r,o,a,s,c,u,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var l=i(this.eventListeners),d=l.next();!d.done;d=l.next()){(0,d.value)(t.event)}}catch(t){n={error:t}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}try{for(var p=i(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=i(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})),S=x&&x.data?_(x.data,t.context,e):void 0;try{for(var w=i(this.doneListeners),b=w.next();!b.done;b=w.next()){(0,b.value)(Tt(this.id,S))}}catch(t){u={error:t}}finally{try{b&&!b.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}this.stop()}},n.prototype.onTransition=function(t){return this.listeners.add(t),this._status===Mt.Running&&t(this.state,this.state.event),this},n.prototype.subscribe=function(t,e,n){var i,r=this;if(!t)return{unsubscribe:function(){}};var o=n;return"function"==typeof t?i=t:(i=t.next.bind(t),o=t.complete.bind(t)),this.listeners.add(i),this._status===Mt.Running&&i(this.state),o&&this.onDone(o),{unsubscribe:function(){i&&r.listeners.delete(i),o&&r.doneListeners.delete(o)}}},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(t){var e=this;if(this._status===Mt.Running)return this;zt.register(this.sessionId,this),this.initialized=!0,this._status=Mt.Running;var n=void 0===t?this.initialState:Bt(this,(function(){return!A(n=t)&&"value"in n&&"history"in n?e.machine.resolveState(t):e.machine.resolveState(Pt.from(t,e.machine.context));var n}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){e.update(n,ut)})),this},n.prototype.stop=function(){var t,e,n,r,o,a,s,c,u,f;try{for(var l=i(this.listeners),d=l.next();!d.done;d=l.next()){var p=d.value;this.listeners.delete(p)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(e=l.return)&&e.call(l)}finally{if(t)throw t.error}}try{for(var v=i(this.stopListeners),y=v.next();!y.done;y=v.next()){(p=y.value)(),this.stopListeners.delete(p)}}catch(t){n={error:t}}finally{try{y&&!y.done&&(r=v.return)&&r.call(v)}finally{if(n)throw n.error}}try{for(var g=i(this.contextListeners),m=g.next();!m.done;m=g.next()){p=m.value;this.contextListeners.delete(p)}}catch(t){o={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(o)throw o.error}}try{for(var x=i(this.doneListeners),S=x.next();!S.done;S=x.next()){p=S.value;this.doneListeners.delete(p)}}catch(t){s={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}finally{if(s)throw s.error}}this.children.forEach((function(t){P(t.stop)&&t.stop()}));try{for(var w=i(h(this.delayedEventsMap)),b=w.next();!b.done;b=w.next()){var _=b.value;this.clock.clearTimeout(this.delayedEventsMap[_])}}catch(t){u={error:t}}finally{try{b&&!b.done&&(f=w.return)&&f.call(w)}finally{if(u)throw u.error}}return this.scheduler.clear(),this.initialized=!1,this._status=Mt.Stopped,zt.free(this.sessionId),this},n.prototype.batch=function(t){var n=this;if(this._status===Mt.NotStarted&&this.options.deferEvents);else if(this._status!==Mt.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((function(){var r,a,s=n.state,c=!1,u=[],h=function(t){var i=F(t);n.forward(i),s=Bt(n,(function(){return n.machine.transition(s,i)})),u.push.apply(u,o(s.actions.map((function(t){return i=s,r=(n=t).exec,e(e({},n),{exec:void 0!==r?function(){return r(i.context,i.event,{action:n,state:i,_event:i._event})}:void 0});var n,i,r})))),c=c||!!s.changed};try{for(var f=i(t),l=f.next();!l.done;l=f.next()){h(l.value)}}catch(t){r={error:t}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(r)throw r.error}}s.changed=c,s.actions=u,n.update(s,F(t[t.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=F(t);if(0===n.name.indexOf(ot)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(ot)})))throw n.data.data;return Bt(this,(function(){return e.machine.transition(e.state,n)}))},n.prototype.forward=function(t){var e,n;try{for(var r=i(this.forwardTo),o=r.next();!o.done;o=r.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=r.return)&&n.call(r)}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,i){var r=n.context,o=n._event,a=ht(e.type,i)||e.exec,s=P(a)?a:a?a.exec:e.exec;if(s)try{return s(r,o.data,{action:e,state:this.state,_event:o})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case Y:var c=e;if("number"==typeof c.delay)return void this.defer(c);c.to?this.sendTo(c._event,c.to):this.send(c._event);break;case Z:this.cancel(e.sendId);break;case K:var u=e.activity;if(!this.state.activities[u.type])break;if(u.type===t.ActionTypes.Invoke){var h=this.machine.options.services?this.machine.options.services[u.src]:void 0,f=u.id,l=u.data,d="autoForward"in u?u.autoForward:!!u.forward;if(!h)return;var p=P(h)?h(r,o.data):h;E(p)?this.state.children[f]=this.spawnPromise(Promise.resolve(p),f):P(p)?this.state.children[f]=this.spawnCallback(p,f):V(p)?this.state.children[f]=this.spawnObservable(p,f):j(p)&&(this.state.children[f]=this.spawnMachine(l?p.withContext(_(l,r,o)):p,{id:f,autoForward:d}))}else this.spawnActivity(u);break;case Q:this.stopChild(e.activity.id);break;case nt:var v=e.label,y=e.value;v?this.logger(v,y):this.logger(y)}},n.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t],P(e.stop)&&e.stop())},n.prototype.spawn=function(t,n,i){if(E(t))return this.spawnPromise(Promise.resolve(t),n);if(P(t))return this.spawnCallback(t,n);if(At(t))return this.spawnActor(t);if(V(t))return this.spawnObservable(t,n);if(j(t))return this.spawnMachine(t,e(e({},i),{id:n}));throw new Error('Unable to spawn entity "'+n+'" of type "'+typeof t+'".')},n.prototype.spawnMachine=function(t,i){var r=this;void 0===i&&(i={});var o=new n(t,e(e({},this.options),{parent:this,id:i.id||t.id})),a=e(e({},Jt),i);a.sync&&o.onTransition((function(t){r.send(st,{state:t,id:o.id})})),o.onDone((function(t){r.send(F(t,{origin:o.id}))})).start();var s=o;return this.children.set(o.id,s),a.autoForward&&this.forwardTo.add(o.id),s},n.prototype.spawnPromise=function(t,e){var n=this,i=!1;t.then((function(t){i||n.send(F(Tt(e,t),{origin:e}))}),(function(t){if(!i){var r=Nt(e,t);try{n.send(F(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=!1;return t.then((function(t){r||(e&&e(t),r||i&&i())}),(function(t){r||n(t)})),{unsubscribe:function(){return r=!0}}},stop:function(){i=!0},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},n.prototype.spawnCallback=function(t,e){var n,i=this,r=!1,o=new Set,a=new Set;try{n=t((function(t){a.forEach((function(e){return e(t)})),r||i.send(t)}),(function(t){o.add(t)}))}catch(t){this.send(Nt(e,t))}if(E(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(){r=!0,P(n)&&n()},toJSON:function(){return{id:e}}};return this.children.set(e,s),s},n.prototype.spawnObservable=function(t,e){var n=this,i=t.subscribe((function(t){n.send(F(t,{origin:e}))}),(function(t){n.send(F(Nt(e,t),{origin:e}))}),(function(){n.send(F(Tt(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},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(){if(this.options.devTools&&"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){var t="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=window.__REDUX_DEVTOOLS_EXTENSION__.connect(e(e({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},t),{features:e({jump:!1,skip:!1},t?t.features:void 0)}),this.machine),this.devTools.init(this.state)}},n.prototype.toJSON=function(){return{id:this.id}},n.prototype[I]=function(){return this},n.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(e,n){return t.setTimeout.call(null,e,n)},clearTimeout:function(e){return t.clearTimeout.call(null,e)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"==typeof window?global:window),n.interpret=Gt,n}(),$t=function(t){return void 0===t&&(t="null"),{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:t}}}},Xt=function(t){return A(t)?e(e({},Jt),{name:t}):e(e(e({},Jt),{name:R()}),t)};function Gt(t,e){return new qt(t,e)}var Ht={raise:pt,send:vt,sendParent:yt,sendUpdate:gt,log:function(t,e){return void 0===t&&(t=mt),{type:nt,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,i){return yt((function(t,e,i){return{type:at,data:P(n)?n(t,e,i):n}}),e(e({},i),{to:t.SpecialTargets.Parent}))}};t.Interpreter=qt,t.Machine=function(t,e,n){void 0===n&&(n=t.context);var i="function"==typeof n?n():n;return new Lt(t,e,i)},t.State=Pt,t.StateNode=Lt,t.actions=Ht,t.assign=bt,t.createMachine=function(t,e){var n="function"==typeof t.context?t.context():t.context;return new Lt(t,e,n)},t.doneInvoke=Tt,t.forwardTo=Ot,t.interpret=Gt,t.mapState=function(t,e){var n,r,o;try{for(var a=i(h(t)),s=a.next();!s.done;s=a.next()){var c=s.value;f(c,e)&&(!o||e.length>o.length)&&(o=c)}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return t[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=i(e),u=c.next();!u.done;u=c.next()){var h=r(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=f,t.send=vt,t.sendParent=yt,t.sendUpdate=gt,t.spawn=function(t,e){var n=Xt(e);return Bt(void 0,(function(e){return e?e.spawn(t,n.name,n):$t(n.name)}))},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
15
|
+
***************************************************************************** */var e=function(){return(e=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 n(t,e){var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(n[i]=t[i]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(t);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(t,i[r])&&(n[i[r]]=t[i[r]])}return n}function i(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function r(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var i,r,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(i=o.next()).done;)a.push(i.value)}catch(t){r={error:t}}finally{try{i&&!i.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return a}function o(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(r(arguments[e]));return t}var a={};function s(t){return Object.keys(t)}function c(t,e,n){void 0===n&&(n=".");var i=f(t,n),r=f(e,n);return N(r)?!!N(i)&&r===i:N(i)?i in r:s(i).every((function(t){return t in r&&c(i[t],r[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,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 d(t,e){for(var n={},i=s(t),r=0;r<i.length;r++){var o=i[r];n[o]=e(t[o],o,t,r)}return n}function v(t,e,n){var r,o,a={};try{for(var c=i(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){r={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(r)throw r.error}}return a}var p=function(t){return function(e){var n,r,o=e;try{for(var a=i(t),s=a.next();!s.done;s=a.next()){o=o[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}return 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 r,o;if(T(t))return t(e,n.data);var a={};try{for(var c=i(s(t)),u=c.next();!u.done;u=c.next()){var h=u.value,f=t[h];T(f)?a[h]=f(e,n.data):a[h]=f}}catch(t){r={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(r)throw r.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=r([[],[]],2),s=a[0],c=a[1];try{for(var u=i(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 i=(N(e)?void 0:e[n])||(t?t.current:void 0);if(i)return{current:i,states:_(t,i)}}}))}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 P(t){try{return"subscribe"in t&&T(t.subscribe)}catch(t){return!1}}var A="function"==typeof Symbol&&Symbol.observable||"@@observable";function k(t){try{return"__xstatenode"in t}catch(t){return!1}}var V,j,C,I=(V=0,function(){return(++V).toString(16)});function L(t,n){return N(t)||"number"==typeof t?e({type:t},n):t}function M(t,n){if(!N(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var i=L(t);return e({name:i.type,data:i,$$type:"scxml",type:"external"},n)}function R(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 D(t,e,n,i,r){var o=t.options.guards,a={state:r,cond:e,_event:i};if("xstate.guard"===e.type)return e.predicate(n,i.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,i.data,a)}(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 z(t){var e=[t];return F(t)?e:e.concat(g(U(t).map(z)))}function J(t,e){var n,r,o,a,s,c,u,h,f=B(new Set(t)),l=new Set(e);try{for(var d=i(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&&(r=d.return)&&r.call(d)}finally{if(n)throw n.error}}var y=B(l);try{for(var g=i(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,i(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=i(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 B(t){var e,n,r=new Map;try{for(var o=i(t),a=o.next();!a.done;a=o.next()){var s=a.value;r.has(s)||r.set(s,[]),s.parent&&(r.has(s.parent)||r.set(s.parent,[]),r.get(s.parent).push(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return r}function q(t,e){return function t(e,n){var i=n.get(e);if(!i)return{};if("compound"===e.type){var r=i[0];if(!r)return{};if(F(r))return r.key}var o={};return i.forEach((function(e){o[e.key]=t(e,n)})),o}(t,B(J([t],e)))}function $(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function X(t,e){return"compound"===e.type?U(e).some((function(e){return"final"===e.type&&$(t,e)})):"parallel"===e.type&&U(e).every((function(e){return X(t,e)}))}var H=t.ActionTypes.Start,G=t.ActionTypes.Stop,K=t.ActionTypes.Raise,Q=t.ActionTypes.Send,W=t.ActionTypes.Cancel,Y=t.ActionTypes.NullEvent,Z=t.ActionTypes.Assign,tt=(t.ActionTypes.After,t.ActionTypes.DoneState,t.ActionTypes.Log),et=t.ActionTypes.Init,nt=t.ActionTypes.Invoke,it=(t.ActionTypes.ErrorExecution,t.ActionTypes.ErrorPlatform),rt=t.ActionTypes.ErrorCustom,ot=t.ActionTypes.Update,at=t.ActionTypes.Choose,st=t.ActionTypes.Pure,ct=M({type:et});function ut(t,e){return e&&e[t]||void 0}function ht(t,i){var r;if(N(t)||"number"==typeof t){var o=ut(t,i);r=T(o)?{type:t,exec:o}:o||{type:t,exec:void 0}}else if(T(t))r={type:t.name||t.toString(),exec:t};else{if(T(o=ut(t.type,i)))r=e(e({},t),{exec:o});else if(o){var a=t.type,s=n(t,["type"]);r=e(e({type:a},o),s)}else r=t}return Object.defineProperty(r,"toString",{value:function(){return r.type},enumerable:!1,configurable:!0}),r}var ft=function(t,e){return t?(E(t)?t:[t]).map((function(t){return ht(t,e)})):[]};function lt(t){var n=ht(t);return e(e({id:N(t)?t:n.id},n),{type:n.type})}function dt(e){return N(e)?{type:K,event:e}:vt(e,{to:t.SpecialTargets.Internal})}function vt(t,e){return{to:e?e.to:void 0,type:Q,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 pt(n,i){return vt(n,e(e({},i),{to:t.SpecialTargets.Parent}))}function yt(){return pt(ot)}var gt=function(t,e){return{context:t,event:e}};var mt=function(t){return{type:W,sendId:t}};function xt(e){var n=lt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function St(e){var n=lt(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}var wt=function(t){return{type:Z,assignment:t}};function bt(e,n){var i=n?"#"+n:"";return t.ActionTypes.After+"("+e+")"+i}function _t(e,n){var i=t.ActionTypes.DoneState+"."+e,r={type:i,data:n,toString:function(){return i}};return r}function Et(e,n){var i=t.ActionTypes.DoneInvoke+"."+e,r={type:i,data:n,toString:function(){return i}};return r}function Tt(e,n){var i=t.ActionTypes.ErrorPlatform+"."+e,r={type:i,data:n,toString:function(){return i}};return r}function Nt(t,n){return vt((function(t,e){return e}),e(e({},n),{to:t}))}function Ot(t,n,o,a,c){var u=r(b(c,(function(t){return t.type===Z})),2),h=u[0],f=u[1],l=h.length?function(t,e,n,r){return t?n.reduce((function(t,n){var o,a,c=n.assignment,u={state:r,action:n,_event:e},h={};if(T(c))h=c(t,e.data,u);else try{for(var f=i(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}(o,a,h,n):o;return[g(f.map((function(i){var r;switch(i.type){case K:return{type:K,_event:M(i.event)};case Q:return function(t,n,i,r){var o,a={_event:i},s=M(T(t.event)?t.event(n,i.data,a):t.event);if(N(t.delay)){var c=r&&r[t.delay];o=T(c)?c(n,i.data,a):c}else o=T(t.delay)?t.delay(n,i.data,a):t.delay;var u=T(t.to)?t.to(n,i.data,a):t.to;return e(e({},t),{to:u,_event:s,event:s.data,delay:o})}(i,l,a,t.options.delays);case tt:return function(t,n,i){return e(e({},t),{value:N(t.expr)?t.expr:t.expr(n,i.data,{_event:i})})}(i,l,a);case at:if(!(s=null===(r=i.conds.find((function(e){var i=O(e.cond,t.options.guards);return!i||D(t,i,l,a,n)})))||void 0===r?void 0:r.actions))return[];var o=Ot(t,n,l,a,ft(x(s)));return l=o[1],o[0];case st:var s;if(!(s=i.get(l,a.data)))return[];o=Ot(t,n,l,a,ft(x(s)));return l=o[1],o[0];default:return ht(i,t.options.actions)}}))),l]}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:ct,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var i=ct;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="."),N(t))return[t];var i=s(t);return i.concat.apply(i,o(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 n(this,["configuration","transitions"])},t.prototype.matches=function(t){return c(t,this.value)},t}();function At(t){try{return"function"==typeof t.send}catch(t){return!1}}var kt={},Vt=function(t){return"#"===t[0]},jt=function(){function a(t,n,r){var c=this;this.config=t,this.context=r,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.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.initial=this.config.initial,this.states=this.config.states?d(this.config.states,(function(t,n){var i,r=new a(t,{_parent:c,_key:n});return Object.assign(c.idMap,e(((i={})[r.id]=r,i),r.idMap)),r})):kt;var u=0;!function t(e){var n,r;e.order=u++;try{for(var o=i(U(e)),a=o.next();!a.done;a=o.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!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 ht(t)})),this.onExit=x(this.config.exit||this.config.onExit).map((function(t){return ht(t)})),this.meta=this.config.meta,this.data="final"===this.type?this.config.data:void 0,this.invoke=x(this.config.invoke).map((function(t,n){var i,r;if(k(t))return c.machine.options.services=e(((i={})[t.id]=t,i),c.machine.options.services),{type:nt,src:t.id,id:t.id};if("string"!=typeof t.src){var o=c.id+":invocation["+n+"]";return c.machine.options.services=e(((r={})[o]=t.src,r),c.machine.options.services),e(e({type:nt,id:o},t),{src:o})}return e(e({},t),{type:nt,id:t.id||t.src,src:t.src})})),this.activities=x(this.config.activities).concat(this.invoke).map((function(t){return lt(t)})),this.transition=this.transition.bind(this)}return a.prototype._init=function(){this.__cache.transitions||z(this).forEach((function(t){return t.on}))},a.prototype.withConfig=function(t,n){void 0===n&&(n=this.context);var i=this.options,r=i.actions,o=i.activities,s=i.guards,c=i.services,u=i.delays;return new a(this.config,{actions:e(e({},r),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.data,invoke:this.invoke}},enumerable:!0,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:!0,configurable:!0}),Object.defineProperty(a.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!0,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 i=n.eventType===t;return e?i:i||"*"===n.eventType}));return this.__cache.candidates[t]=n,n},a.prototype.getDelayedTransitions=function(){var t=this,n=this.config.after;if(!n)return[];var i=function(e,n){var i=bt(T(e)?t.id+":delay["+n+"]":e,t.id);return t.onEntry.push(vt(i,{delay:e})),t.onExit.push(mt(i)),i};return(E(n)?n.map((function(t,n){var r=i(t.delay,n);return e(e({},t),{event:r})})):g(s(n).map((function(t,r){var o=n[t],a=N(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=i(s,r);return x(a).map((function(t){return e(e({},t),{event:c,delay:s})}))})))).map((function(n){var i=n.delay;return e(e({},t.formatTransition(n)),{delay:i})}))},a.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var i=t instanceof Pt?t.value:f(t,this.delimiter);if(N(i)){var r=this.getStateNode(i).initial;return void 0!==r?this.getStateNodes(((e={})[i]=r,e)):[this.states[i]]}var o=s(i);return o.map((function(t){return n.getStateNode(t)})).concat(o.reduce((function(t,e){var r=n.getStateNode(e).getStateNodes(i[e]);return t.concat(r)}),[]))},a.prototype.handles=function(t){var e=u(t);return this.events.includes(e)},a.prototype.resolveState=function(t){var n=Array.from(J([],this.getStateNodes(t.value)));return new Pt(e(e({},t),{value:this.resolve(t.value),configuration:n}))},a.prototype.transitionLeafNode=function(t,e,n){var i=this.getStateNode(t).next(e,n);return i&&i.transitions.length?i:this.next(e,n)},a.prototype.transitionCompoundNode=function(t,e,n){var i=s(t),r=this.getStateNode(i[0])._transition(t[i[0]],e,n);return r&&r.transitions.length?r:this.next(e,n)},a.prototype.transitionParallelNode=function(t,e,n){var r,o,a={};try{for(var c=i(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){r={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(r)throw r.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,r,a,s=this,u=e.name,h=[],l=[];try{for(var d=i(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)&&Vt(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||D(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&&(r=d.return)&&r.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=J([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?J(f,t.configuration):f;try{for(var d=i(l),v=d.next();!v.done;v=d.next()){$(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=i(f),y=p.next();!y.done;y=p.next()){var m;$(l,m=y.value)&&!$(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(i){var r=[];if("final"!==i.type)return r;var o=i.parent;if(!o.parent)return r;r.push(_t(i.id,i.data),_t(o.id,i.data?S(i.data,e,n):void 0));var a=o.parent;return"parallel"===a.type&&U(a).every((function(e){return X(t.configuration,e)}))&&r.push(_t(a.id,a.data)),r})));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),_=r([g(Array.from(w).map((function(t){return o(t.activities.map((function(t){return xt(t)})),t.onEntry)}))).concat(x.map(dt)),g(Array.from(b).map((function(t){return o(t.onExit,t.activities.map((function(t){return St(t)})))})))],2),E=_[0],T=_[1];return ft(T.concat(t.actions).concat(E),this.machine.options.actions)},a.prototype.transition=function(t,e,n){void 0===t&&(t=this.initialState);var i,r,a=M(e);if(t instanceof Pt)i=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;i=this.resolveState(Pt.from(s,c))}if(this.strict&&!this.events.includes(a.name)&&(r=a.name,!/^(done|error)\./.test(r)))throw new Error("Machine '"+this.id+"' does not accept event '"+a.name+"'");var u=this._transition(i.value,i,a)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:i,actions:[]},h=J([],this.getStateNodes(i.value)),f=u.configuration.length?J(h,u.configuration):h;return u.configuration=o(f),this.resolveTransition(u,i,a)},a.prototype.resolveRaisedTransition=function(t,e,n){var i,r=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(i=t.actions).unshift.apply(i,o(r)),t},a.prototype.resolveTransition=function(n,o,a,c){var u,h;void 0===a&&(a=ct),void 0===c&&(c=this.machine.context);var f=n.configuration,l=!o||n.transitions.length>0?q(this.machine,f):void 0,d=o?o.historyValue?o.historyValue:n.source?this.machine.historyValue(o.value):void 0:void 0,v=o?o.context:c,p=this.getActions(n,v,a,o),y=o?e({},o.activities):{};try{for(var g=i(p),m=g.next();!m.done;m=g.next()){var x=m.value;x.type===H?y[x.activity.type]=x:x.type===G&&(y[x.activity.type]=!1)}}catch(t){u={error:t}}finally{try{m&&!m.done&&(h=g.return)&&h.call(g)}finally{if(u)throw u.error}}var S,w,E=r(Ot(this,o,v,a,p),2),T=E[0],O=E[1],P=r(b(T,(function(e){return e.type===K||e.type===Q&&e.to===t.SpecialTargets.Internal})),2),A=P[0],k=P[1],V=T.filter((function(t){return t.type===H&&t.activity.type===nt})).reduce((function(t,e){var n,i,r;return t[e.activity.id]=(n=e.activity,(r={id:i=n.id,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:i}}}).meta=n,r),t}),o?e({},o.children):{}),j=l?n.configuration:o?o.configuration:[],C=j.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{}),I=X(j,this),L=new Pt({value:l||o.value,context:O,_event:a,_sessionid:o?o._sessionid:null,historyValue:l?d?(S=d,w=l,{current:w,states:_(S,w)}):void 0:o?o.historyValue:void 0,history:!l||n.source?o:void 0,actions:l?k:[],activities:l?y:o?o.activities:{},meta:l?C:o?o.meta:void 0,events:[],configuration:j,transitions:n.transitions,children:V,done:I}),M=v!==O;L.changed=a.name===ot||M;var R=L.history;if(R&&delete R.history,!l)return L;var D=L;if(!I)for((this._transient||f.some((function(t){return t._transient})))&&(D=this.resolveRaisedTransition(D,{type:Y},a));A.length;){var F=A.shift();D=this.resolveRaisedTransition(D,F._event,a)}var U=D.changed||(R?!!D.actions.length||M||typeof R.value!=typeof D.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 i=s(e),r=s(n);return i.length===r.length&&i.every((function(i){return t(e[i],n[i])}))}(D.value,R.value):void 0);return D.changed=U,D.historyValue=L.historyValue,D.history=R,D},a.prototype.getStateNode=function(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.");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=Vt(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&&Vt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=h(t,this.delimiter).slice(),n=this;e.length;){var i=e.shift();if(!i.length)break;n=n.getStateNode(i)}return n},a.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||kt;switch(this.type){case"parallel":return d(this.initialStateValue,(function(e,i){return e?n.getStateNode(i).resolve(t[i]||e):kt}));case"compound":if(N(t)){var i=this.getStateNode(t);return"parallel"===i.type||"compound"===i.type?((e={})[t]=i.initialStateValue,e):t}return s(t).length?d(t,(function(t,e){return t?n.getStateNode(e).resolve(t):kt})):this.initialStateValue||{};default:return t||kt}},a.prototype.getResolvedPath=function(t){if(Vt(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||kt}),(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:!0,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:!0,configurable:!0}),Object.defineProperty(a.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=N(e.target)&&Vt(e.target)?l(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!0,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:!0,configurable:!0}),a.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=r(t),n=e[0],i=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(i)},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 i=N(t)?void 0:t[n];return e.historyValue(i||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 r=this.target;return r?g(y(r).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var o,a,s=(o=n.path,a="states",function(t){var e,n,r=t;try{for(var s=i(o),c=s.next();!c.done;c=s.next()){var u=c.value;r=r[a][u]}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return r})(t).current;return 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:!0,configurable:!0}),Object.defineProperty(a.prototype,"events",{get:function(){var t,e,n,r;if(this.__cache.events)return this.__cache.events;var o=this.states,a=new Set(this.ownEvents);if(o)try{for(var c=i(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,i(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&&(r=f.return)&&r.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:!0,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:!0,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 i=n?e.key+t:t;if(!e.parent)return e.getStateNodeByPath(i);try{return e.parent.getStateNodeByPath(i)}catch(t){throw new Error("Invalid transition definition for state node '"+e.id+"':\n"+t.message)}}))},a.prototype.formatTransition=function(t){var n=this,i=function(t){if(void 0!==t&&""!==t)return x(t)}(t.target),r="internal"in t?t.internal:!i||i.some((function(t){return N(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(i),s=e(e({},t),{actions:ft(x(t.actions)),cond:O(t.cond,o),target:a,source:this,internal:r,eventType:t.event});return Object.defineProperty(s,"toJSON",{value:function(){return e(e({},s),{target:s.target?s.target.map((function(t){return"#"+t.id})):void 0,source:"#{this.id}"})}}),s},a.prototype.formatTransitions=function(){var t,e,r,a=this;if(this.config.on)if(Array.isArray(this.config.on))r=this.config.on;else{var c=this.config.on,u=c["*"],h=void 0===u?[]:u,f=n(c,["*"]);r=g(s(f).map((function(t){return R(t,f[t])})).concat(R("*",h)))}else r=[];var l=this.config.onDone?R(String(_t(this.id)),this.config.onDone):[],d=g(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o(R(String(Et(t.id)),t.onDone))),t.onError&&e.push.apply(e,o(R(String(Tt(t.id)),t.onError))),e}))),v=this.after,p=g(o(l,d,r).map((function(t){return x(t).map((function(t){return a.formatTransition(t)}))})));try{for(var y=i(v),m=y.next();!m.done;m=y.next()){var S=m.value;p.push(S)}}catch(e){t={error:e}}finally{try{m&&!m.done&&(e=y.return)&&e.call(y)}finally{if(t)throw t.error}}return p},a}();var Ct,It,Lt={deferEvents:!1},Mt=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=e(e({},Lt),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}(),Rt=new Map,Dt=0,Ft=function(){return"x:"+Dt++},Ut=function(t,e){return Rt.set(t,e),t},zt=function(t){return Rt.get(t)},Jt=function(t){Rt.delete(t)},Bt={sync:!1,autoForward:!1},qt=(Ct=[],function(t,e){t&&Ct.push(t);var n=e(t||Ct[Ct.length-1]);return t&&Ct.pop(),n});!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(It||(It={}));var $t=function(){function n(i,r){var o=this;void 0===r&&(r=n.defaultOptions),this.machine=i,this.scheduler=new Mt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this._status=It.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(t,e){if(E(t))return o.batch(t),o.state;var n=M(L(t,e));if(o._status===It.Stopped)return o.state;if(o._status===It.NotStarted&&o.options.deferEvents);else if(o._status!==It.Running)throw new Error('Event "'+n.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(n.data));return o.scheduler.schedule((function(){o.forward(n);var t=o.nextState(n);o.update(t,n)})),o._state},this.sendTo=function(n,i){var r=o.parent&&(i===t.SpecialTargets.Parent||o.parent.id===i),a=r?o.parent:At(i)?i:o.children.get(i)||zt(i);if(a)"machine"in a?a.send(e(e({},n),{name:n.name===rt?""+Tt(o.id):n.name,origin:o.sessionId})):a.send(n.data);else if(!r)throw new Error("Unable to send event to child '"+i+"' from service '"+o.id+"'.")};var a=e(e({},n.defaultOptions),r),s=a.clock,c=a.logger,u=a.parent,h=a.id,f=void 0!==h?h:i.id;this.id=f,this.logger=c,this.clock=s,this.parent=u,this.options=a,this.scheduler=new Mt({deferEvents:this.options.deferEvents}),this.sessionId=Ft()}return Object.defineProperty(n.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:qt(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"state",{get:function(){return this._state},enumerable:!0,configurable:!0}),n.prototype.execute=function(t,e){var n,r;try{for(var o=i(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&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},n.prototype.update=function(t,e){var n,r,o,a,s,c,u,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var l=i(this.eventListeners),d=l.next();!d.done;d=l.next()){(0,d.value)(t.event)}}catch(t){n={error:t}}finally{try{d&&!d.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}try{for(var v=i(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=i(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=X(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.data?S(x.data,t.context,e):void 0;try{for(var b=i(this.doneListeners),_=b.next();!_.done;_=b.next()){(0,_.value)(Et(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(t){return this.listeners.add(t),this._status===It.Running&&t(this.state,this.state.event),this},n.prototype.subscribe=function(t,e,n){var i,r=this;if(!t)return{unsubscribe:function(){}};var o=n;return"function"==typeof t?i=t:(i=t.next.bind(t),o=t.complete.bind(t)),this.listeners.add(i),this._status===It.Running&&i(this.state),o&&this.onDone(o),{unsubscribe:function(){i&&r.listeners.delete(i),o&&r.doneListeners.delete(o)}}},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(t){var e=this;if(this._status===It.Running)return this;Ut(this.sessionId,this),this.initialized=!0,this._status=It.Running;var n=void 0===t?this.initialState:qt(this,(function(){return!N(n=t)&&"value"in n&&"history"in n?e.machine.resolveState(t):e.machine.resolveState(Pt.from(t,e.machine.context));var n}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){e.update(n,ct)})),this},n.prototype.stop=function(){var t,e,n,r,o,a,c,u,h,f;try{for(var l=i(this.listeners),d=l.next();!d.done;d=l.next()){var v=d.value;this.listeners.delete(v)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(e=l.return)&&e.call(l)}finally{if(t)throw t.error}}try{for(var p=i(this.stopListeners),y=p.next();!y.done;y=p.next()){(v=y.value)(),this.stopListeners.delete(v)}}catch(t){n={error:t}}finally{try{y&&!y.done&&(r=p.return)&&r.call(p)}finally{if(n)throw n.error}}try{for(var g=i(this.contextListeners),m=g.next();!m.done;m=g.next()){v=m.value;this.contextListeners.delete(v)}}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 x=i(this.doneListeners),S=x.next();!S.done;S=x.next()){v=S.value;this.doneListeners.delete(v)}}catch(t){c={error:t}}finally{try{S&&!S.done&&(u=x.return)&&u.call(x)}finally{if(c)throw c.error}}this.children.forEach((function(t){T(t.stop)&&t.stop()}));try{for(var w=i(s(this.delayedEventsMap)),b=w.next();!b.done;b=w.next()){var _=b.value;this.clock.clearTimeout(this.delayedEventsMap[_])}}catch(t){h={error:t}}finally{try{b&&!b.done&&(f=w.return)&&f.call(w)}finally{if(h)throw h.error}}return this.scheduler.clear(),this.initialized=!1,this._status=It.Stopped,Jt(this.sessionId),this},n.prototype.batch=function(t){var n=this;if(this._status===It.NotStarted&&this.options.deferEvents);else if(this._status!==It.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((function(){var r,a,s=n.state,c=!1,u=[],h=function(t){var i=M(t);n.forward(i),s=qt(n,(function(){return n.machine.transition(s,i)})),u.push.apply(u,o(s.actions.map((function(t){return i=s,r=(n=t).exec,e(e({},n),{exec:void 0!==r?function(){return r(i.context,i.event,{action:n,state:i,_event:i._event})}:void 0});var n,i,r})))),c=c||!!s.changed};try{for(var f=i(t),l=f.next();!l.done;l=f.next()){h(l.value)}}catch(t){r={error:t}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(r)throw r.error}}s.changed=c,s.actions=u,n.update(s,M(t[t.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=M(t);if(0===n.name.indexOf(it)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(it)})))throw n.data.data;return qt(this,(function(){return e.machine.transition(e.state,n)}))},n.prototype.forward=function(t){var e,n;try{for(var r=i(this.forwardTo),o=r.next();!o.done;o=r.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=r.return)&&n.call(r)}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,i){var r=n.context,o=n._event,a=ut(e.type,i)||e.exec,s=T(a)?a:a?a.exec:e.exec;if(s)try{return s(r,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 Q: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 W:this.cancel(e.sendId);break;case H:var u=e.activity;if(!this.state.activities[u.type])break;if(u.type===t.ActionTypes.Invoke){var h=this.machine.options.services?this.machine.options.services[u.src]:void 0,f=u.id,l=u.data,d="autoForward"in u?u.autoForward:!!u.forward;if(!h)return;var v=T(h)?h(r,o.data):h;w(v)?this.state.children[f]=this.spawnPromise(Promise.resolve(v),f):T(v)?this.state.children[f]=this.spawnCallback(v,f):P(v)?this.state.children[f]=this.spawnObservable(v,f):k(v)&&(this.state.children[f]=this.spawnMachine(l?v.withContext(S(l,r,o)):v,{id:f,autoForward:d}))}else this.spawnActivity(u);break;case G:this.stopChild(e.activity.id);break;case tt:var p=e.label,y=e.value;p?this.logger(p,y):this.logger(y)}},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,i){if(w(t))return this.spawnPromise(Promise.resolve(t),n);if(T(t))return this.spawnCallback(t,n);if(At(t))return this.spawnActor(t);if(P(t))return this.spawnObservable(t,n);if(k(t))return this.spawnMachine(t,e(e({},i),{id:n}));throw new Error('Unable to spawn entity "'+n+'" of type "'+typeof t+'".')},n.prototype.spawnMachine=function(t,i){var r=this;void 0===i&&(i={});var o=new n(t,e(e({},this.options),{parent:this,id:i.id||t.id})),a=e(e({},Bt),i);a.sync&&o.onTransition((function(t){r.send(ot,{state:t,id:o.id})}));var s=o;return this.children.set(o.id,s),a.autoForward&&this.forwardTo.add(o.id),o.onDone((function(t){r.removeChild(o.id),r.send(M(t,{origin:o.id}))})).start(),s},n.prototype.spawnPromise=function(t,e){var n=this,i=!1;t.then((function(t){i||(n.removeChild(e),n.send(M(Et(e,t),{origin:e})))}),(function(t){if(!i){n.removeChild(e);var r=Tt(e,t);try{n.send(M(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=!1;return t.then((function(t){r||(e&&e(t),r||i&&i())}),(function(t){r||n(t)})),{unsubscribe:function(){return r=!0}}},stop:function(){i=!0},toJSON:function(){return{id:e}}};return this.children.set(e,r),r},n.prototype.spawnCallback=function(t,e){var n,i=this,r=!1,o=new Set,a=new Set;try{n=t((function(t){a.forEach((function(e){return e(t)})),r||i.send(t)}),(function(t){o.add(t)}))}catch(t){this.send(Tt(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(){r=!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,i=t.subscribe((function(t){n.send(M(t,{origin:e}))}),(function(t){n.removeChild(e),n.send(M(Tt(e,t),{origin:e}))}),(function(){n.removeChild(e),n.send(M(Et(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},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(){if(this.options.devTools&&"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){var t="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=window.__REDUX_DEVTOOLS_EXTENSION__.connect(e(e({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},t),{features:e({jump:!1,skip:!1},t?t.features:void 0)}),this.machine),this.devTools.init(this.state)}},n.prototype.toJSON=function(){return{id:this.id}},n.prototype[A]=function(){return this},n.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(e,n){return t.setTimeout.call(null,e,n)},clearTimeout:function(e){return t.clearTimeout.call(null,e)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"==typeof window?global:window),n.interpret=Xt,n}();function Xt(t,e){return new $t(t,e)}var Ht={raise:dt,send:vt,sendParent:pt,sendUpdate:yt,log:function(t,e){return void 0===t&&(t=gt),{type:tt,label:e,expr:t}},cancel:mt,start:xt,stop:St,assign:wt,after:bt,done:_t,respond:function(t,n){return vt(t,e(e({},n),{to:function(t,e,n){return n._event.origin}}))},forwardTo:Nt,escalate:function(n,i){return pt((function(t,e,i){return{type:rt,data:T(n)?n(t,e,i):n}}),e(e({},i),{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=$t,t.Machine=function(t,e,n){void 0===n&&(n=t.context);var i="function"==typeof n?n():n;return new jt(t,e,i)},t.State=Pt,t.StateNode=jt,t.actions=Ht,t.assign=wt,t.createMachine=function(t,e){var n="function"==typeof t.context?t.context():t.context;return new jt(t,e,n)},t.doneInvoke=Et,t.forwardTo=Nt,t.interpret=Xt,t.mapState=function(t,e){var n,r,o;try{for(var a=i(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&&(r=a.return)&&r.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=i(e),u=c.next();!u.done;u=c.next()){var h=r(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=pt,t.sendUpdate=yt,t.spawn=function(t,n){var i=function(t){return N(t)?e(e({},Bt),{name:t}):e(e(e({},Bt),{name:I()}),t)}(n);return qt(void 0,(function(e){return e?e.spawn(t,i.name,i):(void 0===(n=i.name)&&(n="null"),{id:n,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:n}}});var n}))},Object.defineProperty(t,"__esModule",{value:!0})}));
|