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