xstate 4.34.0 → 4.35.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 x(t,e,i="."){const n=j(t,i),s=j(e,i);return z(s)?!!z(n)&&s===n:z(n)?n in s:Object.keys(n).every(t=>t in s&&x(n[t],s[t]))}function _(t){try{return z(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 w(t,e){try{return R(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function j(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(R(t))return E(t);if("string"!=typeof t)return t;return E(w(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 N(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 T=t=>e=>{let i=e;for(const e of t)i=i[e];return i};function A(t){if(!t)return[[]];if(z(t))return[[t]];return $(Object.keys(t).map(e=>{const i=t[e];return"string"==typeof i||i&&Object.keys(i).length?A(t[e]).map(t=>[e].concat(t)):[[e]]}))}function $(t){return[].concat(...t)}function I(t){return R(t)?t:[t]}function P(t){return void 0===t?[]:I(t)}function C(t,e,i){if(M(t))return t(e,i.data);const n={};for(const s of Object.keys(t)){const o=t[s];M(o)?n[s]=o(e,i.data):n[s]=o}return n}function V(t){return t instanceof Promise||!(null===t||!M(t)&&"object"!=typeof t||!M(t.then))}function L(t,e){return k(t.states,(t,i)=>{if(!t)return;const n=(z(e)?void 0:e[i])||(t?t.current:void 0);return n?{current:n,states:L(t,n)}:void 0})}function D(t,e,i,n){return t?i.reduce((t,i)=>{const{assignment:s}=i,o={state:n,action:i,_event:e};let r={};if(M(s))r=s(t,e.data,o);else for(const i of Object.keys(s)){const n=s[i];r[i]=M(n)?n(t,e.data,o):n}return Object.assign({},t,r)},t):t}function R(t){return Array.isArray(t)}function M(t){return"function"==typeof t}function z(t){return"string"==typeof t}function U(t,e){if(t)return z(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:M(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}const B=(()=>"function"==typeof Symbol&&Symbol.observable||"@@observable")();function F(t){return!!t&&"__xstatenode"in t}const J=(()=>{let t=0;return()=>(t++,t.toString(16))})();function q(t,e){return z(t)||"number"==typeof t?Object.assign({type:t},e):t}function Q(t,e){if(!z(t)&&"$$type"in t&&"scxml"===t.$$type)return t;const i=q(t);return Object.assign({name:i.type,data:i,$$type:"scxml",type:"external"},e)}function X(t,e){return I(e).map(e=>void 0===e||"string"==typeof e||F(e)?{target:e,event:t}:Object.assign(Object.assign({},e),{event:t}))}function H(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 G(t){return"string"==typeof t?{type:t}:t}function K(t,e,i){const n=()=>{},s="object"==typeof t,o=s?t:null;return{next:((s?t.next:t)||n).bind(o),error:((s?t.error:e)||n).bind(o),complete:((s?t.complete:i)||n).bind(o)}}function W(t,e){return`${t}:invocation[${e}]`}const Y=Q({type:l});function Z(t,e){return e&&e[t]||void 0}function tt(t,e){let i;if(z(t)||"number"==typeof t){const n=Z(t,e);i=M(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(M(t))i={type:t.name||t.toString(),exec:t};else{const n=Z(t.type,e);if(M(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 et=(t,e)=>{if(!t)return[];return(R(t)?t:[t]).map(t=>tt(t,e))};function it(t){const e=tt(t);return Object.assign(Object.assign({id:z(t)?t:e.id},e),{type:e.type})}function nt(t){return z(t)?{type:s,event:t}:ot(t,{to:e.Internal})}function st(t){return{type:s,_event:Q(t.event)}}function ot(t,e){return{to:e?e.to:void 0,type:o,event:M(t)?t:q(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:M(t)?t.name:_(t)}}function rt(t,e,i,n){const s={_event:i},o=Q(M(t.event)?t.event(e,i.data,s):t.event);let r;if(z(t.delay)){const o=n&&n[t.delay];r=M(o)?o(e,i.data,s):o}else r=M(t.delay)?t.delay(e,i.data,s):t.delay;const a=M(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 at(t,i){return ot(t,Object.assign(Object.assign({},i),{to:e.Parent}))}const ct=(t,e)=>({context:t,event:e});const ht=(t,e,i)=>Object.assign(Object.assign({},t),{value:z(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}),ut=t=>({type:r,sendId:t});function dt(e){const i=it(e);return{type:t.Start,activity:i,exec:void 0}}function lt(e){const i=M(e)?e:it(e);return{type:t.Stop,activity:i,exec:void 0}}function ft(e,i,n){const s=M(e.activity)?e.activity(i,n.data):e.activity,o="string"==typeof s?{id:s}:s;return{type:t.Stop,activity:o}}function pt(e,i){const n=i?"#"+i:"";return`${t.After}(${e})${n}`}function gt(e,i){const n=`${t.DoneState}.${e}`,s={type:n,data:i,toString:()=>n};return s}function vt(e,i){const n=`${t.DoneInvoke}.${e}`,s={type:n,data:i,toString:()=>n};return s}function yt(e,i){const n=`${t.ErrorPlatform}.${e}`,s={type:n,data:i,toString:()=>n};return s}function mt(t,i,r,a,h,u,l=!1){const f=l?[]:(t=>{const e=[];for(const i of t){let t=0;for(;t<i.length;)i[t].type!==c?t++:(e.push(i[t]),i.splice(t,1))}return e})(h);let p=f.length?D(r,a,f,i):r;const g=l?[r]:void 0,v=[];function y(h){var f;switch(h.type){case s:return st(h);case o:const y=rt(h,p,a,t.options.delays);return u&&y.to!==e.Internal&&v.push(y),y;case d:{const t=ht(h,p,a);return null==u||u(t,p,a),t}case m:{const e=null===(f=h.conds.find(e=>{const n=U(e.cond,t.options.guards);return!n||H(t,n,p,a,u?void 0:i)}))||void 0===f?void 0:f.actions;if(!e)return[];const[n,s]=mt(t,i,p,a,[et(P(e),t.options.actions)],u,l);return p=s,null==g||g.push(p),n}case b:{const e=h.get(p,a.data);if(!e)return[];const[n,s]=mt(t,i,p,a,[et(P(e),t.options.actions)],u,l);return p=s,null==g||g.push(p),n}case n:{const t=ft(h,p,a);return null==u||u(t,r,a),t}case c:p=D(p,a,[h],u?void 0:i),null==g||g.push(p);break;default:let S=tt(h,t.options.actions);const{exec:O}=S;if(u)u(S,p,a);else if(O&&g){const t=g.length-1;S=Object.assign(Object.assign({},S),{exec:(e,...i)=>{O(g[t],...i)}})}return S}}return[$(h.map((function(t){let e=[];for(const i of t){const t=y(i);t&&(e=e.concat(t))}return v.forEach(t=>{u(t,p,a)}),v.length=0,e}))),p]}var bt=Object.freeze({__proto__:null,actionTypes:S,initEvent:Y,getActionFunction:Z,toActionObject:tt,toActionObjects:et,toActivityDefinition:it,raise:nt,resolveRaise:st,send:ot,resolveSend:rt,sendParent:at,sendTo:function(t,e,i){return ot(e,Object.assign(Object.assign({},i),{to:t}))},sendUpdate:function(){return at(y)},respond:function(t,e){return ot(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},log:function(t=ct,e){return{type:d,label:e,expr:t}},resolveLog:ht,cancel:ut,start:dt,stop:lt,resolveStop:ft,assign:t=>({type:c,assignment:t}),isActionObject:function(t){return"object"==typeof t&&"type"in t},after:pt,done:gt,doneInvoke:vt,error:yt,pure:function(e){return{type:t.Pure,get:e}},forwardTo:function(t,e){return ot((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))},escalate:function(t,i){return at((e,i,n)=>({type:v,data:M(t)?t(e,i,n):t}),Object.assign(Object.assign({},i),{to:e.Parent}))},choose:function(e){return{type:t.Choose,conds:e}},resolveActions:mt});const St=[],Ot=(t,e)=>{St.push(t);const i=e(t);return St.pop(),i};function xt(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t}),[B]:function(){return this}}}function _t(t,e,i){const n=xt(e);if(n.deferred=!0,F(t)){const e=n.state=Ot(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function wt(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,d=t.DoneState,u=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:d,log:u,init:l,invoke:f,errorExecution:p,errorPlatform:g,error:v,update:y,choose:m,pure:b});const O={};function x(t,e,i="."){const n=j(t,i),s=j(e,i);return z(s)?!!z(n)&&s===n:z(n)?n in s:Object.keys(n).every(t=>t in s&&x(n[t],s[t]))}function _(t){try{return z(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 w(t,e){try{return R(t)?t:t.toString().split(e)}catch(e){throw new Error(`'${t}' is not a valid state path.`)}}function j(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(R(t))return E(t);if("string"!=typeof t)return t;return E(w(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 N(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 T=t=>e=>{let i=e;for(const e of t)i=i[e];return i};function A(t){if(!t)return[[]];if(z(t))return[[t]];return $(Object.keys(t).map(e=>{const i=t[e];return"string"==typeof i||i&&Object.keys(i).length?A(t[e]).map(t=>[e].concat(t)):[[e]]}))}function $(t){return[].concat(...t)}function I(t){return R(t)?t:[t]}function P(t){return void 0===t?[]:I(t)}function C(t,e,i){if(M(t))return t(e,i.data);const n={};for(const s of Object.keys(t)){const o=t[s];M(o)?n[s]=o(e,i.data):n[s]=o}return n}function V(t){return t instanceof Promise||!(null===t||!M(t)&&"object"!=typeof t||!M(t.then))}function L(t,e){return k(t.states,(t,i)=>{if(!t)return;const n=(z(e)?void 0:e[i])||(t?t.current:void 0);return n?{current:n,states:L(t,n)}:void 0})}function D(t,e,i,n){return t?i.reduce((t,i)=>{const{assignment:s}=i,o={state:n,action:i,_event:e};let r={};if(M(s))r=s(t,e.data,o);else for(const i of Object.keys(s)){const n=s[i];r[i]=M(n)?n(t,e.data,o):n}return Object.assign({},t,r)},t):t}function R(t){return Array.isArray(t)}function M(t){return"function"==typeof t}function z(t){return"string"==typeof t}function U(t,e){if(t)return z(t)?{type:"xstate.guard",name:t,predicate:e?e[t]:void 0}:M(t)?{type:"xstate.guard",name:t.name,predicate:t}:t}const B=(()=>"function"==typeof Symbol&&Symbol.observable||"@@observable")();function F(t){return!!t&&"__xstatenode"in t}const J=(()=>{let t=0;return()=>(t++,t.toString(16))})();function q(t,e){return z(t)||"number"==typeof t?Object.assign({type:t},e):t}function Q(t,e){if(!z(t)&&"$$type"in t&&"scxml"===t.$$type)return t;const i=q(t);return Object.assign({name:i.type,data:i,$$type:"scxml",type:"external"},e)}function X(t,e){return I(e).map(e=>void 0===e||"string"==typeof e||F(e)?{target:e,event:t}:Object.assign(Object.assign({},e),{event:t}))}function H(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 G(t){return"string"==typeof t?{type:t}:t}function K(t,e,i){const n=()=>{},s="object"==typeof t,o=s?t:null;return{next:((s?t.next:t)||n).bind(o),error:((s?t.error:e)||n).bind(o),complete:((s?t.complete:i)||n).bind(o)}}function W(t,e){return`${t}:invocation[${e}]`}const Y=Q({type:l});function Z(t,e){return e&&e[t]||void 0}function tt(t,e){let i;if(z(t)||"number"==typeof t){const n=Z(t,e);i=M(n)?{type:t,exec:n}:n||{type:t,exec:void 0}}else if(M(t))i={type:t.name||t.toString(),exec:t};else{const n=Z(t.type,e);if(M(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 et=(t,e)=>{if(!t)return[];return(R(t)?t:[t]).map(t=>tt(t,e))};function it(t){const e=tt(t);return Object.assign(Object.assign({id:z(t)?t:e.id},e),{type:e.type})}function nt(t){return z(t)?{type:s,event:t}:ot(t,{to:e.Internal})}function st(t){return{type:s,_event:Q(t.event)}}function ot(t,e){return{to:e?e.to:void 0,type:o,event:M(t)?t:q(t),delay:e?e.delay:void 0,id:e&&void 0!==e.id?e.id:M(t)?t.name:_(t)}}function rt(t,e,i,n){const s={_event:i},o=Q(M(t.event)?t.event(e,i.data,s):t.event);let r;if(z(t.delay)){const o=n&&n[t.delay];r=M(o)?o(e,i.data,s):o}else r=M(t.delay)?t.delay(e,i.data,s):t.delay;const a=M(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 at(t,i){return ot(t,Object.assign(Object.assign({},i),{to:e.Parent}))}const ct=(t,e)=>({context:t,event:e});const ht=(t,e,i)=>Object.assign(Object.assign({},t),{value:z(t.expr)?t.expr:t.expr(e,i.data,{_event:i})}),dt=t=>({type:r,sendId:t});function ut(e){const i=it(e);return{type:t.Start,activity:i,exec:void 0}}function lt(e){const i=M(e)?e:it(e);return{type:t.Stop,activity:i,exec:void 0}}function ft(e,i,n){const s=M(e.activity)?e.activity(i,n.data):e.activity,o="string"==typeof s?{id:s}:s;return{type:t.Stop,activity:o}}function pt(e,i){const n=i?"#"+i:"";return`${t.After}(${e})${n}`}function gt(e,i){const n=`${t.DoneState}.${e}`,s={type:n,data:i,toString:()=>n};return s}function vt(e,i){const n=`${t.DoneInvoke}.${e}`,s={type:n,data:i,toString:()=>n};return s}function yt(e,i){const n=`${t.ErrorPlatform}.${e}`,s={type:n,data:i,toString:()=>n};return s}function mt(t,i,r,a,h,d,l=!1){const f=l?[]:(t=>{const e=[];for(const i of t){let t=0;for(;t<i.actions.length;)i.actions[t].type!==c?t++:(e.push(i.actions[t]),i.actions.splice(t,1))}return e})(h);let p=f.length?D(r,a,f,i):r;const g=l?[r]:void 0,v=[];function y(h,f){var y;switch(f.type){case s:return st(f);case o:const S=rt(f,p,a,t.options.delays);return d&&S.to!==e.Internal&&("entry"===h?v.push(S):null==d||d(S,p,a)),S;case u:{const t=ht(f,p,a);return null==d||d(t,p,a),t}case m:{const e=null===(y=f.conds.find(e=>{const n=U(e.cond,t.options.guards);return!n||H(t,n,p,a,d?void 0:i)}))||void 0===y?void 0:y.actions;if(!e)return[];const[n,s]=mt(t,i,p,a,[{type:h,actions:et(P(e),t.options.actions)}],d,l);return p=s,null==g||g.push(p),n}case b:{const e=f.get(p,a.data);if(!e)return[];const[n,s]=mt(t,i,p,a,[{type:h,actions:et(P(e),t.options.actions)}],d,l);return p=s,null==g||g.push(p),n}case n:{const t=ft(f,p,a);return null==d||d(t,r,a),t}case c:p=D(p,a,[f],d?void 0:i),null==g||g.push(p);break;default:let O=tt(f,t.options.actions);const{exec:x}=O;if(d)d(O,p,a);else if(x&&g){const t=g.length-1;O=Object.assign(Object.assign({},O),{exec:(e,...i)=>{x(g[t],...i)}})}return O}}return[$(h.map((function(t){let e=[];for(const i of t.actions){const n=y(t.type,i);n&&(e=e.concat(n))}return v.forEach(t=>{d(t,p,a)}),v.length=0,e}))),p]}var bt=Object.freeze({__proto__:null,actionTypes:S,initEvent:Y,getActionFunction:Z,toActionObject:tt,toActionObjects:et,toActivityDefinition:it,raise:nt,resolveRaise:st,send:ot,resolveSend:rt,sendParent:at,sendTo:function(t,e,i){return ot(e,Object.assign(Object.assign({},i),{to:t}))},sendUpdate:function(){return at(y)},respond:function(t,e){return ot(t,Object.assign(Object.assign({},e),{to:(t,e,{_event:i})=>i.origin}))},log:function(t=ct,e){return{type:u,label:e,expr:t}},resolveLog:ht,cancel:dt,start:ut,stop:lt,resolveStop:ft,assign:t=>({type:c,assignment:t}),isActionObject:function(t){return"object"==typeof t&&"type"in t},after:pt,done:gt,doneInvoke:vt,error:yt,pure:function(e){return{type:t.Pure,get:e}},forwardTo:function(t,e){return ot((t,e)=>e,Object.assign(Object.assign({},e),{to:t}))},escalate:function(t,i){return at((e,i,n)=>({type:v,data:M(t)?t(e,i,n):t}),Object.assign(Object.assign({},i),{to:e.Parent}))},choose:function(e){return{type:t.Choose,conds:e}},resolveActions:mt});const St=[],Ot=(t,e)=>{St.push(t);const i=e(t);return St.pop(),i};function xt(t){return{id:t,send:()=>{},subscribe:()=>({unsubscribe:()=>{}}),getSnapshot:()=>{},toJSON:()=>({id:t}),[B]:function(){return this}}}function _t(t,e,i){const n=xt(e);if(n.deferred=!0,F(t)){const e=n.state=Ot(void 0,()=>(i?t.withContext(i):t).initialState);n.getSnapshot=()=>e}return n}function wt(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 jt(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 Et=t=>"atomic"===t.type||"final"===t.type;function kt(t){return Object.keys(t.states).map(e=>t.states[e])}function Nt(t){return kt(t).filter(t=>"history"!==t.type)}function Tt(t){const e=[t];return Et(t)?e:e.concat($(Nt(t).map(Tt)))}function At(t,e){const i=$t(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=$t(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 Nt(t))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 $t(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(Et(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,$t(At([t],e)))}function Pt(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function Ct(t,e){return"compound"===e.type?Nt(e).some(e=>"final"===e.type&&Pt(t,e)):"parallel"===e.type&&Nt(e).every(e=>Ct(t,e))}function Vt(t){return new Set($(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($([...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:Y,_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=Y;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(z(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=jt(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return x(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 Ut=0;const Bt={bookId:()=>"x:"+Ut++,register:(t,e)=>(zt.set(t,e),t),get:t=>zt.get(t),free(t){zt.delete(t)}};function Ft(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Jt(t){if(!Ft())return;const e=function(){const t=Ft();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=wt({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=K(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 Qt={sync:!1,autoForward:!1};var Xt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Xt||(Xt={}));class Ht{constructor(s,a=Ht.defaultOptions){this.machine=s,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=Xt.NotStarted,this.children=new Map,this.forwardTo=new Set,this._outgoingQueue=[],this.init=this.start,this.send=(t,e)=>{if(R(t))return this.batch(t),this.state;const i=Q(q(t,e));if(this.status===Xt.Stopped)return this.state;if(this.status!==Xt.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,n)=>{const s=this.parent&&(i===e.Parent||this.parent.id===i),o=s?this.parent:z(i)?this.children.get(i)||Bt.get(i):(r=i)&&"function"==typeof r.send?i:void 0;var r;if(o)if("machine"in o){if(this.status!==Xt.Stopped||this.parent!==o||this.state.done){const e=Object.assign(Object.assign({},t),{name:t.name===v?""+yt(this.id):t.name,origin:this.sessionId});!n&&this.machine.config.predictableActionArguments?this._outgoingQueue.push([o,e]):o.send(e)}}else!n&&this.machine.config.predictableActionArguments?this._outgoingQueue.push([o,t.data]):o.send(t.data);else if(!s)throw new Error(`Unable to send event to child '${i}' from service '${this.id}'.`)},this._exec=(e,s,a,c=this.machine.options.actions)=>{const h=e.exec||Z(e.type,c),u=M(h)?h:h?h.exec:e.exec;if(u)try{return u(s,a.data,this.machine.config.predictableActionArguments?{action:e,_event:a}:{action:e,state:this.state,_event:a})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case o:const c=e;if("number"==typeof c.delay)return void this.defer(c);c.to?this.sendTo(c._event,c.to,a===Y):this.send(c._event);break;case r:this.cancel(e.sendId);break;case i:{if(this.status!==Xt.Running)return;const i=e.activity;if(!this.machine.config.predictableActionArguments&&!this.state.activities[i.id||i.type])break;if(i.type===t.Invoke){const t=G(i.src),e=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:n,data:o}=i,r="autoForward"in i?i.autoForward:!!i.forward;if(!e)return;const c=o?C(o,s,a):void 0;if("string"==typeof e)return;let h,u=M(e)?e(s,a.data,{data:c,src:t,meta:i.meta}):e;if(!u)return;F(u)&&(u=c?u.withContext(c):u,h={autoForward:r}),this.spawn(u,n,h)}else this.spawnActivity(i);break}case n:this.stopChild(e.activity.id);break;case d:const{label:h,value:u}=e;h?this.logger(h,u):this.logger(u)}};const c=Object.assign(Object.assign({},Ht.defaultOptions),a),{clock:h,logger:u,parent:l,id:f}=c,p=void 0!==f?f:s.id;this.id=p,this.logger=u,this.clock=h,this.parent=l,this.options=c,this.scheduler=new Mt({deferEvents:this.options.deferEvents}),this.sessionId=Bt.bookId()}get initialState(){return this._initialState?this._initialState:Ot(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.machine.config.predictableActionArguments&&e!==Y||!this.options.execute){let t;for(;t=this._outgoingQueue.shift();)t[0].send(t[1])}else this.execute(this.state);if(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);if(this.state.done){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?C(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(vt(this.id,n));this._stop(),this._stopChildren()}}onTransition(t){return this.listeners.add(t),this.status===Xt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){const n=K(t,e,i);this.listeners.add(n.next),this.status!==Xt.NotStarted&&n.next(this.state);const s=()=>{this.doneListeners.delete(s),this.stopListeners.delete(s),n.complete()};return this.status===Xt.Stopped?n.complete():(this.onDone(s),this.onStop(s)),{unsubscribe:()=>{this.listeners.delete(n.next),this.doneListeners.delete(s),this.stopListeners.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===Xt.Running)return this;this.machine._init(),Bt.register(this.sessionId,this),this.initialized=!0,this.status=Xt.Running;const e=void 0===t?this.initialState:Ot(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,Y)}),this}_stopChildren(){this.children.forEach(t=>{M(t.stop)&&t.stop()}),this.children.clear()}_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.initialized=!1,this.status=Xt.Stopped,this._initialState=void 0;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);this.scheduler.clear(),this.scheduler=new Mt({deferEvents:this.options.deferEvents})}stop(){const t=this.scheduler;return this._stop(),t.schedule(()=>{const t=Q({type:"xstate.stop"}),i=Ot(this,()=>{const i=$([...this.state.configuration].sort((t,e)=>e.order-t.order).map(t=>et(t.onExit,this.machine.options.actions))),[n,r]=mt(this.machine,this.state,this.state.context,t,[i],this.machine.config.predictableActionArguments?this._exec:void 0,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),a=new Dt({value:this.state.value,context:r,_event:t,_sessionid:this.sessionId,historyValue:void 0,history:this.state,actions:n.filter(t=>t.type!==s&&(t.type!==o||!!t.to&&t.to!==e.Internal)),activities:{},events:[],configuration:[],transitions:[],children:{},done:this.state.done,tags:this.state.tags,machine:this.machine});return a.changed=!0,a});this.update(i,t),this._stopChildren(),Bt.free(this.sessionId)}),this}batch(t){if(this.status===Xt.NotStarted&&this.options.deferEvents);else if(this.status!==Xt.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.`);if(!t.length)return;const e=!!this.machine.config.predictableActionArguments&&this._exec;this.scheduler.schedule(()=>{let i=this.state,n=!1;const s=[];for(const o of t){const t=Q(o);this.forward(t),i=Ot(this,()=>this.machine.transition(i,t,void 0,e||void 0)),s.push(...this.machine.config.predictableActionArguments?i.actions:i.actions.map(t=>Lt(t,i))),n=n||!!i.changed}i.changed=n,i.actions=s,this.update(i,Q(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}_nextState(t,e=!!this.machine.config.predictableActionArguments&&this._exec){const i=Q(t);if(0===i.name.indexOf(g)&&!this.state.nextEvents.some(t=>0===t.indexOf(g)))throw i.data.data;return Ot(this,()=>this.machine.transition(this.state,i,void 0,e||void 0))}nextState(t){return this._nextState(t,!1)}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,!0):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i=this.machine.options.actions){this._exec(t,e.context,e._event,i)}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),M(e.stop)&&e.stop())}spawn(t,e,i){if(this.status!==Xt.Running)return _t(t,e);if(V(t))return this.spawnPromise(Promise.resolve(t),e);if(M(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&&M(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(F(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 Ht(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Qt),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(Q(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(Q(vt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=yt(e,t);try{this.send(Q(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=K(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(Q(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(yt(e,t))}if(V(a))return this.spawnPromise(a,e);const c={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>{const e=K(t);return s.add(e.next),{unsubscribe:()=>{s.delete(e.next)}}},stop:()=>{i=!0,M(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(Q(t,{origin:e}))},t=>{this.removeChild(e),this.send(Q(yt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(Q(vt(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=Ft();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===Xt.NotStarted?this.initialState:this._state}}Ht.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1},Ht.interpret=Kt;function Gt(t,e){const i=(t=>z(t)?Object.assign(Object.assign({},Qt),{name:t}):Object.assign(Object.assign(Object.assign({},Qt),{name:J()}),t))(e);return(e=>e?e.spawn(t,i.name,i):_t(t,i.name))(St[St.length-1])}function Kt(t,e){return new Ht(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=jt(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 kt(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=P(this.config.entry||this.config.onEntry).map(t=>tt(t)),this.onExit=P(this.config.exit||this.config.onExit).map(t=>tt(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=P(this.config.invoke).map((t,e)=>{if(F(t)){const i=W(this.id,e);return this.machine.options.services=Object.assign({[i]:t},this.machine.options.services),Yt({src:i,id:i})}if(z(t.src)){const i=t.id||W(this.id,e);return Yt(Object.assign(Object.assign({},t),{id:i,src:t.src}))}if(F(t.src)||M(t.src)){const i=t.id||W(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:W(this.id,e)},t),{src:i}))}}),this.activities=P(this.config.activities).concat(this.invoke).map(t=>it(t)),this.transition=this.transition.bind(this),this.tags=P(this.config.tags)}_init(){this.__cache.transitions||Tt(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 M(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=pt(M(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(ot(i,{delay:t})),this.onExit.push(ut(i)),i};return(R(t)?t.map((t,i)=>{const n=e(t.delay,i);return Object.assign(Object.assign({},t),{event:n})}):$(Object.keys(t).map((i,n)=>{const s=t[i],o=z(s)?{target:s}:s,r=isNaN(+i)?i:+i,a=e(r,n);return P(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:j(t,this.delimiter);if(z(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(...$(i.map(t=>this.getStateNode(t).getStateNodes(e[t])))),n}handles(t){const e=_(t);return this.events.includes(e)}resolveState(t){const e=t instanceof Dt?t:Dt.create(t),i=Array.from(At([],this.getStateNodes(e.value)));return new Dt(Object.assign(Object.assign({},e),{value:this.resolve(e.value),configuration:i,done:Ct(i,this),tags:Vt(i),machine:this.machine}))}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=$(s.map(t=>t.transitions));if(!s.some(t=>t.transitions.length>0))return this.next(e,i);const r=$(s.map(t=>t.entrySet)),a=$(Object.keys(n).map(t=>n[t].configuration));return{transitions:o,entrySet:r,exitSet:$(s.map(t=>t.exitSet)),configuration:a,source:e,actions:$(Object.keys(n).map(t=>n[t].actions))}}_transition(t,e,i){return z(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,Q(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||(z(c)&&te(c)?t.matches(j(this.getStateNodeById(c).path,this.delimiter)):x(j(c,this.delimiter),T(this.path.slice(0,-2))(t.value)));let d=!1;try{d=!a||H(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=$(o.map(e=>this.getRelativeStateNodes(e,t.historyValue))),a=!!s.internal,c=[];return a||o.forEach(t=>{c.push(...this.getExternalReentryNodes(t))}),{transitions:[s],entrySet:c,exitSet:a?[]:[this],configuration:r,source:t,actions:n}}getExternalReentryNodes(t){const e=[];let[i,n]=t.order>this.order?[t,this]:[this,t];for(;i&&i!==n;)e.push(i),i=i.parent;return i!==n?[]:(e.push(n),e)}getActions(t,i,n,r,a,c,h){const u=At([],c?this.getStateNodes(c.value):[this]);for(const e of t)(!Pt(u,e)||Pt(n.entrySet,e.parent)&&!Pt(n.entrySet,e))&&n.entrySet.push(e);for(const e of u)Pt(t,e)&&!Pt(n.exitSet,e.parent)||n.exitSet.push(e);const d=$(n.entrySet.map(t=>{const e=[];if("final"!==t.type)return e;const i=t.parent;if(!i.parent)return e;e.push(gt(t.id,t.doneData),gt(i.id,t.doneData?C(t.doneData,r,a):void 0));const s=i.parent;return"parallel"===s.type&&Nt(s).every(t=>Ct(n.configuration,t))&&e.push(gt(s.id)),e}));n.exitSet.sort((t,e)=>e.order-t.order),n.entrySet.sort((t,e)=>t.order-e.order);const l=new Set(n.entrySet),f=new Set(n.exitSet),p=Array.from(l).map(t=>{const e=t.onEntry,i=t.activities.map(t=>dt(t));return et(h?[...e,...i]:[...i,...e],this.machine.options.actions)}).concat([d.map(nt)]),g=Array.from(f).map(t=>et([...t.onExit,...t.activities.map(t=>lt(t))],this.machine.options.actions)).concat([et(n.actions,this.machine.options.actions)]).concat(p);if(i){const i=et($([...t].sort((t,e)=>e.order-t.order).map(t=>t.onExit)),this.machine.options.actions).filter(t=>t.type!==s&&(t.type!==o||!!t.to&&t.to!==e.Internal));return g.concat([i])}return g}transition(t=this.initialState,e,i,n){const s=Q(e);let o;if(t instanceof Dt)o=void 0===i?t:this.resolveState(Dt.from(t,i));else{const e=z(t)?this.resolve(E(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;o=this.resolveState(Dt.from(e,n))}if(this.strict&&!this.events.includes(s.name)&&(r=s.name,!/^(done|error)\./.test(r)))throw new Error(`Machine '${this.id}' does not accept event '${s.name}'`);var r;const a=this._transition(o.value,o,s)||{transitions:[],configuration:[],entrySet:[],exitSet:[],source:o,actions:[]},c=At([],this.getStateNodes(o.value)),h=a.configuration.length?At(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,o,o.context,n,s)}resolveRaisedTransition(t,e,i,n){const s=t.actions;return(t=this.transition(t,e,void 0,n))._event=i,t.event=i.data,t.actions.unshift(...s),t}resolveTransition(t,r,c,h,u=Y){const{configuration:d}=t,l=!r||t.transitions.length>0,p=l?t.configuration:r?r.configuration:[],g=Ct(p,this),v=l?It(this.machine,d):void 0,m=r?r.historyValue?r.historyValue:t.source?this.machine.historyValue(r.value):void 0:void 0,b=this.getActions(new Set(p),g,t,c,u,r,h),S=r?Object.assign({},r.activities):{};for(const t of b)for(const e of t)e.type===i?S[e.activity.id||e.activity.type]=e:e.type===n&&(S[e.activity.id||e.activity.type]=!1);const[O,x]=mt(this,r,c,u,b,h,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),[_,w]=function(t,e){const[i,n]=[[],[]];for(const s of t)e(s)?i.push(s):n.push(s);return[i,n]}(O,t=>t.type===s||t.type===o&&t.to===e.Internal),j=O.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=G(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?C(t.data,i,n):void 0,c=r?_t(r,t.id,a):xt(t.id);return c.meta=t,c}(e.activity,this.machine,x,u),t),r?Object.assign({},r.children):{}),E=new Dt({value:v||r.value,context:x,_event:u,_sessionid:r?r._sessionid:null,historyValue:v?m?(k=m,N=v,{current:N,states:L(k,N)}):void 0:r?r.historyValue:void 0,history:!v||t.source?r:void 0,actions:v?w:[],activities:v?S:r?r.activities:{},events:[],configuration:p,transitions:t.transitions,children:j,done:g,tags:Vt(p),machine:this});var k,N;const T=c!==x;E.changed=u.name===y||T;const{history:A}=E;A&&delete A.history;const $=!g&&(this._transient||d.some(t=>t._transient));if(!(l||$&&""!==u.name))return E;let I=E;if(!g)for($&&(I=this.resolveRaisedTransition(I,{type:a},u,h));_.length;){const t=_.shift();I=this.resolveRaisedTransition(I,t._event,u,h)}const P=I.changed||(A?!!I.actions.length||T||typeof A.value!=typeof I.value||!function t(e,i){if(e===i)return!0;if(void 0===e||void 0===i)return!1;if(z(e)||z(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]))}(I.value,A.value):void 0);return I.changed=P,I.history=A,I}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=w(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(z(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 w(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=N(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=Et(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=z(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(Et(this))return[this];if("compound"===this.type&&!this.initial)return[this];return $(A(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:N(this.states,(e,i)=>{if(!t)return e.historyValue();const n=z(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?$(A(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 z(i)?[e.getStateNode(i)]:$(A(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=$(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(!z(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 P(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>z(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:et(P(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=jt(e,[i+""]);t=$(Object.keys(o).map(t=>X(t,o[t])).concat(X("*",s)))}else t=[];const e=this.config.always?X("",this.config.always):[],i=this.config.onDone?X(String(gt(this.id)),this.config.onDone):[],n=$(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...X(String(vt(t.id)),t.onDone)),t.onError&&e.push(...X(String(yt(t.id)),t.onError)),e})),s=this.after,o=$([...i,...n,...t,...e].map(t=>P(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))x(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,sendTo:ue,sendParent:de,sendUpdate:le,forwardTo:fe,doneInvoke:pe,raise:ge}=bt;export{t as ActionTypes,Ht as Interpreter,Xt as InterpreterStatus,ie as Machine,e as SpecialTargets,Dt as State,ee as StateNode,bt as actions,ce as assign,ne as createMachine,re as createSchema,pe as doneInvoke,fe as forwardTo,Kt as interpret,se as mapState,oe as matchState,x as matchesState,ge as raise,he as send,de as sendParent,ue as sendTo,le as sendUpdate,Gt as spawn,qt as spawnBehavior,ae as t,wt as toActorRef,q as toEventObject,K as toObserver,Q as toSCXMLEvent};
15
+ ***************************************************************************** */function jt(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 Et=t=>"atomic"===t.type||"final"===t.type;function kt(t){return Object.keys(t.states).map(e=>t.states[e])}function Nt(t){return kt(t).filter(t=>"history"!==t.type)}function Tt(t){const e=[t];return Et(t)?e:e.concat($(Nt(t).map(Tt)))}function At(t,e){const i=$t(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=$t(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 Nt(t))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 $t(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(Et(t))return t.key}const s={};return n.forEach(e=>{s[e.key]=t(e,i)}),s}(t,$t(At([t],e)))}function Pt(t,e){return Array.isArray(t)?t.some(t=>t===e):t instanceof Set&&t.has(e)}function Ct(t,e){return"compound"===e.type?Nt(e).some(e=>"final"===e.type&&Pt(t,e)):"parallel"===e.type&&Nt(e).every(e=>Ct(t,e))}function Vt(t){return new Set($(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($([...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:Y,_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=Y;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(z(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=jt(this,["configuration","transitions","tags","machine"]);return Object.assign(Object.assign({},s),{tags:Array.from(i)})}matches(t){return x(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 Ut=0;const Bt={bookId:()=>"x:"+Ut++,register:(t,e)=>(zt.set(t,e),t),get:t=>zt.get(t),free(t){zt.delete(t)}};function Ft(){return"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0}function Jt(t){if(!Ft())return;const e=function(){const t=Ft();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=wt({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=K(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 Qt={sync:!1,autoForward:!1};var Xt;!function(t){t[t.NotStarted=0]="NotStarted",t[t.Running=1]="Running",t[t.Stopped=2]="Stopped"}(Xt||(Xt={}));class Ht{constructor(s,a=Ht.defaultOptions){this.machine=s,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=Xt.NotStarted,this.children=new Map,this.forwardTo=new Set,this._outgoingQueue=[],this.init=this.start,this.send=(t,e)=>{if(R(t))return this.batch(t),this.state;const i=Q(q(t,e));if(this.status===Xt.Stopped)return this.state;if(this.status!==Xt.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,n)=>{const s=this.parent&&(i===e.Parent||this.parent.id===i),o=s?this.parent:z(i)?this.children.get(i)||Bt.get(i):(r=i)&&"function"==typeof r.send?i:void 0;var r;if(o)if("machine"in o){if(this.status!==Xt.Stopped||this.parent!==o||this.state.done){const e=Object.assign(Object.assign({},t),{name:t.name===v?""+yt(this.id):t.name,origin:this.sessionId});!n&&this.machine.config.predictableActionArguments?this._outgoingQueue.push([o,e]):o.send(e)}}else!n&&this.machine.config.predictableActionArguments?this._outgoingQueue.push([o,t.data]):o.send(t.data);else if(!s)throw new Error(`Unable to send event to child '${i}' from service '${this.id}'.`)},this._exec=(e,s,a,c=this.machine.options.actions)=>{const h=e.exec||Z(e.type,c),d=M(h)?h:h?h.exec:e.exec;if(d)try{return d(s,a.data,this.machine.config.predictableActionArguments?{action:e,_event:a}:{action:e,state:this.state,_event:a})}catch(t){throw this.parent&&this.parent.send({type:"xstate.error",data:t}),t}switch(e.type){case o:const c=e;if("number"==typeof c.delay)return void this.defer(c);c.to?this.sendTo(c._event,c.to,a===Y):this.send(c._event);break;case r:this.cancel(e.sendId);break;case i:{if(this.status!==Xt.Running)return;const i=e.activity;if(!this.machine.config.predictableActionArguments&&!this.state.activities[i.id||i.type])break;if(i.type===t.Invoke){const t=G(i.src),e=this.machine.options.services?this.machine.options.services[t.type]:void 0,{id:n,data:o}=i,r="autoForward"in i?i.autoForward:!!i.forward;if(!e)return;const c=o?C(o,s,a):void 0;if("string"==typeof e)return;let h,d=M(e)?e(s,a.data,{data:c,src:t,meta:i.meta}):e;if(!d)return;F(d)&&(d=c?d.withContext(c):d,h={autoForward:r}),this.spawn(d,n,h)}else this.spawnActivity(i);break}case n:this.stopChild(e.activity.id);break;case u:const{label:h,value:d}=e;h?this.logger(h,d):this.logger(d)}};const c=Object.assign(Object.assign({},Ht.defaultOptions),a),{clock:h,logger:d,parent:l,id:f}=c,p=void 0!==f?f:s.id;this.id=p,this.logger=d,this.clock=h,this.parent=l,this.options=c,this.scheduler=new Mt({deferEvents:this.options.deferEvents}),this.sessionId=Bt.bookId()}get initialState(){return this._initialState?this._initialState:Ot(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.machine.config.predictableActionArguments&&e!==Y||!this.options.execute){let t;for(;t=this._outgoingQueue.shift();)t[0].send(t[1])}else this.execute(this.state);if(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);if(this.state.done){const i=t.configuration.find(t=>"final"===t.type&&t.parent===this.machine),n=i&&i.doneData?C(i.doneData,t.context,e):void 0;for(const t of this.doneListeners)t(vt(this.id,n));this._stop(),this._stopChildren()}}onTransition(t){return this.listeners.add(t),this.status===Xt.Running&&t(this.state,this.state.event),this}subscribe(t,e,i){const n=K(t,e,i);this.listeners.add(n.next),this.status!==Xt.NotStarted&&n.next(this.state);const s=()=>{this.doneListeners.delete(s),this.stopListeners.delete(s),n.complete()};return this.status===Xt.Stopped?n.complete():(this.onDone(s),this.onStop(s)),{unsubscribe:()=>{this.listeners.delete(n.next),this.doneListeners.delete(s),this.stopListeners.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===Xt.Running)return this;this.machine._init(),Bt.register(this.sessionId,this),this.initialized=!0,this.status=Xt.Running;const e=void 0===t?this.initialState:Ot(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,Y)}),this}_stopChildren(){this.children.forEach(t=>{M(t.stop)&&t.stop()}),this.children.clear()}_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.initialized=!1,this.status=Xt.Stopped,this._initialState=void 0;for(const t of Object.keys(this.delayedEventsMap))this.clock.clearTimeout(this.delayedEventsMap[t]);this.scheduler.clear(),this.scheduler=new Mt({deferEvents:this.options.deferEvents})}stop(){const t=this.scheduler;return this._stop(),t.schedule(()=>{const t=Q({type:"xstate.stop"}),i=Ot(this,()=>{const i=$([...this.state.configuration].sort((t,e)=>e.order-t.order).map(t=>et(t.onExit,this.machine.options.actions))),[n,r]=mt(this.machine,this.state,this.state.context,t,[{type:"exit",actions:i}],this.machine.config.predictableActionArguments?this._exec:void 0,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),a=new Dt({value:this.state.value,context:r,_event:t,_sessionid:this.sessionId,historyValue:void 0,history:this.state,actions:n.filter(t=>t.type!==s&&(t.type!==o||!!t.to&&t.to!==e.Internal)),activities:{},events:[],configuration:[],transitions:[],children:{},done:this.state.done,tags:this.state.tags,machine:this.machine});return a.changed=!0,a});this.update(i,t),this._stopChildren(),Bt.free(this.sessionId)}),this}batch(t){if(this.status===Xt.NotStarted&&this.options.deferEvents);else if(this.status!==Xt.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.`);if(!t.length)return;const e=!!this.machine.config.predictableActionArguments&&this._exec;this.scheduler.schedule(()=>{let i=this.state,n=!1;const s=[];for(const o of t){const t=Q(o);this.forward(t),i=Ot(this,()=>this.machine.transition(i,t,void 0,e||void 0)),s.push(...this.machine.config.predictableActionArguments?i.actions:i.actions.map(t=>Lt(t,i))),n=n||!!i.changed}i.changed=n,i.actions=s,this.update(i,Q(t[t.length-1]))})}sender(t){return this.send.bind(this,t)}_nextState(t,e=!!this.machine.config.predictableActionArguments&&this._exec){const i=Q(t);if(0===i.name.indexOf(g)&&!this.state.nextEvents.some(t=>0===t.indexOf(g)))throw i.data.data;return Ot(this,()=>this.machine.transition(this.state,i,void 0,e||void 0))}nextState(t){return this._nextState(t,!1)}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,!0):this.send(t._event)},t.delay)}cancel(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]}exec(t,e,i=this.machine.options.actions){this._exec(t,e.context,e._event,i)}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),M(e.stop)&&e.stop())}spawn(t,e,i){if(this.status!==Xt.Running)return _t(t,e);if(V(t))return this.spawnPromise(Promise.resolve(t),e);if(M(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&&M(t.subscribe)}catch(t){return!1}}(t))return this.spawnObservable(t,e);if(F(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 Ht(t,Object.assign(Object.assign({},this.options),{parent:this,id:e.id||t.id})),n=Object.assign(Object.assign({},Qt),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(Q(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(Q(vt(e,t),{origin:e})))},t=>{if(!n){this.removeChild(e);const i=yt(e,t);try{this.send(Q(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=K(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(Q(t,{origin:e}))};let a;try{a=t(r,t=>{n.add(t)})}catch(t){this.send(yt(e,t))}if(V(a))return this.spawnPromise(a,e);const c={id:e,send:t=>n.forEach(e=>e(t)),subscribe:t=>{const e=K(t);return s.add(e.next),{unsubscribe:()=>{s.delete(e.next)}}},stop:()=>{i=!0,M(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(Q(t,{origin:e}))},t=>{this.removeChild(e),this.send(Q(yt(e,t),{origin:e}))},()=>{this.removeChild(e),this.send(Q(vt(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=Ft();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===Xt.NotStarted?this.initialState:this._state}}Ht.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:(t,e)=>setTimeout(t,e),clearTimeout:t=>clearTimeout(t)},logger:console.log.bind(console),devTools:!1},Ht.interpret=Kt;function Gt(t,e){const i=(t=>z(t)?Object.assign(Object.assign({},Qt),{name:t}):Object.assign(Object.assign(Object.assign({},Qt),{name:J()}),t))(e);return(e=>e?e.spawn(t,i.name,i):_t(t,i.name))(St[St.length-1])}function Kt(t,e){return new Ht(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=jt(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 kt(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=P(this.config.entry||this.config.onEntry).map(t=>tt(t)),this.onExit=P(this.config.exit||this.config.onExit).map(t=>tt(t)),this.meta=this.config.meta,this.doneData="final"===this.type?this.config.data:void 0,this.invoke=P(this.config.invoke).map((t,e)=>{if(F(t)){const i=W(this.id,e);return this.machine.options.services=Object.assign({[i]:t},this.machine.options.services),Yt({src:i,id:i})}if(z(t.src)){const i=t.id||W(this.id,e);return Yt(Object.assign(Object.assign({},t),{id:i,src:t.src}))}if(F(t.src)||M(t.src)){const i=t.id||W(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:W(this.id,e)},t),{src:i}))}}),this.activities=P(this.config.activities).concat(this.invoke).map(t=>it(t)),this.transition=this.transition.bind(this),this.tags=P(this.config.tags)}_init(){this.__cache.transitions||Tt(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 M(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=pt(M(t)?`${this.id}:delay[${e}]`:t,this.id);return this.onEntry.push(ot(i,{delay:t})),this.onExit.push(dt(i)),i};return(R(t)?t.map((t,i)=>{const n=e(t.delay,i);return Object.assign(Object.assign({},t),{event:n})}):$(Object.keys(t).map((i,n)=>{const s=t[i],o=z(s)?{target:s}:s,r=isNaN(+i)?i:+i,a=e(r,n);return P(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:j(t,this.delimiter);if(z(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(...$(i.map(t=>this.getStateNode(t).getStateNodes(e[t])))),n}handles(t){const e=_(t);return this.events.includes(e)}resolveState(t){const e=t instanceof Dt?t:Dt.create(t),i=Array.from(At([],this.getStateNodes(e.value)));return new Dt(Object.assign(Object.assign({},e),{value:this.resolve(e.value),configuration:i,done:Ct(i,this),tags:Vt(i),machine:this.machine}))}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=$(s.map(t=>t.transitions));if(!s.some(t=>t.transitions.length>0))return this.next(e,i);const r=$(Object.keys(n).map(t=>n[t].configuration));return{transitions:o,exitSet:$(s.map(t=>t.exitSet)),configuration:r,source:e,actions:$(Object.keys(n).map(t=>n[t].actions))}}_transition(t,e,i){return z(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,Q(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,d=!c||(z(c)&&te(c)?t.matches(j(this.getStateNodeById(c).path,this.delimiter)):x(j(c,this.delimiter),T(this.path.slice(0,-2))(t.value)));let u=!1;try{u=!a||H(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(u&&d){void 0!==r.target&&(o=r.target),n.push(...r.actions),s=r;break}}if(!s)return;if(!o.length)return{transitions:[s],exitSet:[],configuration:t.value?[this]:[],source:t,actions:n};const r=$(o.map(e=>this.getRelativeStateNodes(e,t.historyValue)));return{transitions:[s],exitSet:!!s.internal?[]:$(o.map(t=>this.getPotentiallyReenteringNodes(t))),configuration:r,source:t,actions:n}}getPotentiallyReenteringNodes(t){if(this.order<t.order)return[this];const e=[];let i=this,n=t;for(;i&&i!==n;)e.push(i),i=i.parent;return i!==n?[]:(e.push(n),e)}getActions(t,i,n,r,a,c,h){const d=c?At([],this.getStateNodes(c.value)):[],u=new Set;for(const e of Array.from(t).sort((t,e)=>t.order-e.order))(!Pt(d,e)||Pt(n.exitSet,e)||e.parent&&u.has(e.parent))&&u.add(e);for(const e of d)Pt(t,e)&&!Pt(n.exitSet,e.parent)||n.exitSet.push(e);n.exitSet.sort((t,e)=>e.order-t.order);const l=Array.from(u).sort((t,e)=>t.order-e.order),f=new Set(n.exitSet),p=$(l.map(t=>{const e=[];if("final"!==t.type)return e;const i=t.parent;if(!i.parent)return e;e.push(gt(t.id,t.doneData),gt(i.id,t.doneData?C(t.doneData,r,a):void 0));const s=i.parent;return"parallel"===s.type&&Nt(s).every(t=>Ct(n.configuration,t))&&e.push(gt(s.id)),e})),g=l.map(t=>{const e=t.onEntry,i=t.activities.map(t=>ut(t));return{type:"entry",actions:et(h?[...e,...i]:[...i,...e],this.machine.options.actions)}}).concat({type:"state_done",actions:p.map(nt)}),v=Array.from(f).map(t=>({type:"exit",actions:et([...t.onExit,...t.activities.map(t=>lt(t))],this.machine.options.actions)})).concat({type:"transition",actions:et(n.actions,this.machine.options.actions)}).concat(g);if(i){const i=et($([...t].sort((t,e)=>e.order-t.order).map(t=>t.onExit)),this.machine.options.actions).filter(t=>t.type!==s&&(t.type!==o||!!t.to&&t.to!==e.Internal));return v.concat({type:"stop",actions:i})}return v}transition(t=this.initialState,e,i,n){const s=Q(e);let o;if(t instanceof Dt)o=void 0===i?t:this.resolveState(Dt.from(t,i));else{const e=z(t)?this.resolve(E(this.getResolvedPath(t))):this.resolve(t),n=null!=i?i:this.machine.context;o=this.resolveState(Dt.from(e,n))}if(this.strict&&!this.events.includes(s.name)&&(r=s.name,!/^(done|error)\./.test(r)))throw new Error(`Machine '${this.id}' does not accept event '${s.name}'`);var r;const a=this._transition(o.value,o,s)||{transitions:[],configuration:[],exitSet:[],source:o,actions:[]},c=At([],this.getStateNodes(o.value)),h=a.configuration.length?At(c,a.configuration):c;return a.configuration=[...h],this.resolveTransition(a,o,o.context,n,s)}resolveRaisedTransition(t,e,i,n){const s=t.actions;return(t=this.transition(t,e,void 0,n))._event=i,t.event=i.data,t.actions.unshift(...s),t}resolveTransition(t,r,c,h,d=Y){const{configuration:u}=t,l=!r||t.transitions.length>0,p=l?t.configuration:r?r.configuration:[],g=Ct(p,this),v=l?It(this.machine,u):void 0,m=r?r.historyValue?r.historyValue:t.source?this.machine.historyValue(r.value):void 0:void 0,b=this.getActions(new Set(p),g,t,c,d,r,h),S=r?Object.assign({},r.activities):{};for(const t of b)for(const e of t.actions)e.type===i?S[e.activity.id||e.activity.type]=e:e.type===n&&(S[e.activity.id||e.activity.type]=!1);const[O,x]=mt(this,r,c,d,b,h,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),[_,w]=function(t,e){const[i,n]=[[],[]];for(const s of t)e(s)?i.push(s):n.push(s);return[i,n]}(O,t=>t.type===s||t.type===o&&t.to===e.Internal),j=O.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=G(t.src),r=null===(s=null==e?void 0:e.options.services)||void 0===s?void 0:s[o.type],a=t.data?C(t.data,i,n):void 0,c=r?_t(r,t.id,a):xt(t.id);return c.meta=t,c}(e.activity,this.machine,x,d),t),r?Object.assign({},r.children):{}),E=new Dt({value:v||r.value,context:x,_event:d,_sessionid:r?r._sessionid:null,historyValue:v?m?(k=m,N=v,{current:N,states:L(k,N)}):void 0:r?r.historyValue:void 0,history:!v||t.source?r:void 0,actions:v?w:[],activities:v?S:r?r.activities:{},events:[],configuration:p,transitions:t.transitions,children:j,done:g,tags:Vt(p),machine:this});var k,N;const T=c!==x;E.changed=d.name===y||T;const{history:A}=E;A&&delete A.history;const $=!g&&(this._transient||u.some(t=>t._transient));if(!(l||$&&""!==d.name))return E;let I=E;if(!g)for($&&(I=this.resolveRaisedTransition(I,{type:a},d,h));_.length;){const t=_.shift();I=this.resolveRaisedTransition(I,t._event,d,h)}const P=I.changed||(A?!!I.actions.length||T||typeof A.value!=typeof I.value||!function t(e,i){if(e===i)return!0;if(void 0===e||void 0===i)return!1;if(z(e)||z(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]))}(I.value,A.value):void 0);return I.changed=P,I.history=A,I}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=w(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(z(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 w(t,this.delimiter)}get initialStateValue(){if(this.__cache.initialStateValue)return this.__cache.initialStateValue;let t;if("parallel"===this.type)t=N(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=Et(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,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=z(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(Et(this))return[this];if("compound"===this.type&&!this.initial)return[this];return $(A(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:N(this.states,(e,i)=>{if(!t)return e.historyValue();const n=z(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?$(A(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 z(i)?[e.getStateNode(i)]:$(A(i).map(t=>"deep"===this.history?e.getFromRelativePath(t):[e.states[t[0]]]))}get stateIds(){const t=$(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(!z(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 P(t)}(t.target),i="internal"in t?t.internal:!e||e.some(t=>z(t)&&t[0]===this.delimiter),{guards:n}=this.machine.options,s=this.resolveTarget(e),o=Object.assign(Object.assign({},t),{actions:et(P(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=jt(e,[i+""]);t=$(Object.keys(o).map(t=>X(t,o[t])).concat(X("*",s)))}else t=[];const e=this.config.always?X("",this.config.always):[],i=this.config.onDone?X(String(gt(this.id)),this.config.onDone):[],n=$(this.invoke.map(t=>{const e=[];return t.onDone&&e.push(...X(String(vt(t.id)),t.onDone)),t.onError&&e.push(...X(String(yt(t.id)),t.onError)),e})),s=this.after,o=$([...i,...n,...t,...e].map(t=>P(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))x(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,sendTo:de,sendParent:ue,sendUpdate:le,forwardTo:fe,doneInvoke:pe,raise:ge}=bt;export{t as ActionTypes,Ht as Interpreter,Xt as InterpreterStatus,ie as Machine,e as SpecialTargets,Dt as State,ee as StateNode,bt as actions,ce as assign,ne as createMachine,re as createSchema,pe as doneInvoke,fe as forwardTo,Kt as interpret,se as mapState,oe as matchState,x as matchesState,ge as raise,he as send,ue as sendParent,de as sendTo,le as sendUpdate,Gt as spawn,qt as spawnBehavior,ae as t,wt as toActorRef,q as toEventObject,K as toObserver,Q as toSCXMLEvent};
package/es/Machine.js CHANGED
@@ -10,7 +10,7 @@ function Machine(config, options, initialContext) {
10
10
  return new StateNode(config, options, initialContext);
11
11
  }
12
12
  function createMachine(config, options) {
13
- if (!IS_PRODUCTION && !config.predictableActionArguments && !warned) {
13
+ if (!IS_PRODUCTION && !('predictableActionArguments' in config) && !warned) {
14
14
  warned = true;
15
15
  console.warn('It is highly recommended to set `predictableActionArguments` to `true` when using `createMachine`. https://xstate.js.org/docs/guides/actions.html');
16
16
  }
package/es/StateNode.d.ts CHANGED
@@ -189,7 +189,7 @@ declare class StateNode<TContext = any, TStateSchema extends StateSchema = any,
189
189
  private _transition;
190
190
  getTransitionData(state: State<TContext, TEvent, any, any, any>, event: Event<TEvent> | SCXML.Event<TEvent>): StateTransition<TContext, TEvent> | undefined;
191
191
  private next;
192
- private getExternalReentryNodes;
192
+ private getPotentiallyReenteringNodes;
193
193
  private getActions;
194
194
  /**
195
195
  * Determines the next state given the current `state` and sent `event`.
package/es/StateNode.js CHANGED
@@ -520,15 +520,11 @@ function () {
520
520
  return this.next(state, _event);
521
521
  }
522
522
 
523
- var entryNodes = flatten(stateTransitions.map(function (t) {
524
- return t.entrySet;
525
- }));
526
523
  var configuration = flatten(Object.keys(transitionMap).map(function (key) {
527
524
  return transitionMap[key].configuration;
528
525
  }));
529
526
  return {
530
527
  transitions: enabledTransitions,
531
- entrySet: entryNodes,
532
528
  exitSet: flatten(stateTransitions.map(function (t) {
533
529
  return t.exitSet;
534
530
  })),
@@ -615,7 +611,6 @@ function () {
615
611
  if (!nextStateNodes.length) {
616
612
  return {
617
613
  transitions: [selectedTransition],
618
- entrySet: [],
619
614
  exitSet: [],
620
615
  configuration: state.value ? [this] : [],
621
616
  source: state,
@@ -627,30 +622,28 @@ function () {
627
622
  return _this.getRelativeStateNodes(stateNode, state.historyValue);
628
623
  }));
629
624
  var isInternal = !!selectedTransition.internal;
630
- var reentryNodes = [];
631
-
632
- if (!isInternal) {
633
- nextStateNodes.forEach(function (targetNode) {
634
- reentryNodes.push.apply(reentryNodes, __spreadArray([], __read(_this.getExternalReentryNodes(targetNode)), false));
635
- });
636
- }
637
-
638
625
  return {
639
626
  transitions: [selectedTransition],
640
- entrySet: reentryNodes,
641
- exitSet: isInternal ? [] : [this],
627
+ exitSet: isInternal ? [] : flatten(nextStateNodes.map(function (targetNode) {
628
+ return _this.getPotentiallyReenteringNodes(targetNode);
629
+ })),
642
630
  configuration: allNextStateNodes,
643
631
  source: state,
644
632
  actions: actions
645
633
  };
646
- };
634
+ }; // even though the name of this function mentions reentry nodes
635
+ // we are pushing its result into `exitSet`
636
+ // that's because what we exit might be reentered (it's an invariant of reentrancy)
647
637
 
648
- StateNode.prototype.getExternalReentryNodes = function (targetNode) {
649
- var nodes = [];
650
638
 
651
- var _a = __read(targetNode.order > this.order ? [targetNode, this] : [this, targetNode], 2),
652
- marker = _a[0],
653
- possibleAncestor = _a[1];
639
+ StateNode.prototype.getPotentiallyReenteringNodes = function (targetNode) {
640
+ if (this.order < targetNode.order) {
641
+ return [this];
642
+ }
643
+
644
+ var nodes = [];
645
+ var marker = this;
646
+ var possibleAncestor = targetNode;
654
647
 
655
648
  while (marker && marker !== possibleAncestor) {
656
649
  nodes.push(marker);
@@ -672,14 +665,17 @@ function () {
672
665
 
673
666
  var _this = this;
674
667
 
675
- var prevConfig = getConfiguration([], prevState ? this.getStateNodes(prevState.value) : [this]);
668
+ var prevConfig = prevState ? getConfiguration([], this.getStateNodes(prevState.value)) : [];
669
+ var entrySet = new Set();
676
670
 
677
671
  try {
678
- for (var resolvedConfig_1 = __values(resolvedConfig), resolvedConfig_1_1 = resolvedConfig_1.next(); !resolvedConfig_1_1.done; resolvedConfig_1_1 = resolvedConfig_1.next()) {
679
- var sn = resolvedConfig_1_1.value;
672
+ for (var _c = __values(Array.from(resolvedConfig).sort(function (a, b) {
673
+ return a.order - b.order;
674
+ })), _d = _c.next(); !_d.done; _d = _c.next()) {
675
+ var sn = _d.value;
680
676
 
681
- if (!has(prevConfig, sn) || has(transition.entrySet, sn.parent) && !has(transition.entrySet, sn)) {
682
- transition.entrySet.push(sn);
677
+ if (!has(prevConfig, sn) || has(transition.exitSet, sn) || sn.parent && entrySet.has(sn.parent)) {
678
+ entrySet.add(sn);
683
679
  }
684
680
  }
685
681
  } catch (e_4_1) {
@@ -688,7 +684,7 @@ function () {
688
684
  };
689
685
  } finally {
690
686
  try {
691
- if (resolvedConfig_1_1 && !resolvedConfig_1_1.done && (_a = resolvedConfig_1.return)) _a.call(resolvedConfig_1);
687
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
692
688
  } finally {
693
689
  if (e_4) throw e_4.error;
694
690
  }
@@ -714,7 +710,14 @@ function () {
714
710
  }
715
711
  }
716
712
 
717
- var doneEvents = flatten(transition.entrySet.map(function (sn) {
713
+ transition.exitSet.sort(function (a, b) {
714
+ return b.order - a.order;
715
+ });
716
+ var entryStates = Array.from(entrySet).sort(function (a, b) {
717
+ return a.order - b.order;
718
+ });
719
+ var exitStates = new Set(transition.exitSet);
720
+ var doneEvents = flatten(entryStates.map(function (sn) {
718
721
  var events = [];
719
722
 
720
723
  if (sn.type !== 'final') {
@@ -741,27 +744,31 @@ function () {
741
744
 
742
745
  return events;
743
746
  }));
744
- transition.exitSet.sort(function (a, b) {
745
- return b.order - a.order;
746
- });
747
- transition.entrySet.sort(function (a, b) {
748
- return a.order - b.order;
749
- });
750
- var entryStates = new Set(transition.entrySet);
751
- var exitStates = new Set(transition.exitSet);
752
- var entryActions = Array.from(entryStates).map(function (stateNode) {
747
+ var entryActions = entryStates.map(function (stateNode) {
753
748
  var entryActions = stateNode.onEntry;
754
749
  var invokeActions = stateNode.activities.map(function (activity) {
755
750
  return start(activity);
756
751
  });
757
- return toActionObjects(predictableExec ? __spreadArray(__spreadArray([], __read(entryActions), false), __read(invokeActions), false) : __spreadArray(__spreadArray([], __read(invokeActions), false), __read(entryActions), false), _this.machine.options.actions);
758
- }).concat([doneEvents.map(raise)]);
752
+ return {
753
+ type: 'entry',
754
+ actions: toActionObjects(predictableExec ? __spreadArray(__spreadArray([], __read(entryActions), false), __read(invokeActions), false) : __spreadArray(__spreadArray([], __read(invokeActions), false), __read(entryActions), false), _this.machine.options.actions)
755
+ };
756
+ }).concat({
757
+ type: 'state_done',
758
+ actions: doneEvents.map(raise)
759
+ });
759
760
  var exitActions = Array.from(exitStates).map(function (stateNode) {
760
- return toActionObjects(__spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
761
- return stop(activity);
762
- })), false), _this.machine.options.actions);
761
+ return {
762
+ type: 'exit',
763
+ actions: toActionObjects(__spreadArray(__spreadArray([], __read(stateNode.onExit), false), __read(stateNode.activities.map(function (activity) {
764
+ return stop(activity);
765
+ })), false), _this.machine.options.actions)
766
+ };
763
767
  });
764
- var actions = exitActions.concat([toActionObjects(transition.actions, this.machine.options.actions)]).concat(entryActions);
768
+ var actions = exitActions.concat({
769
+ type: 'transition',
770
+ actions: toActionObjects(transition.actions, this.machine.options.actions)
771
+ }).concat(entryActions);
765
772
 
766
773
  if (isDone) {
767
774
  var stopActions = toActionObjects(flatten(__spreadArray([], __read(resolvedConfig), false).sort(function (a, b) {
@@ -771,7 +778,10 @@ function () {
771
778
  })), this.machine.options.actions).filter(function (action) {
772
779
  return action.type !== raise$1 && (action.type !== send || !!action.to && action.to !== SpecialTargets.Internal);
773
780
  });
774
- return actions.concat([stopActions]);
781
+ return actions.concat({
782
+ type: 'stop',
783
+ actions: stopActions
784
+ });
775
785
  }
776
786
 
777
787
  return actions;
@@ -815,7 +825,6 @@ function () {
815
825
  var stateTransition = this._transition(currentState.value, currentState, _event) || {
816
826
  transitions: [],
817
827
  configuration: [],
818
- entrySet: [],
819
828
  exitSet: [],
820
829
  source: currentState,
821
830
  actions: []
@@ -867,8 +876,8 @@ function () {
867
876
  var block = actionBlocks_1_1.value;
868
877
 
869
878
  try {
870
- for (var block_1 = (e_7 = void 0, __values(block)), block_1_1 = block_1.next(); !block_1_1.done; block_1_1 = block_1.next()) {
871
- var action = block_1_1.value;
879
+ for (var _c = (e_7 = void 0, __values(block.actions)), _d = _c.next(); !_d.done; _d = _c.next()) {
880
+ var action = _d.value;
872
881
 
873
882
  if (action.type === start$1) {
874
883
  activities[action.activity.id || action.activity.type] = action;
@@ -882,7 +891,7 @@ function () {
882
891
  };
883
892
  } finally {
884
893
  try {
885
- if (block_1_1 && !block_1_1.done && (_b = block_1.return)) _b.call(block_1);
894
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
886
895
  } finally {
887
896
  if (e_7) throw e_7.error;
888
897
  }
@@ -900,15 +909,15 @@ function () {
900
909
  }
901
910
  }
902
911
 
903
- var _c = __read(resolveActions(this, currentState, context, _event, actionBlocks, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
904
- resolvedActions = _c[0],
905
- updatedContext = _c[1];
912
+ var _e = __read(resolveActions(this, currentState, context, _event, actionBlocks, predictableExec, this.machine.config.predictableActionArguments || this.machine.config.preserveActionOrder), 2),
913
+ resolvedActions = _e[0],
914
+ updatedContext = _e[1];
906
915
 
907
- var _d = __read(partition(resolvedActions, function (action) {
916
+ var _f = __read(partition(resolvedActions, function (action) {
908
917
  return action.type === raise$1 || action.type === send && action.to === SpecialTargets.Internal;
909
918
  }), 2),
910
- raisedEvents = _d[0],
911
- nonRaisedActions = _d[1];
919
+ raisedEvents = _f[0],
920
+ nonRaisedActions = _f[1];
912
921
 
913
922
  var invokeActions = resolvedActions.filter(function (action) {
914
923
  var _a;
@@ -1161,7 +1170,6 @@ function () {
1161
1170
  var configuration = this.getStateNodes(stateValue);
1162
1171
  return this.resolveTransition({
1163
1172
  configuration: configuration,
1164
- entrySet: configuration,
1165
1173
  exitSet: [],
1166
1174
  transitions: [],
1167
1175
  source: undefined,
package/es/actions.d.ts CHANGED
@@ -133,7 +133,7 @@ export declare function done(id: string, data?: any): DoneEventObject;
133
133
  */
134
134
  export declare function doneInvoke(id: string, data?: any): DoneEvent;
135
135
  export declare function error(id: string, data?: any): ErrorPlatformEvent & string;
136
- export declare function pure<TContext, TEvent extends EventObject>(getActions: (context: TContext, event: TEvent) => SingleOrArray<ActionObject<TContext, TEvent>> | undefined): PureAction<TContext, TEvent>;
136
+ export declare function pure<TContext, TEvent extends EventObject>(getActions: (context: TContext, event: TEvent) => SingleOrArray<ActionObject<TContext, TEvent> | ActionObject<TContext, TEvent>['type']> | undefined): PureAction<TContext, TEvent>;
137
137
  /**
138
138
  * Forwards (sends) an event to a specified service.
139
139
  *
@@ -150,5 +150,8 @@ export declare function forwardTo<TContext, TEvent extends EventObject>(target:
150
150
  */
151
151
  export declare function escalate<TContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionOptions<TContext, TEvent>): SendAction<TContext, TEvent, AnyEventObject>;
152
152
  export declare function choose<TContext, TEvent extends EventObject>(conds: Array<ChooseCondition<TContext, TEvent>>): ChooseAction<TContext, TEvent>;
153
- export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent, any, any, any> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actionBlocks: Array<Array<ActionObject<TContext, TEvent>>>, predictableExec?: PredictableActionArgumentsExec, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
153
+ export declare function resolveActions<TContext, TEvent extends EventObject>(machine: StateNode<TContext, any, TEvent, any, any, any>, currentState: State<TContext, TEvent, any, any, any> | undefined, currentContext: TContext, _event: SCXML.Event<TEvent>, actionBlocks: Array<{
154
+ type: string;
155
+ actions: Array<ActionObject<TContext, TEvent>>;
156
+ }>, predictableExec?: PredictableActionArgumentsExec, preserveActionOrder?: boolean): [Array<ActionObject<TContext, TEvent>>, TContext];
154
157
  //# sourceMappingURL=actions.d.ts.map
package/es/actions.js CHANGED
@@ -437,10 +437,10 @@ var pluckAssigns = function (actionBlocks) {
437
437
  var block = actionBlocks_1_1.value;
438
438
  var i = 0;
439
439
 
440
- while (i < block.length) {
441
- if (block[i].type === assign$1) {
442
- assignActions.push(block[i]);
443
- block.splice(i, 1);
440
+ while (i < block.actions.length) {
441
+ if (block.actions[i].type === assign$1) {
442
+ assignActions.push(block.actions[i]);
443
+ block.actions.splice(i, 1);
444
444
  continue;
445
445
  }
446
446
 
@@ -472,7 +472,7 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
472
472
  var preservedContexts = preserveActionOrder ? [currentContext] : undefined;
473
473
  var deferredToBlockEnd = [];
474
474
 
475
- function handleAction(actionObject) {
475
+ function handleAction(blockType, actionObject) {
476
476
  var _a;
477
477
 
478
478
  switch (actionObject.type) {
@@ -491,7 +491,11 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
491
491
  }
492
492
 
493
493
  if (predictableExec && sendAction.to !== SpecialTargets.Internal) {
494
- deferredToBlockEnd.push(sendAction);
494
+ if (blockType === 'entry') {
495
+ deferredToBlockEnd.push(sendAction);
496
+ } else {
497
+ predictableExec === null || predictableExec === void 0 ? void 0 : predictableExec(sendAction, updatedContext, _event);
498
+ }
495
499
  }
496
500
 
497
501
  return sendAction;
@@ -515,7 +519,10 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
515
519
  return [];
516
520
  }
517
521
 
518
- var _b = __read(resolveActions(machine, currentState, updatedContext, _event, [toActionObjects(toArray(matchedActions), machine.options.actions)], predictableExec, preserveActionOrder), 2),
522
+ var _b = __read(resolveActions(machine, currentState, updatedContext, _event, [{
523
+ type: blockType,
524
+ actions: toActionObjects(toArray(matchedActions), machine.options.actions)
525
+ }], predictableExec, preserveActionOrder), 2),
519
526
  resolvedActionsFromChoose = _b[0],
520
527
  resolvedContextFromChoose = _b[1];
521
528
 
@@ -532,7 +539,10 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
532
539
  return [];
533
540
  }
534
541
 
535
- var _c = __read(resolveActions(machine, currentState, updatedContext, _event, [toActionObjects(toArray(matchedActions), machine.options.actions)], predictableExec, preserveActionOrder), 2),
542
+ var _c = __read(resolveActions(machine, currentState, updatedContext, _event, [{
543
+ type: blockType,
544
+ actions: toActionObjects(toArray(matchedActions), machine.options.actions)
545
+ }], predictableExec, preserveActionOrder), 2),
536
546
  resolvedActionsFromPure = _c[0],
537
547
  resolvedContext = _c[1];
538
548
 
@@ -586,9 +596,9 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
586
596
  var resolvedActions = [];
587
597
 
588
598
  try {
589
- for (var block_1 = __values(block), block_1_1 = block_1.next(); !block_1_1.done; block_1_1 = block_1.next()) {
590
- var action = block_1_1.value;
591
- var resolved = handleAction(action);
599
+ for (var _b = __values(block.actions), _c = _b.next(); !_c.done; _c = _b.next()) {
600
+ var action = _c.value;
601
+ var resolved = handleAction(block.type, action);
592
602
 
593
603
  if (resolved) {
594
604
  resolvedActions = resolvedActions.concat(resolved);
@@ -600,7 +610,7 @@ function resolveActions(machine, currentState, currentContext, _event, actionBlo
600
610
  };
601
611
  } finally {
602
612
  try {
603
- if (block_1_1 && !block_1_1.done && (_a = block_1.return)) _a.call(block_1);
613
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
604
614
  } finally {
605
615
  if (e_2) throw e_2.error;
606
616
  }
package/es/interpreter.js CHANGED
@@ -801,7 +801,10 @@ function () {
801
801
  return toActionObjects(stateNode.onExit, _this.machine.options.actions);
802
802
  }));
803
803
 
804
- var _a = __read(resolveActions(_this.machine, _this.state, _this.state.context, _event, [exitActions], _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
804
+ var _a = __read(resolveActions(_this.machine, _this.state, _this.state.context, _event, [{
805
+ type: 'exit',
806
+ actions: exitActions
807
+ }], _this.machine.config.predictableActionArguments ? _this._exec : undefined, _this.machine.config.predictableActionArguments || _this.machine.config.preserveActionOrder), 2),
805
808
  resolvedActions = _a[0],
806
809
  updatedContext = _a[1];
807
810
 
package/es/model.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import type { Cast, EventObject, BaseActionObject, Prop, IsNever } from './types';
2
2
  import { UnionFromCreatorsReturnTypes, FinalModelCreators, Model, ModelCreators } from './model.types';
3
+ /**
4
+ * @deprecated Use [Typegen](https://stately.ai/blog/introducing-typescript-typegen-for-xstate) instead.
5
+ */
3
6
  export declare function createModel<TContext, TEvent extends EventObject, TAction extends BaseActionObject = BaseActionObject>(initialContext: TContext): Model<TContext, TEvent, TAction, void>;
4
7
  export declare function createModel<TContext, TModelCreators extends ModelCreators<TModelCreators>, TFinalModelCreators = FinalModelCreators<TModelCreators>, TComputedEvent = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'events'>>, TComputedAction = UnionFromCreatorsReturnTypes<Prop<TFinalModelCreators, 'actions'>>>(initialContext: TContext, creators: TModelCreators): Model<TContext, Cast<TComputedEvent, EventObject>, IsNever<TComputedAction> extends true ? BaseActionObject : Cast<TComputedAction, BaseActionObject>, TFinalModelCreators>;
5
8
  //# sourceMappingURL=model.d.ts.map