xstate 4.30.4 → 4.30.5

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.
@@ -1,4 +1,4 @@
1
- var t,e;!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"}(t||(t={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(e||(e={}));const i=t.Start,n=t.Stop,s=t.Raise,o=t.Send,r=t.Cancel,a=t.NullEvent,c=t.Assign,h=t.After,u=t.DoneState,d=t.Log,l=t.Init,f=t.Invoke,p=t.ErrorExecution,g=t.ErrorPlatform,v=t.ErrorCustom,y=t.Update,m=t.Choose,b=t.Pure;var S=Object.freeze({__proto__:null,start:i,stop:n,raise:s,send:o,cancel:r,nullEvent:a,assign:c,after:h,doneState:u,log:d,init:l,invoke:f,errorExecution:p,errorPlatform:g,error:v,update:y,choose:m,pure:b});const O={};function w(t,e,i="."){const n=_(t,i),s=_(e,i);return F(s)?!!F(n)&&s===n:F(n)?n in s:Object.keys(n).every(t=>t in s&&w(n[t],s[t]))}function x(t){try{return F(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 j(t,e){try{return M(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function _(t,e){if("object"==typeof(i=t)&&"value"in i&&"context"in i&&"event"in i&&"_event"in i)return t.value;var i;if(M(t))return E(t);if("string"!=typeof t)return t;return E(j(t,e))}function E(t){if(1===t.length)return t[0];const e={};let i=e;for(let e=0;e<t.length-1;e++)e===t.length-2?i[t[e]]=t[e+1]:(i[t[e]]={},i=i[t[e]]);return e}function k(t,e){const i={},n=Object.keys(t);for(let s=0;s<n.length;s++){const o=n[s];i[o]=e(t[o],o,t,s)}return i}function T(t,e,i){const n={};for(const s of Object.keys(t)){const o=t[s];i(o)&&(n[s]=e(o,s,t))}return n}const N=t=>e=>{let i=e;for(const e of t)i=i[e];return i};function $(t){if(!t)return[[]];if(F(t))return[[t]];return P(Object.keys(t).map(e=>{const i=t[e];return"string"==typeof i||i&&Object.keys(i).length?$(t[e]).map(t=>[e].concat(t)):[[e]]}))}function P(t){return[].concat(...t)}function I(t){return M(t)?t:[t]}function C(t){return void 0===t?[]:I(t)}function V(t,e,i){if(z(t))return t(e,i.data);const n={};for(const s of Object.keys(t)){const o=t[s];z(o)?n[s]=o(e,i.data):n[s]=o}return n}function A(t){return t instanceof Promise||!(null===t||!z(t)&&"object"!=typeof t||!z(t.then))}function L(t,e){const[i,n]=[[],[]];for(const s of t)e(s)?i.push(s):n.push(s);return[i,n]}function D(t,e){return k(t.states,(t,i)=>{if(!t)return;const n=(F(e)?void 0:e[i])||(t?t.current:void 0);return n?{current:n,states:D(t,n)}:void 0})}function R(t,e,i,n){return t?i.reduce((t,i)=>{const{assignment:s}=i,o={state:n,action:i,_event:e};let r={};if(z(s))r=s(t,e.data,o);else for(const i of Object.keys(s)){const n=s[i];r[i]=z(n)?n(t,e.data,o):n}return Object.assign({},t,r)},t):t}function M(t){return Array.isArray(t)}function z(t){return"function"==typeof t}function F(t){return"string"==typeof t}function U(t,e){if(t)return F(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:z(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}const B=(()=>"function"==typeof Symbol&&Symbol.observable||"@@observable")();function J(t){return!!t&&"__xstatenode"in t}const q=(()=>{let t=0;return()=>(t++,t.toString(16))})();function X(t,e){return F(t)||"number"==typeof t?Object.assign({type:t},e):t}function H(t,e){if(!F(t)&&"$$type"in t&&"scxml"===t.$$type)return t;const i=X(t);return Object.assign({name:i.type,data:i,$$type:"scxml",type:"external"},e)}function G(t,e){return I(e).map(e=>void 0===e||"string"==typeof e||J(e)?{target:e,event:t}:Object.assign(Object.assign({},e),{event:t}))}function K(t,e,i,n,s){const{guards:o}=t.options,r={state:s,cond:e,_event:n};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(i,n.data,r);const a=null==o?void 0:o[e.type];if(!a)throw new Error(`Guard '${e.type}' is not implemented on machine '${t.id}'.`);return a(i,n.data,r)}function Q(t){return"string"==typeof t?{type:t}:t}function W(t,e,i){if("object"==typeof t)return t;const n=()=>{};return{next:t,error:e||n,complete:i||n}}function Y(t,e){return`${t}:invocation[${e}]`}const Z=H({type:l});function tt(t,e){return e&&e[t]||void 0}function et(t,e){let i;if(F(t)||"number"==typeof t){const n=tt(t,e);i=z(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(z(t))i={type:t.name||t.toString(),exec:t};else{const n=tt(t.type,e);if(z(n))i=Object.assign(Object.assign({},t),{exec:n});else if(n){const e=n.type||t.type;i=Object.assign(Object.assign(Object.assign({},n),t),{type:e})}else i=t}return i}const it=(t,e)=>{if(!t)return[];return(M(t)?t:[t]).map(t=>et(t,e))};function nt(t){const e=et(t);return Object.assign(Object.assign({id:F(t)?t:e.id},e),{type:e.type})}function st(t){return F(t)?{type:s,event:t}:rt(t,{to:e.Internal})}function ot(t){return{type:s,_event:H(t.event)}}function rt(t,e){return{to:e?e.to:void 0,type:o,event:z(t)?t:X(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:z(t)?t.name:x(t)}}function at(t,e,i,n){const s={_event:i},o=H(z(t.event)?t.event(e,i.data,s):t.event);let r;if(F(t.delay)){const o=n&&n[t.delay];r=z(o)?o(e,i.data,s):o}else r=z(t.delay)?t.delay(e,i.data,s):t.delay;const a=z(t.to)?t.to(e,i.data,s):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}function ct(t,i){return rt(t,Object.assign(Object.assign({},i),{to:e.Parent}))}const ht=(t,e)=>({context:t,event:e});const ut=(t,e,i)=>Object.assign(Object.assign({},t),{value:F(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}),dt=t=>({type:r,sendId:t});function lt(e){const i=nt(e);return{type:t.Start,activity:i,exec:void 0}}function ft(e){const i=z(e)?e:nt(e);return{type:t.Stop,activity:i,exec:void 0}}function pt(e,i,n){const s=z(e.activity)?e.activity(i,n.data):e.activity,o="string"==typeof s?{id:s}:s;return{type:t.Stop,activity:o}}function gt(e,i){const n=i?"#"+i:"";return`${t.After}(${e})${n}`}function vt(e,i){const n=`${t.DoneState}.${e}`,s={type:n,data:i,toString:()=>n};return s}function yt(e,i){const n=`${t.DoneInvoke}.${e}`,s={type:n,data:i,toString:()=>n};return s}function mt(e,i){const n=`${t.ErrorPlatform}.${e}`,s={type:n,data:i,toString:()=>n};return s}function bt(t,e,i,r,a,h=!1){const[u,l]=h?[[],a]:L(a,t=>t.type===c);let f=u.length?R(i,r,u,e):i;const p=h?[i]:void 0;return[P(l.map(i=>{var a;switch(i.type){case s:return ot(i);case o:return at(i,f,r,t.options.delays);case d:return ut(i,f,r);case m:{const n=null===(a=i.conds.find(i=>{const n=U(i.cond,t.options.guards);return!n||K(t,n,f,r,e)}))||void 0===a?void 0:a.actions;if(!n)return[];const[s,o]=bt(t,e,f,r,it(C(n),t.options.actions),h);return f=o,null==p||p.push(f),s}case b:{const n=i.get(f,r.data);if(!n)return[];const[s,o]=bt(t,e,f,r,it(C(n),t.options.actions),h);return f=o,null==p||p.push(f),s}case n:return pt(i,f,r);case c:f=R(f,r,[i],e),null==p||p.push(f);break;default:let u=et(i,t.options.actions);const{exec:l}=u;if(l&&p){const t=p.length-1;u=Object.assign(Object.assign({},u),{exec:(e,...i)=>{l(p[t],...i)}})}return u}}).filter(t=>!!t)),f]}var St=Object.freeze({__proto__:null,actionTypes:S,initEvent:Z,getActionFunction:tt,toActionObject:et,toActionObjects:it,toActivityDefinition:nt,raise:st,resolveRaise:ot,send:rt,resolveSend:at,sendParent:ct,sendTo:function(t,e,i){return rt(e,Object.assign(Object.assign({},i),{to:t}))},sendUpdate:function(){return ct(y)},respond:function(t,e){return rt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},log:function(t=ht,e){return{type:d,label:e,expr:t}},resolveLog:ut,cancel:dt,start:lt,stop:ft,resolveStop:pt,assign:t=>({type:c,assignment:t}),isActionObject:function(t){return"object"==typeof t&&"type"in t},after:gt,done:vt,doneInvoke:yt,error:mt,pure:function(e){return{type:t.Pure,get:e}},forwardTo:function(t,e){return rt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))},escalate:function(t,i){return ct((e,i,n)=>({type:v,data:z(t)?t(e,i,n):t}),Object.assign(Object.assign({},i),{to:e.Parent}))},choose:function(e){return{type:t.Choose,conds:e}},resolveActions:bt});const Ot=[],wt=(t,e)=>{Ot.push(t);const i=e(t);return Ot.pop(),i};function xt(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t}),[B]:function(){return this}}}function jt(t,e,i){const n=xt(e);if(n.deferred=!0,J(t)){const e=n.state=wt(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function _t(t){return Object.assign({subscribe:()=>({unsubscribe:()=>{}}),id:"anonymous",getSnapshot:()=>{},[B]:function(){return this}},t)}
1
+ var t,e;!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"}(t||(t={})),function(t){t.Parent="#_parent",t.Internal="#_internal"}(e||(e={}));const i=t.Start,n=t.Stop,s=t.Raise,o=t.Send,r=t.Cancel,a=t.NullEvent,c=t.Assign,h=t.After,u=t.DoneState,d=t.Log,l=t.Init,f=t.Invoke,p=t.ErrorExecution,g=t.ErrorPlatform,v=t.ErrorCustom,y=t.Update,m=t.Choose,b=t.Pure;var S=Object.freeze({__proto__:null,start:i,stop:n,raise:s,send:o,cancel:r,nullEvent:a,assign:c,after:h,doneState:u,log:d,init:l,invoke:f,errorExecution:p,errorPlatform:g,error:v,update:y,choose:m,pure:b});const O={};function w(t,e,i="."){const n=_(t,i),s=_(e,i);return F(s)?!!F(n)&&s===n:F(n)?n in s:Object.keys(n).every(t=>t in s&&w(n[t],s[t]))}function x(t){try{return F(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 j(t,e){try{return M(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function _(t,e){if("object"==typeof(i=t)&&"value"in i&&"context"in i&&"event"in i&&"_event"in i)return t.value;var i;if(M(t))return E(t);if("string"!=typeof t)return t;return E(j(t,e))}function E(t){if(1===t.length)return t[0];const e={};let i=e;for(let e=0;e<t.length-1;e++)e===t.length-2?i[t[e]]=t[e+1]:(i[t[e]]={},i=i[t[e]]);return e}function k(t,e){const i={},n=Object.keys(t);for(let s=0;s<n.length;s++){const o=n[s];i[o]=e(t[o],o,t,s)}return i}function T(t,e,i){const n={};for(const s of Object.keys(t)){const o=t[s];i(o)&&(n[s]=e(o,s,t))}return n}const N=t=>e=>{let i=e;for(const e of t)i=i[e];return i};function $(t){if(!t)return[[]];if(F(t))return[[t]];return P(Object.keys(t).map(e=>{const i=t[e];return"string"==typeof i||i&&Object.keys(i).length?$(t[e]).map(t=>[e].concat(t)):[[e]]}))}function P(t){return[].concat(...t)}function C(t){return M(t)?t:[t]}function I(t){return void 0===t?[]:C(t)}function V(t,e,i){if(z(t))return t(e,i.data);const n={};for(const s of Object.keys(t)){const o=t[s];z(o)?n[s]=o(e,i.data):n[s]=o}return n}function A(t){return t instanceof Promise||!(null===t||!z(t)&&"object"!=typeof t||!z(t.then))}function L(t,e){const[i,n]=[[],[]];for(const s of t)e(s)?i.push(s):n.push(s);return[i,n]}function D(t,e){return k(t.states,(t,i)=>{if(!t)return;const n=(F(e)?void 0:e[i])||(t?t.current:void 0);return n?{current:n,states:D(t,n)}:void 0})}function R(t,e,i,n){return t?i.reduce((t,i)=>{const{assignment:s}=i,o={state:n,action:i,_event:e};let r={};if(z(s))r=s(t,e.data,o);else for(const i of Object.keys(s)){const n=s[i];r[i]=z(n)?n(t,e.data,o):n}return Object.assign({},t,r)},t):t}function M(t){return Array.isArray(t)}function z(t){return"function"==typeof t}function F(t){return"string"==typeof t}function U(t,e){if(t)return F(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:z(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}const B=(()=>"function"==typeof Symbol&&Symbol.observable||"@@observable")();function J(t){return!!t&&"__xstatenode"in t}const q=(()=>{let t=0;return()=>(t++,t.toString(16))})();function X(t,e){return F(t)||"number"==typeof t?Object.assign({type:t},e):t}function H(t,e){if(!F(t)&&"$$type"in t&&"scxml"===t.$$type)return t;const i=X(t);return Object.assign({name:i.type,data:i,$$type:"scxml",type:"external"},e)}function G(t,e){return C(e).map(e=>void 0===e||"string"==typeof e||J(e)?{target:e,event:t}:Object.assign(Object.assign({},e),{event:t}))}function K(t,e,i,n,s){const{guards:o}=t.options,r={state:s,cond:e,_event:n};if("xstate.guard"===e.type)return((null==o?void 0:o[e.name])||e.predicate)(i,n.data,r);const a=null==o?void 0:o[e.type];if(!a)throw new Error(`Guard '${e.type}' is not implemented on machine '${t.id}'.`);return a(i,n.data,r)}function Q(t){return"string"==typeof t?{type:t}:t}function W(t,e,i){if("object"==typeof t)return t;const n=()=>{};return{next:t,error:e||n,complete:i||n}}function Y(t,e){return`${t}:invocation[${e}]`}const Z=H({type:l});function tt(t,e){return e&&e[t]||void 0}function et(t,e){let i;if(F(t)||"number"==typeof t){const n=tt(t,e);i=z(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(z(t))i={type:t.name||t.toString(),exec:t};else{const n=tt(t.type,e);if(z(n))i=Object.assign(Object.assign({},t),{exec:n});else if(n){const e=n.type||t.type;i=Object.assign(Object.assign(Object.assign({},n),t),{type:e})}else i=t}return i}const it=(t,e)=>{if(!t)return[];return(M(t)?t:[t]).map(t=>et(t,e))};function nt(t){const e=et(t);return Object.assign(Object.assign({id:F(t)?t:e.id},e),{type:e.type})}function st(t){return F(t)?{type:s,event:t}:rt(t,{to:e.Internal})}function ot(t){return{type:s,_event:H(t.event)}}function rt(t,e){return{to:e?e.to:void 0,type:o,event:z(t)?t:X(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:z(t)?t.name:x(t)}}function at(t,e,i,n){const s={_event:i},o=H(z(t.event)?t.event(e,i.data,s):t.event);let r;if(F(t.delay)){const o=n&&n[t.delay];r=z(o)?o(e,i.data,s):o}else r=z(t.delay)?t.delay(e,i.data,s):t.delay;const a=z(t.to)?t.to(e,i.data,s):t.to;return Object.assign(Object.assign({},t),{to:a,_event:o,event:o.data,delay:r})}function ct(t,i){return rt(t,Object.assign(Object.assign({},i),{to:e.Parent}))}const ht=(t,e)=>({context:t,event:e});const ut=(t,e,i)=>Object.assign(Object.assign({},t),{value:F(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}),dt=t=>({type:r,sendId:t});function lt(e){const i=nt(e);return{type:t.Start,activity:i,exec:void 0}}function ft(e){const i=z(e)?e:nt(e);return{type:t.Stop,activity:i,exec:void 0}}function pt(e,i,n){const s=z(e.activity)?e.activity(i,n.data):e.activity,o="string"==typeof s?{id:s}:s;return{type:t.Stop,activity:o}}function gt(e,i){const n=i?"#"+i:"";return`${t.After}(${e})${n}`}function vt(e,i){const n=`${t.DoneState}.${e}`,s={type:n,data:i,toString:()=>n};return s}function yt(e,i){const n=`${t.DoneInvoke}.${e}`,s={type:n,data:i,toString:()=>n};return s}function mt(e,i){const n=`${t.ErrorPlatform}.${e}`,s={type:n,data:i,toString:()=>n};return s}function bt(t,e,i,r,a,h=!1){const[u,l]=h?[[],a]:L(a,t=>t.type===c);let f=u.length?R(i,r,u,e):i;const p=h?[i]:void 0;return[P(l.map(i=>{var a;switch(i.type){case s:return ot(i);case o:return at(i,f,r,t.options.delays);case d:return ut(i,f,r);case m:{const n=null===(a=i.conds.find(i=>{const n=U(i.cond,t.options.guards);return!n||K(t,n,f,r,e)}))||void 0===a?void 0:a.actions;if(!n)return[];const[s,o]=bt(t,e,f,r,it(I(n),t.options.actions),h);return f=o,null==p||p.push(f),s}case b:{const n=i.get(f,r.data);if(!n)return[];const[s,o]=bt(t,e,f,r,it(I(n),t.options.actions),h);return f=o,null==p||p.push(f),s}case n:return pt(i,f,r);case c:f=R(f,r,[i],e),null==p||p.push(f);break;default:let u=et(i,t.options.actions);const{exec:l}=u;if(l&&p){const t=p.length-1;u=Object.assign(Object.assign({},u),{exec:(e,...i)=>{l(p[t],...i)}})}return u}}).filter(t=>!!t)),f]}var St=Object.freeze({__proto__:null,actionTypes:S,initEvent:Z,getActionFunction:tt,toActionObject:et,toActionObjects:it,toActivityDefinition:nt,raise:st,resolveRaise:ot,send:rt,resolveSend:at,sendParent:ct,sendTo:function(t,e,i){return rt(e,Object.assign(Object.assign({},i),{to:t}))},sendUpdate:function(){return ct(y)},respond:function(t,e){return rt(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},log:function(t=ht,e){return{type:d,label:e,expr:t}},resolveLog:ut,cancel:dt,start:lt,stop:ft,resolveStop:pt,assign:t=>({type:c,assignment:t}),isActionObject:function(t){return"object"==typeof t&&"type"in t},after:gt,done:vt,doneInvoke:yt,error:mt,pure:function(e){return{type:t.Pure,get:e}},forwardTo:function(t,e){return rt((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))},escalate:function(t,i){return ct((e,i,n)=>({type:v,data:z(t)?t(e,i,n):t}),Object.assign(Object.assign({},i),{to:e.Parent}))},choose:function(e){return{type:t.Choose,conds:e}},resolveActions:bt});const Ot=[],wt=(t,e)=>{Ot.push(t);const i=e(t);return Ot.pop(),i};function xt(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t}),[B]:function(){return this}}}function jt(t,e,i){const n=xt(e);if(n.deferred=!0,J(t)){const e=n.state=wt(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function _t(t){return Object.assign({subscribe:()=>({unsubscribe:()=>{}}),id:"anonymous",getSnapshot:()=>{},[B]:function(){return this}},t)}
2
2
  /*! *****************************************************************************
3
3
  Copyright (c) Microsoft Corporation.
4
4
 
@@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
12
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
13
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
14
  PERFORMANCE OF THIS SOFTWARE.
15
- ***************************************************************************** */function Et(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(i[n[s]]=t[n[s]])}return i}const kt=t=>"atomic"===t.type||"final"===t.type;function Tt(t){return Object.keys(t.states).map(e=>t.states[e])}function Nt(t){const e=[t];return kt(t)?e:e.concat(P(Tt(t).map(Nt)))}function $t(t,e){const i=Pt(new Set(t)),n=new Set(e);for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}const s=Pt(n);for(const t of n)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of Tt(t))"history"!==e.type&&(n.has(e)||(n.add(e),i.get(e)?i.get(e).forEach(t=>n.add(t)):e.initialStateNodes.forEach(t=>n.add(t))))}else i.get(t)?i.get(t).forEach(t=>n.add(t)):t.initialStateNodes.forEach(t=>n.add(t));for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}return n}function Pt(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 It(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(kt(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,Pt($t([t],e)))}function Ct(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function Vt(t,e){return"compound"===e.type?Tt(e).some(e=>"final"===e.type&&Ct(t,e)):"parallel"===e.type&&Tt(e).every(e=>Vt(t,e))}function At(t){return new Set(P(t.map(t=>t.tags)))}function Lt(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 Dt{constructor(t){var e;this.actions=[],this.activities=O,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||O,this.meta=function(t=[]){return t.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{})}(t.configuration),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,[...new Set(P([...t.map(t=>t.ownEvents)]))];var t}})}static from(t,e){if(t instanceof Dt)return t.context!==e?new Dt({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 Dt({value:t,context:e,_event:Z,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Dt(t)}static inert(t,e){if(t instanceof Dt){if(!t.actions.length)return t;const i=Z;return new Dt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Dt.from(t,e)}toStrings(t=this.value,e="."){if(F(t))return[t];const i=Object.keys(t);return i.concat(...i.map(i=>this.toStrings(t[i],e).map(t=>i+e+t)))}toJSON(){const{configuration:t,transitions:e,tags:i,machine:n}=this,s=Et(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return w(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){var e;this.machine;const i=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==i?void 0:i.transitions.length)&&i.transitions.some(t=>void 0!==t.target||t.actions.length)}}const Rt={deferEvents:!1};class Mt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Rt),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const zt=new Map;let Ft=0;const Ut={bookId:()=>"x:"+Ft++,register:(t,e)=>(zt.set(t,e),t),get:t=>zt.get(t),free(t){zt.delete(t)}};function Bt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Jt(t){if(!Bt())return;const e=function(){const t=Bt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function qt(t,e={}){let i=t.initialState;const n=new Set,s=[];let o=!1;const r=_t({id:e.id,send:e=>{s.push(e),(()=>{if(!o){for(o=!0;s.length>0;){const e=s.shift();i=t.transition(i,e,a),n.forEach(t=>t.next(i))}o=!1}})()},getSnapshot:()=>i,subscribe:(t,e,s)=>{const o=W(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}}),a={parent:e.parent,self:r,id:e.id||"anonymous",observers:n};return i=t.start?t.start(a):i,r}const Xt={sync:!1,autoForward:!1};var Ht;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Ht||(Ht={}));class Gt{constructor(t,i=Gt.defaultOptions){this.machine=t,this.scheduler=new Mt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=Ht.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(M(t))return this.batch(t),this.state;const i=H(X(t,e));if(this.status===Ht.Stopped)return this.state;if(this.status!==Ht.Running&&!this.options.deferEvents)throw new Error(`Event "${i.name}" was sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ${JSON.stringify(i.data)}`);return this.scheduler.schedule(()=>{this.forward(i);const t=this.nextState(i);this.update(t,i)}),this._state},this.sendTo=(t,i)=>{const n=this.parent&&(i===e.Parent||this.parent.id===i),s=n?this.parent:F(i)?this.children.get(i)||Ut.get(i):(o=i)&&"function"==typeof o.send?i:void 0;var o;if(s)"machine"in s?s.send(Object.assign(Object.assign({},t),{name:t.name===v?""+mt(this.id):t.name,origin:this.sessionId})):s.send(t.data);else if(!n)throw new Error(`Unable to send event to child '${i}' from service '${this.id}'.`)};const n=Object.assign(Object.assign({},Gt.defaultOptions),i),{clock:s,logger:o,parent:r,id:a}=n,c=void 0!==a?a:t.id;this.id=c,this.logger=o,this.clock=s,this.parent=r,this.options=n,this.scheduler=new Mt({deferEvents:this.options.deferEvents}),this.sessionId=Ut.bookId()}get initialState(){return this._initialState?this._initialState:wt(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=Vt(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?V(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(yt(this.id,n));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===Ht.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>{}};let n,s=i;return"function"==typeof t?n=t:(n=t.next.bind(t),s=t.complete.bind(t)),this.listeners.add(n),this.status===Ht.Running&&n(this.state),s&&this.onDone(s),{unsubscribe:()=>{n&&this.listeners.delete(n),s&&this.doneListeners.delete(s)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this.status===Ht.Running)return this;Ut.register(this.sessionId,this),this.initialized=!0,this.status=Ht.Running;const e=void 0===t?this.initialState:wt(this,()=>{return"object"==typeof(e=t)&&null!==e&&"value"in e&&"_event"in e?this.machine.resolveState(t):this.machine.resolveState(Dt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,Z)}),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].sort((t,e)=>e.order-t.order).forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{z(t.stop)&&t.stop()});for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this.status=Ht.Stopped,Ut.free(this.sessionId),this}batch(t){if(this.status===Ht.NotStarted&&this.options.deferEvents);else if(this.status!==Ht.Running)throw new Error(`${t.length} event(s) were sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.`);this.scheduler.schedule(()=>{let e=this.state,i=!1;const n=[];for(const s of t){const t=H(s);this.forward(t),e=wt(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>Lt(t,e))),i=i||!!e.changed}e.changed=i,e.actions=n,this.update(e,H(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=H(t);if(0===e.name.indexOf(g)&&!this.state.nextEvents.some(t=>0===t.indexOf(g)))throw e.data.data;return wt(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(e,s,a=this.machine.options.actions){const{context:c,_event:h}=s,u=e.exec||tt(e.type,a),l=z(u)?u:u?u.exec:e.exec;if(l)try{return l(c,h.data,{action:e,state:this.state,_event:h})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case o:const s=e;if("number"==typeof s.delay)return void this.defer(s);s.to?this.sendTo(s._event,s.to):this.send(s._event);break;case r:this.cancel(e.sendId);break;case i:{if(this.status!==Ht.Running)return;const i=e.activity;if(!this.state.activities[i.id||i.type])break;if(i.type===t.Invoke){const t=Q(i.src),e=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:n,data:s}=i,o="autoForward"in i?i.autoForward:!!i.forward;if(!e)return;const r=s?V(s,c,h):void 0;if("string"==typeof e)return;let a,u=z(e)?e(c,h.data,{data:r,src:t,meta:i.meta}):e;if(!u)return;J(u)&&(u=r?u.withContext(r):u,a={autoForward:o}),this.spawn(u,n,a)}else this.spawnActivity(i);break}case n:this.stopChild(e.activity.id);break;case d:const{label:a,value:u}=e;a?this.logger(a,u):this.logger(u)}}removeChild(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),z(e.stop)&&e.stop())}spawn(t,e,i){if(A(t))return this.spawnPromise(Promise.resolve(t),e);if(z(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=t)&&"id"in s)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&z(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(J(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));if(null!==(n=t)&&"object"==typeof n&&"transition"in n&&"function"==typeof n.transition)return this.spawnBehavior(t,e);throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var n,s}spawnMachine(t,e={}){const i=new Gt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Xt),e);n.sync&&i.onTransition(t=>{this.send(y,{state:t,id:i.id})});const s=i;return this.children.set(i.id,s),n.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(H(t,{origin:i.id}))}).start(),s}spawnBehavior(t,e){const i=qt(t,{id:e,parent:this});return this.children.set(e,i),i}spawnPromise(t,e){let i,n=!1;t.then(t=>{n||(i=t,this.removeChild(e),this.send(H(yt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=mt(e,t);try{this.send(H(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=W(e,i,n);let o=!1;return t.then(t=>{o||(s.next(t),o||s.complete())},t=>{o||s.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{n=!0},toJSON:()=>({id:e}),getSnapshot:()=>i,[B]:function(){return this}};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set;let o;const r=t=>{o=t,s.forEach(e=>e(t)),i||this.send(H(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(mt(e,t))}if(A(a))return this.spawnPromise(a,e);const c={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>{const e=W(t);return s.add(e.next),{unsubscribe:()=>{s.delete(e.next)}}},stop:()=>{i=!0,z(a)&&a()},toJSON:()=>({id:e}),getSnapshot:()=>o,[B]:function(){return this}};return this.children.set(e,c),c}spawnObservable(t,e){let i;const n=t.subscribe(t=>{i=t,this.send(H(t,{origin:e}))},t=>{this.removeChild(e),this.send(H(mt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(H(yt(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>n.unsubscribe(),getSnapshot:()=>i,toJSON:()=>({id:e}),[B]:function(){return this}};return this.children.set(e,s),s}spawnActor(t,e){return this.children.set(e,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t}),[B]:function(){return this}})}attachDev(){const t=Bt();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)}Jt(this)}}toJSON(){return{id:this.id}}[B](){return this}getSnapshot(){return this.status===Ht.NotStarted?this.initialState:this._state}}Gt.defaultOptions=(t=>({execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:t.console.log.bind(console),devTools:!1}))("undefined"!=typeof self?self:global),Gt.interpret=Qt;function Kt(t,e){const i=(t=>F(t)?Object.assign(Object.assign({},Xt),{name:t}):Object.assign(Object.assign(Object.assign({},Xt),{name:q()}),t))(e);return(e=>e?e.spawn(t,i.name,i):jt(t,i.name))(Ot[Ot.length-1])}function Qt(t,e){return new Gt(t,e)}function Wt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Yt(t){return Object.assign(Object.assign({type:f},t),{toJSON(){const e=Et(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:f,src:Wt(t.src)})}})}const Zt={},te=t=>"#"===t[0];class ee{constructor(t,e,i=("context"in t?t.context:void 0),n){var s;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:{}},e),this.parent=null==n?void 0:n.parent,this.key=this.config.key||(null==n?void 0:n.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&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(s=this.config.schema)&&void 0!==s?s:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?k(this.config.states,(t,e)=>{const i=new ee(t,{},void 0,{parent:this,key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Zt;let o=0;!function t(e){e.order=o++;for(const i of Tt(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=C(this.config.entry||this.config.onEntry).map(t=>et(t)),this.onExit=C(this.config.exit||this.config.onExit).map(t=>et(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=C(this.config.invoke).map((t,e)=>{if(J(t)){const i=Y(this.id,e);return this.machine.options.services=Object.assign({[i]:t},this.machine.options.services),Yt({src:i,id:i})}if(F(t.src)){const i=t.id||Y(this.id,e);return Yt(Object.assign(Object.assign({},t),{id:i,src:t.src}))}if(J(t.src)||z(t.src)){const i=t.id||Y(this.id,e);return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Yt(Object.assign(Object.assign({id:i},t),{src:i}))}{const i=t.src;return Yt(Object.assign(Object.assign({id:Y(this.id,e)},t),{src:i}))}}),this.activities=C(this.config.activities).concat(this.invoke).map(t=>nt(t)),this.transition=this.transition.bind(this),this.tags=C(this.config.tags)}_init(){this.__cache.transitions||Nt(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new ee(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},n),t.activities),guards:Object.assign(Object.assign({},s),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},null!=e?e:this.context)}withContext(t){return new ee(this.config,this.options,t)}get context(){return z(this._context)?this._context():this._context}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:k(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,description:this.description,tags:this.tags}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=""===t,i=this.transitions.filter(i=>{const n=i.eventType===t;return e?n:n||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const e=(t,e)=>{const i=gt(z(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(rt(i,{delay:t})),this.onExit.push(dt(i)),i};return(M(t)?t.map((t,i)=>{const n=e(t.delay,i);return Object.assign(Object.assign({},t),{event:n})}):P(Object.keys(t).map((i,n)=>{const s=t[i],o=F(s)?{target:s}:s,r=isNaN(+i)?i:+i,a=e(r,n);return C(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 e=t instanceof Dt?t.value:_(t,this.delimiter);if(F(e)){const t=this.getStateNode(e).initial;return void 0!==t?this.getStateNodes({[e]:t}):[this,this.states[e]]}const i=Object.keys(e),n=[this];return n.push(...P(i.map(t=>this.getStateNode(t).getStateNodes(e[t])))),n}handles(t){const e=x(t);return this.events.includes(e)}resolveState(t){const e=t instanceof Dt?t:Dt.create(t),i=Array.from($t([],this.getStateNodes(e.value)));return new Dt(Object.assign(Object.assign({},e),{value:this.resolve(e.value),configuration:i,done:Vt(i,this),tags:At(i)}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,e,i){const n=Object.keys(t),s=this.getStateNode(n[0])._transition(t[n[0]],e,i);return s&&s.transitions.length?s:this.next(e,i)}transitionParallelNode(t,e,i){const n={};for(const s of Object.keys(t)){const o=t[s];if(!o)continue;const r=this.getStateNode(s)._transition(o,e,i);r&&(n[s]=r)}const s=Object.keys(n).map(t=>n[t]),o=P(s.map(t=>t.transitions));if(!s.some(t=>t.transitions.length>0))return this.next(e,i);const r=P(s.map(t=>t.entrySet)),a=P(Object.keys(n).map(t=>n[t].configuration));return{transitions:o,entrySet:r,exitSet:P(s.map(t=>t.exitSet)),configuration:a,source:e,actions:P(Object.keys(n).map(t=>n[t].actions))}}_transition(t,e,i){return F(t)?this.transitionLeafNode(t,e,i):1===Object.keys(t).length?this.transitionCompoundNode(t,e,i):this.transitionParallelNode(t,e,i)}getTransitionData(t,e){return this._transition(t.value,t,H(e))}next(t,e){const i=e.name,n=[];let s,o=[];for(const r of this.getCandidates(i)){const{cond:a,in:c}=r,h=t.context,u=!c||(F(c)&&te(c)?t.matches(_(this.getStateNodeById(c).path,this.delimiter)):w(_(c,this.delimiter),N(this.path.slice(0,-2))(t.value)));let d=!1;try{d=!a||K(this.machine,a,h,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${a.name||a.type}' in transition for event '${i}' in state node '${this.id}':\n${t.message}`)}if(d&&u){void 0!==r.target&&(o=r.target),n.push(...r.actions),s=r;break}}if(!s)return;if(!o.length)return{transitions:[s],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:n};const r=P(o.map(e=>this.getRelativeStateNodes(e,t.historyValue))),a=!!s.internal;return{transitions:[s],entrySet:a?[]:P(r.map(t=>this.nodesFromChild(t))),exitSet:a?[]:[this],configuration:r,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,n){const s=$t([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?$t(s,t.configuration):s;for(const e of o)Ct(s,e)||t.entrySet.push(e);for(const e of s)Ct(o,e)&&!Ct(t.exitSet,e.parent)||t.exitSet.push(e);const r=P(t.entrySet.map(n=>{const s=[];if("final"!==n.type)return s;const o=n.parent;if(!o.parent)return s;s.push(vt(n.id,n.doneData),vt(o.id,n.doneData?V(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&Tt(r).every(e=>Vt(t.configuration,e))&&s.push(vt(r.id)),s}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,u]=[P(Array.from(a).map(t=>[...t.activities.map(t=>lt(t)),...t.onEntry])).concat(r.map(st)),P(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>ft(t))]))];return it(u.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const n=H(e);let s;if(t instanceof Dt)s=void 0===i?t:this.resolveState(Dt.from(t,i));else{const e=F(t)?this.resolve(E(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;s=this.resolveState(Dt.from(e,n))}if(this.strict&&!this.events.includes(n.name)&&(o=n.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${n.name}'`);var o;const r=this._transition(s.value,s,n)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},a=$t([],this.getStateNodes(s.value)),c=r.configuration.length?$t(a,r.configuration):a;return r.configuration=[...c],this.resolveTransition(r,s,s.context,n)}resolveRaisedTransition(t,e,i){const n=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...n),t}resolveTransition(t,r,c,h=Z){const{configuration:u}=t,d=!r||t.transitions.length>0,l=d?It(this.machine,u):void 0,p=r?r.historyValue?r.historyValue:t.source?this.machine.historyValue(r.value):void 0:void 0,g=this.getActions(t,c,h,r),v=r?Object.assign({},r.activities):{};for(const t of g)t.type===i?v[t.activity.id||t.activity.type]=t:t.type===n&&(v[t.activity.id||t.activity.type]=!1);const[m,b]=bt(this,r,c,h,g,this.machine.config.preserveActionOrder),[S,O]=L(m,t=>t.type===s||t.type===o&&t.to===e.Internal),w=m.filter(t=>{var e;return t.type===i&&(null===(e=t.activity)||void 0===e?void 0:e.type)===f}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=Q(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?V(t.data,i,n):void 0,c=r?jt(r,t.id,a):xt(t.id);return c.meta=t,c}(e.activity,this.machine,b,h),t),r?Object.assign({},r.children):{}),x=d?t.configuration:r?r.configuration:[],j=Vt(x,this),_=new Dt({value:l||r.value,context:b,_event:h,_sessionid:r?r._sessionid:null,historyValue:l?p?(E=p,k=l,{current:k,states:D(E,k)}):void 0:r?r.historyValue:void 0,history:!l||t.source?r:void 0,actions:l?O:[],activities:l?v:r?r.activities:{},events:[],configuration:x,transitions:t.transitions,children:w,done:j,tags:null==r?void 0:r.tags,machine:this});var E,k;const T=c!==b;_.changed=h.name===y||T;const{history:N}=_;N&&delete N.history;const $=!j&&(this._transient||u.some(t=>t._transient));if(!(d||$&&""!==h.name))return _;let P=_;if(!j)for($&&(P=this.resolveRaisedTransition(P,{type:a},h));S.length;){const t=S.shift();P=this.resolveRaisedTransition(P,t._event,h)}const I=P.changed||(N?!!P.actions.length||T||typeof N.value!=typeof P.value||!function t(e,i){if(e===i)return!0;if(void 0===e||void 0===i)return!1;if(F(e)||F(i))return e===i;const n=Object.keys(e),s=Object.keys(i);return n.length===s.length&&n.every(n=>t(e[n],i[n]))}(P.value,N.value):void 0);return P.changed=I,P.history=N,P.tags=At(P.configuration),P}getStateNode(t){if(te(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=te(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&&te(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=j(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||Zt;switch(this.type){case"parallel":return k(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Zt);case"compound":if(F(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return Object.keys(t).length?k(t,(t,e)=>t?this.getStateNode(e).resolve(t):Zt):this.initialStateValue||{};default:return t||Zt}}getResolvedPath(t){if(te(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return j(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=T(this.states,t=>t.initialStateValue||Zt,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=kt(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){this._init();const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)}get initialState(){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=F(e.target)&&te(e.target)?E(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(kt(this))return[this];if("compound"===this.type&&!this.initial)return[this];return P($(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const n=this.getStateNode(e);if("history"===n.type)return n.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:T(this.states,(e,i)=>{if(!t)return e.historyValue();const n=F(t)?void 0:t[i];return e.historyValue(n||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?P($(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(n=e.path,s="states",t=>{let e=t;for(const t of n)e=e[s][t];return e})(t).current;var n,s;return F(i)?[e.getStateNode(i)]:P($(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=P(Object.keys(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,e=new Set(this.ownEvents);if(t)for(const i of Object.keys(t)){const n=t[i];if(n.states)for(const t of n.events)e.add(""+t)}return this.__cache.events=Array.from(e)}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(!F(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 C(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>F(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:it(C(t.actions)),cond:U(t.cond,n),target:s,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>"#"+t.id):void 0,source:"#"+this.id})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const e=this.config.on,i="*",n=e[i],s=void 0===n?[]:n,o=Et(e,[i+""]);t=P(Object.keys(o).map(t=>G(t,o[t])).concat(G("*",s)))}else t=[];const e=this.config.always?G("",this.config.always):[],i=this.config.onDone?G(String(vt(this.id)),this.config.onDone):[],n=P(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...G(String(yt(t.id)),t.onDone)),t.onError&&e.push(...G(String(mt(t.id)),t.onError)),e})),s=this.after,o=P([...i,...n,...t,...e].map(t=>C(t).map(t=>this.formatTransition(t))));for(const t of s)o.push(t);return o}}function ie(t,e,i=t.context){return new ee(t,e,i)}function ne(t,e){return new ee(t,e)}function se(t,e){let i;for(const n of Object.keys(t))w(n,e)&&(!i||e.length>i.length)&&(i=n);return t[i]}function oe(t,e,i){const n=Dt.from(t,t instanceof Dt?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function re(t){return t}const ae=re,{assign:ce,send:he,sendParent:ue,sendUpdate:de,forwardTo:le,doneInvoke:fe}=St;export{t as ActionTypes,Gt as Interpreter,Ht as InterpreterStatus,ie as Machine,e as SpecialTargets,Dt as State,ee as StateNode,St as actions,ce as assign,ne as createMachine,re as createSchema,fe as doneInvoke,le as forwardTo,Qt as interpret,se as mapState,oe as matchState,w as matchesState,he as send,ue as sendParent,de as sendUpdate,Kt as spawn,qt as spawnBehavior,ae as t,_t as toActorRef,X as toEventObject,W as toObserver,H as toSCXMLEvent};
15
+ ***************************************************************************** */function Et(t,e){var i={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(i[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(i[n[s]]=t[n[s]])}return i}const kt=t=>"atomic"===t.type||"final"===t.type;function Tt(t){return Object.keys(t.states).map(e=>t.states[e])}function Nt(t){const e=[t];return kt(t)?e:e.concat(P(Tt(t).map(Nt)))}function $t(t,e){const i=Pt(new Set(t)),n=new Set(e);for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}const s=Pt(n);for(const t of n)if("compound"!==t.type||s.get(t)&&s.get(t).length){if("parallel"===t.type)for(const e of Tt(t))"history"!==e.type&&(n.has(e)||(n.add(e),i.get(e)?i.get(e).forEach(t=>n.add(t)):e.initialStateNodes.forEach(t=>n.add(t))))}else i.get(t)?i.get(t).forEach(t=>n.add(t)):t.initialStateNodes.forEach(t=>n.add(t));for(const t of n){let e=t.parent;for(;e&&!n.has(e);)n.add(e),e=e.parent}return n}function Pt(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 Ct(t,e){return function t(e,i){const n=i.get(e);if(!n)return{};if("compound"===e.type){const t=n[0];if(!t)return{};if(kt(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,Pt($t([t],e)))}function It(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function Vt(t,e){return"compound"===e.type?Tt(e).some(e=>"final"===e.type&&It(t,e)):"parallel"===e.type&&Tt(e).every(e=>Vt(t,e))}function At(t){return new Set(P(t.map(t=>t.tags)))}function Lt(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 Dt{constructor(t){var e;this.actions=[],this.activities=O,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||O,this.meta=function(t=[]){return t.reduce((t,e)=>(void 0!==e.meta&&(t[e.id]=e.meta),t),{})}(t.configuration),this.events=t.events||[],this.matches=this.matches.bind(this),this.toStrings=this.toStrings.bind(this),this.configuration=t.configuration,this.transitions=t.transitions,this.children=t.children,this.done=!!t.done,this.tags=null!==(e=Array.isArray(t.tags)?new Set(t.tags):t.tags)&&void 0!==e?e:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:()=>{return t=this.configuration,[...new Set(P([...t.map(t=>t.ownEvents)]))];var t}})}static from(t,e){if(t instanceof Dt)return t.context!==e?new Dt({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 Dt({value:t,context:e,_event:Z,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})}static create(t){return new Dt(t)}static inert(t,e){if(t instanceof Dt){if(!t.actions.length)return t;const i=Z;return new Dt({value:t.value,context:e,_event:i,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return Dt.from(t,e)}toStrings(t=this.value,e="."){if(F(t))return[t];const i=Object.keys(t);return i.concat(...i.map(i=>this.toStrings(t[i],e).map(t=>i+e+t)))}toJSON(){const{configuration:t,transitions:e,tags:i,machine:n}=this,s=Et(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return w(t,this.value)}hasTag(t){return this.tags.has(t)}can(t){var e;this.machine;const i=null===(e=this.machine)||void 0===e?void 0:e.getTransitionData(this,t);return!!(null==i?void 0:i.transitions.length)&&i.transitions.some(t=>void 0!==t.target||t.actions.length)}}const Rt={deferEvents:!1};class Mt{constructor(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=Object.assign(Object.assign({},Rt),t)}initialize(t){if(this.initialized=!0,t){if(!this.options.deferEvents)return void this.schedule(t);this.process(t)}this.flushEvents()}schedule(t){if(this.initialized&&!this.processingEvent){if(0!==this.queue.length)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()}else this.queue.push(t)}clear(){this.queue=[]}flushEvents(){let t=this.queue.shift();for(;t;)this.process(t),t=this.queue.shift()}process(t){this.processingEvent=!0;try{t()}catch(t){throw this.clear(),t}finally{this.processingEvent=!1}}}const zt=new Map;let Ft=0;const Ut={bookId:()=>"x:"+Ft++,register:(t,e)=>(zt.set(t,e),t),get:t=>zt.get(t),free(t){zt.delete(t)}};function Bt(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Jt(t){if(!Bt())return;const e=function(){const t=Bt();if(t&&"__xstate__"in t)return t.__xstate__}();e&&e.register(t)}function qt(t,e={}){let i=t.initialState;const n=new Set,s=[];let o=!1;const r=_t({id:e.id,send:e=>{s.push(e),(()=>{if(!o){for(o=!0;s.length>0;){const e=s.shift();i=t.transition(i,e,a),n.forEach(t=>t.next(i))}o=!1}})()},getSnapshot:()=>i,subscribe:(t,e,s)=>{const o=W(t,e,s);return n.add(o),o.next(i),{unsubscribe:()=>{n.delete(o)}}}}),a={parent:e.parent,self:r,id:e.id||"anonymous",observers:n};return i=t.start?t.start(a):i,r}const Xt={sync:!1,autoForward:!1};var Ht;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Ht||(Ht={}));class Gt{constructor(t,i=Gt.defaultOptions){this.machine=t,this.scheduler=new Mt,this.delayedEventsMap={},this.listeners=new Set,this.contextListeners=new Set,this.stopListeners=new Set,this.doneListeners=new Set,this.eventListeners=new Set,this.sendListeners=new Set,this.initialized=!1,this.status=Ht.NotStarted,this.children=new Map,this.forwardTo=new Set,this.init=this.start,this.send=(t,e)=>{if(M(t))return this.batch(t),this.state;const i=H(X(t,e));if(this.status===Ht.Stopped)return this.state;if(this.status!==Ht.Running&&!this.options.deferEvents)throw new Error(`Event "${i.name}" was sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.\nEvent: ${JSON.stringify(i.data)}`);return this.scheduler.schedule(()=>{this.forward(i);const t=this.nextState(i);this.update(t,i)}),this._state},this.sendTo=(t,i)=>{const n=this.parent&&(i===e.Parent||this.parent.id===i),s=n?this.parent:F(i)?this.children.get(i)||Ut.get(i):(o=i)&&"function"==typeof o.send?i:void 0;var o;if(s)"machine"in s?s.send(Object.assign(Object.assign({},t),{name:t.name===v?""+mt(this.id):t.name,origin:this.sessionId})):s.send(t.data);else if(!n)throw new Error(`Unable to send event to child '${i}' from service '${this.id}'.`)};const n=Object.assign(Object.assign({},Gt.defaultOptions),i),{clock:s,logger:o,parent:r,id:a}=n,c=void 0!==a?a:t.id;this.id=c,this.logger=o,this.clock=s,this.parent=r,this.options=n,this.scheduler=new Mt({deferEvents:this.options.deferEvents}),this.sessionId=Ut.bookId()}get initialState(){return this._initialState?this._initialState:wt(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=Vt(t.configuration||[],this.machine);if(this.state.configuration&&i){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?V(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(yt(this.id,n));this.stop()}}onTransition(t){return this.listeners.add(t),this.status===Ht.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){if(!t)return{unsubscribe:()=>{}};let n,s=i;return"function"==typeof t?n=t:(n=t.next.bind(t),s=t.complete.bind(t)),this.listeners.add(n),this.status===Ht.Running&&n(this.state),s&&this.onDone(s),{unsubscribe:()=>{n&&this.listeners.delete(n),s&&this.doneListeners.delete(s)}}}onEvent(t){return this.eventListeners.add(t),this}onSend(t){return this.sendListeners.add(t),this}onChange(t){return this.contextListeners.add(t),this}onStop(t){return this.stopListeners.add(t),this}onDone(t){return this.doneListeners.add(t),this}off(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this}start(t){if(this.status===Ht.Running)return this;Ut.register(this.sessionId,this),this.initialized=!0,this.status=Ht.Running;const e=void 0===t?this.initialState:wt(this,()=>{return"object"==typeof(e=t)&&null!==e&&"value"in e&&"_event"in e?this.machine.resolveState(t):this.machine.resolveState(Dt.from(t,this.machine.context));var e});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(()=>{this.update(e,Z)}),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].sort((t,e)=>e.order-t.order).forEach(t=>{for(const e of t.definition.exit)this.exec(e,this.state)}),this.children.forEach(t=>{z(t.stop)&&t.stop()});for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);return this.scheduler.clear(),this.initialized=!1,this.status=Ht.Stopped,Ut.free(this.sessionId),this}batch(t){if(this.status===Ht.NotStarted&&this.options.deferEvents);else if(this.status!==Ht.Running)throw new Error(`${t.length} event(s) were sent to uninitialized service "${this.machine.id}". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.`);this.scheduler.schedule(()=>{let e=this.state,i=!1;const n=[];for(const s of t){const t=H(s);this.forward(t),e=wt(this,()=>this.machine.transition(e,t)),n.push(...e.actions.map(t=>Lt(t,e))),i=i||!!e.changed}e.changed=i,e.actions=n,this.update(e,H(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}nextState(t){const e=H(t);if(0===e.name.indexOf(g)&&!this.state.nextEvents.some(t=>0===t.indexOf(g)))throw e.data.data;return wt(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(e,s,a=this.machine.options.actions){const{context:c,_event:h}=s,u=e.exec||tt(e.type,a),l=z(u)?u:u?u.exec:e.exec;if(l)try{return l(c,h.data,{action:e,state:this.state,_event:h})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case o:const s=e;if("number"==typeof s.delay)return void this.defer(s);s.to?this.sendTo(s._event,s.to):this.send(s._event);break;case r:this.cancel(e.sendId);break;case i:{if(this.status!==Ht.Running)return;const i=e.activity;if(!this.state.activities[i.id||i.type])break;if(i.type===t.Invoke){const t=Q(i.src),e=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:n,data:s}=i,o="autoForward"in i?i.autoForward:!!i.forward;if(!e)return;const r=s?V(s,c,h):void 0;if("string"==typeof e)return;let a,u=z(e)?e(c,h.data,{data:r,src:t,meta:i.meta}):e;if(!u)return;J(u)&&(u=r?u.withContext(r):u,a={autoForward:o}),this.spawn(u,n,a)}else this.spawnActivity(i);break}case n:this.stopChild(e.activity.id);break;case d:const{label:a,value:u}=e;a?this.logger(a,u):this.logger(u)}}removeChild(t){var e;this.children.delete(t),this.forwardTo.delete(t),null===(e=this.state)||void 0===e||delete e.children[t]}stopChild(t){const e=this.children.get(t);e&&(this.removeChild(t),z(e.stop)&&e.stop())}spawn(t,e,i){if(A(t))return this.spawnPromise(Promise.resolve(t),e);if(z(t))return this.spawnCallback(t,e);if(function(t){try{return"function"==typeof t.send}catch(t){return!1}}(s=t)&&"id"in s)return this.spawnActor(t,e);if(function(t){try{return"subscribe"in t&&z(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(J(t))return this.spawnMachine(t,Object.assign(Object.assign({},i),{id:e}));if(null!==(n=t)&&"object"==typeof n&&"transition"in n&&"function"==typeof n.transition)return this.spawnBehavior(t,e);throw new Error(`Unable to spawn entity "${e}" of type "${typeof t}".`);var n,s}spawnMachine(t,e={}){const i=new Gt(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Xt),e);n.sync&&i.onTransition(t=>{this.send(y,{state:t,id:i.id})});const s=i;return this.children.set(i.id,s),n.autoForward&&this.forwardTo.add(i.id),i.onDone(t=>{this.removeChild(i.id),this.send(H(t,{origin:i.id}))}).start(),s}spawnBehavior(t,e){const i=qt(t,{id:e,parent:this});return this.children.set(e,i),i}spawnPromise(t,e){let i,n=!1;t.then(t=>{n||(i=t,this.removeChild(e),this.send(H(yt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=mt(e,t);try{this.send(H(i,{origin:e}))}catch(t){this.devTools&&this.devTools.send(i,this.state),this.machine.strict&&this.stop()}}});const s={id:e,send:()=>{},subscribe:(e,i,n)=>{const s=W(e,i,n);let o=!1;return t.then(t=>{o||(s.next(t),o||s.complete())},t=>{o||s.error(t)}),{unsubscribe:()=>o=!0}},stop:()=>{n=!0},toJSON:()=>({id:e}),getSnapshot:()=>i,[B]:function(){return this}};return this.children.set(e,s),s}spawnCallback(t,e){let i=!1;const n=new Set,s=new Set;let o;const r=t=>{o=t,s.forEach(e=>e(t)),i||this.send(H(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(mt(e,t))}if(A(a))return this.spawnPromise(a,e);const c={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>{const e=W(t);return s.add(e.next),{unsubscribe:()=>{s.delete(e.next)}}},stop:()=>{i=!0,z(a)&&a()},toJSON:()=>({id:e}),getSnapshot:()=>o,[B]:function(){return this}};return this.children.set(e,c),c}spawnObservable(t,e){let i;const n=t.subscribe(t=>{i=t,this.send(H(t,{origin:e}))},t=>{this.removeChild(e),this.send(H(mt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(H(yt(e),{origin:e}))}),s={id:e,send:()=>{},subscribe:(e,i,n)=>t.subscribe(e,i,n),stop:()=>n.unsubscribe(),getSnapshot:()=>i,toJSON:()=>({id:e}),[B]:function(){return this}};return this.children.set(e,s),s}spawnActor(t,e){return this.children.set(e,t),t}spawnActivity(t){const e=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(!e)return;const i=e(this.state.context,t);this.spawnEffect(t.id,i)}spawnEffect(t,e){this.children.set(t,{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),stop:e||void 0,getSnapshot:()=>{},toJSON:()=>({id:t}),[B]:function(){return this}})}attachDev(){const t=Bt();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)}Jt(this)}}toJSON(){return{id:this.id}}[B](){return this}getSnapshot(){return this.status===Ht.NotStarted?this.initialState:this._state}}Gt.defaultOptions=(t=>({execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:t.console.log.bind(console),devTools:!1}))("undefined"!=typeof self?self:global),Gt.interpret=Qt;function Kt(t,e){const i=(t=>F(t)?Object.assign(Object.assign({},Xt),{name:t}):Object.assign(Object.assign(Object.assign({},Xt),{name:q()}),t))(e);return(e=>e?e.spawn(t,i.name,i):jt(t,i.name))(Ot[Ot.length-1])}function Qt(t,e){return new Gt(t,e)}function Wt(t){if("string"==typeof t){const e={type:t,toString:()=>t};return e}return t}function Yt(t){return Object.assign(Object.assign({type:f},t),{toJSON(){const e=Et(t,["onDone","onError"]);return Object.assign(Object.assign({},e),{type:f,src:Wt(t.src)})}})}const Zt={},te=t=>"#"===t[0];class ee{constructor(t,e,i=("context"in t?t.context:void 0),n){var s;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:{}},e),this.parent=null==n?void 0:n.parent,this.key=this.config.key||(null==n?void 0:n.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&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.schema=this.parent?this.machine.schema:null!==(s=this.config.schema)&&void 0!==s?s:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?k(this.config.states,(t,e)=>{const i=new ee(t,{},void 0,{parent:this,key:e});return Object.assign(this.idMap,Object.assign({[i.id]:i},i.idMap)),i}):Zt;let o=0;!function t(e){e.order=o++;for(const i of Tt(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=I(this.config.entry||this.config.onEntry).map(t=>et(t)),this.onExit=I(this.config.exit||this.config.onExit).map(t=>et(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=I(this.config.invoke).map((t,e)=>{if(J(t)){const i=Y(this.id,e);return this.machine.options.services=Object.assign({[i]:t},this.machine.options.services),Yt({src:i,id:i})}if(F(t.src)){const i=t.id||Y(this.id,e);return Yt(Object.assign(Object.assign({},t),{id:i,src:t.src}))}if(J(t.src)||z(t.src)){const i=t.id||Y(this.id,e);return this.machine.options.services=Object.assign({[i]:t.src},this.machine.options.services),Yt(Object.assign(Object.assign({id:i},t),{src:i}))}{const i=t.src;return Yt(Object.assign(Object.assign({id:Y(this.id,e)},t),{src:i}))}}),this.activities=I(this.config.activities).concat(this.invoke).map(t=>nt(t)),this.transition=this.transition.bind(this),this.tags=I(this.config.tags)}_init(){this.__cache.transitions||Nt(this).forEach(t=>t.on)}withConfig(t,e){const{actions:i,activities:n,guards:s,services:o,delays:r}=this.options;return new ee(this.config,{actions:Object.assign(Object.assign({},i),t.actions),activities:Object.assign(Object.assign({},n),t.activities),guards:Object.assign(Object.assign({},s),t.guards),services:Object.assign(Object.assign({},o),t.services),delays:Object.assign(Object.assign({},r),t.delays)},null!=e?e:this.context)}withContext(t){return new ee(this.config,this.options,t)}get context(){return z(this._context)?this._context():this._context}get definition(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:k(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,description:this.description,tags:this.tags}}toJSON(){return this.definition}get on(){if(this.__cache.on)return this.__cache.on;const t=this.transitions;return this.__cache.on=t.reduce((t,e)=>(t[e.eventType]=t[e.eventType]||[],t[e.eventType].push(e),t),{})}get after(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)}get transitions(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)}getCandidates(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];const e=""===t,i=this.transitions.filter(i=>{const n=i.eventType===t;return e?n:n||"*"===i.eventType});return this.__cache.candidates[t]=i,i}getDelayedTransitions(){const t=this.config.after;if(!t)return[];const e=(t,e)=>{const i=gt(z(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(rt(i,{delay:t})),this.onExit.push(dt(i)),i};return(M(t)?t.map((t,i)=>{const n=e(t.delay,i);return Object.assign(Object.assign({},t),{event:n})}):P(Object.keys(t).map((i,n)=>{const s=t[i],o=F(s)?{target:s}:s,r=isNaN(+i)?i:+i,a=e(r,n);return I(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 e=t instanceof Dt?t.value:_(t,this.delimiter);if(F(e)){const t=this.getStateNode(e).initial;return void 0!==t?this.getStateNodes({[e]:t}):[this,this.states[e]]}const i=Object.keys(e),n=[this];return n.push(...P(i.map(t=>this.getStateNode(t).getStateNodes(e[t])))),n}handles(t){const e=x(t);return this.events.includes(e)}resolveState(t){const e=t instanceof Dt?t:Dt.create(t),i=Array.from($t([],this.getStateNodes(e.value)));return new Dt(Object.assign(Object.assign({},e),{value:this.resolve(e.value),configuration:i,done:Vt(i,this),tags:At(i)}))}transitionLeafNode(t,e,i){const n=this.getStateNode(t).next(e,i);return n&&n.transitions.length?n:this.next(e,i)}transitionCompoundNode(t,e,i){const n=Object.keys(t),s=this.getStateNode(n[0])._transition(t[n[0]],e,i);return s&&s.transitions.length?s:this.next(e,i)}transitionParallelNode(t,e,i){const n={};for(const s of Object.keys(t)){const o=t[s];if(!o)continue;const r=this.getStateNode(s)._transition(o,e,i);r&&(n[s]=r)}const s=Object.keys(n).map(t=>n[t]),o=P(s.map(t=>t.transitions));if(!s.some(t=>t.transitions.length>0))return this.next(e,i);const r=P(s.map(t=>t.entrySet)),a=P(Object.keys(n).map(t=>n[t].configuration));return{transitions:o,entrySet:r,exitSet:P(s.map(t=>t.exitSet)),configuration:a,source:e,actions:P(Object.keys(n).map(t=>n[t].actions))}}_transition(t,e,i){return F(t)?this.transitionLeafNode(t,e,i):1===Object.keys(t).length?this.transitionCompoundNode(t,e,i):this.transitionParallelNode(t,e,i)}getTransitionData(t,e){return this._transition(t.value,t,H(e))}next(t,e){const i=e.name,n=[];let s,o=[];for(const r of this.getCandidates(i)){const{cond:a,in:c}=r,h=t.context,u=!c||(F(c)&&te(c)?t.matches(_(this.getStateNodeById(c).path,this.delimiter)):w(_(c,this.delimiter),N(this.path.slice(0,-2))(t.value)));let d=!1;try{d=!a||K(this.machine,a,h,e,t)}catch(t){throw new Error(`Unable to evaluate guard '${a.name||a.type}' in transition for event '${i}' in state node '${this.id}':\n${t.message}`)}if(d&&u){void 0!==r.target&&(o=r.target),n.push(...r.actions),s=r;break}}if(!s)return;if(!o.length)return{transitions:[s],entrySet:[],exitSet:[],configuration:t.value?[this]:[],source:t,actions:n};const r=P(o.map(e=>this.getRelativeStateNodes(e,t.historyValue))),a=!!s.internal;return{transitions:[s],entrySet:a?[]:P(r.map(t=>this.nodesFromChild(t))),exitSet:a?[]:[this],configuration:r,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,n){const s=$t([],n?this.getStateNodes(n.value):[this]),o=t.configuration.length?$t(s,t.configuration):s;for(const e of o)It(s,e)||t.entrySet.push(e);for(const e of s)It(o,e)&&!It(t.exitSet,e.parent)||t.exitSet.push(e);const r=P(t.entrySet.map(n=>{const s=[];if("final"!==n.type)return s;const o=n.parent;if(!o.parent)return s;s.push(vt(n.id,n.doneData),vt(o.id,n.doneData?V(n.doneData,e,i):void 0));const r=o.parent;return"parallel"===r.type&&Tt(r).every(e=>Vt(t.configuration,e))&&s.push(vt(r.id)),s}));t.exitSet.sort((t,e)=>e.order-t.order),t.entrySet.sort((t,e)=>t.order-e.order);const a=new Set(t.entrySet),c=new Set(t.exitSet),[h,u]=[P(Array.from(a).map(t=>[...t.activities.map(t=>lt(t)),...t.onEntry])).concat(r.map(st)),P(Array.from(c).map(t=>[...t.onExit,...t.activities.map(t=>ft(t))]))];return it(u.concat(t.actions).concat(h),this.machine.options.actions)}transition(t=this.initialState,e,i){const n=H(e);let s;if(t instanceof Dt)s=void 0===i?t:this.resolveState(Dt.from(t,i));else{const e=F(t)?this.resolve(E(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;s=this.resolveState(Dt.from(e,n))}if(this.strict&&!this.events.includes(n.name)&&(o=n.name,!/^(done|error)\./.test(o)))throw new Error(`Machine '${this.id}' does not accept event '${n.name}'`);var o;const r=this._transition(s.value,s,n)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:s,actions:[]},a=$t([],this.getStateNodes(s.value)),c=r.configuration.length?$t(a,r.configuration):a;return r.configuration=[...c],this.resolveTransition(r,s,s.context,n)}resolveRaisedTransition(t,e,i){const n=t.actions;return(t=this.transition(t,e))._event=i,t.event=i.data,t.actions.unshift(...n),t}resolveTransition(t,r,c,h=Z){const{configuration:u}=t,d=!r||t.transitions.length>0,l=d?Ct(this.machine,u):void 0,p=r?r.historyValue?r.historyValue:t.source?this.machine.historyValue(r.value):void 0:void 0,g=this.getActions(t,c,h,r),v=r?Object.assign({},r.activities):{};for(const t of g)t.type===i?v[t.activity.id||t.activity.type]=t:t.type===n&&(v[t.activity.id||t.activity.type]=!1);const[m,b]=bt(this,r,c,h,g,this.machine.config.preserveActionOrder),[S,O]=L(m,t=>t.type===s||t.type===o&&t.to===e.Internal),w=m.filter(t=>{var e;return t.type===i&&(null===(e=t.activity)||void 0===e?void 0:e.type)===f}).reduce((t,e)=>(t[e.activity.id]=function(t,e,i,n){var s;const o=Q(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?V(t.data,i,n):void 0,c=r?jt(r,t.id,a):xt(t.id);return c.meta=t,c}(e.activity,this.machine,b,h),t),r?Object.assign({},r.children):{}),x=d?t.configuration:r?r.configuration:[],j=Vt(x,this),_=new Dt({value:l||r.value,context:b,_event:h,_sessionid:r?r._sessionid:null,historyValue:l?p?(E=p,k=l,{current:k,states:D(E,k)}):void 0:r?r.historyValue:void 0,history:!l||t.source?r:void 0,actions:l?O:[],activities:l?v:r?r.activities:{},events:[],configuration:x,transitions:t.transitions,children:w,done:j,tags:null==r?void 0:r.tags,machine:this});var E,k;const T=c!==b;_.changed=h.name===y||T;const{history:N}=_;N&&delete N.history;const $=!j&&(this._transient||u.some(t=>t._transient));if(!(d||$&&""!==h.name))return _;let P=_;if(!j)for($&&(P=this.resolveRaisedTransition(P,{type:a},h));S.length;){const t=S.shift();P=this.resolveRaisedTransition(P,t._event,h)}const C=P.changed||(N?!!P.actions.length||T||typeof N.value!=typeof P.value||!function t(e,i){if(e===i)return!0;if(void 0===e||void 0===i)return!1;if(F(e)||F(i))return e===i;const n=Object.keys(e),s=Object.keys(i);return n.length===s.length&&n.every(n=>t(e[n],i[n]))}(P.value,N.value):void 0);return P.changed=C,P.history=N,P.tags=At(P.configuration),P}getStateNode(t){if(te(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=te(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&&te(t))try{return this.getStateNodeById(t.slice(1))}catch(t){}const e=j(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||Zt;switch(this.type){case"parallel":return k(this.initialStateValue,(e,i)=>e?this.getStateNode(i).resolve(t[i]||e):Zt);case"compound":if(F(t)){const e=this.getStateNode(t);return"parallel"===e.type||"compound"===e.type?{[t]:e.initialStateValue}:t}return Object.keys(t).length?k(t,(t,e)=>t?this.getStateNode(e).resolve(t):Zt):this.initialStateValue||{};default:return t||Zt}}getResolvedPath(t){if(te(t)){const e=this.machine.idMap[t.slice("#".length)];if(!e)throw new Error(`Unable to find state node '${t}'`);return e.path}return j(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=T(this.states,t=>t.initialStateValue||Zt,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=kt(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){this._init();const i=this.getStateNodes(t);return this.resolveTransition({configuration:i,entrySet:i,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,null!=e?e:this.machine.context,void 0)}get initialState(){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=F(e.target)&&te(e.target)?E(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(kt(this))return[this];if("compound"===this.type&&!this.initial)return[this];return P($(this.initialStateValue).map(t=>this.getFromRelativePath(t)))}getFromRelativePath(t){if(!t.length)return[this];const[e,...i]=t;if(!this.states)throw new Error(`Cannot retrieve subPath '${e}' from node with no states`);const n=this.getStateNode(e);if("history"===n.type)return n.resolveHistory();if(!this.states[e])throw new Error(`Child state '${e}' does not exist on '${this.id}'`);return this.states[e].getFromRelativePath(i)}historyValue(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:T(this.states,(e,i)=>{if(!t)return e.historyValue();const n=F(t)?void 0:t[i];return e.historyValue(n||e.initialStateValue)},t=>!t.history)}}resolveHistory(t){if("history"!==this.type)return[this];const e=this.parent;if(!t){const t=this.target;return t?P($(t).map(t=>e.getFromRelativePath(t))):e.initialStateNodes}const i=(n=e.path,s="states",t=>{let e=t;for(const t of n)e=e[s][t];return e})(t).current;var n,s;return F(i)?[e.getStateNode(i)]:P($(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=P(Object.keys(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,e=new Set(this.ownEvents);if(t)for(const i of Object.keys(t)){const n=t[i];if(n.states)for(const t of n.events)e.add(""+t)}return this.__cache.events=Array.from(e)}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(!F(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 I(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>F(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:it(I(t.actions)),cond:U(t.cond,n),target:s,source:this,internal:i,eventType:t.event,toJSON:()=>Object.assign(Object.assign({},o),{target:o.target?o.target.map(t=>"#"+t.id):void 0,source:"#"+this.id})});return o}formatTransitions(){let t;if(this.config.on)if(Array.isArray(this.config.on))t=this.config.on;else{const e=this.config.on,i="*",n=e[i],s=void 0===n?[]:n,o=Et(e,[i+""]);t=P(Object.keys(o).map(t=>G(t,o[t])).concat(G("*",s)))}else t=[];const e=this.config.always?G("",this.config.always):[],i=this.config.onDone?G(String(vt(this.id)),this.config.onDone):[],n=P(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...G(String(yt(t.id)),t.onDone)),t.onError&&e.push(...G(String(mt(t.id)),t.onError)),e})),s=this.after,o=P([...i,...n,...t,...e].map(t=>I(t).map(t=>this.formatTransition(t))));for(const t of s)o.push(t);return o}}function ie(t,e,i=t.context){return new ee(t,e,i)}function ne(t,e){return new ee(t,e)}function se(t,e){let i;for(const n of Object.keys(t))w(n,e)&&(!i||e.length>i.length)&&(i=n);return t[i]}function oe(t,e,i){const n=Dt.from(t,t instanceof Dt?t.context:void 0);for(const[t,i]of e)if(n.matches(t))return i(n);return i(n)}function re(t){return t}const ae=re,{assign:ce,send:he,sendParent:ue,sendUpdate:de,forwardTo:le,doneInvoke:fe}=St;export{t as ActionTypes,Gt as Interpreter,Ht as InterpreterStatus,ie as Machine,e as SpecialTargets,Dt as State,ee as StateNode,St as actions,ce as assign,ne as createMachine,re as createSchema,fe as doneInvoke,le as forwardTo,Qt as interpret,se as mapState,oe as matchState,w as matchesState,he as send,ue as sendParent,de as sendUpdate,Kt as spawn,qt as spawnBehavior,ae as t,_t as toActorRef,X as toEventObject,W as toObserver,H as toSCXMLEvent};
@@ -0,0 +1,81 @@
1
+ import { __spreadArray, __read } from './_virtual/_tslib.js';
2
+
3
+ var SimulatedClock =
4
+ /*#__PURE__*/
5
+
6
+ /** @class */
7
+ function () {
8
+ function SimulatedClock() {
9
+ this.timeouts = new Map();
10
+ this._now = 0;
11
+ this._id = 0;
12
+ }
13
+
14
+ SimulatedClock.prototype.now = function () {
15
+ return this._now;
16
+ };
17
+
18
+ SimulatedClock.prototype.getId = function () {
19
+ return this._id++;
20
+ };
21
+
22
+ SimulatedClock.prototype.setTimeout = function (fn, timeout) {
23
+ var id = this.getId();
24
+ this.timeouts.set(id, {
25
+ start: this.now(),
26
+ timeout: timeout,
27
+ fn: fn
28
+ });
29
+ return id;
30
+ };
31
+
32
+ SimulatedClock.prototype.clearTimeout = function (id) {
33
+ this.timeouts.delete(id);
34
+ };
35
+
36
+ SimulatedClock.prototype.set = function (time) {
37
+ if (this._now > time) {
38
+ throw new Error('Unable to travel back in time');
39
+ }
40
+
41
+ this._now = time;
42
+ this.flushTimeouts();
43
+ };
44
+
45
+ SimulatedClock.prototype.flushTimeouts = function () {
46
+ var _this = this;
47
+
48
+ __spreadArray([], __read(this.timeouts), false).sort(function (_a, _b) {
49
+ var _c = __read(_a, 2);
50
+ _c[0];
51
+ var timeoutA = _c[1];
52
+
53
+ var _d = __read(_b, 2);
54
+ _d[0];
55
+ var timeoutB = _d[1];
56
+
57
+ var endA = timeoutA.start + timeoutA.timeout;
58
+ var endB = timeoutB.start + timeoutB.timeout;
59
+ return endB > endA ? -1 : 1;
60
+ }).forEach(function (_a) {
61
+ var _b = __read(_a, 2),
62
+ id = _b[0],
63
+ timeout = _b[1];
64
+
65
+ if (_this.now() - timeout.start >= timeout.timeout) {
66
+ _this.timeouts.delete(id);
67
+
68
+ timeout.fn.call(null);
69
+ }
70
+ });
71
+ };
72
+
73
+ SimulatedClock.prototype.increment = function (ms) {
74
+ this._now += ms;
75
+ this.flushTimeouts();
76
+ };
77
+
78
+ return SimulatedClock;
79
+ }();
80
+
81
+ export { SimulatedClock };
package/es/State.js CHANGED
@@ -1,9 +1,9 @@
1
- import { __spreadArray, __read, __rest, __assign } from './_virtual/_tslib.js';
1
+ import { __assign, __spreadArray, __read, __rest } from './_virtual/_tslib.js';
2
2
  import { EMPTY_ACTIVITY_MAP } from './constants.js';
3
- import { IS_PRODUCTION } from './environment.js';
4
3
  import { isString, matchesState, warn } from './utils.js';
5
- import { initEvent } from './actions.js';
6
4
  import { getMeta, nextEvents } from './stateUtils.js';
5
+ import { initEvent } from './actions.js';
6
+ import { IS_PRODUCTION } from './environment.js';
7
7
 
8
8
  function stateValuesEqual(a, b) {
9
9
  if (a === b) {
@@ -31,6 +31,11 @@ function isStateConfig(state) {
31
31
 
32
32
  return 'value' in state && '_event' in state;
33
33
  }
34
+ /**
35
+ * @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
36
+ */
37
+
38
+ var isState = isStateConfig;
34
39
  function bindActionToState(action, state) {
35
40
  var exec = action.exec;
36
41
 
@@ -215,12 +220,12 @@ function () {
215
220
  };
216
221
 
217
222
  State.prototype.toJSON = function () {
218
- var _a = this,
219
- configuration = _a.configuration,
220
- transitions = _a.transitions,
221
- tags = _a.tags,
222
- machine = _a.machine,
223
- jsonValues = __rest(_a, ["configuration", "transitions", "tags", "machine"]);
223
+ var _a = this;
224
+ _a.configuration;
225
+ _a.transitions;
226
+ var tags = _a.tags;
227
+ _a.machine;
228
+ var jsonValues = __rest(_a, ["configuration", "transitions", "tags", "machine"]);
224
229
 
225
230
  return __assign(__assign({}, jsonValues), {
226
231
  tags: Array.from(tags)
@@ -266,4 +271,4 @@ function () {
266
271
  return State;
267
272
  }();
268
273
 
269
- export { State, bindActionToState, isStateConfig, stateValuesEqual };
274
+ export { State, bindActionToState, isState, isStateConfig, stateValuesEqual };
package/es/StateNode.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { __assign, __spreadArray, __read, __values, __rest } from './_virtual/_tslib.js';
2
+ import { isFunction, mapValues, isArray, flatten, toArray, toStateValue, isString, getEventType, toSCXMLEvent, matchesState, path, evaluateGuard, mapContext, pathToStateValue, isBuiltInEvent, partition, updateHistoryValue, toStatePath, mapFilterValues, warn, toStatePaths, nestedPath, normalizeTarget, toGuard, toTransitionConfigArray, isMachine, createInvokeId } from './utils.js';
2
3
  import { SpecialTargets } from './types.js';
3
- import { start as start$1, stop as stop$1, invoke, update, nullEvent, raise as raise$1, send as send$1 } from './actionTypes.js';
4
- import { STATE_DELIMITER } from './constants.js';
4
+ import { State, stateValuesEqual } from './State.js';
5
+ import { start as start$1, stop as stop$1, raise as raise$1, send, invoke, update, nullEvent } from './actionTypes.js';
6
+ import { done, start, raise, stop, toActionObjects, resolveActions, doneInvoke, error, toActionObject, toActivityDefinition, after, send as send$1, cancel, initEvent } from './actions.js';
5
7
  import { IS_PRODUCTION } from './environment.js';
6
- import { isFunction, mapValues, isArray, flatten, toArray, toStateValue, isString, getEventType, toSCXMLEvent, matchesState, path, evaluateGuard, mapContext, pathToStateValue, isBuiltInEvent, partition, updateHistoryValue, toStatePath, mapFilterValues, warn, toStatePaths, nestedPath, normalizeTarget, toGuard, toTransitionConfigArray, isMachine, createInvokeId } from './utils.js';
7
- import { done, start, raise, stop, toActionObjects, resolveActions, doneInvoke, error, toActionObject, toActivityDefinition, after, send, cancel, initEvent } from './actions.js';
8
- import { createInvocableActor } from './Actor.js';
8
+ import { STATE_DELIMITER } from './constants.js';
9
9
  import { getAllStateNodes, getConfiguration, isInFinalState, getTagsFromConfiguration, has, getChildren, getValue, isLeafNode } from './stateUtils.js';
10
- import { State, stateValuesEqual } from './State.js';
10
+ import { createInvocableActor } from './Actor.js';
11
11
  import { toInvokeDefinition } from './invokeUtils.js';
12
12
 
13
13
  var NULL_EVENT = '';
@@ -351,7 +351,7 @@ function () {
351
351
  var delayRef = isFunction(delay) ? "".concat(_this.id, ":delay[").concat(i, "]") : delay;
352
352
  var eventType = after(delayRef, _this.id);
353
353
 
354
- _this.onEntry.push(send(eventType, {
354
+ _this.onEntry.push(send$1(eventType, {
355
355
  delay: delay
356
356
  }));
357
357
 
@@ -888,7 +888,7 @@ function () {
888
888
  updatedContext = _b[1];
889
889
 
890
890
  var _c = __read(partition(resolvedActions, function (action) {
891
- return action.type === raise$1 || action.type === send$1 && action.to === SpecialTargets.Internal;
891
+ return action.type === raise$1 || action.type === send && action.to === SpecialTargets.Internal;
892
892
  }), 2),
893
893
  raisedEvents = _c[0],
894
894
  nonRaisedActions = _c[1];
package/es/actions.js CHANGED
@@ -3,8 +3,8 @@ import { SpecialTargets, ActionTypes } from './types.js';
3
3
  import { init, send as send$1, raise as raise$1, update, log as log$1, cancel as cancel$1, assign as assign$1, error as error$1, stop as stop$1, pure as pure$1, choose as choose$1 } from './actionTypes.js';
4
4
  import * as actionTypes from './actionTypes.js';
5
5
  export { actionTypes };
6
- import { IS_PRODUCTION } from './environment.js';
7
6
  import { toSCXMLEvent, isString, isFunction, toEventObject, getEventType, partition, updateContext, flatten, toArray, toGuard, evaluateGuard, warn, isArray } from './utils.js';
7
+ import { IS_PRODUCTION } from './environment.js';
8
8
 
9
9
  var initEvent = /*#__PURE__*/toSCXMLEvent({
10
10
  type: init
package/es/behaviors.js CHANGED
@@ -1,9 +1,75 @@
1
- import './types.js';
2
- import './actionTypes.js';
3
- import './environment.js';
4
- import { toObserver } from './utils.js';
1
+ import { error, doneInvoke } from './actions.js';
5
2
  import { toActorRef } from './Actor.js';
3
+ import { toObserver } from './utils.js';
4
+
5
+ /**
6
+ * Returns an actor behavior from a reducer and its initial state.
7
+ *
8
+ * @param transition The pure reducer that returns the next state given the current state and event.
9
+ * @param initialState The initial state of the reducer.
10
+ * @returns An actor behavior
11
+ */
12
+
13
+ function fromReducer(transition, initialState) {
14
+ return {
15
+ transition: transition,
16
+ initialState: initialState
17
+ };
18
+ }
19
+ function fromPromise(promiseFn) {
20
+ var initialState = {
21
+ error: undefined,
22
+ data: undefined,
23
+ status: 'pending'
24
+ };
25
+ return {
26
+ transition: function (state, event, _a) {
27
+ var parent = _a.parent,
28
+ id = _a.id,
29
+ observers = _a.observers;
6
30
 
31
+ switch (event.type) {
32
+ case 'fulfill':
33
+ parent === null || parent === void 0 ? void 0 : parent.send(doneInvoke(id, event.data));
34
+ return {
35
+ error: undefined,
36
+ data: event.data,
37
+ status: 'fulfilled'
38
+ };
39
+
40
+ case 'reject':
41
+ parent === null || parent === void 0 ? void 0 : parent.send(error(id, event.error));
42
+ observers.forEach(function (observer) {
43
+ observer.error(event.error);
44
+ });
45
+ return {
46
+ error: event.error,
47
+ data: undefined,
48
+ status: 'rejected'
49
+ };
50
+
51
+ default:
52
+ return state;
53
+ }
54
+ },
55
+ initialState: initialState,
56
+ start: function (_a) {
57
+ var self = _a.self;
58
+ promiseFn().then(function (data) {
59
+ self.send({
60
+ type: 'fulfill',
61
+ data: data
62
+ });
63
+ }, function (reason) {
64
+ self.send({
65
+ type: 'reject',
66
+ error: reason
67
+ });
68
+ });
69
+ return initialState;
70
+ }
71
+ };
72
+ }
7
73
  function spawnBehavior(behavior, options) {
8
74
  if (options === void 0) {
9
75
  options = {};
@@ -62,4 +128,4 @@ function spawnBehavior(behavior, options) {
62
128
  return actor;
63
129
  }
64
130
 
65
- export { spawnBehavior };
131
+ export { fromPromise, fromReducer, spawnBehavior };
package/es/each.js ADDED
@@ -0,0 +1,13 @@
1
+ function each(collection, item, indexOrActions, maybeActions) {
2
+ var actions = maybeActions || indexOrActions;
3
+ var index = maybeActions ? indexOrActions : undefined;
4
+ return {
5
+ type: 'xstate.foreach',
6
+ collection: collection,
7
+ item: item,
8
+ index: index,
9
+ actions: actions
10
+ };
11
+ }
12
+
13
+ export { each };
package/es/index.js CHANGED
@@ -1,17 +1,17 @@
1
- export { ActionTypes, SpecialTargets } from './types.js';
2
- export { matchesState, toEventObject, toObserver, toSCXMLEvent } from './utils.js';
3
1
  import { assign as assign$1, send as send$1, sendParent as sendParent$1, sendUpdate as sendUpdate$1, forwardTo as forwardTo$1, doneInvoke as doneInvoke$1 } from './actions.js';
4
2
  import * as actions from './actions.js';
5
3
  export { actions };
6
4
  export { toActorRef } from './Actor.js';
7
- export { State } from './State.js';
8
- export { spawnBehavior } from './behaviors.js';
9
5
  export { Interpreter, InterpreterStatus, interpret, spawn } from './interpreter.js';
10
- export { StateNode } from './StateNode.js';
11
6
  export { Machine, createMachine } from './Machine.js';
12
7
  export { mapState } from './mapState.js';
13
8
  export { matchState } from './match.js';
14
9
  export { createSchema, t } from './schema.js';
10
+ export { State } from './State.js';
11
+ export { StateNode } from './StateNode.js';
12
+ export { spawnBehavior } from './behaviors.js';
13
+ export { ActionTypes, SpecialTargets } from './types.js';
14
+ export { matchesState, toEventObject, toObserver, toSCXMLEvent } from './utils.js';
15
15
 
16
16
  var assign = assign$1,
17
17
  send = send$1,
package/es/interpreter.js CHANGED
@@ -1,16 +1,16 @@
1
1
  import { __values, __spreadArray, __read, __assign } from './_virtual/_tslib.js';
2
2
  import { ActionTypes, SpecialTargets } from './types.js';
3
+ import { isStateConfig, State, bindActionToState } from './State.js';
3
4
  import { errorPlatform, log, stop, start, cancel, send, update, error as error$1 } from './actionTypes.js';
5
+ import { doneInvoke, initEvent, getActionFunction, error } from './actions.js';
4
6
  import { IS_PRODUCTION } from './environment.js';
5
7
  import { warn, mapContext, isFunction, toSCXMLEvent, toInvokeSource, isMachine, isPromiseLike, isObservable, isBehavior, reportUnhandledExceptionOnInvocation, symbolObservable, isArray, toEventObject, isString, isActor, uniqueId, toObserver } from './utils.js';
6
- import { doneInvoke, initEvent, getActionFunction, error } from './actions.js';
7
- import { provide, consume } from './serviceScope.js';
8
+ import { Scheduler } from './scheduler.js';
8
9
  import { isSpawnedActor, createDeferredActor } from './Actor.js';
9
10
  import { isInFinalState } from './stateUtils.js';
10
- import { isStateConfig, State, bindActionToState } from './State.js';
11
- import { Scheduler } from './scheduler.js';
12
11
  import { registry } from './registry.js';
13
12
  import { registerService, getGlobal } from './devTools.js';
13
+ import { provide, consume } from './serviceScope.js';
14
14
  import { spawnBehavior } from './behaviors.js';
15
15
 
16
16
  var DEFAULT_SPAWN_OPTIONS = {
package/es/invokeUtils.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { __assign, __rest } from './_virtual/_tslib.js';
2
2
  import './types.js';
3
3
  import { invoke } from './actionTypes.js';
4
- import './environment.js';
5
4
  import './utils.js';
5
+ import './environment.js';
6
6
 
7
7
  function toInvokeSource(src) {
8
8
  if (typeof src === 'string') {
@@ -25,9 +25,9 @@ function toInvokeDefinition(invokeConfig) {
25
25
  type: invoke
26
26
  }, invokeConfig), {
27
27
  toJSON: function () {
28
- var onDone = invokeConfig.onDone,
29
- onError = invokeConfig.onError,
30
- invokeDef = __rest(invokeConfig, ["onDone", "onError"]);
28
+ invokeConfig.onDone;
29
+ invokeConfig.onError;
30
+ var invokeDef = __rest(invokeConfig, ["onDone", "onError"]);
31
31
 
32
32
  return __assign(__assign({}, invokeDef), {
33
33
  type: invoke,