1import{d as kt,m as ge,p as fe,f as Ze,t as Ee,a as xt,b as It,e as me,E as At,h as Mt,v as $t}from"./B3fy5JdC.js";import{stegaEncodeSourceMap as Ot}from"./BGA4RB1G.js";import{a as Ue}from"./DeMPSf6W.js";import"./Cl1E8ht_.js";import"./DFHKiizX.js";const b=[];for(let e=0;e<256;++e)b.push((e+256).toString(16).slice(1));function Rt(e,t=0){return(b[e[t+0]]+b[e[t+1]]+b[e[t+2]]+b[e[t+3]]+"-"+b[e[t+4]]+b[e[t+5]]+"-"+b[e[t+6]]+b[e[t+7]]+"-"+b[e[t+8]]+b[e[t+9]]+"-"+b[e[t+10]]+b[e[t+11]]+b[e[t+12]]+b[e[t+13]]+b[e[t+14]]+b[e[t+15]]).toLowerCase()}let he;const Ct=new Uint8Array(16);function qt(){if(!he){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");he=crypto.getRandomValues.bind(crypto)}return he(Ct)}const jt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Je={randomUUID:jt};function Qe(e,t,s){if(Je.randomUUID&&!e)return Je.randomUUID();e=e||{};const n=e.random??e.rng?.()??qt();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Rt(n)}function Dt(){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 Lt(){const e=Dt();if(e.__xstate__)return e.__xstate__}const Ut=e=>{if(typeof window>"u")return;const t=Lt();t&&t.register(e)};class Be{constructor(t){this._process=t,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(t){const s={value:t,next:null};if(this._current){this._last.next=s,this._last=s;return}this._current=s,this._last=s,this._active&&this.flush()}flush(){for(;this._current;){const t=this._current;this._process(t.value),this._current=t.next}this._last=null}}const et=".",Jt="",tt="",Bt="#",Ht="*",st="xstate.init",Pt="xstate.error",se="xstate.stop";function Wt(e,t){return{type:`xstate.after.${e}.${t}`}}function ve(e,t){return{type:`xstate.done.state.${e}`,output:t}}function zt(e,t){return{type:`xstate.done.actor.${e}`,output:t,actorId:e}}function nt(e,t){return{type:`xstate.error.actor.${e}`,error:t,actorId:e}}function it(e){return{type:st,input:e}}function I(e){setTimeout(()=>{throw e})}const Gt=typeof Symbol=="function"&&Symbol.observable||"@@observable";function rt(e,t){const s=He(e),n=He(t);return typeof n=="string"?typeof s=="string"?n===s:!1:typeof s=="string"?s in n:Object.keys(s).every(i=>i in n?rt(s[i],n[i]):!1)}function ke(e){if(at(e))return e;const t=[];let s="";for(let n=0;n<e.length;n++){switch(e.charCodeAt(n)){case 92:s+=e[n+1],n++;continue;case 46:t.push(s),s="";continue}s+=e[n]}return t.push(s),t}function He(e){if(ws(e))return e.value;if(typeof e!="string")return e;const t=ke(e);return Kt(t)}function Kt(e){if(e.length===1)return e[0];const t={};let s=t;for(let n=0;n<e.length-1;n++)if(n===e.length-2)s[e[n]]=e[n+1];else{const i=s;s={},i[e[n]]=s}return t}function Pe(e,t){const s={},n=Object.keys(e);for(let i=0;i<n.length;i++){const r=n[i];s[r]=t(e[r],r,e,i)}return s}function ot(e){return at(e)?e:[e]}function M(e){return e===void 0?[]:ot(e)}function _e(e,t,s,n){return typeof e=="function"?e({context:t,event:s,self:n}):e}function at(e){return Array.isArray(e)}function Nt(e){return e.type.startsWith("xstate.error.actor")}function U(e){return ot(e).map(t=>typeof t>"u"||typeof t=="string"?{target:t}:t)}function ct(e){if(!(e===void 0||e===Jt))return M(e)}function be(e,t,s){const n=typeof e=="object",i=n?e:void 0;return{next:(n?e.next:e)?.bind(i),error:(n?e.error:t)?.bind(i),complete:(n?e.complete:s)?.bind(i)}}function We(e,t){return`${t}.${e}`}function xe(e,t){const s=t.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!s)return e.implementations.actors[t];const[,n,i]=s,o=e.getStateNodeById(i).config.invoke;return(Array.isArray(o)?o[n]:o).src}function ut(e,t){if(t===e||t===Ht)return!0;if(!t.endsWith(".*"))return!1;const s=t.split("."),n=e.split(".");for(let i=0;i<s.length;i++){const r=s[i],o=n[i];if(r==="*")return i===s.length-1;if(r!==o)return!1}return!0}function ze(e,t){return`${e.sessionId}.${t}`}let Yt=0;function Ft(e,t){const s=new Map,n=new Map,i=new WeakMap,r=new Set,o={},{clock:a,logger:d}=t,f={schedule:(c,h,l,y,g=Math.random().toString(36).slice(2))=>{const S={source:c,target:h,event:l,delay:y,id:g,startedAt:Date.now()},w=ze(c,g);u._snapshot._scheduledEvents[w]=S;const de=a.setTimeout(()=>{delete o[w],delete u._snapshot._scheduledEvents[w],u._relay(c,h,l)},y);o[w]=de},cancel:(c,h)=>{const l=ze(c,h),y=o[l];delete o[l],delete u._snapshot._scheduledEvents[l],y!==void 0&&a.clearTimeout(y)}
1,cancelAll:c=>{for(const h in u._snapshot._scheduledEvents){const l=u._snapshot._scheduledEvents[h];l.source===c&&f.cancel(c,l.id)}}},p=c=>{if(!r.size)return;const h={...c,rootId:e.sessionId};r.forEach(l=>l.next?.(h))},u={_snapshot:{_scheduledEvents:(t?.snapshot&&t.snapshot.scheduler)??{}},_bookId:()=>`x:${Yt++}`,_register:(c,h)=>(s.set(c,h),c),_unregister:c=>{s.delete(c.sessionId);const h=i.get(c);h!==void 0&&(n.delete(h),i.delete(c))},get:c=>n.get(c),getAll:()=>Object.fromEntries(n.entries()),_set:(c,h)=>{const l=n.get(c);if(l&&l!==h)throw new Error(`Actor with system ID '${c}' already exists.`);n.set(c,h),i.set(h,c)},inspect:c=>{const h=be(c);return r.add(h),{unsubscribe(){r.delete(h)}}},_sendInspectionEvent:p,_relay:(c,h,l)=>{u._sendInspectionEvent({type:"@xstate.event",sourceRef:c,actorRef:h,event:l}),h._send(l)},scheduler:f,getSnapshot:()=>({_scheduledEvents:{...u._snapshot._scheduledEvents}}),start:()=>{const c=u._snapshot._scheduledEvents;u._snapshot._scheduledEvents={};for(const h in c){const{source:l,target:y,event:g,delay:S,id:w}=c[h];f.schedule(l,y,g,S,w)}},_clock:a,_logger:d};return u}let le=!1;const Ie=1;let T=(function(e){return e[e.NotStarted=0]="NotStarted",e[e.Running=1]="Running",e[e.Stopped=2]="Stopped",e})({});const Xt={clock:{setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e)},logger:console.log.bind(console),devTools:!1};class Vt{constructor(t,s){this.logic=t,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new Be(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=T.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 n={...Xt,...s},{clock:i,logger:r,parent:o,syncSnapshot:a,id:d,systemId:f,inspect:p}=n;this.system=o?o.system:Ft(this,{clock:i,logger:r}),p&&!o&&this.system.inspect(be(p)),this.sessionId=this.system._bookId(),this.id=d??this.sessionId,this.logger=s?.logger??this.system._logger,this.clock=s?.clock??this.system._clock,this._parent=o,this._syncSnapshot=a,this.options=n,this.src=n.src??t,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:u=>{this._deferred.push(u)},system:this.system,stopChild:u=>{if(u._parent!==this)throw new Error(`Cannot stop child actor ${u.id} of ${this.id} because it is not a child`);u._stop()},emit:u=>{const c=this.eventListeners.get(u.type),h=this.eventListeners.get("*");if(!c&&!h)return;const l=[...c?c.values():[],...h?h.values():[]];for(const y of l)try{y(u)}catch(g){I(g)}},actionExecutor:u=>{const c=()=>{if(this._actorScope.system._sendInspectionEvent({type:"@xstate.action",actorRef:this,action:{type:u.type,params:u.params}}),!u.exec)return;const h=le;try{le=!0,u.exec(u.info,u.params)}finally{le=h}};this._processingStatus===T.Running?c():this._deferred.push(c)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),f&&(this.systemId=f,this.system._set(f,this)),this._initState(s?.snapshot??s?.state),f&&this._snapshot.status!=="active"&&this.system._unregister(this)}_initState(t){try{this._snapshot=t?this.logic.restoreSnapshot?this.logic.restoreSnapshot(t,this._actorScope):t:this.logic.getInitialSnapshot(this._actorScope,this.options?.input)}catch(s){this._snapshot={status:"error",output:void 0,error:s}}}update(t,s){this._snapshot=t;let n;for(;n=this._deferred.shift();)try{n()}catch(i){this._deferred.length=0,this._snapshot={...t,status:"error",error:i}}switch(this._snapshot.status){case"active":for(const i of this.observers)try{i.next?.(t)}catch(r){I(r)}break;case"done":for(const i of this.observers)try{i.next?.(t)}catch(r){I(r)}this._stopProcedure(),this._complete(),this._doneEvent=zt(this.id,this._snapshot.output),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error);break}this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:s,snapshot:t})}subscribe(t,s,n){const i=be(t,s,n);if(this._processingStatus!==T.Stopped)this.observers.add(i);else switch(this._snapshot.status){case"done":try{i.complete?.()}catch(r){I(r)}break;case"error":{const r=this._snapshot.error;if(!i.error)I(r);else try{i.error(r)}catch(o){I(o)}break}}return{unsubscribe:()=>{this.observers.delete(i)}}}on(t,s){let n=this.eventListeners.get(t);n||(n=new Set,this.eventListeners.set(t,n));const i=s.bind(void 0);return n.add(i),{unsubscribe:()=>{n.delete(i)}}}
1start(){if(this._processingStatus===T.Running)return this;this._syncSnapshot&&this.subscribe({next:n=>{n.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:n})},error:()=>{}}),this.system._register(this.sessionId,this),this.systemId&&this.system._set(this.systemId,this),this._processingStatus=T.Running;const t=it(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:t}),this._snapshot.status){case"done":return this.update(this._snapshot,t),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(n){return this._snapshot={...this._snapshot,status:"error",error:n},this._error(n),this}return this.update(this._snapshot,t),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(t){let s,n;try{s=this.logic.transition(this._snapshot,t,this._actorScope)}catch(i){n={err:i}}if(n){const{err:i}=n;this._snapshot={...this._snapshot,status:"error",error:i},this._error(i);return}this.update(s,t),t.type===se&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===T.Stopped?this:(this.mailbox.clear(),this._processingStatus===T.NotStarted?(this._processingStatus=T.Stopped,this):(this.mailbox.enqueue({type:se}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){for(const t of this.observers)try{t.complete?.()}catch(s){I(s)}this.observers.clear(),this.eventListeners.clear()}_reportError(t){if(!this.observers.size){this._parent||I(t),this.eventListeners.clear();return}let s=!1;for(const n of this.observers){const i=n.error;s||=!i;try{i?.(t)}catch(r){I(r)}}this.observers.clear(),this.eventListeners.clear(),s&&I(t)}_error(t){this._stopProcedure(),this._reportError(t),this._parent&&this.system._relay(this,this._parent,nt(this.id,t))}_stopProcedure(){return this._processingStatus!==T.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new Be(this._process.bind(this)),this._processingStatus=T.Stopped,this.system._unregister(this),this)}_send(t){this._processingStatus!==T.Stopped&&this.mailbox.enqueue(t)}send(t){this.system._relay(void 0,this,t)}attachDevTools(){const{devTools:t}=this.options;t&&(typeof t=="function"?t:Ut)(this)}toJSON(){return{xstate$$type:Ie,id:this.id}}getPersistedSnapshot(t){return this.logic.getPersistedSnapshot(this._snapshot,t)}[Gt](){return this}getSnapshot(){return this._snapshot}}function Z(e,...[t]){return new Vt(e,t)}function Zt(e,t,s,n,{sendId:i}){const r=typeof i=="function"?i(s,n):i;return[t,{sendId:r},void 0]}function Qt(e,t){e.defer(()=>{e.system.scheduler.cancel(e.self,t.sendId)})}function Ae(e){function t(s,n){}return t.type="xstate.cancel",t.sendId=e,t.resolve=Zt,t.execute=Qt,t}function es(e,t,s,n,{id:i,systemId:r,src:o,input:a,syncSnapshot:d}){const f=typeof o=="string"?xe(t.machine,o):o,p=typeof i=="function"?i(s):i;let u,c;return f&&(c=typeof a=="function"?a({context:t.context,event:s.event,self:e.self}):a,u=Z(f,{id:p,src:o,parent:e.self,syncSnapshot:d,systemId:r,input:c})),[D(t,{children:{...t.children,[p]:u}}),{id:i,systemId:r,actorRef:u,src:o,input:c},void 0]}function ts(e,{actorRef:t}){t&&e.defer(()=>{t._processingStatus!==T.Stopped&&t.start()})}function Me(...[e,{id:t,systemId:s,input:n,syncSnapshot:i=!1}={}]){function r(o,a){}return r.type="xstate.spawnChild",r.id=t,r.systemId=s,r.src=e,r.input=n,r.syncSnapshot=i,r.resolve=es,r.execute=ts,r}function ss(e,t,s,n,{actorRef:i}){const r=typeof i=="function"?i(s,n):i,o=typeof r=="string"?t.children[r]:r;let a=t.children;return o&&(a={...a},delete a[o.id]),[D(t,{children:a}),o,void 0]}function dt(e,t){const s=t.getSnapshot();if(s&&"children"in s)for(const n of Object.values(s.children))dt(e,n);e.system._unregister(t)}function ns(e,t){if(t){if(dt(e,t),t._processingStatus!==T.Running){e.stopChild(t);return}e.defer(()=>{e.stopChild(t)})}}function Q(e){function t(s,n){}return t.type="xstate.stopChild",t.actorRef=e,t.resolve=ss,t.execute=ns,t}function ce(e,t,s,n){const{machine:i}=n,r=typeof e=="function",o=r?e:i.implementations.guards[typeof e=="string"?e:e.type];if(!r&&!o)throw new Error(`Guard '${typeof e=="string"?e:e.type}' is not implemented.'.`);if(typeof o!="function")return ce(o,t,s,n);const a={context:t,event:s},d=r||typeof e=="string"?void 0:"params"in e?typeof e.params=="function"?e.params({context:t,event:s}):e.params:void 0;return"check"in o?o.check(n,a,o):o(a,d)}const $e=e=>e.type==="atomic"||e.type==="final";function G(e){return Object.values(e.states).filter(t=>t.type!=="history")}function ee(e,t){const s=[];if(t===e)return s;let n=e.parent;for(;n&&n!==t;)s.push(n),n=n.parent;return s}function ne(e){const t=new Set(e),s=ht(t);for(const n of t)if(n.type==="compound"&&(!s.get(n)||!s.get(n).length))Ge(n).forEac
1h(i=>t.add(i));else if(n.type==="parallel"){for(const i of G(n))if(i.type!=="history"&&!t.has(i)){const r=Ge(i);for(const o of r)t.add(o)}}for(const n of t){let i=n.parent;for(;i;)t.add(i),i=i.parent}return t}function ft(e,t){const s=t.get(e);if(!s)return{};if(e.type==="compound"){const i=s[0];if(i){if($e(i))return i.key}else return{}}const n={};for(const i of s)n[i.key]=ft(i,t);return n}function ht(e){const t=new Map;for(const s of e)t.has(s)||t.set(s,[]),s.parent&&(t.has(s.parent)||t.set(s.parent,[]),t.get(s.parent).push(s));return t}function lt(e,t){const s=ne(t);return ft(e,ht(s))}function Oe(e,t){return t.type==="compound"?G(t).some(s=>s.type==="final"&&e.has(s)):t.type==="parallel"?G(t).every(s=>Oe(e,s)):t.type==="final"}const ue=e=>e[0]===Bt;function is(e,t){return e.transitions.get(t)||[...e.transitions.keys()].filter(n=>ut(t,n)).sort((n,i)=>i.length-n.length).flatMap(n=>e.transitions.get(n))}function rs(e){const t=e.config.after;if(!t)return[];const s=i=>{const r=Wt(i,e.id),o=r.type;return e.entry.push(P(r,{id:o,delay:i})),e.exit.push(Ae(o)),o};return Object.keys(t).flatMap(i=>{const r=t[i],o=typeof r=="string"?{target:r}:r,a=Number.isNaN(+i)?i:+i,d=s(a);return M(o).map(f=>({...f,event:d,delay:a}))}).map(i=>{const{delay:r}=i;return{...C(e,i.event,i),delay:r}})}function C(e,t,s){const n=ct(s.target),i=s.reenter??!1,r=cs(e,n),o={...s,actions:M(s.actions),guard:s.guard,target:r,source:e,reenter
1:i,eventType:t,toJSON:()=>({...o,source:`#${e.id}`,target:r?r.map(a=>`#${a.id}`):void 0})};return o}function os(e){const t=new Map;if(e.config.on)for(const s of Object.keys(e.config.on)){if(s===tt)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const n=e.config.on[s];t.set(s,U(n).map(i=>C(e,s,i)))}if(e.config.onDone){const s=`xstate.done.state.${e.id}`;t.set(s,U(e.config.onDone).map(n=>C(e,s,n)))}for(const s of e.invoke){if(s.onDone){const n=`xstate.done.actor.${s.id}`;t.set(n,U(s.onDone).map(i=>C(e,n,i)))}if(s.onError){const n=`xstate.error.actor.${s.id}`;t.set(n,U(s.onError).map(i=>C(e,n,i)))}if(s.onSnapshot){const n=`xstate.snapshot.${s.id}`;t.set(n,U(s.onSnapshot).map(i=>C(e,n,i)))}}for(const s of e.after){let n=t.get(s.eventType);n||(n=[],t.set(s.eventType,n)),n.push(s)}return t}function as(e,t){const s=typeof t=="string"?e.states[t]:t?e.states[t.target]:void 0;if(!s&&t)throw new Error(`Initial state node "${t}" not found on parent state node #${e.id}`);const n={source:e,actions:!t||typeof t=="string"?[]:M(t.actions),eventType:null,reenter:!1,target:s?[s]:[],toJSON:()=>({...n,source:`#${e.id}`,target:s?[`#${s.id}`]:[]})};return n}function cs(e,t){if(t!==void 0)return t.map(s=>{if(typeof s!="string")return s;if(ue(s))return e.machine.getStateNodeById(s);const n=s[0]===et;if(n&&!e.parent)return ie(e,s.slice(1));const i=n?e.key+s:s;if(e.parent)try{return ie(e.parent,i)}catch(r){throw new Error(`Invalid transition definition for state node '${e.id}': 2${r.message}`)}else throw new Error(`Invalid target: "${s}" is not a valid target from the root node. Did you mean ".${s}"?`)})}function pt(e){const t=ct(e.config.target);return t?{target:t.map(s=>typeof s=="string"?ie(e.parent,s):s)}:e.parent.initial}function q(e){return e.type==="history"}function Ge(e){const t=yt(e);for(const s of t)for(const n of ee(s,e))t.add(n);return t}function yt(e){const t=new Set;function s(n){if(!t.has(n)){if(t.add(n),n.type==="compound")s(n.initial.target[0]);else if(n.type==="parallel")for(const i of G(n))s(i)}}return s(e),t}function K(e,t){if(ue(t))return e.machine.getStateNodeById(t);if(!e.states)throw new Error(`Unable to retrieve child state '${t}' from '${e.id}'; no child states exist.`);const s=e.states[t];if(!s)throw new Error(`Child state '${t}' does not exist on '${e.id}'`);return s}function ie(e,t){if(typeof t=="string"&&ue(t))try{return e.machine.getStateNodeById(t)}catch{}const s=ke(t).slice();let n=e;for(;s.length;){const i=s.shift();if(!i.length)break;n=K(n,i)}return n}function re(e,t){if(typeof t=="string"){const i=e.states[t];if(!i)throw new Error(`State '${t}' does not exist on '${e.id}'`);return[e,i]}const s=Object.keys(t),n=s.map(i=>K(e,i)).filter(Boolean);return[e.machine.root,e].concat(n,s.reduce((i,r)=>{const o=K(e,r);if(!o)return i;const a=re(o,t[r]);return i.concat(a)},[]))}function us(e,t,s,n){const r=K(e,t).next(s,n);return!r||!r.length?e.next(s,n):r}function ds(e,t,s,n){const i=Object.keys(t),r=K(e,i[0]),o=Re(r,t[i[0]],s,n);return!o||!o.length?e.next(s,n):o}function fs(e,t,s,n){const i=[];for(const r of Object.keys(t)){const o=t[r];if(!o)continue;const a=K(e,r),d=Re(a,o,s,n);d&&i.push(...d)}return i.length?i:e.next(s,n)}function Re(e,t,s,n){return typeof t=="string"?us(e,t,s,n):Object.keys(t).length===1?ds(e,t,s,n):fs(e,t,s,n)}function hs(e){return Object.keys(e.states).map(t=>e.states[t]).filter(t=>t.type==="history")}function $(e,t){let s=e;for(;s.parent&&s.parent!==t;)s=s.parent;return s.parent===t}function ls(e,t){const s=new Set(e),n=new Set(t);for(const i of s)if(n.has(i))return!0;for(const i of n)if(s.has(i))return!0;return!1}function gt(e,t,s){const n=new Set;for(const i of e){let r=!1;const o=new Set;for(const a of n)if(ls(Se([i],t,s),Se([a],t,s)))if($(i.source,a.source))o.add(a);else{r=!0;break}if(!r){for(const a of o)n.delete(a);n.add(i)}}return Array.from(n)}function ps(e){const[t,...s]=e;for(const n of ee(t,void 0))if(s.every(i=>$(i,n)))return n}function Ce(e,t){if(!e.target)return[];const s=new Set;for(const n of e.target)if(q(n))if(t[n.id])for(const i of t[n.id])s.add(i);else for(const i of Ce(pt(n),t))s.add(i);else s.add(n);return[...s]}function mt(e,t){const s=Ce(e,t);if(!s)return;if(!e.reenter&&s.every(i=>i===e.source||$(i,e.source)))return e.source;const n=ps(s.concat(e.source));if(n)return n;if(!e.reenter)return e.source.machine.root}function Se(e,t,s){const n=new Set;for(const i of e)if(i.target?.length){const r=mt(i,s);i.reenter&&i.source===r&&n.add(r);for(const o of t)$(o,r)&&n.add(o)}return[...n]}function ys(e,t){if(e.length!==t.size)return!1;for(const s of e)if(!t.has(s))return!1;return!0}function Te(e,t,s,n,i,r){if(!e.length)return t;const o=new Set(t._nodes);let a=t.historyValue;const d=gt(e,o,a);let f=t;i||([f,a]=_s(f,n,s,d,o,a,r,s.actionExecutor)),f=N(f,n,s,d.flatMap(u=>u.actions),r,void 0),f=ms(f,n,s,d,o,r,a,i);const p=[...o];f.status==="done"&&(f=N(f,n,s,p.sort((u,c)=>c.order-u.order).flatMap(u=>u.exit),r,void 0));try{return a===t.historyValue&&ys(t._nodes,o)?f:D(f,{_nodes:p,historyValue:a})}catch(u){throw u}}function gs(e,t,s,n,i){if(n.output===void 0)return;const r=ve(i.id,i.output!==void 0&&i.parent?_e(i.output,e.context,t,s.self):void 0);return _e(n.output,e.context,r,s.self)}function ms(e,t,s,n,i,r,o,a){let d=e;const f=new Set,p=new Set;vs(n,o,p,f),a&&p.add(e.machine.root);const u=new Set;for(const c of[...f].sort((h,l)=>h.order-l.order)){i.add(c);const h=[];h.push(...c.entry);for(const l of c.invoke)h.push(Me(l.src,{...l,syncSnapshot:!!l.onSnapshot}));if(p.has(c)){const l=c.initial.actions;h.push(...l)}if(d=N(d,t,s,h,r,c.invoke.map(l=>l.id)),c.type==="final"){const l=c.parent;let y=l?.type==="parallel"?l:l?.parent,g=y||c;for(l?.type==="compound"&&r.push(ve(l.id,c.output!==void 0?_e(c.output,d.context,t,s.self):void 0));y?.type==="parallel"&&!u.has(y)&&Oe(i,y);)u.add(y),r.push(ve(y.id)),g=y,y=y.parent;if(y)continue;d=D(d,{status:"done",output:gs(d,t,s,d.machine.root,g)})}}return d}function vs(e,t,s,n){for(const i of e){const r=mt(i,t);for(const a of i.target||[])!q(a)&&(i.source!==a||i.source!==r||i.reenter)&&(n.add(a),s.add(a)),B(a,t,s,n);const o=Ce(i,t);for(const a of o){const d=ee(a,r);r?.type==="parallel"&&d.push(r),vt(n,t,s,d,!i.source.parent&&i.reenter?void 0:r)}}}function B(e,t,s,n){if(q(e))if(t[e.id]){const i=t[e.id];for(const r of i)n.add(r),B(r,t,s,n);for(const r of i)pe(r,e.parent,n,t,s)}else{const i=pt(e);for(const r of i.target)n.add(r),i===e.parent?.initial&&s.add(e.parent),B(r,t,s,n);for(const r of i.target)pe(r,e.parent,n,t,s)}else if(e.type==="compound"){const[i]=e.initial.target;q(i)||(n.add(i),s.add(i)),B(i,t,s,n),pe(i,e,n,t,s)}else if(e.type==="parallel")for(const i of G(e).filter(r=>!q(r)))[...n].some(r=>$(r,i))||(q(i)||(n.add(i),s.add(i)),B(i,t,s,n))}function vt(e,t,s,n,i){for(const r of n)if((!i||$(r,i))&&e.add(r),r.type==="parallel")for(const o of G(r).filter(a=>!q(a)))[...e].some(a=>$(a,o))||(e.add(o),B(o,t,s,e))}function pe(e,t,s,n,i){vt(s,n,i,ee(e,t))}function _s(e,t,s,n,i,r,o,a){let d=e;const f=Se(n,i,r);f.sort((u,c)=>c.order-u.order);let p;for(const u of f)for(const c of hs(u)){let h;c.history==="deep"?h=l=>$e(l)&&$(l,u):h=l=>l.parent===u,p??={...r},p[c.id]=Array.from(i).filter(h)}for(const u of f)d=N(d,t,s,[...u.exit,...u.invoke.map(c=>Q(c.id))],o,void 0),i.delete(u);return[d,p||r]}function bs(e,t){return e.implementations.actions[t]}function _t(e,t,s,n,i,r){const{machine:o}=e;let a=e;for(const d of n){const f=typeof d=="function",p=f?d:bs(o,typeof d=="str
2ing"?d:d.type),u={context:a.context,event:t,self:s.self,system:s.system},c=f||typeof d=="string"?void 0:"params"in d?typeof d.params=="function"?d.params({context:a.context,event:t}):d.params:void 0;if(!p||!("resolve"in p)){s.actionExecutor({type:typeof d=="string"?d:typeof d=="object"?d.type:d.name||"(anonymous)",info:u,params:c,exec:p});continue}const h=p,[l,y,g]=h.resolve(s,a,u,c,p,i);a=l,"retryResolve"in h&&r?.push([h,y]),"execute"in h&&s.actionExecutor({type:h.type,info:u,params:y,exec:h.execute.bind(null,s,y)}),g&&(a=_t(a,t,s,g,i,r))}return a}function N(e,t,s,n,i,r){const o=r?[]:void 0,a=_t(e,t,s,n,{internalQueue:i,deferredActorIds:r},o);return o?.forEach(([d,f])=>{d.retryResolve(s,a,f)}),a}function ye(e,t,s,n){let i=e;const r=[];function o(f,p,u){s.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:s.self,event:p,snapshot:f,_transitions:u}),r.push(f)}if(t.type===se)return i=D(Ke(i,t,s),{status:"stopped"}),o(i,t,[]),{snapshot:i,microstates:r};let a=t;if(a.type!==st){const f=a,p=Nt(f),u=Ne(f,i);if(p&&!u.length)return i=D(e,{status:"error",error:f.error}),o(i,f,[]),{snapshot:i,microstates:r};i=Te(u,e,s,a,!1,n),o(i,f,u)}let d=!0;for(;i.status==="active";){let f=d?Ss(i,a):[];const p=f.length?i:void 0;if(!f.length){if(!n.length)break;a=n.shift(),f=Ne(a,i)}i=Te(f,i,s,a,!1,n),d=i!==p,o(i,a,f)}return i.status!=="active"&&Ke(i,a,s),{snapshot:i,microstates:r}}function Ke(e,t,s){return N(e,t,s,Object.values(e.children).map(n=>Q(n)),[],void 0)}function Ne(e,t){return t.machine.getTransitionData(t,e)}function Ss(e,t){const s=new Set,n=e._nodes.filter($e);for(const i of n)e:for(const r of[i].concat(ee(i,void 0)))if(r.always){for(const o of r.always)if(o.guard===void 0||ce(o.guard,e.context,t,e)){s.add(o);break e}}return gt(Array.from(s),new Set(e._nodes),e.historyValue)}function Ts(e,t){const s=ne(re(e,t));return lt(e,[...s])}function ws(e){return!!e&&typeof e=="object"&&"machine"in e&&"value"in e}const Es=function(t){return rt(t,this.value)},ks=function(t){return this.tags.has(t)},xs=function(t){const s=this.machine.getTransitionData(this,t);return!!s?.length&&s.some(n=>n.target!==void 0||n.actions.length)},Is=function(){const{_nodes:t,tags:s,machine:n,getMeta:i,toJSON:r,can:o,hasTag:a,matches:d,...f}=this;return{...f,tags:Array.from(s)}},As=function(){return this._nodes.reduce((t,s)=>(s.meta!==void 0&&(t[s.id]=s.meta),t),{})};function te(e,t){return{status:e.status,output:e.output,error:e.error,machine:t,context:e.context,_nodes:e._nodes,value:lt(t.root,e._nodes),tags:new Set(e._nodes.flatMap(s=>s.tags)),children:e.children,historyValue:e.historyValue||{},matches:Es,hasTag:ks,can:xs,getMeta:As,toJSON:Is}}function D(e,t={}){return te({...e,...t},e.machine)}function Ms(e){if(typeof e!="object"||e===null)return{};const t={};for(const s in e){const n=e[s];Array.isArray(n)&&(t[s]=n.map(i=>({id:i.id})))}return t}function $s(e,t){const{_nodes:s,tags:n,machine:i,children:r,context:o,can:a,hasTag:d,matches:f,getMeta:p,toJSON:u,...c}=e,h={};for(const y in r){const g=r[y];h[y]={snapshot:g.getPersistedSnapshot(t),src:g.src,systemId:g.systemId,syncSnapshot:g._syncSnapshot}}return{...c,context:bt(o),children:h,historyValue:Ms(c.historyValue)}}function bt(e){let t;for(const s in e){const n=e[s];if(n&&typeof n=="object")if("sessionId"in n&&"send"in n&&"ref"in n)t??=Array.isArray(e)?e.slice():{...e},t[s]={xstate$$type:Ie,id:n.id};else{const i=bt(n);i!==n&&(t??=Array.isArray(e)?e.slice():{...e},t[s]=i)}}return t??e}function Os(e,t,s,n,{event:i,id:r,delay:o},{internalQueue:a}){const d=t.machine.implementations.delays;if(typeof i=="string")throw new Error(`Only event objects may be used with raise; use raise({ type: "${i}" }) instead`);const f=typeof i=="function"?i(s,n):i;let p;if(typeof o=="string"){const u=d&&d[o];p=typeof u=="function"?u(s,n):u}else p=typeof o=="function"?o(s,n):o;return typeof p!="number"&&a.push(f),[t,{event:f,id:r,delay:p},void 0]}function Rs(e,t){const{event:s,delay:n,id:i}=t;if(typeof n=="number"){e.defer(()=>{const r=e.self;e.system.scheduler.schedule(r,r,s,n,i)});return}}function P(e,t){function s(n,i){}return s.type="xstate.raise",s.event=e,s.id=t?.id,s.delay=t?.delay,s.resolve=Os,s.execute=Rs,s}const Ye="xstate.observable.error",Fe="xstate.observable.complete";function St(e){return{config:e,transition:(s,n)=>{if(s.status!=="active")return s;switch(n.type){case Ye:return{...s,status:"error",error:n.data,input:void 0,_subscription:void 0};case Fe:return{...s,status:"done",input:void 0,_subscription:void 0};case se:return s._subscription.unsubscribe(),{...s,status:"stopped",input:void 0,_subscription:void 0};default:return s}},getInitialSnapshot:(s,n)=>({status:"active",output:void 0,error:void 0,context:void 0,input:n,_subscription:void 0}),start:(s,{self:n,system:i,emit:r})=>{s.status!=="done"&&(s._subscription=e({input:s.input,system:i,self:n,emit:r}).subscribe({next:o=>{n._parent&&i._relay(n,n._parent,o)},error:o=>{i._relay(n,n,{type:Ye,data:o})},complete:()=>{i._relay(n,n,{type:Fe})}}))},getPersistedSnapshot:({_subscription:s,...n})=>n,restoreSnapshot:s=>({...s,_subscription:void 0})}}function Cs(e,{machine:t,context:s},n,i){const r=(o,a)=>
2{if(typeof o=="string"){const d=xe(t,o);if(!d)throw new Error(`Actor logic '${o}' not implemented in machine '${t.id}'`);const f=Z(d,{id:a?.id,parent:e.self,syncSnapshot:a?.syncSnapshot,input:typeof a?.input=="function"?a.input({context:s,event:n,self:e.self}):a?.input,src:o,systemId:a?.systemId});return i[f.id]=f,f}else return Z(o,{id:a?.id,parent:e.self,syncSnapshot:a?.syncSnapshot,input:a?.input,src:o,systemId:a?.systemId})};return(o,a)=>{const d=r(o,a);return i[d.id]=d,e.defer(()=>{d._processingStatus!==T.Stopped&&d.start()}),d}}function qs(e,t,s,n,{assignment:i}){if(!t.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const r={},o={context:t.context,event:s.event,spawn:Cs(e,t,s.event,r),self:e.self,system:e.system};let a={};if(typeof i=="function")a=i(o,n);else for(const f of Object.keys(i)){const p=i[f];a[f]=typeof p=="function"?p(o,n):p}const d=Object.assign({},t.context,a);return[D(t,{context:d,children:Object.keys(r).length?{...t.children,...r}:t.children}),void 0,void 0]}function j(e){function t(s,n){}return t.type="xstate.assign",t.assignment=e,t.resolve=qs,t}const Xe=new WeakMap;function L(e,t,s){let n=Xe.get(e);return n?t in n||(n[t]=s()):(n={[t]:s()},Xe.set(e,n)),n[t]}const js={},Y=e=>typeof e=="string"?{type:e}:typeof e=="function"?"resolve"in e?{type:e.type}:{type:e.name}:e;class oe{constructor(t,s){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=s._parent,this.key=s._key,this.machine=s._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(et),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?Pe(this.config.states,(n,i)=>new oe(n,{_parent:this,_key:i,_machine:this.machine})):js,this.type==="compound"&&!this.config.initial)throw new 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=this.config.history===!0?"shallow":this.config.history||!1,this.entry=M(this.config.entry).slice(),this.exit=M(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=M(t.tags).slice()}_initialize(){this.transitions=os(this),this.config.always&&(this.always=U(this.config.always).map(t=>C(this,tt,t))),Object.keys(this.states).forEach(t=>{this.states[t]._initialize()})}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.t
2ype,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(Y),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(t=>`#${t.id}`),source:`#${this.id}`,actions:this.initial.actions.map(Y),eventType:null})}:void 0,history:this.history,states:Pe(this.states,t=>t.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(t=>({...t,actions:t.actions.map(Y)})),entry:this.entry.map(Y),exit:this.exit.map(Y),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 L(this,"invoke",()=>M(this.config.invoke).map((t,s)=>{const{src:n,systemId:i}=t,r=t.id??We(this.id,s),o=typeof n=="string"?n:`xstate.invoke.${We(this.id,s)}`;return{...t,src:o,id:r,systemId:i,toJSON(){const{onDone:a,onError:d,...f}=t;return{...f,type:"xstate.invoke",src:o,id:r}}}}))}get on(){return L(this,"on",()=>[...this.transitions].flatMap(([s,n])=>n.map(i=>[s,i])).reduce((s,[n,i])=>(s[n]=s[n]||[],s[n].push(i),s),{}))}get after(){return L(this,"delayedTransitions",()=>rs(this))}get initial(){return L(this,"initial",()=>as(this,this.config.initial))}next(t,s){const n=s.type,i=[];let r;const o=L(this,`candidates-${n}`,()=>is(this,n));for(const a of o){const{guard:d}=a,f=t.context;let p=!1;try{p=!d||ce(d,f,s,t)}catch(u){const c=typeof d=="string"?d:typeof d=="object"?d.type:void 0;throw new Error(`Unable to evaluate guard ${c?`'${c}' `:""}in transition for event '${n}' in state node '${this.id}': 3${u.message}`)}if(p){i.push(...a.actions),r=a;break}}return r?[r]:void 0}get events(){return L(this,"events",()=>{const{states:t}=this,s=new Set(this.ownEvents);if(t)for(const n of Object.keys(t)){const i=t[n];if(i.states)for(const r of i.events)s.add(`${r}`)}return Array.from(s)})}get ownEvents(){const t=Object.keys(Object.fromEntries(this.transitions)),s=new Set(t.filter(n=>this.transitions.get(n).some(i=>!(!i.target&&!i.actions.length&&!i.reenter))));return Array.from(s)}}const Ds="#";class qe{constructor(t,s){this.config=t,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=t.id||"(machine)",this.implementations={actors:s?.actors??{},actions:s?.actions??{},delays:s?.delays??{},guards:s?.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 oe(t,{_key:this.id,_machine:this}),this.root._initialize(),this.states=this.root.states,this.events=this.root.events}provide(t){const{actions:s,guards:n,actors:i,delays:r}=this.implementations;return new qe(this.config,{actions:{...s,...t.actions},guards:{...n,...t.guards},actors:{...i,...t.actors},delays:{...r,...t.delays}})}resolveState(t){const s=Ts(this.root,t.value),n=ne(re(this.root,s));return te({_nodes:[...n],context:t.context||{},children:{},status:Oe(n,this.root)?"done":t.status||"active",output:t.output,error:t.error,historyValue:t.historyValue},this)}transition(t,s,n){return ye(t,s,n,[]).snapshot}microstep(t,s,n){return ye(t,s,n,[]).microstates}getTransitionData(t,s){return Re(this.root,t.value,t,s)||[]}getPreInitialState(t,s,n){const{context:i}=this.config,r=te({context:typeof i!="function"&&i?i:{},_nodes:[this.root],children:{},status:"active"},this);return typeof i=="function"?N(r,s,t,[j(({spawn:a,event:d,self:f})=>i({spawn:a,input:d.input,self:f}))],n,void 0):r}getInitialSnapshot(t,s){const n=it(s),i=[],r=this.getPreInitialState(t,n,i),o=Te([{target:[...yt(this.root)],source:this.root,reenter:!0,actions:[],eventType:null,toJSON:null}],r,t,n,!0,i),{snapshot:a}=ye(o,n,t,i);return a}start(t){Object.values(t.children).forEach(s=>{s.getSnapshot().status==="active"&&s.start()})}getStateNodeById(t){const s=ke(t),n=s.slice(1),i=ue(s[0])?s[0].slice(Ds.length):s[0],r=this.idMap.get(i);if(!r)throw new Error(`Child state node '#${i}' does not exist on machine '${this.id}'`);return ie(r,n)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(t,s){return $s(t,s)}restoreSnapshot(t,s){const n={},i=t.children;
3Object.keys(i).forEach(u=>{const c=i[u],h=c.snapshot,l=c.src,y=typeof l=="string"?xe(this,l):l;if(!y)return;const g=Z(y,{id:u,parent:s.self,syncSnapshot:c.syncSnapshot,snapshot:h,src:l,systemId:c.systemId});n[u]=g});function r(u,c){if(c instanceof oe)return c;try{return u.machine.getStateNodeById(c.id)}catch{}}function o(u,c){if(!c||typeof c!="object")return{};const h={};for(const l in c){const y=c[l];for(const g of y){const S=r(u,g);S&&(h[l]??=[],h[l].push(S))}}return h}const a=o(this.root,t.historyValue),d=te({...t,children:n,_nodes:Array.from(ne(re(this.root,t.value))),historyValue:a},this),f=new Set;function p(u,c){if(!f.has(u)){f.add(u);for(const h in u){const l=u[h];if(l&&typeof l=="object"){if("xstate$$type"in l&&l.xstate$$type===Ie){u[h]=c[l.id];continue}p(l,c)}}}}return p(d.context,n),d}}function Ls(e,t,s,n,{event:i}){const r=typeof i=="function"?i(s,n):i;return[t,{event:r},void 0]}function Us(e,{event:t}){e.defer(()=>e.emit(t))}function ae(e){function t(s,n){}return t.type="xstate.emit",t.event=e,t.resolve=Ls,t.execute=Us,t}let we=(function(e){return e.Parent="#_parent",e.Internal="#_internal",e})({});function Js(e,t,s,n,{to:i,event:r,id:o,delay:a},d){const f=t.machine.implementations.delays;if(typeof r=="string")throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${r}" }) instead`);const p=typeof r=="function"?r(s,n):r;let u;if(typeof a=="string"){const l=f&&f[a];u=typeof l=="function"?l(s,n):l}else u=typeof a=="function"?a(s,n):a;const c=typeof i=="function"?i(s,n):i;let h;if(typeof c=="string"){if(c===we.Parent?h=e.self._parent:c===we.Internal?h=e.self:c.startsWith("#_")?h=t.children[c.slice(2)]:h=d.deferredActorIds?.includes(c)?c:t.children[c],!h)throw new Error(`Unable to send event to actor '${c}' from machine '${t.machine.id}'.`)}else h=c||e.self;return[t,{to:h,targetId:typeof c=="string"?c:void 0,event:p,id:o,delay:u},void 0]}function Bs(e,t,s){typeof s.to=="string"&&(s.to=t.children[s.to])}function Hs(e,t){e.defer(()=>{const{to:s,event:n,delay:i,id:r}=t;if(typeof i=="number"){e.system.scheduler.schedule(e.self,s,n,i,r);return}e.system._relay(e.self,s,n.type===Pt?nt(e.self.id,n.data):n)})}function W(e,t,s){function n(i,r){}return n.type="xstate.sendTo",n.to=e,n.event=t,n.id=s?.id,n.delay=s?.delay,n.resolve=Js,n.retryResolve=Bs,n.execute=Hs,n}function Ps(e,t){return W(we.Parent,e,t)}function Ws(e,t,s,n,{collect:i}){const r=[],o=function(d){r.push(d)};return o.assign=(...a)=>{r.push(j(...a))},o.cancel=(...a)=>{r.push(Ae(...a))},o.raise=(...a)=>{r.push(P(...a))},o.sendTo=(...a)=>{r.push(W(...a))},o.sendParent=(...a)=>{r.push(Ps(...a))},o.spawnChild=(...a)=>{r.push(Me(...a))},o.stopChild=(...a)=>{r.push(Q(...a))},o.emit=(...a)=>{r.push(ae(...a))},i({context:s.context,event:s.event,enqueue:o,check:a=>ce(a,t.context,s.event,t),self:e.self,system:e.system},n),[t,void 0,r]}function J(e){function t(s,n){}return t.type="xstate.enqueueActions",t.collect=e,t.resolve=Ws,t}function zs(e,t,s,n,{value:i,label:r}){return[t,{value:typeof i=="function"?i(s,n):i,label:r},void 0]}function Gs({logger:e},{value:t,label:s}){s?e(s,t):e(t)}function Ks(e=({context:s,event:n})=>({context:s,event:n}),t){function s(n,i){}return s.type="xstate.log",s.value=e,s.label=t,s.resolve=zs,s.execute=Gs,s}function x(e,t){const s=M(t);if(!s.some(i=>ut(e.type,i))){const i=s.length===1?`type matching "${s[0]}"`:`one of types matching "${s.join('", "')}"`;throw new Error(`Expected event ${JSON.stringify(e)} to have ${i}`)}}function Ns(e,t){return new qe(e,t)}function je({schemas:e,actors:t,actions:s,guards:n,delays:i}){return{assign:j,sendTo:W,raise:P,log:Ks,cancel:Ae,stopChild:Q,enqueueActions:J,emit:ae,spawnChild:Me,createStateConfig:r=>r,createAction:r=>r,createMachine:r=>Ns({...r,schemas:e},{actors:t,actions:s,guards:n,delays:i}),extend:r=>je({schemas:e,actors:t,actions:{...s,...r.actions},guards:{...n,...r.guards},delays:{...i,...r.delays}})}}const R=e=>({context:t})=>{const{count:s,include:n,exclude:i,responseType:r="message.received"}=e;return{count:s,domain:t.domain,from:t.connectTo,include:n?Array.isArray(n)?n:[n]:[],exclude:i?Array.isArray(i)?i:[i]:[],responseType:r,target:t.target,to:t.name}},Ys=e=>t=>{const{data:s}=t;return(e.include.length?e.include.includes(s.type):!0)&&(e.exclude.length?!e.exclude.includes(s.type):!0)&&s.domain===e.domain&&s.from===e.from&&s.to===e.to&&(!e.target||t.source===e.target)},Fs=e=>t=>({type:e,message:t}),Xs=kt(()=>me(window,"message")),Tt=e=>St(({input:t})=>Xs.pipe(e?ge(e):fe(),Ze(Ys(t)),ge(Fs(t.responseType)),t.count?fe(It(t.count),xt(s=>s),Ee(t.count)):fe())),De="sanity/comlink",Vs=3e3,Zs=1e4,z="comlink/response",F="comlink/heartbeat",H="comlink/disconnect",X="comlink/handshake/syn",Le="comlink/handshake/syn-ack",V="comlink/handshake/ack",Qs=e=>t=>t.pipe(Ee(1),ge(()=>{throw new Error(e)})),wt=()=>je({actors:{listen:St(({input:e})=>{const t=e.signal?me(e.signal,"abort").pipe(Qs(`Request ${e.requestId} aborted`)):At,s=n=>n.data?.type===z&&n.data?.responseTo===e.requestId&&!!n.source&&e.sources.has(n.source);return me(window,"message").pipe(Ze(s),Ee(e.sources.size),Mt(t))})},actions:{"send message":({context:e},t)=>{const{sources:s,targetOrigin:n}=e,{message:i}=t;
3s.forEach(r=>{r.postMessage(i,{targetOrigin:n})})},"on success":W(({context:e})=>e.parentRef,({context:e,self:t})=>(e.response&&e.resolvable?.resolve(e.response),{type:"request.success",requestId:t.id,response:e.response,responseTo:e.responseTo})),"on fail":W(({context:e})=>e.parentRef,({context:e,self:t})=>(e.suppressWarnings||console.warn(`[@sanity/comlink] Received no response to message '${e.type}' on client '${e.from}' (ID: '${e.id}').`),e.resolvable?.reject(new Error("No response received")),{type:"request.failed",requestId:t.id})),"on abort":W(({context:e})=>e.parentRef,({context:e,self:t})=>(e.resolvable?.reject(new Error("Request aborted")),{type:"request.aborted",requestId:t.id}))},guards:{expectsResponse:({context:e})=>e.expectResponse},delays:{initialTimeout:0,responseTimeout:({context:e})=>e.responseTimeout??Vs}}).createMachine({context:({input:e})=>({channelId:e.channelId,data:e.data,domain:e.domain,expectResponse:e.expectResponse??!1,from:e.from,id:`msg-${Qe()}`,parentRef:e.parentRef,resolvable:e.resolvable,response:null,responseTimeout:e.responseTimeout,responseTo:e.responseTo,signal:e.signal,sources:e.sources instanceof Set?e.sources:new Set([e.sources]),suppressWarnings:e.suppressWarnings,targetOrigin:e.targetOrigin,to:e.to,type:e.type}),initial:"idle",on:{abort:".aborted"},states:{idle:{after:{initialTimeout:[{target:"sending"}]}},sending:{entry:{type:"send message",params:({context:e})=>{const{channelId:t,data:s,domain:n,from:i,id:r,responseTo:o,to:a,type:d}=e;return{message:{channelId:t,data:s,domain:n,from:i,id:r,to:a,type:d,responseTo:o}}}},always:[{guard:"expectsResponse",target:"awaiting"},"success"]},awaiting:{invoke:{id:"listen for response",src:"listen",input:({context:e})=>({requestId:e.id,sources:e.sources,signal:e.signal}),onError:"aborted"},after:{responseTimeout:"failed"},on:{message:{actions:j({response:({event:e})=>e.data.data,responseTo:({event:e})=>e.data.responseTo}),target:"success"}}},failed:{type:"final",entry:"on fail"},success:{type:"final",entry:"on success"},aborted:{type:"final",entry:"on abort"}},output:({context:e,self:t})=>({requestId:t.id,response:e.response,responseTo:e.responseTo})});function en(){if(typeof Promise.withResolvers=="function")return Promise.withResolvers();let e,t;return{promise:new Promise((s,n)=>{e=s,t=n}),resolve:e,reject:t}}const Et=()=>je({actors:{requestMachine:wt(),listen:Tt()},actions:{"buffer handshake":j({handshakeBuffer:({event:e,context:t})=>(x(e,"message.received"),[...t.handshakeBuffer,e])}),"buffer message":J(({enqueue:e})=>{e.assign({buffer:({event:t,context:s})=>(x(t,"post"),[...s.buffer,{data:t.data,resolvable:t.resolvable,options:t.options}])}),e.emit(({event:t})=>(x(t,"post"),{type:"buffer.added",message:t.data}))}),"create request":j({requests:({context:e,event:t,self:s,spawn:n})=>{x(t,"request");const i=(Array.isArray(t.data)?t.data:[t.data]).map(r=>{const o=`req-${Qe()}`;return n("requestMachine",{id:o,input:{channelId:e.channelId,data:r.data,domain:e.domain,expectResponse:r.expectResponse,from:e.name,parentRef:s,resolvable:r.resolvable,responseTimeout:r.options?.responseTimeout,responseTo:r.responseTo,signal:r.options?.signal,sources:e.target,suppressWarnings:r.options?.suppressWarnings,targetOrigin:e.targetOrigin,to:e.connectTo,type:r.type}})});return[...e.requests,...i]}}),"emit heartbeat":ae(()=>({type:"heartbeat"})),"emit received message":J(({enqueue:e})=>{e.emit(({event:t})=>(x(t,"message.received"),{type:"message",message:t.message.data}))}),"emit status":ae((e,t)=>({type:"status",status:t.status})),"post message":P(({event:e})=>(x(e,"post"),{type:"request",data:{data:e.data.data,expectResponse:!!e.resolvable,type:e.data.type,resolvable:e.resolvable,options:e.options}})),"process pending handshakes":J(({context:e,enqueue:t})=>{e.handshakeBuffer.forEach(s=>t.raise(s)),t.assign({handshakeBuffer:[]})}),"remove request":J(({context:e,enqueue:t,event:s})=>{x(s,["request.success","request.failed","request.aborted"]),Q(s.requestId),t.assign({requests:e.requests.filter(({id:n})=>n!==s.requestId)})}),"send response":P(({event:e})=>(x(e,["message.received","heartbeat.received"]),{type:"request",data:{type:z,responseTo:e.message.data.id,data:void 0}})),"send handshake syn ack":P({type:"request",data:{type:Le}}),"send pending messages":J(({enqueue:e})=>{e.raise(({context:t})=>({type:"request",data:t.buffer.map(({data:s,resolvable:n,options:i})=>
3({data:s.data,type:s.type,expectResponse:!!n,resolvable:n,options:i}))})),e.emit(({context:t})=>({type:"buffer.flushed",messages:t.buffer.map(({data:s})=>s)})),e.assign({buffer:[]})}),"set connection config":j({channelId:({event:e})=>(x(e,"handshake.syn"),e.message.data.channelId),target:({event:e})=>(x(e,"handshake.syn"),e.message.source||void 0),targetOrigin:({event:e})=>(x(e,"handshake.syn"),e.message.origin)})},guards:{hasSource:({context:e})=>e.target!==null}}).createMachine({id:"node",context:({input:e})=>({buffer:[],channelId:null,connectTo:e.connectTo,domain:e.domain??De,handshakeBuffer:[],name:e.name,requests:[],target:void 0,targetOrigin:null}),invoke:{id:"listen for handshake syn",src:"listen",input:R({include:X,responseType:"handshake.syn"})},on:{"request.success":{actions:"remove request"},"request.failed":{actions:"remove request"},"request.aborted":{actions:"remove request"},"handshake.syn":{actions:"set connection config",target:".handshaking"}},initial:"idle",states:{idle:{entry:[{type:"emit status",params:{status:"idle"}}],on:{post:{actions:"buffer message"}}},handshaking:{guard:"hasSource",entry:["send handshake syn ack",{type:"emit status",params:{status:"handshaking"}}],invoke:[{id:"listen for handshake ack",src:"listen",input:R({include:V,count:1,responseType:"handshake.complete"}),onDone:"connected"},{id:"listen for disconnect",src:"listen",input:R({include:H,count:1,responseType:"disconnect"})},{id:"listen for messages",src:"listen",input:R({exclude:[H,X,V,F,z]})}],on:{request:{actions:"create request"},post:{actions:"buffer message"},"message.received":{actions:"buffer handshake"},disconnect:{target:"idle"}}},connected:{entry:["process pending handshakes","send pending messages",{type:"emit status",params:{status:"connected"}}],invoke:[{id:"listen for messages",src:"listen",input:R({exclude:[H,X,V,F,z]})},{id:"listen for heartbeat",src:"listen",input:R({include:F,responseType:"heartbeat.received"})},{id:"listen for disconnect",src:"listen",input:R({include:H,count:1,responseType:"disconnect"})}],on:{request:{actions:"create request"},post:{actions:"post message"},disconnect:{target:"idle"},"message.received":{actions:["send response","emit received message"]},"heartbeat.received":{actions:["send response","emit heartbeat"]}}}}}),tn=(e,t=Et())=>{const s=Z(t,{input:e}),n=new Map,i=new Map,r=(u,c,h)=>{const l=n.get(u)||new Set;n.has(u)||n.set(u,l),l.add(c);const y=i.get(u);if(y){const g=h?.replay??1;Array.from(y).slice(-g).forEach(({data:S})=>c(S)),i.delete(u)}return()=>{l.delete(c)}};let o;const a=(u,c)=>{const h=s.on("status",l=>{o=l.status,!(c&&l.status!==c)&&u(l.status)});return o&&u(o),()=>h.unsubscribe()},d=(u,c)=>{const h={type:u,data:c};s.send({type:"post",data:h})},f=(u,c,h)=>{const{responseTimeout:l=Zs,signal:y,suppressWarnings:g}=h||{},S=en(),w={type:u,data:c};return s.send({type:"post",data:w,resolvable:S,options:{responseTimeout:l,signal:y,suppressWarnings:g}}),S.promise};s.on("message",({message:u})=>{const c=n.get(u.type);
3if(c){c.forEach(l=>l(u.data));return}const h=i.get(u.type);h?h.add(u):i.set(u.type,new Set([u]))});const p=()=>{s.stop()};return{actor:s,fetch:f,machine:t,on:r,onStatus:a,post:d,start:()=>(s.start(),p),stop:p}},sn={"handshake/syn":X,"handshake/syn-ack":Le,"handshake/ack":V,"channel/response":z,"channel/heartbeat":F,"channel/disconnect":H,"overlay/focus":"visual-editing/focus","overlay/navigate":"visual-editing/navigate","overlay/toggle":"visual-editing/toggle","presentation/toggleOverlay":"presentation/toggle-overlay"},nn={[X]:"handshake/syn",[Le]:"handshake/syn-ack",[V]:"handshake/ack",[z]:"channel/response",[F]:"channel/heartbeat",[H]:"channel/disconnect","visual-editing/focus":"overlay/focus","visual-editing/navigate":"overlay/navigate","visual-editing/toggle":"overlay/toggle","presentation/toggle-overlay":"presentation/toggleOverlay"},rn=e=>{const{data:t}=e;return t&&typeof t=="object"&&"domain"in t&&"type"in t&&"from"in t&&"to"in t&&(t.domain==="sanity/channels"&&(t.domain=De),t.to==="overlays"&&(t.to="visual-editing"),t.from==="overlays"&&(t.from="visual-editing"),t.channelId=t.connectionId,delete t.connectionId,t.type=sn[t.type]??t.type),e},on=e=>{const{channelId:t,...s}=e,n={...s,connectionId:t};return n.domain===De&&(n.domain="sanity/channels"),n.to==="visual-editing"&&(n.to="overlays"),n.from==="visual-editing"&&(n.from="overlays"),n.type=nn[n.type]??n.type,n.type==="channel/response"&&n.responseTo&&!n.data&&(n.data={responseTo:n.responseTo}),(n.type==="handshake/syn"||n.type==="handshake/syn-ack"||n.type==="handshake/ack")&&(n.data={id:n.connectionId}),n},an=({context:e},t)=>{const{sources:s,targetOrigin:n}=e,i=on(t.message);s.forEach(r=>{r.postMessage(i,{targetOrigin:n})})},cn=()=>({listen:Tt(rn),requestMachine:wt().provide({actions:{"send message":an}})}),Ve=1e4;function pn(e){const{client:t,setFetcher:s,onConnect:n,onDisconnect:i,onPerspective:r}=e;if(!t)throw new Error(`Expected \`client\` to be an instance of SanityClient: ${JSON.stringify(t)}`);const{projectId:o,dataset:a,perspective:d}=t.config(),f=Ue(d&&d!=="raw"?d:"drafts"),p=Ue(!1),u=new Map,c=tn({name:"loaders",connectTo:"presentation"},Et().provide({actors:cn()}));c.onStatus(()=>{p.set(!0)},"connected"),c.on("loader/perspective",m=>{if(m.projectId===o&&m.dataset===a){$t(m.perspective);const _=m.perspective==="raw"?"drafts":m.perspective;f.set(_),r?.(_),w()}}),c.on("loader/query-change",m=>{if(m.projectId===o&&m.dataset===a){const{perspective:_,query:E,params:v}=m;m.result!==void 0&&m.resultSourceMap!==void 0&&t.config().stega.enabled?u.set(JSON.stringify({perspective:_,query:E,params:v}),{...m,result:Ot(m.result,m.resultSourceMap,t.config().stega)}):u.set(JSON.stringify({perspective:_,query:E,params:v}),m),w()}});let h;const l=p.listen(m=>{m?(h=s({hydrate:(_,E,v)=>{const k=v?.perspective||f.get(),O=JSON.stringify({perspective:k,query:_,params:E}),A=u.get(O);return A?.result!==void 0&&A?.resultSourceMap!==void 0?{loading:!1,error:void 0,data:A.result,sourceMap:A.resultSourceMap,perspective:k}:{loading:p.value===!0&&v?.data===void 0||v?.sourceMap===void 0,error:void 0,data:v?.data,sourceMap:v?.sourceMap,perspective:v?.perspective||"published"}},fetch:(_,E,v,k)=>{try{const O=g(_,E,v);if(k.signal.addEventListener("abort",()=>{O(),w()},{once:!0}),w(),v.setKey("error",void 0),k.signal.aborted)return}catch(O){v.setKey("error",O),v.setKey("loading",!1)}}}),n?.()):(h?.(),i?.())}),y=new Set,g=(m,_,E)=>{const v={query:m,params:_,$fetch:E};y.add(v),S();const k=setInterval(()=>S(!0),Ve);return()=>{clearInterval(k),y.delete(v),S()}},S=m=>{if(!c)throw new Error("No connection");const _=f.get();for(const{query:E,params:v,$fetch:k}of y)c.post("loader/query-listen",{projectId:o,dataset:a,perspective:_,query:E,params:v,heartbeat:Ve}),!m&&p.value===!0&&k.setKey("loading",!0),k.setKey("perspective",_)};function w(){const m=f.get(),_=[];for(const{query:E,params:v,$fetch:k}of y){const O=JSON.stringify({perspective:m,query:E,params:v}),A=u.get(O);A&&(k.set({data:A.result,error:void 0,loading:!1,perspective:m,sourceMap:A.resultSourceMap}),_.push(...A.resultSourceMap?.documents??[]))}c.post("loader/documents",{projectId:o,dataset:a,perspective:m,documents:_})}const de=c.start();return()=>{h?.(),l(),de(),p.set(!1)}}export{pn as enableLiveMode};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.