xstate 4.19.0 → 4.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # xstate
2
2
 
3
+ ## 4.19.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`64ab1150`](https://github.com/davidkpiano/xstate/commit/64ab1150e0a383202f4af1d586b28e081009c929) [#2173](https://github.com/davidkpiano/xstate/pull/2173) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue with tags not being set correctly after sending an event to a machine that didn't result in selecting any transitions.
8
+
3
9
  ## 4.19.0
4
10
 
5
11
  ### Minor Changes
package/README.md CHANGED
@@ -33,11 +33,11 @@ npm install xstate
33
33
  ```
34
34
 
35
35
  ```js
36
- import { Machine, interpret } from 'xstate';
36
+ import { createMachine, interpret } from 'xstate';
37
37
 
38
38
  // Stateless machine definition
39
39
  // machine.transition(...) is a pure function used by the interpreter.
40
- const toggleMachine = Machine({
40
+ const toggleMachine = createMachine({
41
41
  id: 'toggle',
42
42
  initial: 'inactive',
43
43
  states: {
@@ -48,7 +48,7 @@ const toggleMachine = Machine({
48
48
 
49
49
  // Machine instance with internal state
50
50
  const toggleService = interpret(toggleMachine)
51
- .onTransition(state => console.log(state.value))
51
+ .onTransition((state) => console.log(state.value))
52
52
  .start();
53
53
  // => 'inactive'
54
54
 
@@ -90,9 +90,9 @@ Read [📽 the slides](http://slides.com/davidkhourshid/finite-state-machines) (
90
90
  <img src="https://imgur.com/rqqmkJh.png" alt="Light Machine" width="300" />
91
91
 
92
92
  ```js
93
- import { Machine } from 'xstate';
93
+ import { createMachine } from 'xstate';
94
94
 
95
- const lightMachine = Machine({
95
+ const lightMachine = createMachine({
96
96
  id: 'light',
97
97
  initial: 'green',
98
98
  states: {
@@ -126,7 +126,7 @@ const nextState = lightMachine.transition(currentState, 'TIMER').value;
126
126
  <img src="https://imgur.com/GDZAeB9.png" alt="Hierarchical Light Machine" width="300" />
127
127
 
128
128
  ```js
129
- import { Machine } from 'xstate';
129
+ import { createMachine } from 'xstate';
130
130
 
131
131
  const pedestrianStates = {
132
132
  initial: 'walk',
@@ -145,7 +145,7 @@ const pedestrianStates = {
145
145
  }
146
146
  };
147
147
 
148
- const lightMachine = Machine({
148
+ const lightMachine = createMachine({
149
149
  id: 'light',
150
150
  initial: 'green',
151
151
  states: {
@@ -203,7 +203,7 @@ lightMachine.transition({ red: 'stop' }, 'TIMER').value;
203
203
  <img src="https://imgur.com/GKd4HwR.png" width="300" alt="Parallel state machine" />
204
204
 
205
205
  ```js
206
- const wordMachine = Machine({
206
+ const wordMachine = createMachine({
207
207
  id: 'word',
208
208
  type: 'parallel',
209
209
  states: {
@@ -289,7 +289,7 @@ const nextState = wordMachine.transition(
289
289
  <img src="https://imgur.com/I4QsQsz.png" width="300" alt="Machine with history state" />
290
290
 
291
291
  ```js
292
- const paymentMachine = Machine({
292
+ const paymentMachine = createMachine({
293
293
  id: 'payment',
294
294
  initial: 'method',
295
295
  states: {
package/dist/xstate.js CHANGED
@@ -12,4 +12,4 @@
12
12
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
14
  PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function n(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return a}function o(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(i(arguments[e]));return t}var a={};function s(t){return Object.keys(t)}function c(t,e,n){void 0===n&&(n=".");var r=f(t,n),i=f(e,n);return N(i)?!!N(r)&&i===r:N(r)?r in i:s(r).every((function(t){return t in i&&c(r[t],i[t])}))}function u(t){try{return N(t)||"number"==typeof t?""+t:t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function h(t,e){try{return E(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}function f(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:E(t)?l(t):"string"!=typeof t?t:l(h(t,e));var n}function l(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function d(t,e){for(var n={},r=s(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function v(t,e,n){var i,o,a={};try{for(var c=r(s(t)),u=c.next();!u.done;u=c.next()){var h=u.value,f=t[h];n(f)&&(a[h]=e(f,h,t))}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(i)throw i.error}}return a}var p=function(t){return function(e){var n,i,o=e;try{for(var a=r(t),s=a.next();!s.done;s=a.next()){o=o[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return o}};function y(t){return t?N(t)?[[t]]:g(s(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?y(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function g(t){var e;return(e=[]).concat.apply(e,o(t))}function m(t){return E(t)?t:[t]}function x(t){return void 0===t?[]:m(t)}function S(t,e,n){var i,o;if(T(t))return t(e,n.data);var a={};try{for(var s=r(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];T(h)?a[u]=h(e,n.data):a[u]=h}}catch(t){i={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}return a}function w(t){return t instanceof Promise||!(null===t||!T(t)&&"object"!=typeof t||!T(t.then))}function b(t,e){var n,o,a=i([[],[]],2),s=a[0],c=a[1];try{for(var u=r(t),h=u.next();!h.done;h=u.next()){var f=h.value;e(f)?s.push(f):c.push(f)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(o=u.return)&&o.call(u)}finally{if(n)throw n.error}}return[s,c]}function _(t,e){return d(t.states,(function(t,n){if(t){var r=(N(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:_(t,r)}}}))}function E(t){return Array.isArray(t)}function T(t){return"function"==typeof t}function N(t){return"string"==typeof t}function O(t,e){if(t)return N(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:T(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}function A(t){try{return"subscribe"in t&&T(t.subscribe)}catch(t){return!1}}var P="function"==typeof Symbol&&Symbol.observable||"@@observable";function k(t){try{return"__xstatenode"in t}catch(t){return!1}}var I,j,C,V=(I=0,function(){return(++I).toString(16)});function L(t,n){return N(t)||"number"==typeof t?e({type:t},n):t}function D(t,n){if(!N(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var r=L(t);return e({name:r.type,data:r,$$type:"scxml",type:"external"},n)}function M(t,n){return m(n).map((function(n){return void 0===n||"string"==typeof n||k(n)?{target:n,event:t}:e(e({},n),{event:t})}))}function R(t,e,n,r,i){var o=t.options.guards,a={state:i,cond:e,_event:r};if("xstate.guard"===e.type)return e.predicate(n,r.data,a);var s=o[e.type];if(!s)throw new Error("Guard '"+e.type+"' is not implemented on machine '"+t.id+"'.");return s(n,r.data,a)}function z(t){return"string"==typeof t?{type:t}:t}(j=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",j.Stop="xstate.stop",j.Raise="xstate.raise",j.Send="xstate.send",j.Cancel="xstate.cancel",j.NullEvent="",j.Assign="xstate.assign",j.After="xstate.after",j.DoneState="done.state",j.DoneInvoke="done.invoke",j.Log="xstate.log",j.Init="xstate.init",j.Invoke="xstate.invoke",j.ErrorExecution="error.execution",j.ErrorCommunication="error.communication",j.ErrorPlatform="error.platform",j.ErrorCustom="xstate.error",j.Update="xstate.update",j.Pure="xstate.pure",j.Choose="xstate.choose",(C=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",C.Internal="#_internal";var F=function(t){return"atomic"===t.type||"final"===t.type};function U(t){return s(t.states).map((function(e){return t.states[e]}))}function J(t){var e=[t];return F(t)?e:e.concat(g(U(t).map(J)))}function B(t,e){var n,i,o,a,s,c,u,h,f=q(new Set(t)),l=new Set(e);try{for(var d=r(l),v=d.next();!v.done;v=d.next())for(var p=(E=v.value).parent;p&&!l.has(p);)l.add(p),p=p.parent}catch(t){n={error:t}}finally{try{v&&!v.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}var y=q(l);try{for(var g=r(l),m=g.next();!m.done;m=g.next()){if("compound"!==(E=m.value).type||y.get(E)&&y.get(E).length){if("parallel"===E.type)try{for(var x=(s=void 0,r(U(E))),S=x.next();!S.done;S=x.next()){var w=S.value;"history"!==w.type&&(l.has(w)||(l.add(w),f.get(w)?f.get(w).forEach((function(t){return l.add(t)})):w.initialStateNodes.forEach((function(t){return l.add(t)}))))}}catch(t){s={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}finally{if(s)throw s.error}}}else f.get(E)?f.get(E).forEach((function(t){return l.add(t)})):E.initialStateNodes.forEach((function(t){return l.add(t)}))}}catch(t){o={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(o)throw o.error}}try{for(var b=r(l),_=b.next();!_.done;_=b.next()){var E;for(p=(E=_.value).parent;p&&!l.has(p);)l.add(p),p=p.parent}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}return l}function q(t){var e,n,i=new Map;try{for(var o=r(t),a=o.next();!a.done;a=o.next()){var s=a.value;i.has(s)||i.set(s,[]),s.parent&&(i.has(s.parent)||i.set(s.parent,[]),i.get(s.parent).push(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return i}function $(t,e){return function t(e,n){var r=n.get(e);if(!r)return{};if("compound"===e.type){var i=r[0];if(!i)return{};if(F(i))return i.key}var o={};return r.forEach((function(e){o[e.key]=t(e,n)})),o}(t,q(B([t],e)))}function X(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function H(t,e){return"compound"===e.type?U(e).some((function(e){return"final"===e.type&&X(t,e)})):"parallel"===e.type&&U(e).every((function(e){return H(t,e)}))}var G=t.ActionTypes.Start,K=t.ActionTypes.Stop,Q=t.ActionTypes.Raise,W=t.ActionTypes.Send,Y=t.ActionTypes.Cancel,Z=t.ActionTypes.NullEvent,tt=t.ActionTypes.Assign,et=(t.ActionTypes.After,t.ActionTypes.DoneState,t.ActionTypes.Log),nt=t.ActionTypes.Init,rt=t.ActionTypes.Invoke,it=(t.ActionTypes.ErrorExecution,t.ActionTypes.ErrorPlatform),ot=t.ActionTypes.ErrorCustom,at=t.ActionTypes.Update,st=t.ActionTypes.Choose,ct=t.ActionTypes.Pure,ut=D({type:nt});function ht(t,e){return e&&e[t]||void 0}function ft(t,n){var r;if(N(t)||"number"==typeof t){var i=ht(t,n);r=T(i)?{type:t,exec:i}:i||{type:t,exec:void 0}}else if(T(t))r={type:t.name||t.toString(),exec:t};else{if(T(i=ht(t.type,n)))r=e(e({},t),{exec:i});else if(i){var o=i.type||t.type;r=e(e(e({},i),t),{type:o})}else r=t}return Object.defineProperty(r,"toString",{value:function(){return r.type},enumerable:!1,configurable:!0}),r}var lt=function(t,e){return t?(E(t)?t:[t]).map((function(t){return ft(t,e)})):[]};function dt(t){var n=ft(t);return e(e({id:N(t)?t:n.id},n),{type:n.type})}function vt(e){return N(e)?{type:Q,event:e}:pt(e,{to:t.SpecialTargets.Internal})}function pt(t,e){return{to:e?e.to:void 0,type:W,event:T(t)?t:L(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:T(t)?t.name:u(t)}}function yt(n,r){return pt(n,e(e({},r),{to:t.SpecialTargets.Parent}))}function gt(){return yt(at)}var mt=function(t,e){return{context:t,event:e}};var xt=function(t){return{type:Y,sendId:t}};function St(e){var n=dt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function wt(e){var n=T(e)?e:dt(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}var bt=function(t){return{type:tt,assignment:t}};function _t(e,n){var r=n?"#"+n:"";return t.ActionTypes.After+"("+e+")"+r}function Et(e,n){var r=t.ActionTypes.DoneState+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function Tt(e,n){var r=t.ActionTypes.DoneInvoke+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function Nt(e,n){var r=t.ActionTypes.ErrorPlatform+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function Ot(t,n){return pt((function(t,e){return e}),e(e({},n),{to:t}))}function At(n,o,a,c,u){var h=i(b(u,(function(t){return t.type===tt})),2),f=h[0],l=h[1],d=f.length?function(t,e,n,i){return t?n.reduce((function(t,n){var o,a,c=n.assignment,u={state:i,action:n,_event:e},h={};if(T(c))h=c(t,e.data,u);else try{for(var f=r(s(c)),l=f.next();!l.done;l=f.next()){var d=l.value,v=c[d];h[d]=T(v)?v(t,e.data,u):v}}catch(t){o={error:t}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(o)throw o.error}}return Object.assign({},t,h)}),t):t}(a,c,f,o):a;return[g(l.map((function(r){var i;switch(r.type){case Q:return{type:Q,_event:D(r.event)};case W:return function(t,n,r,i){var o,a={_event:r},s=D(T(t.event)?t.event(n,r.data,a):t.event);if(N(t.delay)){var c=i&&i[t.delay];o=T(c)?c(n,r.data,a):c}else o=T(t.delay)?t.delay(n,r.data,a):t.delay;var u=T(t.to)?t.to(n,r.data,a):t.to;return e(e({},t),{to:u,_event:s,event:s.data,delay:o})}(r,d,c,n.options.delays);case et:return function(t,n,r){return e(e({},t),{value:N(t.expr)?t.expr:t.expr(n,r.data,{_event:r})})}(r,d,c);case st:if(!(s=null===(i=r.conds.find((function(t){var e=O(t.cond,n.options.guards);return!e||R(n,e,d,c,o)})))||void 0===i?void 0:i.actions))return[];var a=At(n,o,d,c,lt(x(s),n.options.actions));return d=a[1],a[0];case ct:var s;if(!(s=r.get(d,c.data)))return[];a=At(n,o,d,c,lt(x(s),n.options.actions));return d=a[1],a[0];case K:return function(e,n,r){var i=T(e.activity)?e.activity(n,r.data):e.activity,o="string"==typeof i?{id:i}:i;return{type:t.ActionTypes.Stop,activity:o}}(r,d,c);default:return ft(r,n.options.actions)}}))),d]}var Pt=function(){function t(t){var e,n=this;this.actions=[],this.activities=a,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||a,this.meta=t.meta||{},this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=t.tags)&&void 0!==e?e:new Set,Object.defineProperty(this,"nextEvents",{get:function(){return t=n.configuration,g(o(new Set(t.map((function(t){return t.ownEvents})))));var t}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:ut,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var r=ut;return new t({value:e.value,context:n,_event:r,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,n)},t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),N(t))return[t];var r=s(t);return r.concat.apply(r,o(r.map((function(r){return n.toStrings(t[r],e).map((function(t){return r+e+t}))}))))},t.prototype.toJSON=function(){this.configuration,this.transitions;var t=this.tags,r=n(this,["configuration","transitions","tags"]);return e(e({},r),{tags:Array.from(t)})},t.prototype.matches=function(t){return c(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t}(),kt=[],It=function(t,e){kt.push(t);var n=e(t);return kt.pop(),n};function jt(t){return{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:t}}}}function Ct(t,e,n){var r=jt(e);return r.deferred=!0,k(t)&&(r.state=It(void 0,(function(){return(n?t.withContext(n):t).initialState}))),r}function Vt(t){if("string"==typeof t){var e={type:t,toString:function(){return t}};return e}return t}function Lt(t){return e(e({type:rt},t),{toJSON:function(){t.onDone,t.onError;var r=n(t,["onDone","onError"]);return e(e({},r),{type:rt,src:Vt(t.src)})}})}var Dt={},Mt=function(t){return"#"===t[0]},Rt=function(){function a(t,n,i){var c,u=this;void 0===i&&(i=void 0),this.config=t,this.context=i,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},n),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||o([this.machine.key],this.path).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&s(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(c=this.config.schema)&&void 0!==c?c:{},this.initial=this.config.initial,this.states=this.config.states?d(this.config.states,(function(t,n){var r,i=new a(t,{_parent:u,_key:n});return Object.assign(u.idMap,e(((r={})[i.id]=i,r),i.idMap)),i})):Dt;var h=0;!function t(e){var n,i;e.order=h++;try{for(var o=r(U(e)),a=o.next();!a.done;a=o.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some((function(t){return""===t.event})):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=x(this.config.entry||this.config.onEntry).map((function(t){return ft(t)})),this.onExit=x(this.config.exit||this.config.onExit).map((function(t){return ft(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=x(this.config.invoke).map((function(t,n){var r,i;if(k(t))return u.machine.options.services=e(((r={})[t.id]=t,r),u.machine.options.services),Lt({src:t.id,id:t.id});if(N(t.src))return Lt(e(e({},t),{id:t.id||t.src,src:t.src}));if(k(t.src)||T(t.src)){var o=u.id+":invocation["+n+"]";return u.machine.options.services=e(((i={})[o]=t.src,i),u.machine.options.services),Lt(e(e({id:o},t),{src:o}))}var a=t.src;return Lt(e(e({id:a.type},t),{src:a}))})),this.activities=x(this.config.activities).concat(this.invoke).map((function(t){return dt(t)})),this.transition=this.transition.bind(this),this.tags=x(this.config.tags)}return a.prototype._init=function(){this.__cache.transitions||J(this).forEach((function(t){return t.on}))},a.prototype.withConfig=function(t,n){void 0===n&&(n=this.context);var r=this.options,i=r.actions,o=r.activities,s=r.guards,c=r.services,u=r.delays;return new a(this.config,{actions:e(e({},i),t.actions),activities:e(e({},o),t.activities),guards:e(e({},s),t.guards),services:e(e({},c),t.services),delays:e(e({},u),t.delays)},n)},a.prototype.withContext=function(t){return new a(this.config,this.options,t)},Object.defineProperty(a.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:d(this.states,(function(t){return t.definition})),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke}},enumerable:!1,configurable:!0}),a.prototype.toJSON=function(){return this.definition},Object.defineProperty(a.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var t=this.transitions;return this.__cache.on=t.reduce((function(t,e){return t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t}),{})},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),a.prototype.getCandidates=function(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];var e=""===t,n=this.transitions.filter((function(n){var r=n.eventType===t;return e?r:r||"*"===n.eventType}));return this.__cache.candidates[t]=n,n},a.prototype.getDelayedTransitions=function(){var t=this,n=this.config.after;if(!n)return[];var r=function(e,n){var r=_t(T(e)?t.id+":delay["+n+"]":e,t.id);return t.onEntry.push(pt(r,{delay:e})),t.onExit.push(xt(r)),r};return(E(n)?n.map((function(t,n){var i=r(t.delay,n);return e(e({},t),{event:i})})):g(s(n).map((function(t,i){var o=n[t],a=N(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=r(s,i);return x(a).map((function(t){return e(e({},t),{event:c,delay:s})}))})))).map((function(n){var r=n.delay;return e(e({},t.formatTransition(n)),{delay:r})}))},a.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof Pt?t.value:f(t,this.delimiter);if(N(r)){var i=this.getStateNode(r).initial;return void 0!==i?this.getStateNodes(((e={})[r]=i,e)):[this.states[r]]}var o=s(r);return o.map((function(t){return n.getStateNode(t)})).concat(o.reduce((function(t,e){var i=n.getStateNode(e).getStateNodes(r[e]);return t.concat(i)}),[]))},a.prototype.handles=function(t){var e=u(t);return this.events.includes(e)},a.prototype.resolveState=function(t){var n=Array.from(B([],this.getStateNodes(t.value)));return new Pt(e(e({},t),{value:this.resolve(t.value),configuration:n,done:H(n,this)}))},a.prototype.transitionLeafNode=function(t,e,n){var r=this.getStateNode(t).next(e,n);return r&&r.transitions.length?r:this.next(e,n)},a.prototype.transitionCompoundNode=function(t,e,n){var r=s(t),i=this.getStateNode(r[0])._transition(t[r[0]],e,n);return i&&i.transitions.length?i:this.next(e,n)},a.prototype.transitionParallelNode=function(t,e,n){var i,o,a={};try{for(var c=r(s(t)),u=c.next();!u.done;u=c.next()){var h=u.value,f=t[h];if(f){var l=this.getStateNode(h)._transition(f,e,n);l&&(a[h]=l)}}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(i)throw i.error}}var d=s(a).map((function(t){return a[t]})),v=g(d.map((function(t){return t.transitions})));if(!d.some((function(t){return t.transitions.length>0})))return this.next(e,n);var p=g(d.map((function(t){return t.entrySet}))),y=g(s(a).map((function(t){return a[t].configuration})));return{transitions:v,entrySet:p,exitSet:g(d.map((function(t){return t.exitSet}))),configuration:y,source:e,actions:g(s(a).map((function(t){return a[t].actions})))}},a.prototype._transition=function(t,e,n){return N(t)?this.transitionLeafNode(t,e,n):1===s(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},a.prototype.next=function(t,e){var n,i,a,s=this,u=e.name,h=[],l=[];try{for(var d=r(this.getCandidates(u)),v=d.next();!v.done;v=d.next()){var y=v.value,m=y.cond,x=y.in,S=t.context,w=!x||(N(x)&&Mt(x)?t.matches(f(this.getStateNodeById(x).path,this.delimiter)):c(f(x,this.delimiter),p(this.path.slice(0,-2))(t.value))),b=!1;try{b=!m||R(this.machine,m,S,e,t)}catch(t){throw new Error("Unable to evaluate guard '"+(m.name||m.type)+"' in transition for event '"+u+"' in state node '"+this.id+"':\n"+t.message)}if(b&&w){void 0!==y.target&&(l=y.target),h.push.apply(h,o(y.actions)),a=y;break}}}catch(t){n={error:t}}finally{try{v&&!v.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}if(a){if(!l.length)return{transitions:[a],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:h};var _=g(l.map((function(e){return s.getRelativeStateNodes(e,t.historyValue)}))),E=!!a.internal;return{transitions:[a],entrySet:E?[]:g(_.map((function(t){return s.nodesFromChild(t)}))),exitSet:E?[]:[this],configuration:_,source:t,actions:h}}},a.prototype.nodesFromChild=function(t){if(t.escapes(this))return[];for(var e=[],n=t;n&&n!==this;)e.push(n),n=n.parent;return e.push(this),e},a.prototype.escapes=function(t){if(this===t)return!1;for(var e=this.parent;e;){if(e===t)return!1;e=e.parent}return!0},a.prototype.getActions=function(t,e,n,a){var s,c,u,h,f=B([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?B(f,t.configuration):f;try{for(var d=r(l),v=d.next();!v.done;v=d.next()){X(f,m=v.value)||t.entrySet.push(m)}}catch(t){s={error:t}}finally{try{v&&!v.done&&(c=d.return)&&c.call(d)}finally{if(s)throw s.error}}try{for(var p=r(f),y=p.next();!y.done;y=p.next()){var m;X(l,m=y.value)&&!X(t.exitSet,m.parent)||t.exitSet.push(m)}}catch(t){u={error:t}}finally{try{y&&!y.done&&(h=p.return)&&h.call(p)}finally{if(u)throw u.error}}t.source||(t.exitSet=[],t.entrySet.push(this));var x=g(t.entrySet.map((function(r){var i=[];if("final"!==r.type)return i;var o=r.parent;if(!o.parent)return i;i.push(Et(r.id,r.doneData),Et(o.id,r.doneData?S(r.doneData,e,n):void 0));var a=o.parent;return"parallel"===a.type&&U(a).every((function(e){return H(t.configuration,e)}))&&i.push(Et(a.id)),i})));t.exitSet.sort((function(t,e){return e.order-t.order})),t.entrySet.sort((function(t,e){return t.order-e.order}));var w=new Set(t.entrySet),b=new Set(t.exitSet),_=i([g(Array.from(w).map((function(t){return o(t.activities.map((function(t){return St(t)})),t.onEntry)}))).concat(x.map(vt)),g(Array.from(b).map((function(t){return o(t.onExit,t.activities.map((function(t){return wt(t)})))})))],2),E=_[0],T=_[1];return lt(T.concat(t.actions).concat(E),this.machine.options.actions)},a.prototype.transition=function(t,e,n){void 0===t&&(t=this.initialState);var r,i,a=D(e);if(t instanceof Pt)r=void 0===n?t:this.resolveState(Pt.from(t,n));else{var s=N(t)?this.resolve(l(this.getResolvedPath(t))):this.resolve(t),c=n||this.machine.context;r=this.resolveState(Pt.from(s,c))}if(this.strict&&!this.events.includes(a.name)&&(i=a.name,!/^(done|error)\./.test(i)))throw new Error("Machine '"+this.id+"' does not accept event '"+a.name+"'");var u=this._transition(r.value,r,a)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:r,actions:[]},h=B([],this.getStateNodes(r.value)),f=u.configuration.length?B(h,u.configuration):h;return u.configuration=o(f),this.resolveTransition(u,r,a)},a.prototype.resolveRaisedTransition=function(t,e,n){var r,i=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(r=t.actions).unshift.apply(r,o(i)),t},a.prototype.resolveTransition=function(n,o,a,c){var u,h,f=this;void 0===a&&(a=ut),void 0===c&&(c=this.machine.context);var l=n.configuration,d=!o||n.transitions.length>0?$(this.machine,l):void 0,v=o?o.historyValue?o.historyValue:n.source?this.machine.historyValue(o.value):void 0:void 0,p=o?o.context:c,y=this.getActions(n,p,a,o),m=o?e({},o.activities):{};try{for(var x=r(y),w=x.next();!w.done;w=x.next()){var E=w.value;E.type===G?m[E.activity.id||E.activity.type]=E:E.type===K&&(m[E.activity.id||E.activity.type]=!1)}}catch(t){u={error:t}}finally{try{w&&!w.done&&(h=x.return)&&h.call(x)}finally{if(u)throw u.error}}var T,O,A=i(At(this,o,p,a,y),2),P=A[0],k=A[1],I=i(b(P,(function(e){return e.type===Q||e.type===W&&e.to===t.SpecialTargets.Internal})),2),j=I[0],C=I[1],V=P.filter((function(t){var e;return t.type===G&&(null===(e=t.activity)||void 0===e?void 0:e.type)===rt})).reduce((function(t,e){return t[e.activity.id]=function(t,e,n,r){var i,o=z(t.src),a=null===(i=null==e?void 0:e.options.services)||void 0===i?void 0:i[o.type],s=t.data?S(t.data,n,r):void 0,c=a?Ct(a,t.id,s):jt(t.id);return c.meta=t,c}(e.activity,f.machine,k,a),t}),o?e({},o.children):{}),L=d?n.configuration:o?o.configuration:[],D=L.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{}),M=H(L,this),R=new Pt({value:d||o.value,context:k,_event:a,_sessionid:o?o._sessionid:null,historyValue:d?v?(T=v,O=d,{current:O,states:_(T,O)}):void 0:o?o.historyValue:void 0,history:!d||n.source?o:void 0,actions:d?C:[],activities:d?m:o?o.activities:{},meta:d?D:o?o.meta:void 0,events:[],configuration:L,transitions:n.transitions,children:V,done:M}),F=p!==k;R.changed=a.name===at||F;var U=R.history;if(U&&delete U.history,!d)return R;var J=R;if(!M)for((this._transient||l.some((function(t){return t._transient})))&&(J=this.resolveRaisedTransition(J,{type:Z},a));j.length;){var B=j.shift();J=this.resolveRaisedTransition(J,B._event,a)}var q=J.changed||(U?!!J.actions.length||F||typeof U.value!=typeof J.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(N(e)||N(n))return e===n;var r=s(e),i=s(n);return r.length===i.length&&r.every((function(r){return t(e[r],n[r])}))}(J.value,U.value):void 0);return J.changed=q,J.history=U,J.tags=new Set(g(J.configuration.map((function(t){return t.tags})))),J},a.prototype.getStateNode=function(t){if(Mt(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error("Unable to retrieve child state '"+t+"' from '"+this.id+"'; no child states exist.");var e=this.states[t];if(!e)throw new Error("Child state '"+t+"' does not exist on '"+this.id+"'");return e},a.prototype.getStateNodeById=function(t){var e=Mt(t)?t.slice("#".length):t;if(e===this.id)return this;var n=this.machine.idMap[e];if(!n)throw new Error("Child state node '#"+e+"' does not exist on machine '"+this.id+"'");return n},a.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&Mt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=h(t,this.delimiter).slice(),n=this;e.length;){var r=e.shift();if(!r.length)break;n=n.getStateNode(r)}return n},a.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||Dt;switch(this.type){case"parallel":return d(this.initialStateValue,(function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):Dt}));case"compound":if(N(t)){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return s(t).length?d(t,(function(t,e){return t?n.getStateNode(e).resolve(t):Dt})):this.initialStateValue||{};default:return t||Dt}},a.prototype.getResolvedPath=function(t){if(Mt(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return h(t,this.delimiter)},Object.defineProperty(a.prototype,"initialStateValue",{get:function(){var t,e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;if("parallel"===this.type)e=v(this.states,(function(t){return t.initialStateValue||Dt}),(function(t){return!("history"===t.type)}));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error("Initial state '"+this.initial+"' not found on '"+this.key+"'");e=F(this.states[this.initial])?this.initial:((t={})[this.initial]=this.states[this.initial].initialStateValue,t)}else e={};return this.__cache.initialStateValue=e,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),a.prototype.getInitialState=function(t,e){var n=this.getStateNodes(t);return this.resolveTransition({configuration:n,entrySet:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)},Object.defineProperty(a.prototype,"initialState",{get:function(){this._init();var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '"+this.id+"'.");return this.getInitialState(t)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=N(e.target)&&Mt(e.target)?l(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!1,configurable:!0}),a.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(a.prototype,"initialStateNodes",{get:function(){var t=this;return F(this)?[this]:"compound"!==this.type||this.initial?g(y(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!1,configurable:!0}),a.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=i(t),n=e[0],r=e.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+n+"' from node with no states");var o=this.getStateNode(n);if("history"===o.type)return o.resolveHistory();if(!this.states[n])throw new Error("Child state '"+n+"' does not exist on '"+this.id+"'");return this.states[n].getFromRelativePath(r)},a.prototype.historyValue=function(t){if(s(this.states).length)return{current:t||this.initialStateValue,states:v(this.states,(function(e,n){if(!t)return e.historyValue();var r=N(t)?void 0:t[n];return e.historyValue(r||e.initialStateValue)}),(function(t){return!t.history}))}},a.prototype.resolveHistory=function(t){var e=this;if("history"!==this.type)return[this];var n=this.parent;if(!t){var i=this.target;return i?g(y(i).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var o,a,s=(o=n.path,a="states",function(t){var e,n,i=t;try{for(var s=r(o),c=s.next();!c.done;c=s.next()){var u=c.value;i=i[a][u]}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return i})(t).current;return N(s)?[n.getStateNode(s)]:g(y(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(a.prototype,"stateIds",{get:function(){var t=this,e=g(s(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"events",{get:function(){var t,e,n,i;if(this.__cache.events)return this.__cache.events;var o=this.states,a=new Set(this.ownEvents);if(o)try{for(var c=r(s(o)),u=c.next();!u.done;u=c.next()){var h=o[u.value];if(h.states)try{for(var f=(n=void 0,r(h.events)),l=f.next();!l.done;l=f.next()){var d=l.value;a.add(""+d)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(i=f.return)&&i.call(f)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{u&&!u.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(a)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"ownEvents",{get:function(){var t=new Set(this.transitions.filter((function(t){return!(!t.target&&!t.actions.length&&t.internal)})).map((function(t){return t.eventType})));return Array.from(t)},enumerable:!1,configurable:!0}),a.prototype.resolveTarget=function(t){var e=this;if(void 0!==t)return t.map((function(t){if(!N(t))return t;var n=t[0]===e.delimiter;if(n&&!e.parent)return e.getStateNodeByPath(t.slice(1));var r=n?e.key+t:t;if(!e.parent)return e.getStateNodeByPath(r);try{return e.parent.getStateNodeByPath(r)}catch(t){throw new Error("Invalid transition definition for state node '"+e.id+"':\n"+t.message)}}))},a.prototype.formatTransition=function(t){var n=this,r=function(t){if(void 0!==t&&""!==t)return x(t)}(t.target),i="internal"in t?t.internal:!r||r.some((function(t){return N(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(r),s=e(e({},t),{actions:lt(x(t.actions)),cond:O(t.cond,o),target:a,source:this,internal:i,eventType:t.event,toJSON:function(){return e(e({},s),{target:s.target?s.target.map((function(t){return"#"+t.id})):void 0,source:"#"+n.id})}});return s},a.prototype.formatTransitions=function(){var t,e,i,a=this;if(this.config.on)if(Array.isArray(this.config.on))i=this.config.on;else{var c=this.config.on,u=c["*"],h=void 0===u?[]:u,f=n(c,["*"]);i=g(s(f).map((function(t){return M(t,f[t])})).concat(M("*",h)))}else i=[];var l=this.config.always?M("",this.config.always):[],d=this.config.onDone?M(String(Et(this.id)),this.config.onDone):[],v=g(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o(M(String(Tt(t.id)),t.onDone))),t.onError&&e.push.apply(e,o(M(String(Nt(t.id)),t.onError))),e}))),p=this.after,y=g(o(d,v,i,l).map((function(t){return x(t).map((function(t){return a.formatTransition(t)}))})));try{for(var m=r(p),S=m.next();!S.done;S=m.next()){var w=S.value;y.push(w)}}catch(e){t={error:e}}finally{try{S&&!S.done&&(e=m.return)&&e.call(m)}finally{if(t)throw t.error}}return y},a}();var zt={deferEvents:!1},Ft=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=e(e({},zt),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),Ut=new Map,Jt=0,Bt=function(){return"x:"+Jt++},qt=function(t,e){return Ut.set(t,e),t},$t=function(t){return Ut.get(t)},Xt=function(t){Ut.delete(t)};function Ht(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Gt(t){if(Ht()){var e=function(){var t=Ht();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}var Kt,Qt={sync:!1,autoForward:!1};(Kt=t.InterpreterStatus||(t.InterpreterStatus={}))[Kt.NotStarted=0]="NotStarted",Kt[Kt.Running=1]="Running",Kt[Kt.Stopped=2]="Stopped";var Wt=function(){function n(r,i){var o=this;void 0===i&&(i=n.defaultOptions),this.machine=r,this.scheduler=new Ft,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if(E(e))return o.batch(e),o.state;var r=D(L(e,n));if(o.status===t.InterpreterStatus.Stopped)return o.state;if(o.status!==t.InterpreterStatus.Running&&!o.options.deferEvents)throw new Error('Event "'+r.name+'" was sent to uninitialized service "'+o.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: '+JSON.stringify(r.data));return o.scheduler.schedule((function(){o.forward(r);var t=o.nextState(r);o.update(t,r)})),o._state},this.sendTo=function(n,r){var i,a=o.parent&&(r===t.SpecialTargets.Parent||o.parent.id===r),s=a?o.parent:N(r)?o.children.get(r)||$t(r):(i=r)&&"function"==typeof i.send?r:void 0;if(s)"machine"in s?s.send(e(e({},n),{name:n.name===ot?""+Nt(o.id):n.name,origin:o.sessionId})):s.send(n.data);else if(!a)throw new Error("Unable to send event to child '"+r+"' from service '"+o.id+"'.")};var a=e(e({},n.defaultOptions),i),s=a.clock,c=a.logger,u=a.parent,h=a.id,f=void 0!==h?h:r.id;this.id=f,this.logger=c,this.clock=s,this.parent=u,this.options=a,this.scheduler=new Ft({deferEvents:this.options.deferEvents}),this.sessionId=Bt()}return Object.defineProperty(n.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:It(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),n.prototype.execute=function(t,e){var n,i;try{for(var o=r(t.actions),a=o.next();!a.done;a=o.next()){var s=a.value;this.exec(s,t,e)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}},n.prototype.update=function(t,e){var n,i,o,a,s,c,u,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){f.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var l=r(this.eventListeners),d=l.next();!d.done;d=l.next()){(0,d.value)(t.event)}}catch(t){n={error:t}}finally{try{d&&!d.done&&(i=l.return)&&i.call(l)}finally{if(n)throw n.error}}try{for(var v=r(this.listeners),p=v.next();!p.done;p=v.next()){(0,p.value)(t,t.event)}}catch(t){o={error:t}}finally{try{p&&!p.done&&(a=v.return)&&a.call(v)}finally{if(o)throw o.error}}try{for(var y=r(this.contextListeners),g=y.next();!g.done;g=y.next()){(0,g.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){s={error:t}}finally{try{g&&!g.done&&(c=y.return)&&c.call(y)}finally{if(s)throw s.error}}var m=H(t.configuration||[],this.machine);if(this.state.configuration&&m){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),w=x&&x.doneData?S(x.doneData,t.context,e):void 0;try{for(var b=r(this.doneListeners),_=b.next();!_.done;_=b.next()){(0,_.value)(Tt(this.id,w))}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}this.stop()}},n.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},n.prototype.subscribe=function(e,n,r){var i,o=this;if(!e)return{unsubscribe:function(){}};var a=r;return"function"==typeof e?i=e:(i=e.next.bind(e),a=e.complete.bind(e)),this.listeners.add(i),this.status===t.InterpreterStatus.Running&&i(this.state),a&&this.onDone(a),{unsubscribe:function(){i&&o.listeners.delete(i),a&&o.doneListeners.delete(a)}}},n.prototype.onEvent=function(t){return this.eventListeners.add(t),this},n.prototype.onSend=function(t){return this.sendListeners.add(t),this},n.prototype.onChange=function(t){return this.contextListeners.add(t),this},n.prototype.onStop=function(t){return this.stopListeners.add(t),this},n.prototype.onDone=function(t){return this.doneListeners.add(t),this},n.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},n.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;qt(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:It(this,(function(){return!N(t=e)&&"value"in t&&"history"in t?n.machine.resolveState(e):n.machine.resolveState(Pt.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,ut)})),this},n.prototype.stop=function(){var e,n,i,o,a,c,u,h,f,l,d=this;try{for(var v=r(this.listeners),p=v.next();!p.done;p=v.next()){var y=p.value;this.listeners.delete(y)}}catch(t){e={error:t}}finally{try{p&&!p.done&&(n=v.return)&&n.call(v)}finally{if(e)throw e.error}}try{for(var g=r(this.stopListeners),m=g.next();!m.done;m=g.next()){(y=m.value)(),this.stopListeners.delete(y)}}catch(t){i={error:t}}finally{try{m&&!m.done&&(o=g.return)&&o.call(g)}finally{if(i)throw i.error}}try{for(var x=r(this.contextListeners),S=x.next();!S.done;S=x.next()){y=S.value;this.contextListeners.delete(y)}}catch(t){a={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}finally{if(a)throw a.error}}try{for(var w=r(this.doneListeners),b=w.next();!b.done;b=w.next()){y=b.value;this.doneListeners.delete(y)}}catch(t){u={error:t}}finally{try{b&&!b.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}if(!this.initialized)return this;this.state.configuration.forEach((function(t){var e,n;try{for(var i=r(t.definition.exit),o=i.next();!o.done;o=i.next()){var a=o.value;d.exec(a,d.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){T(t.stop)&&t.stop()}));try{for(var _=r(s(this.delayedEventsMap)),E=_.next();!E.done;E=_.next()){var N=E.value;this.clock.clearTimeout(this.delayedEventsMap[N])}}catch(t){f={error:t}}finally{try{E&&!E.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,Xt(this.sessionId),this},n.prototype.batch=function(n){var i=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error(n.length+' event(s) were sent to uninitialized service "'+this.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.');this.scheduler.schedule((function(){var t,a,s=i.state,c=!1,u=[],h=function(t){var n=D(t);i.forward(n),s=It(i,(function(){return i.machine.transition(s,n)})),u.push.apply(u,o(s.actions.map((function(t){return r=s,i=(n=t).exec,e(e({},n),{exec:void 0!==i?function(){return i(r.context,r.event,{action:n,state:r,_event:r._event})}:void 0});var n,r,i})))),c=c||!!s.changed};try{for(var f=r(n),l=f.next();!l.done;l=f.next()){h(l.value)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(t)throw t.error}}s.changed=c,s.actions=u,i.update(s,D(n[n.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=D(t);if(0===n.name.indexOf(it)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(it)})))throw n.data.data;return It(this,(function(){return e.machine.transition(e.state,n)}))},n.prototype.forward=function(t){var e,n;try{for(var i=r(this.forwardTo),o=i.next();!o.done;o=i.next()){var a=o.value,s=this.children.get(a);if(!s)throw new Error("Unable to forward event '"+t+"' from interpreter '"+this.id+"' to nonexistant child '"+a+"'.");s.send(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},n.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to):e.send(t._event)}),t.delay)},n.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},n.prototype.exec=function(e,n,r){void 0===r&&(r=this.machine.options.actions);var i=n.context,o=n._event,a=e.exec||ht(e.type,r),s=T(a)?a:a?a.exec:e.exec;if(s)try{return s(i,o.data,{action:e,state:this.state,_event:o})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case W:var c=e;if("number"==typeof c.delay)return void this.defer(c);c.to?this.sendTo(c._event,c.to):this.send(c._event);break;case Y:this.cancel(e.sendId);break;case G:var u=e.activity;if(!this.state.activities[u.id||u.type])break;if(u.type===t.ActionTypes.Invoke){var h=z(u.src),f=this.machine.options.services?this.machine.options.services[h.type]:void 0,l=u.id,d=u.data,v="autoForward"in u?u.autoForward:!!u.forward;if(!f)return;var p=d?S(d,i,o):void 0,y=T(f)?f(i,o.data,{data:p,src:h}):f;w(y)?this.spawnPromise(Promise.resolve(y),l):T(y)?this.spawnCallback(y,l):A(y)?this.spawnObservable(y,l):k(y)&&this.spawnMachine(p?y.withContext(p):y,{id:l,autoForward:v})}else this.spawnActivity(u);break;case K:this.stopChild(e.activity.id);break;case et:var g=e.label,m=e.value;g?this.logger(g,m):this.logger(m)}},n.prototype.removeChild=function(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]},n.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),T(e.stop)&&e.stop())},n.prototype.spawn=function(t,n,r){if(w(t))return this.spawnPromise(Promise.resolve(t),n);if(T(t))return this.spawnCallback(t,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(i=t)&&"id"in i)return this.spawnActor(t);if(A(t))return this.spawnObservable(t,n);if(k(t))return this.spawnMachine(t,e(e({},r),{id:n}));throw new Error('Unable to spawn entity "'+n+'" of type "'+typeof t+'".');var i},n.prototype.spawnMachine=function(t,r){var i=this;void 0===r&&(r={});var o=new n(t,e(e({},this.options),{parent:this,id:r.id||t.id})),a=e(e({},Qt),r);a.sync&&o.onTransition((function(t){i.send(at,{state:t,id:o.id})}));var s=o;return this.children.set(o.id,s),a.autoForward&&this.forwardTo.add(o.id),o.onDone((function(t){i.removeChild(o.id),i.send(D(t,{origin:o.id}))})).start(),s},n.prototype.spawnPromise=function(t,e){var n=this,r=!1;t.then((function(t){r||(n.removeChild(e),n.send(D(Tt(e,t),{origin:e})))}),(function(t){if(!r){n.removeChild(e);var i=Nt(e,t);try{n.send(D(i,{origin:e}))}catch(t){n.devTools&&n.devTools.send(i,n.state),n.machine.strict&&n.stop()}}}));var i={id:e,send:function(){},subscribe:function(e,n,r){var i=function(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}(e,n,r),o=!1;return t.then((function(t){o||(i.next(t),o||i.complete())}),(function(t){o||i.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){r=!0},toJSON:function(){return{id:e}}};return this.children.set(e,i),i},n.prototype.spawnCallback=function(t,e){var n,r=this,i=!1,o=new Set,a=new Set;try{n=t((function(t){a.forEach((function(e){return e(t)})),i||r.send(D(t,{origin:e}))}),(function(t){o.add(t)}))}catch(t){this.send(Nt(e,t))}if(w(n))return this.spawnPromise(n,e);var s={id:e,send:function(t){return o.forEach((function(e){return e(t)}))},subscribe:function(t){return a.add(t),{unsubscribe:function(){a.delete(t)}}},stop:function(){i=!0,T(n)&&n()},toJSON:function(){return{id:e}}};return this.children.set(e,s),s},n.prototype.spawnObservable=function(t,e){var n=this,r=t.subscribe((function(t){n.send(D(t,{origin:e}))}),(function(t){n.removeChild(e),n.send(D(Nt(e,t),{origin:e}))}),(function(){n.removeChild(e),n.send(D(Tt(e),{origin:e}))})),i={id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return r.unsubscribe()},toJSON:function(){return{id:e}}};return this.children.set(e,i),i},n.prototype.spawnActor=function(t){return this.children.set(t.id,t),t},n.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},n.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,toJSON:function(){return{id:t}}})},n.prototype.attachDev=function(){var t=Ht();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var n="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(e(e({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},n),{features:e({jump:!1,skip:!1},n?n.features:void 0)}),this.machine),this.devTools.init(this.state)}Gt(this)}},n.prototype.toJSON=function(){return{id:this.id}},n.prototype[P]=function(){return this},n.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"!=typeof self?self:global),n.interpret=Yt,n}();function Yt(t,e){return new Wt(t,e)}var Zt={raise:vt,send:pt,sendParent:yt,sendUpdate:gt,log:function(t,e){return void 0===t&&(t=mt),{type:et,label:e,expr:t}},cancel:xt,start:St,stop:wt,assign:bt,after:_t,done:Et,respond:function(t,n){return pt(t,e(e({},n),{to:function(t,e,n){return n._event.origin}}))},forwardTo:Ot,escalate:function(n,r){return yt((function(t,e,r){return{type:ot,data:T(n)?n(t,e,r):n}}),e(e({},r),{to:t.SpecialTargets.Parent}))},choose:function(e){return{type:t.ActionTypes.Choose,conds:e}},pure:function(e){return{type:t.ActionTypes.Pure,get:e}}};t.Interpreter=Wt,t.Machine=function(t,e,n){void 0===n&&(n=t.context);var r="function"==typeof n?n():n;return new Rt(t,e,r)},t.State=Pt,t.StateNode=Rt,t.actions=Zt,t.assign=bt,t.createMachine=function(t,e){var n="function"==typeof t.context?t.context():t.context;return new Rt(t,e,n)},t.createSchema=function(t){return t},t.doneInvoke=Tt,t.forwardTo=Ot,t.interpret=Yt,t.mapState=function(t,e){var n,i,o;try{for(var a=r(s(t)),u=a.next();!u.done;u=a.next()){var h=u.value;c(h,e)&&(!o||e.length>o.length)&&(o=h)}}catch(t){n={error:t}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return t[o]},t.matchState=function(t,e,n){var o,a,s=Pt.from(t,t instanceof Pt?t.context:void 0);try{for(var c=r(e),u=c.next();!u.done;u=c.next()){var h=i(u.value,2),f=h[0],l=h[1];if(s.matches(f))return l(s)}}catch(t){o={error:t}}finally{try{u&&!u.done&&(a=c.return)&&a.call(c)}finally{if(o)throw o.error}}return n(s)},t.matchesState=c,t.send=pt,t.sendParent=yt,t.sendUpdate=gt,t.spawn=function(t,n){var r=function(t){return N(t)?e(e({},Qt),{name:t}):e(e(e({},Qt),{name:V()}),t)}(n);return function(e){return e?e.spawn(t,r.name,r):Ct(t,r.name)}(kt[kt.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
15
+ ***************************************************************************** */var e=function(){return(e=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function n(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(r=o.next()).done;)a.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return a}function o(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(i(arguments[e]));return t}var a={};function s(t){return Object.keys(t)}function c(t,e,n){void 0===n&&(n=".");var r=f(t,n),i=f(e,n);return N(i)?!!N(r)&&i===r:N(r)?r in i:s(r).every((function(t){return t in i&&c(r[t],i[t])}))}function u(t){try{return N(t)||"number"==typeof t?""+t:t.type}catch(t){throw new Error("Events must be strings or objects with a string event.type property.")}}function h(t,e){try{return E(t)?t:t.toString().split(e)}catch(e){throw new Error("'"+t+"' is not a valid state path.")}}function f(t,e){return"object"==typeof(n=t)&&"value"in n&&"context"in n&&"event"in n&&"_event"in n?t.value:E(t)?l(t):"string"!=typeof t?t:l(h(t,e));var n}function l(t){if(1===t.length)return t[0];for(var e={},n=e,r=0;r<t.length-1;r++)r===t.length-2?n[t[r]]=t[r+1]:(n[t[r]]={},n=n[t[r]]);return e}function d(t,e){for(var n={},r=s(t),i=0;i<r.length;i++){var o=r[i];n[o]=e(t[o],o,t,i)}return n}function v(t,e,n){var i,o,a={};try{for(var c=r(s(t)),u=c.next();!u.done;u=c.next()){var h=u.value,f=t[h];n(f)&&(a[h]=e(f,h,t))}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(i)throw i.error}}return a}var p=function(t){return function(e){var n,i,o=e;try{for(var a=r(t),s=a.next();!s.done;s=a.next()){o=o[s.value]}}catch(t){n={error:t}}finally{try{s&&!s.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return o}};function y(t){return t?N(t)?[[t]]:g(s(t).map((function(e){var n=t[e];return"string"==typeof n||n&&Object.keys(n).length?y(t[e]).map((function(t){return[e].concat(t)})):[[e]]}))):[[]]}function g(t){var e;return(e=[]).concat.apply(e,o(t))}function m(t){return E(t)?t:[t]}function x(t){return void 0===t?[]:m(t)}function S(t,e,n){var i,o;if(T(t))return t(e,n.data);var a={};try{for(var s=r(Object.keys(t)),c=s.next();!c.done;c=s.next()){var u=c.value,h=t[u];T(h)?a[u]=h(e,n.data):a[u]=h}}catch(t){i={error:t}}finally{try{c&&!c.done&&(o=s.return)&&o.call(s)}finally{if(i)throw i.error}}return a}function w(t){return t instanceof Promise||!(null===t||!T(t)&&"object"!=typeof t||!T(t.then))}function b(t,e){var n,o,a=i([[],[]],2),s=a[0],c=a[1];try{for(var u=r(t),h=u.next();!h.done;h=u.next()){var f=h.value;e(f)?s.push(f):c.push(f)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(o=u.return)&&o.call(u)}finally{if(n)throw n.error}}return[s,c]}function _(t,e){return d(t.states,(function(t,n){if(t){var r=(N(e)?void 0:e[n])||(t?t.current:void 0);if(r)return{current:r,states:_(t,r)}}}))}function E(t){return Array.isArray(t)}function T(t){return"function"==typeof t}function N(t){return"string"==typeof t}function O(t,e){if(t)return N(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:T(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}function A(t){try{return"subscribe"in t&&T(t.subscribe)}catch(t){return!1}}var P="function"==typeof Symbol&&Symbol.observable||"@@observable";function k(t){try{return"__xstatenode"in t}catch(t){return!1}}var I,j,C,V=(I=0,function(){return(++I).toString(16)});function L(t,n){return N(t)||"number"==typeof t?e({type:t},n):t}function D(t,n){if(!N(t)&&"$$type"in t&&"scxml"===t.$$type)return t;var r=L(t);return e({name:r.type,data:r,$$type:"scxml",type:"external"},n)}function M(t,n){return m(n).map((function(n){return void 0===n||"string"==typeof n||k(n)?{target:n,event:t}:e(e({},n),{event:t})}))}function R(t,e,n,r,i){var o=t.options.guards,a={state:i,cond:e,_event:r};if("xstate.guard"===e.type)return e.predicate(n,r.data,a);var s=o[e.type];if(!s)throw new Error("Guard '"+e.type+"' is not implemented on machine '"+t.id+"'.");return s(n,r.data,a)}function z(t){return"string"==typeof t?{type:t}:t}(j=t.ActionTypes||(t.ActionTypes={})).Start="xstate.start",j.Stop="xstate.stop",j.Raise="xstate.raise",j.Send="xstate.send",j.Cancel="xstate.cancel",j.NullEvent="",j.Assign="xstate.assign",j.After="xstate.after",j.DoneState="done.state",j.DoneInvoke="done.invoke",j.Log="xstate.log",j.Init="xstate.init",j.Invoke="xstate.invoke",j.ErrorExecution="error.execution",j.ErrorCommunication="error.communication",j.ErrorPlatform="error.platform",j.ErrorCustom="xstate.error",j.Update="xstate.update",j.Pure="xstate.pure",j.Choose="xstate.choose",(C=t.SpecialTargets||(t.SpecialTargets={})).Parent="#_parent",C.Internal="#_internal";var F=function(t){return"atomic"===t.type||"final"===t.type};function U(t){return s(t.states).map((function(e){return t.states[e]}))}function J(t){var e=[t];return F(t)?e:e.concat(g(U(t).map(J)))}function B(t,e){var n,i,o,a,s,c,u,h,f=q(new Set(t)),l=new Set(e);try{for(var d=r(l),v=d.next();!v.done;v=d.next())for(var p=(E=v.value).parent;p&&!l.has(p);)l.add(p),p=p.parent}catch(t){n={error:t}}finally{try{v&&!v.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}var y=q(l);try{for(var g=r(l),m=g.next();!m.done;m=g.next()){if("compound"!==(E=m.value).type||y.get(E)&&y.get(E).length){if("parallel"===E.type)try{for(var x=(s=void 0,r(U(E))),S=x.next();!S.done;S=x.next()){var w=S.value;"history"!==w.type&&(l.has(w)||(l.add(w),f.get(w)?f.get(w).forEach((function(t){return l.add(t)})):w.initialStateNodes.forEach((function(t){return l.add(t)}))))}}catch(t){s={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}finally{if(s)throw s.error}}}else f.get(E)?f.get(E).forEach((function(t){return l.add(t)})):E.initialStateNodes.forEach((function(t){return l.add(t)}))}}catch(t){o={error:t}}finally{try{m&&!m.done&&(a=g.return)&&a.call(g)}finally{if(o)throw o.error}}try{for(var b=r(l),_=b.next();!_.done;_=b.next()){var E;for(p=(E=_.value).parent;p&&!l.has(p);)l.add(p),p=p.parent}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}return l}function q(t){var e,n,i=new Map;try{for(var o=r(t),a=o.next();!a.done;a=o.next()){var s=a.value;i.has(s)||i.set(s,[]),s.parent&&(i.has(s.parent)||i.set(s.parent,[]),i.get(s.parent).push(s))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return i}function $(t,e){return function t(e,n){var r=n.get(e);if(!r)return{};if("compound"===e.type){var i=r[0];if(!i)return{};if(F(i))return i.key}var o={};return r.forEach((function(e){o[e.key]=t(e,n)})),o}(t,q(B([t],e)))}function X(t,e){return Array.isArray(t)?t.some((function(t){return t===e})):t instanceof Set&&t.has(e)}function H(t,e){return"compound"===e.type?U(e).some((function(e){return"final"===e.type&&X(t,e)})):"parallel"===e.type&&U(e).every((function(e){return H(t,e)}))}var G=t.ActionTypes.Start,K=t.ActionTypes.Stop,Q=t.ActionTypes.Raise,W=t.ActionTypes.Send,Y=t.ActionTypes.Cancel,Z=t.ActionTypes.NullEvent,tt=t.ActionTypes.Assign,et=(t.ActionTypes.After,t.ActionTypes.DoneState,t.ActionTypes.Log),nt=t.ActionTypes.Init,rt=t.ActionTypes.Invoke,it=(t.ActionTypes.ErrorExecution,t.ActionTypes.ErrorPlatform),ot=t.ActionTypes.ErrorCustom,at=t.ActionTypes.Update,st=t.ActionTypes.Choose,ct=t.ActionTypes.Pure,ut=D({type:nt});function ht(t,e){return e&&e[t]||void 0}function ft(t,n){var r;if(N(t)||"number"==typeof t){var i=ht(t,n);r=T(i)?{type:t,exec:i}:i||{type:t,exec:void 0}}else if(T(t))r={type:t.name||t.toString(),exec:t};else{if(T(i=ht(t.type,n)))r=e(e({},t),{exec:i});else if(i){var o=i.type||t.type;r=e(e(e({},i),t),{type:o})}else r=t}return Object.defineProperty(r,"toString",{value:function(){return r.type},enumerable:!1,configurable:!0}),r}var lt=function(t,e){return t?(E(t)?t:[t]).map((function(t){return ft(t,e)})):[]};function dt(t){var n=ft(t);return e(e({id:N(t)?t:n.id},n),{type:n.type})}function vt(e){return N(e)?{type:Q,event:e}:pt(e,{to:t.SpecialTargets.Internal})}function pt(t,e){return{to:e?e.to:void 0,type:W,event:T(t)?t:L(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:T(t)?t.name:u(t)}}function yt(n,r){return pt(n,e(e({},r),{to:t.SpecialTargets.Parent}))}function gt(){return yt(at)}var mt=function(t,e){return{context:t,event:e}};var xt=function(t){return{type:Y,sendId:t}};function St(e){var n=dt(e);return{type:t.ActionTypes.Start,activity:n,exec:void 0}}function wt(e){var n=T(e)?e:dt(e);return{type:t.ActionTypes.Stop,activity:n,exec:void 0}}var bt=function(t){return{type:tt,assignment:t}};function _t(e,n){var r=n?"#"+n:"";return t.ActionTypes.After+"("+e+")"+r}function Et(e,n){var r=t.ActionTypes.DoneState+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function Tt(e,n){var r=t.ActionTypes.DoneInvoke+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function Nt(e,n){var r=t.ActionTypes.ErrorPlatform+"."+e,i={type:r,data:n,toString:function(){return r}};return i}function Ot(t,n){return pt((function(t,e){return e}),e(e({},n),{to:t}))}function At(n,o,a,c,u){var h=i(b(u,(function(t){return t.type===tt})),2),f=h[0],l=h[1],d=f.length?function(t,e,n,i){return t?n.reduce((function(t,n){var o,a,c=n.assignment,u={state:i,action:n,_event:e},h={};if(T(c))h=c(t,e.data,u);else try{for(var f=r(s(c)),l=f.next();!l.done;l=f.next()){var d=l.value,v=c[d];h[d]=T(v)?v(t,e.data,u):v}}catch(t){o={error:t}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(o)throw o.error}}return Object.assign({},t,h)}),t):t}(a,c,f,o):a;return[g(l.map((function(r){var i;switch(r.type){case Q:return{type:Q,_event:D(r.event)};case W:return function(t,n,r,i){var o,a={_event:r},s=D(T(t.event)?t.event(n,r.data,a):t.event);if(N(t.delay)){var c=i&&i[t.delay];o=T(c)?c(n,r.data,a):c}else o=T(t.delay)?t.delay(n,r.data,a):t.delay;var u=T(t.to)?t.to(n,r.data,a):t.to;return e(e({},t),{to:u,_event:s,event:s.data,delay:o})}(r,d,c,n.options.delays);case et:return function(t,n,r){return e(e({},t),{value:N(t.expr)?t.expr:t.expr(n,r.data,{_event:r})})}(r,d,c);case st:if(!(s=null===(i=r.conds.find((function(t){var e=O(t.cond,n.options.guards);return!e||R(n,e,d,c,o)})))||void 0===i?void 0:i.actions))return[];var a=At(n,o,d,c,lt(x(s),n.options.actions));return d=a[1],a[0];case ct:var s;if(!(s=r.get(d,c.data)))return[];a=At(n,o,d,c,lt(x(s),n.options.actions));return d=a[1],a[0];case K:return function(e,n,r){var i=T(e.activity)?e.activity(n,r.data):e.activity,o="string"==typeof i?{id:i}:i;return{type:t.ActionTypes.Stop,activity:o}}(r,d,c);default:return ft(r,n.options.actions)}}))),d]}var Pt=function(){function t(t){var e,n=this;this.actions=[],this.activities=a,this.meta={},this.events=[],this.value=t.value,this.context=t.context,this._event=t._event,this._sessionid=t._sessionid,this.event=this._event.data,this.historyValue=t.historyValue,this.history=t.history,this.actions=t.actions||[],this.activities=t.activities||a,this.meta=t.meta||{},this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=t.tags)&&void 0!==e?e:new Set,Object.defineProperty(this,"nextEvents",{get:function(){return t=n.configuration,g(o(new Set(t.map((function(t){return t.ownEvents})))));var t}})}return t.from=function(e,n){return e instanceof t?e.context!==n?new t({value:e.value,context:n,_event:e._event,_sessionid:null,historyValue:e.historyValue,history:e.history,actions:[],activities:e.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):e:new t({value:e,context:n,_event:ut,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},t.create=function(e){return new t(e)},t.inert=function(e,n){if(e instanceof t){if(!e.actions.length)return e;var r=ut;return new t({value:e.value,context:n,_event:r,_sessionid:null,historyValue:e.historyValue,history:e.history,activities:e.activities,configuration:e.configuration,transitions:[],children:{}})}return t.from(e,n)},t.prototype.toStrings=function(t,e){var n=this;if(void 0===t&&(t=this.value),void 0===e&&(e="."),N(t))return[t];var r=s(t);return r.concat.apply(r,o(r.map((function(r){return n.toStrings(t[r],e).map((function(t){return r+e+t}))}))))},t.prototype.toJSON=function(){this.configuration,this.transitions;var t=this.tags,r=n(this,["configuration","transitions","tags"]);return e(e({},r),{tags:Array.from(t)})},t.prototype.matches=function(t){return c(t,this.value)},t.prototype.hasTag=function(t){return this.tags.has(t)},t}(),kt=[],It=function(t,e){kt.push(t);var n=e(t);return kt.pop(),n};function jt(t){return{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},toJSON:function(){return{id:t}}}}function Ct(t,e,n){var r=jt(e);return r.deferred=!0,k(t)&&(r.state=It(void 0,(function(){return(n?t.withContext(n):t).initialState}))),r}function Vt(t){if("string"==typeof t){var e={type:t,toString:function(){return t}};return e}return t}function Lt(t){return e(e({type:rt},t),{toJSON:function(){t.onDone,t.onError;var r=n(t,["onDone","onError"]);return e(e({},r),{type:rt,src:Vt(t.src)})}})}var Dt={},Mt=function(t){return"#"===t[0]},Rt=function(){function a(t,n,i){var c,u=this;void 0===i&&(i=void 0),this.config=t,this.context=i,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},n),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||o([this.machine.key],this.path).join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&s(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(c=this.config.schema)&&void 0!==c?c:{},this.initial=this.config.initial,this.states=this.config.states?d(this.config.states,(function(t,n){var r,i=new a(t,{_parent:u,_key:n});return Object.assign(u.idMap,e(((r={})[i.id]=i,r),i.idMap)),i})):Dt;var h=0;!function t(e){var n,i;e.order=h++;try{for(var o=r(U(e)),a=o.next();!a.done;a=o.next()){t(a.value)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some((function(t){return""===t.event})):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=x(this.config.entry||this.config.onEntry).map((function(t){return ft(t)})),this.onExit=x(this.config.exit||this.config.onExit).map((function(t){return ft(t)})),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=x(this.config.invoke).map((function(t,n){var r,i;if(k(t))return u.machine.options.services=e(((r={})[t.id]=t,r),u.machine.options.services),Lt({src:t.id,id:t.id});if(N(t.src))return Lt(e(e({},t),{id:t.id||t.src,src:t.src}));if(k(t.src)||T(t.src)){var o=u.id+":invocation["+n+"]";return u.machine.options.services=e(((i={})[o]=t.src,i),u.machine.options.services),Lt(e(e({id:o},t),{src:o}))}var a=t.src;return Lt(e(e({id:a.type},t),{src:a}))})),this.activities=x(this.config.activities).concat(this.invoke).map((function(t){return dt(t)})),this.transition=this.transition.bind(this),this.tags=x(this.config.tags)}return a.prototype._init=function(){this.__cache.transitions||J(this).forEach((function(t){return t.on}))},a.prototype.withConfig=function(t,n){void 0===n&&(n=this.context);var r=this.options,i=r.actions,o=r.activities,s=r.guards,c=r.services,u=r.delays;return new a(this.config,{actions:e(e({},i),t.actions),activities:e(e({},o),t.activities),guards:e(e({},s),t.guards),services:e(e({},c),t.services),delays:e(e({},u),t.delays)},n)},a.prototype.withContext=function(t){return new a(this.config,this.options,t)},Object.defineProperty(a.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:d(this.states,(function(t){return t.definition})),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke}},enumerable:!1,configurable:!0}),a.prototype.toJSON=function(){return this.definition},Object.defineProperty(a.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var t=this.transitions;return this.__cache.on=t.reduce((function(t,e){return t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t}),{})},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),a.prototype.getCandidates=function(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];var e=""===t,n=this.transitions.filter((function(n){var r=n.eventType===t;return e?r:r||"*"===n.eventType}));return this.__cache.candidates[t]=n,n},a.prototype.getDelayedTransitions=function(){var t=this,n=this.config.after;if(!n)return[];var r=function(e,n){var r=_t(T(e)?t.id+":delay["+n+"]":e,t.id);return t.onEntry.push(pt(r,{delay:e})),t.onExit.push(xt(r)),r};return(E(n)?n.map((function(t,n){var i=r(t.delay,n);return e(e({},t),{event:i})})):g(s(n).map((function(t,i){var o=n[t],a=N(o)?{target:o}:o,s=isNaN(+t)?t:+t,c=r(s,i);return x(a).map((function(t){return e(e({},t),{event:c,delay:s})}))})))).map((function(n){var r=n.delay;return e(e({},t.formatTransition(n)),{delay:r})}))},a.prototype.getStateNodes=function(t){var e,n=this;if(!t)return[];var r=t instanceof Pt?t.value:f(t,this.delimiter);if(N(r)){var i=this.getStateNode(r).initial;return void 0!==i?this.getStateNodes(((e={})[r]=i,e)):[this.states[r]]}var o=s(r);return o.map((function(t){return n.getStateNode(t)})).concat(o.reduce((function(t,e){var i=n.getStateNode(e).getStateNodes(r[e]);return t.concat(i)}),[]))},a.prototype.handles=function(t){var e=u(t);return this.events.includes(e)},a.prototype.resolveState=function(t){var n=Array.from(B([],this.getStateNodes(t.value)));return new Pt(e(e({},t),{value:this.resolve(t.value),configuration:n,done:H(n,this)}))},a.prototype.transitionLeafNode=function(t,e,n){var r=this.getStateNode(t).next(e,n);return r&&r.transitions.length?r:this.next(e,n)},a.prototype.transitionCompoundNode=function(t,e,n){var r=s(t),i=this.getStateNode(r[0])._transition(t[r[0]],e,n);return i&&i.transitions.length?i:this.next(e,n)},a.prototype.transitionParallelNode=function(t,e,n){var i,o,a={};try{for(var c=r(s(t)),u=c.next();!u.done;u=c.next()){var h=u.value,f=t[h];if(f){var l=this.getStateNode(h)._transition(f,e,n);l&&(a[h]=l)}}}catch(t){i={error:t}}finally{try{u&&!u.done&&(o=c.return)&&o.call(c)}finally{if(i)throw i.error}}var d=s(a).map((function(t){return a[t]})),v=g(d.map((function(t){return t.transitions})));if(!d.some((function(t){return t.transitions.length>0})))return this.next(e,n);var p=g(d.map((function(t){return t.entrySet}))),y=g(s(a).map((function(t){return a[t].configuration})));return{transitions:v,entrySet:p,exitSet:g(d.map((function(t){return t.exitSet}))),configuration:y,source:e,actions:g(s(a).map((function(t){return a[t].actions})))}},a.prototype._transition=function(t,e,n){return N(t)?this.transitionLeafNode(t,e,n):1===s(t).length?this.transitionCompoundNode(t,e,n):this.transitionParallelNode(t,e,n)},a.prototype.next=function(t,e){var n,i,a,s=this,u=e.name,h=[],l=[];try{for(var d=r(this.getCandidates(u)),v=d.next();!v.done;v=d.next()){var y=v.value,m=y.cond,x=y.in,S=t.context,w=!x||(N(x)&&Mt(x)?t.matches(f(this.getStateNodeById(x).path,this.delimiter)):c(f(x,this.delimiter),p(this.path.slice(0,-2))(t.value))),b=!1;try{b=!m||R(this.machine,m,S,e,t)}catch(t){throw new Error("Unable to evaluate guard '"+(m.name||m.type)+"' in transition for event '"+u+"' in state node '"+this.id+"':\n"+t.message)}if(b&&w){void 0!==y.target&&(l=y.target),h.push.apply(h,o(y.actions)),a=y;break}}}catch(t){n={error:t}}finally{try{v&&!v.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}if(a){if(!l.length)return{transitions:[a],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:h};var _=g(l.map((function(e){return s.getRelativeStateNodes(e,t.historyValue)}))),E=!!a.internal;return{transitions:[a],entrySet:E?[]:g(_.map((function(t){return s.nodesFromChild(t)}))),exitSet:E?[]:[this],configuration:_,source:t,actions:h}}},a.prototype.nodesFromChild=function(t){if(t.escapes(this))return[];for(var e=[],n=t;n&&n!==this;)e.push(n),n=n.parent;return e.push(this),e},a.prototype.escapes=function(t){if(this===t)return!1;for(var e=this.parent;e;){if(e===t)return!1;e=e.parent}return!0},a.prototype.getActions=function(t,e,n,a){var s,c,u,h,f=B([],a?this.getStateNodes(a.value):[this]),l=t.configuration.length?B(f,t.configuration):f;try{for(var d=r(l),v=d.next();!v.done;v=d.next()){X(f,m=v.value)||t.entrySet.push(m)}}catch(t){s={error:t}}finally{try{v&&!v.done&&(c=d.return)&&c.call(d)}finally{if(s)throw s.error}}try{for(var p=r(f),y=p.next();!y.done;y=p.next()){var m;X(l,m=y.value)&&!X(t.exitSet,m.parent)||t.exitSet.push(m)}}catch(t){u={error:t}}finally{try{y&&!y.done&&(h=p.return)&&h.call(p)}finally{if(u)throw u.error}}t.source||(t.exitSet=[],t.entrySet.push(this));var x=g(t.entrySet.map((function(r){var i=[];if("final"!==r.type)return i;var o=r.parent;if(!o.parent)return i;i.push(Et(r.id,r.doneData),Et(o.id,r.doneData?S(r.doneData,e,n):void 0));var a=o.parent;return"parallel"===a.type&&U(a).every((function(e){return H(t.configuration,e)}))&&i.push(Et(a.id)),i})));t.exitSet.sort((function(t,e){return e.order-t.order})),t.entrySet.sort((function(t,e){return t.order-e.order}));var w=new Set(t.entrySet),b=new Set(t.exitSet),_=i([g(Array.from(w).map((function(t){return o(t.activities.map((function(t){return St(t)})),t.onEntry)}))).concat(x.map(vt)),g(Array.from(b).map((function(t){return o(t.onExit,t.activities.map((function(t){return wt(t)})))})))],2),E=_[0],T=_[1];return lt(T.concat(t.actions).concat(E),this.machine.options.actions)},a.prototype.transition=function(t,e,n){void 0===t&&(t=this.initialState);var r,i,a=D(e);if(t instanceof Pt)r=void 0===n?t:this.resolveState(Pt.from(t,n));else{var s=N(t)?this.resolve(l(this.getResolvedPath(t))):this.resolve(t),c=n||this.machine.context;r=this.resolveState(Pt.from(s,c))}if(this.strict&&!this.events.includes(a.name)&&(i=a.name,!/^(done|error)\./.test(i)))throw new Error("Machine '"+this.id+"' does not accept event '"+a.name+"'");var u=this._transition(r.value,r,a)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:r,actions:[]},h=B([],this.getStateNodes(r.value)),f=u.configuration.length?B(h,u.configuration):h;return u.configuration=o(f),this.resolveTransition(u,r,a)},a.prototype.resolveRaisedTransition=function(t,e,n){var r,i=t.actions;return(t=this.transition(t,e))._event=n,t.event=n.data,(r=t.actions).unshift.apply(r,o(i)),t},a.prototype.resolveTransition=function(n,o,a,c){var u,h,f=this;void 0===a&&(a=ut),void 0===c&&(c=this.machine.context);var l=n.configuration,d=!o||n.transitions.length>0?$(this.machine,l):void 0,v=o?o.historyValue?o.historyValue:n.source?this.machine.historyValue(o.value):void 0:void 0,p=o?o.context:c,y=this.getActions(n,p,a,o),m=o?e({},o.activities):{};try{for(var x=r(y),w=x.next();!w.done;w=x.next()){var E=w.value;E.type===G?m[E.activity.id||E.activity.type]=E:E.type===K&&(m[E.activity.id||E.activity.type]=!1)}}catch(t){u={error:t}}finally{try{w&&!w.done&&(h=x.return)&&h.call(x)}finally{if(u)throw u.error}}var T,O,A=i(At(this,o,p,a,y),2),P=A[0],k=A[1],I=i(b(P,(function(e){return e.type===Q||e.type===W&&e.to===t.SpecialTargets.Internal})),2),j=I[0],C=I[1],V=P.filter((function(t){var e;return t.type===G&&(null===(e=t.activity)||void 0===e?void 0:e.type)===rt})).reduce((function(t,e){return t[e.activity.id]=function(t,e,n,r){var i,o=z(t.src),a=null===(i=null==e?void 0:e.options.services)||void 0===i?void 0:i[o.type],s=t.data?S(t.data,n,r):void 0,c=a?Ct(a,t.id,s):jt(t.id);return c.meta=t,c}(e.activity,f.machine,k,a),t}),o?e({},o.children):{}),L=d?n.configuration:o?o.configuration:[],D=L.reduce((function(t,e){return void 0!==e.meta&&(t[e.id]=e.meta),t}),{}),M=H(L,this),R=new Pt({value:d||o.value,context:k,_event:a,_sessionid:o?o._sessionid:null,historyValue:d?v?(T=v,O=d,{current:O,states:_(T,O)}):void 0:o?o.historyValue:void 0,history:!d||n.source?o:void 0,actions:d?C:[],activities:d?m:o?o.activities:{},meta:d?D:o?o.meta:void 0,events:[],configuration:L,transitions:n.transitions,children:V,done:M,tags:null==o?void 0:o.tags}),F=p!==k;R.changed=a.name===at||F;var U=R.history;if(U&&delete U.history,!d)return R;var J=R;if(!M)for((this._transient||l.some((function(t){return t._transient})))&&(J=this.resolveRaisedTransition(J,{type:Z},a));j.length;){var B=j.shift();J=this.resolveRaisedTransition(J,B._event,a)}var q=J.changed||(U?!!J.actions.length||F||typeof U.value!=typeof J.value||!function t(e,n){if(e===n)return!0;if(void 0===e||void 0===n)return!1;if(N(e)||N(n))return e===n;var r=s(e),i=s(n);return r.length===i.length&&r.every((function(r){return t(e[r],n[r])}))}(J.value,U.value):void 0);return J.changed=q,J.history=U,J.tags=new Set(g(J.configuration.map((function(t){return t.tags})))),J},a.prototype.getStateNode=function(t){if(Mt(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error("Unable to retrieve child state '"+t+"' from '"+this.id+"'; no child states exist.");var e=this.states[t];if(!e)throw new Error("Child state '"+t+"' does not exist on '"+this.id+"'");return e},a.prototype.getStateNodeById=function(t){var e=Mt(t)?t.slice("#".length):t;if(e===this.id)return this;var n=this.machine.idMap[e];if(!n)throw new Error("Child state node '#"+e+"' does not exist on machine '"+this.id+"'");return n},a.prototype.getStateNodeByPath=function(t){if("string"==typeof t&&Mt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}for(var e=h(t,this.delimiter).slice(),n=this;e.length;){var r=e.shift();if(!r.length)break;n=n.getStateNode(r)}return n},a.prototype.resolve=function(t){var e,n=this;if(!t)return this.initialStateValue||Dt;switch(this.type){case"parallel":return d(this.initialStateValue,(function(e,r){return e?n.getStateNode(r).resolve(t[r]||e):Dt}));case"compound":if(N(t)){var r=this.getStateNode(t);return"parallel"===r.type||"compound"===r.type?((e={})[t]=r.initialStateValue,e):t}return s(t).length?d(t,(function(t,e){return t?n.getStateNode(e).resolve(t):Dt})):this.initialStateValue||{};default:return t||Dt}},a.prototype.getResolvedPath=function(t){if(Mt(t)){var e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error("Unable to find state node '"+t+"'");return e.path}return h(t,this.delimiter)},Object.defineProperty(a.prototype,"initialStateValue",{get:function(){var t,e;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;if("parallel"===this.type)e=v(this.states,(function(t){return t.initialStateValue||Dt}),(function(t){return!("history"===t.type)}));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error("Initial state '"+this.initial+"' not found on '"+this.key+"'");e=F(this.states[this.initial])?this.initial:((t={})[this.initial]=this.states[this.initial].initialStateValue,t)}else e={};return this.__cache.initialStateValue=e,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),a.prototype.getInitialState=function(t,e){var n=this.getStateNodes(t);return this.resolveTransition({configuration:n,entrySet:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)},Object.defineProperty(a.prototype,"initialState",{get:function(){this._init();var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '"+this.id+"'.");return this.getInitialState(t)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"target",{get:function(){var t;if("history"===this.type){var e=this.config;t=N(e.target)&&Mt(e.target)?l(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t},enumerable:!1,configurable:!0}),a.prototype.getRelativeStateNodes=function(t,e,n){return void 0===n&&(n=!0),n?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]},Object.defineProperty(a.prototype,"initialStateNodes",{get:function(){var t=this;return F(this)?[this]:"compound"!==this.type||this.initial?g(y(this.initialStateValue).map((function(e){return t.getFromRelativePath(e)}))):[this]},enumerable:!1,configurable:!0}),a.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var e=i(t),n=e[0],r=e.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '"+n+"' from node with no states");var o=this.getStateNode(n);if("history"===o.type)return o.resolveHistory();if(!this.states[n])throw new Error("Child state '"+n+"' does not exist on '"+this.id+"'");return this.states[n].getFromRelativePath(r)},a.prototype.historyValue=function(t){if(s(this.states).length)return{current:t||this.initialStateValue,states:v(this.states,(function(e,n){if(!t)return e.historyValue();var r=N(t)?void 0:t[n];return e.historyValue(r||e.initialStateValue)}),(function(t){return!t.history}))}},a.prototype.resolveHistory=function(t){var e=this;if("history"!==this.type)return[this];var n=this.parent;if(!t){var i=this.target;return i?g(y(i).map((function(t){return n.getFromRelativePath(t)}))):n.initialStateNodes}var o,a,s=(o=n.path,a="states",function(t){var e,n,i=t;try{for(var s=r(o),c=s.next();!c.done;c=s.next()){var u=c.value;i=i[a][u]}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return i})(t).current;return N(s)?[n.getStateNode(s)]:g(y(s).map((function(t){return"deep"===e.history?n.getFromRelativePath(t):[n.states[t[0]]]})))},Object.defineProperty(a.prototype,"stateIds",{get:function(){var t=this,e=g(s(this.states).map((function(e){return t.states[e].stateIds})));return[this.id].concat(e)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"events",{get:function(){var t,e,n,i;if(this.__cache.events)return this.__cache.events;var o=this.states,a=new Set(this.ownEvents);if(o)try{for(var c=r(s(o)),u=c.next();!u.done;u=c.next()){var h=o[u.value];if(h.states)try{for(var f=(n=void 0,r(h.events)),l=f.next();!l.done;l=f.next()){var d=l.value;a.add(""+d)}}catch(t){n={error:t}}finally{try{l&&!l.done&&(i=f.return)&&i.call(f)}finally{if(n)throw n.error}}}}catch(e){t={error:e}}finally{try{u&&!u.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(a)},enumerable:!1,configurable:!0}),Object.defineProperty(a.prototype,"ownEvents",{get:function(){var t=new Set(this.transitions.filter((function(t){return!(!t.target&&!t.actions.length&&t.internal)})).map((function(t){return t.eventType})));return Array.from(t)},enumerable:!1,configurable:!0}),a.prototype.resolveTarget=function(t){var e=this;if(void 0!==t)return t.map((function(t){if(!N(t))return t;var n=t[0]===e.delimiter;if(n&&!e.parent)return e.getStateNodeByPath(t.slice(1));var r=n?e.key+t:t;if(!e.parent)return e.getStateNodeByPath(r);try{return e.parent.getStateNodeByPath(r)}catch(t){throw new Error("Invalid transition definition for state node '"+e.id+"':\n"+t.message)}}))},a.prototype.formatTransition=function(t){var n=this,r=function(t){if(void 0!==t&&""!==t)return x(t)}(t.target),i="internal"in t?t.internal:!r||r.some((function(t){return N(t)&&t[0]===n.delimiter})),o=this.machine.options.guards,a=this.resolveTarget(r),s=e(e({},t),{actions:lt(x(t.actions)),cond:O(t.cond,o),target:a,source:this,internal:i,eventType:t.event,toJSON:function(){return e(e({},s),{target:s.target?s.target.map((function(t){return"#"+t.id})):void 0,source:"#"+n.id})}});return s},a.prototype.formatTransitions=function(){var t,e,i,a=this;if(this.config.on)if(Array.isArray(this.config.on))i=this.config.on;else{var c=this.config.on,u=c["*"],h=void 0===u?[]:u,f=n(c,["*"]);i=g(s(f).map((function(t){return M(t,f[t])})).concat(M("*",h)))}else i=[];var l=this.config.always?M("",this.config.always):[],d=this.config.onDone?M(String(Et(this.id)),this.config.onDone):[],v=g(this.invoke.map((function(t){var e=[];return t.onDone&&e.push.apply(e,o(M(String(Tt(t.id)),t.onDone))),t.onError&&e.push.apply(e,o(M(String(Nt(t.id)),t.onError))),e}))),p=this.after,y=g(o(d,v,i,l).map((function(t){return x(t).map((function(t){return a.formatTransition(t)}))})));try{for(var m=r(p),S=m.next();!S.done;S=m.next()){var w=S.value;y.push(w)}}catch(e){t={error:e}}finally{try{S&&!S.done&&(e=m.return)&&e.call(m)}finally{if(t)throw t.error}}return y},a}();var zt={deferEvents:!1},Ft=function(){function t(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=e(e({},zt),t)}return t.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()},t.prototype.schedule=function(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)},t.prototype.clear=function(){this.queue=[]},t.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},t.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}},t}(),Ut=new Map,Jt=0,Bt=function(){return"x:"+Jt++},qt=function(t,e){return Ut.set(t,e),t},$t=function(t){return Ut.get(t)},Xt=function(t){Ut.delete(t)};function Ht(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Gt(t){if(Ht()){var e=function(){var t=Ht();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}}var Kt,Qt={sync:!1,autoForward:!1};(Kt=t.InterpreterStatus||(t.InterpreterStatus={}))[Kt.NotStarted=0]="NotStarted",Kt[Kt.Running=1]="Running",Kt[Kt.Stopped=2]="Stopped";var Wt=function(){function n(r,i){var o=this;void 0===i&&(i=n.defaultOptions),this.machine=r,this.scheduler=new Ft,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=t.InterpreterStatus.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=function(e,n){if(E(e))return o.batch(e),o.state;var r=D(L(e,n));if(o.status===t.InterpreterStatus.Stopped)return o.state;if(o.status!==t.InterpreterStatus.Running&&!o.options.deferEvents)throw new Error('Event "'+r.name+'" was sent to uninitialized service "'+o.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: '+JSON.stringify(r.data));return o.scheduler.schedule((function(){o.forward(r);var t=o.nextState(r);o.update(t,r)})),o._state},this.sendTo=function(n,r){var i,a=o.parent&&(r===t.SpecialTargets.Parent||o.parent.id===r),s=a?o.parent:N(r)?o.children.get(r)||$t(r):(i=r)&&"function"==typeof i.send?r:void 0;if(s)"machine"in s?s.send(e(e({},n),{name:n.name===ot?""+Nt(o.id):n.name,origin:o.sessionId})):s.send(n.data);else if(!a)throw new Error("Unable to send event to child '"+r+"' from service '"+o.id+"'.")};var a=e(e({},n.defaultOptions),i),s=a.clock,c=a.logger,u=a.parent,h=a.id,f=void 0!==h?h:r.id;this.id=f,this.logger=c,this.clock=s,this.parent=u,this.options=a,this.scheduler=new Ft({deferEvents:this.options.deferEvents}),this.sessionId=Bt()}return Object.defineProperty(n.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:It(this,(function(){return t._initialState=t.machine.initialState,t._initialState}))},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),n.prototype.execute=function(t,e){var n,i;try{for(var o=r(t.actions),a=o.next();!a.done;a=o.next()){var s=a.value;this.exec(s,t,e)}}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=o.return)&&i.call(o)}finally{if(n)throw n.error}}},n.prototype.update=function(t,e){var n,i,o,a,s,c,u,h,f=this;if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach((function(t){f.state.children[t.id]=t})),this.devTools&&this.devTools.send(e.data,t),t.event)try{for(var l=r(this.eventListeners),d=l.next();!d.done;d=l.next()){(0,d.value)(t.event)}}catch(t){n={error:t}}finally{try{d&&!d.done&&(i=l.return)&&i.call(l)}finally{if(n)throw n.error}}try{for(var v=r(this.listeners),p=v.next();!p.done;p=v.next()){(0,p.value)(t,t.event)}}catch(t){o={error:t}}finally{try{p&&!p.done&&(a=v.return)&&a.call(v)}finally{if(o)throw o.error}}try{for(var y=r(this.contextListeners),g=y.next();!g.done;g=y.next()){(0,g.value)(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(t){s={error:t}}finally{try{g&&!g.done&&(c=y.return)&&c.call(y)}finally{if(s)throw s.error}}var m=H(t.configuration||[],this.machine);if(this.state.configuration&&m){var x=t.configuration.find((function(t){return"final"===t.type&&t.parent===f.machine})),w=x&&x.doneData?S(x.doneData,t.context,e):void 0;try{for(var b=r(this.doneListeners),_=b.next();!_.done;_=b.next()){(0,_.value)(Tt(this.id,w))}}catch(t){u={error:t}}finally{try{_&&!_.done&&(h=b.return)&&h.call(b)}finally{if(u)throw u.error}}this.stop()}},n.prototype.onTransition=function(e){return this.listeners.add(e),this.status===t.InterpreterStatus.Running&&e(this.state,this.state.event),this},n.prototype.subscribe=function(e,n,r){var i,o=this;if(!e)return{unsubscribe:function(){}};var a=r;return"function"==typeof e?i=e:(i=e.next.bind(e),a=e.complete.bind(e)),this.listeners.add(i),this.status===t.InterpreterStatus.Running&&i(this.state),a&&this.onDone(a),{unsubscribe:function(){i&&o.listeners.delete(i),a&&o.doneListeners.delete(a)}}},n.prototype.onEvent=function(t){return this.eventListeners.add(t),this},n.prototype.onSend=function(t){return this.sendListeners.add(t),this},n.prototype.onChange=function(t){return this.contextListeners.add(t),this},n.prototype.onStop=function(t){return this.stopListeners.add(t),this},n.prototype.onDone=function(t){return this.doneListeners.add(t),this},n.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},n.prototype.start=function(e){var n=this;if(this.status===t.InterpreterStatus.Running)return this;qt(this.sessionId,this),this.initialized=!0,this.status=t.InterpreterStatus.Running;var r=void 0===e?this.initialState:It(this,(function(){return!N(t=e)&&"value"in t&&"history"in t?n.machine.resolveState(e):n.machine.resolveState(Pt.from(e,n.machine.context));var t}));return this.options.devTools&&this.attachDev(),this.scheduler.initialize((function(){n.update(r,ut)})),this},n.prototype.stop=function(){var e,n,i,o,a,c,u,h,f,l,d=this;try{for(var v=r(this.listeners),p=v.next();!p.done;p=v.next()){var y=p.value;this.listeners.delete(y)}}catch(t){e={error:t}}finally{try{p&&!p.done&&(n=v.return)&&n.call(v)}finally{if(e)throw e.error}}try{for(var g=r(this.stopListeners),m=g.next();!m.done;m=g.next()){(y=m.value)(),this.stopListeners.delete(y)}}catch(t){i={error:t}}finally{try{m&&!m.done&&(o=g.return)&&o.call(g)}finally{if(i)throw i.error}}try{for(var x=r(this.contextListeners),S=x.next();!S.done;S=x.next()){y=S.value;this.contextListeners.delete(y)}}catch(t){a={error:t}}finally{try{S&&!S.done&&(c=x.return)&&c.call(x)}finally{if(a)throw a.error}}try{for(var w=r(this.doneListeners),b=w.next();!b.done;b=w.next()){y=b.value;this.doneListeners.delete(y)}}catch(t){u={error:t}}finally{try{b&&!b.done&&(h=w.return)&&h.call(w)}finally{if(u)throw u.error}}if(!this.initialized)return this;this.state.configuration.forEach((function(t){var e,n;try{for(var i=r(t.definition.exit),o=i.next();!o.done;o=i.next()){var a=o.value;d.exec(a,d.state)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}})),this.children.forEach((function(t){T(t.stop)&&t.stop()}));try{for(var _=r(s(this.delayedEventsMap)),E=_.next();!E.done;E=_.next()){var N=E.value;this.clock.clearTimeout(this.delayedEventsMap[N])}}catch(t){f={error:t}}finally{try{E&&!E.done&&(l=_.return)&&l.call(_)}finally{if(f)throw f.error}}return this.scheduler.clear(),this.initialized=!1,this.status=t.InterpreterStatus.Stopped,Xt(this.sessionId),this},n.prototype.batch=function(n){var i=this;if(this.status===t.InterpreterStatus.NotStarted&&this.options.deferEvents);else if(this.status!==t.InterpreterStatus.Running)throw new Error(n.length+' event(s) were sent to uninitialized service "'+this.machine.id+'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.');this.scheduler.schedule((function(){var t,a,s=i.state,c=!1,u=[],h=function(t){var n=D(t);i.forward(n),s=It(i,(function(){return i.machine.transition(s,n)})),u.push.apply(u,o(s.actions.map((function(t){return r=s,i=(n=t).exec,e(e({},n),{exec:void 0!==i?function(){return i(r.context,r.event,{action:n,state:r,_event:r._event})}:void 0});var n,r,i})))),c=c||!!s.changed};try{for(var f=r(n),l=f.next();!l.done;l=f.next()){h(l.value)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(a=f.return)&&a.call(f)}finally{if(t)throw t.error}}s.changed=c,s.actions=u,i.update(s,D(n[n.length-1]))}))},n.prototype.sender=function(t){return this.send.bind(this,t)},n.prototype.nextState=function(t){var e=this,n=D(t);if(0===n.name.indexOf(it)&&!this.state.nextEvents.some((function(t){return 0===t.indexOf(it)})))throw n.data.data;return It(this,(function(){return e.machine.transition(e.state,n)}))},n.prototype.forward=function(t){var e,n;try{for(var i=r(this.forwardTo),o=i.next();!o.done;o=i.next()){var a=o.value,s=this.children.get(a);if(!s)throw new Error("Unable to forward event '"+t+"' from interpreter '"+this.id+"' to nonexistant child '"+a+"'.");s.send(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}},n.prototype.defer=function(t){var e=this;this.delayedEventsMap[t.id]=this.clock.setTimeout((function(){t.to?e.sendTo(t._event,t.to):e.send(t._event)}),t.delay)},n.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},n.prototype.exec=function(e,n,r){void 0===r&&(r=this.machine.options.actions);var i=n.context,o=n._event,a=e.exec||ht(e.type,r),s=T(a)?a:a?a.exec:e.exec;if(s)try{return s(i,o.data,{action:e,state:this.state,_event:o})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case W:var c=e;if("number"==typeof c.delay)return void this.defer(c);c.to?this.sendTo(c._event,c.to):this.send(c._event);break;case Y:this.cancel(e.sendId);break;case G:var u=e.activity;if(!this.state.activities[u.id||u.type])break;if(u.type===t.ActionTypes.Invoke){var h=z(u.src),f=this.machine.options.services?this.machine.options.services[h.type]:void 0,l=u.id,d=u.data,v="autoForward"in u?u.autoForward:!!u.forward;if(!f)return;var p=d?S(d,i,o):void 0,y=T(f)?f(i,o.data,{data:p,src:h}):f;w(y)?this.spawnPromise(Promise.resolve(y),l):T(y)?this.spawnCallback(y,l):A(y)?this.spawnObservable(y,l):k(y)&&this.spawnMachine(p?y.withContext(p):y,{id:l,autoForward:v})}else this.spawnActivity(u);break;case K:this.stopChild(e.activity.id);break;case et:var g=e.label,m=e.value;g?this.logger(g,m):this.logger(m)}},n.prototype.removeChild=function(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]},n.prototype.stopChild=function(t){var e=this.children.get(t);e&&(this.removeChild(t),T(e.stop)&&e.stop())},n.prototype.spawn=function(t,n,r){if(w(t))return this.spawnPromise(Promise.resolve(t),n);if(T(t))return this.spawnCallback(t,n);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(i=t)&&"id"in i)return this.spawnActor(t);if(A(t))return this.spawnObservable(t,n);if(k(t))return this.spawnMachine(t,e(e({},r),{id:n}));throw new Error('Unable to spawn entity "'+n+'" of type "'+typeof t+'".');var i},n.prototype.spawnMachine=function(t,r){var i=this;void 0===r&&(r={});var o=new n(t,e(e({},this.options),{parent:this,id:r.id||t.id})),a=e(e({},Qt),r);a.sync&&o.onTransition((function(t){i.send(at,{state:t,id:o.id})}));var s=o;return this.children.set(o.id,s),a.autoForward&&this.forwardTo.add(o.id),o.onDone((function(t){i.removeChild(o.id),i.send(D(t,{origin:o.id}))})).start(),s},n.prototype.spawnPromise=function(t,e){var n=this,r=!1;t.then((function(t){r||(n.removeChild(e),n.send(D(Tt(e,t),{origin:e})))}),(function(t){if(!r){n.removeChild(e);var i=Nt(e,t);try{n.send(D(i,{origin:e}))}catch(t){n.devTools&&n.devTools.send(i,n.state),n.machine.strict&&n.stop()}}}));var i={id:e,send:function(){},subscribe:function(e,n,r){var i=function(t,e,n){if("object"==typeof t)return t;var r=function(){};return{next:t,error:e||r,complete:n||r}}(e,n,r),o=!1;return t.then((function(t){o||(i.next(t),o||i.complete())}),(function(t){o||i.error(t)})),{unsubscribe:function(){return o=!0}}},stop:function(){r=!0},toJSON:function(){return{id:e}}};return this.children.set(e,i),i},n.prototype.spawnCallback=function(t,e){var n,r=this,i=!1,o=new Set,a=new Set;try{n=t((function(t){a.forEach((function(e){return e(t)})),i||r.send(D(t,{origin:e}))}),(function(t){o.add(t)}))}catch(t){this.send(Nt(e,t))}if(w(n))return this.spawnPromise(n,e);var s={id:e,send:function(t){return o.forEach((function(e){return e(t)}))},subscribe:function(t){return a.add(t),{unsubscribe:function(){a.delete(t)}}},stop:function(){i=!0,T(n)&&n()},toJSON:function(){return{id:e}}};return this.children.set(e,s),s},n.prototype.spawnObservable=function(t,e){var n=this,r=t.subscribe((function(t){n.send(D(t,{origin:e}))}),(function(t){n.removeChild(e),n.send(D(Nt(e,t),{origin:e}))}),(function(){n.removeChild(e),n.send(D(Tt(e),{origin:e}))})),i={id:e,send:function(){},subscribe:function(e,n,r){return t.subscribe(e,n,r)},stop:function(){return r.unsubscribe()},toJSON:function(){return{id:e}}};return this.children.set(e,i),i},n.prototype.spawnActor=function(t){return this.children.set(t.id,t),t},n.prototype.spawnActivity=function(t){var e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(e){var n=e(this.state.context,t);this.spawnEffect(t.id,n)}},n.prototype.spawnEffect=function(t,e){this.children.set(t,{id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:e||void 0,toJSON:function(){return{id:t}}})},n.prototype.attachDev=function(){var t=Ht();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var n="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(e(e({name:this.id,autoPause:!0,stateSanitizer:function(t){return{value:t.value,context:t.context,actions:t.actions}}},n),{features:e({jump:!1,skip:!1},n?n.features:void 0)}),this.machine),this.devTools.init(this.state)}Gt(this)}},n.prototype.toJSON=function(){return{id:this.id}},n.prototype[P]=function(){return this},n.defaultOptions=function(t){return{execute:!0,deferEvents:!0,clock:{setTimeout:function(t,e){return setTimeout(t,e)},clearTimeout:function(t){return clearTimeout(t)}},logger:t.console.log.bind(console),devTools:!1}}("undefined"!=typeof self?self:global),n.interpret=Yt,n}();function Yt(t,e){return new Wt(t,e)}var Zt={raise:vt,send:pt,sendParent:yt,sendUpdate:gt,log:function(t,e){return void 0===t&&(t=mt),{type:et,label:e,expr:t}},cancel:xt,start:St,stop:wt,assign:bt,after:_t,done:Et,respond:function(t,n){return pt(t,e(e({},n),{to:function(t,e,n){return n._event.origin}}))},forwardTo:Ot,escalate:function(n,r){return yt((function(t,e,r){return{type:ot,data:T(n)?n(t,e,r):n}}),e(e({},r),{to:t.SpecialTargets.Parent}))},choose:function(e){return{type:t.ActionTypes.Choose,conds:e}},pure:function(e){return{type:t.ActionTypes.Pure,get:e}}};t.Interpreter=Wt,t.Machine=function(t,e,n){void 0===n&&(n=t.context);var r="function"==typeof n?n():n;return new Rt(t,e,r)},t.State=Pt,t.StateNode=Rt,t.actions=Zt,t.assign=bt,t.createMachine=function(t,e){var n="function"==typeof t.context?t.context():t.context;return new Rt(t,e,n)},t.createSchema=function(t){return t},t.doneInvoke=Tt,t.forwardTo=Ot,t.interpret=Yt,t.mapState=function(t,e){var n,i,o;try{for(var a=r(s(t)),u=a.next();!u.done;u=a.next()){var h=u.value;c(h,e)&&(!o||e.length>o.length)&&(o=h)}}catch(t){n={error:t}}finally{try{u&&!u.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}return t[o]},t.matchState=function(t,e,n){var o,a,s=Pt.from(t,t instanceof Pt?t.context:void 0);try{for(var c=r(e),u=c.next();!u.done;u=c.next()){var h=i(u.value,2),f=h[0],l=h[1];if(s.matches(f))return l(s)}}catch(t){o={error:t}}finally{try{u&&!u.done&&(a=c.return)&&a.call(c)}finally{if(o)throw o.error}}return n(s)},t.matchesState=c,t.send=pt,t.sendParent=yt,t.sendUpdate=gt,t.spawn=function(t,n){var r=function(t){return N(t)?e(e({},Qt),{name:t}):e(e(e({},Qt),{name:V()}),t)}(n);return function(e){return e?e.spawn(t,r.name,r):Ct(t,r.name)}(kt[kt.length-1])},Object.defineProperty(t,"__esModule",{value:!0})}));
@@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
12
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
14
  PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */function C(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(i[s[n]]=t[s[n]])}return i}var V,I;!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(V||(V={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(I||(I={}));const L=t=>"atomic"===t.type||"final"===t.type;function D(t){return e(t.states).map(e=>t.states[e])}function A(t){const e=[t];return L(t)?e:e.concat(u(D(t).map(A)))}function R(t,e){const i=M(new Set(t)),s=new Set(e);for(const t of s){let e=t.parent;for(;e&&!s.has(e);)s.add(e),e=e.parent}const n=M(s);for(const t of s)if("compound"!==t.type||n.get(t)&&n.get(t).length){if("parallel"===t.type)for(const e of D(t))"history"!==e.type&&(s.has(e)||(s.add(e),i.get(e)?i.get(e).forEach(t=>s.add(t)):e.initialStateNodes.forEach(t=>s.add(t))))}else i.get(t)?i.get(t).forEach(t=>s.add(t)):t.initialStateNodes.forEach(t=>s.add(t));for(const t of s){let e=t.parent;for(;e&&!s.has(e);)s.add(e),e=e.parent}return s}function M(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function z(t,e){return function t(e,i){const s=i.get(e);if(!s)return{};if("compound"===e.type){const t=s[0];if(!t)return{};if(L(t))return t.key}const n={};return s.forEach(e=>{n[e.key]=t(e,i)}),n}(t,M(R([t],e)))}function F(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function J(t,e){return"compound"===e.type?D(e).some(e=>"final"===e.type&&F(t,e)):"parallel"===e.type&&D(e).every(e=>J(t,e))}const U=V.Start,B=V.Stop,q=V.Raise,X=V.Send,H=V.Cancel,G=V.NullEvent,K=V.Assign,Q=(V.After,V.DoneState,V.Log),W=V.Init,Y=V.Invoke,Z=(V.ErrorExecution,V.ErrorPlatform),tt=V.ErrorCustom,et=V.Update,it=V.Choose,st=V.Pure,nt=N({type:W});function ot(t,e){return e&&e[t]||void 0}function rt(t,e){let i;if(S(t)||"number"==typeof t){const s=ot(t,e);i=b(s)?{type:t,exec:s}:s||{type:t,exec:void 0}}else if(b(t))i={type:t.name||t.toString(),exec:t};else{const s=ot(t.type,e);if(b(s))i=Object.assign(Object.assign({},t),{exec:s});else if(s){const e=s.type||t.type;i=Object.assign(Object.assign(Object.assign({},s),t),{type:e})}else i=t}return Object.defineProperty(i,"toString",{value:()=>i.type,enumerable:!1,configurable:!0}),i}const at=(t,e)=>{if(!t)return[];return(m(t)?t:[t]).map(t=>rt(t,e))};function ct(t){const e=rt(t);return Object.assign(Object.assign({id:S(t)?t:e.id},e),{type:e.type})}function ht(t){return S(t)?{type:q,event:t}:dt(t,{to:I.Internal})}function dt(t,e){return{to:e?e.to:void 0,type:X,event:b(t)?t:E(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:b(t)?t.name:s(t)}}function ut(t,e){return dt(t,Object.assign(Object.assign({},e),{to:I.Parent}))}function lt(){return ut(et)}const ft=(t,e)=>({context:t,event:e});const pt=t=>({type:H,sendId:t});function gt(t){const e=ct(t);return{type:V.Start,activity:e,exec:void 0}}function vt(t){const e=b(t)?t:ct(t);return{type:V.Stop,activity:e,exec:void 0}}const yt=t=>({type:K,assignment:t});function mt(t,e){const i=e?"#"+e:"";return`${V.After}(${t})${i}`}function bt(t,e){const i=`${V.DoneState}.${t}`,s={type:i,data:e,toString:()=>i};return s}function St(t,e){const i=`${V.DoneInvoke}.${t}`,s={type:i,data:e,toString:()=>i};return s}function wt(t,e){const i=`${V.ErrorPlatform}.${t}`,s={type:i,data:e,toString:()=>i};return s}function xt(t,e){return dt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function Ot(t,i,s,n,o){const[r,a]=v(o,t=>t.type===K);let c=r.length?function(t,i,s,n){return t?s.reduce((t,s)=>{const{assignment:o}=s,r={state:n,action:s,_event:i};let a={};if(b(o))a=o(t,i.data,r);else for(const s of e(o)){const e=o[s];a[s]=b(e)?e(t,i.data,r):e}return Object.assign({},t,a)},t):t}(s,n,r,i):s;return[u(a.map(e=>{var s;switch(e.type){case q:return{type:q,_event:N(e.event)};case X:return function(t,e,i,s){const n={_event:i},o=N(b(t.event)?t.event(e,i.data,n):t.event);let r;if(S(t.delay)){const o=s&&s[t.delay];r=b(o)?o(e,i.data,n):o}else r=b(t.delay)?t.delay(e,i.data,n):t.delay;const a=b(t.to)?t.to(e,i.data,n):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}(e,c,n,t.options.delays);case Q:return((t,e,i)=>Object.assign(Object.assign({},t),{value:S(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}))(e,c,n);case it:{const o=null===(s=e.conds.find(e=>{const s=w(e.cond,t.options.guards);return!s||$(t,s,c,n,i)}))||void 0===s?void 0:s.actions;if(!o)return[];const r=Ot(t,i,c,n,at(f(o),t.options.actions));return c=r[1],r[0]}case st:{const s=e.get(c,n.data);if(!s)return[];const o=Ot(t,i,c,n,at(f(s),t.options.actions));return c=o[1],o[0]}case B:return function(t,e,i){const s=b(t.activity)?t.activity(e,i.data):t.activity,n="string"==typeof s?{id:s}:s;return{type:V.Stop,activity:n}}(e,c,n);default:return rt(e,t.options.actions)}})),c]}function _t(t,e){const{exec:i}=t;return Object.assign(Object.assign({},t),{exec:void 0!==i?()=>i(e.context,e.event,{action:t,state:e,_event:e._event}):void 0})}class jt{constructor(e){var i;this.actions=[],this.activities=t,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||t,this.meta=e.meta||{},this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,this.tags=null!==(i=e.tags)&&void 0!==i?i:new Set,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,u([...new Set(t.map(t=>t.ownEvents))]);var t}})}static from(t,e){if(t instanceof jt)return t.context!==e?new jt({value:t.value,context:e,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;return new jt({value:t,context:e,_event:nt,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new jt(t)}static inert(t,e){if(t instanceof jt){if(!t.actions.length)return t;const i=nt;return new jt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return jt.from(t,e)}toStrings(t=this.value,i="."){if(S(t))return[t];const s=e(t);return s.concat(...s.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){const{configuration:t,transitions:e,tags:i}=this,s=C(this,["configuration","transitions","tags"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return i(t,this.value)}hasTag(t){return this.tags.has(t)}}const Et=[],Nt=(t,e)=>{Et.push(t);const i=e(t);return Et.pop(),i};function Tt(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),toJSON:()=>({id:t})}}function $t(t,e,i){const s=Tt(e);return s.deferred=!0,_(t)&&(s.state=Nt(void 0,()=>(i?t.withContext(i):t).initialState)),s}function kt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Pt(t){return Object.assign(Object.assign({type:Y},t),{toJSON(){const e=C(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:Y,src:kt(t.src)})}})}const Ct={},Vt=t=>"#"===t[0];class It{constructor(t,i,s){var n;this.config=t,this.context=s,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},i),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&e(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(n=this.config.schema)&&void 0!==n?n:{},this.initial=this.config.initial,this.states=this.config.states?a(this.config.states,(t,e)=>{const i=new It(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Ct;let o=0;!function t(e){e.order=o++;for(const i of D(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=f(this.config.entry||this.config.onEntry).map(t=>rt(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>rt(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=f(this.config.invoke).map((t,e)=>{if(_(t))return this.machine.options.services=Object.assign({[t.id]:t},this.machine.options.services),Pt({src:t.id,id:t.id});if(S(t.src))return Pt(Object.assign(Object.assign({},t),{id:t.id||t.src,src:t.src}));if(_(t.src)||b(t.src)){const i=`${this.id}:invocation[${e}]`;return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Pt(Object.assign(Object.assign({id:i},t),{src:i}))}{const e=t.src;return Pt(Object.assign(Object.assign({id:e.type},t),{src:e}))}}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>ct(t)),this.transition=this.transition.bind(this),this.tags=f(this.config.tags)}_init(){this.__cache.transitions||A(this).forEach(t=>t.on)}withConfig(t,e=this.context){const{actions:i,activities:s,guards:n,services:o,delays:r}=this.options;return new It(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},s),t.activities),guards:Object.assign(Object.assign({},n),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},e)}withContext(t){return new It(this.config,this.options,t)}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:a(this.states,t=>t.definition),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=""===t,i=this.transitions.filter(i=>{const s=i.eventType===t;return e?s:s||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const i=(t,e)=>{const i=mt(b(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(dt(i,{delay:t})),this.onExit.push(pt(i)),i};return(m(t)?t.map((t,e)=>{const s=i(t.delay,e);return Object.assign(Object.assign({},t),{event:s})}):u(e(t).map((e,s)=>{const n=t[e],o=S(n)?{target:n}:n,r=isNaN(+e)?e:+e,a=i(r,s);return f(o).map(t=>Object.assign(Object.assign({},t),{event:a,delay:r}))}))).map(t=>{const{delay:e}=t;return Object.assign(Object.assign({},this.formatTransition(t)),{delay:e})})}getStateNodes(t){if(!t)return[];const i=t instanceof jt?t.value:o(t,this.delimiter);if(S(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this.states[i]]}const s=e(i);return s.map(t=>this.getStateNode(t)).concat(s.reduce((t,e)=>{const s=this.getStateNode(e).getStateNodes(i[e]);return t.concat(s)},[]))}handles(t){const e=s(t);return this.events.includes(e)}resolveState(t){const e=Array.from(R([],this.getStateNodes(t.value)));return new jt(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e,done:J(e,this)}))}transitionLeafNode(t,e,i){const s=this.getStateNode(t).next(e,i);return s&&s.transitions.length?s:this.next(e,i)}transitionCompoundNode(t,i,s){const n=e(t),o=this.getStateNode(n[0])._transition(t[n[0]],i,s);return o&&o.transitions.length?o:this.next(i,s)}transitionParallelNode(t,i,s){const n={};for(const o of e(t)){const e=t[o];if(!e)continue;const r=this.getStateNode(o)._transition(e,i,s);r&&(n[o]=r)}const o=e(n).map(t=>n[t]),r=u(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,s);const a=u(o.map(t=>t.entrySet)),c=u(e(n).map(t=>n[t].configuration));return{transitions:r,entrySet:a,exitSet:u(o.map(t=>t.exitSet)),configuration:c,source:i,actions:u(e(n).map(t=>n[t].actions))}}_transition(t,i,s){return S(t)?this.transitionLeafNode(t,i,s):1===e(t).length?this.transitionCompoundNode(t,i,s):this.transitionParallelNode(t,i,s)}next(t,e){const s=e.name,n=[];let r,a=[];for(const c of this.getCandidates(s)){const{cond:d,in:u}=c,l=t.context,f=!u||(S(u)&&Vt(u)?t.matches(o(this.getStateNodeById(u).path,this.delimiter)):i(o(u,this.delimiter),h(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!d||$(this.machine,d,l,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${d.name||d.type}' in transition for event '${s}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==c.target&&(a=c.target),n.push(...c.actions),r=c;break}}if(!r)return;if(!a.length)return{transitions:[r],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:n};const c=u(a.map(e=>this.getRelativeStateNodes(e,t.historyValue))),d=!!r.internal;return{transitions:[r],entrySet:d?[]:u(c.map(t=>this.nodesFromChild(t))),exitSet:d?[]:[this],configuration:c,source:t,actions:n}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,s){const n=R([],s?this.getStateNodes(s.value):[this]),o=t.configuration.length?R(n,t.configuration):n;for(const e of o)F(n,e)||t.entrySet.push(e);for(const e of n)F(o,e)&&!F(t.exitSet,e.parent)||t.exitSet.push(e);t.source||(t.exitSet=[],t.entrySet.push(this));const r=u(t.entrySet.map(s=>{const n=[];if("final"!==s.type)return n;const o=s.parent;if(!o.parent)return n;n.push(bt(s.id,s.doneData),bt(o.id,s.doneData?p(s.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&D(r).every(e=>J(t.configuration,e))&&n.push(bt(r.id)),n}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,d]=[u(Array.from(a).map(t=>[...t.activities.map(t=>gt(t)),...t.onEntry])).concat(r.map(ht)),u(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>vt(t))]))];return at(d.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const s=N(e);let n;if(t instanceof jt)n=void 0===i?t:this.resolveState(jt.from(t,i));else{const e=S(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),s=i||this.machine.context;n=this.resolveState(jt.from(e,s))}if(this.strict&&!this.events.includes(s.name)&&(o=s.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${s.name}'`);var o;const a=this._transition(n.value,n,s)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:n,actions:[]},c=R([],this.getStateNodes(n.value)),h=a.configuration.length?R(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,n,s)}resolveRaisedTransition(t,e,i){const s=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...s),t}resolveTransition(t,i,s=nt,n=this.machine.context){const{configuration:o}=t,r=!i||t.transitions.length>0?z(this.machine,o):void 0,a=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,c=i?i.context:n,h=this.getActions(t,c,s,i),d=i?Object.assign({},i.activities):{};for(const t of h)t.type===U?d[t.activity.id||t.activity.type]=t:t.type===B&&(d[t.activity.id||t.activity.type]=!1);const[l,f]=Ot(this,i,c,s,h),[g,m]=v(l,t=>t.type===q||t.type===X&&t.to===I.Internal),b=l.filter(t=>{var e;return t.type===U&&(null===(e=t.activity)||void 0===e?void 0:e.type)===Y}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,s){var n;const o=k(t.src),r=null===(n=null==e?void 0:e.options.services)||void 0===n?void 0:n[o.type],a=t.data?p(t.data,i,s):void 0,c=r?$t(r,t.id,a):Tt(t.id);return c.meta=t,c}(e.activity,this.machine,f,s),t),i?Object.assign({},i.children):{}),w=r?t.configuration:i?i.configuration:[],x=w.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{}),O=J(w,this),_=new jt({value:r||i.value,context:f,_event:s,_sessionid:i?i._sessionid:null,historyValue:r?a?(j=a,E=r,{current:E,states:y(j,E)}):void 0:i?i.historyValue:void 0,history:!r||t.source?i:void 0,actions:r?m:[],activities:r?d:i?i.activities:{},meta:r?x:i?i.meta:void 0,events:[],configuration:w,transitions:t.transitions,children:b,done:O});var j,E;const N=c!==f;_.changed=s.name===et||N;const{history:T}=_;if(T&&delete T.history,!r)return _;let $=_;if(!O){for((this._transient||o.some(t=>t._transient))&&($=this.resolveRaisedTransition($,{type:G},s));g.length;){const t=g.shift();$=this.resolveRaisedTransition($,t._event,s)}}const P=$.changed||(T?!!$.actions.length||N||typeof T.value!=typeof $.value||!function t(i,s){if(i===s)return!0;if(void 0===i||void 0===s)return!1;if(S(i)||S(s))return i===s;const n=e(i),o=e(s);return n.length===o.length&&n.every(e=>t(i[e],s[e]))}($.value,T.value):void 0);return $.changed=P,$.history=T,$.tags=new Set(u($.configuration.map(t=>t.tags))),$}getStateNode(t){if(Vt(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error(`Unable to retrieve child state '${t}' from '${this.id}'; no child states exist.`);const e=this.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${this.id}'`);return e}getStateNodeById(t){const e=Vt(t)?t.slice("#".length):t;if(e===this.id)return this;const i=this.machine.idMap[e];if(!i)throw new Error(`Child state node '#${e}' does not exist on machine '${this.id}'`);return i}getStateNodeByPath(t){if("string"==typeof t&&Vt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=n(t,this.delimiter).slice();let i=this;for(;e.length;){const t=e.shift();if(!t.length)break;i=i.getStateNode(t)}return i}resolve(t){if(!t)return this.initialStateValue||Ct;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Ct);case"compound":if(S(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return e(t).length?a(t,(t,e)=>t?this.getStateNode(e).resolve(t):Ct):this.initialStateValue||{};default:return t||Ct}}getResolvedPath(t){if(Vt(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return n(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=c(this.states,t=>t.initialStateValue||Ct,t=>!("history"===t.type));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error(`Initial state '${this.initial}' not found on '${this.key}'`);t=L(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}else t={};return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)}get initialState(){this._init();const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=S(e.target)&&Vt(e.target)?r(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t}getRelativeStateNodes(t,e,i=!0){return i?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]}get initialStateNodes(){if(L(this))return[this];if("compound"===this.type&&!this.initial)return[this];return u(d(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const s=this.getStateNode(e);if("history"===s.type)return s.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(e(this.states).length)return{current:t||this.initialStateValue,states:c(this.states,(e,i)=>{if(!t)return e.historyValue();const s=S(t)?void 0:t[i];return e.historyValue(s||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?u(d(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(s=e.path,n="states",t=>{let e=t;for(const t of s)e=e[n][t];return e})(t).current;var s,n;return S(i)?[e.getStateNode(i)]:u(d(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=u(e(this.states).map(t=>this.states[t].stateIds));return[this.id].concat(t)}get events(){if(this.__cache.events)return this.__cache.events;const{states:t}=this,i=new Set(this.ownEvents);if(t)for(const s of e(t)){const e=t[s];if(e.states)for(const t of e.events)i.add(""+t)}return this.__cache.events=Array.from(i)}get ownEvents(){const t=new Set(this.transitions.filter(t=>!(!t.target&&!t.actions.length&&t.internal)).map(t=>t.eventType));return Array.from(t)}resolveTarget(t){if(void 0!==t)return t.map(t=>{if(!S(t))return t;const e=t[0]===this.delimiter;if(e&&!this.parent)return this.getStateNodeByPath(t.slice(1));const i=e?this.key+t:t;if(!this.parent)return this.getStateNodeByPath(i);try{return this.parent.getStateNodeByPath(i)}catch(t){throw new Error(`Invalid transition definition for state node '${this.id}':\n${t.message}`)}})}formatTransition(t){const e=function(t){if(void 0!==t&&""!==t)return f(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>S(t)&&t[0]===this.delimiter),{guards:s}=this.machine.options,n=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:at(f(t.actions)),cond:w(t.cond,s),target:n,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>"#"+t.id):void 0,source:"#"+this.id})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const i=this.config.on,s="*",n=i[s],o=void 0===n?[]:n,r=C(i,[s+""]);t=u(e(r).map(t=>T(t,r[t])).concat(T("*",o)))}else t=[];const i=this.config.always?T("",this.config.always):[],s=this.config.onDone?T(String(bt(this.id)),this.config.onDone):[],n=u(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...T(String(St(t.id)),t.onDone)),t.onError&&e.push(...T(String(wt(t.id)),t.onError)),e})),o=this.after,r=u([...s,...n,...t,...i].map(t=>f(t).map(t=>this.formatTransition(t))));for(const t of o)r.push(t);return r}}function Lt(t,e,i=t.context){const s="function"==typeof i?i():i;return new It(t,e,s)}function Dt(t,e){const i="function"==typeof t.context?t.context():t.context;return new It(t,e,i)}const At={deferEvents:!1};class Rt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},At),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const Mt=new Map;let zt=0;const Ft={bookId:()=>"x:"+zt++,register:(t,e)=>(Mt.set(t,e),t),get:t=>Mt.get(t),free(t){Mt.delete(t)}};function Jt(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Ut(t){if(!Jt())return;const e=function(){const t=Jt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}const Bt={sync:!1,autoForward:!1};var qt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(qt||(qt={}));class Xt{constructor(t,e=Xt.defaultOptions){this.machine=t,this.scheduler=new Rt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=qt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(m(t))return this.batch(t),this.state;const i=N(E(t,e));if(this.status===qt.Stopped)return this.state;if(this.status!==qt.Running&&!this.options.deferEvents)throw new Error(`Event "${i.name}" was sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ${JSON.stringify(i.data)}`);return this.scheduler.schedule(()=>{this.forward(i);const t=this.nextState(i);this.update(t,i)}),this._state},this.sendTo=(t,e)=>{const i=this.parent&&(e===I.Parent||this.parent.id===e),s=i?this.parent:S(e)?this.children.get(e)||Ft.get(e):(n=e)&&"function"==typeof n.send?e:void 0;var n;if(s)"machine"in s?s.send(Object.assign(Object.assign({},t),{name:t.name===tt?""+wt(this.id):t.name,origin:this.sessionId})):s.send(t.data);else if(!i)throw new Error(`Unable to send event to child '${e}' from service '${this.id}'.`)};const i=Object.assign(Object.assign({},Xt.defaultOptions),e),{clock:s,logger:n,parent:o,id:r}=i,a=void 0!==r?r:t.id;this.id=a,this.logger=n,this.clock=s,this.parent=o,this.options=i,this.scheduler=new Rt({deferEvents:this.options.deferEvents}),this.sessionId=Ft.bookId()}get initialState(){return this._initialState?this._initialState:Nt(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach(t=>{this.state.children[t.id]=t}),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);const i=J(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),s=i&&i.doneData?p(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(St(this.id,s));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===qt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>{}};let s,n=i;return"function"==typeof t?s=t:(s=t.next.bind(t),n=t.complete.bind(t)),this.listeners.add(s),this.status===qt.Running&&s(this.state),n&&this.onDone(n),{unsubscribe:()=>{s&&this.listeners.delete(s),n&&this.doneListeners.delete(n)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this.status===qt.Running)return this;Ft.register(this.sessionId,this),this.initialized=!0,this.status=qt.Running;const e=void 0===t?this.initialState:Nt(this,()=>{return!S(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState(jt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,nt)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);if(!this.initialized)return this;this.state.configuration.forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{b(t.stop)&&t.stop()});for(const t of e(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this.status=qt.Stopped,Ft.free(this.sessionId),this}batch(t){if(this.status===qt.NotStarted&&this.options.deferEvents);else if(this.status!==qt.Running)throw new Error(`${t.length} event(s) were sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.`);this.scheduler.schedule(()=>{let e=this.state,i=!1;const s=[];for(const n of t){const t=N(n);this.forward(t),e=Nt(this,()=>this.machine.transition(e,t)),s.push(...e.actions.map(t=>_t(t,e))),i=i||!!e.changed}e.changed=i,e.actions=s,this.update(e,N(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=N(t);if(0===e.name.indexOf(Z)&&!this.state.nextEvents.some(t=>0===t.indexOf(Z)))throw e.data.data;return Nt(this,()=>this.machine.transition(this.state,e))}forward(t){for(const e of this.forwardTo){const i=this.children.get(e);if(!i)throw new Error(`Unable to forward event '${t}' from interpreter '${this.id}' to nonexistant child '${e}'.`);i.send(t)}}defer(t){this.delayedEventsMap[t.id]=this.clock.setTimeout(()=>{t.to?this.sendTo(t._event,t.to):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i=this.machine.options.actions){const{context:s,_event:n}=e,o=t.exec||ot(t.type,i),r=b(o)?o:o?o.exec:t.exec;if(r)try{return r(s,n.data,{action:t,state:this.state,_event:n})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case X:const e=t;if("number"==typeof e.delay)return void this.defer(e);e.to?this.sendTo(e._event,e.to):this.send(e._event);break;case H:this.cancel(t.sendId);break;case U:{const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===V.Invoke){const t=k(e.src),i=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:o,data:r}=e,a="autoForward"in e?e.autoForward:!!e.forward;if(!i)return;const c=r?p(r,s,n):void 0,h=b(i)?i(s,n.data,{data:c,src:t}):i;g(h)?this.spawnPromise(Promise.resolve(h),o):b(h)?this.spawnCallback(h,o):x(h)?this.spawnObservable(h,o):_(h)&&this.spawnMachine(c?h.withContext(c):h,{id:o,autoForward:a})}else this.spawnActivity(e);break}case B:this.stopChild(t.activity.id);break;case Q:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}removeChild(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),b(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(b(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=t)&&"id"in s)return this.spawnActor(t);if(x(t))return this.spawnObservable(t,e);if(_(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var s}spawnMachine(t,e={}){const i=new Xt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),s=Object.assign(Object.assign({},Bt),e);s.sync&&i.onTransition(t=>{this.send(et,{state:t,id:i.id})});const n=i;return this.children.set(i.id,n),s.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(N(t,{origin:i.id}))}).start(),n}spawnPromise(t,e){let i=!1;t.then(t=>{i||(this.removeChild(e),this.send(N(St(e,t),{origin:e})))},t=>{if(!i){this.removeChild(e);const i=wt(e,t);try{this.send(N(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>{},subscribe:(e,i,s)=>{const n=function(t,e,i){if("object"==typeof t)return t;const s=()=>{};return{next:t,error:e||s,complete:i||s}}(e,i,s);let o=!1;return t.then(t=>{o||(n.next(t),o||n.complete())},t=>{o||n.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{i=!0},toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const s=new Set,n=new Set,o=t=>{n.forEach(e=>e(t)),i||this.send(N(t,{origin:e}))};let r;try{r=t(o,t=>{s.add(t)})}catch(t){this.send(wt(e,t))}if(g(r))return this.spawnPromise(r,e);const a={id:e,send:t=>s.forEach(e=>e(t)),subscribe:t=>(n.add(t),{unsubscribe:()=>{n.delete(t)}}),stop:()=>{i=!0,b(r)&&r()},toJSON:()=>({id:e})};return this.children.set(e,a),a}spawnObservable(t,e){const i=t.subscribe(t=>{this.send(N(t,{origin:e}))},t=>{this.removeChild(e),this.send(N(wt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(N(St(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,s)=>t.subscribe(e,i,s),stop:()=>i.unsubscribe(),toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnActor(t){return this.children.set(t.id,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,toJSON:()=>({id:t})})}attachDev(){const t=Jt();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){const e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},e),{features:Object.assign({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}Ut(this)}}toJSON(){return{id:this.id}}[O](){return this}}Xt.defaultOptions=(t=>({execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:t.console.log.bind(console),devTools:!1}))("undefined"!=typeof self?self:global),Xt.interpret=Gt;function Ht(t,e){const i=(t=>S(t)?Object.assign(Object.assign({},Bt),{name:t}):Object.assign(Object.assign(Object.assign({},Bt),{name:j()}),t))(e);return(e=>e?e.spawn(t,i.name,i):$t(t,i.name))(Et[Et.length-1])}function Gt(t,e){return new Xt(t,e)}function Kt(t,e,i){const s=jt.from(t,t instanceof jt?t.context:void 0);for(const[t,i]of e)if(s.matches(t))return i(s);return i(s)}function Qt(t){return t}const Wt={raise:ht,send:dt,sendParent:ut,sendUpdate:lt,log:function(t=ft,e){return{type:Q,label:e,expr:t}},cancel:pt,start:gt,stop:vt,assign:yt,after:mt,done:bt,respond:function(t,e){return dt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:xt,escalate:function(t,e){return ut((e,i,s)=>({type:tt,data:b(t)?t(e,i,s):t}),Object.assign(Object.assign({},e),{to:I.Parent}))},choose:function(t){return{type:V.Choose,conds:t}},pure:function(t){return{type:V.Pure,get:t}}};export{V as ActionTypes,Xt as Interpreter,qt as InterpreterStatus,Lt as Machine,I as SpecialTargets,jt as State,It as StateNode,Wt as actions,yt as assign,Dt as createMachine,Qt as createSchema,St as doneInvoke,xt as forwardTo,Gt as interpret,P as mapState,Kt as matchState,i as matchesState,dt as send,ut as sendParent,lt as sendUpdate,Ht as spawn};
15
+ ***************************************************************************** */function C(t,e){var i={};for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&e.indexOf(s)<0&&(i[s]=t[s]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(t);n<s.length;n++)e.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(t,s[n])&&(i[s[n]]=t[s[n]])}return i}var V,I;!function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(V||(V={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(I||(I={}));const L=t=>"atomic"===t.type||"final"===t.type;function D(t){return e(t.states).map(e=>t.states[e])}function A(t){const e=[t];return L(t)?e:e.concat(u(D(t).map(A)))}function R(t,e){const i=M(new Set(t)),s=new Set(e);for(const t of s){let e=t.parent;for(;e&&!s.has(e);)s.add(e),e=e.parent}const n=M(s);for(const t of s)if("compound"!==t.type||n.get(t)&&n.get(t).length){if("parallel"===t.type)for(const e of D(t))"history"!==e.type&&(s.has(e)||(s.add(e),i.get(e)?i.get(e).forEach(t=>s.add(t)):e.initialStateNodes.forEach(t=>s.add(t))))}else i.get(t)?i.get(t).forEach(t=>s.add(t)):t.initialStateNodes.forEach(t=>s.add(t));for(const t of s){let e=t.parent;for(;e&&!s.has(e);)s.add(e),e=e.parent}return s}function M(t){const e=new Map;for(const i of t)e.has(i)||e.set(i,[]),i.parent&&(e.has(i.parent)||e.set(i.parent,[]),e.get(i.parent).push(i));return e}function z(t,e){return function t(e,i){const s=i.get(e);if(!s)return{};if("compound"===e.type){const t=s[0];if(!t)return{};if(L(t))return t.key}const n={};return s.forEach(e=>{n[e.key]=t(e,i)}),n}(t,M(R([t],e)))}function F(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function J(t,e){return"compound"===e.type?D(e).some(e=>"final"===e.type&&F(t,e)):"parallel"===e.type&&D(e).every(e=>J(t,e))}const U=V.Start,B=V.Stop,q=V.Raise,X=V.Send,H=V.Cancel,G=V.NullEvent,K=V.Assign,Q=(V.After,V.DoneState,V.Log),W=V.Init,Y=V.Invoke,Z=(V.ErrorExecution,V.ErrorPlatform),tt=V.ErrorCustom,et=V.Update,it=V.Choose,st=V.Pure,nt=N({type:W});function ot(t,e){return e&&e[t]||void 0}function rt(t,e){let i;if(S(t)||"number"==typeof t){const s=ot(t,e);i=b(s)?{type:t,exec:s}:s||{type:t,exec:void 0}}else if(b(t))i={type:t.name||t.toString(),exec:t};else{const s=ot(t.type,e);if(b(s))i=Object.assign(Object.assign({},t),{exec:s});else if(s){const e=s.type||t.type;i=Object.assign(Object.assign(Object.assign({},s),t),{type:e})}else i=t}return Object.defineProperty(i,"toString",{value:()=>i.type,enumerable:!1,configurable:!0}),i}const at=(t,e)=>{if(!t)return[];return(m(t)?t:[t]).map(t=>rt(t,e))};function ct(t){const e=rt(t);return Object.assign(Object.assign({id:S(t)?t:e.id},e),{type:e.type})}function ht(t){return S(t)?{type:q,event:t}:dt(t,{to:I.Internal})}function dt(t,e){return{to:e?e.to:void 0,type:X,event:b(t)?t:E(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:b(t)?t.name:s(t)}}function ut(t,e){return dt(t,Object.assign(Object.assign({},e),{to:I.Parent}))}function lt(){return ut(et)}const ft=(t,e)=>({context:t,event:e});const pt=t=>({type:H,sendId:t});function gt(t){const e=ct(t);return{type:V.Start,activity:e,exec:void 0}}function vt(t){const e=b(t)?t:ct(t);return{type:V.Stop,activity:e,exec:void 0}}const yt=t=>({type:K,assignment:t});function mt(t,e){const i=e?"#"+e:"";return`${V.After}(${t})${i}`}function bt(t,e){const i=`${V.DoneState}.${t}`,s={type:i,data:e,toString:()=>i};return s}function St(t,e){const i=`${V.DoneInvoke}.${t}`,s={type:i,data:e,toString:()=>i};return s}function wt(t,e){const i=`${V.ErrorPlatform}.${t}`,s={type:i,data:e,toString:()=>i};return s}function xt(t,e){return dt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))}function Ot(t,i,s,n,o){const[r,a]=v(o,t=>t.type===K);let c=r.length?function(t,i,s,n){return t?s.reduce((t,s)=>{const{assignment:o}=s,r={state:n,action:s,_event:i};let a={};if(b(o))a=o(t,i.data,r);else for(const s of e(o)){const e=o[s];a[s]=b(e)?e(t,i.data,r):e}return Object.assign({},t,a)},t):t}(s,n,r,i):s;return[u(a.map(e=>{var s;switch(e.type){case q:return{type:q,_event:N(e.event)};case X:return function(t,e,i,s){const n={_event:i},o=N(b(t.event)?t.event(e,i.data,n):t.event);let r;if(S(t.delay)){const o=s&&s[t.delay];r=b(o)?o(e,i.data,n):o}else r=b(t.delay)?t.delay(e,i.data,n):t.delay;const a=b(t.to)?t.to(e,i.data,n):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}(e,c,n,t.options.delays);case Q:return((t,e,i)=>Object.assign(Object.assign({},t),{value:S(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}))(e,c,n);case it:{const o=null===(s=e.conds.find(e=>{const s=w(e.cond,t.options.guards);return!s||$(t,s,c,n,i)}))||void 0===s?void 0:s.actions;if(!o)return[];const r=Ot(t,i,c,n,at(f(o),t.options.actions));return c=r[1],r[0]}case st:{const s=e.get(c,n.data);if(!s)return[];const o=Ot(t,i,c,n,at(f(s),t.options.actions));return c=o[1],o[0]}case B:return function(t,e,i){const s=b(t.activity)?t.activity(e,i.data):t.activity,n="string"==typeof s?{id:s}:s;return{type:V.Stop,activity:n}}(e,c,n);default:return rt(e,t.options.actions)}})),c]}function _t(t,e){const{exec:i}=t;return Object.assign(Object.assign({},t),{exec:void 0!==i?()=>i(e.context,e.event,{action:t,state:e,_event:e._event}):void 0})}class jt{constructor(e){var i;this.actions=[],this.activities=t,this.meta={},this.events=[],this.value=e.value,this.context=e.context,this._event=e._event,this._sessionid=e._sessionid,this.event=this._event.data,this.historyValue=e.historyValue,this.history=e.history,this.actions=e.actions||[],this.activities=e.activities||t,this.meta=e.meta||{},this.events=e.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=e.configuration,this.transitions=e.transitions,this.children=e.children,this.done=!!e.done,this.tags=null!==(i=e.tags)&&void 0!==i?i:new Set,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,u([...new Set(t.map(t=>t.ownEvents))]);var t}})}static from(t,e){if(t instanceof jt)return t.context!==e?new jt({value:t.value,context:e,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;return new jt({value:t,context:e,_event:nt,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new jt(t)}static inert(t,e){if(t instanceof jt){if(!t.actions.length)return t;const i=nt;return new jt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return jt.from(t,e)}toStrings(t=this.value,i="."){if(S(t))return[t];const s=e(t);return s.concat(...s.map(e=>this.toStrings(t[e],i).map(t=>e+i+t)))}toJSON(){const{configuration:t,transitions:e,tags:i}=this,s=C(this,["configuration","transitions","tags"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return i(t,this.value)}hasTag(t){return this.tags.has(t)}}const Et=[],Nt=(t,e)=>{Et.push(t);const i=e(t);return Et.pop(),i};function Tt(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),toJSON:()=>({id:t})}}function $t(t,e,i){const s=Tt(e);return s.deferred=!0,_(t)&&(s.state=Nt(void 0,()=>(i?t.withContext(i):t).initialState)),s}function kt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Pt(t){return Object.assign(Object.assign({type:Y},t),{toJSON(){const e=C(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:Y,src:kt(t.src)})}})}const Ct={},Vt=t=>"#"===t[0];class It{constructor(t,i,s){var n;this.config=t,this.context=s,this.order=-1,this.__xstatenode=!0,this.__cache={events:void 0,relativeValue:new Map,initialStateValue:void 0,initialState:void 0,on:void 0,transitions:void 0,candidates:{},delayedTransitions:void 0},this.idMap={},this.tags=[],this.options=Object.assign({actions:{},guards:{},services:{},activities:{},delays:{}},i),this.parent=this.options._parent,this.key=this.config.key||this.options._key||this.config.id||"(machine)",this.machine=this.parent?this.parent.machine:this,this.path=this.parent?this.parent.path.concat(this.key):[],this.delimiter=this.config.delimiter||(this.parent?this.parent.delimiter:"."),this.id=this.config.id||[this.machine.key,...this.path].join(this.delimiter),this.version=this.parent?this.parent.version:this.config.version,this.type=this.config.type||(this.config.parallel?"parallel":this.config.states&&e(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(n=this.config.schema)&&void 0!==n?n:{},this.initial=this.config.initial,this.states=this.config.states?a(this.config.states,(t,e)=>{const i=new It(t,{_parent:this,_key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Ct;let o=0;!function t(e){e.order=o++;for(const i of D(e))t(i)}(this),this.history=!0===this.config.history?"shallow":this.config.history||!1,this._transient=!!this.config.always||!!this.config.on&&(Array.isArray(this.config.on)?this.config.on.some(({event:t})=>""===t):""in this.config.on),this.strict=!!this.config.strict,this.onEntry=f(this.config.entry||this.config.onEntry).map(t=>rt(t)),this.onExit=f(this.config.exit||this.config.onExit).map(t=>rt(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=f(this.config.invoke).map((t,e)=>{if(_(t))return this.machine.options.services=Object.assign({[t.id]:t},this.machine.options.services),Pt({src:t.id,id:t.id});if(S(t.src))return Pt(Object.assign(Object.assign({},t),{id:t.id||t.src,src:t.src}));if(_(t.src)||b(t.src)){const i=`${this.id}:invocation[${e}]`;return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Pt(Object.assign(Object.assign({id:i},t),{src:i}))}{const e=t.src;return Pt(Object.assign(Object.assign({id:e.type},t),{src:e}))}}),this.activities=f(this.config.activities).concat(this.invoke).map(t=>ct(t)),this.transition=this.transition.bind(this),this.tags=f(this.config.tags)}_init(){this.__cache.transitions||A(this).forEach(t=>t.on)}withConfig(t,e=this.context){const{actions:i,activities:s,guards:n,services:o,delays:r}=this.options;return new It(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},s),t.activities),guards:Object.assign(Object.assign({},n),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},e)}withContext(t){return new It(this.config,this.options,t)}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:a(this.states,t=>t.definition),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=""===t,i=this.transitions.filter(i=>{const s=i.eventType===t;return e?s:s||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const i=(t,e)=>{const i=mt(b(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(dt(i,{delay:t})),this.onExit.push(pt(i)),i};return(m(t)?t.map((t,e)=>{const s=i(t.delay,e);return Object.assign(Object.assign({},t),{event:s})}):u(e(t).map((e,s)=>{const n=t[e],o=S(n)?{target:n}:n,r=isNaN(+e)?e:+e,a=i(r,s);return f(o).map(t=>Object.assign(Object.assign({},t),{event:a,delay:r}))}))).map(t=>{const{delay:e}=t;return Object.assign(Object.assign({},this.formatTransition(t)),{delay:e})})}getStateNodes(t){if(!t)return[];const i=t instanceof jt?t.value:o(t,this.delimiter);if(S(i)){const t=this.getStateNode(i).initial;return void 0!==t?this.getStateNodes({[i]:t}):[this.states[i]]}const s=e(i);return s.map(t=>this.getStateNode(t)).concat(s.reduce((t,e)=>{const s=this.getStateNode(e).getStateNodes(i[e]);return t.concat(s)},[]))}handles(t){const e=s(t);return this.events.includes(e)}resolveState(t){const e=Array.from(R([],this.getStateNodes(t.value)));return new jt(Object.assign(Object.assign({},t),{value:this.resolve(t.value),configuration:e,done:J(e,this)}))}transitionLeafNode(t,e,i){const s=this.getStateNode(t).next(e,i);return s&&s.transitions.length?s:this.next(e,i)}transitionCompoundNode(t,i,s){const n=e(t),o=this.getStateNode(n[0])._transition(t[n[0]],i,s);return o&&o.transitions.length?o:this.next(i,s)}transitionParallelNode(t,i,s){const n={};for(const o of e(t)){const e=t[o];if(!e)continue;const r=this.getStateNode(o)._transition(e,i,s);r&&(n[o]=r)}const o=e(n).map(t=>n[t]),r=u(o.map(t=>t.transitions));if(!o.some(t=>t.transitions.length>0))return this.next(i,s);const a=u(o.map(t=>t.entrySet)),c=u(e(n).map(t=>n[t].configuration));return{transitions:r,entrySet:a,exitSet:u(o.map(t=>t.exitSet)),configuration:c,source:i,actions:u(e(n).map(t=>n[t].actions))}}_transition(t,i,s){return S(t)?this.transitionLeafNode(t,i,s):1===e(t).length?this.transitionCompoundNode(t,i,s):this.transitionParallelNode(t,i,s)}next(t,e){const s=e.name,n=[];let r,a=[];for(const c of this.getCandidates(s)){const{cond:d,in:u}=c,l=t.context,f=!u||(S(u)&&Vt(u)?t.matches(o(this.getStateNodeById(u).path,this.delimiter)):i(o(u,this.delimiter),h(this.path.slice(0,-2))(t.value)));let p=!1;try{p=!d||$(this.machine,d,l,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${d.name||d.type}' in transition for event '${s}' in state node '${this.id}':\n${t.message}`)}if(p&&f){void 0!==c.target&&(a=c.target),n.push(...c.actions),r=c;break}}if(!r)return;if(!a.length)return{transitions:[r],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:n};const c=u(a.map(e=>this.getRelativeStateNodes(e,t.historyValue))),d=!!r.internal;return{transitions:[r],entrySet:d?[]:u(c.map(t=>this.nodesFromChild(t))),exitSet:d?[]:[this],configuration:c,source:t,actions:n}}nodesFromChild(t){if(t.escapes(this))return[];const e=[];let i=t;for(;i&&i!==this;)e.push(i),i=i.parent;return e.push(this),e}escapes(t){if(this===t)return!1;let e=this.parent;for(;e;){if(e===t)return!1;e=e.parent}return!0}getActions(t,e,i,s){const n=R([],s?this.getStateNodes(s.value):[this]),o=t.configuration.length?R(n,t.configuration):n;for(const e of o)F(n,e)||t.entrySet.push(e);for(const e of n)F(o,e)&&!F(t.exitSet,e.parent)||t.exitSet.push(e);t.source||(t.exitSet=[],t.entrySet.push(this));const r=u(t.entrySet.map(s=>{const n=[];if("final"!==s.type)return n;const o=s.parent;if(!o.parent)return n;n.push(bt(s.id,s.doneData),bt(o.id,s.doneData?p(s.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&D(r).every(e=>J(t.configuration,e))&&n.push(bt(r.id)),n}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,d]=[u(Array.from(a).map(t=>[...t.activities.map(t=>gt(t)),...t.onEntry])).concat(r.map(ht)),u(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>vt(t))]))];return at(d.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const s=N(e);let n;if(t instanceof jt)n=void 0===i?t:this.resolveState(jt.from(t,i));else{const e=S(t)?this.resolve(r(this.getResolvedPath(t))):this.resolve(t),s=i||this.machine.context;n=this.resolveState(jt.from(e,s))}if(this.strict&&!this.events.includes(s.name)&&(o=s.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${s.name}'`);var o;const a=this._transition(n.value,n,s)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:n,actions:[]},c=R([],this.getStateNodes(n.value)),h=a.configuration.length?R(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,n,s)}resolveRaisedTransition(t,e,i){const s=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...s),t}resolveTransition(t,i,s=nt,n=this.machine.context){const{configuration:o}=t,r=!i||t.transitions.length>0?z(this.machine,o):void 0,a=i?i.historyValue?i.historyValue:t.source?this.machine.historyValue(i.value):void 0:void 0,c=i?i.context:n,h=this.getActions(t,c,s,i),d=i?Object.assign({},i.activities):{};for(const t of h)t.type===U?d[t.activity.id||t.activity.type]=t:t.type===B&&(d[t.activity.id||t.activity.type]=!1);const[l,f]=Ot(this,i,c,s,h),[g,m]=v(l,t=>t.type===q||t.type===X&&t.to===I.Internal),b=l.filter(t=>{var e;return t.type===U&&(null===(e=t.activity)||void 0===e?void 0:e.type)===Y}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,s){var n;const o=k(t.src),r=null===(n=null==e?void 0:e.options.services)||void 0===n?void 0:n[o.type],a=t.data?p(t.data,i,s):void 0,c=r?$t(r,t.id,a):Tt(t.id);return c.meta=t,c}(e.activity,this.machine,f,s),t),i?Object.assign({},i.children):{}),w=r?t.configuration:i?i.configuration:[],x=w.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{}),O=J(w,this),_=new jt({value:r||i.value,context:f,_event:s,_sessionid:i?i._sessionid:null,historyValue:r?a?(j=a,E=r,{current:E,states:y(j,E)}):void 0:i?i.historyValue:void 0,history:!r||t.source?i:void 0,actions:r?m:[],activities:r?d:i?i.activities:{},meta:r?x:i?i.meta:void 0,events:[],configuration:w,transitions:t.transitions,children:b,done:O,tags:null==i?void 0:i.tags});var j,E;const N=c!==f;_.changed=s.name===et||N;const{history:T}=_;if(T&&delete T.history,!r)return _;let $=_;if(!O){for((this._transient||o.some(t=>t._transient))&&($=this.resolveRaisedTransition($,{type:G},s));g.length;){const t=g.shift();$=this.resolveRaisedTransition($,t._event,s)}}const P=$.changed||(T?!!$.actions.length||N||typeof T.value!=typeof $.value||!function t(i,s){if(i===s)return!0;if(void 0===i||void 0===s)return!1;if(S(i)||S(s))return i===s;const n=e(i),o=e(s);return n.length===o.length&&n.every(e=>t(i[e],s[e]))}($.value,T.value):void 0);return $.changed=P,$.history=T,$.tags=new Set(u($.configuration.map(t=>t.tags))),$}getStateNode(t){if(Vt(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error(`Unable to retrieve child state '${t}' from '${this.id}'; no child states exist.`);const e=this.states[t];if(!e)throw new Error(`Child state '${t}' does not exist on '${this.id}'`);return e}getStateNodeById(t){const e=Vt(t)?t.slice("#".length):t;if(e===this.id)return this;const i=this.machine.idMap[e];if(!i)throw new Error(`Child state node '#${e}' does not exist on machine '${this.id}'`);return i}getStateNodeByPath(t){if("string"==typeof t&&Vt(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=n(t,this.delimiter).slice();let i=this;for(;e.length;){const t=e.shift();if(!t.length)break;i=i.getStateNode(t)}return i}resolve(t){if(!t)return this.initialStateValue||Ct;switch(this.type){case"parallel":return a(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Ct);case"compound":if(S(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return e(t).length?a(t,(t,e)=>t?this.getStateNode(e).resolve(t):Ct):this.initialStateValue||{};default:return t||Ct}}getResolvedPath(t){if(Vt(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return n(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=c(this.states,t=>t.initialStateValue||Ct,t=>!("history"===t.type));else if(void 0!==this.initial){if(!this.states[this.initial])throw new Error(`Initial state '${this.initial}' not found on '${this.key}'`);t=L(this.states[this.initial])?this.initial:{[this.initial]:this.states[this.initial].initialStateValue}}else t={};return this.__cache.initialStateValue=t,this.__cache.initialStateValue}getInitialState(t,e){const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,void 0,e)}get initialState(){this._init();const{initialStateValue:t}=this;if(!t)throw new Error(`Cannot retrieve initial state from simple state '${this.id}'.`);return this.getInitialState(t)}get target(){let t;if("history"===this.type){const e=this.config;t=S(e.target)&&Vt(e.target)?r(this.machine.getStateNodeById(e.target).path.slice(this.path.length-1)):e.target}return t}getRelativeStateNodes(t,e,i=!0){return i?"history"===t.type?t.resolveHistory(e):t.initialStateNodes:[t]}get initialStateNodes(){if(L(this))return[this];if("compound"===this.type&&!this.initial)return[this];return u(d(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const s=this.getStateNode(e);if("history"===s.type)return s.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(e(this.states).length)return{current:t||this.initialStateValue,states:c(this.states,(e,i)=>{if(!t)return e.historyValue();const s=S(t)?void 0:t[i];return e.historyValue(s||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?u(d(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(s=e.path,n="states",t=>{let e=t;for(const t of s)e=e[n][t];return e})(t).current;var s,n;return S(i)?[e.getStateNode(i)]:u(d(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=u(e(this.states).map(t=>this.states[t].stateIds));return[this.id].concat(t)}get events(){if(this.__cache.events)return this.__cache.events;const{states:t}=this,i=new Set(this.ownEvents);if(t)for(const s of e(t)){const e=t[s];if(e.states)for(const t of e.events)i.add(""+t)}return this.__cache.events=Array.from(i)}get ownEvents(){const t=new Set(this.transitions.filter(t=>!(!t.target&&!t.actions.length&&t.internal)).map(t=>t.eventType));return Array.from(t)}resolveTarget(t){if(void 0!==t)return t.map(t=>{if(!S(t))return t;const e=t[0]===this.delimiter;if(e&&!this.parent)return this.getStateNodeByPath(t.slice(1));const i=e?this.key+t:t;if(!this.parent)return this.getStateNodeByPath(i);try{return this.parent.getStateNodeByPath(i)}catch(t){throw new Error(`Invalid transition definition for state node '${this.id}':\n${t.message}`)}})}formatTransition(t){const e=function(t){if(void 0!==t&&""!==t)return f(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>S(t)&&t[0]===this.delimiter),{guards:s}=this.machine.options,n=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:at(f(t.actions)),cond:w(t.cond,s),target:n,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>"#"+t.id):void 0,source:"#"+this.id})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const i=this.config.on,s="*",n=i[s],o=void 0===n?[]:n,r=C(i,[s+""]);t=u(e(r).map(t=>T(t,r[t])).concat(T("*",o)))}else t=[];const i=this.config.always?T("",this.config.always):[],s=this.config.onDone?T(String(bt(this.id)),this.config.onDone):[],n=u(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...T(String(St(t.id)),t.onDone)),t.onError&&e.push(...T(String(wt(t.id)),t.onError)),e})),o=this.after,r=u([...s,...n,...t,...i].map(t=>f(t).map(t=>this.formatTransition(t))));for(const t of o)r.push(t);return r}}function Lt(t,e,i=t.context){const s="function"==typeof i?i():i;return new It(t,e,s)}function Dt(t,e){const i="function"==typeof t.context?t.context():t.context;return new It(t,e,i)}const At={deferEvents:!1};class Rt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},At),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const Mt=new Map;let zt=0;const Ft={bookId:()=>"x:"+zt++,register:(t,e)=>(Mt.set(t,e),t),get:t=>Mt.get(t),free(t){Mt.delete(t)}};function Jt(){return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Ut(t){if(!Jt())return;const e=function(){const t=Jt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}const Bt={sync:!1,autoForward:!1};var qt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(qt||(qt={}));class Xt{constructor(t,e=Xt.defaultOptions){this.machine=t,this.scheduler=new Rt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=qt.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(m(t))return this.batch(t),this.state;const i=N(E(t,e));if(this.status===qt.Stopped)return this.state;if(this.status!==qt.Running&&!this.options.deferEvents)throw new Error(`Event "${i.name}" was sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ${JSON.stringify(i.data)}`);return this.scheduler.schedule(()=>{this.forward(i);const t=this.nextState(i);this.update(t,i)}),this._state},this.sendTo=(t,e)=>{const i=this.parent&&(e===I.Parent||this.parent.id===e),s=i?this.parent:S(e)?this.children.get(e)||Ft.get(e):(n=e)&&"function"==typeof n.send?e:void 0;var n;if(s)"machine"in s?s.send(Object.assign(Object.assign({},t),{name:t.name===tt?""+wt(this.id):t.name,origin:this.sessionId})):s.send(t.data);else if(!i)throw new Error(`Unable to send event to child '${e}' from service '${this.id}'.`)};const i=Object.assign(Object.assign({},Xt.defaultOptions),e),{clock:s,logger:n,parent:o,id:r}=i,a=void 0!==r?r:t.id;this.id=a,this.logger=n,this.clock=s,this.parent=o,this.options=i,this.scheduler=new Rt({deferEvents:this.options.deferEvents}),this.sessionId=Ft.bookId()}get initialState(){return this._initialState?this._initialState:Nt(this,()=>(this._initialState=this.machine.initialState,this._initialState))}get state(){return this._state}execute(t,e){for(const i of t.actions)this.exec(i,t,e)}update(t,e){if(t._sessionid=this.sessionId,this._state=t,this.options.execute&&this.execute(this.state),this.children.forEach(t=>{this.state.children[t.id]=t}),this.devTools&&this.devTools.send(e.data,t),t.event)for(const e of this.eventListeners)e(t.event);for(const e of this.listeners)e(t,t.event);for(const t of this.contextListeners)t(this.state.context,this.state.history?this.state.history.context:void 0);const i=J(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),s=i&&i.doneData?p(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(St(this.id,s));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===qt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>{}};let s,n=i;return"function"==typeof t?s=t:(s=t.next.bind(t),n=t.complete.bind(t)),this.listeners.add(s),this.status===qt.Running&&s(this.state),n&&this.onDone(n),{unsubscribe:()=>{s&&this.listeners.delete(s),n&&this.doneListeners.delete(n)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this.status===qt.Running)return this;Ft.register(this.sessionId,this),this.initialized=!0,this.status=qt.Running;const e=void 0===t?this.initialState:Nt(this,()=>{return!S(e=t)&&"value"in e&&"history"in e?this.machine.resolveState(t):this.machine.resolveState(jt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,nt)}),this}stop(){for(const t of this.listeners)this.listeners.delete(t);for(const t of this.stopListeners)t(),this.stopListeners.delete(t);for(const t of this.contextListeners)this.contextListeners.delete(t);for(const t of this.doneListeners)this.doneListeners.delete(t);if(!this.initialized)return this;this.state.configuration.forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{b(t.stop)&&t.stop()});for(const t of e(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this.status=qt.Stopped,Ft.free(this.sessionId),this}batch(t){if(this.status===qt.NotStarted&&this.options.deferEvents);else if(this.status!==qt.Running)throw new Error(`${t.length} event(s) were sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.`);this.scheduler.schedule(()=>{let e=this.state,i=!1;const s=[];for(const n of t){const t=N(n);this.forward(t),e=Nt(this,()=>this.machine.transition(e,t)),s.push(...e.actions.map(t=>_t(t,e))),i=i||!!e.changed}e.changed=i,e.actions=s,this.update(e,N(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=N(t);if(0===e.name.indexOf(Z)&&!this.state.nextEvents.some(t=>0===t.indexOf(Z)))throw e.data.data;return Nt(this,()=>this.machine.transition(this.state,e))}forward(t){for(const e of this.forwardTo){const i=this.children.get(e);if(!i)throw new Error(`Unable to forward event '${t}' from interpreter '${this.id}' to nonexistant child '${e}'.`);i.send(t)}}defer(t){this.delayedEventsMap[t.id]=this.clock.setTimeout(()=>{t.to?this.sendTo(t._event,t.to):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i=this.machine.options.actions){const{context:s,_event:n}=e,o=t.exec||ot(t.type,i),r=b(o)?o:o?o.exec:t.exec;if(r)try{return r(s,n.data,{action:t,state:this.state,_event:n})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(t.type){case X:const e=t;if("number"==typeof e.delay)return void this.defer(e);e.to?this.sendTo(e._event,e.to):this.send(e._event);break;case H:this.cancel(t.sendId);break;case U:{const e=t.activity;if(!this.state.activities[e.id||e.type])break;if(e.type===V.Invoke){const t=k(e.src),i=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:o,data:r}=e,a="autoForward"in e?e.autoForward:!!e.forward;if(!i)return;const c=r?p(r,s,n):void 0,h=b(i)?i(s,n.data,{data:c,src:t}):i;g(h)?this.spawnPromise(Promise.resolve(h),o):b(h)?this.spawnCallback(h,o):x(h)?this.spawnObservable(h,o):_(h)&&this.spawnMachine(c?h.withContext(c):h,{id:o,autoForward:a})}else this.spawnActivity(e);break}case B:this.stopChild(t.activity.id);break;case Q:const{label:i,value:o}=t;i?this.logger(i,o):this.logger(o)}}removeChild(t){this.children.delete(t),this.forwardTo.delete(t),delete this.state.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),b(e.stop)&&e.stop())}spawn(t,e,i){if(g(t))return this.spawnPromise(Promise.resolve(t),e);if(b(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=t)&&"id"in s)return this.spawnActor(t);if(x(t))return this.spawnObservable(t,e);if(_(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var s}spawnMachine(t,e={}){const i=new Xt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),s=Object.assign(Object.assign({},Bt),e);s.sync&&i.onTransition(t=>{this.send(et,{state:t,id:i.id})});const n=i;return this.children.set(i.id,n),s.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(N(t,{origin:i.id}))}).start(),n}spawnPromise(t,e){let i=!1;t.then(t=>{i||(this.removeChild(e),this.send(N(St(e,t),{origin:e})))},t=>{if(!i){this.removeChild(e);const i=wt(e,t);try{this.send(N(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>{},subscribe:(e,i,s)=>{const n=function(t,e,i){if("object"==typeof t)return t;const s=()=>{};return{next:t,error:e||s,complete:i||s}}(e,i,s);let o=!1;return t.then(t=>{o||(n.next(t),o||n.complete())},t=>{o||n.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{i=!0},toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const s=new Set,n=new Set,o=t=>{n.forEach(e=>e(t)),i||this.send(N(t,{origin:e}))};let r;try{r=t(o,t=>{s.add(t)})}catch(t){this.send(wt(e,t))}if(g(r))return this.spawnPromise(r,e);const a={id:e,send:t=>s.forEach(e=>e(t)),subscribe:t=>(n.add(t),{unsubscribe:()=>{n.delete(t)}}),stop:()=>{i=!0,b(r)&&r()},toJSON:()=>({id:e})};return this.children.set(e,a),a}spawnObservable(t,e){const i=t.subscribe(t=>{this.send(N(t,{origin:e}))},t=>{this.removeChild(e),this.send(N(wt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(N(St(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,s)=>t.subscribe(e,i,s),stop:()=>i.unsubscribe(),toJSON:()=>({id:e})};return this.children.set(e,s),s}spawnActor(t){return this.children.set(t.id,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,toJSON:()=>({id:t})})}attachDev(){const t=Jt();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){const e="object"==typeof this.options.devTools?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign(Object.assign({name:this.id,autoPause:!0,stateSanitizer:t=>({value:t.value,context:t.context,actions:t.actions})},e),{features:Object.assign({jump:!1,skip:!1},e?e.features:void 0)}),this.machine),this.devTools.init(this.state)}Ut(this)}}toJSON(){return{id:this.id}}[O](){return this}}Xt.defaultOptions=(t=>({execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:t.console.log.bind(console),devTools:!1}))("undefined"!=typeof self?self:global),Xt.interpret=Gt;function Ht(t,e){const i=(t=>S(t)?Object.assign(Object.assign({},Bt),{name:t}):Object.assign(Object.assign(Object.assign({},Bt),{name:j()}),t))(e);return(e=>e?e.spawn(t,i.name,i):$t(t,i.name))(Et[Et.length-1])}function Gt(t,e){return new Xt(t,e)}function Kt(t,e,i){const s=jt.from(t,t instanceof jt?t.context:void 0);for(const[t,i]of e)if(s.matches(t))return i(s);return i(s)}function Qt(t){return t}const Wt={raise:ht,send:dt,sendParent:ut,sendUpdate:lt,log:function(t=ft,e){return{type:Q,label:e,expr:t}},cancel:pt,start:gt,stop:vt,assign:yt,after:mt,done:bt,respond:function(t,e){return dt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},forwardTo:xt,escalate:function(t,e){return ut((e,i,s)=>({type:tt,data:b(t)?t(e,i,s):t}),Object.assign(Object.assign({},e),{to:I.Parent}))},choose:function(t){return{type:V.Choose,conds:t}},pure:function(t){return{type:V.Pure,get:t}}};export{V as ActionTypes,Xt as Interpreter,qt as InterpreterStatus,Lt as Machine,I as SpecialTargets,jt as State,It as StateNode,Wt as actions,yt as assign,Dt as createMachine,Qt as createSchema,St as doneInvoke,xt as forwardTo,Gt as interpret,P as mapState,Kt as matchState,i as matchesState,dt as send,ut as sendParent,lt as sendUpdate,Ht as spawn};
package/es/StateNode.js CHANGED
@@ -926,7 +926,8 @@ function () {
926
926
  configuration: resolvedConfiguration,
927
927
  transitions: stateTransition.transitions,
928
928
  children: children,
929
- done: isDone
929
+ done: isDone,
930
+ tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags
930
931
  });
931
932
  var didUpdateContext = currentContext !== updatedContext;
932
933
  nextState.changed = _event.name === update || didUpdateContext; // Dispose of penultimate histories to prevent memory leaks
package/lib/StateNode.js CHANGED
@@ -853,7 +853,8 @@ var StateNode = /** @class */ (function () {
853
853
  configuration: resolvedConfiguration,
854
854
  transitions: stateTransition.transitions,
855
855
  children: children,
856
- done: isDone
856
+ done: isDone,
857
+ tags: currentState === null || currentState === void 0 ? void 0 : currentState.tags
857
858
  });
858
859
  var didUpdateContext = currentContext !== updatedContext;
859
860
  nextState.changed = _event.name === actionTypes.update || didUpdateContext;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xstate",
3
- "version": "4.19.0",
3
+ "version": "4.19.1",
4
4
  "description": "Finite State Machines and Statecharts for the Modern Web.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",