/*! *****************************************************************************
Copyright (c) Microsoft Corporation.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var g=function(){return g=Object.assign||function(t){for(var r,n=1,a=arguments.length;n<a;n++){r=arguments[n];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t},g.apply(this,arguments)};function we(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,n=Object.getOwnPropertySymbols(e);a<n.length;a++)t.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(r[n[a]]=e[n[a]]);return r}function D(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function M(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var n=r.call(e),a,i=[],o;try{for(;(t===void 0||t-- >0)&&!(a=n.next()).done;)i.push(a.value)}catch(f){o={error:f}}finally{try{a&&!a.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return i}function K(e,t,r){if(r||arguments.length===2)for(var n=0,a=t.length,i;n<a;n++)(i||!(n in t))&&(i||(i=Array.prototype.slice.call(t,0,n)),i[n]=t[n]);return e.concat(i||Array.prototype.slice.call(t))}var J;(function(e){e.Start="xstate.start",e.Stop="xstate.stop",e.Raise="xstate.raise",e.Send="xstate.send",e.Cancel="xstate.cancel",e.NullEvent="",e.Assign="xstate.assign",e.After="xstate.after",e.DoneState="done.state",e.DoneInvoke="done.invoke",e.Log="xstate.log",e.Init="xstate.init",e.Invoke="xstate.invoke",e.ErrorExecution="error.execution",e.ErrorCommunication="error.communication",e.ErrorPlatform="error.platform",e.ErrorCustom="xstate.error",e.Update="xstate.update",e.Pure="xstate.pure",e.Choose="xstate.choose"})(J||(J={}));var Et;(function(e){e.Parent="#_parent",e.Internal="#_internal"})(Et||(Et={}));var fe=J.Start,be=J.Stop,Dt=J.Raise,Ht=J.Send,Me=J.Cancel,mr=J.NullEvent,Ee=J.Assign;J.After;J.DoneState;var ke=J.Log,Sr=J.Init,ce=J.Invoke;J.ErrorExecution;var Ne=J.ErrorPlatform,wr=J.ErrorCustom,Ge=J.Update,br=J.Choose,Er=J.Pure,Ye=".",$e={},le="xstate.guard",xr="",kt;function xe(e,t,r){r===void 0&&(r=Ye);var n=$t(e,r),a=$t(t,r);return z(a)?z(n)?a===n:!1:z(n)?n in a:Object.keys(n).every(function(i){return i in a?xe(n[i],a[i]):!1})}function ze(e){try{return z(e)||typeof e=="number"?"".concat(e):e.type}catch{throw new Error("Events must be strings or objects with a string event.type property.")}}function de(e,t){try{return Tt(e)?e:e.toString().split(t)}catch{throw new Error("'".concat(e,"' is not a valid state path."))}}function Tr(e){return typeof e=="object"&&"value"in e&&"context"in e&&"event"in e&&"_event"in e}function $t(e,t){if(Tr(e))return e.value;if(Tt(e))return Qt(e);if(typeof e!="string")return e;var r=de(e,t);return Qt(r)}function Qt(e){if(e.length===1)return e[0];for(var t={},r=t,n=0;n<e.length-1;n++)n===e.length-2?r[e[n]]=e[n+1]:(r[e[n]]={},r=r[e[n]]);return t}function jt(e,t){for(var r={},n=Object.keys(e),a=0;a<n.length;a++){var i=n[a];r[i]=t(e[i],i,e,a)}return r}function Le(e,t,r){var n,a,i={};try{for(var o=D(Object.keys(e)),f=o.next();!f.done;f=o.next()){var s=f.value,c=e[s];r(c)&&(i[s]=t(c,s,e))}}catch(l){n={error:l}}finally{try{f&&!f.done&&(a=o.return)&&a.call(o)}finally{if(n)throw n.error}}return i}var Or=function(e){return function(t){var r,n,a=t;try{for(var i=D(e),o=i.next();!o.done;o=i.next()){var f=o.value;a=a[f]}}catch(s){r={error:s}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return a}};function Ar(e,t){return function(r){var n,a,i=r;try{for(var o=D(e),f=o.next();!f.done;f=o.next()){var s=f.value;i=i[t][s]}}catch(c){n={error:c}}finally{try{f&&!f.done&&(a=o.return)&&a.call(o)}finally{if(n)throw n.error}}return i}}function Xt(e){if(!e)return[[]];if(z(e))return[[e]];var t=B(Object.keys(e).map(function(r){var n=e[r];return typeof n!="string"&&(!n||!Object.keys(n).length)?[[r]]:Xt(e[r]).map(function(a){return[r].concat(a)})}));return t}function B(e){var t;return(t=[]).concat.apply(t,K([],M(e),!1))}function Je(e){return Tt(e)?e:[e]}function ct(e){return e===void 0?[]:Je(e)}function Wt(e,t,r){var n,a;if(Y(e))return e(t,r.data);var i={};try{for(var o=D(Object.keys(e)),f=o.next();!f.done;f=o.next()){var s=f.value,c=e[s];Y(c)?i[s]=c(t,r.data):i[s]=c}}catch(l){n={error:l}}finally{try{f&&!f.done&&(a=o.return)&&a.call(o)}finally{if(n)throw n.error}}return i}function _r(e){return/^(done|error)\./.test(e)}function Re(e){return!!(e instanceof Promise||e!==null&&(Y(e)||typeof e=="object")&&Y(e.then))}function jr(e){return e!==null&&typeof e=="object"&&"transition"in e&&typeof e.transition=="function"}function Pr(e,t){var r,n,a=M([[],[]],2),i=a[0],o=a[1];try{for(var f=D(e),s=f.next();!s.done;s=f.next()){var c=s.value;t(c)?i.push(c):o.push(c)}}catch(l){r={error:l}}finally{try{s&&!s.done&&(n=f.return)&&n.call(f)}finally{if(r)throw r.error}}return[i,o]}function Xe(e,t){return jt(e.states,function(r,n){if(r){var a=(z(t)?void 0:t[n])||(r?r.current:void 0);if(a)return{current:a,states:Xe(r,a)}}})}function Ir(e,t){return{current:t,states:Xe(e,t)}}function De(e,t,r,n){var a=e&&r.reduce(function(i,o){var f,s,c=o.assignment,l={state:n,action:o,_event:t},v={};if(Y(c))v=c(i,t.data,l);else try{for(var d=D(Object.keys(c)),h=d.next();!h.done;h=d.next()){var p=h.value,y=c[p];v[p]=Y(y)?y(i,t.data,l):y}}catch(T){f={error:T}}finally{try{h&&!h.done&&(s=d.return)&&s.call(d)}finally{if(f)throw f.error}}return Object.assign({},i,v)},e);return a}var Nr=function(){};function Tt(e){return Array.isArray(e)}function Y(e){return typeof e=="function"}function z(e){return typeof e=="string"}function Ve(e,t){if(e)return z(e)?{type:le,name:e,predicate:t?t[e]:void 0}:Y(e)?{type:le,name:e.name,predicate:e}:e}function $r(e){try{return"subscribe"in e&&Y(e.subscribe)}catch{return!1}}var yt=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();kt={},kt[yt]=function(){return this},kt[Symbol.observable]=function(){return this};function xt(e){return!!e&&"__xstatenode"in e}function Lr(e){return!!e&&typeof e.send=="function"}function te(e,t){return z(e)||typeof e=="number"?g({type:e},t):e}function it(e,t){if(!z(e)&&"$$type"in e&&e.$$type==="scxml")return e;var r=te(e);return g({name:r.type,data:r,$$type:"scxml",type:"external"},t)}function gt(e,t){var r=Je(t).map(function(n){return typeof n>"u"||typeof n=="string"||xt(n)?{target:n,event:e}:g(g({},n),{event:e})});return r}function Rr(e){if(!(e===void 0||e===xr))return ct(e)}function qe(e,t,r,n,a){var i=e.options.guards,o={state:a,cond:t,_event:n};if(t.type===le)return((i==null?void 0:i[t.name])||t.predicate)(r,n.data,o);var f=i==null?void 0:i[t.type];if(!f)throw new Error("Guard '".concat(t.type,"' is not implemented on machine '").concat(e.id,"'."));return f(r,n.data,o)}function Ke(e){return typeof e=="string"?{type:e}:e}function Vt(e,t,r){var n=function(){},a=typeof e=="object",i=a?e:null;return{next:((a?e.next:e)||n).bind(i),error:((a?e.error:t)||n).bind(i),complete:((a?e.complete:r)||n).bind(i)}}function Gt(e,t){return"".concat(e,":invocation[").concat(t,"]")}function ve(e){return(e.type===Dt||e.type===Ht&&e.to===Et.Internal)&&typeof e.delay!="number"}var bt=it({type:Sr});function he(e,t){return t&&t[e]||void 0}function Lt(e,t){var r;if(z(e)||typeof e=="number"){var n=he(e,t);Y(n)?r={type:e,exec:n}:n?r=n:r={type:e,exec:void 0}}else if(Y(e))r={type:e.name||e.toString(),exec:e};else{var n=he(e.type,t);if(Y(n))r=g(g({},e),{exec:n});else if(n){var a=n.type||e.type;r=g(g(g({},n),e),{type:a})}else r=e}return r}var pt=function(e,t){if(!e)return[];var r=Tt(e)?e:[e];return r.map(function(n){return Lt(n,t)})};function Te(e){var t=Lt(e);return g(g({id:z(e)?e:t.id},t),{type:t.type})}function Dr(e,t){return{type:Dt,event:typeof e=="function"?e:te(e),delay:t?t.delay:void 0,id:t==null?void 0:t.id}}function Cr(e,t,r,n){var a={_event:r},i=it(Y(e.event)?e.event(t,r.data,a):e.event),o;if(z(e.delay)){var f=n&&n[e.delay];o=Y(f)?f(t,r.data,a):f}else o=Y(e.delay)?e.delay(t,r.data,a):e.delay;return g(g({},e),{type:Dt,_event:i,delay:o})}function Qe(e,t){return{to:t?t.to:void 0,type:Ht,event:Y(e)?e:te(e),delay:t?t.delay:void 0,id:t&&t.id!==void 0?t.id:Y(e)?e.name:ze(e)}}function Fr(e,t,r,n){var a={_event:r},i=it(Y(e.event)?e.event(t,r.data,a):e.event),o;if(z(e.delay)){var f=n&&n[e.delay];o=Y(f)?f(t,r.data,a):f}else o=Y(e.delay)?e.delay(t,r.data,a):e.delay;var s=Y(e.to)?e.to(t,r.data,a):e.to;return g(g({},e),{to:s,_event:i,event:i.data,delay:o})}function Ur(e,t,r){return Qe(t,g(g({},r),{to:e}))}var Mr=function(e,t,r){return g(g({},e),{value:z(e.expr)?e.expr:e.expr(t,r.data,{_event:r})})},kr=function(e){return{type:Me,sendId:e}};function Gr(e){var t=Te(e);return{type:J.Start,activity:t,exec:void 0}}function Yr(e){var t=Y(e)?e:Te(e);return{type:J.Stop,activity:t,exec:void 0}}function zr(e,t,r){var n=Y(e.activity)?e.activity(t,r.data):e.activity,a=typeof n=="string"?{id:n}:n,i={type:J.Stop,activity:a};return i}var Jr=function(e){return{type:Ee,assignment:e}};function Xr(e,t){var r=t?"#".concat(t):"";return"".concat(J.After,"(").concat(e,")").concat(r)}function Yt(e,t){var r="".concat(J.DoneState,".").concat(e),n={type:r,data:t};return n.toString=function(){return r},n}function qt(e,t){var r="".concat(J.DoneInvoke,".").concat(e),n={type:r,data:t};return n.toString=function(){return r},n}function Pt(e,t){var r="".concat(J.ErrorPlatform,".").concat(e),n={type:r,data:t};return n.toString=function(){return r},n}var Vr=function(e){var t,r,n=[];try{for(var a=D(e),i=a.next();!i.done;i=a.next())for(var o=i.value,f=0;f<o.actions.length;){if(o.actions[f].type===Ee){n.push(o.actions[f]),o.actions.splice(f,1);continue}f++}}catch(s){t={error:s}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}return n};function Bt(e,t,r,n,a,i,o){o===void 0&&(o=!1);var f=o?[]:Vr(a),s=f.length?De(r,n,f,t):r,c=o?[r]:void 0,l=[];function v(p,y){var T;switch(y.type){case Dt:{var S=Cr(y,s,n,e.options.delays);return i&&typeof S.delay=="number"&&i(S,s,n),S}case Ht:var m=Fr(y,s,n,e.options.delays);return i&&m.to!==Et.Internal&&(p==="entry"?l.push(m):i(m,s,n)),m;case ke:{var b=Mr(y,s,n);return i==null||i(b,s,n),b}case br:{var O=y,N=(T=O.conds.find(function(ft){var W=Ve(ft.cond,e.options.guards);return!W||qe(e,W,s,n,i?void 0:t)}))===null||T===void 0?void 0:T.actions;if(!N)return[];var P=M(Bt(e,t,s,n,[{type:p,actions:pt(ct(N),e.options.actions)}],i,o),2),$=P[0],G=P[1];return s=G,c==null||c.push(s),$}case Er:{var N=y.get(s,n.data);if(!N)return[];var I=M(Bt(e,t,s,n,[{type:p,actions:pt(ct(N),e.options.actions)}],i,o),2),Q=I[0],j=I[1];return s=j,c==null||c.push(s),Q}case be:{var b=zr(y,s,n);return i==null||i(b,r,n),b}case Ee:{s=De(s,n,[y],i?void 0:t),c==null||c.push(s);break}default:var C=Lt(y,e.options.actions),V=C.exec;if(i)i(C,s,n);else if(V&&c){var nt=c.length-1,vt=g(g({},C),{exec:function(ft){for(var W=[],q=1;q<arguments.length;q++)W[q-1]=arguments[q];V.apply(void 0,K([c[nt]],M(W),!1))}});C=vt}return C}}function d(p){var y,T,S=[];try{for(var m=D(p.actions),b=m.next();!b.done;b=m.next()){var O=b.value,N=v(p.type,O);N&&(S=S.concat(N))}}catch(P){y={error:P}}finally{try{b&&!b.done&&(T=m.return)&&T.call(m)}finally{if(y)throw y.error}}return l.forEach(function(P){i(P,s,n)}),l.length=0,S}var h=B(a.map(d));return[h,s]}var Ce=[],wt=function(e,t){Ce.push(e);var r=t(e);return Ce.pop(),r};function We(e){var t;return t={id:e,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},getSnapshot:function(){},toJSON:function(){return{id:e}}},t[yt]=function(){return this},t}function qr(e,t,r,n){var a,i=Ke(e.src),o=(a=t==null?void 0:t.options.services)===null||a===void 0?void 0:a[i.type],f=e.data?Wt(e.data,r,n):void 0,s=o?Be(o,e.id,f):We(e.id);return s.meta=e,s}function Be(e,t,r){var n=We(t);if(n.deferred=!0,xt(e)){var a=n.state=wt(void 0,function(){return(r?e.withContext(r):e).initialState});n.getSnapshot=function(){return a}}return n}function Kr(e){try{return typeof e.send=="function"}catch{return!1}}function Qr(e){return Kr(e)&&"id"in e}function Wr(e){var t;return g((t={subscribe:function(){return{unsubscribe:function(){}}},id:"anonymous",getSnapshot:function(){}},t[yt]=function(){return this},t),e)}var Zt=function(e){return e.type==="atomic"||e.type==="final"};function Ze(e){return Object.keys(e.states).map(function(t){return e.states[t]})}function Rt(e){return Ze(e).filter(function(t){return t.type!=="history"})}function He(e){var t=[e];return Zt(e)?t:t.concat(B(Rt(e).map(He)))}function It(e,t){var r,n,a,i,o,f,s,c,l=new Set(e),v=ye(l),d=new Set(t);try{for(var h=D(d),p=h.next();!p.done;p=h.next())for(var y=p.value,T=y.parent;T&&!d.has(T);)d.add(T),T=T.parent}catch(I){r={error:I}}finally{try{p&&!p.done&&(n=h.return)&&n.call(h)}finally{if(r)throw r.error}}var S=ye(d);try{for(var m=D(d),b=m.next();!b.done;b=m.next()){var y=b.value;if(y.type==="compound"&&(!S.get(y)||!S.get(y).length))v.get(y)?v.get(y).forEach(function(Q){return d.add(Q)}):y.initialStateNodes.forEach(function(Q){return d.add(Q)});else if(y.type==="parallel")try{for(var O=(o=void 0,D(Rt(y))),N=O.next();!N.done;N=O.next()){var P=N.value;d.has(P)||(d.add(P),v.get(P)?v.get(P).forEach(function(Q){return d.add(Q)}):P.initialStateNodes.forEach(function(Q){return d.add(Q)}))}}catch(Q){o={error:Q}}finally{try{N&&!N.done&&(f=O.return)&&f.call(O)}finally{if(o)throw o.error}}}}catch(I){a={error:I}}finally{try{b&&!b.done&&(i=m.return)&&i.call(m)}finally{if(a)throw a.error}}try{for(var $=D(d),G=$.next();!G.done;G=$.next())for(var y=G.value,T=y.parent;T&&!d.has(T);)d.add(T),T=T.parent}catch(I){s={error:I}}finally{try{G&&!G.done&&(c=$.return)&&c.call($)}finally{if(s)throw s.error}}return d}function tr(e,t){var r=t.get(e);if(!r)return{};if(e.type==="compound"){var n=r[0];if(n){if(Zt(n))return n.key}else return{}}var a={};return r.forEach(function(i){a[i.key]=tr(i,t)}),a}function ye(e){var t,r,n=new Map;try{for(var a=D(e),i=a.next();!i.done;i=a.next()){var o=i.value;n.has(o)||n.set(o,[]),o.parent&&(n.has(o.parent)||n.set(o.parent,[]),n.get(o.parent).push(o))}}catch(f){t={error:f}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}return n}function Br(e,t){var r=It([e],t);return tr(e,ye(r))}function Nt(e,t){return Array.isArray(e)?e.some(function(r){return r===t}):e instanceof Set?e.has(t):!1}function Zr(e){return K([],M(new Set(B(K([],M(e.map(function(t){return t.ownEvents})),!1)))),!1)}function Kt(e,t){return t.type==="compound"?Rt(t).some(function(r){return r.type==="final"&&Nt(e,r)}):t.type==="parallel"?Rt(t).every(function(r){return Kt(e,r)}):!1}function Hr(e){return e===void 0&&(e=[]),e.reduce(function(t,r){return r.meta!==void 0&&(t[r.id]=r.meta),t},{})}function Fe(e){return new Set(B(e.map(function(t){return t.tags})))}function er(e,t){if(e===t)return!0;if(e===void 0||t===void 0)return!1;if(z(e)||z(t))return e===t;var r=Object.keys(e),n=Object.keys(t);return r.length===n.length&&r.every(function(a){return er(e[a],t[a])})}function tn(e){return typeof e!="object"||e===null?!1:"value"in e&&"_event"in e}function en(e,t){var r=e.exec,n=g(g({},e),{exec:r!==void 0?function(){return r(t.context,t.event,{action:e,state:t,_event:t._event})}:void 0});return n}var dt=function(){function e(t){var r=this,n;this.actions=[],this.activities=$e,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||$e,this.meta=Hr(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=(n=Array.isArray(t.tags)?new Set(t.tags):t.tags)!==null&&n!==void 0?n:new Set,this.machine=t.machine,Object.defineProperty(this,"nextEvents",{get:function(){return Zr(r.configuration)}})}return e.from=function(t,r){if(t instanceof e)return t.context!==r?new e({value:t.value,context:r,_event:t._event,_sessionid:null,historyValue:t.historyValue,history:t.history,actions:[],activities:t.activities,meta:{},events:[],configuration:[],transitions:[],children:{}}):t;var n=bt;return new e({value:t,context:r,_event:n,_sessionid:null,historyValue:void 0,history:void 0,actions:[],activities:void 0,meta:void 0,events:[],configuration:[],transitions:[],children:{}})},e.create=function(t){return new e(t)},e.inert=function(t,r){if(t instanceof e){if(!t.actions.length)return t;var n=bt;return new e({value:t.value,context:r,_event:n,_sessionid:null,historyValue:t.historyValue,history:t.history,activities:t.activities,configuration:t.configuration,transitions:[],children:{}})}return e.from(t,r)},e.prototype.toStrings=function(t,r){var n=this;if(t===void 0&&(t=this.value),r===void 0&&(r="."),z(t))return[t];var a=Object.keys(t);return a.concat.apply(a,K([],M(a.map(function(i){return n.toStrings(t[i],r).map(function(o){return i+r+o})})),!1))},e.prototype.toJSON=function(){var t=this;t.configuration,t.transitions;var r=t.tags;t.machine;var n=we(t,["configuration","transitions","tags","machine"]);return g(g({},n),{tags:Array.from(r)})},e.prototype.matches=function(t){return xe(t,this.value)},e.prototype.hasTag=function(t){return this.tags.has(t)},e.prototype.can=function(t){var r;Nr(!!this.machine);var n=(r=this.machine)===null||r===void 0?void 0:r.getTransitionData(this,t);return!!(n!=null&&n.transitions.length)&&n.transitions.some(function(a){return a.target!==void 0||a.actions.length})},e}(),rn={deferEvents:!1},Ue=function(){function e(t){this.processingEvent=!1,this.queue=[],this.initialized=!1,this.options=g(g({},rn),t)}return e.prototype.initialize=function(t){if(this.initialized=!0,t){if(!this.options.deferEvents){this.schedule(t);return}this.process(t)}this.flushEvents()},e.prototype.schedule=function(t){if(!this.initialized||this.processingEvent){this.queue.push(t);return}if(this.queue.length!==0)throw new Error("Event queue should be empty when it is not processing events");this.process(t),this.flushEvents()},e.prototype.clear=function(){this.queue=[]},e.prototype.flushEvents=function(){for(var t=this.queue.shift();t;)this.process(t),t=this.queue.shift()},e.prototype.process=function(t){this.processingEvent=!0;try{t()}catch(r){throw this.clear(),r}finally{this.processingEvent=!1}},e}(),se=new Map,nn=0,_t={bookId:function(){return"x:".concat(nn++)},register:function(e,t){return se.set(e,t),e},get:function(e){return se.get(e)},free:function(e){se.delete(e)}};function Oe(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function an(){var e=Oe();if(e&&"__xstate__"in e)return e.__xstate__}function on(e){if(Oe()){var t=an();t&&t.register(e)}}function sn(e,t){t===void 0&&(t={});var r=e.initialState,n=new Set,a=[],i=!1,o=function(){if(!i){for(i=!0;a.length>0;){var c=a.shift();r=e.transition(r,c,s),n.forEach(function(l){return l.next(r)})}i=!1}},f=Wr({id:t.id,send:function(c){a.push(c),o()},getSnapshot:function(){return r},subscribe:function(c,l,v){var d=Vt(c,l,v);return n.add(d),d.next(r),{unsubscribe:function(){n.delete(d)}}}}),s={parent:t.parent,self:f,id:t.id||"anonymous",observers:n};return r=e.start?e.start(s):r,f}var un={sync:!1,autoForward:!1},tt;(function(e){e[e.NotStarted=0]="NotStarted",e[e.Running=1]="Running",e[e.Stopped=2]="Stopped"})(tt||(tt={}));var fn=function(){function e(t,r){r===void 0&&(r=e.defaultOptions);var n=this;this.machine=t,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=tt.NotStarted,this.children=new Map,this.forwardTo=new Set,this._outgoingQueue=[],this.init=this.start,this.send=function(l,v){if(Tt(l))return n.batch(l),n.state;var d=it(te(l,v));if(n.status===tt.Stopped)return n.state;if(n.status!==tt.Running&&!n.options.deferEvents)throw new Error('Event "'.concat(d.name,'" was sent to uninitialized service "').concat(n.machine.id,`". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.
Event: `).concat(JSON.stringify(d.data)));return n.scheduler.schedule(function(){n.forward(d);var h=n._nextState(d);n.update(h,d)}),n._state},this.sendTo=function(l,v,d){var h=n.parent&&(v===Et.Parent||n.parent.id===v),p=h?n.parent:z(v)?v===Et.Internal?n:n.children.get(v)||_t.get(v):Lr(v)?v:void 0;if(!p){if(!h)throw new Error("Unable to send event to child '".concat(v,"' from service '").concat(n.id,"'."));return}if("machine"in p){if(n.status!==tt.Stopped||n.parent!==p||n.state.done){var y=g(g({},l),{name:l.name===wr?"".concat(Pt(n.id)):l.name,origin:n.sessionId});!d&&n.machine.config.predictableActionArguments?n._outgoingQueue.push([p,y]):p.send(y)}}else!d&&n.machine.config.predictableActionArguments?n._outgoingQueue.push([p,l.data]):p.send(l.data)},this._exec=function(l,v,d,h){h===void 0&&(h=n.machine.options.actions);var p=l.exec||he(l.type,h),y=Y(p)?p:p?p.exec:l.exec;if(y)try{return y(v,d.data,n.machine.config.predictableActionArguments?{action:l,_event:d}:{action:l,state:n.state,_event:d})}catch(nt){throw n.parent&&n.parent.send({type:"xstate.error",data:nt}),nt}switch(l.type){case Dt:{var T=l;n.defer(T);break}case Ht:var S=l;if(typeof S.delay=="number"){n.defer(S);return}else S.to?n.sendTo(S._event,S.to,d===bt):n.send(S._event);break;case Me:n.cancel(l.sendId);break;case fe:{if(n.status!==tt.Running)return;var m=l.activity;if(!n.machine.config.predictableActionArguments&&!n.state.activities[m.id||m.type])break;if(m.type===J.Invoke){var b=Ke(m.src),O=n.machine.options.services?n.machine.options.services[b.type]:void 0,N=m.id,P=m.data,$="autoForward"in m?m.autoForward:!!m.forward;if(!O)return;var G=P?Wt(P,v,d):void 0;if(typeof O=="string")return;var I=Y(O)?O(v,d.data,{data:G,src:b,meta:m.meta}):O;if(!I)return;var Q=void 0;xt(I)&&(I=G?I.withContext(G):I,Q={autoForward:$}),n.spawn(I,N,Q)}else n.spawnActivity(m);break}case be:{n.stopChild(l.activity.id);break}case ke:var j=l,C=j.label,V=j.value;C?n.logger(C,V):n.logger(V);break}};var a=g(g({},e.defaultOptions),r),i=a.clock,o=a.logger,f=a.parent,s=a.id,c=s!==void 0?s:t.id;this.id=c,this.logger=o,this.clock=i,this.parent=f,this.options=a,this.scheduler=new Ue({deferEvents:this.options.deferEvents}),this.sessionId=_t.bookId()}return Object.defineProperty(e.prototype,"initialState",{get:function(){var t=this;return this._initialState?this._initialState:wt(this,function(){return t._initialState=t.machine.initialState,t._initialState})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"state",{get:function(){return this._state},enumerable:!1,configurable:!0}),e.prototype.execute=function(t,r){var n,a;try{for(var i=D(t.actions),o=i.next();!o.done;o=i.next()){var f=o.value;this.exec(f,t,r)}}catch(s){n={error:s}}finally{try{o&&!o.done&&(a=i.return)&&a.call(i)}finally{if(n)throw n.error}}},e.prototype.update=function(t,r){var n,a,i,o,f,s,c,l,v=this;if(t._sessionid=this.sessionId,this._state=t,(!this.machine.config.predictableActionArguments||r===bt)&&this.options.execute)this.execute(this.state);else for(var d=void 0;d=this._outgoingQueue.shift();)d[0].send(d[1]);if(this.children.forEach(function(I){v.state.children[I.id]=I}),this.devTools&&this.devTools.send(r.data,t),t.event)try{for(var h=D(this.eventListeners),p=h.next();!p.done;p=h.next()){var y=p.value;y(t.event)}}catch(I){n={error:I}}finally{try{p&&!p.done&&(a=h.return)&&a.call(h)}finally{if(n)throw n.error}}try{for(var T=D(this.listeners),S=T.next();!S.done;S=T.next()){var y=S.value;y(t,t.event)}}catch(I){i={error:I}}finally{try{S&&!S.done&&(o=T.return)&&o.call(T)}finally{if(i)throw i.error}}try{for(var m=D(this.contextListeners),b=m.next();!b.done;b=m.next()){var O=b.value;O(this.state.context,this.state.history?this.state.history.context:void 0)}}catch(I){f={error:I}}finally{try{b&&!b.done&&(s=m.return)&&s.call(m)}finally{if(f)throw f.error}}if(this.state.done){var N=t.configuration.find(function(I){return I.type==="final"&&I.parent===v.machine}),P=N&&N.doneData?Wt(N.doneData,t.context,r):void 0;this._doneEvent=qt(this.id,P);try{for(var $=D(this.doneListeners),G=$.next();!G.done;G=$.next()){var y=G.value;y(this._doneEvent)}}catch(I){c={error:I}}finally{try{G&&!G.done&&(l=$.return)&&l.call($)}finally{if(c)throw c.error}}this._stop(),this._stopChildren(),_t.free(this.sessionId)}},e.prototype.onTransition=function(t){return this.listeners.add(t),this.status===tt.Running&&t(this.state,this.state.event),this},e.prototype.subscribe=function(t,r,n){var a=this,i=Vt(t,r,n);this.listeners.add(i.next),this.status!==tt.NotStarted&&i.next(this.state);var o=function(){a.doneListeners.delete(o),a.stopListeners.delete(o),i.complete()};return this.status===tt.Stopped?i.complete():(this.onDone(o),this.onStop(o)),{unsubscribe:function(){a.listeners.delete(i.next),a.doneListeners.delete(o),a.stopListeners.delete(o)}}},e.prototype.onEvent=function(t){return this.eventListeners.add(t),this},e.prototype.onSend=function(t){return this.sendListeners.add(t),this},e.prototype.onChange=function(t){return this.contextListeners.add(t),this},e.prototype.onStop=function(t){return this.stopListeners.add(t),this},e.prototype.onDone=function(t){return this.status===tt.Stopped&&this._doneEvent?t(this._doneEvent):this.doneListeners.add(t),this},e.prototype.off=function(t){return this.listeners.delete(t),this.eventListeners.delete(t),this.sendListeners.delete(t),this.stopListeners.delete(t),this.doneListeners.delete(t),this.contextListeners.delete(t),this},e.prototype.start=function(t){var r=this;if(this.status===tt.Running)return this;this.machine._init(),_t.register(this.sessionId,this),this.initialized=!0,this.status=tt.Running;var n=t===void 0?this.initialState:wt(this,function(){return tn(t)?r.machine.resolveState(t):r.machine.resolveState(dt.from(t,r.machine.context))});return this.options.devTools&&this.attachDev(),this.scheduler.initialize(function(){r.update(n,bt)}),this},e.prototype._stopChildren=function(){this.children.forEach(function(t){Y(t.stop)&&t.stop()}),this.children.clear()},e.prototype._stop=function(){var t,r,n,a,i,o,f,s,c,l;try{for(var v=D(this.listeners),d=v.next();!d.done;d=v.next()){var h=d.value;this.listeners.delete(h)}}catch($){t={error:$}}finally{try{d&&!d.done&&(r=v.return)&&r.call(v)}finally{if(t)throw t.error}}try{for(var p=D(this.stopListeners),y=p.next();!y.done;y=p.next()){var h=y.value;h(),this.stopListeners.delete(h)}}catch($){n={error:$}}finally{try{y&&!y.done&&(a=p.return)&&a.call(p)}finally{if(n)throw n.error}}try{for(var T=D(this.contextListeners),S=T.next();!S.done;S=T.next()){var h=S.value;this.contextListeners.delete(h)}}catch($){i={error:$}}finally{try{S&&!S.done&&(o=T.return)&&o.call(T)}finally{if(i)throw i.error}}try{for(var m=D(this.doneListeners),b=m.next();!b.done;b=m.next()){var h=b.value;this.doneListeners.delete(h)}}catch($){f={error:$}}finally{try{b&&!b.done&&(s=m.return)&&s.call(m)}finally{if(f)throw f.error}}if(!this.initialized)return this;this.initialized=!1,this.status=tt.Stopped,this._initialState=void 0;try{for(var O=D(Object.keys(this.delayedEventsMap)),N=O.next();!N.done;N=O.next()){var P=N.value;this.clock.clearTimeout(this.delayedEventsMap[P])}}catch($){c={error:$}}finally{try{N&&!N.done&&(l=O.return)&&l.call(O)}finally{if(c)throw c.error}}this.scheduler.clear(),this.scheduler=new Ue({deferEvents:this.options.deferEvents})},e.prototype.stop=function(){var t=this,r=this.scheduler;return this._stop(),r.schedule(function(){var n=it({type:"xstate.stop"}),a=wt(t,function(){var i=B(K([],M(t.state.configuration),!1).sort(function(l,v){return v.order-l.order}).map(function(l){return pt(l.onExit,t.machine.options.actions)})),o=M(Bt(t.machine,t.state,t.state.context,n,[{type:"exit",actions:i}],t.machine.config.predictableActionArguments?t._exec:void 0,t.machine.config.predictableActionArguments||t.machine.config.preserveActionOrder),2),f=o[0],s=o[1],c=new dt({value:t.state.value,context:s,_event:n,_sessionid:t.sessionId,historyValue:void 0,history:t.state,actions:f.filter(function(l){return!ve(l)}),activities:{},events:[],configuration:[],transitions:[],children:{},done:t.state.done,tags:t.state.tags,machine:t.machine});return c.changed=!0,c});t.update(a,n),t._stopChildren(),_t.free(t.sessionId)}),this},e.prototype.batch=function(t){var r=this;if(!(this.status===tt.NotStarted&&this.options.deferEvents)){if(this.status!==tt.Running)throw new Error("".concat(t.length,' event(s) were sent to uninitialized service "').concat(this.machine.id,'". Make sure .start() is called for this service, or set { deferEvents: true } in the service options.'))}if(t.length){var n=!!this.machine.config.predictableActionArguments&&this._exec;this.scheduler.schedule(function(){var a,i,o=r.state,f=!1,s=[],c=function(h){var p=it(h);r.forward(p),o=wt(r,function(){return r.machine.transition(o,p,void 0,n||void 0)}),s.push.apply(s,K([],M(r.machine.config.predictableActionArguments?o.actions:o.actions.map(function(y){return en(y,o)})),!1)),f=f||!!o.changed};try{for(var l=D(t),v=l.next();!v.done;v=l.next()){var d=v.value;c(d)}}catch(h){a={error:h}}finally{try{v&&!v.done&&(i=l.return)&&i.call(l)}finally{if(a)throw a.error}}o.changed=f,o.actions=s,r.update(o,it(t[t.length-1]))})}},e.prototype.sender=function(t){return this.send.bind(this,t)},e.prototype._nextState=function(t,r){var n=this;r===void 0&&(r=!!this.machine.config.predictableActionArguments&&this._exec);var a=it(t);if(a.name.indexOf(Ne)===0&&!this.state.nextEvents.some(function(o){return o.indexOf(Ne)===0}))throw a.data.data;var i=wt(this,function(){return n.machine.transition(n.state,a,void 0,r||void 0)});return i},e.prototype.nextState=function(t){return this._nextState(t,!1)},e.prototype.forward=function(t){var r,n;try{for(var a=D(this.forwardTo),i=a.next();!i.done;i=a.next()){var o=i.value,f=this.children.get(o);if(!f)throw new Error("Unable to forward event '".concat(t,"' from interpreter '").concat(this.id,"' to nonexistant child '").concat(o,"'."));f.send(t)}}catch(s){r={error:s}}finally{try{i&&!i.done&&(n=a.return)&&n.call(a)}finally{if(r)throw r.error}}},e.prototype.defer=function(t){var r=this,n=this.clock.setTimeout(function(){"to"in t&&t.to?r.sendTo(t._event,t.to,!0):r.send(t._event)},t.delay);t.id&&(this.delayedEventsMap[t.id]=n)},e.prototype.cancel=function(t){this.clock.clearTimeout(this.delayedEventsMap[t]),delete this.delayedEventsMap[t]},e.prototype.exec=function(t,r,n){n===void 0&&(n=this.machine.options.actions),this._exec(t,r.context,r._event,n)},e.prototype.removeChild=function(t){var r;this.children.delete(t),this.forwardTo.delete(t),(r=this.state)===null||r===void 0||delete r.children[t]},e.prototype.stopChild=function(t){var r=this.children.get(t);r&&(this.removeChild(t),Y(r.stop)&&r.stop())},e.prototype.spawn=function(t,r,n){if(this.status!==tt.Running)return Be(t,r);if(Re(t))return this.spawnPromise(Promise.resolve(t),r);if(Y(t))return this.spawnCallback(t,r);if(Qr(t))return this.spawnActor(t,r);if($r(t))return this.spawnObservable(t,r);if(xt(t))return this.spawnMachine(t,g(g({},n),{id:r}));if(jr(t))return this.spawnBehavior(t,r);throw new Error('Unable to spawn entity "'.concat(r,'" of type "').concat(typeof t,'".'))},e.prototype.spawnMachine=function(t,r){var n=this;r===void 0&&(r={});var a=new e(t,g(g({},this.options),{parent:this,id:r.id||t.id})),i=g(g({},un),r);i.sync&&a.onTransition(function(f){n.send(Ge,{state:f,id:a.id})});var o=a;return this.children.set(a.id,o),i.autoForward&&this.forwardTo.add(a.id),a.onDone(function(f){n.removeChild(a.id),n.send(it(f,{origin:a.id}))}).start(),o},e.prototype.spawnBehavior=function(t,r){var n=sn(t,{id:r,parent:this});return this.children.set(r,n),n},e.prototype.spawnPromise=function(t,r){var n,a=this,i=!1,o;t.then(function(s){i||(o=s,a.removeChild(r),a.send(it(qt(r,s),{origin:r})))},function(s){if(!i){a.removeChild(r);var c=Pt(r,s);try{a.send(it(c,{origin:r}))}catch{a.devTools&&a.devTools.send(c,a.state),a.machine.strict&&a.stop()}}});var f=(n={id:r,send:function(){},subscribe:function(s,c,l){var v=Vt(s,c,l),d=!1;return t.then(function(h){d||(v.next(h),!d&&v.complete())},function(h){d||v.error(h)}),{unsubscribe:function(){return d=!0}}},stop:function(){i=!0},toJSON:function(){return{id:r}},getSnapshot:function(){return o}},n[yt]=function(){return this},n);return this.children.set(r,f),f},e.prototype.spawnCallback=function(t,r){var n,a=this,i=!1,o=new Set,f=new Set,s,c=function(d){s=d,f.forEach(function(h){return h(d)}),!i&&a.send(it(d,{origin:r}))},l;try{l=t(c,function(d){o.add(d)})}catch(d){this.send(Pt(r,d))}if(Re(l))return this.spawnPromise(l,r);var v=(n={id:r,send:function(d){return o.forEach(function(h){return h(d)})},subscribe:function(d){var h=Vt(d);return f.add(h.next),{unsubscribe:function(){f.delete(h.next)}}},stop:function(){i=!0,Y(l)&&l()},toJSON:function(){return{id:r}},getSnapshot:function(){return s}},n[yt]=function(){return this},n);return this.children.set(r,v),v},e.prototype.spawnObservable=function(t,r){var n,a=this,i,o=t.subscribe(function(s){i=s,a.send(it(s,{origin:r}))},function(s){a.removeChild(r),a.send(it(Pt(r,s),{origin:r}))},function(){a.removeChild(r),a.send(it(qt(r),{origin:r}))}),f=(n={id:r,send:function(){},subscribe:function(s,c,l){return t.subscribe(s,c,l)},stop:function(){return o.unsubscribe()},getSnapshot:function(){return i},toJSON:function(){return{id:r}}},n[yt]=function(){return this},n);return this.children.set(r,f),f},e.prototype.spawnActor=function(t,r){return this.children.set(r,t),t},e.prototype.spawnActivity=function(t){var r=this.machine.options&&this.machine.options.activities?this.machine.options.activities[t.type]:void 0;if(r){var n=r(this.state.context,t);this.spawnEffect(t.id,n)}},e.prototype.spawnEffect=function(t,r){var n;this.children.set(t,(n={id:t,send:function(){},subscribe:function(){return{unsubscribe:function(){}}},stop:r||void 0,getSnapshot:function(){},toJSON:function(){return{id:t}}},n[yt]=function(){return this},n))},e.prototype.attachDev=function(){var t=Oe();if(this.options.devTools&&t){if(t.__REDUX_DEVTOOLS_EXTENSION__){var r=typeof this.options.devTools=="object"?this.options.devTools:void 0;this.devTools=t.__REDUX_DEVTOOLS_EXTENSION__.connect(g(g({name:this.id,autoPause:!0,stateSanitizer:function(n){return{value:n.value,context:n.context,actions:n.actions}}},r),{features:g({jump:!1,skip:!1},r?r.features:void 0)}),this.machine),this.devTools.init(this.state)}on(this)}},e.prototype.toJSON=function(){return{id:this.id}},e.prototype[yt]=function(){return this},e.prototype.getSnapshot=function(){return this.status===tt.NotStarted?this.initialState:this._state},e.defaultOptions={execute:!0,deferEvents:!0,clock:{setTimeout:function(t,r){return setTimeout(t,r)},clearTimeout:function(t){return clearTimeout(t)}},logger:console.log.bind(console),devTools:!1},e.interpret=cn,e}();function cn(e,t){var r=new fn(e,t);return r}function ln(e){if(typeof e=="string"){var t={type:e};return t.toString=function(){return e},t}return e}function zt(e){return g(g({type:ce},e),{toJSON:function(){e.onDone,e.onError;var t=we(e,["onDone","onError"]);return g(g({},t),{type:ce,src:ln(e.src)})}})}var Jt="",pe="#",ue="*",mt={},St=function(e){return e[0]===pe},dn=function(){return{actions:{},guards:{},services:{},activities:{},delays:{}}},vn=function(){function e(t,r,n,a){n===void 0&&(n="context"in t?t.context:void 0);var i=this,o;this.config=t,this._context=n,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(dn(),r),this.parent=a==null?void 0:a.parent,this.key=this.config.key||(a==null?void 0:a.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:Ye),this.id=this.config.id||K([this.machine.key],M(this.path),!1).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:(o=this.config.schema)!==null&&o!==void 0?o:{},this.description=this.config.description,this.initial=this.config.initial,this.states=this.config.states?jt(this.config.states,function(c,l){var v,d=new e(c,{},void 0,{parent:i,key:l});return Object.assign(i.idMap,g((v={},v[d.id]=d,v),d.idMap)),d}):mt;var f=0;function s(c){var l,v;c.order=f++;try{for(var d=D(Ze(c)),h=d.next();!h.done;h=d.next()){var p=h.value;s(p)}}catch(y){l={error:y}}finally{try{h&&!h.done&&(v=d.return)&&v.call(d)}finally{if(l)throw l.error}}}s(this),this.history=this.config.history===!0?"shallow":this.config.history||!1,this._transient=!!this.config.always||(this.config.on?Array.isArray(this.config.on)?this.config.on.some(function(c){var l=c.event;return l===Jt}):Jt in this.config.on:!1),this.strict=!!this.config.strict,this.onEntry=ct(this.config.entry||this.config.onEntry).map(function(c){return Lt(c)}),this.onExit=ct(this.config.exit||this.config.onExit).map(function(c){return Lt(c)}),this.meta=this.config.meta,this.doneData=this.type==="final"?this.config.data:void 0,this.invoke=ct(this.config.invoke).map(function(c,l){var v,d;if(xt(c)){var h=Gt(i.id,l);return i.machine.options.services=g((v={},v[h]=c,v),i.machine.options.services),zt({src:h,id:h})}else if(z(c.src)){var h=c.id||Gt(i.id,l);return zt(g(g({},c),{id:h,src:c.src}))}else if(xt(c.src)||Y(c.src)){var h=c.id||Gt(i.id,l);return i.machine.options.services=g((d={},d[h]=c.src,d),i.machine.options.services),zt(g(g({id:h},c),{src:h}))}else{var p=c.src;return zt(g(g({id:Gt(i.id,l)},c),{src:p}))}}),this.activities=ct(this.config.activities).concat(this.invoke).map(function(c){return Te(c)}),this.transition=this.transition.bind(this),this.tags=ct(this.config.tags)}return e.prototype._init=function(){this.__cache.transitions||He(this).forEach(function(t){return t.on})},e.prototype.withConfig=function(t,r){var n=this.options,a=n.actions,i=n.activities,o=n.guards,f=n.services,s=n.delays;return new e(this.config,{actions:g(g({},a),t.actions),activities:g(g({},i),t.activities),guards:g(g({},o),t.guards),services:g(g({},f),t.services),delays:g(g({},s),t.delays)},r??this.context)},e.prototype.withContext=function(t){return new e(this.config,this.options,t)},Object.defineProperty(e.prototype,"context",{get:function(){return Y(this._context)?this._context():this._context},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"definition",{get:function(){return{id:this.id,key:this.key,version:this.version,context:this.context,type:this.type,initial:this.initial,history:this.history,states:jt(this.states,function(t){return t.definition}),on:this.on,transitions:this.transitions,entry:this.onEntry,exit:this.onExit,activities:this.activities||[],meta:this.meta,order:this.order||-1,data:this.doneData,invoke:this.invoke,description:this.description,tags:this.tags}},enumerable:!1,configurable:!0}),e.prototype.toJSON=function(){return this.definition},Object.defineProperty(e.prototype,"on",{get:function(){if(this.__cache.on)return this.__cache.on;var t=this.transitions;return this.__cache.on=t.reduce(function(r,n){return r[n.eventType]=r[n.eventType]||[],r[n.eventType].push(n),r},{})},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"after",{get:function(){return this.__cache.delayedTransitions||(this.__cache.delayedTransitions=this.getDelayedTransitions(),this.__cache.delayedTransitions)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"transitions",{get:function(){return this.__cache.transitions||(this.__cache.transitions=this.formatTransitions(),this.__cache.transitions)},enumerable:!1,configurable:!0}),e.prototype.getCandidates=function(t){if(this.__cache.candidates[t])return this.__cache.candidates[t];var r=t===Jt,n=this.transitions.filter(function(a){var i=a.eventType===t;return r?i:i||a.eventType===ue});return this.__cache.candidates[t]=n,n},e.prototype.getDelayedTransitions=function(){var t=this,r=this.config.after;if(!r)return[];var n=function(i,o){var f=Y(i)?"".concat(t.id,":delay[").concat(o,"]"):i,s=Xr(f,t.id);return t.onEntry.push(Qe(s,{delay:i})),t.onExit.push(kr(s)),s},a=Tt(r)?r.map(function(i,o){var f=n(i.delay,o);return g(g({},i),{event:f})}):B(Object.keys(r).map(function(i,o){var f=r[i],s=z(f)?{target:f}:f,c=isNaN(+i)?i:+i,l=n(c,o);return ct(s).map(function(v){return g(g({},v),{event:l,delay:c})})}));return a.map(function(i){var o=i.delay;return g(g({},t.formatTransition(i)),{delay:o})})},e.prototype.getStateNodes=function(t){var r,n=this;if(!t)return[];var a=t instanceof dt?t.value:$t(t,this.delimiter);if(z(a)){var i=this.getStateNode(a).initial;return i!==void 0?this.getStateNodes((r={},r[a]=i,r)):[this,this.states[a]]}var o=Object.keys(a),f=[this];return f.push.apply(f,K([],M(B(o.map(function(s){return n.getStateNode(s).getStateNodes(a[s])}))),!1)),f},e.prototype.handles=function(t){var r=ze(t);return this.events.includes(r)},e.prototype.resolveState=function(t){var r=t instanceof dt?t:dt.create(t),n=Array.from(It([],this.getStateNodes(r.value)));return new dt(g(g({},r),{value:this.resolve(r.value),configuration:n,done:Kt(n,this),tags:Fe(n),machine:this.machine}))},e.prototype.transitionLeafNode=function(t,r,n){var a=this.getStateNode(t),i=a.next(r,n);return!i||!i.transitions.length?this.next(r,n):i},e.prototype.transitionCompoundNode=function(t,r,n){var a=Object.keys(t),i=this.getStateNode(a[0]),o=i._transition(t[a[0]],r,n);return!o||!o.transitions.length?this.next(r,n):o},e.prototype.transitionParallelNode=function(t,r,n){var a,i,o={};try{for(var f=D(Object.keys(t)),s=f.next();!s.done;s=f.next()){var c=s.value,l=t[c];if(l){var v=this.getStateNode(c),d=v._transition(l,r,n);d&&(o[c]=d)}}}catch(S){a={error:S}}finally{try{s&&!s.done&&(i=f.return)&&i.call(f)}finally{if(a)throw a.error}}var h=Object.keys(o).map(function(S){return o[S]}),p=B(h.map(function(S){return S.transitions})),y=h.some(function(S){return S.transitions.length>0});if(!y)return this.next(r,n);var T=B(Object.keys(o).map(function(S){return o[S].configuration}));return{transitions:p,exitSet:B(h.map(function(S){return S.exitSet})),configuration:T,source:r,actions:B(Object.keys(o).map(function(S){return o[S].actions}))}},e.prototype._transition=function(t,r,n){return z(t)?this.transitionLeafNode(t,r,n):Object.keys(t).length===1?this.transitionCompoundNode(t,r,n):this.transitionParallelNode(t,r,n)},e.prototype.getTransitionData=function(t,r){return this._transition(t.value,t,it(r))},e.prototype.next=function(t,r){var n,a,i=this,o=r.name,f=[],s=[],c;try{for(var l=D(this.getCandidates(o)),v=l.next();!v.done;v=l.next()){var d=v.value,h=d.cond,p=d.in,y=t.context,T=p?z(p)&&St(p)?t.matches($t(this.getStateNodeById(p).path,this.delimiter)):xe($t(p,this.delimiter),Or(this.path.slice(0,-2))(t.value)):!0,S=!1;try{S=!h||qe(this.machine,h,y,r,t)}catch(O){throw new Error("Unable to evaluate guard '".concat(h.name||h.type,"' in transition for event '").concat(o,"' in state node '").concat(this.id,`':
`).concat(O.message))}if(S&&T){d.target!==void 0&&(s=d.target),f.push.apply(f,K([],M(d.actions),!1)),c=d;break}}}catch(O){n={error:O}}finally{try{v&&!v.done&&(a=l.return)&&a.call(l)}finally{if(n)throw n.error}}if(c){if(!s.length)return{transitions:[c],exitSet:[],configuration:t.value?[this]:[],source:t,actions:f};var m=B(s.map(function(O){return i.getRelativeStateNodes(O,t.historyValue)})),b=!!c.internal;return{transitions:[c],exitSet:b?[]:B(s.map(function(O){return i.getPotentiallyReenteringNodes(O)})),configuration:m,source:t,actions:f}}},e.prototype.getPotentiallyReenteringNodes=function(t){if(this.order<t.order)return[this];for(var r=[],n=this,a=t;n&&n!==a;)r.push(n),n=n.parent;return n!==a?[]:(r.push(a),r)},e.prototype.getActions=function(t,r,n,a,i,o,f){var s,c,l,v,d=this,h=o?It([],this.getStateNodes(o.value)):[],p=new Set;try{for(var y=D(Array.from(t).sort(function(j,C){return j.order-C.order})),T=y.next();!T.done;T=y.next()){var S=T.value;(!Nt(h,S)||Nt(n.exitSet,S)||S.parent&&p.has(S.parent))&&p.add(S)}}catch(j){s={error:j}}finally{try{T&&!T.done&&(c=y.return)&&c.call(y)}finally{if(s)throw s.error}}try{for(var m=D(h),b=m.next();!b.done;b=m.next()){var S=b.value;(!Nt(t,S)||Nt(n.exitSet,S.parent))&&n.exitSet.push(S)}}catch(j){l={error:j}}finally{try{b&&!b.done&&(v=m.return)&&v.call(m)}finally{if(l)throw l.error}}n.exitSet.sort(function(j,C){return C.order-j.order});var O=Array.from(p).sort(function(j,C){return j.order-C.order}),N=new Set(n.exitSet),P=B(O.map(function(j){var C=[];if(j.type!=="final")return C;var V=j.parent;if(!V.parent)return C;C.push(Yt(j.id,j.doneData),Yt(V.id,j.doneData?Wt(j.doneData,a,i):void 0));var nt=V.parent;return nt.type==="parallel"&&Rt(nt).every(function(vt){return Kt(n.configuration,vt)})&&C.push(Yt(nt.id)),C})),$=O.map(function(j){var C=j.onEntry,V=j.activities.map(function(nt){return Gr(nt)});return{type:"entry",actions:pt(f?K(K([],M(C),!1),M(V),!1):K(K([],M(V),!1),M(C),!1),d.machine.options.actions)}}).concat({type:"state_done",actions:P.map(function(j){return Dr(j)})}),G=Array.from(N).map(function(j){return{type:"exit",actions:pt(K(K([],M(j.onExit),!1),M(j.activities.map(function(C){return Yr(C)})),!1),d.machine.options.actions)}}),I=G.concat({type:"transition",actions:pt(n.actions,this.machine.options.actions)}).concat($);if(r){var Q=pt(B(K([],M(t),!1).sort(function(j,C){return C.order-j.order}).map(function(j){return j.onExit})),this.machine.options.actions).filter(function(j){return!ve(j)});return I.concat({type:"stop",actions:Q})}return I},e.prototype.transition=function(t,r,n,a){t===void 0&&(t=this.initialState);var i=it(r),o;if(t instanceof dt)o=n===void 0?t:this.resolveState(dt.from(t,n));else{var f=z(t)?this.resolve(Qt(this.getResolvedPath(t))):this.resolve(t),s=n??this.machine.context;o=this.resolveState(dt.from(f,s))}if(this.strict&&!this.events.includes(i.name)&&!_r(i.name))throw new Error("Machine '".concat(this.id,"' does not accept event '").concat(i.name,"'"));var c=this._transition(o.value,o,i)||{transitions:[],configuration:[],exitSet:[],source:o,actions:[]},l=It([],this.getStateNodes(o.value)),v=c.configuration.length?It(l,c.configuration):l;return c.configuration=K([],M(v),!1),this.resolveTransition(c,o,o.context,a,i)},e.prototype.resolveRaisedTransition=function(t,r,n,a){var i,o=t.actions;return t=this.transition(t,r,void 0,a),t._event=n,t.event=n.data,(i=t.actions).unshift.apply(i,K([],M(o),!1)),t},e.prototype.resolveTransition=function(t,r,n,a,i){var o,f,s,c,l=this;i===void 0&&(i=bt);var v=t.configuration,d=!r||t.transitions.length>0,h=d?t.configuration:r?r.configuration:[],p=Kt(h,this),y=d?Br(this.machine,v):void 0,T=r?r.historyValue?r.historyValue:t.source?this.machine.historyValue(r.value):void 0:void 0,S=this.getActions(new Set(h),p,t,n,i,r,a),m=r?g({},r.activities):{};try{for(var b=D(S),O=b.next();!O.done;O=b.next()){var N=O.value;try{for(var P=(s=void 0,D(N.actions)),$=P.next();!$.done;$=P.next()){var G=$.value;G.type===fe?m[G.activity.id||G.activity.type]=G:G.type===be&&(m[G.activity.id||G.activity.type]=!1)}}catch(st){s={error:st}}finally{try{$&&!$.done&&(c=P.return)&&c.call(P)}finally{if(s)throw s.error}}}}catch(st){o={error:st}}finally{try{O&&!O.done&&(f=b.return)&&f.call(b)}finally{if(o)throw o.error}}var I=M(Bt(this,r,n,i,S,a,this.machine.config.predictableActionArguments||this.machine.config.preserveActionOrder),2),Q=I[0],j=I[1],C=M(Pr(Q,ve),2),V=C[0],nt=C[1],vt=Q.filter(function(st){var ht;return st.type===fe&&((ht=st.activity)===null||ht===void 0?void 0:ht.type)===ce}),ft=vt.reduce(function(st,ht){return st[ht.activity.id]=qr(ht.activity,l.machine,j,i),st},r?g({},r.children):{}),W=new dt({value:y||r.value,context:j,_event:i,_sessionid:r?r._sessionid:null,historyValue:y?T?Ir(T,y):void 0:r?r.historyValue:void 0,history:!y||t.source?r:void 0,actions:y?nt:[],activities:y?m:r?r.activities:{},events:[],configuration:h,transitions:t.transitions,children:ft,done:p,tags:Fe(h),machine:this}),q=n!==j;W.changed=i.name===Ge||q;var ot=W.history;ot&&delete ot.history;var Ft=!p&&(this._transient||v.some(function(st){return st._transient}));if(!d&&(!Ft||i.name===Jt))return W;var at=W;if(!p)for(Ft&&(at=this.resolveRaisedTransition(at,{type:mr},i,a));V.length;){var ie=V.shift();at=this.resolveRaisedTransition(at,ie._event,i,a)}var Ut=at.changed||(ot?!!at.actions.length||q||typeof ot.value!=typeof at.value||!er(at.value,ot.value):void 0);return at.changed=Ut,at.history=ot,at},e.prototype.getStateNode=function(t){if(St(t))return this.machine.getStateNodeById(t);if(!this.states)throw new Error("Unable to retrieve child state '".concat(t,"' from '").concat(this.id,"'; no child states exist."));var r=this.states[t];if(!r)throw new Error("Child state '".concat(t,"' does not exist on '").concat(this.id,"'"));return r},e.prototype.getStateNodeById=function(t){var r=St(t)?t.slice(pe.length):t;if(r===this.id)return this;var n=this.machine.idMap[r];if(!n)throw new Error("Child state node '#".concat(r,"' does not exist on machine '").concat(this.id,"'"));return n},e.prototype.getStateNodeByPath=function(t){if(typeof t=="string"&&St(t))try{return this.getStateNodeById(t.slice(1))}catch{}for(var r=de(t,this.delimiter).slice(),n=this;r.length;){var a=r.shift();if(!a.length)break;n=n.getStateNode(a)}return n},e.prototype.resolve=function(t){var r,n=this;if(!t)return this.initialStateValue||mt;switch(this.type){case"parallel":return jt(this.initialStateValue,function(i,o){return i?n.getStateNode(o).resolve(t[o]||i):mt});case"compound":if(z(t)){var a=this.getStateNode(t);return a.type==="parallel"||a.type==="compound"?(r={},r[t]=a.initialStateValue,r):t}return Object.keys(t).length?jt(t,function(i,o){return i?n.getStateNode(o).resolve(i):mt}):this.initialStateValue||{};default:return t||mt}},e.prototype.getResolvedPath=function(t){if(St(t)){var r=this.machine.idMap[t.slice(pe.length)];if(!r)throw new Error("Unable to find state node '".concat(t,"'"));return r.path}return de(t,this.delimiter)},Object.defineProperty(e.prototype,"initialStateValue",{get:function(){var t;if(this.__cache.initialStateValue)return this.__cache.initialStateValue;var r;if(this.type==="parallel")r=Le(this.states,function(n){return n.initialStateValue||mt},function(n){return n.type!=="history"});else if(this.initial!==void 0){if(!this.states[this.initial])throw new Error("Initial state '".concat(this.initial,"' not found on '").concat(this.key,"'"));r=Zt(this.states[this.initial])?this.initial:(t={},t[this.initial]=this.states[this.initial].initialStateValue,t)}else r={};return this.__cache.initialStateValue=r,this.__cache.initialStateValue},enumerable:!1,configurable:!0}),e.prototype.getInitialState=function(t,r){this._init();var n=this.getStateNodes(t);return this.resolveTransition({configuration:n,exitSet:[],transitions:[],source:void 0,actions:[]},void 0,r??this.machine.context,void 0)},Object.defineProperty(e.prototype,"initialState",{get:function(){var t=this.initialStateValue;if(!t)throw new Error("Cannot retrieve initial state from simple state '".concat(this.id,"'."));return this.getInitialState(t)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"target",{get:function(){var t;if(this.type==="history"){var r=this.config;z(r.target)?t=St(r.target)?Qt(this.machine.getStateNodeById(r.target).path.slice(this.path.length-1)):r.target:t=r.target}return t},enumerable:!1,configurable:!0}),e.prototype.getRelativeStateNodes=function(t,r,n){return n===void 0&&(n=!0),n?t.type==="history"?t.resolveHistory(r):t.initialStateNodes:[t]},Object.defineProperty(e.prototype,"initialStateNodes",{get:function(){var t=this;if(Zt(this))return[this];if(this.type==="compound"&&!this.initial)return[this];var r=Xt(this.initialStateValue);return B(r.map(function(n){return t.getFromRelativePath(n)}))},enumerable:!1,configurable:!0}),e.prototype.getFromRelativePath=function(t){if(!t.length)return[this];var r=M(t),n=r[0],a=r.slice(1);if(!this.states)throw new Error("Cannot retrieve subPath '".concat(n,"' from node with no states"));var i=this.getStateNode(n);if(i.type==="history")return i.resolveHistory();if(!this.states[n])throw new Error("Child state '".concat(n,"' does not exist on '").concat(this.id,"'"));return this.states[n].getFromRelativePath(a)},e.prototype.historyValue=function(t){if(Object.keys(this.states).length)return{current:t||this.initialStateValue,states:Le(this.states,function(r,n){if(!t)return r.historyValue();var a=z(t)?void 0:t[n];return r.historyValue(a||r.initialStateValue)},function(r){return!r.history})}},e.prototype.resolveHistory=function(t){var r=this;if(this.type!=="history")return[this];var n=this.parent;if(!t){var a=this.target;return a?B(Xt(a).map(function(o){return n.getFromRelativePath(o)})):n.initialStateNodes}var i=Ar(n.path,"states")(t).current;return z(i)?[n.getStateNode(i)]:B(Xt(i).map(function(o){return r.history==="deep"?n.getFromRelativePath(o):[n.states[o[0]]]}))},Object.defineProperty(e.prototype,"stateIds",{get:function(){var t=this,r=B(Object.keys(this.states).map(function(n){return t.states[n].stateIds}));return[this.id].concat(r)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"events",{get:function(){var t,r,n,a;if(this.__cache.events)return this.__cache.events;var i=this.states,o=new Set(this.ownEvents);if(i)try{for(var f=D(Object.keys(i)),s=f.next();!s.done;s=f.next()){var c=s.value,l=i[c];if(l.states)try{for(var v=(n=void 0,D(l.events)),d=v.next();!d.done;d=v.next()){var h=d.value;o.add("".concat(h))}}catch(p){n={error:p}}finally{try{d&&!d.done&&(a=v.return)&&a.call(v)}finally{if(n)throw n.error}}}}catch(p){t={error:p}}finally{try{s&&!s.done&&(r=f.return)&&r.call(f)}finally{if(t)throw t.error}}return this.__cache.events=Array.from(o)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"ownEvents",{get:function(){var t=new Set(this.transitions.filter(function(r){return!(!r.target&&!r.actions.length&&r.internal)}).map(function(r){return r.eventType}));return Array.from(t)},enumerable:!1,configurable:!0}),e.prototype.resolveTarget=function(t){var r=this;if(t!==void 0)return t.map(function(n){if(!z(n))return n;var a=n[0]===r.delimiter;if(a&&!r.parent)return r.getStateNodeByPath(n.slice(1));var i=a?r.key+n:n;if(r.parent)try{var o=r.parent.getStateNodeByPath(i);return o}catch(f){throw new Error("Invalid transition definition for state node '".concat(r.id,`':
`).concat(f.message))}else return r.getStateNodeByPath(i)})},e.prototype.formatTransition=function(t){var r=this,n=Rr(t.target),a="internal"in t?t.internal:n?n.some(function(s){return z(s)&&s[0]===r.delimiter}):!0,i=this.machine.options.guards,o=this.resolveTarget(n),f=g(g({},t),{actions:pt(ct(t.actions)),cond:Ve(t.cond,i),target:o,source:this,internal:a,eventType:t.event,toJSON:function(){return g(g({},f),{target:f.target?f.target.map(function(s){return"#".concat(s.id)}):void 0,source:"#".concat(r.id)})}});return f},e.prototype.formatTransitions=function(){var t,r,n=this,a;if(!this.config.on)a=[];else if(Array.isArray(this.config.on))a=this.config.on;else{var i=this.config.on,o=ue,f=i[o],s=f===void 0?[]:f,c=we(i,[typeof o=="symbol"?o:o+""]);a=B(Object.keys(c).map(function(m){var b=gt(m,c[m]);return b}).concat(gt(ue,s)))}var l=this.config.always?gt("",this.config.always):[],v=this.config.onDone?gt(String(Yt(this.id)),this.config.onDone):[],d=B(this.invoke.map(function(m){var b=[];return m.onDone&&b.push.apply(b,K([],M(gt(String(qt(m.id)),m.onDone)),!1)),m.onError&&b.push.apply(b,K([],M(gt(String(Pt(m.id)),m.onError)),!1)),b})),h=this.after,p=B(K(K(K(K([],M(v),!1),M(d),!1),M(a),!1),M(l),!1).map(function(m){return ct(m).map(function(b){return n.formatTransition(b)})}));try{for(var y=D(h),T=y.next();!T.done;T=y.next()){var S=T.value;p.push(S)}}catch(m){t={error:m}}finally{try{T&&!T.done&&(r=y.return)&&r.call(y)}finally{if(t)throw t.error}}return p},e}();function ii(e,t,r){return r===void 0&&(r=e.context),new vn(e,t,r)}var ai=Jr,oi=Ur,k={},Ae={};(function(e){Object.defineProperty(e,"__esModule",{value:!0});/*! *****************************************************************************
	Copyright (c) Microsoft Corporation.

	Permission to use, copy, modify, and/or distribute this software for any
	purpose with or without fee is hereby granted.

	THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
	REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
	AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
	INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
	LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
	OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
	PERFORMANCE OF THIS SOFTWARE.
	***************************************************************************** */e.__assign=function(){return e.__assign=Object.assign||function(o){for(var f,s=1,c=arguments.length;s<c;s++){f=arguments[s];for(var l in f)Object.prototype.hasOwnProperty.call(f,l)&&(o[l]=f[l])}return o},e.__assign.apply(this,arguments)};function t(i,o){var f={};for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&o.indexOf(s)<0&&(f[s]=i[s]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var c=0,s=Object.getOwnPropertySymbols(i);c<s.length;c++)o.indexOf(s[c])<0&&Object.prototype.propertyIsEnumerable.call(i,s[c])&&(f[s[c]]=i[s[c]]);return f}function r(i){var o=typeof Symbol=="function"&&Symbol.iterator,f=o&&i[o],s=0;if(f)return f.call(i);if(i&&typeof i.length=="number")return{next:function(){return i&&s>=i.length&&(i=void 0),{value:i&&i[s++],done:!i}}};throw new TypeError(o?"Object is not iterable.":"Symbol.iterator is not defined.")}function n(i,o){var f=typeof Symbol=="function"&&i[Symbol.iterator];if(!f)return i;var s=f.call(i),c,l=[],v;try{for(;(o===void 0||o-- >0)&&!(c=s.next()).done;)l.push(c.value)}catch(d){v={error:d}}finally{try{c&&!c.done&&(f=s.return)&&f.call(s)}finally{if(v)throw v.error}}return l}function a(i,o,f){if(f||arguments.length===2)for(var s=0,c=o.length,l;s<c;s++)(l||!(s in o))&&(l||(l=Array.prototype.slice.call(o,0,s)),l[s]=o[s]);return i.concat(l||Array.prototype.slice.call(o))}e.__read=n,e.__rest=t,e.__spreadArray=a,e.__values=r})(Ae);var ee={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.ActionTypes=void 0,function(t){t.Start="xstate.start",t.Stop="xstate.stop",t.Raise="xstate.raise",t.Send="xstate.send",t.Cancel="xstate.cancel",t.NullEvent="",t.Assign="xstate.assign",t.After="xstate.after",t.DoneState="done.state",t.DoneInvoke="done.invoke",t.Log="xstate.log",t.Init="xstate.init",t.Invoke="xstate.invoke",t.ErrorExecution="error.execution",t.ErrorCommunication="error.communication",t.ErrorPlatform="error.platform",t.ErrorCustom="xstate.error",t.Update="xstate.update",t.Pure="xstate.pure",t.Choose="xstate.choose"}(e.ActionTypes||(e.ActionTypes={})),e.SpecialTargets=void 0,function(t){t.Parent="#_parent",t.Internal="#_internal"}(e.SpecialTargets||(e.SpecialTargets={}))})(ee);var H={};Object.defineProperty(H,"__esModule",{value:!0});var rt=ee,hn=rt.ActionTypes.Start,yn=rt.ActionTypes.Stop,pn=rt.ActionTypes.Raise,gn=rt.ActionTypes.Send,mn=rt.ActionTypes.Cancel,Sn=rt.ActionTypes.NullEvent,wn=rt.ActionTypes.Assign,bn=rt.ActionTypes.After,En=rt.ActionTypes.DoneState,xn=rt.ActionTypes.Log,Tn=rt.ActionTypes.Init,On=rt.ActionTypes.Invoke,An=rt.ActionTypes.ErrorExecution,_n=rt.ActionTypes.ErrorPlatform,jn=rt.ActionTypes.ErrorCustom,Pn=rt.ActionTypes.Update,In=rt.ActionTypes.Choose,Nn=rt.ActionTypes.Pure;H.after=bn;H.assign=wn;H.cancel=mn;H.choose=In;H.doneState=En;H.error=jn;H.errorExecution=An;H.errorPlatform=_n;H.init=Tn;H.invoke=On;H.log=xn;H.nullEvent=Sn;H.pure=Nn;H.raise=pn;H.send=gn;H.start=hn;H.stop=yn;H.update=Pn;var rr={},Ot={};Object.defineProperty(Ot,"__esModule",{value:!0});var $n=".",Ln={},Rn="xstate.guard",Dn="";Ot.DEFAULT_GUARD_TYPE=Rn;Ot.EMPTY_ACTIVITY_MAP=Ln;Ot.STATE_DELIMITER=$n;Ot.TARGETLESS_KEY=Dn;var re={};Object.defineProperty(re,"__esModule",{value:!0});var Cn=!0;re.IS_PRODUCTION=Cn;(function(e){Object.defineProperty(e,"__esModule",{value:!0});var t=Ae,r=ee,n=H,a=Ot,i=re,o;function f(u){return Object.keys(u)}function s(u,w,x){x===void 0&&(x=a.STATE_DELIMITER);var E=h(u,x),A=h(w,x);return q(A)?q(E)?A===E:!1:q(E)?E in A:Object.keys(E).every(function(_){return _ in A?s(E[_],A[_]):!1})}function c(u){try{return q(u)||typeof u=="number"?"".concat(u):u.type}catch{throw new Error("Events must be strings or objects with a string event.type property.")}}function l(u){try{return q(u)||typeof u=="number"?"".concat(u):W(u)?u.name:u.type}catch{throw new Error("Actions must be strings or objects with a string action.type property.")}}function v(u,w){try{return ft(u)?u:u.toString().split(w)}catch{throw new Error("'".concat(u,"' is not a valid state path."))}}function d(u){return typeof u=="object"&&"value"in u&&"context"in u&&"event"in u&&"_event"in u}function h(u,w){if(d(u))return u.value;if(ft(u))return p(u);if(typeof u!="string")return u;var x=v(u,w);return p(x)}function p(u){if(u.length===1)return u[0];for(var w={},x=w,E=0;E<u.length-1;E++)E===u.length-2?x[u[E]]=u[E+1]:(x[u[E]]={},x=x[u[E]]);return w}function y(u,w){for(var x={},E=Object.keys(u),A=0;A<E.length;A++){var _=E[A];x[_]=w(u[_],_,u,A)}return x}function T(u,w,x){var E,A,_={};try{for(var F=t.__values(Object.keys(u)),L=F.next();!L.done;L=F.next()){var X=L.value,Z=u[X];x(Z)&&(_[X]=w(Z,X,u))}}catch(lt){E={error:lt}}finally{try{L&&!L.done&&(A=F.return)&&A.call(F)}finally{if(E)throw E.error}}return _}var S=function(u){return function(w){var x,E,A=w;try{for(var _=t.__values(u),F=_.next();!F.done;F=_.next()){var L=F.value;A=A[L]}}catch(X){x={error:X}}finally{try{F&&!F.done&&(E=_.return)&&E.call(_)}finally{if(x)throw x.error}}return A}};function m(u,w){return function(x){var E,A,_=x;try{for(var F=t.__values(u),L=F.next();!L.done;L=F.next()){var X=L.value;_=_[w][X]}}catch(Z){E={error:Z}}finally{try{L&&!L.done&&(A=F.return)&&A.call(F)}finally{if(E)throw E.error}}return _}}function b(u){if(!u)return[[]];if(q(u))return[[u]];var w=N(Object.keys(u).map(function(x){var E=u[x];return typeof E!="string"&&(!E||!Object.keys(E).length)?[[x]]:b(u[x]).map(function(A){return[x].concat(A)})}));return w}function O(u){var w,x,E={};if(u&&u.length===1&&u[0].length===1)return u[0][0];try{for(var A=t.__values(u),_=A.next();!_.done;_=A.next())for(var F=_.value,L=E,X=0;X<F.length;X++){var Z=F[X];if(X===F.length-2){L[Z]=F[X+1];break}L[Z]=L[Z]||{},L=L[Z]}}catch(lt){w={error:lt}}finally{try{_&&!_.done&&(x=A.return)&&x.call(A)}finally{if(w)throw w.error}}return E}function N(u){var w;return(w=[]).concat.apply(w,t.__spreadArray([],t.__read(u),!1))}function P(u){return ft(u)?u:[u]}function $(u){return u===void 0?[]:P(u)}function G(u,w,x){var E,A;if(W(u))return u(w,x.data);var _={};try{for(var F=t.__values(Object.keys(u)),L=F.next();!L.done;L=F.next()){var X=L.value,Z=u[X];W(Z)?_[X]=Z(w,x.data):_[X]=Z}}catch(lt){E={error:lt}}finally{try{L&&!L.done&&(A=F.return)&&A.call(F)}finally{if(E)throw E.error}}return _}function I(u){return/^(done|error)\./.test(u)}function Q(u){return!!(u instanceof Promise||u!==null&&(W(u)||typeof u=="object")&&W(u.then))}function j(u){return u!==null&&typeof u=="object"&&"transition"in u&&typeof u.transition=="function"}function C(u,w){var x,E,A=t.__read([[],[]],2),_=A[0],F=A[1];try{for(var L=t.__values(u),X=L.next();!X.done;X=L.next()){var Z=X.value;w(Z)?_.push(Z):F.push(Z)}}catch(lt){x={error:lt}}finally{try{X&&!X.done&&(E=L.return)&&E.call(L)}finally{if(x)throw x.error}}return[_,F]}function V(u,w){return y(u.states,function(x,E){if(x){var A=(q(w)?void 0:w[E])||(x?x.current:void 0);if(A)return{current:A,states:V(x,A)}}})}function nt(u,w){return{current:w,states:V(u,w)}}function vt(u,w,x,E){i.IS_PRODUCTION||e.warn(!!u,"Attempting to update undefined context");var A=u&&x.reduce(function(_,F){var L,X,Z=F.assignment,lt={state:E,action:F,_event:w},ae={};if(W(Z))ae=Z(_,w.data,lt);else try{for(var Mt=t.__values(Object.keys(Z)),At=Mt.next();!At.done;At=Mt.next()){var Ie=At.value,oe=Z[Ie];ae[Ie]=W(oe)?oe(_,w.data,lt):oe}}catch(gr){L={error:gr}}finally{try{At&&!At.done&&(X=Mt.return)&&X.call(Mt)}finally{if(L)throw L.error}}return Object.assign({},_,ae)},u);return A}e.warn=function(){},i.IS_PRODUCTION||(e.warn=function(u,w){var x=u instanceof Error?u:void 0;if(!(!x&&u)&&console!==void 0){var E=["Warning: ".concat(w)];x&&E.push(x),console.warn.apply(console,E)}});function ft(u){return Array.isArray(u)}function W(u){return typeof u=="function"}function q(u){return typeof u=="string"}function ot(u,w){if(u)return q(u)?{type:a.DEFAULT_GUARD_TYPE,name:u,predicate:w?w[u]:void 0}:W(u)?{type:a.DEFAULT_GUARD_TYPE,name:u.name,predicate:u}:u}function Ft(u){try{return"subscribe"in u&&W(u.subscribe)}catch{return!1}}var at=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}(),ie=(o={},o[at]=function(){return this},o[Symbol.observable]=function(){return this},o);function Ut(u){return!!u&&"__xstatenode"in u}function st(u){return!!u&&typeof u.send=="function"}var ht=function(){var u=0;return function(){return u++,u.toString(16)}}();function Pe(u,w){return q(u)||typeof u=="number"?t.__assign({type:u},w):u}function ur(u,w){if(!q(u)&&"$$type"in u&&u.$$type==="scxml")return u;var x=Pe(u);return t.__assign({name:x.type,data:x,$$type:"scxml",type:"external"},w)}function fr(u,w){var x=P(w).map(function(E){return typeof E>"u"||typeof E=="string"||Ut(E)?{target:E,event:u}:t.__assign(t.__assign({},E),{event:u})});return x}function cr(u){if(!(u===void 0||u===a.TARGETLESS_KEY))return $(u)}function lr(u,w,x){if(!i.IS_PRODUCTION){var E=u.stack?" Stacktrace was '".concat(u.stack,"'"):"";if(u===w)console.error("Missing onError handler for invocation '".concat(x,"', error was '").concat(u,"'.").concat(E));else{var A=w.stack?" Stacktrace was '".concat(w.stack,"'"):"";console.error("Missing onError handler and/or unhandled exception/promise rejection for invocation '".concat(x,"'. ")+"Original error: '".concat(u,"'. ").concat(E," Current error is '").concat(w,"'.").concat(A))}}}function dr(u,w,x,E,A){var _=u.options.guards,F={state:A,cond:w,_event:E};if(w.type===a.DEFAULT_GUARD_TYPE)return((_==null?void 0:_[w.name])||w.predicate)(x,E.data,F);var L=_==null?void 0:_[w.type];if(!L)throw new Error("Guard '".concat(w.type,"' is not implemented on machine '").concat(u.id,"'."));return L(x,E.data,F)}function vr(u){return typeof u=="string"?{type:u}:u}function hr(u,w,x){var E=function(){},A=typeof u=="object",_=A?u:null;return{next:((A?u.next:u)||E).bind(_),error:((A?u.error:w)||E).bind(_),complete:((A?u.complete:x)||E).bind(_)}}function yr(u,w){return"".concat(u,":invocation[").concat(w,"]")}function pr(u){return(u.type===n.raise||u.type===n.send&&u.to===r.SpecialTargets.Internal)&&typeof u.delay!="number"}e.createInvokeId=yr,e.evaluateGuard=dr,e.flatten=N,e.getActionType=l,e.getEventType=c,e.interopSymbols=ie,e.isActor=st,e.isArray=ft,e.isBehavior=j,e.isBuiltInEvent=I,e.isFunction=W,e.isMachine=Ut,e.isObservable=Ft,e.isPromiseLike=Q,e.isRaisableAction=pr,e.isStateLike=d,e.isString=q,e.keys=f,e.mapContext=G,e.mapFilterValues=T,e.mapValues=y,e.matchesState=s,e.nestedPath=m,e.normalizeTarget=cr,e.partition=C,e.path=S,e.pathToStateValue=p,e.pathsToStateValue=O,e.reportUnhandledExceptionOnInvocation=lr,e.symbolObservable=at,e.toArray=$,e.toArrayStrict=P,e.toEventObject=Pe,e.toGuard=ot,e.toInvokeSource=vr,e.toObserver=hr,e.toSCXMLEvent=ur,e.toStatePath=v,e.toStatePaths=b,e.toStateValue=h,e.toTransitionConfigArray=fr,e.uniqueId=ht,e.updateContext=vt,e.updateHistoryStates=V,e.updateHistoryValue=nt})(rr);Object.defineProperty(k,"__esModule",{value:!0});var U=Ae,ut=ee,et=H,R=rr,nr=re,Fn=R.toSCXMLEvent({type:et.init});function ge(e,t){return t&&t[e]||void 0}function ne(e,t){var r;if(R.isString(e)||typeof e=="number"){var n=ge(e,t);R.isFunction(n)?r={type:e,exec:n}:n?r=n:r={type:e,exec:void 0}}else if(R.isFunction(e))r={type:e.name||e.toString(),exec:e};else{var n=ge(e.type,t);if(R.isFunction(n))r=U.__assign(U.__assign({},e),{exec:n});else if(n){var a=n.type||e.type;r=U.__assign(U.__assign(U.__assign({},n),e),{type:a})}else r=e}return r}var me=function(e,t){if(!e)return[];var r=R.isArray(e)?e:[e];return r.map(function(n){return ne(n,t)})};function _e(e){var t=ne(e);return U.__assign(U.__assign({id:R.isString(e)?e:t.id},t),{type:t.type})}function Un(e,t){return{type:et.raise,event:typeof e=="function"?e:R.toEventObject(e),delay:t?t.delay:void 0,id:t==null?void 0:t.id}}function ir(e,t,r,n){var a={_event:r},i=R.toSCXMLEvent(R.isFunction(e.event)?e.event(t,r.data,a):e.event),o;if(R.isString(e.delay)){var f=n&&n[e.delay];o=R.isFunction(f)?f(t,r.data,a):f}else o=R.isFunction(e.delay)?e.delay(t,r.data,a):e.delay;return U.__assign(U.__assign({},e),{type:et.raise,_event:i,delay:o})}function Ct(e,t){return{to:t?t.to:void 0,type:et.send,event:R.isFunction(e)?e:R.toEventObject(e),delay:t?t.delay:void 0,id:t&&t.id!==void 0?t.id:R.isFunction(e)?e.name:R.getEventType(e)}}function ar(e,t,r,n){var a={_event:r},i=R.toSCXMLEvent(R.isFunction(e.event)?e.event(t,r.data,a):e.event),o;if(R.isString(e.delay)){var f=n&&n[e.delay];o=R.isFunction(f)?f(t,r.data,a):f}else o=R.isFunction(e.delay)?e.delay(t,r.data,a):e.delay;var s=R.isFunction(e.to)?e.to(t,r.data,a):e.to;return U.__assign(U.__assign({},e),{to:s,_event:i,event:i.data,delay:o})}function je(e,t){return Ct(e,U.__assign(U.__assign({},t),{to:ut.SpecialTargets.Parent}))}function Mn(e,t,r){return Ct(t,U.__assign(U.__assign({},r),{to:e}))}function kn(){return je(et.update)}function Gn(e,t){return Ct(e,U.__assign(U.__assign({},t),{to:function(r,n,a){var i=a._event;return i.origin}}))}var Yn=function(e,t){return{context:e,event:t}};function zn(e,t){return e===void 0&&(e=Yn),{type:et.log,label:t,expr:e}}var or=function(e,t,r){return U.__assign(U.__assign({},e),{value:R.isString(e.expr)?e.expr:e.expr(t,r.data,{_event:r})})},Jn=function(e){return{type:et.cancel,sendId:e}};function Xn(e){var t=_e(e);return{type:ut.ActionTypes.Start,activity:t,exec:void 0}}function Vn(e){var t=R.isFunction(e)?e:_e(e);return{type:ut.ActionTypes.Stop,activity:t,exec:void 0}}function sr(e,t,r){var n=R.isFunction(e.activity)?e.activity(t,r.data):e.activity,a=typeof n=="string"?{id:n}:n,i={type:ut.ActionTypes.Stop,activity:a};return i}var qn=function(e){return{type:et.assign,assignment:e}};function Kn(e){return typeof e=="object"&&"type"in e}function Qn(e,t){var r=t?"#".concat(t):"";return"".concat(ut.ActionTypes.After,"(").concat(e,")").concat(r)}function Wn(e,t){var r="".concat(ut.ActionTypes.DoneState,".").concat(e),n={type:r,data:t};return n.toString=function(){return r},n}function Bn(e,t){var r="".concat(ut.ActionTypes.DoneInvoke,".").concat(e),n={type:r,data:t};return n.toString=function(){return r},n}function Zn(e,t){var r="".concat(ut.ActionTypes.ErrorPlatform,".").concat(e),n={type:r,data:t};return n.toString=function(){return r},n}function Hn(e){return{type:ut.ActionTypes.Pure,get:e}}function ti(e,t){if(!nr.IS_PRODUCTION&&(!e||typeof e=="function")){var r=e;e=function(){for(var n=[],a=0;a<arguments.length;a++)n[a]=arguments[a];var i=typeof r=="function"?r.apply(void 0,U.__spreadArray([],U.__read(n),!1)):r;if(!i)throw new Error("Attempted to forward event to undefined actor. This risks an infinite loop in the sender.");return i}}return Ct(function(n,a){return a},U.__assign(U.__assign({},t),{to:e}))}function ei(e,t){return je(function(r,n,a){return{type:et.error,data:R.isFunction(e)?e(r,n,a):e}},U.__assign(U.__assign({},t),{to:ut.SpecialTargets.Parent}))}function ri(e){return{type:ut.ActionTypes.Choose,conds:e}}var ni=function(e){var t,r,n=[];try{for(var a=U.__values(e),i=a.next();!i.done;i=a.next())for(var o=i.value,f=0;f<o.actions.length;){if(o.actions[f].type===et.assign){n.push(o.actions[f]),o.actions.splice(f,1);continue}f++}}catch(s){t={error:s}}finally{try{i&&!i.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}return n};function Se(e,t,r,n,a,i,o){o===void 0&&(o=!1);var f=o?[]:ni(a),s=f.length?R.updateContext(r,n,f,t):r,c=o?[r]:void 0,l=[];function v(p,y){var T;switch(y.type){case et.raise:{var S=ir(y,s,n,e.options.delays);return i&&typeof S.delay=="number"&&i(S,s,n),S}case et.send:var m=ar(y,s,n,e.options.delays);if(!nr.IS_PRODUCTION){var b=y.delay;R.warn(!R.isString(b)||typeof m.delay=="number","No delay reference for delay expression '".concat(b,"' was found on machine '").concat(e.id,"'"))}return i&&m.to!==ut.SpecialTargets.Internal&&(p==="entry"?l.push(m):i(m,s,n)),m;case et.log:{var O=or(y,s,n);return i==null||i(O,s,n),O}case et.choose:{var N=y,P=(T=N.conds.find(function(W){var q=R.toGuard(W.cond,e.options.guards);return!q||R.evaluateGuard(e,q,s,n,i?void 0:t)}))===null||T===void 0?void 0:T.actions;if(!P)return[];var $=U.__read(Se(e,t,s,n,[{type:p,actions:me(R.toArray(P),e.options.actions)}],i,o),2),G=$[0],I=$[1];return s=I,c==null||c.push(s),G}case et.pure:{var P=y.get(s,n.data);if(!P)return[];var Q=U.__read(Se(e,t,s,n,[{type:p,actions:me(R.toArray(P),e.options.actions)}],i,o),2),j=Q[0],C=Q[1];return s=C,c==null||c.push(s),j}case et.stop:{var O=sr(y,s,n);return i==null||i(O,r,n),O}case et.assign:{s=R.updateContext(s,n,[y],i?void 0:t),c==null||c.push(s);break}default:var V=ne(y,e.options.actions),nt=V.exec;if(i)i(V,s,n);else if(nt&&c){var vt=c.length-1,ft=U.__assign(U.__assign({},V),{exec:function(W){for(var q=[],ot=1;ot<arguments.length;ot++)q[ot-1]=arguments[ot];nt.apply(void 0,U.__spreadArray([c[vt]],U.__read(q),!1))}});V=ft}return V}}function d(p){var y,T,S=[];try{for(var m=U.__values(p.actions),b=m.next();!b.done;b=m.next()){var O=b.value,N=v(p.type,O);N&&(S=S.concat(N))}}catch(P){y={error:P}}finally{try{b&&!b.done&&(T=m.return)&&T.call(m)}finally{if(y)throw y.error}}return l.forEach(function(P){i(P,s,n)}),l.length=0,S}var h=R.flatten(a.map(d));return[h,s]}k.actionTypes=et;k.after=Qn;k.assign=qn;k.cancel=Jn;k.choose=ri;k.done=Wn;k.doneInvoke=Bn;k.error=Zn;k.escalate=ei;k.forwardTo=ti;k.getActionFunction=ge;k.initEvent=Fn;k.isActionObject=Kn;k.log=zn;k.pure=Hn;var si=k.raise=Un;k.resolveActions=Se;k.resolveLog=or;k.resolveRaise=ir;k.resolveSend=ar;k.resolveStop=sr;k.respond=Gn;k.send=Ct;k.sendParent=je;k.sendTo=Mn;k.sendUpdate=kn;k.start=Xn;k.stop=Vn;k.toActionObject=ne;k.toActionObjects=me;k.toActivityDefinition=_e;export{tt as I,ii as M,ai as a,cn as i,si as r,oi as s};
