xstate 4.9.1 → 4.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/xstate.interpreter.js +1 -1
- package/dist/xstate.js +1 -1
- package/dist/xstate.web.js +1 -1
- package/es/Machine.d.ts +4 -1
- package/es/State.d.ts +9 -4
- package/es/StateNode.d.ts +4 -1
- package/es/StateNode.js +10 -7
- package/es/actions.d.ts +12 -10
- package/es/actions.js +2 -2
- package/es/interpreter.d.ts +11 -11
- package/es/interpreter.js +6 -2
- package/es/types.d.ts +14 -7
- package/lib/Machine.d.ts +4 -1
- package/lib/State.d.ts +9 -4
- package/lib/StateNode.d.ts +4 -1
- package/lib/StateNode.js +7 -7
- package/lib/actions.d.ts +12 -10
- package/lib/actions.js +2 -2
- package/lib/interpreter.d.ts +11 -11
- package/lib/interpreter.js +4 -2
- package/lib/types.d.ts +14 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# xstate
|
|
2
2
|
|
|
3
|
+
## 4.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`0133954`](https://github.com/davidkpiano/xstate/commit/013395463b955e950ab24cb4be51faf524b0de6e) [#1178](https://github.com/davidkpiano/xstate/pull/1178) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The types for the `send()` and `sendParent()` action creators have been changed to fix the issue of only being able to send events that the machine can receive. In reality, a machine can and should send events to other actors that it might not be able to receive itself. See [#711](https://github.com/davidkpiano/xstate/issues/711) for more information.
|
|
8
|
+
|
|
9
|
+
* [`a1f1239`](https://github.com/davidkpiano/xstate/commit/a1f1239e20e05e338ed994d031e7ef6f2f09ad68) [#1189](https://github.com/davidkpiano/xstate/pull/1189) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Previously, `state.matches(...)` was problematic because it was casting `state` to `never` if it didn't match the state value. This is now fixed by making the `Typestate` resolution more granular.
|
|
10
|
+
|
|
11
|
+
- [`dbc6a16`](https://github.com/davidkpiano/xstate/commit/dbc6a161c068a3e12dd12452b68a66fe3f4fb8eb) [#1183](https://github.com/davidkpiano/xstate/pull/1183) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Actions from a restored state provided as a custom initial state to `interpret(machine).start(initialState)` are now executed properly. See #1174 for more information.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`a10d604`](https://github.com/davidkpiano/xstate/commit/a10d604a6afcf39048b02be5436acdd197f16c2b) [#1176](https://github.com/davidkpiano/xstate/pull/1176) Thanks [@itfarrier](https://github.com/itfarrier)! - Fix passing state schema into State generic
|
|
16
|
+
|
|
17
|
+
* [`326db72`](https://github.com/davidkpiano/xstate/commit/326db725e50f7678af162626c6c7491e4364ec07) [#1185](https://github.com/davidkpiano/xstate/pull/1185) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with invoked service not being correctly started if other service got stopped in a subsequent microstep (in response to raised or null event).
|
|
18
|
+
|
|
19
|
+
- [`c3a496e`](https://github.com/davidkpiano/xstate/commit/c3a496e1f92ec27db0643fd1ddc32d683db4e751) [#1160](https://github.com/davidkpiano/xstate/pull/1160) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Delayed transitions defined using `after` were previously causing a circular dependency when the machine was converted using `.toJSON()`. This has now been fixed.
|
|
20
|
+
|
|
21
|
+
* [`e16e48e`](https://github.com/davidkpiano/xstate/commit/e16e48e05e6243a3eacca58a13d3e663cd641f55) [#1153](https://github.com/davidkpiano/xstate/pull/1153) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with `choose` and `pure` not being able to use actions defined in options.
|
|
22
|
+
|
|
23
|
+
- [`d496ecb`](https://github.com/davidkpiano/xstate/commit/d496ecb11b26011f2382d1ce6c4433284a7b3e9b) [#1165](https://github.com/davidkpiano/xstate/pull/1165) Thanks [@davidkpiano](https://github.com/davidkpiano)! - XState will now warn if you define an `.onDone` transition on the root node. Root nodes which are "done" represent the machine being in its final state, and can no longer accept any events. This has been reported as confusing in [#1111](https://github.com/davidkpiano/xstate/issues/1111).
|
|
24
|
+
|
|
3
25
|
## 4.9.1
|
|
4
26
|
|
|
5
27
|
### 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",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})}));
|
|
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){void 0===i&&(i=this.machine.options.actions);var r=n.context,o=n._event,s=t.exec||function(t,e){return e&&e[t]||void 0}(t.type,i),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.id||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={};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})}));
|
|
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,C,j,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)}(C=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",C.Stop="xstate.stop",C.Raise="xstate.raise",C.Send="xstate.send",C.Cancel="xstate.cancel",C.NullEvent="",C.Assign="xstate.assign",C.After="xstate.after",C.DoneState="done.state",C.DoneInvoke="done.invoke",C.Log="xstate.log",C.Init="xstate.init",C.Invoke="xstate.invoke",C.ErrorExecution="error.execution",C.ErrorCommunication="error.communication",C.ErrorPlatform="error.platform",C.ErrorCustom="xstate.error",C.Update="xstate.update",C.Pure="xstate.pure",C.Choose="xstate.choose",(j=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",j.Internal="#_internal";var F=function(t){return"atomic"===t.type||"final"===t.type};function U(t){return s(t.states).map((function(e){return t.states[e]}))}function 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),t.options.actions));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),t.options.actions));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]},Ct=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.id||x.activity.type]=x:x.type===G&&(y[x.activity.id||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):{}),C=l?n.configuration:o?o.configuration:[],j=C.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{}),I=X(C,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?j:o?o.meta:void 0,events:[],configuration:C,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,toJSON:function(){return e(e({},s),{target:s.target?s.target.map((function(t){return"#"+t.id})):void 0,source:"#{this.id}"})}});return 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 jt,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=(jt=[],function(t,e){t&&jt.push(t);var n=e(t||jt[jt.length-1]);return t&&jt.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){void 0===i&&(i=this.machine.options.actions);var r=n.context,o=n._event,a=e.exec||ut(e.type,i),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.id||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 Ct(t,e,i)},t.State=Pt,t.StateNode=Ct,t.actions=Ht,t.assign=wt,t.createMachine=function(t,e){var n="function"==typeof t.context?t.context():t.context;return new Ct(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})}));
|
package/dist/xstate.web.js
CHANGED
|
@@ -12,4 +12,4 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
12
12
|
|
|
13
13
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
14
|
and limitations under the License.
|
|
15
|
-
***************************************************************************** */function P(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(i[s[n]]=t[s[n]])}return i}var V,C;!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(V||(V={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(C||(C={}));const I=t=>"atomic"===t.type||"final"===t.type;function L(t){return e(t.states).map(e=>t.states[e])}function A(t){const e=[t];return I(t)?e:e.concat(u(L(t).map(A)))}function R(t,e){const i=M(new Set(t)),s=new Set(e);for(const t of s){let e=t.parent;for(;e&&!s.has(e);)s.add(e),e=e.parent}const n=M(s);for(const t of s)if("compound"!==t.type||n.get(t)&&n.get(t).length){if("parallel"===t.type)for(const e of L(t))"history"!==e.type&&(s.has(e)||(s.add(e),i.get(e)?i.get(e).forEach(t=>s.add(t)):e.initialStateNodes.forEach(t=>s.add(t))))}else i.get(t)?i.get(t).forEach(t=>s.add(t)):t.initialStateNodes.forEach(t=>s.add(t));for(const t of s){let e=t.parent;for(;e&&!s.has(e);)s.add(e),e=e.parent}return s}function M(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function D(t,e){return function t(e,i){const s=i.get(e);if(!s)return{};if("compound"===e.type){const t=s[0];if(!t)return{};if(I(t))return t.key}const n={};return s.forEach(e=>{n[e.key]=t(e,i)}),n}(t,M(R([t],e)))}function F(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function z(t,e){return"compound"===e.type?L(e).some(e=>"final"===e.type&&F(t,e)):"parallel"===e.type&&L(e).every(e=>z(t,e))}const J=V.Start,U=V.Stop,B=V.Raise,q=V.Send,X=V.Cancel,H=V.NullEvent,G=V.Assign,K=(V.After,V.DoneState,V.Log),Q=V.Init,W=V.Invoke,Y=(V.ErrorExecution,V.ErrorPlatform),Z=V.ErrorCustom,tt=V.Update,et=V.Choose,it=V.Pure,st=N({type:Q});function nt(t,e){return e&&e[t]||void 0}function ot(t,e){let i;if(S(t)||"number"==typeof t){const s=nt(t,e);i=b(s)?{type:t,exec:s}:s||{type:t,exec:void 0}}else if(b(t))i={type:t.name||t.toString(),exec:t};else{const s=nt(t.type,e);if(b(s))i=Object.assign(Object.assign({},t),{exec:s});else if(s){const{type:e}=t,n=P(t,["type"]);i=Object.assign(Object.assign({type:e},s),n)}else i=t}return Object.defineProperty(i,"toString",{value:()=>i.type,enumerable:!1,configurable:!0}),i}const rt=(t,e)=>{if(!t)return[];return(m(t)?t:[t]).map(t=>ot(t,e))};function at(t){const e=ot(t);return Object.assign(Object.assign({id:S(t)?t:e.id},e),{type:e.type})}function ct(t){return S(t)?{type:B,event:t}:ht(t,{to:C.Internal})}function ht(t,e){return{to:e?e.to:void 0,type:q,event:b(t)?t:j(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:b(t)?t.name:s(t)}}function dt(t,e){return ht(t,Object.assign(Object.assign({},e),{to:C.Parent}))}function ut(){return dt(tt)}const lt=(t,e)=>({context:t,event:e});const ft=t=>({type:X,sendId:t});function pt(t){const e=at(t);return{type:V.Start,activity:e,exec:void 0}}function gt(t){const e=at(t);return{type:V.Stop,activity:e,exec:void 0}}const vt=t=>({type:G,assignment:t});function yt(t,e){const i=e?`#${e}`:"";return`${V.After}(${t})${i}`}function mt(t,e){const i=`${V.DoneState}.${t}`,s={type:i,data:e,toString:()=>i};return s}function bt(t,e){const i=`${V.DoneInvoke}.${t}`,s={type:i,data:e,toString:()=>i};return s}function St(t,e){const i=`${V.ErrorPlatform}.${t}`,s={type:i,data:e,toString:()=>i};return s}function wt(t,e){return ht((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function xt(t,i,s,n,o){const[r,a]=v(o,t=>t.type===G);let c=r.length?function(t,i,s,n){return t?s.reduce((t,s)=>{const{assignment:o}=s,r={state:n,action:s,_event:i};let a={};if(b(o))a=o(t,i.data,r);else for(const s of e(o)){const e=o[s];a[s]=b(e)?e(t,i.data,r):e}return Object.assign({},t,a)},t):t}(s,n,r,i):s;return[u(a.map(e=>{var s;switch(e.type){case B:return{type:B,_event:N(e.event)};case q:return function(t,e,i,s){const n={_event:i},o=N(b(t.event)?t.event(e,i.data,n):t.event);let r;if(S(t.delay)){const o=s&&s[t.delay];r=b(o)?o(e,i.data,n):o}else r=b(t.delay)?t.delay(e,i.data,n):t.delay;const a=b(t.to)?t.to(e,i.data,n):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}(e,c,n,t.options.delays);case K:return((t,e,i)=>Object.assign(Object.assign({},t),{value:S(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}))(e,c,n);case et:{const o=null===(s=e.conds.find(e=>{const s=w(e.cond,t.options.guards);return!s||T(t,s,c,n,i)}))||void 0===s?void 0:s.actions;if(!o)return[];const r=xt(t,i,c,n,rt(f(o)));return c=r[1],r[0]}case it:{const s=e.get(c,n.data);if(!s)return[];const o=xt(t,i,c,n,rt(f(s)));return c=o[1],o[0]}default:return ot(e,t.options.actions)}})),c]}function _t(t,e){const{exec:i}=t;return Object.assign(Object.assign({},t),{exec:void 0!==i?()=>i(e.context,e.event,{action:t,state:e,_event:e._event}):void 0})}class Ot{constructor(e){this.actions=[],this.activities=t,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||t,this.meta=e.meta||{},this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,u([...new Set(t.map(t=>t.ownEvents))]);var t}})}static from(t,e){if(t instanceof Ot)return t.context!==e?new Ot({value:t.value,context:e,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;return new Ot({value:t,context:e,_event:st,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Ot(t)}static inert(t,e){if(t instanceof Ot){if(!t.actions.length)return t;const i=st;return new Ot({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Ot.from(t,e)}toStrings(t=this.value,i="."){if(S(t))return[t];const s=e(t);return s.concat(...s.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){return P(this,["configuration","transitions"])}matches(t){return i(t,this.value)}}function Et(t){try{return"function"==typeof t.send}catch(t){return!1}}const jt={},Nt=t=>"#"===t[0];class $t{constructor(t,i,s){this.config=t,this.context=s,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},i),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&e(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.initial=this.config.initial,this.states=this.config.states?a(this.config.states,(t,e)=>{const i=new $t(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):jt;let n=0;!function t(e){e.order=n++;for(const i of L(e))t(i)}(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(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=f(this.config.entry||this.config.onEntry).map(t=>ot(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>ot(t)),this.meta=this.config.meta,this.data="final"===this.type?this.config.data:void 0,this.invoke=f(this.config.invoke).map((t,e)=>{if(O(t))return this.machine.options.services=Object.assign({[t.id]:t},this.machine.options.services),{type:W,src:t.id,id:t.id};if("string"!=typeof t.src){const i=`${this.id}:invocation[${e}]`;return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Object.assign(Object.assign({type:W,id:i},t),{src:i})}return Object.assign(Object.assign({},t),{type:W,id:t.id||t.src,src:t.src})}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>at(t)),this.transition=this.transition.bind(this)}_init(){this.__cache.transitions||A(this).forEach(t=>t.on)}withConfig(t,e=this.context){const{actions:i,activities:s,guards:n,services:o,delays:r}=this.options;return new $t(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},s),t.activities),guards:Object.assign(Object.assign({},n),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},e)}withContext(t){return new $t(this.config,this.options,t)}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:a(this.states,t=>t.definition),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.data,invoke:this.invoke}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=""===t,i=this.transitions.filter(i=>{const s=i.eventType===t;return e?s:s||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const i=(t,e)=>{const i=yt(b(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(ht(i,{delay:t})),this.onExit.push(ft(i)),i};return(m(t)?t.map((t,e)=>{const s=i(t.delay,e);return Object.assign(Object.assign({},t),{event:s})}):u(e(t).map((e,s)=>{const n=t[e],o=S(n)?{target:n}:n,r=isNaN(+e)?e:+e,a=i(r,s);return f(o).map(t=>Object.assign(Object.assign({},t),{event:a,delay:r}))}))).map(t=>{const{delay:e}=t;return Object.assign(Object.assign({},this.formatTransition(t)),{delay:e})})}getStateNodes(t){if(!t)return[];const i=t instanceof Ot?t.value:o(t,this.delimiter);if(S(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this.states[i]]}const s=e(i);return s.map(t=>this.getStateNode(t)).concat(s.reduce((t,e)=>{const s=this.getStateNode(e).getStateNodes(i[e]);return t.concat(s)},[]))}handles(t){const e=s(t);return this.events.includes(e)}resolveState(t){const e=Array.from(R([],this.getStateNodes(t.value)));return new Ot(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e}))}transitionLeafNode(t,e,i){const s=this.getStateNode(t).next(e,i);return s&&s.transitions.length?s:this.next(e,i)}transitionCompoundNode(t,i,s){const n=e(t),o=this.getStateNode(n[0])._transition(t[n[0]],i,s);return o&&o.transitions.length?o:this.next(i,s)}transitionParallelNode(t,i,s){const n={};for(const o of e(t)){const e=t[o];if(!e)continue;const r=this.getStateNode(o)._transition(e,i,s);r&&(n[o]=r)}const o=e(n).map(t=>n[t]),r=u(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,s);const a=u(o.map(t=>t.entrySet)),c=u(e(n).map(t=>n[t].configuration));return{transitions:r,entrySet:a,exitSet:u(o.map(t=>t.exitSet)),configuration:c,source:i,actions:u(e(n).map(t=>n[t].actions))}}_transition(t,i,s){return S(t)?this.transitionLeafNode(t,i,s):1===e(t).length?this.transitionCompoundNode(t,i,s):this.transitionParallelNode(t,i,s)}next(t,e){const s=e.name,n=[];let r,a=[];for(const c of this.getCandidates(s)){const{cond:d,in:u}=c,l=t.context,f=!u||(S(u)&&Nt(u)?t.matches(o(this.getStateNodeById(u).path,this.delimiter)):i(o(u,this.delimiter),h(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!d||T(this.machine,d,l,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${d.name||d.type}' in transition for event '${s}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==c.target&&(a=c.target),n.push(...c.actions),r=c;break}}if(!r)return;if(!a.length)return{transitions:[r],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:n};const c=u(a.map(e=>this.getRelativeStateNodes(e,t.historyValue))),d=!!r.internal;return{transitions:[r],entrySet:d?[]:u(c.map(t=>this.nodesFromChild(t))),exitSet:d?[]:[this],configuration:c,source:t,actions:n}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,s){const n=R([],s?this.getStateNodes(s.value):[this]),o=t.configuration.length?R(n,t.configuration):n;for(const e of o)F(n,e)||t.entrySet.push(e);for(const e of n)F(o,e)&&!F(t.exitSet,e.parent)||t.exitSet.push(e);t.source||(t.exitSet=[],t.entrySet.push(this));const r=u(t.entrySet.map(s=>{const n=[];if("final"!==s.type)return n;const o=s.parent;if(!o.parent)return n;n.push(mt(s.id,s.data),mt(o.id,s.data?p(s.data,e,i):void 0));const r=o.parent;return"parallel"===r.type&&L(r).every(e=>z(t.configuration,e))&&n.push(mt(r.id,r.data)),n}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,d]=[u(Array.from(a).map(t=>[...t.activities.map(t=>pt(t)),...t.onEntry])).concat(r.map(ct)),u(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>gt(t))]))];return rt(d.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const s=N(e);let n;if(t instanceof Ot)n=void 0===i?t:this.resolveState(Ot.from(t,i));else{const e=S(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),s=i||this.machine.context;n=this.resolveState(Ot.from(e,s))}if(this.strict&&!this.events.includes(s.name)&&(o=s.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${s.name}'`);var o;const a=this._transition(n.value,n,s)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:n,actions:[]},c=R([],this.getStateNodes(n.value)),h=a.configuration.length?R(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,n,s)}resolveRaisedTransition(t,e,i){const s=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...s),t}resolveTransition(t,i,s=st,n=this.machine.context){const{configuration:o}=t,r=!i||t.transitions.length>0?D(this.machine,o):void 0,a=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,c=i?i.context:n,h=this.getActions(t,c,s,i),d=i?Object.assign({},i.activities):{};for(const t of h)t.type===J?d[t.activity.type]=t:t.type===U&&(d[t.activity.type]=!1);const[u,l]=xt(this,i,c,s,h),[f,p]=v(u,t=>t.type===B||t.type===q&&t.to===C.Internal),g=u.filter(t=>t.type===J&&t.activity.type===W).reduce((t,e)=>(t[e.activity.id]=function(t){const e={id:i=t.id,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),toJSON:()=>({id:i})};var i;return e.meta=t,e}(e.activity),t),i?Object.assign({},i.children):{}),m=r?t.configuration:i?i.configuration:[],b=m.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{}),w=z(m,this),x=new Ot({value:r||i.value,context:l,_event:s,_sessionid:i?i._sessionid:null,historyValue:r?a?(_=a,O=r,{current:O,states:y(_,O)}):void 0:i?i.historyValue:void 0,history:!r||t.source?i:void 0,actions:r?p:[],activities:r?d:i?i.activities:{},meta:r?b:i?i.meta:void 0,events:[],configuration:m,transitions:t.transitions,children:g,done:w});var _,O;const E=c!==l;x.changed=s.name===tt||E;const{history:j}=x;if(j&&delete j.history,!r)return x;let N=x;if(!w){for((this._transient||o.some(t=>t._transient))&&(N=this.resolveRaisedTransition(N,{type:H},s));f.length;){const t=f.shift();N=this.resolveRaisedTransition(N,t._event,s)}}const $=N.changed||(j?!!N.actions.length||E||typeof j.value!=typeof N.value||!function t(i,s){if(i===s)return!0;if(void 0===i||void 0===s)return!1;if(S(i)||S(s))return i===s;const n=e(i),o=e(s);return n.length===o.length&&n.every(e=>t(i[e],s[e]))}(N.value,j.value):void 0);return N.changed=$,N.historyValue=x.historyValue,N.history=j,N}getStateNode(t){if(Nt(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error(`Unable to retrieve child state '${t}' from '${this.id}'; no child states exist.`);const e=this.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${this.id}'`);return e}getStateNodeById(t){const e=Nt(t)?t.slice("#".length):t;if(e===this.id)return this;const i=this.machine.idMap[e];if(!i)throw new Error(`Child state node '#${e}' does not exist on machine '${this.id}'`);return i}getStateNodeByPath(t){if("string"==typeof t&&Nt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=n(t,this.delimiter).slice();let i=this;for(;e.length;){const t=e.shift();if(!t.length)break;i=i.getStateNode(t)}return i}resolve(t){if(!t)return this.initialStateValue||jt;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):jt);case"compound":if(S(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return e(t).length?a(t,(t,e)=>t?this.getStateNode(e).resolve(t):jt):this.initialStateValue||{};default:return t||jt}}getResolvedPath(t){if(Nt(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return n(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=c(this.states,t=>t.initialStateValue||jt,t=>!("history"===t.type));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error(`Initial state '${this.initial}' not found on '${this.key}'`);t=I(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)}get initialState(){this._init();const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=S(e.target)&&Nt(e.target)?r(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t}getRelativeStateNodes(t,e,i=!0){return i?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]}get initialStateNodes(){if(I(this))return[this];if("compound"===this.type&&!this.initial)return[this];return u(d(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const s=this.getStateNode(e);if("history"===s.type)return s.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(e(this.states).length)return{current:t||this.initialStateValue,states:c(this.states,(e,i)=>{if(!t)return e.historyValue();const s=S(t)?void 0:t[i];return e.historyValue(s||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?u(d(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(s=e.path,n="states",t=>{let e=t;for(const t of s)e=e[n][t];return e})(t).current;var s,n;return S(i)?[e.getStateNode(i)]:u(d(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=u(e(this.states).map(t=>this.states[t].stateIds));return[this.id].concat(t)}get events(){if(this.__cache.events)return this.__cache.events;const{states:t}=this,i=new Set(this.ownEvents);if(t)for(const s of e(t)){const e=t[s];if(e.states)for(const t of e.events)i.add(`${t}`)}return this.__cache.events=Array.from(i)}get ownEvents(){const t=new Set(this.transitions.filter(t=>!(!t.target&&!t.actions.length&&t.internal)).map(t=>t.eventType));return Array.from(t)}resolveTarget(t){if(void 0!==t)return t.map(t=>{if(!S(t))return t;const e=t[0]===this.delimiter;if(e&&!this.parent)return this.getStateNodeByPath(t.slice(1));const i=e?this.key+t:t;if(!this.parent)return this.getStateNodeByPath(i);try{return this.parent.getStateNodeByPath(i)}catch(t){throw new Error(`Invalid transition definition for state node '${this.id}':\n${t.message}`)}})}formatTransition(t){const e=function(t){if(void 0!==t&&""!==t)return f(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>S(t)&&t[0]===this.delimiter),{guards:s}=this.machine.options,n=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:rt(f(t.actions)),cond:w(t.cond,s),target:n,source:this,internal:i,eventType:t.event});return Object.defineProperty(o,"toJSON",{value:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>`#${t.id}`):void 0,source:"#{this.id}"})}),o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const i=this.config.on,s="*",n=i[s],o=void 0===n?[]:n,r=P(i,[s+""]);t=u(e(r).map(t=>$(t,r[t])).concat($("*",o)))}else t=[];const i=this.config.onDone?$(String(mt(this.id)),this.config.onDone):[],s=u(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...$(String(bt(t.id)),t.onDone)),t.onError&&e.push(...$(String(St(t.id)),t.onError)),e})),n=this.after,o=u([...i,...s,...t].map(t=>f(t).map(t=>this.formatTransition(t))));for(const t of n)o.push(t);return o}}function Tt(t,e,i=t.context){const s="function"==typeof i?i():i;return new $t(t,e,s)}function kt(t,e){const i="function"==typeof t.context?t.context():t.context;return new $t(t,e,i)}const Pt={deferEvents:!1};class Vt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Pt),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const Ct=new Map;let It=0;const Lt={bookId:()=>`x:${It++}`,register:(t,e)=>(Ct.set(t,e),t),get:t=>Ct.get(t),free(t){Ct.delete(t)}},At={sync:!1,autoForward:!1},Rt=(()=>{const t=[];return(e,i)=>{e&&t.push(e);const s=i(e||t[t.length-1]);return e&&t.pop(),s}})();var Mt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Mt||(Mt={}));class Dt{constructor(t,e=Dt.defaultOptions){this.machine=t,this.scheduler=new Vt,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=(t,e)=>{if(m(t))return this.batch(t),this.state;const i=N(j(t,e));if(this._status===Mt.Stopped)return this.state;if(this._status===Mt.NotStarted&&this.options.deferEvents);else if(this._status!==Mt.Running)throw new Error(`Event "${i.name}" was sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ${JSON.stringify(i.data)}`);return this.scheduler.schedule(()=>{this.forward(i);const t=this.nextState(i);this.update(t,i)}),this._state},this.sendTo=(t,e)=>{const i=this.parent&&(e===C.Parent||this.parent.id===e),s=i?this.parent:Et(e)?e:this.children.get(e)||Lt.get(e);if(s)"machine"in s?s.send(Object.assign(Object.assign({},t),{name:t.name===Z?`${St(this.id)}`:t.name,origin:this.sessionId})):s.send(t.data);else if(!i)throw new Error(`Unable to send event to child '${e}' from service '${this.id}'.`)};const i=Object.assign(Object.assign({},Dt.defaultOptions),e),{clock:s,logger:n,parent:o,id:r}=i,a=void 0!==r?r:t.id;this.id=a,this.logger=n,this.clock=s,this.parent=o,this.options=i,this.scheduler=new Vt({deferEvents:this.options.deferEvents}),this.sessionId=Lt.bookId()}get initialState(){return this._initialState?this._initialState:Rt(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);const i=z(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),s=i&&i.data?p(i.data,t.context,e):void 0;for(const t of this.doneListeners)t(bt(this.id,s));this.stop()}}onTransition(t){return this.listeners.add(t),this._status===Mt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>{}};let s,n=i;return"function"==typeof t?s=t:(s=t.next.bind(t),n=t.complete.bind(t)),this.listeners.add(s),this._status===Mt.Running&&s(this.state),n&&this.onDone(n),{unsubscribe:()=>{s&&this.listeners.delete(s),n&&this.doneListeners.delete(n)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this._status===Mt.Running)return this;Lt.register(this.sessionId,this),this.initialized=!0,this._status=Mt.Running;const e=void 0===t?this.initialState:Rt(this,()=>{return!S(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState(Ot.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,st)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);this.children.forEach(t=>{b(t.stop)&&t.stop()});for(const t of e(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this._status=Mt.Stopped,Lt.free(this.sessionId),this}batch(t){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(()=>{let e=this.state,i=!1;const s=[];for(const n of t){const t=N(n);this.forward(t),e=Rt(this,()=>this.machine.transition(e,t)),s.push(...e.actions.map(t=>_t(t,e))),i=i||!!e.changed}e.changed=i,e.actions=s,this.update(e,N(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=N(t);if(0===e.name.indexOf(Y)&&!this.state.nextEvents.some(t=>0===t.indexOf(Y)))throw e.data.data;return Rt(this,()=>this.machine.transition(this.state,e))}forward(t){for(const e of this.forwardTo){const i=this.children.get(e);if(!i)throw new Error(`Unable to forward event '${t}' from interpreter '${this.id}' to nonexistant child '${e}'.`);i.send(t)}}defer(t){this.delayedEventsMap[t.id]=this.clock.setTimeout(()=>{t.to?this.sendTo(t._event,t.to):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i){const{context:s,_event:n}=e,o=nt(t.type,i)||t.exec,r=b(o)?o:o?o.exec:t.exec;if(r)try{return r(s,n.data,{action:t,state:this.state,_event:n})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case q:const e=t;if("number"==typeof e.delay)return void this.defer(e);e.to?this.sendTo(e._event,e.to):this.send(e._event);break;case X:this.cancel(t.sendId);break;case J:{const e=t.activity;if(!this.state.activities[e.type])break;if(e.type===V.Invoke){const t=this.machine.options.services?this.machine.options.services[e.src]:void 0,{id:i,data:o}=e,r="autoForward"in e?e.autoForward:!!e.forward;if(!t)return;const a=b(t)?t(s,n.data):t;g(a)?this.state.children[i]=this.spawnPromise(Promise.resolve(a),i):b(a)?this.state.children[i]=this.spawnCallback(a,i):x(a)?this.state.children[i]=this.spawnObservable(a,i):O(a)&&(this.state.children[i]=this.spawnMachine(o?a.withContext(p(o,s,n)):a,{id:i,autoForward:r}))}else this.spawnActivity(e);break}case U:this.stopChild(t.activity.id);break;case K:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}removeChild(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),b(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(b(t))return this.spawnCallback(t,e);if(Et(t))return this.spawnActor(t);if(x(t))return this.spawnObservable(t,e);if(O(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`)}spawnMachine(t,e={}){const i=new Dt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),s=Object.assign(Object.assign({},At),e);s.sync&&i.onTransition(t=>{this.send(tt,{state:t,id:i.id})});const n=i;return this.children.set(i.id,n),s.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(N(t,{origin:i.id}))}).start(),n}spawnPromise(t,e){let i=!1;t.then(t=>{i||(this.removeChild(e),this.send(N(bt(e,t),{origin:e})))},t=>{if(!i){this.removeChild(e);const i=St(e,t);try{this.send(N(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>{},subscribe:(e,i,s)=>{let n=!1;return t.then(t=>{n||(e&&e(t),n||s&&s())},t=>{n||i(t)}),{unsubscribe:()=>n=!0}},stop:()=>{i=!0},toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const s=new Set,n=new Set,o=t=>{n.forEach(e=>e(t)),i||this.send(t)};let r;try{r=t(o,t=>{s.add(t)})}catch(t){this.send(St(e,t))}if(g(r))return this.spawnPromise(r,e);const a={id:e,send:t=>s.forEach(e=>e(t)),subscribe:t=>(n.add(t),{unsubscribe:()=>{n.delete(t)}}),stop:()=>{i=!0,b(r)&&r()},toJSON:()=>({id:e})};return this.children.set(e,a),a}spawnObservable(t,e){const i=t.subscribe(t=>{this.send(N(t,{origin:e}))},t=>{this.removeChild(e),this.send(N(St(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(N(bt(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,s)=>t.subscribe(e,i,s),stop:()=>i.unsubscribe(),toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnActor(t){return this.children.set(t.id,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,toJSON:()=>({id:t})})}attachDev(){if(this.options.devTools&&"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){const t="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=window.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},t),{features:Object.assign({jump:!1,skip:!1},t?t.features:void 0)}),this.machine),this.devTools.init(this.state)}}toJSON(){return{id:this.id}}[_](){return this}}Dt.defaultOptions=(t=>({execute:!0,deferEvents:!0,clock:{setTimeout:(e,i)=>t.setTimeout.call(null,e,i),clearTimeout:e=>t.clearTimeout.call(null,e)},logger:t.console.log.bind(console),devTools:!1}))("undefined"==typeof window?global:window),Dt.interpret=zt;function Ft(t,e){const i=(t=>S(t)?Object.assign(Object.assign({},At),{name:t}):Object.assign(Object.assign(Object.assign({},At),{name:E()}),t))(e);return Rt(void 0,e=>e?e.spawn(t,i.name,i):((t="null")=>({id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),toJSON:()=>({id:t})}))(i.name))}function zt(t,e){return new Dt(t,e)}function Jt(t,e,i){const s=Ot.from(t,t instanceof Ot?t.context:void 0);for(const[t,i]of e)if(s.matches(t))return i(s);return i(s)}const Ut={raise:ct,send:ht,sendParent:dt,sendUpdate:ut,log:function(t=lt,e){return{type:K,label:e,expr:t}},cancel:ft,start:pt,stop:gt,assign:vt,after:yt,done:mt,respond:function(t,e){return ht(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:wt,escalate:function(t,e){return dt((e,i,s)=>({type:Z,data:b(t)?t(e,i,s):t}),Object.assign(Object.assign({},e),{to:C.Parent}))},choose:function(t){return{type:V.Choose,conds:t}},pure:function(t){return{type:V.Pure,get:t}}};export{V as ActionTypes,Dt as Interpreter,Tt as Machine,C as SpecialTargets,Ot as State,$t as StateNode,Ut as actions,vt as assign,kt as createMachine,bt as doneInvoke,wt as forwardTo,zt as interpret,k as mapState,Jt as matchState,i as matchesState,ht as send,dt as sendParent,ut as sendUpdate,Ft as spawn};
|
|
15
|
+
***************************************************************************** */function P(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(i[s[n]]=t[s[n]])}return i}var V,C;!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(V||(V={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(C||(C={}));const I=t=>"atomic"===t.type||"final"===t.type;function L(t){return e(t.states).map(e=>t.states[e])}function A(t){const e=[t];return I(t)?e:e.concat(u(L(t).map(A)))}function R(t,e){const i=M(new Set(t)),s=new Set(e);for(const t of s){let e=t.parent;for(;e&&!s.has(e);)s.add(e),e=e.parent}const n=M(s);for(const t of s)if("compound"!==t.type||n.get(t)&&n.get(t).length){if("parallel"===t.type)for(const e of L(t))"history"!==e.type&&(s.has(e)||(s.add(e),i.get(e)?i.get(e).forEach(t=>s.add(t)):e.initialStateNodes.forEach(t=>s.add(t))))}else i.get(t)?i.get(t).forEach(t=>s.add(t)):t.initialStateNodes.forEach(t=>s.add(t));for(const t of s){let e=t.parent;for(;e&&!s.has(e);)s.add(e),e=e.parent}return s}function M(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function D(t,e){return function t(e,i){const s=i.get(e);if(!s)return{};if("compound"===e.type){const t=s[0];if(!t)return{};if(I(t))return t.key}const n={};return s.forEach(e=>{n[e.key]=t(e,i)}),n}(t,M(R([t],e)))}function F(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function z(t,e){return"compound"===e.type?L(e).some(e=>"final"===e.type&&F(t,e)):"parallel"===e.type&&L(e).every(e=>z(t,e))}const J=V.Start,U=V.Stop,B=V.Raise,q=V.Send,X=V.Cancel,H=V.NullEvent,G=V.Assign,K=(V.After,V.DoneState,V.Log),Q=V.Init,W=V.Invoke,Y=(V.ErrorExecution,V.ErrorPlatform),Z=V.ErrorCustom,tt=V.Update,et=V.Choose,it=V.Pure,st=N({type:Q});function nt(t,e){return e&&e[t]||void 0}function ot(t,e){let i;if(S(t)||"number"==typeof t){const s=nt(t,e);i=b(s)?{type:t,exec:s}:s||{type:t,exec:void 0}}else if(b(t))i={type:t.name||t.toString(),exec:t};else{const s=nt(t.type,e);if(b(s))i=Object.assign(Object.assign({},t),{exec:s});else if(s){const{type:e}=t,n=P(t,["type"]);i=Object.assign(Object.assign({type:e},s),n)}else i=t}return Object.defineProperty(i,"toString",{value:()=>i.type,enumerable:!1,configurable:!0}),i}const rt=(t,e)=>{if(!t)return[];return(m(t)?t:[t]).map(t=>ot(t,e))};function at(t){const e=ot(t);return Object.assign(Object.assign({id:S(t)?t:e.id},e),{type:e.type})}function ct(t){return S(t)?{type:B,event:t}:ht(t,{to:C.Internal})}function ht(t,e){return{to:e?e.to:void 0,type:q,event:b(t)?t:j(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:b(t)?t.name:s(t)}}function dt(t,e){return ht(t,Object.assign(Object.assign({},e),{to:C.Parent}))}function ut(){return dt(tt)}const lt=(t,e)=>({context:t,event:e});const ft=t=>({type:X,sendId:t});function pt(t){const e=at(t);return{type:V.Start,activity:e,exec:void 0}}function gt(t){const e=at(t);return{type:V.Stop,activity:e,exec:void 0}}const vt=t=>({type:G,assignment:t});function yt(t,e){const i=e?`#${e}`:"";return`${V.After}(${t})${i}`}function mt(t,e){const i=`${V.DoneState}.${t}`,s={type:i,data:e,toString:()=>i};return s}function bt(t,e){const i=`${V.DoneInvoke}.${t}`,s={type:i,data:e,toString:()=>i};return s}function St(t,e){const i=`${V.ErrorPlatform}.${t}`,s={type:i,data:e,toString:()=>i};return s}function wt(t,e){return ht((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function xt(t,i,s,n,o){const[r,a]=v(o,t=>t.type===G);let c=r.length?function(t,i,s,n){return t?s.reduce((t,s)=>{const{assignment:o}=s,r={state:n,action:s,_event:i};let a={};if(b(o))a=o(t,i.data,r);else for(const s of e(o)){const e=o[s];a[s]=b(e)?e(t,i.data,r):e}return Object.assign({},t,a)},t):t}(s,n,r,i):s;return[u(a.map(e=>{var s;switch(e.type){case B:return{type:B,_event:N(e.event)};case q:return function(t,e,i,s){const n={_event:i},o=N(b(t.event)?t.event(e,i.data,n):t.event);let r;if(S(t.delay)){const o=s&&s[t.delay];r=b(o)?o(e,i.data,n):o}else r=b(t.delay)?t.delay(e,i.data,n):t.delay;const a=b(t.to)?t.to(e,i.data,n):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}(e,c,n,t.options.delays);case K:return((t,e,i)=>Object.assign(Object.assign({},t),{value:S(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}))(e,c,n);case et:{const o=null===(s=e.conds.find(e=>{const s=w(e.cond,t.options.guards);return!s||T(t,s,c,n,i)}))||void 0===s?void 0:s.actions;if(!o)return[];const r=xt(t,i,c,n,rt(f(o),t.options.actions));return c=r[1],r[0]}case it:{const s=e.get(c,n.data);if(!s)return[];const o=xt(t,i,c,n,rt(f(s),t.options.actions));return c=o[1],o[0]}default:return ot(e,t.options.actions)}})),c]}function _t(t,e){const{exec:i}=t;return Object.assign(Object.assign({},t),{exec:void 0!==i?()=>i(e.context,e.event,{action:t,state:e,_event:e._event}):void 0})}class Ot{constructor(e){this.actions=[],this.activities=t,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||t,this.meta=e.meta||{},this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,u([...new Set(t.map(t=>t.ownEvents))]);var t}})}static from(t,e){if(t instanceof Ot)return t.context!==e?new Ot({value:t.value,context:e,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;return new Ot({value:t,context:e,_event:st,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Ot(t)}static inert(t,e){if(t instanceof Ot){if(!t.actions.length)return t;const i=st;return new Ot({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Ot.from(t,e)}toStrings(t=this.value,i="."){if(S(t))return[t];const s=e(t);return s.concat(...s.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){return P(this,["configuration","transitions"])}matches(t){return i(t,this.value)}}function Et(t){try{return"function"==typeof t.send}catch(t){return!1}}const jt={},Nt=t=>"#"===t[0];class $t{constructor(t,i,s){this.config=t,this.context=s,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},i),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&e(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.initial=this.config.initial,this.states=this.config.states?a(this.config.states,(t,e)=>{const i=new $t(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):jt;let n=0;!function t(e){e.order=n++;for(const i of L(e))t(i)}(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(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=f(this.config.entry||this.config.onEntry).map(t=>ot(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>ot(t)),this.meta=this.config.meta,this.data="final"===this.type?this.config.data:void 0,this.invoke=f(this.config.invoke).map((t,e)=>{if(O(t))return this.machine.options.services=Object.assign({[t.id]:t},this.machine.options.services),{type:W,src:t.id,id:t.id};if("string"!=typeof t.src){const i=`${this.id}:invocation[${e}]`;return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Object.assign(Object.assign({type:W,id:i},t),{src:i})}return Object.assign(Object.assign({},t),{type:W,id:t.id||t.src,src:t.src})}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>at(t)),this.transition=this.transition.bind(this)}_init(){this.__cache.transitions||A(this).forEach(t=>t.on)}withConfig(t,e=this.context){const{actions:i,activities:s,guards:n,services:o,delays:r}=this.options;return new $t(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},s),t.activities),guards:Object.assign(Object.assign({},n),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},e)}withContext(t){return new $t(this.config,this.options,t)}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:a(this.states,t=>t.definition),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.data,invoke:this.invoke}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=""===t,i=this.transitions.filter(i=>{const s=i.eventType===t;return e?s:s||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const i=(t,e)=>{const i=yt(b(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(ht(i,{delay:t})),this.onExit.push(ft(i)),i};return(m(t)?t.map((t,e)=>{const s=i(t.delay,e);return Object.assign(Object.assign({},t),{event:s})}):u(e(t).map((e,s)=>{const n=t[e],o=S(n)?{target:n}:n,r=isNaN(+e)?e:+e,a=i(r,s);return f(o).map(t=>Object.assign(Object.assign({},t),{event:a,delay:r}))}))).map(t=>{const{delay:e}=t;return Object.assign(Object.assign({},this.formatTransition(t)),{delay:e})})}getStateNodes(t){if(!t)return[];const i=t instanceof Ot?t.value:o(t,this.delimiter);if(S(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this.states[i]]}const s=e(i);return s.map(t=>this.getStateNode(t)).concat(s.reduce((t,e)=>{const s=this.getStateNode(e).getStateNodes(i[e]);return t.concat(s)},[]))}handles(t){const e=s(t);return this.events.includes(e)}resolveState(t){const e=Array.from(R([],this.getStateNodes(t.value)));return new Ot(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e}))}transitionLeafNode(t,e,i){const s=this.getStateNode(t).next(e,i);return s&&s.transitions.length?s:this.next(e,i)}transitionCompoundNode(t,i,s){const n=e(t),o=this.getStateNode(n[0])._transition(t[n[0]],i,s);return o&&o.transitions.length?o:this.next(i,s)}transitionParallelNode(t,i,s){const n={};for(const o of e(t)){const e=t[o];if(!e)continue;const r=this.getStateNode(o)._transition(e,i,s);r&&(n[o]=r)}const o=e(n).map(t=>n[t]),r=u(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,s);const a=u(o.map(t=>t.entrySet)),c=u(e(n).map(t=>n[t].configuration));return{transitions:r,entrySet:a,exitSet:u(o.map(t=>t.exitSet)),configuration:c,source:i,actions:u(e(n).map(t=>n[t].actions))}}_transition(t,i,s){return S(t)?this.transitionLeafNode(t,i,s):1===e(t).length?this.transitionCompoundNode(t,i,s):this.transitionParallelNode(t,i,s)}next(t,e){const s=e.name,n=[];let r,a=[];for(const c of this.getCandidates(s)){const{cond:d,in:u}=c,l=t.context,f=!u||(S(u)&&Nt(u)?t.matches(o(this.getStateNodeById(u).path,this.delimiter)):i(o(u,this.delimiter),h(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!d||T(this.machine,d,l,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${d.name||d.type}' in transition for event '${s}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==c.target&&(a=c.target),n.push(...c.actions),r=c;break}}if(!r)return;if(!a.length)return{transitions:[r],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:n};const c=u(a.map(e=>this.getRelativeStateNodes(e,t.historyValue))),d=!!r.internal;return{transitions:[r],entrySet:d?[]:u(c.map(t=>this.nodesFromChild(t))),exitSet:d?[]:[this],configuration:c,source:t,actions:n}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,s){const n=R([],s?this.getStateNodes(s.value):[this]),o=t.configuration.length?R(n,t.configuration):n;for(const e of o)F(n,e)||t.entrySet.push(e);for(const e of n)F(o,e)&&!F(t.exitSet,e.parent)||t.exitSet.push(e);t.source||(t.exitSet=[],t.entrySet.push(this));const r=u(t.entrySet.map(s=>{const n=[];if("final"!==s.type)return n;const o=s.parent;if(!o.parent)return n;n.push(mt(s.id,s.data),mt(o.id,s.data?p(s.data,e,i):void 0));const r=o.parent;return"parallel"===r.type&&L(r).every(e=>z(t.configuration,e))&&n.push(mt(r.id,r.data)),n}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,d]=[u(Array.from(a).map(t=>[...t.activities.map(t=>pt(t)),...t.onEntry])).concat(r.map(ct)),u(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>gt(t))]))];return rt(d.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const s=N(e);let n;if(t instanceof Ot)n=void 0===i?t:this.resolveState(Ot.from(t,i));else{const e=S(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),s=i||this.machine.context;n=this.resolveState(Ot.from(e,s))}if(this.strict&&!this.events.includes(s.name)&&(o=s.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${s.name}'`);var o;const a=this._transition(n.value,n,s)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:n,actions:[]},c=R([],this.getStateNodes(n.value)),h=a.configuration.length?R(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,n,s)}resolveRaisedTransition(t,e,i){const s=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...s),t}resolveTransition(t,i,s=st,n=this.machine.context){const{configuration:o}=t,r=!i||t.transitions.length>0?D(this.machine,o):void 0,a=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,c=i?i.context:n,h=this.getActions(t,c,s,i),d=i?Object.assign({},i.activities):{};for(const t of h)t.type===J?d[t.activity.id||t.activity.type]=t:t.type===U&&(d[t.activity.id||t.activity.type]=!1);const[u,l]=xt(this,i,c,s,h),[f,p]=v(u,t=>t.type===B||t.type===q&&t.to===C.Internal),g=u.filter(t=>t.type===J&&t.activity.type===W).reduce((t,e)=>(t[e.activity.id]=function(t){const e={id:i=t.id,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),toJSON:()=>({id:i})};var i;return e.meta=t,e}(e.activity),t),i?Object.assign({},i.children):{}),m=r?t.configuration:i?i.configuration:[],b=m.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{}),w=z(m,this),x=new Ot({value:r||i.value,context:l,_event:s,_sessionid:i?i._sessionid:null,historyValue:r?a?(_=a,O=r,{current:O,states:y(_,O)}):void 0:i?i.historyValue:void 0,history:!r||t.source?i:void 0,actions:r?p:[],activities:r?d:i?i.activities:{},meta:r?b:i?i.meta:void 0,events:[],configuration:m,transitions:t.transitions,children:g,done:w});var _,O;const E=c!==l;x.changed=s.name===tt||E;const{history:j}=x;if(j&&delete j.history,!r)return x;let N=x;if(!w){for((this._transient||o.some(t=>t._transient))&&(N=this.resolveRaisedTransition(N,{type:H},s));f.length;){const t=f.shift();N=this.resolveRaisedTransition(N,t._event,s)}}const $=N.changed||(j?!!N.actions.length||E||typeof j.value!=typeof N.value||!function t(i,s){if(i===s)return!0;if(void 0===i||void 0===s)return!1;if(S(i)||S(s))return i===s;const n=e(i),o=e(s);return n.length===o.length&&n.every(e=>t(i[e],s[e]))}(N.value,j.value):void 0);return N.changed=$,N.historyValue=x.historyValue,N.history=j,N}getStateNode(t){if(Nt(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error(`Unable to retrieve child state '${t}' from '${this.id}'; no child states exist.`);const e=this.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${this.id}'`);return e}getStateNodeById(t){const e=Nt(t)?t.slice("#".length):t;if(e===this.id)return this;const i=this.machine.idMap[e];if(!i)throw new Error(`Child state node '#${e}' does not exist on machine '${this.id}'`);return i}getStateNodeByPath(t){if("string"==typeof t&&Nt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=n(t,this.delimiter).slice();let i=this;for(;e.length;){const t=e.shift();if(!t.length)break;i=i.getStateNode(t)}return i}resolve(t){if(!t)return this.initialStateValue||jt;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):jt);case"compound":if(S(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return e(t).length?a(t,(t,e)=>t?this.getStateNode(e).resolve(t):jt):this.initialStateValue||{};default:return t||jt}}getResolvedPath(t){if(Nt(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return n(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=c(this.states,t=>t.initialStateValue||jt,t=>!("history"===t.type));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error(`Initial state '${this.initial}' not found on '${this.key}'`);t=I(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)}get initialState(){this._init();const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=S(e.target)&&Nt(e.target)?r(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t}getRelativeStateNodes(t,e,i=!0){return i?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]}get initialStateNodes(){if(I(this))return[this];if("compound"===this.type&&!this.initial)return[this];return u(d(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const s=this.getStateNode(e);if("history"===s.type)return s.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(e(this.states).length)return{current:t||this.initialStateValue,states:c(this.states,(e,i)=>{if(!t)return e.historyValue();const s=S(t)?void 0:t[i];return e.historyValue(s||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?u(d(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(s=e.path,n="states",t=>{let e=t;for(const t of s)e=e[n][t];return e})(t).current;var s,n;return S(i)?[e.getStateNode(i)]:u(d(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=u(e(this.states).map(t=>this.states[t].stateIds));return[this.id].concat(t)}get events(){if(this.__cache.events)return this.__cache.events;const{states:t}=this,i=new Set(this.ownEvents);if(t)for(const s of e(t)){const e=t[s];if(e.states)for(const t of e.events)i.add(`${t}`)}return this.__cache.events=Array.from(i)}get ownEvents(){const t=new Set(this.transitions.filter(t=>!(!t.target&&!t.actions.length&&t.internal)).map(t=>t.eventType));return Array.from(t)}resolveTarget(t){if(void 0!==t)return t.map(t=>{if(!S(t))return t;const e=t[0]===this.delimiter;if(e&&!this.parent)return this.getStateNodeByPath(t.slice(1));const i=e?this.key+t:t;if(!this.parent)return this.getStateNodeByPath(i);try{return this.parent.getStateNodeByPath(i)}catch(t){throw new Error(`Invalid transition definition for state node '${this.id}':\n${t.message}`)}})}formatTransition(t){const e=function(t){if(void 0!==t&&""!==t)return f(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>S(t)&&t[0]===this.delimiter),{guards:s}=this.machine.options,n=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:rt(f(t.actions)),cond:w(t.cond,s),target:n,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>`#${t.id}`):void 0,source:"#{this.id}"})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const i=this.config.on,s="*",n=i[s],o=void 0===n?[]:n,r=P(i,[s+""]);t=u(e(r).map(t=>$(t,r[t])).concat($("*",o)))}else t=[];const i=this.config.onDone?$(String(mt(this.id)),this.config.onDone):[],s=u(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...$(String(bt(t.id)),t.onDone)),t.onError&&e.push(...$(String(St(t.id)),t.onError)),e})),n=this.after,o=u([...i,...s,...t].map(t=>f(t).map(t=>this.formatTransition(t))));for(const t of n)o.push(t);return o}}function Tt(t,e,i=t.context){const s="function"==typeof i?i():i;return new $t(t,e,s)}function kt(t,e){const i="function"==typeof t.context?t.context():t.context;return new $t(t,e,i)}const Pt={deferEvents:!1};class Vt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Pt),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const Ct=new Map;let It=0;const Lt={bookId:()=>`x:${It++}`,register:(t,e)=>(Ct.set(t,e),t),get:t=>Ct.get(t),free(t){Ct.delete(t)}},At={sync:!1,autoForward:!1},Rt=(()=>{const t=[];return(e,i)=>{e&&t.push(e);const s=i(e||t[t.length-1]);return e&&t.pop(),s}})();var Mt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Mt||(Mt={}));class Dt{constructor(t,e=Dt.defaultOptions){this.machine=t,this.scheduler=new Vt,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=(t,e)=>{if(m(t))return this.batch(t),this.state;const i=N(j(t,e));if(this._status===Mt.Stopped)return this.state;if(this._status===Mt.NotStarted&&this.options.deferEvents);else if(this._status!==Mt.Running)throw new Error(`Event "${i.name}" was sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ${JSON.stringify(i.data)}`);return this.scheduler.schedule(()=>{this.forward(i);const t=this.nextState(i);this.update(t,i)}),this._state},this.sendTo=(t,e)=>{const i=this.parent&&(e===C.Parent||this.parent.id===e),s=i?this.parent:Et(e)?e:this.children.get(e)||Lt.get(e);if(s)"machine"in s?s.send(Object.assign(Object.assign({},t),{name:t.name===Z?`${St(this.id)}`:t.name,origin:this.sessionId})):s.send(t.data);else if(!i)throw new Error(`Unable to send event to child '${e}' from service '${this.id}'.`)};const i=Object.assign(Object.assign({},Dt.defaultOptions),e),{clock:s,logger:n,parent:o,id:r}=i,a=void 0!==r?r:t.id;this.id=a,this.logger=n,this.clock=s,this.parent=o,this.options=i,this.scheduler=new Vt({deferEvents:this.options.deferEvents}),this.sessionId=Lt.bookId()}get initialState(){return this._initialState?this._initialState:Rt(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);const i=z(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),s=i&&i.data?p(i.data,t.context,e):void 0;for(const t of this.doneListeners)t(bt(this.id,s));this.stop()}}onTransition(t){return this.listeners.add(t),this._status===Mt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>{}};let s,n=i;return"function"==typeof t?s=t:(s=t.next.bind(t),n=t.complete.bind(t)),this.listeners.add(s),this._status===Mt.Running&&s(this.state),n&&this.onDone(n),{unsubscribe:()=>{s&&this.listeners.delete(s),n&&this.doneListeners.delete(n)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this._status===Mt.Running)return this;Lt.register(this.sessionId,this),this.initialized=!0,this._status=Mt.Running;const e=void 0===t?this.initialState:Rt(this,()=>{return!S(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState(Ot.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,st)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);this.children.forEach(t=>{b(t.stop)&&t.stop()});for(const t of e(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this._status=Mt.Stopped,Lt.free(this.sessionId),this}batch(t){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(()=>{let e=this.state,i=!1;const s=[];for(const n of t){const t=N(n);this.forward(t),e=Rt(this,()=>this.machine.transition(e,t)),s.push(...e.actions.map(t=>_t(t,e))),i=i||!!e.changed}e.changed=i,e.actions=s,this.update(e,N(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=N(t);if(0===e.name.indexOf(Y)&&!this.state.nextEvents.some(t=>0===t.indexOf(Y)))throw e.data.data;return Rt(this,()=>this.machine.transition(this.state,e))}forward(t){for(const e of this.forwardTo){const i=this.children.get(e);if(!i)throw new Error(`Unable to forward event '${t}' from interpreter '${this.id}' to nonexistant child '${e}'.`);i.send(t)}}defer(t){this.delayedEventsMap[t.id]=this.clock.setTimeout(()=>{t.to?this.sendTo(t._event,t.to):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i=this.machine.options.actions){const{context:s,_event:n}=e,o=t.exec||nt(t.type,i),r=b(o)?o:o?o.exec:t.exec;if(r)try{return r(s,n.data,{action:t,state:this.state,_event:n})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case q:const e=t;if("number"==typeof e.delay)return void this.defer(e);e.to?this.sendTo(e._event,e.to):this.send(e._event);break;case X:this.cancel(t.sendId);break;case J:{const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===V.Invoke){const t=this.machine.options.services?this.machine.options.services[e.src]:void 0,{id:i,data:o}=e,r="autoForward"in e?e.autoForward:!!e.forward;if(!t)return;const a=b(t)?t(s,n.data):t;g(a)?this.state.children[i]=this.spawnPromise(Promise.resolve(a),i):b(a)?this.state.children[i]=this.spawnCallback(a,i):x(a)?this.state.children[i]=this.spawnObservable(a,i):O(a)&&(this.state.children[i]=this.spawnMachine(o?a.withContext(p(o,s,n)):a,{id:i,autoForward:r}))}else this.spawnActivity(e);break}case U:this.stopChild(t.activity.id);break;case K:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}removeChild(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),b(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(b(t))return this.spawnCallback(t,e);if(Et(t))return this.spawnActor(t);if(x(t))return this.spawnObservable(t,e);if(O(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`)}spawnMachine(t,e={}){const i=new Dt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),s=Object.assign(Object.assign({},At),e);s.sync&&i.onTransition(t=>{this.send(tt,{state:t,id:i.id})});const n=i;return this.children.set(i.id,n),s.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(N(t,{origin:i.id}))}).start(),n}spawnPromise(t,e){let i=!1;t.then(t=>{i||(this.removeChild(e),this.send(N(bt(e,t),{origin:e})))},t=>{if(!i){this.removeChild(e);const i=St(e,t);try{this.send(N(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>{},subscribe:(e,i,s)=>{let n=!1;return t.then(t=>{n||(e&&e(t),n||s&&s())},t=>{n||i(t)}),{unsubscribe:()=>n=!0}},stop:()=>{i=!0},toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const s=new Set,n=new Set,o=t=>{n.forEach(e=>e(t)),i||this.send(t)};let r;try{r=t(o,t=>{s.add(t)})}catch(t){this.send(St(e,t))}if(g(r))return this.spawnPromise(r,e);const a={id:e,send:t=>s.forEach(e=>e(t)),subscribe:t=>(n.add(t),{unsubscribe:()=>{n.delete(t)}}),stop:()=>{i=!0,b(r)&&r()},toJSON:()=>({id:e})};return this.children.set(e,a),a}spawnObservable(t,e){const i=t.subscribe(t=>{this.send(N(t,{origin:e}))},t=>{this.removeChild(e),this.send(N(St(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(N(bt(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,s)=>t.subscribe(e,i,s),stop:()=>i.unsubscribe(),toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnActor(t){return this.children.set(t.id,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,toJSON:()=>({id:t})})}attachDev(){if(this.options.devTools&&"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){const t="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=window.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},t),{features:Object.assign({jump:!1,skip:!1},t?t.features:void 0)}),this.machine),this.devTools.init(this.state)}}toJSON(){return{id:this.id}}[_](){return this}}Dt.defaultOptions=(t=>({execute:!0,deferEvents:!0,clock:{setTimeout:(e,i)=>t.setTimeout.call(null,e,i),clearTimeout:e=>t.clearTimeout.call(null,e)},logger:t.console.log.bind(console),devTools:!1}))("undefined"==typeof window?global:window),Dt.interpret=zt;function Ft(t,e){const i=(t=>S(t)?Object.assign(Object.assign({},At),{name:t}):Object.assign(Object.assign(Object.assign({},At),{name:E()}),t))(e);return Rt(void 0,e=>e?e.spawn(t,i.name,i):((t="null")=>({id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),toJSON:()=>({id:t})}))(i.name))}function zt(t,e){return new Dt(t,e)}function Jt(t,e,i){const s=Ot.from(t,t instanceof Ot?t.context:void 0);for(const[t,i]of e)if(s.matches(t))return i(s);return i(s)}const Ut={raise:ct,send:ht,sendParent:dt,sendUpdate:ut,log:function(t=lt,e){return{type:K,label:e,expr:t}},cancel:ft,start:pt,stop:gt,assign:vt,after:yt,done:mt,respond:function(t,e){return ht(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:wt,escalate:function(t,e){return dt((e,i,s)=>({type:Z,data:b(t)?t(e,i,s):t}),Object.assign(Object.assign({},e),{to:C.Parent}))},choose:function(t){return{type:V.Choose,conds:t}},pure:function(t){return{type:V.Pure,get:t}}};export{V as ActionTypes,Dt as Interpreter,Tt as Machine,C as SpecialTargets,Ot as State,$t as StateNode,Ut as actions,vt as assign,kt as createMachine,bt as doneInvoke,wt as forwardTo,zt as interpret,k as mapState,Jt as matchState,i as matchesState,ht as send,dt as sendParent,ut as sendUpdate,Ft as spawn};
|
package/es/Machine.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { StateMachine, MachineOptions, DefaultContext, MachineConfig, StateSchema, EventObject, AnyEventObject, Typestate } from './types';
|
|
2
2
|
export declare function Machine<TContext = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, any, TEvent>;
|
|
3
3
|
export declare function Machine<TContext = DefaultContext, TStateSchema extends StateSchema = any, TEvent extends EventObject = AnyEventObject>(config: MachineConfig<TContext, TStateSchema, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>, initialContext?: TContext): StateMachine<TContext, TStateSchema, TEvent>;
|
|
4
|
-
export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> =
|
|
4
|
+
export declare function createMachine<TContext, TEvent extends EventObject = AnyEventObject, TTypestate extends Typestate<TContext> = {
|
|
5
|
+
value: any;
|
|
6
|
+
context: TContext;
|
|
7
|
+
}>(config: MachineConfig<TContext, any, TEvent>, options?: Partial<MachineOptions<TContext, TEvent>>): StateMachine<TContext, any, TEvent, TTypestate>;
|
|
5
8
|
//# sourceMappingURL=Machine.d.ts.map
|