Loading
function(l,t,d){function i(l){let{actor:t,mapState:d,createApi:i,instrumentation:c}=l;function e(){return t.getSnapshot()}function a(){return d(e())}let s=c?.getScreenName(e()),Z=c?.getErrorName(e()),n=c?.getErrorPayload(e()),b=i({actor:t,getSnapshot:e,trackElementClicked:c?(l,t)=>{c.onElementClicked?.(c.moduleName,s,{element:l,action:t?.action,metadata:t?.metadata})}:void 0,trackCaptureAttemptFinished:c?l=>{c.onCaptureAttemptFinished?.(c.moduleName,s,{logs:l.logs})}:void 0});c?.onModuleOpened(c.moduleName),c&&void 0!==s&&c.onScreenOpened(c.moduleName,s),c&&void 0!==Z&&c.onErrorTriggered(c.moduleName,Z,n);let m=c?t.subscribe(l=>{let t=c.getScreenName(l),d=c.getErrorName(l),i=c.getErrorPayload(l);if(s===t){void 0!==d&&d!==Z&&c.onErrorTriggered(c.moduleName,d,i),Z=d,n=i;return}void 0!==s&&c.onScreenClosed(c.moduleName,s),void 0!==t&&c.onScreenOpened(c.moduleName,t),s=t,void 0!==d&&d!==Z&&c.onErrorTriggered(c.moduleName,d,i),Z=d,n=i}):void 0,o=!1;return Object.defineProperties({getState:a,subscribe:function(l){let d=t.subscribe(()=>{l(a())});return()=>d.unsubscribe()},stop(){o||(o=!0,m?.unsubscribe(),c&&void 0!==s&&c.onScreenClosed(c.moduleName,s),s=void 0,Z=void 0,n=void 0,c?.onModuleClosed(c.moduleName),t.stop())}},Object.getOwnPropertyDescriptors(b))}d.d(t,{a:()=>lS,c:()=>i,i:()=>lz,n:()=>lf,o:()=>k,r:()=>lg,s:()=>R,t:()=>function l({schemas:t,actors:d,actions:i,guards:c,delays:e}){return{assign:lg,sendTo:lf,raise:lL,log:lq,cancel:x,stopChild:J,enqueueActions:lA,emit:lv,spawnChild:j,createStateConfig:l=>l,createAction:l=>l,createMachine:l=>new lO({...l,schemas:t},{actors:d,actions:i,guards:c,delays:e}),extend:a=>l({schemas:t,actors:d,actions:{...i,...a.actions},guards:{...c,...a.guards},delays:{...e,...a.delays}})}}});var c,e,a=class{constructor(l){this._process=l,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(l){let t={value:l,next:null};if(this._current){this._last.next=t,this._last=t;return}this._current=t,this._last=t,this._active&&this.flush()}flush(){for(;this._current;){let l=this._current;this._process(l.value),this._current=l.next}this._last=null}};let s="xstate.init",Z="xstate.stop";function n(l,t){return{type:`xstate.done.state.${l}`,output:t}}function b(l,t){return{type:`xstate.error.actor.${l}`,error:t,actorId:l}}function m(l){return{type:s,input:l}}function o(l){setTimeout(()=>{throw l})}let u="function"==typeof Symbol&&Symbol.observable||"@@observable";function h(l){if(M(l))return l;let t=[],d="";for(let i=0;i<l.length;i++){switch(l.charCodeAt(i)){case 92:d+=l[i+1],i++;continue;case 46:t.push(d),d="";continue}d+=l[i]}return t.push(d),t}function W(l){var t;return(t=l)&&"object"==typeof t&&"machine"in t&&"value"in t?l.value:"string"!=typeof l?l:function(l){if(1===l.length)return l[0];let t={},d=t;for(let t=0;t<l.length-1;t++)if(t===l.length-2)d[l[t]]=l[t+1];else{let i=d;d={},i[l[t]]=d}return t}(h(l))}function G(l,t){let d={},i=Object.keys(l);for(let c=0;c<i.length;c++){let e=i[c];d[e]=t(l[e],e,l,c)}return d}function p(l){var t;return void 0===l?[]:M(t=l)?t:[t]}function N(l,t,d,i){return"function"==typeof l?l({context:t,event:d,self:i}):l}function M(l){return Array.isArray(l)}function X(l){var t;return(M(t=l)?t:[t]).map(l=>void 0===l||"string"==typeof l?{target:l}:l)}function y(l){if(void 0!==l&&""!==l)return p(l)}function Y(l,t,d){let i="object"==typeof l,c=i?l:void 0;return{next:(i?l.next:l)?.bind(c),error:(i?l.error:t)?.bind(c),complete:(i?l.complete:d)?.bind(c)}}function r(l,t){let d=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!d)return l.implementations.actors[t];let[,i,c]=d,e=l.getStateNodeById(c).config.invoke;return(Array.isArray(e)?e[i]:e).src}function T(l,t){return`${l.sessionId}.${t}`}let V=0,L=!1,I=((c={})[c.NotStarted=0]="NotStarted",c[c.Running=1]="Running",c[c.Stopped=2]="Stopped",c),z={clock:{setTimeout:(l,t)=>setTimeout(l,t),clearTimeout:l=>clearTimeout(l)},logger:console.log.bind(console),devTools:!1};var w=class{constructor(l,t){this.logic=l,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new a(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=I.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this.systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const d={...z,...t},{clock:i,logger:c,parent:e,syncSnapshot:s,id:Z,systemId:n,inspect:b}=d;this.system=e?e.system:function(l,t){let d=new Map,i=new Map,c=new WeakMap,e=new Set,a={},{clock:s,logger:Z}=t,n={schedule:(l,t,d,i,c=Math.random().toString(36).slice(2))=>{let e={source:l,target:t,event:d,delay:i,id:c,startedAt:Date.now()},Z=T(l,c);b._snapshot._scheduledEvents[Z]=e,a[Z]=s.setTimeout(()=>{delete a[Z],delete b._snapshot._scheduledEvents[Z],b._relay(l,t,d)},i)},cancel:(l,t)=>{let d=T(l,t),i=a[d];delete a[d],delete b._snapshot._scheduledEvents[d],void 0!==i&&s.clearTimeout(i)},cancelAll:l=>{for(let t in b._snapshot._scheduledEvents){let d=b._snapshot._scheduledEvents[t];d.source===l&&n.cancel(l,d.id)}}},b={_snapshot:{_scheduledEvents:(t?.snapshot&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${V++}`,_register:(l,t)=>(d.set(l,t),l),_unregister:l=>{d.delete(l.sessionId);let t=c.get(l);void 0!==t&&(i.delete(t),c.delete(l))},get:l=>i.get(l),getAll:()=>Object.fromEntries(i.entries()),_set:(l,t)=>{let d=i.get(l);if(d&&d!==t)throw Error(`Actor with system ID '${l}' already exists.`);i.set(l,t),c.set(t,l)},inspect:l=>{let t=Y(l);return e.add(t),{unsubscribe(){e.delete(t)}}},_sendInspectionEvent:t=>{if(!e.size)return;let d={...t,rootId:l.sessionId};e.forEach(l=>l.next?.(d))},_relay:(l,t,d)=>{b._sendInspectionEvent({type:"@xstate.event",sourceRef:l,actorRef:t,event:d}),t._send(d)},scheduler:n,getSnapshot:()=>({_scheduledEvents:{...b._snapshot._scheduledEvents}}),start:()=>{let l=b._snapshot._scheduledEvents;for(let t in b._snapshot._scheduledEvents={},l){let{source:d,target:i,event:c,delay:e,id:a}=l[t];n.schedule(d,i,c,e,a)}},_clock:s,_logger:Z};return b}(this,{clock:i,logger:c}),b&&!e&&this.system.inspect(Y(b)),this.sessionId=this.system._bookId(),this.id=Z??this.sessionId,this.logger=t?.logger??this.system._logger,this.clock=t?.clock??this.system._clock,this._parent=e,this._syncSnapshot=s,this.options=d,this.src=d.src??l,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:l=>{this._deferred.push(l)},system:this.system,stopChild:l=>{if(l._parent!==this)throw Error(`Cannot stop child actor ${l.id} of ${this.id} because it is not a child`);l._stop()},emit:l=>{let t=this.eventListeners.get(l.type),d=this.eventListeners.get("*");if(t||d)for(let i of[...t?t.values():[],...d?d.values():[]])try{i(l)}catch(l){o(l)}},actionExecutor:l=>{let t=()=>{if(this._actorScope.system._sendInspectionEvent({type:"@xstate.action",actorRef:this,action:{type:l.type,params:l.params}}),!l.exec)return;let t=L;try{L=!0,l.exec(l.info,l.params)}finally{L=t}};this._processingStatus===I.Running?t():this._deferred.push(t)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),n&&(this.systemId=n,this.system._set(n,this)),this._initState(t?.snapshot??t?.state),n&&"active"!==this._snapshot.status&&this.system._unregister(this)}_initState(l){try{this._snapshot=l?this.logic.restoreSnapshot?this.logic.restoreSnapshot(l,this._actorScope):l:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(l){this._snapshot={status:"error",output:void 0,error:l}}}update(l,t){let d;for(this._snapshot=l;d=this._deferred.shift();)try{d()}catch(t){this._deferred.length=0,this._snapshot={...l,status:"error",error:t}}switch(this._snapshot.status){case"active":for(let t of this.observers)try{t.next?.(l)}catch(l){o(l)}break;case"done":var i;for(let t of this.observers)try{t.next?.(l)}catch(l){o(l)}this._stopProcedure(),this._complete(),this._doneEvent=(i=this.id,{type:`xstate.done.actor.${i}`,output:this._snapshot.output,actorId:i}),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error)}this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:t,snapshot:l})}subscribe(l,t,d){let i=Y(l,t,d);if(this._processingStatus!==I.Stopped)this.observers.add(i);else switch(this._snapshot.status){case"done":try{i.complete?.()}catch(l){o(l)}break;case"error":{let l=this._snapshot.error;if(i.error)try{i.error(l)}catch(l){o(l)}else o(l)}}return{unsubscribe:()=>{this.observers.delete(i)}}}on(l,t){let d=this.eventListeners.get(l);d||(d=new Set,this.eventListeners.set(l,d));let i=t.bind(void 0);return d.add(i),{unsubscribe:()=>{d.delete(i)}}}start(){if(this._processingStatus===I.Running)return this;this._syncSnapshot&&this.subscribe({next:l=>{"active"===l.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:l})},error:()=>{}}),this.system._register(this.sessionId,this),this.systemId&&this.system._set(this.systemId,this),this._processingStatus=I.Running;let l=m(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:l}),this._snapshot.status){case"done":return this.update(this._snapshot,l),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(l){return this._snapshot={...this._snapshot,status:"error",error:l},this._error(l),this}return this.update(this._snapshot,l),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(l){let t,d;try{t=this.logic.transition(this._snapshot,l,this._actorScope)}catch(l){d={err:l}}if(d){let{err:l}=d;this._snapshot={...this._snapshot,status:"error",error:l},this._error(l);return}this.update(t,l),l.type===Z&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===I.Stopped||((this.mailbox.clear(),this._processingStatus===I.NotStarted)?this._processingStatus=I.Stopped:this.mailbox.enqueue({type:Z})),this}stop(){if(this._parent)throw Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(let l of this.observers)try{l.complete?.()}catch(l){o(l)}this.observers.clear()}_reportError(l){if(!this.observers.size){this._parent||o(l);return}let t=!1;for(let d of this.observers){let i=d.error;t||=!i;try{i?.(l)}catch(l){o(l)}}this.observers.clear(),t&&o(l)}_error(l){this._stopProcedure(),this._reportError(l),this._parent&&this.system._relay(this,this._parent,b(this.id,l))}_stopProcedure(){return this._processingStatus!==I.Running||(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new a(this._process.bind(this)),this._processingStatus=I.Stopped,this.system._unregister(this)),this}_send(l){this._processingStatus!==I.Stopped&&this.mailbox.enqueue(l)}send(l){this.system._relay(void 0,this,l)}attachDevTools(){let{devTools:l}=this.options;l&&("function"==typeof l?l:l=>{if("u"<typeof window)return;let t=function(){let l="u">typeof globalThis?globalThis:"u">typeof self?self:"u">typeof window?window:"u">typeof global?global:void 0;if(l.__xstate__)return l.__xstate__}();t&&t.register(l)})(this)}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedSnapshot(l){return this.logic.getPersistedSnapshot(this._snapshot,l)}[u](){return this}getSnapshot(){return this._snapshot}};function R(l,...[t]){return new w(l,t)}function C(l,t,d,i,{sendId:c}){return[t,{sendId:"function"==typeof c?c(d,i):c},void 0]}function S(l,t){l.defer(()=>{l.system.scheduler.cancel(l.self,t.sendId)})}function x(l){function t(l,t){}return t.type="xstate.cancel",t.sendId=l,t.resolve=C,t.execute=S,t}function g(l,t,d,i,{id:c,systemId:e,src:a,input:s,syncSnapshot:Z}){let n,b,m="string"==typeof a?r(t.machine,a):a,o="function"==typeof c?c(d):c;return m&&(b="function"==typeof s?s({context:t.context,event:d.event,self:l.self}):s,n=R(m,{id:o,src:a,parent:l.self,syncSnapshot:Z,systemId:e,input:b})),[lr(t,{children:{...t.children,[o]:n}}),{id:c,systemId:e,actorRef:n,src:a,input:b},void 0]}function D(l,{actorRef:t}){t&&l.defer(()=>{t._processingStatus!==I.Stopped&&t.start()})}function j(...[l,{id:t,systemId:d,input:i,syncSnapshot:c=!1}={}]){function e(l,t){}return e.type="xstate.spawnChild",e.id=t,e.systemId=d,e.src=l,e.input=i,e.syncSnapshot=c,e.resolve=g,e.execute=D,e}function U(l,t,d,i,{actorRef:c}){let e="function"==typeof c?c(d,i):c,a="string"==typeof e?t.children[e]:e,s=t.children;return a&&(s={...s},delete s[a.id]),[lr(t,{children:s}),a,void 0]}function F(l,t){if(t){if(l.system._unregister(t),t._processingStatus!==I.Running)return void l.stopChild(t);l.defer(()=>{l.stopChild(t)})}}function J(l){function t(l,t){}return t.type="xstate.stopChild",t.actorRef=l,t.resolve=U,t.execute=F,t}function O(l,{context:t,event:d},{guards:i}){return i.every(i=>E(i,t,d,l))}function k(l){function t(l,t){return!1}return t.check=O,t.guards=l,t}function E(l,t,d,i){let{machine:c}=i,e="function"==typeof l,a=e?l:c.implementations.guards["string"==typeof l?l:l.type];if(!e&&!a)throw Error(`Guard '${"string"==typeof l?l:l.type}' is not implemented.'.`);if("function"!=typeof a)return E(a,t,d,i);let s={context:t,event:d},Z=e||"string"==typeof l?void 0:"params"in l?"function"==typeof l.params?l.params({context:t,event:d}):l.params:void 0;return"check"in a?a.check(i,s,a):a(s,Z)}let v=l=>"atomic"===l.type||"final"===l.type;function K(l){return Object.values(l.states).filter(l=>"history"!==l.type)}function H(l,t){let d=[];if(t===l)return d;let i=l.parent;for(;i&&i!==t;)d.push(i),i=i.parent;return d}function Q(l){let t=new Set(l),d=P(t);for(let l of t)if("compound"!==l.type||d.get(l)&&d.get(l).length){if("parallel"===l.type){for(let d of K(l))if("history"!==d.type&&!t.has(d))for(let l of ll(d))t.add(l)}}else ll(l).forEach(l=>t.add(l));for(let l of t){let d=l.parent;for(;d;)t.add(d),d=d.parent}return t}function P(l){let t=new Map;for(let d of l)t.has(d)||t.set(d,[]),d.parent&&(t.has(d.parent)||t.set(d.parent,[]),t.get(d.parent).push(d));return t}function f(l,t){return function l(t,d){let i=d.get(t);if(!i)return{};if("compound"===t.type){let l=i[0];if(!l)return{};if(v(l))return l.key}let c={};for(let t of i)c[t.key]=l(t,d);return c}(l,P(Q(t)))}function B(l,t){return"compound"===t.type?K(t).some(t=>"final"===t.type&&l.has(t)):"parallel"===t.type?K(t).every(t=>B(l,t)):"final"===t.type}let A=l=>"#"===l[0];function _(l,t,d){let i=y(d.target),c=d.reenter??!1,e=function(l,t){if(void 0!==t)return t.map(t=>{if("string"!=typeof t)return t;if(A(t))return l.machine.getStateNodeById(t);let d="."===t[0];if(d&&!l.parent)return li(l,t.slice(1));let i=d?l.key+t:t;if(l.parent)try{return li(l.parent,i)}catch(t){throw Error(`Invalid transition definition for state node '${l.id}':
${t.message}`)}throw Error(`Invalid target: "${t}" is not a valid target from the root node. Did you mean ".${t}"?`)})}(l,i),a={...d,actions:p(d.actions),guard:d.guard,target:e,source:l,reenter:c,eventType:t,toJSON:()=>({...a,source:`#${l.id}`,target:e?e.map(l=>`#${l.id}`):void 0})};return a}function $(l){let t=y(l.config.target);return t?{target:t.map(t=>"string"==typeof t?li(l.parent,t):t)}:l.parent.initial}function q(l){return"history"===l.type}function ll(l){let t=lt(l);for(let d of t)for(let i of H(d,l))t.add(i);return t}function lt(l){let t=new Set;return!function l(d){if(!t.has(d)){if(t.add(d),"compound"===d.type)l(d.initial.target[0]);else if("parallel"===d.type)for(let t of K(d))l(t)}}(l),t}function ld(l,t){if(A(t))return l.machine.getStateNodeById(t);if(!l.states)throw Error(`Unable to retrieve child state '${t}' from '${l.id}'; no child states exist.`);let d=l.states[t];if(!d)throw Error(`Child state '${t}' does not exist on '${l.id}'`);return d}function li(l,t){if("string"==typeof t&&A(t))try{return l.machine.getStateNodeById(t)}catch{}let d=h(t).slice(),i=l;for(;d.length;){let l=d.shift();if(!l.length)break;i=ld(i,l)}return i}function lc(l,t){if("string"==typeof t){let d=l.states[t];if(!d)throw Error(`State '${t}' does not exist on '${l.id}'`);return[l,d]}let d=Object.keys(t),i=d.map(t=>ld(l,t)).filter(Boolean);return[l.machine.root,l].concat(i,d.reduce((d,i)=>{let c=ld(l,i);if(!c)return d;let e=lc(c,t[i]);return d.concat(e)},[]))}function le(l,t){let d=l;for(;d.parent&&d.parent!==t;)d=d.parent;return d.parent===t}function la(l,t,d){let i=new Set;for(let c of l){let l=!1,e=new Set;for(let a of i)if(function(l,t){let d=new Set(l),i=new Set(t);for(let l of d)if(i.has(l))return!0;for(let l of i)if(d.has(l))return!0;return!1}(ln([c],t,d),ln([a],t,d)))if(le(c.source,a.source))e.add(a);else{l=!0;break}if(!l){for(let l of e)i.delete(l);i.add(c)}}return Array.from(i)}function ls(l,t){if(!l.target)return[];let d=new Set;for(let i of l.target)if(q(i))if(t[i.id])for(let l of t[i.id])d.add(l);else for(let l of ls($(i),t))d.add(l);else d.add(i);return[...d]}function lZ(l,t){let d=ls(l,t);if(!d)return;if(!l.reenter&&d.every(t=>t===l.source||le(t,l.source)))return l.source;let i=function(l){let[t,...d]=l;for(let l of H(t,void 0))if(d.every(t=>le(t,l)))return l}(d.concat(l.source));return i||(l.reenter?void 0:l.source.machine.root)}function ln(l,t,d){let i=new Set;for(let c of l)if(c.target?.length){let l=lZ(c,d);for(let d of(c.reenter&&c.source===l&&i.add(l),t))le(d,l)&&i.add(d)}return[...i]}function lb(l,t,d,i,c,e){if(!l.length)return t;let a=new Set(t._nodes),s=t.historyValue,Z=la(l,a,s),b=t;c||([b,s]=function(l,t,d,i,c,e,a,s){let Z,n=l,b=ln(i,c,e);for(let l of(b.sort((l,t)=>t.order-l.order),b))for(let t of function(l){return Object.keys(l.states).map(t=>l.states[t]).filter(l=>"history"===l.type)}(l)){let d;d="deep"===t.history?t=>v(t)&&le(t,l):t=>t.parent===l,(Z??={...e})[t.id]=Array.from(c).filter(d)}for(let l of b)n=lu(n,t,d,[...l.exit,...l.invoke.map(l=>J(l.id))],a,void 0),c.delete(l);return[n,Z||e]}(b,i,d,Z,a,s,e,d.actionExecutor)),b=function(l,t,d,i,c,e,a,s){let Z=l,b=new Set,m=new Set;(function(l,t,d,i){for(let c of l){let l=lZ(c,t);for(let e of c.target||[])!q(e)&&(c.source!==e||c.source!==l||c.reenter)&&(i.add(e),d.add(e)),lm(e,t,d,i);for(let e of ls(c,t)){let a=H(e,l);l?.type==="parallel"&&a.push(l),lo(i,t,d,a,!c.source.parent&&c.reenter?void 0:l)}}})(i,a,m,b),s&&m.add(l.machine.root);let o=new Set;for(let l of[...b].sort((l,t)=>l.order-t.order)){c.add(l);let i=[];for(let t of(i.push(...l.entry),l.invoke))i.push(j(t.src,{...t,syncSnapshot:!!t.onSnapshot}));if(m.has(l)){let t=l.initial.actions;i.push(...t)}if(Z=lu(Z,t,d,i,e,l.invoke.map(l=>l.id)),"final"===l.type){let i=l.parent,a=i?.type==="parallel"?i:i?.parent,s=a||l;for(i?.type==="compound"&&e.push(n(i.id,void 0!==l.output?N(l.output,Z.context,t,d.self):void 0));a?.type==="parallel"&&!o.has(a)&&B(c,a);)o.add(a),e.push(n(a.id)),s=a,a=a.parent;if(a)continue;Z=lr(Z,{status:"done",output:function(l,t,d,i,c){if(void 0===i.output)return;let e=n(c.id,void 0!==c.output&&c.parent?N(c.output,l.context,t,d.self):void 0);return N(i.output,l.context,e,d.self)}(Z,t,d,Z.machine.root,s)})}}return Z}(b=lu(b,i,d,Z.flatMap(l=>l.actions),e,void 0),i,d,Z,a,e,s,c);let m=[...a];"done"===b.status&&(b=lu(b,i,d,m.sort((l,t)=>t.order-l.order).flatMap(l=>l.exit),e,void 0));try{if(s===t.historyValue&&function(l,t){if(l.length!==t.size)return!1;for(let d of l)if(!t.has(d))return!1;return!0}(t._nodes,a))return b;return lr(b,{_nodes:m,historyValue:s})}catch(l){throw l}}function lm(l,t,d,i){var c,e,a,s;if(q(l))if(t[l.id]){let a=t[l.id];for(let l of a)i.add(l),lm(l,t,d,i);for(let s of a){c=s,e=l.parent,lo(i,t,d,H(c,e))}}else{let c=$(l);for(let e of c.target)i.add(e),c===l.parent?.initial&&d.add(l.parent),lm(e,t,d,i);for(let e of c.target){a=e,s=l.parent,lo(i,t,d,H(a,s))}}else if("compound"===l.type){let[c]=l.initial.target;q(c)||(i.add(c),d.add(c)),lm(c,t,d,i),lo(i,t,d,H(c,l))}else if("parallel"===l.type)for(let c of K(l).filter(l=>!q(l)))[...i].some(l=>le(l,c))||(q(c)||(i.add(c),d.add(c)),lm(c,t,d,i))}function lo(l,t,d,i,c){for(let e of i)if((!c||le(e,c))&&l.add(e),"parallel"===e.type)for(let i of K(e).filter(l=>!q(l)))[...l].some(l=>le(l,i))||(l.add(i),lm(i,t,d,l))}function lu(l,t,d,i,c,e){let a=e?[]:void 0,s=function l(t,d,i,c,e,a){let{machine:s}=t,Z=t;for(let t of c){var n;let c="function"==typeof t,b=c?t:(n="string"==typeof t?t:t.type,s.implementations.actions[n]),m={context:Z.context,event:d,self:i.self,system:i.system},o=c||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:Z.context,event:d}):t.params:void 0;if(!b||!("resolve"in b)){i.actionExecutor({type:"string"==typeof t?t:"object"==typeof t?t.type:t.name||"(anonymous)",info:m,params:o,exec:b});continue}let[u,h,W]=b.resolve(i,Z,m,o,b,e);Z=u,"retryResolve"in b&&a?.push([b,h]),"execute"in b&&i.actionExecutor({type:b.type,info:m,params:h,exec:b.execute.bind(null,i,h)}),W&&(Z=l(Z,d,i,W,e,a))}return Z}(l,t,d,i,{internalQueue:c,deferredActorIds:e},a);return a?.forEach(([l,t])=>{l.retryResolve(d,s,t)}),s}function lh(l,t,d,i){let c=l,e=[];function a(l,t,i){d.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:d.self,event:t,snapshot:l,_transitions:i}),e.push(l)}if(t.type===Z)return a(c=lr(lW(c,t,d),{status:"stopped"}),t,[]),{snapshot:c,microstates:e};let n=t;if(n.type!==s){let t=n,s=t.type.startsWith("xstate.error.actor"),Z=lG(t,c);if(s&&!Z.length)return a(c=lr(l,{status:"error",error:t.error}),t,[]),{snapshot:c,microstates:e};a(c=lb(Z,l,d,n,!1,i),t,Z)}let b=!0;for(;"active"===c.status;){let l=b?function(l,t){let d=new Set;for(let i of l._nodes.filter(v))l:for(let c of[i].concat(H(i,void 0)))if(c.always){for(let i of c.always)if(void 0===i.guard||E(i.guard,l.context,t,l)){d.add(i);break l}}return la(Array.from(d),new Set(l._nodes),l.historyValue)}(c,n):[],t=l.length?c:void 0;if(!l.length){if(!i.length)break;l=lG(n=i.shift(),c)}b=(c=lb(l,c,d,n,!1,i))!==t,a(c,n,l)}return"active"!==c.status&&lW(c,n,d),{snapshot:c,microstates:e}}function lW(l,t,d){return lu(l,t,d,Object.values(l.children).map(l=>J(l)),[],void 0)}function lG(l,t){return t.machine.getTransitionData(t,l)}let lp=function(l){return function l(t,d){let i=W(t),c=W(d);return"string"==typeof c?"string"==typeof i&&c===i:"string"==typeof i?i in c:Object.keys(i).every(t=>t in c&&l(i[t],c[t]))}(l,this.value)},lN=function(l){return this.tags.has(l)},lM=function(l){let t=this.machine.getTransitionData(this,l);return!!t?.length&&t.some(l=>void 0!==l.target||l.actions.length)},lX=function(){let{_nodes:l,tags:t,machine:d,getMeta:i,toJSON:c,can:e,hasTag:a,matches:s,...Z}=this;return{...Z,tags:Array.from(t)}},ly=function(){return this._nodes.reduce((l,t)=>(void 0!==t.meta&&(l[t.id]=t.meta),l),{})};function lY(l,t){return{status:l.status,output:l.output,error:l.error,machine:t,context:l.context,_nodes:l._nodes,value:f(t.root,l._nodes),tags:new Set(l._nodes.flatMap(l=>l.tags)),children:l.children,historyValue:l.historyValue||{},matches:lp,hasTag:lN,can:lM,getMeta:ly,toJSON:lX}}function lr(l,t={}){return lY({...l,...t},l.machine)}function lT(l,t,d,i,{event:c,id:e,delay:a},{internalQueue:s}){let Z,n=t.machine.implementations.delays;if("string"==typeof c)throw Error(`Only event objects may be used with raise; use raise({ type: "${c}" }) instead`);let b="function"==typeof c?c(d,i):c;if("string"==typeof a){let l=n&&n[a];Z="function"==typeof l?l(d,i):l}else Z="function"==typeof a?a(d,i):a;return"number"!=typeof Z&&s.push(b),[t,{event:b,id:e,delay:Z},void 0]}function lV(l,t){let{event:d,delay:i,id:c}=t;if("number"==typeof i)return void l.defer(()=>{let t=l.self;l.system.scheduler.schedule(t,t,d,i,c)})}function lL(l,t){function d(l,t){}return d.type="xstate.raise",d.event=l,d.id=t?.id,d.delay=t?.delay,d.resolve=lT,d.execute=lV,d}let lI=new WeakMap;function lz(l){return{config:l,start:(t,d)=>{let{self:i,system:c,emit:e}=d,a={receivers:void 0,dispose:void 0};lI.set(i,a),a.dispose=l({input:t.input,system:c,self:i,sendBack:l=>{"stopped"!==i.getSnapshot().status&&i._parent&&c._relay(i,i._parent,l)},receive:l=>{a.receivers??=new Set,a.receivers.add(l)},emit:e})},transition:(l,t,d)=>{let i=lI.get(d.self);return t.type===Z?(l={...l,status:"stopped",error:void 0},i.dispose?.()):i.receivers?.forEach(l=>l(t)),l},getInitialSnapshot:(l,t)=>({status:"active",output:void 0,error:void 0,input:t}),getPersistedSnapshot:l=>l,restoreSnapshot:l=>l}}let lw="xstate.promise.resolve",lR="xstate.promise.reject",lC=new WeakMap;function lS(l){return{config:l,transition:(l,t,d)=>{if("active"!==l.status)return l;switch(t.type){case lw:{let d=t.data;return{...l,status:"done",output:d,input:void 0}}case lR:return{...l,status:"error",error:t.data,input:void 0};case Z:return lC.get(d.self)?.abort(),{...l,status:"stopped",input:void 0};default:return l}},start:(t,{self:d,system:i,emit:c})=>{if("active"!==t.status)return;let e=new AbortController;lC.set(d,e),Promise.resolve(l({input:t.input,system:i,self:d,signal:e.signal,emit:c})).then(l=>{"active"===d.getSnapshot().status&&(lC.delete(d),i._relay(d,d,{type:lw,data:l}))},l=>{"active"===d.getSnapshot().status&&(lC.delete(d),i._relay(d,d,{type:lR,data:l}))})},getInitialSnapshot:(l,t)=>({status:"active",output:void 0,error:void 0,input:t}),getPersistedSnapshot:l=>l,restoreSnapshot:l=>l}}function lx(l,t,d,i,{assignment:c}){if(!t.context)throw Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");let e={},a={context:t.context,event:d.event,spawn:function(l,{machine:t,context:d},i,c){return(e,a)=>{let s=((e,a)=>{if("string"!=typeof e)return R(e,{id:a?.id,parent:l.self,syncSnapshot:a?.syncSnapshot,input:a?.input,src:e,systemId:a?.systemId});{let s=r(t,e);if(!s)throw Error(`Actor logic '${e}' not implemented in machine '${t.id}'`);let Z=R(s,{id:a?.id,parent:l.self,syncSnapshot:a?.syncSnapshot,input:"function"==typeof a?.input?a.input({context:d,event:i,self:l.self}):a?.input,src:e,systemId:a?.systemId});return c[Z.id]=Z,Z}})(e,a);return c[s.id]=s,l.defer(()=>{s._processingStatus!==I.Stopped&&s.start()}),s}}(l,t,d.event,e),self:l.self,system:l.system},s={};if("function"==typeof c)s=c(a,i);else for(let l of Object.keys(c)){let t=c[l];s[l]="function"==typeof t?t(a,i):t}return[lr(t,{context:Object.assign({},t.context,s),children:Object.keys(e).length?{...t.children,...e}:t.children}),void 0,void 0]}function lg(l){function t(l,t){}return t.type="xstate.assign",t.assignment=l,t.resolve=lx,t}let lD=new WeakMap;function lj(l,t,d){let i=lD.get(l);return i?t in i||(i[t]=d()):(i={[t]:d()},lD.set(l,i)),i[t]}let lU={},lF=l=>"string"==typeof l?{type:l}:"function"==typeof l?"resolve"in l?{type:l.type}:{type:l.name}:l;var lJ=class l{constructor(t,d){if(this.config=t,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=d._parent,this.key=d._key,this.machine=d._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join("."),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?G(this.config.states,(t,d)=>new l(t,{_parent:this,_key:d,_machine:this.machine})):lU,"compound"===this.type&&!this.config.initial)throw Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=!0===this.config.history?"shallow":this.config.history||!1,this.entry=p(this.config.entry).slice(),this.exit=p(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"!==this.type&&this.parent?void 0:this.config.output,this.tags=p(t.tags).slice()}_initialize(){this.transitions=function(l){let t=new Map;if(l.config.on)for(let d of Object.keys(l.config.on)){if(""===d)throw Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');let i=l.config.on[d];t.set(d,X(i).map(t=>_(l,d,t)))}if(l.config.onDone){let d=`xstate.done.state.${l.id}`;t.set(d,X(l.config.onDone).map(t=>_(l,d,t)))}for(let d of l.invoke){if(d.onDone){let i=`xstate.done.actor.${d.id}`;t.set(i,X(d.onDone).map(t=>_(l,i,t)))}if(d.onError){let i=`xstate.error.actor.${d.id}`;t.set(i,X(d.onError).map(t=>_(l,i,t)))}if(d.onSnapshot){let i=`xstate.snapshot.${d.id}`;t.set(i,X(d.onSnapshot).map(t=>_(l,i,t)))}}for(let d of l.after){let l=t.get(d.eventType);l||(l=[],t.set(d.eventType,l)),l.push(d)}return t}(this),this.config.always&&(this.always=X(this.config.always).map(l=>_(this,"",l))),Object.keys(this.states).forEach(l=>{this.states[l]._initialize()})}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(lF),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(l=>`#${l.id}`),source:`#${this.id}`,actions:this.initial.actions.map(lF),eventType:null})}:void 0,history:this.history,states:G(this.states,l=>l.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(l=>({...l,actions:l.actions.map(lF)})),entry:this.entry.map(lF),exit:this.exit.map(lF),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return lj(this,"invoke",()=>p(this.config.invoke).map((l,t)=>{var d,i;let{src:c,systemId:e}=l,a=l.id??(d=this.id,`${t}.${d}`),s="string"==typeof c?c:`xstate.invoke.${i=this.id,`${t}.${i}`}`;return{...l,src:s,id:a,systemId:e,toJSON(){let{onDone:t,onError:d,...i}=l;return{...i,type:"xstate.invoke",src:s,id:a}}}}))}get on(){return lj(this,"on",()=>[...this.transitions].flatMap(([l,t])=>t.map(t=>[l,t])).reduce((l,[t,d])=>(l[t]=l[t]||[],l[t].push(d),l),{}))}get after(){return lj(this,"delayedTransitions",()=>{var l;let t;return l=this,(t=l.config.after)?Object.keys(t).flatMap(d=>{var i;let c,e,a=t[d],s=Number.isNaN(+d)?d:+d,Z=(i=l.id,e=(c={type:`xstate.after.${s}.${i}`}).type,l.entry.push(lL(c,{id:e,delay:s})),l.exit.push(x(e)),e);return p("string"==typeof a?{target:a}:a).map(l=>({...l,event:Z,delay:s}))}).map(t=>{let{delay:d}=t;return{..._(l,t.event,t),delay:d}}):[]})}get initial(){return lj(this,"initial",()=>(function(l,t){let d="string"==typeof t?l.states[t]:t?l.states[t.target]:void 0;if(!d&&t)throw Error(`Initial state node "${t}" not found on parent state node #${l.id}`);let i={source:l,actions:t&&"string"!=typeof t?p(t.actions):[],eventType:null,reenter:!1,target:d?[d]:[],toJSON:()=>({...i,source:`#${l.id}`,target:d?[`#${d.id}`]:[]})};return i})(this,this.config.initial))}next(l,t){let d,i=t.type,c=[];for(let e of lj(this,`candidates-${i}`,()=>{var l;return l=this,l.transitions.get(i)||[...l.transitions.keys()].filter(l=>{if("*"===l)return!0;if(!l.endsWith(".*"))return!1;let t=l.split("."),d=i.split(".");for(let l=0;l<t.length;l++){let i=t[l],c=d[l];if("*"===i)return l===t.length-1;if(i!==c)return!1}return!0}).sort((l,t)=>t.length-l.length).flatMap(t=>l.transitions.get(t))})){let{guard:a}=e,s=l.context,Z=!1;try{Z=!a||E(a,s,t,l)}catch(t){let l="string"==typeof a?a:"object"==typeof a?a.type:void 0;throw Error(`Unable to evaluate guard ${l?`'${l}' `:""}in transition for event '${i}' in state node '${this.id}':
${t.message}`)}if(Z){c.push(...e.actions),d=e;break}}return d?[d]:void 0}get events(){return lj(this,"events",()=>{let{states:l}=this,t=new Set(this.ownEvents);if(l)for(let d of Object.keys(l)){let i=l[d];if(i.states)for(let l of i.events)t.add(`${l}`)}return Array.from(t)})}get ownEvents(){return Array.from(new Set([...this.transitions.keys()].filter(l=>this.transitions.get(l).some(l=>!(!l.target&&!l.actions.length&&!l.reenter)))))}},lO=class l{constructor(l,t){this.config=l,this.version=void 0,this.schemas=void 0,this.implementations=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.id=l.id||"(machine)",this.implementations={actors:t?.actors??{},actions:t?.actions??{},delays:t?.delays??{},guards:t?.guards??{}},this.version=this.config.version,this.schemas=this.config.schemas,this.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new lJ(l,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){let{actions:d,guards:i,actors:c,delays:e}=this.implementations;return new l(this.config,{actions:{...d,...t.actions},guards:{...i,...t.guards},actors:{...c,...t.actors},delays:{...e,...t.delays}})}resolveState(l){var t;let d=f(t=this.root,[...Q(lc(t,l.value))]),i=Q(lc(this.root,d));return lY({_nodes:[...i],context:l.context||{},children:{},status:B(i,this.root)?"done":l.status||"active",output:l.output,error:l.error,historyValue:l.historyValue},this)}transition(l,t,d){return lh(l,t,d,[]).snapshot}microstep(l,t,d){return lh(l,t,d,[]).microstates}getTransitionData(l,t){return function l(t,d,i,c){if("string"==typeof d){let l;return(l=ld(t,d).next(i,c))&&l.length?l:t.next(i,c)}if(1===Object.keys(d).length){let e,a;return(a=l(ld(t,(e=Object.keys(d))[0]),d[e[0]],i,c))&&a.length?a:t.next(i,c)}let e=[];for(let a of Object.keys(d)){let s=d[a];if(!s)continue;let Z=l(ld(t,a),s,i,c);Z&&e.push(...Z)}return e.length?e:t.next(i,c)}(this.root,l.value,l,t)||[]}getPreInitialState(l,t,d){let{context:i}=this.config,c=lY({context:"function"!=typeof i&&i?i:{},_nodes:[this.root],children:{},status:"active"},this);return"function"==typeof i?lu(c,t,l,[lg(({spawn:l,event:t,self:d})=>i({spawn:l,input:t.input,self:d}))],d,void 0):c}getInitialSnapshot(l,t){let d=m(t),i=[],c=this.getPreInitialState(l,d,i),{snapshot:e}=lh(lb([{target:[...lt(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],c,l,d,!0,i),d,l,i);return e}start(l){Object.values(l.children).forEach(l=>{"active"===l.getSnapshot().status&&l.start()})}getStateNodeById(l){let t=h(l),d=t.slice(1),i=A(t[0])?t[0].slice(1):t[0],c=this.idMap.get(i);if(!c)throw Error(`Child state node '#${i}' does not exist on machine '${this.id}'`);return li(c,d)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(l,t){return function(l,t){let{_nodes:d,tags:i,machine:c,children:e,context:a,can:s,hasTag:Z,matches:n,getMeta:b,toJSON:m,...o}=l,u={};for(let l in e){let d=e[l];u[l]={snapshot:d.getPersistedSnapshot(t),src:d.src,systemId:d.systemId,syncSnapshot:d._syncSnapshot}}return{...o,context:function l(t){let d;for(let i in t){let c=t[i];if(c&&"object"==typeof c)if("sessionId"in c&&"send"in c&&"ref"in c)(d??=Array.isArray(t)?t.slice():{...t})[i]={xstate$$type:1,id:c.id};else{let e=l(c);e!==c&&((d??=Array.isArray(t)?t.slice():{...t})[i]=e)}}return d??t}(a),children:u,historyValue:function(l){if("object"!=typeof l||null===l)return{};let t={};for(let d in l){let i=l[d];Array.isArray(i)&&(t[d]=i.map(l=>({id:l.id})))}return t}(o.historyValue)}}(l,t)}restoreSnapshot(l,t){let d={},i=l.children;Object.keys(i).forEach(l=>{let c=i[l],e=c.snapshot,a=c.src,s="string"==typeof a?r(this,a):a;s&&(d[l]=R(s,{id:l,parent:t.self,syncSnapshot:c.syncSnapshot,snapshot:e,src:a,systemId:c.systemId}))});let c=function(l,t){if(!t||"object"!=typeof t)return{};let d={};for(let i in t)for(let c of t[i]){let t=function(l,t){if(t instanceof lJ)return t;try{return l.machine.getStateNodeById(t.id)}catch{}}(l,c);t&&(d[i]??=[],d[i].push(t))}return d}(this.root,l.historyValue),e=lY({...l,children:d,_nodes:Array.from(Q(lc(this.root,l.value))),historyValue:c},this),a=new Set;return!function l(t,d){if(!a.has(t))for(let i in a.add(t),t){let c=t[i];if(c&&"object"==typeof c){if("xstate$$type"in c&&1===c.xstate$$type){t[i]=d[c.id];continue}l(c,d)}}}(e.context,d),e}};function lk(l,t,d,i,{event:c}){return[t,{event:"function"==typeof c?c(d,i):c},void 0]}function lE(l,{event:t}){l.defer(()=>l.emit(t))}function lv(l){function t(l,t){}return t.type="xstate.emit",t.event=l,t.resolve=lk,t.execute=lE,t}let lK=((e={}).Parent="#_parent",e.Internal="#_internal",e);function lH(l,t,d,i,{to:c,event:e,id:a,delay:s},Z){let n,b,m=t.machine.implementations.delays;if("string"==typeof e)throw Error(`Only event objects may be used with sendTo; use sendTo({ type: "${e}" }) instead`);let o="function"==typeof e?e(d,i):e;if("string"==typeof s){let l=m&&m[s];n="function"==typeof l?l(d,i):l}else n="function"==typeof s?s(d,i):s;let u="function"==typeof c?c(d,i):c;if("string"==typeof u){if(!(b=u===lK.Parent?l.self._parent:u===lK.Internal?l.self:u.startsWith("#_")?t.children[u.slice(2)]:Z.deferredActorIds?.includes(u)?u:t.children[u]))throw Error(`Unable to send event to actor '${u}' from machine '${t.machine.id}'.`)}else b=u||l.self;return[t,{to:b,targetId:"string"==typeof u?u:void 0,event:o,id:a,delay:n},void 0]}function lQ(l,t,d){"string"==typeof d.to&&(d.to=t.children[d.to])}function lP(l,t){l.defer(()=>{let{to:d,event:i,delay:c,id:e}=t;"number"==typeof c?l.system.scheduler.schedule(l.self,d,i,c,e):l.system._relay(l.self,d,"xstate.error"===i.type?b(l.self.id,i.data):i)})}function lf(l,t,d){function i(l,t){}return i.type="xstate.sendTo",i.to=l,i.event=t,i.id=d?.id,i.delay=d?.delay,i.resolve=lH,i.retryResolve=lQ,i.execute=lP,i}function lB(l,t,d,i,{collect:c}){let e=[],a=function(l){e.push(l)};return a.assign=(...l)=>{e.push(lg(...l))},a.cancel=(...l)=>{e.push(x(...l))},a.raise=(...l)=>{e.push(lL(...l))},a.sendTo=(...l)=>{e.push(lf(...l))},a.sendParent=(...l)=>{e.push(function(l,t){return lf(lK.Parent,l,t)}(...l))},a.spawnChild=(...l)=>{e.push(j(...l))},a.stopChild=(...l)=>{e.push(J(...l))},a.emit=(...l)=>{e.push(lv(...l))},c({context:d.context,event:d.event,enqueue:a,check:l=>E(l,t.context,d.event,t),self:l.self,system:l.system},i),[t,void 0,e]}function lA(l){function t(l,t){}return t.type="xstate.enqueueActions",t.collect=l,t.resolve=lB,t}function l_(l,t,d,i,{value:c,label:e}){return[t,{value:"function"==typeof c?c(d,i):c,label:e},void 0]}function l$({logger:l},{value:t,label:d}){d?l(d,t):l(t)}function lq(l=({context:l,event:t})=>({context:l,event:t}),t){function d(l,t){}return d.type="xstate.log",d.value=l,d.label=t,d.resolve=l_,d.execute=l$,d}}