Build 576754stable
Module 64755
38,668 characters · in 7af349a24887a0e7.jsDependencies
Source Raw
function(e,t,i){function n(e){let{actor:t,mapState:i,createApi:n,instrumentation:r}=e;function o(){return t.getSnapshot()}function a(){return i(o())}let s=r?.getScreenName(o()),l=r?.getErrorName(o()),c=r?.getErrorPayload(o()),d=n({actor:t,getSnapshot:o,trackElementClicked:r?(e,t)=>{r.onElementClicked?.(r.moduleName,s,{element:e,action:t?.action,metadata:t?.metadata})}:void 0,trackCaptureAttemptFinished:r?e=>{r.onCaptureAttemptFinished?.(r.moduleName,s,{logs:e.logs})}:void 0});r?.onModuleOpened(r.moduleName),r&&void 0!==s&&r.onScreenOpened(r.moduleName,s),r&&void 0!==l&&r.onErrorTriggered(r.moduleName,l,c);let u=r?t.subscribe(e=>{let t=r.getScreenName(e),i=r.getErrorName(e),n=r.getErrorPayload(e);if(s===t){void 0!==i&&i!==l&&r.onErrorTriggered(r.moduleName,i,n),l=i,c=n;return}void 0!==s&&r.onScreenClosed(r.moduleName,s),void 0!==t&&r.onScreenOpened(r.moduleName,t),s=t,void 0!==i&&i!==l&&r.onErrorTriggered(r.moduleName,i,n),l=i,c=n}):void 0,h=!1;return Object.defineProperties({getState:a,subscribe:function(e){let i=t.subscribe(()=>{e(a())});return()=>i.unsubscribe()},stop(){h||(h=!0,u?.unsubscribe(),r&&void 0!==s&&r.onScreenClosed(r.moduleName,s),s=void 0,l=void 0,c=void 0,r?.onModuleClosed(r.moduleName),t.stop())}},Object.getOwnPropertyDescriptors(d))}i.d(t,{a:()=>eR,c:()=>n,i:()=>eI,n:()=>eK,o:()=>B,r:()=>eP,s:()=>M,t:()=>function e({schemas:t,actors:i,actions:n,guards:r,delays:o}){return{assign:eP,sendTo:eK,raise:ek,log:eJ,cancel:O,stopChild:H,enqueueActions:eY,emit:ez,spawnChild:F,createStateConfig:e=>e,createAction:e=>e,createMachine:e=>new e$({...e,schemas:t},{actors:i,actions:n,guards:r,delays:o}),extend:a=>e({schemas:t,actors:i,actions:{...n,...a.actions},guards:{...r,...a.guards},delays:{...o,...a.delays}})}}});var r,o,a=class{constructor(e){this._process=e,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(e){let t={value:e,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 e=this._current;this._process(e.value),this._current=e.next}this._last=null}};let s="xstate.init",l="xstate.stop";function c(e,t){return{type:`xstate.done.state.${e}`,output:t}}function d(e,t){return{type:`xstate.error.actor.${e}`,error:t,actorId:e}}function u(e){return{type:s,input:e}}function h(e){setTimeout(()=>{throw e})}let p="function"==typeof Symbol&&Symbol.observable||"@@observable";function f(e){if(y(e))return e;let t=[],i="";for(let n=0;n<e.length;n++){switch(e.charCodeAt(n)){case 92:i+=e[n+1],n++;continue;case 46:t.push(i),i="";continue}i+=e[n]}return t.push(i),t}function m(e){var t;return(t=e)&&"object"==typeof t&&"machine"in t&&"value"in t?e.value:"string"!=typeof e?e:function(e){if(1===e.length)return e[0];let t={},i=t;for(let t=0;t<e.length-1;t++)if(t===e.length-2)i[e[t]]=e[t+1];else{let n=i;i={},n[e[t]]=i}return t}(f(e))}function g(e,t){let i={},n=Object.keys(e);for(let r=0;r<n.length;r++){let o=n[r];i[o]=t(e[o],o,e,r)}return i}function v(e){var t;return void 0===e?[]:y(t=e)?t:[t]}function C(e,t,i,n){return"function"==typeof e?e({context:t,event:i,self:n}):e}function y(e){return Array.isArray(e)}function w(e){var t;return(y(t=e)?t:[t]).map(e=>void 0===e||"string"==typeof e?{target:e}:e)}function b(e){if(void 0!==e&&""!==e)return v(e)}function _(e,t,i){let n="object"==typeof e,r=n?e:void 0;return{next:(n?e.next:e)?.bind(r),error:(n?e.error:t)?.bind(r),complete:(n?e.complete:i)?.bind(r)}}function S(e,t){let i=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!i)return e.implementations.actors[t];let[,n,r]=i,o=e.getStateNodeById(r).config.invoke;return(Array.isArray(o)?o[n]:o).src}function L(e,t){return`${e.sessionId}.${t}`}let E=0,k=!1,x=((r={})[r.NotStarted=0]="NotStarted",r[r.Running=1]="Running",r[r.Stopped=2]="Stopped",r),I={clock:{setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e)},logger:console.log.bind(console),devTools:!1};var T=class{constructor(e,t){this.logic=e,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=x.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 i={...I,...t},{clock:n,logger:r,parent:o,syncSnapshot:s,id:l,systemId:c,inspect:d}=i;this.system=o?o.system:function(e,t){let i=new Map,n=new Map,r=new WeakMap,o=new Set,a={},{clock:s,logger:l}=t,c={schedule:(e,t,i,n,r=Math.random().toString(36).slice(2))=>{let o={source:e,target:t,event:i,delay:n,id:r,startedAt:Date.now()},l=L(e,r);d._snapshot._scheduledEvents[l]=o,a[l]=s.setTimeout(()=>{delete a[l],delete d._snapshot._scheduledEvents[l],d._relay(e,t,i)},n)},cancel:(e,t)=>{let i=L(e,t),n=a[i];delete a[i],delete d._snapshot._scheduledEvents[i],void 0!==n&&s.clearTimeout(n)},cancelAll:e=>{for(let t in d._snapshot._scheduledEvents){let i=d._snapshot._scheduledEvents[t];i.source===e&&c.cancel(e,i.id)}}},d={_snapshot:{_scheduledEvents:(t?.snapshot&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${E++}`,_register:(e,t)=>(i.set(e,t),e),_unregister:e=>{i.delete(e.sessionId);let t=r.get(e);void 0!==t&&(n.delete(t),r.delete(e))},get:e=>n.get(e),getAll:()=>Object.fromEntries(n.entries()),_set:(e,t)=>{let i=n.get(e);if(i&&i!==t)throw Error(`Actor with system ID '${e}' already exists.`);n.set(e,t),r.set(t,e)},inspect:e=>{let t=_(e);return o.add(t),{unsubscribe(){o.delete(t)}}},_sendInspectionEvent:t=>{if(!o.size)return;let i={...t,rootId:e.sessionId};o.forEach(e=>e.next?.(i))},_relay:(e,t,i)=>{d._sendInspectionEvent({type:"@xstate.event",sourceRef:e,actorRef:t,event:i}),t._send(i)},scheduler:c,getSnapshot:()=>({_scheduledEvents:{...d._snapshot._scheduledEvents}}),start:()=>{let e=d._snapshot._scheduledEvents;for(let t in d._snapshot._scheduledEvents={},e){let{source:i,target:n,event:r,delay:o,id:a}=e[t];c.schedule(i,n,r,o,a)}},_clock:s,_logger:l};return d}(this,{clock:n,logger:r}),d&&!o&&this.system.inspect(_(d)),this.sessionId=this.system._bookId(),this.id=l??this.sessionId,this.logger=t?.logger??this.system._logger,this.clock=t?.clock??this.system._clock,this._parent=o,this._syncSnapshot=s,this.options=i,this.src=i.src??e,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:e=>{this._deferred.push(e)},system:this.system,stopChild:e=>{if(e._parent!==this)throw Error(`Cannot stop child actor ${e.id} of ${this.id} because it is not a child`);e._stop()},emit:e=>{let t=this.eventListeners.get(e.type),i=this.eventListeners.get("*");if(t||i)for(let n of[...t?t.values():[],...i?i.values():[]])try{n(e)}catch(e){h(e)}},actionExecutor:e=>{let t=()=>{if(this._actorScope.system._sendInspectionEvent({type:"@xstate.action",actorRef:this,action:{type:e.type,params:e.params}}),!e.exec)return;let t=k;try{k=!0,e.exec(e.info,e.params)}finally{k=t}};this._processingStatus===x.Running?t():this._deferred.push(t)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),c&&(this.systemId=c,this.system._set(c,this)),this._initState(t?.snapshot??t?.state),c&&"active"!==this._snapshot.status&&this.system._unregister(this)}_initState(e){try{this._snapshot=e?this.logic.restoreSnapshot?this.logic.restoreSnapshot(e,this._actorScope):e:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(e){this._snapshot={status:"error",output:void 0,error:e}}}update(e,t){let i;for(this._snapshot=e;i=this._deferred.shift();)try{i()}catch(t){this._deferred.length=0,this._snapshot={...e,status:"error",error:t}}switch(this._snapshot.status){case"active":for(let t of this.observers)try{t.next?.(e)}catch(e){h(e)}break;case"done":var n;for(let t of this.observers)try{t.next?.(e)}catch(e){h(e)}this._stopProcedure(),this._complete(),this._doneEvent=(n=this.id,{type:`xstate.done.actor.${n}`,output:this._snapshot.output,actorId:n}),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:e})}subscribe(e,t,i){let n=_(e,t,i);if(this._processingStatus!==x.Stopped)this.observers.add(n);else switch(this._snapshot.status){case"done":try{n.complete?.()}catch(e){h(e)}break;case"error":{let e=this._snapshot.error;if(n.error)try{n.error(e)}catch(e){h(e)}else h(e)}}return{unsubscribe:()=>{this.observers.delete(n)}}}on(e,t){let i=this.eventListeners.get(e);i||(i=new Set,this.eventListeners.set(e,i));let n=t.bind(void 0);return i.add(n),{unsubscribe:()=>{i.delete(n)}}}start(){if(this._processingStatus===x.Running)return this;this._syncSnapshot&&this.subscribe({next:e=>{"active"===e.status&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:e})},error:()=>{}}),this.system._register(this.sessionId,this),this.systemId&&this.system._set(this.systemId,this),this._processingStatus=x.Running;let e=u(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:e}),this._snapshot.status){case"done":return this.update(this._snapshot,e),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(e){return this._snapshot={...this._snapshot,status:"error",error:e},this._error(e),this}return this.update(this._snapshot,e),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(e){let t,i;try{t=this.logic.transition(this._snapshot,e,this._actorScope)}catch(e){i={err:e}}if(i){let{err:e}=i;this._snapshot={...this._snapshot,status:"error",error:e},this._error(e);return}this.update(t,e),e.type===l&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===x.Stopped||((this.mailbox.clear(),this._processingStatus===x.NotStarted)?this._processingStatus=x.Stopped:this.mailbox.enqueue({type:l})),this}stop(){if(this._parent)throw Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(let e of this.observers)try{e.complete?.()}catch(e){h(e)}this.observers.clear()}_reportError(e){if(!this.observers.size){this._parent||h(e);return}let t=!1;for(let i of this.observers){let n=i.error;t||=!n;try{n?.(e)}catch(e){h(e)}}this.observers.clear(),t&&h(e)}_error(e){this._stopProcedure(),this._reportError(e),this._parent&&this.system._relay(this,this._parent,d(this.id,e))}_stopProcedure(){return this._processingStatus!==x.Running||(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new a(this._process.bind(this)),this._processingStatus=x.Stopped,this.system._unregister(this)),this}_send(e){this._processingStatus!==x.Stopped&&this.mailbox.enqueue(e)}send(e){this.system._relay(void 0,this,e)}attachDevTools(){let{devTools:e}=this.options;e&&("function"==typeof e?e:e=>{if("u"<typeof window)return;let t=function(){let e="u">typeof globalThis?globalThis:"u">typeof self?self:"u">typeof window?window:"u">typeof global?global:void 0;if(e.__xstate__)return e.__xstate__}();t&&t.register(e)})(this)}toJSON(){return{xstate$$type:1,id:this.id}}getPersistedSnapshot(e){return this.logic.getPersistedSnapshot(this._snapshot,e)}[p](){return this}getSnapshot(){return this._snapshot}};function M(e,...[t]){return new T(e,t)}function A(e,t,i,n,{sendId:r}){return[t,{sendId:"function"==typeof r?r(i,n):r},void 0]}function R(e,t){e.defer(()=>{e.system.scheduler.cancel(e.self,t.sendId)})}function O(e){function t(e,t){}return t.type="xstate.cancel",t.sendId=e,t.resolve=A,t.execute=R,t}function P(e,t,i,n,{id:r,systemId:o,src:a,input:s,syncSnapshot:l}){let c,d,u="string"==typeof a?S(t.machine,a):a,h="function"==typeof r?r(i):r;return u&&(d="function"==typeof s?s({context:t.context,event:i.event,self:e.self}):s,c=M(u,{id:h,src:a,parent:e.self,syncSnapshot:l,systemId:o,input:d})),[eS(t,{children:{...t.children,[h]:c}}),{id:r,systemId:o,actorRef:c,src:a,input:d},void 0]}function D(e,{actorRef:t}){t&&e.defer(()=>{t._processingStatus!==x.Stopped&&t.start()})}function F(...[e,{id:t,systemId:i,input:n,syncSnapshot:r=!1}={}]){function o(e,t){}return o.type="xstate.spawnChild",o.id=t,o.systemId=i,o.src=e,o.input=n,o.syncSnapshot=r,o.resolve=P,o.execute=D,o}function N(e,t,i,n,{actorRef:r}){let o="function"==typeof r?r(i,n):r,a="string"==typeof o?t.children[o]:o,s=t.children;return a&&(s={...s},delete s[a.id]),[eS(t,{children:s}),a,void 0]}function U(e,t){if(t){if(e.system._unregister(t),t._processingStatus!==x.Running)return void e.stopChild(t);e.defer(()=>{e.stopChild(t)})}}function H(e){function t(e,t){}return t.type="xstate.stopChild",t.actorRef=e,t.resolve=N,t.execute=U,t}function $(e,{context:t,event:i},{guards:n}){return n.every(n=>V(n,t,i,e))}function B(e){function t(e,t){return!1}return t.check=$,t.guards=e,t}function V(e,t,i,n){let{machine:r}=n,o="function"==typeof e,a=o?e:r.implementations.guards["string"==typeof e?e:e.type];if(!o&&!a)throw Error(`Guard '${"string"==typeof e?e:e.type}' is not implemented.'.`);if("function"!=typeof a)return V(a,t,i,n);let s={context:t,event:i},l=o||"string"==typeof e?void 0:"params"in e?"function"==typeof e.params?e.params({context:t,event:i}):e.params:void 0;return"check"in a?a.check(n,s,a):a(s,l)}let z=e=>"atomic"===e.type||"final"===e.type;function j(e){return Object.values(e.states).filter(e=>"history"!==e.type)}function Z(e,t){let i=[];if(t===e)return i;let n=e.parent;for(;n&&n!==t;)i.push(n),n=n.parent;return i}function W(e){let t=new Set(e),i=G(t);for(let e of t)if("compound"!==e.type||i.get(e)&&i.get(e).length){if("parallel"===e.type){for(let i of j(e))if("history"!==i.type&&!t.has(i))for(let e of ee(i))t.add(e)}}else ee(e).forEach(e=>t.add(e));for(let e of t){let i=e.parent;for(;i;)t.add(i),i=i.parent}return t}function G(e){let t=new Map;for(let i of e)t.has(i)||t.set(i,[]),i.parent&&(t.has(i.parent)||t.set(i.parent,[]),t.get(i.parent).push(i));return t}function K(e,t){return function e(t,i){let n=i.get(t);if(!n)return{};if("compound"===t.type){let e=n[0];if(!e)return{};if(z(e))return e.key}let r={};for(let t of n)r[t.key]=e(t,i);return r}(e,G(W(t)))}function q(e,t){return"compound"===t.type?j(t).some(t=>"final"===t.type&&e.has(t)):"parallel"===t.type?j(t).every(t=>q(e,t)):"final"===t.type}let Y=e=>"#"===e[0];function Q(e,t,i){let n=b(i.target),r=i.reenter??!1,o=function(e,t){if(void 0!==t)return t.map(t=>{if("string"!=typeof t)return t;if(Y(t))return e.machine.getStateNodeById(t);let i="."===t[0];if(i&&!e.parent)return en(e,t.slice(1));let n=i?e.key+t:t;if(e.parent)try{return en(e.parent,n)}catch(t){throw Error(`Invalid transition definition for state node '${e.id}':
${t.message}`)}throw Error(`Invalid target: "${t}" is not a valid target from the root node. Did you mean ".${t}"?`)})}(e,n),a={...i,actions:v(i.actions),guard:i.guard,target:o,source:e,reenter:r,eventType:t,toJSON:()=>({...a,source:`#${e.id}`,target:o?o.map(e=>`#${e.id}`):void 0})};return a}function X(e){let t=b(e.config.target);return t?{target:t.map(t=>"string"==typeof t?en(e.parent,t):t)}:e.parent.initial}function J(e){return"history"===e.type}function ee(e){let t=et(e);for(let i of t)for(let n of Z(i,e))t.add(n);return t}function et(e){let t=new Set;return!function e(i){if(!t.has(i)){if(t.add(i),"compound"===i.type)e(i.initial.target[0]);else if("parallel"===i.type)for(let t of j(i))e(t)}}(e),t}function ei(e,t){if(Y(t))return e.machine.getStateNodeById(t);if(!e.states)throw Error(`Unable to retrieve child state '${t}' from '${e.id}'; no child states exist.`);let i=e.states[t];if(!i)throw Error(`Child state '${t}' does not exist on '${e.id}'`);return i}function en(e,t){if("string"==typeof t&&Y(t))try{return e.machine.getStateNodeById(t)}catch{}let i=f(t).slice(),n=e;for(;i.length;){let e=i.shift();if(!e.length)break;n=ei(n,e)}return n}function er(e,t){if("string"==typeof t){let i=e.states[t];if(!i)throw Error(`State '${t}' does not exist on '${e.id}'`);return[e,i]}let i=Object.keys(t),n=i.map(t=>ei(e,t)).filter(Boolean);return[e.machine.root,e].concat(n,i.reduce((i,n)=>{let r=ei(e,n);if(!r)return i;let o=er(r,t[n]);return i.concat(o)},[]))}function eo(e,t){let i=e;for(;i.parent&&i.parent!==t;)i=i.parent;return i.parent===t}function ea(e,t,i){let n=new Set;for(let r of e){let e=!1,o=new Set;for(let a of n)if(function(e,t){let i=new Set(e),n=new Set(t);for(let e of i)if(n.has(e))return!0;for(let e of n)if(i.has(e))return!0;return!1}(ec([r],t,i),ec([a],t,i)))if(eo(r.source,a.source))o.add(a);else{e=!0;break}if(!e){for(let e of o)n.delete(e);n.add(r)}}return Array.from(n)}function es(e,t){if(!e.target)return[];let i=new Set;for(let n of e.target)if(J(n))if(t[n.id])for(let e of t[n.id])i.add(e);else for(let e of es(X(n),t))i.add(e);else i.add(n);return[...i]}function el(e,t){let i=es(e,t);if(!i)return;if(!e.reenter&&i.every(t=>t===e.source||eo(t,e.source)))return e.source;let n=function(e){let[t,...i]=e;for(let e of Z(t,void 0))if(i.every(t=>eo(t,e)))return e}(i.concat(e.source));return n||(e.reenter?void 0:e.source.machine.root)}function ec(e,t,i){let n=new Set;for(let r of e)if(r.target?.length){let e=el(r,i);for(let i of(r.reenter&&r.source===e&&n.add(e),t))eo(i,e)&&n.add(i)}return[...n]}function ed(e,t,i,n,r,o){if(!e.length)return t;let a=new Set(t._nodes),s=t.historyValue,l=ea(e,a,s),d=t;r||([d,s]=function(e,t,i,n,r,o,a,s){let l,c=e,d=ec(n,r,o);for(let e of(d.sort((e,t)=>t.order-e.order),d))for(let t of function(e){return Object.keys(e.states).map(t=>e.states[t]).filter(e=>"history"===e.type)}(e)){let i;i="deep"===t.history?t=>z(t)&&eo(t,e):t=>t.parent===e,(l??={...o})[t.id]=Array.from(r).filter(i)}for(let e of d)c=ep(c,t,i,[...e.exit,...e.invoke.map(e=>H(e.id))],a,void 0),r.delete(e);return[c,l||o]}(d,n,i,l,a,s,o,i.actionExecutor)),d=function(e,t,i,n,r,o,a,s){let l=e,d=new Set,u=new Set;(function(e,t,i,n){for(let r of e){let e=el(r,t);for(let o of r.target||[])!J(o)&&(r.source!==o||r.source!==e||r.reenter)&&(n.add(o),i.add(o)),eu(o,t,i,n);for(let o of es(r,t)){let a=Z(o,e);e?.type==="parallel"&&a.push(e),eh(n,t,i,a,!r.source.parent&&r.reenter?void 0:e)}}})(n,a,u,d),s&&u.add(e.machine.root);let h=new Set;for(let e of[...d].sort((e,t)=>e.order-t.order)){r.add(e);let n=[];for(let t of(n.push(...e.entry),e.invoke))n.push(F(t.src,{...t,syncSnapshot:!!t.onSnapshot}));if(u.has(e)){let t=e.initial.actions;n.push(...t)}if(l=ep(l,t,i,n,o,e.invoke.map(e=>e.id)),"final"===e.type){let n=e.parent,a=n?.type==="parallel"?n:n?.parent,s=a||e;for(n?.type==="compound"&&o.push(c(n.id,void 0!==e.output?C(e.output,l.context,t,i.self):void 0));a?.type==="parallel"&&!h.has(a)&&q(r,a);)h.add(a),o.push(c(a.id)),s=a,a=a.parent;if(a)continue;l=eS(l,{status:"done",output:function(e,t,i,n,r){if(void 0===n.output)return;let o=c(r.id,void 0!==r.output&&r.parent?C(r.output,e.context,t,i.self):void 0);return C(n.output,e.context,o,i.self)}(l,t,i,l.machine.root,s)})}}return l}(d=ep(d,n,i,l.flatMap(e=>e.actions),o,void 0),n,i,l,a,o,s,r);let u=[...a];"done"===d.status&&(d=ep(d,n,i,u.sort((e,t)=>t.order-e.order).flatMap(e=>e.exit),o,void 0));try{if(s===t.historyValue&&function(e,t){if(e.length!==t.size)return!1;for(let i of e)if(!t.has(i))return!1;return!0}(t._nodes,a))return d;return eS(d,{_nodes:u,historyValue:s})}catch(e){throw e}}function eu(e,t,i,n){var r,o,a,s;if(J(e))if(t[e.id]){let a=t[e.id];for(let e of a)n.add(e),eu(e,t,i,n);for(let s of a){r=s,o=e.parent,eh(n,t,i,Z(r,o))}}else{let r=X(e);for(let o of r.target)n.add(o),r===e.parent?.initial&&i.add(e.parent),eu(o,t,i,n);for(let o of r.target){a=o,s=e.parent,eh(n,t,i,Z(a,s))}}else if("compound"===e.type){let[r]=e.initial.target;J(r)||(n.add(r),i.add(r)),eu(r,t,i,n),eh(n,t,i,Z(r,e))}else if("parallel"===e.type)for(let r of j(e).filter(e=>!J(e)))[...n].some(e=>eo(e,r))||(J(r)||(n.add(r),i.add(r)),eu(r,t,i,n))}function eh(e,t,i,n,r){for(let o of n)if((!r||eo(o,r))&&e.add(o),"parallel"===o.type)for(let n of j(o).filter(e=>!J(e)))[...e].some(e=>eo(e,n))||(e.add(n),eu(n,t,i,e))}function ep(e,t,i,n,r,o){let a=o?[]:void 0,s=function e(t,i,n,r,o,a){let{machine:s}=t,l=t;for(let t of r){var c;let r="function"==typeof t,d=r?t:(c="string"==typeof t?t:t.type,s.implementations.actions[c]),u={context:l.context,event:i,self:n.self,system:n.system},h=r||"string"==typeof t?void 0:"params"in t?"function"==typeof t.params?t.params({context:l.context,event:i}):t.params:void 0;if(!d||!("resolve"in d)){n.actionExecutor({type:"string"==typeof t?t:"object"==typeof t?t.type:t.name||"(anonymous)",info:u,params:h,exec:d});continue}let[p,f,m]=d.resolve(n,l,u,h,d,o);l=p,"retryResolve"in d&&a?.push([d,f]),"execute"in d&&n.actionExecutor({type:d.type,info:u,params:f,exec:d.execute.bind(null,n,f)}),m&&(l=e(l,i,n,m,o,a))}return l}(e,t,i,n,{internalQueue:r,deferredActorIds:o},a);return a?.forEach(([e,t])=>{e.retryResolve(i,s,t)}),s}function ef(e,t,i,n){let r=e,o=[];function a(e,t,n){i.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:i.self,event:t,snapshot:e,_transitions:n}),o.push(e)}if(t.type===l)return a(r=eS(em(r,t,i),{status:"stopped"}),t,[]),{snapshot:r,microstates:o};let c=t;if(c.type!==s){let t=c,s=t.type.startsWith("xstate.error.actor"),l=eg(t,r);if(s&&!l.length)return a(r=eS(e,{status:"error",error:t.error}),t,[]),{snapshot:r,microstates:o};a(r=ed(l,e,i,c,!1,n),t,l)}let d=!0;for(;"active"===r.status;){let e=d?function(e,t){let i=new Set;for(let n of e._nodes.filter(z))e:for(let r of[n].concat(Z(n,void 0)))if(r.always){for(let n of r.always)if(void 0===n.guard||V(n.guard,e.context,t,e)){i.add(n);break e}}return ea(Array.from(i),new Set(e._nodes),e.historyValue)}(r,c):[],t=e.length?r:void 0;if(!e.length){if(!n.length)break;e=eg(c=n.shift(),r)}d=(r=ed(e,r,i,c,!1,n))!==t,a(r,c,e)}return"active"!==r.status&&em(r,c,i),{snapshot:r,microstates:o}}function em(e,t,i){return ep(e,t,i,Object.values(e.children).map(e=>H(e)),[],void 0)}function eg(e,t){return t.machine.getTransitionData(t,e)}let ev=function(e){return function e(t,i){let n=m(t),r=m(i);return"string"==typeof r?"string"==typeof n&&r===n:"string"==typeof n?n in r:Object.keys(n).every(t=>t in r&&e(n[t],r[t]))}(e,this.value)},eC=function(e){return this.tags.has(e)},ey=function(e){let t=this.machine.getTransitionData(this,e);return!!t?.length&&t.some(e=>void 0!==e.target||e.actions.length)},ew=function(){let{_nodes:e,tags:t,machine:i,getMeta:n,toJSON:r,can:o,hasTag:a,matches:s,...l}=this;return{...l,tags:Array.from(t)}},eb=function(){return this._nodes.reduce((e,t)=>(void 0!==t.meta&&(e[t.id]=t.meta),e),{})};function e_(e,t){return{status:e.status,output:e.output,error:e.error,machine:t,context:e.context,_nodes:e._nodes,value:K(t.root,e._nodes),tags:new Set(e._nodes.flatMap(e=>e.tags)),children:e.children,historyValue:e.historyValue||{},matches:ev,hasTag:eC,can:ey,getMeta:eb,toJSON:ew}}function eS(e,t={}){return e_({...e,...t},e.machine)}function eL(e,t,i,n,{event:r,id:o,delay:a},{internalQueue:s}){let l,c=t.machine.implementations.delays;if("string"==typeof r)throw Error(`Only event objects may be used with raise; use raise({ type: "${r}" }) instead`);let d="function"==typeof r?r(i,n):r;if("string"==typeof a){let e=c&&c[a];l="function"==typeof e?e(i,n):e}else l="function"==typeof a?a(i,n):a;return"number"!=typeof l&&s.push(d),[t,{event:d,id:o,delay:l},void 0]}function eE(e,t){let{event:i,delay:n,id:r}=t;if("number"==typeof n)return void e.defer(()=>{let t=e.self;e.system.scheduler.schedule(t,t,i,n,r)})}function ek(e,t){function i(e,t){}return i.type="xstate.raise",i.event=e,i.id=t?.id,i.delay=t?.delay,i.resolve=eL,i.execute=eE,i}let ex=new WeakMap;function eI(e){return{config:e,start:(t,i)=>{let{self:n,system:r,emit:o}=i,a={receivers:void 0,dispose:void 0};ex.set(n,a),a.dispose=e({input:t.input,system:r,self:n,sendBack:e=>{"stopped"!==n.getSnapshot().status&&n._parent&&r._relay(n,n._parent,e)},receive:e=>{a.receivers??=new Set,a.receivers.add(e)},emit:o})},transition:(e,t,i)=>{let n=ex.get(i.self);return t.type===l?(e={...e,status:"stopped",error:void 0},n.dispose?.()):n.receivers?.forEach(e=>e(t)),e},getInitialSnapshot:(e,t)=>({status:"active",output:void 0,error:void 0,input:t}),getPersistedSnapshot:e=>e,restoreSnapshot:e=>e}}let eT="xstate.promise.resolve",eM="xstate.promise.reject",eA=new WeakMap;function eR(e){return{config:e,transition:(e,t,i)=>{if("active"!==e.status)return e;switch(t.type){case eT:{let i=t.data;return{...e,status:"done",output:i,input:void 0}}case eM:return{...e,status:"error",error:t.data,input:void 0};case l:return eA.get(i.self)?.abort(),{...e,status:"stopped",input:void 0};default:return e}},start:(t,{self:i,system:n,emit:r})=>{if("active"!==t.status)return;let o=new AbortController;eA.set(i,o),Promise.resolve(e({input:t.input,system:n,self:i,signal:o.signal,emit:r})).then(e=>{"active"===i.getSnapshot().status&&(eA.delete(i),n._relay(i,i,{type:eT,data:e}))},e=>{"active"===i.getSnapshot().status&&(eA.delete(i),n._relay(i,i,{type:eM,data:e}))})},getInitialSnapshot:(e,t)=>({status:"active",output:void 0,error:void 0,input:t}),getPersistedSnapshot:e=>e,restoreSnapshot:e=>e}}function eO(e,t,i,n,{assignment:r}){if(!t.context)throw Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");let o={},a={context:t.context,event:i.event,spawn:function(e,{machine:t,context:i},n,r){return(o,a)=>{let s=((o,a)=>{if("string"!=typeof o)return M(o,{id:a?.id,parent:e.self,syncSnapshot:a?.syncSnapshot,input:a?.input,src:o,systemId:a?.systemId});{let s=S(t,o);if(!s)throw Error(`Actor logic '${o}' not implemented in machine '${t.id}'`);let l=M(s,{id:a?.id,parent:e.self,syncSnapshot:a?.syncSnapshot,input:"function"==typeof a?.input?a.input({context:i,event:n,self:e.self}):a?.input,src:o,systemId:a?.systemId});return r[l.id]=l,l}})(o,a);return r[s.id]=s,e.defer(()=>{s._processingStatus!==x.Stopped&&s.start()}),s}}(e,t,i.event,o),self:e.self,system:e.system},s={};if("function"==typeof r)s=r(a,n);else for(let e of Object.keys(r)){let t=r[e];s[e]="function"==typeof t?t(a,n):t}return[eS(t,{context:Object.assign({},t.context,s),children:Object.keys(o).length?{...t.children,...o}:t.children}),void 0,void 0]}function eP(e){function t(e,t){}return t.type="xstate.assign",t.assignment=e,t.resolve=eO,t}let eD=new WeakMap;function eF(e,t,i){let n=eD.get(e);return n?t in n||(n[t]=i()):(n={[t]:i()},eD.set(e,n)),n[t]}let eN={},eU=e=>"string"==typeof e?{type:e}:"function"==typeof e?"resolve"in e?{type:e.type}:{type:e.name}:e;var eH=class e{constructor(t,i){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=i._parent,this.key=i._key,this.machine=i._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,i)=>new e(t,{_parent:this,_key:i,_machine:this.machine})):eN,"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=v(this.config.entry).slice(),this.exit=v(this.config.exit).slice(),this.meta=this.config.meta,this.output="final"!==this.type&&this.parent?void 0:this.config.output,this.tags=v(t.tags).slice()}_initialize(){this.transitions=function(e){let t=new Map;if(e.config.on)for(let i of Object.keys(e.config.on)){if(""===i)throw Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');let n=e.config.on[i];t.set(i,w(n).map(t=>Q(e,i,t)))}if(e.config.onDone){let i=`xstate.done.state.${e.id}`;t.set(i,w(e.config.onDone).map(t=>Q(e,i,t)))}for(let i of e.invoke){if(i.onDone){let n=`xstate.done.actor.${i.id}`;t.set(n,w(i.onDone).map(t=>Q(e,n,t)))}if(i.onError){let n=`xstate.error.actor.${i.id}`;t.set(n,w(i.onError).map(t=>Q(e,n,t)))}if(i.onSnapshot){let n=`xstate.snapshot.${i.id}`;t.set(n,w(i.onSnapshot).map(t=>Q(e,n,t)))}}for(let i of e.after){let e=t.get(i.eventType);e||(e=[],t.set(i.eventType,e)),e.push(i)}return t}(this),this.config.always&&(this.always=w(this.config.always).map(e=>Q(this,"",e))),Object.keys(this.states).forEach(e=>{this.states[e]._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(eU),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(e=>`#${e.id}`),source:`#${this.id}`,actions:this.initial.actions.map(eU),eventType:null})}:void 0,history:this.history,states:g(this.states,e=>e.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(e=>({...e,actions:e.actions.map(eU)})),entry:this.entry.map(eU),exit:this.exit.map(eU),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 eF(this,"invoke",()=>v(this.config.invoke).map((e,t)=>{var i,n;let{src:r,systemId:o}=e,a=e.id??(i=this.id,`${t}.${i}`),s="string"==typeof r?r:`xstate.invoke.${n=this.id,`${t}.${n}`}`;return{...e,src:s,id:a,systemId:o,toJSON(){let{onDone:t,onError:i,...n}=e;return{...n,type:"xstate.invoke",src:s,id:a}}}}))}get on(){return eF(this,"on",()=>[...this.transitions].flatMap(([e,t])=>t.map(t=>[e,t])).reduce((e,[t,i])=>(e[t]=e[t]||[],e[t].push(i),e),{}))}get after(){return eF(this,"delayedTransitions",()=>{var e;let t;return e=this,(t=e.config.after)?Object.keys(t).flatMap(i=>{var n;let r,o,a=t[i],s=Number.isNaN(+i)?i:+i,l=(n=e.id,o=(r={type:`xstate.after.${s}.${n}`}).type,e.entry.push(ek(r,{id:o,delay:s})),e.exit.push(O(o)),o);return v("string"==typeof a?{target:a}:a).map(e=>({...e,event:l,delay:s}))}).map(t=>{let{delay:i}=t;return{...Q(e,t.event,t),delay:i}}):[]})}get initial(){return eF(this,"initial",()=>(function(e,t){let i="string"==typeof t?e.states[t]:t?e.states[t.target]:void 0;if(!i&&t)throw Error(`Initial state node "${t}" not found on parent state node #${e.id}`);let n={source:e,actions:t&&"string"!=typeof t?v(t.actions):[],eventType:null,reenter:!1,target:i?[i]:[],toJSON:()=>({...n,source:`#${e.id}`,target:i?[`#${i.id}`]:[]})};return n})(this,this.config.initial))}next(e,t){let i,n=t.type,r=[];for(let o of eF(this,`candidates-${n}`,()=>{var e;return e=this,e.transitions.get(n)||[...e.transitions.keys()].filter(e=>{if("*"===e)return!0;if(!e.endsWith(".*"))return!1;let t=e.split("."),i=n.split(".");for(let e=0;e<t.length;e++){let n=t[e],r=i[e];if("*"===n)return e===t.length-1;if(n!==r)return!1}return!0}).sort((e,t)=>t.length-e.length).flatMap(t=>e.transitions.get(t))})){let{guard:a}=o,s=e.context,l=!1;try{l=!a||V(a,s,t,e)}catch(t){let e="string"==typeof a?a:"object"==typeof a?a.type:void 0;throw Error(`Unable to evaluate guard ${e?`'${e}' `:""}in transition for event '${n}' in state node '${this.id}':
${t.message}`)}if(l){r.push(...o.actions),i=o;break}}return i?[i]:void 0}get events(){return eF(this,"events",()=>{let{states:e}=this,t=new Set(this.ownEvents);if(e)for(let i of Object.keys(e)){let n=e[i];if(n.states)for(let e of n.events)t.add(`${e}`)}return Array.from(t)})}get ownEvents(){return Array.from(new Set([...this.transitions.keys()].filter(e=>this.transitions.get(e).some(e=>!(!e.target&&!e.actions.length&&!e.reenter)))))}},e$=class e{constructor(e,t){this.config=e,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=e.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 eH(e,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){let{actions:i,guards:n,actors:r,delays:o}=this.implementations;return new e(this.config,{actions:{...i,...t.actions},guards:{...n,...t.guards},actors:{...r,...t.actors},delays:{...o,...t.delays}})}resolveState(e){var t;let i=K(t=this.root,[...W(er(t,e.value))]),n=W(er(this.root,i));return e_({_nodes:[...n],context:e.context||{},children:{},status:q(n,this.root)?"done":e.status||"active",output:e.output,error:e.error,historyValue:e.historyValue},this)}transition(e,t,i){return ef(e,t,i,[]).snapshot}microstep(e,t,i){return ef(e,t,i,[]).microstates}getTransitionData(e,t){return function e(t,i,n,r){if("string"==typeof i){let e;return(e=ei(t,i).next(n,r))&&e.length?e:t.next(n,r)}if(1===Object.keys(i).length){let o,a;return(a=e(ei(t,(o=Object.keys(i))[0]),i[o[0]],n,r))&&a.length?a:t.next(n,r)}let o=[];for(let a of Object.keys(i)){let s=i[a];if(!s)continue;let l=e(ei(t,a),s,n,r);l&&o.push(...l)}return o.length?o:t.next(n,r)}(this.root,e.value,e,t)||[]}getPreInitialState(e,t,i){let{context:n}=this.config,r=e_({context:"function"!=typeof n&&n?n:{},_nodes:[this.root],children:{},status:"active"},this);return"function"==typeof n?ep(r,t,e,[eP(({spawn:e,event:t,self:i})=>n({spawn:e,input:t.input,self:i}))],i,void 0):r}getInitialSnapshot(e,t){let i=u(t),n=[],r=this.getPreInitialState(e,i,n),{snapshot:o}=ef(ed([{target:[...et(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],r,e,i,!0,n),i,e,n);return o}start(e){Object.values(e.children).forEach(e=>{"active"===e.getSnapshot().status&&e.start()})}getStateNodeById(e){let t=f(e),i=t.slice(1),n=Y(t[0])?t[0].slice(1):t[0],r=this.idMap.get(n);if(!r)throw Error(`Child state node '#${n}' does not exist on machine '${this.id}'`);return en(r,i)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(e,t){return function(e,t){let{_nodes:i,tags:n,machine:r,children:o,context:a,can:s,hasTag:l,matches:c,getMeta:d,toJSON:u,...h}=e,p={};for(let e in o){let i=o[e];p[e]={snapshot:i.getPersistedSnapshot(t),src:i.src,systemId:i.systemId,syncSnapshot:i._syncSnapshot}}return{...h,context:function e(t){let i;for(let n in t){let r=t[n];if(r&&"object"==typeof r)if("sessionId"in r&&"send"in r&&"ref"in r)(i??=Array.isArray(t)?t.slice():{...t})[n]={xstate$$type:1,id:r.id};else{let o=e(r);o!==r&&((i??=Array.isArray(t)?t.slice():{...t})[n]=o)}}return i??t}(a),children:p,historyValue:function(e){if("object"!=typeof e||null===e)return{};let t={};for(let i in e){let n=e[i];Array.isArray(n)&&(t[i]=n.map(e=>({id:e.id})))}return t}(h.historyValue)}}(e,t)}restoreSnapshot(e,t){let i={},n=e.children;Object.keys(n).forEach(e=>{let r=n[e],o=r.snapshot,a=r.src,s="string"==typeof a?S(this,a):a;s&&(i[e]=M(s,{id:e,parent:t.self,syncSnapshot:r.syncSnapshot,snapshot:o,src:a,systemId:r.systemId}))});let r=function(e,t){if(!t||"object"!=typeof t)return{};let i={};for(let n in t)for(let r of t[n]){let t=function(e,t){if(t instanceof eH)return t;try{return e.machine.getStateNodeById(t.id)}catch{}}(e,r);t&&(i[n]??=[],i[n].push(t))}return i}(this.root,e.historyValue),o=e_({...e,children:i,_nodes:Array.from(W(er(this.root,e.value))),historyValue:r},this),a=new Set;return!function e(t,i){if(!a.has(t))for(let n in a.add(t),t){let r=t[n];if(r&&"object"==typeof r){if("xstate$$type"in r&&1===r.xstate$$type){t[n]=i[r.id];continue}e(r,i)}}}(o.context,i),o}};function eB(e,t,i,n,{event:r}){return[t,{event:"function"==typeof r?r(i,n):r},void 0]}function eV(e,{event:t}){e.defer(()=>e.emit(t))}function ez(e){function t(e,t){}return t.type="xstate.emit",t.event=e,t.resolve=eB,t.execute=eV,t}let ej=((o={}).Parent="#_parent",o.Internal="#_internal",o);function eZ(e,t,i,n,{to:r,event:o,id:a,delay:s},l){let c,d,u=t.machine.implementations.delays;if("string"==typeof o)throw Error(`Only event objects may be used with sendTo; use sendTo({ type: "${o}" }) instead`);let h="function"==typeof o?o(i,n):o;if("string"==typeof s){let e=u&&u[s];c="function"==typeof e?e(i,n):e}else c="function"==typeof s?s(i,n):s;let p="function"==typeof r?r(i,n):r;if("string"==typeof p){if(!(d=p===ej.Parent?e.self._parent:p===ej.Internal?e.self:p.startsWith("#_")?t.children[p.slice(2)]:l.deferredActorIds?.includes(p)?p:t.children[p]))throw Error(`Unable to send event to actor '${p}' from machine '${t.machine.id}'.`)}else d=p||e.self;return[t,{to:d,targetId:"string"==typeof p?p:void 0,event:h,id:a,delay:c},void 0]}function eW(e,t,i){"string"==typeof i.to&&(i.to=t.children[i.to])}function eG(e,t){e.defer(()=>{let{to:i,event:n,delay:r,id:o}=t;"number"==typeof r?e.system.scheduler.schedule(e.self,i,n,r,o):e.system._relay(e.self,i,"xstate.error"===n.type?d(e.self.id,n.data):n)})}function eK(e,t,i){function n(e,t){}return n.type="xstate.sendTo",n.to=e,n.event=t,n.id=i?.id,n.delay=i?.delay,n.resolve=eZ,n.retryResolve=eW,n.execute=eG,n}function eq(e,t,i,n,{collect:r}){let o=[],a=function(e){o.push(e)};return a.assign=(...e)=>{o.push(eP(...e))},a.cancel=(...e)=>{o.push(O(...e))},a.raise=(...e)=>{o.push(ek(...e))},a.sendTo=(...e)=>{o.push(eK(...e))},a.sendParent=(...e)=>{o.push(function(e,t){return eK(ej.Parent,e,t)}(...e))},a.spawnChild=(...e)=>{o.push(F(...e))},a.stopChild=(...e)=>{o.push(H(...e))},a.emit=(...e)=>{o.push(ez(...e))},r({context:i.context,event:i.event,enqueue:a,check:e=>V(e,t.context,i.event,t),self:e.self,system:e.system},n),[t,void 0,o]}function eY(e){function t(e,t){}return t.type="xstate.enqueueActions",t.collect=e,t.resolve=eq,t}function eQ(e,t,i,n,{value:r,label:o}){return[t,{value:"function"==typeof r?r(i,n):r,label:o},void 0]}function eX({logger:e},{value:t,label:i}){i?e(i,t):e(t)}function eJ(e=({context:e,event:t})=>({context:e,event:t}),t){function i(e,t){}return i.type="xstate.log",i.value=e,i.label=t,i.resolve=eQ,i.execute=eX,i}}