@deslop/auth 0.1.1287 → 0.1.1291
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/assets/(home)-HEAEx3uj.js +1 -0
- package/dist/client/assets/components-Ct6yjLbn.js +1 -0
- package/dist/client/assets/dropdown-menu-CxK8bylw.js +1 -0
- package/dist/client/assets/effect-DfvaysSc.js +17 -0
- package/dist/client/assets/index-B0ra-Jbs.css +2 -0
- package/dist/client/assets/index-BfJrmHP2.js +2 -0
- package/dist/client/assets/people-97uWIIv4.js +1 -0
- package/dist/client/assets/reason-parts-DycsCGQg.js +1 -0
- package/dist/client/assets/route-CyMqR1_V.js +1 -0
- package/dist/client/assets/utils-BatAIFEP.js +2 -0
- package/dist/client/assets/utils-Dl62aFvH.js +1 -0
- package/dist/client/index.html +5 -4
- package/dist/server.js +656 -343
- package/package.json +2 -2
- package/dist/client/assets/(home)-6NwrLz5K.js +0 -1
- package/dist/client/assets/components-BXbYUD7C.js +0 -1
- package/dist/client/assets/effect-ByTkGkTS.js +0 -17
- package/dist/client/assets/index-CEBeXdrM.css +0 -2
- package/dist/client/assets/index-Dc0f55_m.js +0 -2
- package/dist/client/assets/people-CqY9_5CK.js +0 -1
- package/dist/client/assets/reason-parts-CZ9lROBA.js +0 -1
- package/dist/client/assets/route-LfaVoPPO.js +0 -1
- package/dist/client/assets/utils-ZppjrtBG.js +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{a as t,i as n,n as r,o as i}from"./react-CYMlNKV3.js";import{$ as a,$a as o,$i as s,$n as c,$r as l,$t as u,A as d,Ai as f,An as p,Ar as m,At as h,B as g,Ba as _,Bi as v,Bn as y,Bt as b,C as x,Ca as S,Cn as C,Co as w,Cr as ee,Ct as T,D as te,Di as E,Dn as ne,Dr as re,Dt as ie,E as ae,Ei as oe,En as se,Er as ce,Et as D,F as le,Fa as ue,Fi as de,Fn as fe,Fr as pe,Ft as me,G as he,Ga as ge,Gi as _e,Gn as ve,Gr as ye,Gt as be,Ha as xe,Hi as Se,Hn as Ce,Hr as we,Ht as Te,I as Ee,Ia as De,Ii as Oe,In as ke,Ir as Ae,It as je,J as Me,Ja as Ne,Ji as Pe,Jn as Fe,Jr as O,Jt as Ie,Ka as Le,Ki as Re,Kn as ze,Kr as k,Kt as Be,L as Ve,Li as He,Ln as Ue,Lr as We,Lt as Ge,M as Ke,Mi as qe,Mn as Je,Mr as Ye,Mt as A,Ni as Xe,Nn as Ze,Nr as Qe,Nt as $e,O as et,Oi as tt,On as nt,Or as rt,Ot as it,Pi as at,Pn as ot,Pr as st,Pt as ct,Q as lt,Qa as ut,Qi as dt,Qn as ft,Qr as pt,Qt as mt,Ri as ht,Rn as gt,Rr as _t,Rt as vt,S as yt,Sa as bt,Si as xt,Sn as St,So as Ct,Sr as wt,St as Tt,T as Et,Ta as Dt,Tn as Ot,To as kt,Tr as At,Tt as jt,Ui as Mt,Un as Nt,Ur as Pt,Ut as Ft,V as It,Vi as Lt,Vn as Rt,Vr as zt,Vt as Bt,W as Vt,Wa as Ht,Wi as Ut,Wn as Wt,Wr as Gt,Wt as j,X as Kt,Xi as qt,Xn as Jt,Xr as Yt,Xt,Y as Zt,Ya as Qt,Yi as $t,Yn as en,Yr as tn,Yt as M,Z as nn,Za as rn,Zi as an,Zn as on,Zr as sn,Zt as cn,_ as ln,_a as un,_o as dn,_r as fn,_t as pn,a as mn,aa as hn,ai as gn,an as _n,ao as vn,ar as yn,at as bn,b as xn,bi as Sn,br as Cn,bt as wn,c as Tn,ca as En,ci as Dn,cn as On,co as kn,cr as An,ct as jn,d as Mn,da as Nn,di as Pn,dn as Fn,dr as In,ea as Ln,ei as Rn,en as zn,eo as Bn,er as Vn,et as Hn,f as Un,fa as Wn,fi as Gn,fn as Kn,fo as qn,fr as Jn,ft as Yn,g as Xn,gi as Zn,go as N,gr as Qn,gt as $n,h as er,ha as tr,hi as nr,hn as rr,ho as ir,hr as ar,ht as or,i as sr,ia as cr,ii as lr,in as ur,io as dr,ir as fr,it as pr,j as mr,ja as hr,ji as gr,jn as _r,jr as P,jt as F,k as vr,ka as yr,ki as br,kn as xr,kr as Sr,kt as Cr,l as wr,la as Tr,li as Er,ln as Dr,lo as Or,lr as I,m as kr,ma as Ar,mi as jr,mn as Mr,mo as Nr,mr as Pr,mt as Fr,n as Ir,na as Lr,ni as L,nn as Rr,no as R,nr as zr,nt as Br,o as Vr,oa as Hr,oi as Ur,on as Wr,oo as z,or as B,ot as Gr,p as Kr,pi as qr,pn as Jr,po as Yr,pr as Xr,pt as Zr,q as Qr,qa as $r,qi as ei,qn as ti,qr as V,qt as ni,r as ri,ra as ii,ri as ai,rn as oi,ro as si,rr as ci,rt as li,s as ui,sa as di,si as fi,sn as pi,so as mi,sr as hi,st as gi,t as _i,ta as vi,ti as yi,tn as bi,to as xi,tr as Si,u as Ci,ua as wi,ui as Ti,un as Ei,uo as Di,ur as Oi,ut as ki,v as Ai,va as ji,vr as Mi,vt as Ni,w as Pi,wi as Fi,wn as Ii,wo as H,wr as Li,wt as Ri,x as zi,xa as Bi,xi as Vi,xn as Hi,xo as Ui,xr as U,xt as Wi,ya as Gi,yr as W,yt as Ki,z as qi,zi as Ji,zn as Yi,zr as Xi,zt as Zi}from"./effect-DfvaysSc.js";import{B as Qi,i as $i,n as ea,t as ta,u as na,z as ra}from"./utils-Dl62aFvH.js";var G=e(i(),1),ia=G.use,aa=G.useLayoutEffect,oa=G.createContext(null);function sa(e){return G.useContext(oa)}function ca(e){let t=sa();return G.useCallback(n=>t.navigate({...n,from:n.from??e?.from}),[e?.from,t])}function la(e){let t=sa(),n=ca(),r=G.useRef(null);return aa(()=>{r.current!==e&&(n(e),r.current=e)},[t,e,n]),null}function ua(e){return e[e.length-1]}function da(e,t){return typeof e==`function`?e(t):e}var fa=Object.prototype.hasOwnProperty;function pa(e){for(let t in e)if(fa.call(e,t))return!0;return!1}var ma=()=>Object.create(null),ha=(e,t)=>ga(e,t,!0);function ga(e,t,n,r=0){if(e===t)return e;if(r++>500)return t;let i=Array.isArray(e)&&Array.isArray(t);if(!i&&!(_a(e)&&_a(t)))return t;let a=Object.keys(e),o=a.length,s=Object.keys(t),c=s.length;if(i?o!==e.length||c!==t.length||o&&ua(a)!==`${o-1}`||c&&ua(s)!==`${c-1}`:o!==Object.getOwnPropertyNames(e).length||c!==Object.getOwnPropertyNames(t).length||Object.getOwnPropertySymbols(t).length)return t;let l=0,u,d,f;if(i){for(;l<c&&(f=l,d=e[f],u=t[f],u=d===u?d:typeof d==`object`?ga(d,u,n,r):u,u===d);l++);if(l===c&&o===c)return e}else{let i=o===c,p=!0;for(;l<c;l++){f=s[l],d=e[f];let o=t[f];u=d===o?d:typeof d==`object`?ga(d,o,n,r):o,i&&=u===d&&(a[l]===f||fa.call(e,f)),p&&=Object.is(u,o),a[l]=u}if(i)return Object.getOwnPropertySymbols(e).length?t:e;if(p)return t}let p=i?s.fill(0):n?ma():{};for(let o=0;o<c;o++)f=i?o:s[o],i?(d=e[f],o>l&&(u=t[f],u=d===u?d:typeof d==`object`?ga(d,u,n,r):u),p[f]=o<l?d:u):p[f]=a[o];return p}function _a(e){return!e||typeof e!=`object`?!1:(Object.getPrototypeOf(e)?.constructor??Object)===Object}function va(e,t,n,r){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let i=0,a=e.length;i<a;i++){let a=e[i],o=t[i];if(a!==o&&!va(a,o,n,r))return!1}return!0}if(_a(e)&&_a(t)){if(n){for(let i in t)if((r||t[i]!==void 0)&&!va(e[i],t[i],n,r))return!1;return!0}let i=0;if(r)i=Object.keys(e).length;else for(let t in e)e[t]!==void 0&&i++;for(let a in t)if((r||t[a]!==void 0)&&(i--===0||!va(e[a],t[a],n,r)))return!1;return i===0}return!1}function ya(e){return typeof e?.message==`string`?e.message.startsWith(`Failed to fetch dynamically imported module`)||e.message.startsWith(`error loading dynamically imported module`)||e.message.startsWith(`Importing a module script failed`):!1}var ba=/[\x00-\x1f\x7f"<>`{}]/g;function xa(e){return e.replace(ba,e=>`%`+e.charCodeAt(0).toString(16).toUpperCase().padStart(2,`0`))}function Sa(e){let t;try{t=decodeURI(e)}catch{t=e.replaceAll(/%[0-9A-F]{2}/gi,e=>{try{return decodeURI(e)}catch{return e}})}return xa(t)}var Ca=[`http:`,`https:`,`mailto:`,`tel:`];function wa(e){if(e[0]!==`/`&&e.includes(`:`))return/^[\x00-\x20]*([a-z][a-z\d+.\t\n\r-]*:)/i.exec(e)?.[1]?.replace(/[\t\n\r]/g,``).toLowerCase()}var Ta=/^[\x00-\x20]*[\\/][\t\n\r]*[\\/]/;function Ea(e,t){if(!e)return!1;if(Ta.test(e))return!0;let n=wa(e);return n?!t.has(n):!1}function Da(e){if(!e)return e;let t=e;if(/[%\\\x00-\x1f\x7f]/.test(e)){let n=/%25|%5C/gi,r=0,i;for(t=``;(i=n.exec(e))!==null;)t+=Sa(e.slice(r,i.index))+i[0],r=n.lastIndex;t+=Sa(r?e.slice(r):e)}return t}function Oa(e){return/[\s\u0080-\uFFFF]/.test(e)?e.replace(/\s|[^\u0000-\u007F]/gu,encodeURIComponent):e}function ka(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Aa(){throw Error(`Invariant failed`)}function ja(e){return e.replace(/\/{2,}/g,`/`)}function Ma(e){return e===`/`?e:e.replace(/^\/+/,``)}function Na(e){let t=e.length;return t>1&&e[t-1]===`/`?e.replace(/\/+$/,``):e}function Pa(e){return Na(Ma(e))}function Fa(e,t){return e?.endsWith(`/`)&&e!==`/`&&e!==`${t}/`?e.slice(0,-1):e}function Ia(e,t,n=`never`,r){if(t.includes(`//`)&&(t=ja(t)),t.startsWith(`/`))return t.length===1||n===`preserve`?t:n===`always`?t.endsWith(`/`)?t:`${t}/`:t.endsWith(`/`)?t.slice(0,-1):t;let i=t===`.`,a;if(r){a=i?e:e+`\0`+t;let n=r.get(a);if(n)return n}let o;if(i)o=e.split(`/`);else{for(e.includes(`//`)&&(e=ja(e)),o=e.split(`/`);o.length>1&&ua(o)===``;)o.pop();let n=t.split(`/`);for(let e=0,t=n.length;e<t;e++){let r=n[e];r===``?e?e===t-1&&o.push(r):o=[r]:r===`..`?o.length>1?o.pop():o=[``]:r===`.`||o.push(r)}}o.length>1&&(ua(o)===``?n===`never`&&o.pop():n===`always`&&o.push(``));let s=o.join(`/`),c=(i?ja(s):s)||`/`;return a&&r&&r.set(a,c),c}function La(e){let t=new Map(e.map(e=>[encodeURIComponent(e),e])),n=new RegExp([...t.keys()].join(`|`).replace(/[.*()]/g,`\\$&`),`g`);return e=>e.replace(n,e=>t.get(e)??e)}function Ra(e){return e==null||e===``}function za(e,t,n){if(typeof t!=`string`)return``+(t??void 0);let r=e===`_splat`;if(r&&(!t||/^[a-zA-Z0-9\-._~!/]*$/.test(t)))return t;let i=encodeURIComponent(t);return r&&(i=i.replaceAll(`%2F`,`/`)),n?n(i):i}function Ba(e,t,n,r,i){let a=e.endsWith(`/`)?`/`:``,o=``;for(let e of t){if(typeof e==`string`){o+=e;continue}let[t,s,c,l]=e,u=t===2,d=u&&l!==void 0?l+a:l,f=n[s];if(t!==3||f!=null){if(i&&(i[s]=f,u&&(i[`*`]=f)),u&&Ra(f)){if(c===`/`&&!d)continue;f=``}o+=c+za(s,f,r)+(d||``)}}return o+a||`/`}function Va(e={}){if(e.isNotFound=!0,e.throw)throw e;return e}function Ha(e){return e?.isNotFound===!0}var Ua=`__root__`;function Wa(e){e.statusCode=e.statusCode||e.code||307;let t=new Headers(e.headers);e.href&&t.get(`Location`)===null&&t.set(`Location`,e.href);let n=new Response(null,{status:e.statusCode,headers:t});if(n.options=e,e.throw)throw n;return n}function Ga(e){return e instanceof Response&&!!e.options}function Ka(e){let t=new Map,n,r;return{get(e){let n=t.get(e);if(n)return n.visited=!0,n.value},set(i,a){let o=t.get(i);if(o){o.value=a;return}if(t.size>=e){let e=n?.next().value;for(;!e||e.visited;)e?e.visited=!1:n=t.values(),e=n.next().value;e===r&&(n=void 0),t.delete(e.key)}let s={key:i,value:a,visited:!1};r=s,t.set(i,s)},clear(){t.clear(),n=void 0,r=void 0}}}var qa=4,Ja=5;function Ya(e){let t=e.names;if(t)return t;let n=[];for(let t of e)typeof t!=`string`&&n.push(t[1]);return e.names=n}function Xa(e,t,n){let r=e.slice(t,n);if(r.charCodeAt(0)===36)return r.length===1?[2,`_splat`,``,void 0]:[1,r.slice(1),``,``];let i=r.indexOf(`{`);if(i>=0){let a=r.indexOf(`}`,i),o=r.charCodeAt(i+1)===45,s=i+(o?3:2);if(a>=0&&r.charCodeAt(s-1)===36&&(!o||s<a)){let c=r.slice(s,a);return[o?3:c?1:2,c||`_splat`,r.slice(0,i),e.slice(t+a+1,c?n:e.length)]}}return r}function Za(e,t,n,r,i,a){let o=n,s=t.fullPath??t.from,c=t.options,l=s.length,u=s.endsWith(`/`)?l-1:l,d=c?.caseSensitive??e,f=c?.params?.parse??c?.parseParams,p,m=a?n-1:0;if(!r||s.includes(`$`)){p=a?.slice()??[];let e=ua(p);e&&typeof e!=`string`&&e[0]===2&&(p[p.length-1]=[e[0],e[1],e[2],e[3]===void 0?void 0:e[3]+s.substring(n-(s[n-2]===`/`?2:1),u)],m=l)}for(;o<l;){let e=o,t=s.indexOf(`/`,e),n=t===-1?l:t,a=Xa(s,e,n);o=n+1;let c;if(typeof a==`string`){if(!r)continue;let e=a,t;d?t=r.static??=new Map:(e=a.toLowerCase(),t=r.staticInsensitive??=new Map);let n=t.get(e);if(n)c=n;else{let n=$a(r);c=n,t.set(e,n)}}else{let t=a[0],h=a[2],g=a[3]??``;if(t===2&&(n=l,o=n+1),p&&m<n&&(m<e-1&&p.push(s.slice(m,e-1)),a[2]=`/`+h,t===2&&a[3]!==void 0&&u<l&&(a[3]=g.slice(0,-1)),p.push(a),m=n),!r)continue;let _=d&&!!(h||g);d||(h=h.toLowerCase(),g=g.toLowerCase());let v=t===1?r.dynamic??=[]:t===3?r.optional??=[]:r.wildcard??=[],y=t!==2&&!f&&v.find(e=>!e.parse&&e.caseSensitive===_&&e.prefix===h&&e.suffix===g);if(y)c=y;else{let e=$a(r,t,_,h,g);c=e,v.push(e),v.length===2&&i?.push(v)}}r=c}p&&m<u&&p.push(s.slice(m,u));let h=p?.slice();if(!r)return h;if(f&&t.children&&!t.isRoot&&t.id&&t.id.charCodeAt(t.id.lastIndexOf(`/`)+1)===95){let e=$a(r,Ja);(r.pathless??=[]).push(e),r=e}let g=(t.path||!t.children)&&!t.isRoot;if(g&&u<l){let e=$a(r,qa);r.index=e,r=e}return r.parse=f??null,r.priority=c?.params?.priority??0,r.route||(r.data=h,g&&(r.route=t)),[r,o,h]}function Qa(e,t){if(e.parse&&!t.parse)return-1;if(!e.parse&&t.parse)return 1;if(e.parse&&t.parse&&(e.priority||t.priority))return t.priority-e.priority;if(e.prefix&&t.prefix&&e.prefix!==t.prefix){if(e.prefix.startsWith(t.prefix))return-1;if(t.prefix.startsWith(e.prefix))return 1}if(e.suffix&&t.suffix&&e.suffix!==t.suffix){if(e.suffix.endsWith(t.suffix))return-1;if(t.suffix.endsWith(e.suffix))return 1}return e.prefix&&!t.prefix?-1:!e.prefix&&t.prefix?1:e.suffix&&!t.suffix?-1:!e.suffix&&t.suffix?1:e.caseSensitive&&!t.caseSensitive?-1:!e.caseSensitive&&t.caseSensitive?1:0}function $a(e,t=0,n,r,i){return{kind:t,depth:e?e.depth+1:0,pathless:null,index:null,static:null,staticInsensitive:null,dynamic:null,optional:null,wildcard:null,route:null,data:void 0,parent:e,parse:null,priority:0,caseSensitive:n,prefix:r,suffix:i}}function eo(e,t){let n=$a(),r=[];function i(e,t,n,a){let[o,s,c]=Za(!1,e,t,n,r,a);if(e.children)for(let t of e.children)i(t,s,o,c)}for(let t of e)i(t,1,n);for(let e of r)e.sort(Qa);t.masksTree=n,t.flatCache=Ka(1e3)}function to(e,t){e||=`/`;let n=t.flatCache.get(e);if(n!==void 0)return n;let r=ao(e,t.masksTree);return t.flatCache.set(e,r),r}function no(e,t,n,r,i){e||=`/`,r||=`/`;let a=t?`case\0${e}`:e,o=i.singleCache.get(a);return o||(o=$a(),Za(t,{from:e},1,o),i.singleCache.set(a,o)),ao(r,o,n)}function ro(e,t,n=!1){let r=n?e:`nofuzz\0${e}`,i=t.matchCache.get(r);if(i!==void 0)return i;e||=`/`;let a;try{a=ao(e,t.segmentTree,n)}catch(e){if(e instanceof URIError)a=null;else throw e}return a&&(a.branch=so(a.route)),t.matchCache.set(r,a),a}function io(e,t=!1){let n=$a(),r=[],i={},a={},o=0;function s(e,n,c,l){if(e.init(o),e.id in i&&Aa(),i[e.id]=e,o!==0&&e.path){let t=Na(e.fullPath);(!a[t]||e.fullPath.endsWith(`/`))&&(a[t]=e)}o++;let[u,d,f]=Za(t,e,n,c,r,l);if(e._interpolation=f,e.children)for(let t of e.children)s(t,d,u,f)}s(e,1,n);for(let e of r)e.sort(Qa);return{processedTree:{segmentTree:n,singleCache:Ka(1e3),matchCache:Ka(1e3),flatCache:null,masksTree:null},routesById:i,routesByPath:a}}function ao(e,t,n=!1){let r=e.split(`/`),i=lo(e,r,t,n);if(!i)return null;let[a]=oo(e,r,i);return{route:i.node.route,rawParams:a}}function oo(e,t,n){let r=co(n.node),i=n.node.data&&Ya(n.node.data),a=Object.create(null),o=n.extract?.part??0,s=n.extract?.node??0,c=n.extract?.path??0,l=n.extract?.param??0;for(;s<r.length;o++,s++,c++){let u=r[s];if(u.kind===qa)break;if(u.kind===Ja){o--,c--;continue}let d=t[o],f=c;if(d&&(c+=d.length),u.kind===1||u.kind===3){let e=i[l++];if(u.kind===3&&n.skipped&1<<s){o--,c=f-1;continue}let t=u.suffix||u.prefix?d.substring(u.prefix.length,d.length-u.suffix.length):d;(t||u.kind===1)&&(a[e]=decodeURIComponent(t))}else if(u.kind===2){let t=u,n=e.substring(f+t.prefix.length,e.length-t.suffix.length),r=decodeURIComponent(n);a[`*`]=r,a._splat=r;break}}return n.rawParams&&Object.assign(a,n.rawParams),[a,{part:o,node:s,path:c,param:l}]}function so(e){let t=[e];for(;e.parentRoute;)e=e.parentRoute,t.push(e);return t.reverse(),t}function co(e){let t=Array(e.depth+1);do t[e.depth]=e,e=e.parent;while(e);return t}function lo(e,t,n,r){if(e===`/`&&n.index)return{node:n.index,skipped:0};let i=!ua(t),a=i&&e!==`/`,o=t.length-+!!i,s=[{node:n,index:1,skipped:0,statics:0,dynamics:0,optionals:0}],c=null,l=null;for(;s.length;){let n=s.pop(),{node:i,index:u,skipped:d,statics:f,dynamics:p,optionals:m}=n,{extract:h,rawParams:g}=n;if(i.kind===2&&i.route&&!mo(l,n))continue;if(i.parse){if(!po(e,t,n))continue;g=n.rawParams,h=n.extract}r&&i.route&&i.kind!==qa&&mo(c,n)&&(c=n);let _=u===o;if(_&&(i.route&&(!a||i.kind===qa||i.kind===2)&&mo(l,n)&&(l=n),!i.optional&&!i.wildcard&&!i.index&&!i.pathless))continue;let v=_?void 0:t[u],y;if(_&&i.index){let n={node:i.index,index:u,skipped:d,statics:f,dynamics:p,optionals:m,extract:h,rawParams:g},r=!0;if(i.index.parse&&(po(e,t,n)||(r=!1)),r){if(!p&&!m&&!d&&fo(f,o))return n;mo(l,n)&&(l=n)}}if(i.wildcard)for(let e=i.wildcard.length-1;e>=0;e--){let n=i.wildcard[e],{prefix:r,suffix:a}=n;if(!r||!_&&(n.caseSensitive?v:y??=v.toLowerCase()).startsWith(r)){if(a){if(_)continue;let e=t.slice(u).join(`/`),i=e.slice(-a.length);if((n.caseSensitive?i:i.toLowerCase())!==a||e.length-a.length<r.length)continue}s.push({node:n,index:o,skipped:d,statics:f,dynamics:p,optionals:m,extract:h,rawParams:g})}}if(i.optional){let e=d|1<<i.depth+1;for(let t=i.optional.length-1;t>=0;t--){let n=i.optional[t];s.push({node:n,index:u,skipped:e,statics:f,dynamics:p,optionals:m,extract:h,rawParams:g})}if(!_)for(let e=i.optional.length-1;e>=0;e--){let t=i.optional[e],{prefix:n,suffix:r}=t;if(n||r){let e=t.caseSensitive?v:y??=v.toLowerCase();if(n&&!e.startsWith(n)||r&&e.indexOf(r,e.length-r.length)<n.length)continue}s.push({node:t,index:u+1,skipped:d,statics:f,dynamics:p,optionals:m+uo(o,u),extract:h,rawParams:g})}}if(!_&&i.dynamic&&v)for(let e=i.dynamic.length-1;e>=0;e--){let t=i.dynamic[e],{prefix:n,suffix:r}=t;if(n||r){let e=t.caseSensitive?v:y??=v.toLowerCase();if(n&&!e.startsWith(n)||r&&e.indexOf(r,e.length-r.length)<n.length)continue}s.push({node:t,index:u+1,skipped:d,statics:f,dynamics:p+uo(o,u),optionals:m,extract:h,rawParams:g})}if(!_&&i.staticInsensitive){let e=i.staticInsensitive.get(y??=v.toLowerCase());e&&s.push({node:e,index:u+1,skipped:d,statics:f+uo(o,u),dynamics:p,optionals:m,extract:h,rawParams:g})}if(!_&&i.static){let e=i.static.get(v);e&&s.push({node:e,index:u+1,skipped:d,statics:f+uo(o,u),dynamics:p,optionals:m,extract:h,rawParams:g})}if(i.pathless)for(let e=i.pathless.length-1;e>=0;e--){let t=i.pathless[e];s.push({node:t,index:u,skipped:d,statics:f,dynamics:p,optionals:m,extract:h,rawParams:g})}}if(l)return l;if(r&&c){let n=c.index;for(let e=0;e<c.index;e++)n+=t[e].length;let r=n===e.length?`/`:e.slice(n);return c.rawParams??=Object.create(null),c.rawParams[`**`]=decodeURIComponent(r),c}return null}function uo(e,t){return 2**(e-t-1)}function fo(e,t){return e===2**(t-1)-1}function po(e,t,n){let r,i;try{[r,i]=oo(e,t,n)}catch{return null}if(n.rawParams=r,n.extract=i,!n.node.parse)return!0;try{if(n.node.parse(r)===!1)return null}catch{}return!0}function mo(e,t){return!e||t.statics>e.statics||t.statics===e.statics&&(t.dynamics>e.dynamics||t.dynamics===e.dynamics&&(t.optionals>e.optionals||t.optionals===e.optionals&&((t.node.kind===qa)>(e.node.kind===qa)||t.node.kind===qa==(e.node.kind===qa)&&t.node.depth>e.node.depth)))}function ho(){try{return sessionStorage}catch{return}}var go=`tsr-scroll-restoration-v1_3`,_o=ho();function vo(){try{return JSON.parse(_o?.getItem(`tsr-scroll-restoration-v1_3`)||`{}`)}catch{return{}}}var yo=vo(),bo=`data-scroll-restoration-id`,xo=e=>e.state.__TSR_key||e.href;function So(e){let t=e.getAttribute(bo);if(t)return`[${bo}="${t}"]`;let n=``,r=e,i;for(;i=r.parentNode;){let e=1,t=r;for(;t=t.previousElementSibling;)e++;let a=`${r.localName}:nth-child(${e})`;n=n?`${a} > ${n}`:a,r=i}return n}var Co=!1,wo=`window`;function To(e){try{return typeof e==`function`?e():document.querySelector(e)}catch{}}function Eo(e){let t=new Set;for(let n of e){if(n===wo)continue;let e=To(n);e&&t.add(e)}return t}function Do(e,t){let n=t??e.options.scrollRestoration,r=e._scroll;n&&(r.e=!0);let i=e.options.getScrollRestorationKey||xo,a=new Set,o=e=>{let t=yo[e]||={};for(let e of a)e===document?t[wo]={scrollX,scrollY}:e.isConnected&&(t[So(e)]={scrollX:e.scrollLeft,scrollY:e.scrollTop})};n&&!r.s&&(r.s=!0,Co=!1,history.scrollRestoration=`manual`,document.addEventListener(`scroll`,e=>{Co||a.add(e.target)},!0),e.subscribe(`onBeforeLoad`,e=>{e.fromLocation&&o(i(e.fromLocation)),a.clear()}),addEventListener(`pagehide`,()=>{history.scrollRestoration=`auto`,o(i(e.stores.resolvedLocation.get()??e.stores.location.get()));try{_o?.setItem(go,JSON.stringify(yo))}catch{}}),addEventListener(`pageshow`,e=>{e.persisted&&(history.scrollRestoration=`manual`)})),r.r||(r.r=!0,e.subscribe(`onRendered`,t=>{let n=e.options.scrollRestorationBehavior,o=e.options.scrollToTopSelectors,s=r.n,c=r.h,l;if(a.clear(),r.n=!0,r.h=!1,typeof e.options.scrollRestoration==`function`&&!e.options.scrollRestoration({location:e.latestLocation}))return;let u=i(t.toLocation),d=t.fromLocation&&i(t.fromLocation);if(r.e&&d&&d!==u){let e=yo[d];if(e){let t=yo[u];for(let n in e){if(n===wo){if(s)continue}else{let e=To(n);if(!e||s&&o&&(l??=Eo(o),l.has(e)))continue}t||=yo[u]={},t[n]??=e[n]}}}Co=!0;try{let e=t.toLocation.hash,i=t.toLocation.state.__hashScrollIntoViewOptions??!0,a=!1;if(s){!e&&o&&(l??=Eo(o));let t=e&&i&&c,s=r.e?yo[u]:void 0;if(s)for(let e in s){let{scrollX:r,scrollY:i}=s[e];if(e===wo){if(t)continue;scrollTo({top:i,left:r,behavior:n}),a=!0}else{let t=To(e);t&&(t.scrollLeft=r,t.scrollTop=i,l?.delete(t))}}if(!e){let e={top:0,left:0,behavior:n};if(a||scrollTo(e),l)for(let t of l)t.scrollTo(e)}}!a&&e&&i&&document.getElementById(e)?.scrollIntoView(i)}finally{Co=!1}}))}function Oo(e,t=String){let n;for(let r in e){let i=e[r];i!==void 0&&(n||=new URLSearchParams).set(r,t(i))}return n?n.toString():``}function ko(e){return e?e===`false`?!1:e===`true`?!0:e*0==0&&+e+``===e?+e:e:``}function Ao(e){let t=new URLSearchParams(e),n=Object.create(null);for(let[e,r]of t.entries()){let t=n[e];t==null?n[e]=ko(r):Array.isArray(t)?t.push(ko(r)):n[e]=[t,ko(r)]}return n}var jo=/^(?:\s|["[{\d-]|fa|nu|tr)/,Mo=Po(JSON.parse),No=Fo(JSON.stringify,JSON.parse);function Po(e){let t=e===JSON.parse;return n=>{n[0]===`?`&&(n=n.slice(1));let r=Ao(n);for(let n in r){let i=r[n];if(typeof i==`string`){if(t&&!jo.test(i))continue;try{r[n]=e(i)}catch{}}}return r}}function Fo(e,t){let n=t===JSON.parse;function r(r){if(r&&typeof r==`object`)try{return e(r)}catch{}else if(t&&typeof r==`string`){if(n&&!jo.test(r))return r;try{return t(r),e(r)}catch{}}return r}return e=>{let t=Oo(e,r);return t?`?${t}`:``}}function Io(e,t,n){let r=Pa(e),i=`/${r}`,a=t?i:i.toLowerCase(),o=`${a}/`,s={input:({url:e})=>{let n=t?e.pathname:e.pathname.toLowerCase();return n===a?e.pathname=`/`:n.startsWith(o)&&(e.pathname=e.pathname.slice(i.length)),e},output:({url:e})=>(e.pathname=ja(`/${r}${e.pathname}`),e)};return n?{input:({url:e})=>Lo(n,s.input({url:e})),output:({url:e})=>s.output({url:Ro(n,e)})}:s}function Lo(e,t){let n=e?.input?.({url:t});if(n){if(typeof n==`string`)return new URL(n);if(n instanceof URL)return n}return t}function Ro(e,t){let n=e?.output?.({url:t});if(n){if(typeof n==`string`)return new URL(n);if(n instanceof URL)return n}return t}function zo(e,t){let{createMutableStore:n,createReadonlyStore:r,batch:i}=t,a=new Map,o=n(`idle`),s=n(e),c=n(void 0),l=n([]),u=r(()=>l.get().map(e=>a.get(e).get())),d=r(()=>({status:o.get(),isLoading:o.get()===`pending`,matches:u.get(),location:s.get(),resolvedLocation:c.get()}));function f(e){let t=a.get(e);return t||(t=n(void 0),a.set(e,t)),t}let p={status:o,location:s,resolvedLocation:c,ids:l,matches:u,byRoute:a,__store:d,getMatchStore:f,setMatches:m};function m(e){let t=l.get(),n=e.map(e=>e.routeId);i(()=>{ka(t,n)||l.set(n);for(let e of t)n.includes(e)||a.get(e).set(()=>void 0);for(let t of e){let e=f(t.routeId);e.get()!==t&&e.set(t)}})}return p}var Bo=`__TSR_index`,Vo=`popstate`,Ho=`beforeunload`,Uo=/^[\x00-\x20]*(?:[\\/][\t\n\r]*){2,}/;function Wo(e){let t=Uo.exec(e);return t?`/`+e.slice(t[0].length):e}function Go(e){return/[\x00-\x1f\x7f]/.test(e)&&(e=e.replace(/[\x00-\x1f\x7f]/g,e=>`
|
|
2
|
+
\r`.includes(e)?``:encodeURIComponent(e))),Wo(e)}function Ko(e){let t=e.getLocation(),n=new Set,r=r=>{t=e.getLocation(),n.forEach(e=>e({location:t,action:r}))},i=n=>{e.notifyOnIndexChange??!0?r(n):t=e.getLocation()},a=async n=>{let r=n.navigateOpts?.ignoreBlocker?void 0:e.getBlockers?.();if(typeof document<`u`&&r?.length&&(n.type===`PUSH`||n.type===`REPLACE`))for(let i of r){let r=Yo(n.path,n.state);if(await i.blockerFn({currentLocation:t,nextLocation:r,action:n.type})){e.onBlocked?.();return}}n.task()};return{get location(){return t},get length(){return e.getLength()},subscribers:n,subscribe:e=>(n.add(e),()=>{n.delete(e)}),push:(n,i,o)=>{let s=t.state[Bo];i=qo(s+1,i),a({task:()=>{e.pushState(n,i),r({type:`PUSH`})},navigateOpts:o,type:`PUSH`,path:n,state:i})},replace:(n,i,o)=>{let s=t.state[Bo];i=qo(s,i),a({task:()=>{e.replaceState(n,i),r({type:`REPLACE`})},navigateOpts:o,type:`REPLACE`,path:n,state:i})},go:(t,n)=>{a({task:()=>{e.go(t,n?.ignoreBlocker??!1),i({type:`GO`,index:t})},navigateOpts:n,type:`GO`})},back:t=>{a({task:()=>{e.back(t?.ignoreBlocker??!1),i({type:`BACK`})},navigateOpts:t,type:`BACK`})},forward:t=>{a({task:()=>{e.forward(t?.ignoreBlocker??!1),i({type:`FORWARD`})},navigateOpts:t,type:`FORWARD`})},canGoBack:()=>t.state[Bo]!==0,createHref:t=>e.createHref(t),block:t=>{if(!e.setBlockers)return()=>{};let n=e.getBlockers?.()??[];return e.setBlockers([...n,t]),()=>{let n=e.getBlockers?.()??[];e.setBlockers?.(n.filter(e=>e!==t))}},flush:()=>e.flush?.(),destroy:()=>e.destroy?.(),notify:r,_getBlockers:()=>e.getBlockers?.()??[]}}function qo(e,t){let n=Xo();return{...t,key:n,__TSR_key:n,[Bo]:e}}function Jo(e){let t=e?.window??(typeof document<`u`?window:void 0),n=t.history.pushState,r=t.history.replaceState,i=[],a=()=>i,o=e=>i=e,s=t=>Go(e?.createHref?e.createHref(t):t),c=e?.parseLocation??(()=>Yo(`${t.location.pathname}${t.location.search}${t.location.hash}`,t.history.state));if(!t.history.state?.__TSR_key&&!t.history.state?.key){let e=Xo();t.history.replaceState({[Bo]:0,key:e,__TSR_key:e},``)}let l=c(),u,d=!1,f=!1,p=!1,m=!1,h=()=>l,g,_=()=>{g&&(S._ignoreSubscribers=!0,(g[2]?t.history.pushState:t.history.replaceState)(g[1],``,g[0]),S._ignoreSubscribers=!1,g=void 0,u=void 0)},v=(t,n,r)=>{let i=e?.createHref?s(n):void 0,a=!!g;a||(u=l),l=Yo(n,r),g=[i??l.href,r,g?.[2]||t],a||queueMicrotask(()=>_())},y=e=>{l=c(),S.notify({type:e})},b=async()=>{if(m=!1,f){f=!1;return}let e=c(),n=e.state[Bo]-l.state[Bo],r=n===1,i=n===-1,o=!r&&!i||d;d=!1;let s=o?`GO`:i?`BACK`:`FORWARD`,u=o?{type:`GO`,index:n}:{type:i?`BACK`:`FORWARD`};if(p)p=!1;else{let r=a();if(typeof document<`u`&&r.length){for(let i of r)if(await i.blockerFn({currentLocation:l,nextLocation:e,action:s})){f=!0,t.history.go(-n),S.notify(u);return}}}l=c(),S.notify(u)},x=e=>{if(m){m=!1;return}let t=!1,n=a();if(typeof document<`u`&&n.length)for(let e of n){let n=e.enableBeforeUnload??!0;if(n===!0||typeof n==`function`&&n()===!0){t=!0;break}}if(t)return e.preventDefault(),e.returnValue=``},S=Ko({getLocation:h,getLength:()=>t.history.length,pushState:(e,t)=>v(!0,e,t),replaceState:(e,t)=>v(!1,e,t),back:e=>(e&&(p=!0,m=!0),t.history.back()),forward:e=>{e&&(p=!0,m=!0),t.history.forward()},go:(e,n)=>{d=!0,n&&(p=!0,m=!0),t.history.go(e)},createHref:s,flush:_,destroy:()=>{t.history.pushState=n,t.history.replaceState=r,t.removeEventListener(Ho,x,{capture:!0}),t.removeEventListener(Vo,b)},onBlocked:()=>{u&&l!==u&&(l=u)},getBlockers:a,setBlockers:o,notifyOnIndexChange:!1});return S._ignoreNextBeforeUnload=e=>{m=!1;try{e=new URL(e,t.document.baseURI).href,m=/^https?:/.test(e)&&(!e.includes(`#`)||e.split(`#`)[0]!==t.location.href.split(`#`)[0])}catch{}},t.addEventListener(Ho,x,{capture:!0}),t.addEventListener(Vo,b),t.history.pushState=function(...e){let r=n.apply(t.history,e);return S._ignoreSubscribers||y(`PUSH`),r},t.history.replaceState=function(...e){let n=r.apply(t.history,e);return S._ignoreSubscribers||y(`REPLACE`),n},S}function Yo(e,t){let n=Go(e),r=n.indexOf(`#`),i=n.indexOf(`?`);if(!t){let e=Xo();t={[Bo]:0,key:e,__TSR_key:e}}return{href:n,pathname:n.slice(0,r>-1?i>-1?Math.min(r,i):r:i>-1?i:n.length),hash:r>-1?n.slice(r):``,search:i>-1?n.slice(i,r===-1?void 0:r):``,state:t}}function Xo(){return(Math.random()+1).toString(36).slice(7)}function Zo(e,t){return e.protocol!==`http:`&&e.protocol!==`https:`||e.origin!==t||!!e.username||!!e.password}function Qo(e){return e.pathname+e.search+e.hash}function $o(e){return e.options.loader||e.options.beforeLoad||e.lazyFn||e.options.component?.preload||e.options.pendingComponent?.preload}function es(e,t){return{fromLocation:t,toLocation:e,pathChanged:t?.pathname!==e.pathname,hrefChanged:t?.href!==e.href,hashChanged:t?.hash!==e.hash}}function ts({key:e,__TSR_key:t,__TSR_index:n,__hashScrollIntoViewOptions:r,...i}){return i}function ns(e){return e.findIndex(e=>e.status===`error`||e.status===`notFound`||e._notFound)+1}function rs(e,t,n,r,i,a){r&&(t=t.slice(0,r)),i&&(n=n.slice(0,i));for(let r of t){if(a&&e._tx!==a)return;n.some(e=>e.routeId===r.routeId)||e.routesById[r.routeId].options.onLeave?.(r)}for(let r of n){if(a&&e._tx!==a)return;e.routesById[r.routeId].options[t.some(e=>e.routeId===r.routeId)?`onStay`:`onEnter`]?.(r)}}var is=class{constructor(e,t){this.tempLocationKey=`${Math.round(Math.random()*1e7)}`,this._scroll={n:!0},this.subscribers=new Set,this._cache=new Map,this._committed=[],this.startTransition=async e=>(e(),!1),this.update=e=>{let t=this.options;this.options={...t,...e},this.isServer=this.options.isServer??!1??typeof document>`u`,this.staticLocations=new WeakMap,this.protocolAllowlist=new Set(this.options.protocolAllowlist),(!this.history||this.options.history&&this.options.history!==this.history)&&(this.history=this.options.history?this.options.history:Jo()),this.origin=this.options.origin,this.origin||=window?.origin&&window.origin!==`null`?window.origin:`http://localhost`;let n=this.options.basepath??`/`,r=this.options.rewrite,i=this.basepath!==n||t?.rewrite!==r||t?.caseSensitive!==this.options.caseSensitive;if(i&&(this.basepath=n,this.rewrite=n!==`/`&&Pa(n)?Io(n,this.options.caseSensitive,r):r),this.history&&this.updateLatestLocation(),this.options.routeTree!==this.routeTree){this.routeTree=this.options.routeTree;let e;e=this.buildRouteTree(),this.setRoutes(e)}if(this.stores)i&&this.stores.location.set(this.latestLocation);else if(this.latestLocation){let e=this.getStoreConfig(this);this.batch=e.batch,this.stores=zo(this.latestLocation,e),Do(this)}},this.updateLatestLocation=()=>{this.latestLocation=this.parseLocation(this.history.location,this.latestLocation)},this.buildRouteTree=()=>{let e=io(this.routeTree,this.options.caseSensitive);return this.options.routeMasks&&eo(this.options.routeMasks,e.processedTree),{...e,resolvePathCache:Ka(1e3)}},this.subscribe=(e,t)=>{let n={eventType:e,fn:t};return this.subscribers.add(n),()=>{this.subscribers.delete(n)}},this.emit=e=>{for(let t of this.subscribers)if(t.eventType===e.type)try{t.fn(e)}catch(e){console.error(e)}},this.parseLocation=(e,t)=>{let n=({pathname:e,search:n,hash:r,href:i},a)=>{if(!this.rewrite&&!/[ \x00-\x1f\x7f\u0080-\uffff]/.test(e)){let i=this.options.parseSearch(n),o=this.options.stringifySearch(i);return{href:e+o+r,publicHref:e+o+r,pathname:Da(e),external:!1,searchStr:o,search:ha(t?.search,i),hash:Da(r.slice(1)),state:ga(t?.state,a)}}let o=Lo(this.rewrite,new URL(i,this.origin)),s=this.options.parseSearch(o.search),c=this.options.stringifySearch(s);return o.search=c,{href:o.href.replace(o.origin,``),publicHref:i,pathname:Da(Wo(o.pathname)),external:!!this.rewrite&&Zo(o,this.origin),searchStr:c,search:ha(t?.search,s),hash:Da(o.hash.slice(1)),state:ga(t?.state,a)}},r=n(e,e.state),{__tempLocation:i,__tempKey:a}=r.state;if(i&&(!a||a===this.tempLocationKey)){let e=n(i,{...i.state,__tempLocation:void 0,key:r.state.key,__TSR_key:r.state.__TSR_key});return e.maskedLocation=r,e}return r},this.matchRoutes=(e,t,n)=>typeof e==`string`?this.matchRoutesInternal({pathname:e,search:t},n):this.matchRoutesInternal(e,t),this.getMatchedRoutes=e=>{let t=Object.create(null),n=ro(Na(e),this.processedTree,!0);return n&&Object.assign(t,n.rawParams),[n?.branch||[this.routesById.__root__],t,n?.route]},this.buildLocation=e=>{{let t=this.staticLocations.get(e);if(t)return t}let t=!1,n=(n={})=>{if(n.href){let e=Yo(n.href,{});n={...n,to:Lo(this.rewrite,new URL(e.pathname,this.origin)).pathname,search:this.options.parseSearch(e.search),hash:e.hash.slice(1)}}let r=e._fromLocation||this._pendingLocation||this.latestLocation,i,a=()=>(t=!0,r),o=()=>i??=this.matchRoutesLightweight(a()),s=n.to?`${n.to}`:`.`,c=Ia(s[0]===`/`?``:n.unsafeRelative===`path`?a().pathname:n.from??o()[1],s,this.options.trailingSlash,this.resolvePathCache),l=this.routesByPath[Na(c)],u=c.includes(`$`),d;if(l)d=l._branch??=so(l);else if(u)d=[];else{let[e,t,n]=this.getMatchedRoutes(c);d=e,this.options.notFoundRoute&&(!n||n.path!==`/`&&t[`**`])&&(d=[...d,this.options.notFoundRoute])}let f=u?l?._interpolation??Za(!1,{fullPath:c},0):void 0,p;for(let e of d){let t=e.options.params?.stringify??e.options.stringifyParams;if(t){let e=o()[3];if(p??=ls(n.params,e),!pa(p))break;p===e&&(p=Object.assign(ma(),p));try{Object.assign(p,t(p))}catch{}}}p??=ls(n.params,us(n.params,f)?o()[3]:ds);let m=e.leaveParams?c:Wo(Da(f?Ba(c,f,p,this.pathParamsDecoder):c)),h=fs(d,e._includeValidateSearch),g=()=>{let t=o()[2];if(e._includeValidateSearch&&this.options.search?.strict){let e={};d.forEach(n=>{if(n.options.validateSearch)try{Object.assign(e,cs(n.options.validateSearch,{...e,...t}))}catch{}}),t=e}return t},_=h.length?ps(h,g(),n):n.search===!0?g():typeof n.search==`function`?n.search(g()):n.search||ds,v=this.options.stringifySearch(_),y=n.hash===!0?a().hash:typeof n.hash==`function`?n.hash(a().hash):n.hash||void 0,b=y?`#${y}`:``,x=n.state?n.state===!0?a().state:typeof n.state==`function`?n.state(a().state):n.state:ds,S=`${m}${v}${b}`,C,w,ee=!1;if(this.rewrite){let e=new URL(S,this.origin),t=e.origin,n=Ro(this.rewrite,e);C=Qo(e),Zo(n,t)?(w=n.href,ee=!0):w=Wo(Qo(n))}else C=Oa(S),w=C;return{publicHref:w,href:C,pathname:m,search:_,searchStr:v,state:x,hash:y??``,external:ee,unmaskOnReload:n.unmaskOnReload}},r=n(e);if(e.mask)r.maskedLocation=n({from:e.from,...e.mask});else if(this.options.routeMasks){let t=to(r.pathname,this.processedTree);if(t){let i=Object.assign(ma(),t.rawParams),{from:a,params:o,...s}=t.route,c=ls(o,i);r.maskedLocation=n({from:e.from,...s,params:c})}}return!t&&e._fromLocation&&this.staticLocations.set(e,r),r},this.commitLocation=async({viewTransition:e,ignoreBlocker:t,...n})=>{let r=n.maskedLocation??n;if(r.external)return as(this,r.publicHref,{replace:n.replace,ignoreBlocker:t});let i,a=Na(this.latestLocation.href)===Na(n.href)&&va(ts(n.state),ts(this.latestLocation.state)),o=this._commitPromise,s,c=new Promise(e=>{s=e});if(c.resolve=()=>{s(),o?.resolve()},this._commitPromise=c,a)this.load();else{let{maskedLocation:r,hashScrollIntoView:a,...o}=n;r&&(o={...r,state:{...r.state,__tempKey:void 0,__tempLocation:{...o,search:o.searchStr,state:{...o.state,__tempKey:void 0,__tempLocation:void 0,__TSR_key:void 0,key:void 0}}}},(o.unmaskOnReload??this.options.unmaskOnReload??!1)&&(o.state.__tempKey=this.tempLocationKey)),o.state={...o.state,__hashScrollIntoViewOptions:a??this.options.defaultHashScrollIntoView??!0},this.shouldViewTransition=e,i=n.replace?`REPLACE`:`PUSH`,this.history[i===`REPLACE`?`replace`:`push`](o.publicHref,o.state,{ignoreBlocker:t}),this.history.subscribers.size||this.load({action:{type:i}})}return this._scroll.n=n.resetScroll??!0,this._commitPromise},this.buildAndCommitLocation=({replace:e,resetScroll:t,hashScrollIntoView:n,viewTransition:r,ignoreBlocker:i,...a}={})=>{let o=this.buildLocation({...a,_includeValidateSearch:!0});this._pendingLocation=o;let s=this.commitLocation({...o,viewTransition:r,replace:e,resetScroll:t,hashScrollIntoView:n,ignoreBlocker:i});return queueMicrotask(()=>{this._pendingLocation===o&&(this._pendingLocation=void 0)}),s},this.navigate=async({to:e,reloadDocument:t,href:n,publicHref:r,...i})=>{let a=n?wa(n):void 0;if(a||t){if(e!==void 0||!n){let t=this.buildLocation({to:e,...i}),a=t.maskedLocation??t;n??=a.publicHref,r??=a.publicHref}let t=!a&&r?r:n;return as(this,t,i)}return this.buildAndCommitLocation({...i,href:n,to:e,_isNavigate:!0})},this.load=async e=>{this.updateLatestLocation(),e?.action&&(this._scroll.h=e.action.type===`PUSH`||e.action.type===`REPLACE`),await oc(this,e)},this.startViewTransition=e=>{let t=this.shouldViewTransition??this.options.defaultViewTransition;if(this.shouldViewTransition=void 0,t&&typeof document.startViewTransition==`function`){let n;if(typeof t==`object`&&window.CSS?.supports?.(`selector(:active-view-transition-type(a))`)){let r=this.latestLocation,i=this.stores.resolvedLocation.get(),a=typeof t.types==`function`?t.types(es(r,i)):t.types;if(a===!1)return e();n={update:e,types:a}}else n=e;return document.startViewTransition(n).updateCallbackDone}return e()},this.invalidate=e=>{let t=this._committed,n=e?.filter,r=this._preloads,i=new Set,a=e=>{(!n||n(e))&&i.add(e.id)};t.forEach(a),this._cache.forEach(a),r?.forEach(e=>e.forEach(a)),this._tx?.[3].forEach(a);let o=[];for(let[e,t]of r??[])t.some(e=>i.has(e.id))&&(r.delete(e),o.push(e));let s=t=>{if(i.has(t.id)){let n=this.routesById[t.routeId],r={...t,invalid:!0,...(e?.forcePending||t.status===`error`||t.status===`notFound`)&&$o(n)?{status:`pending`,error:void 0}:void 0};return t._flight=void 0,r}return t};this._committed=t.map(s);for(let[t,n]of this._cache)i.has(t)&&(n.invalid=!0,e?.forcePending&&(n.status=`pending`));for(let e of i){let t=this._flights?.get(e);this._flights?.delete(e),t&&!t[2]&&o.push(t[1])}for(let e of o)e.abort();return this.shouldViewTransition=!1,this.load({sync:e?.sync})},this.resolveRedirect=e=>{let t=e.options,n=e.headers.get(`Location`)||t.href;if(!n){let e=this.buildLocation(t);n=(e.maskedLocation??e).publicHref||`/`}let r;if(Ta.test(n)||(r=wa(n))&&!this.protocolAllowlist.has(r))throw Error(`Redirect blocked: unsafe protocol`);if(r===`http:`||r===`https:`){let e=new URL(n);e.pathname.startsWith(`//`)?n=e.href:Zo(e,this.origin)||(n=Qo(e),r=void 0)}return r&&(t.reloadDocument=!0),t.href=n,e.headers.set(`Location`,n),e},this.clearCache=e=>{let t=this._cache,n=this._preloads,r=e?.filter,i=[],a=[];for(let[e,n]of t)(!r||r(n))&&(a.push(e),i.push(n));let o=[];for(let[e,t]of n??[])(!r||t.some(r))&&(o.push(e),i.push(...t));for(let e of a)t.delete(e);for(let e of o)n.delete(e);for(let e of i){let t=e._flight;e._flight=void 0,t&&!--t[2]&&(this._flights?.get(e.id)===t&&this._flights.delete(e.id),o.push(t[1]))}for(let e of o)e.abort()},this.loadRouteChunk=vs,this.preloadRoute=e=>sc(this,e),this.matchRoute=(e,t)=>{let n={...e,to:e.to?Ia(e.from||``,e.to,this.options.trailingSlash,this.resolvePathCache):void 0,params:e.params||{},leaveParams:!0},r=this.buildLocation(n),i=this.stores.status.get()===`pending`;if(t?.pending&&!i)return!1;let a=t?.pending??!i?this.latestLocation:this.stores.resolvedLocation.get()||this.stores.location.get(),o=no(r.pathname,t?.caseSensitive??!1,t?.fuzzy??!1,a.pathname,this.processedTree);return!o||e.params&&!va(o.rawParams,e.params,!0)?!1:t?.includeSearch??!0?va(a.search,r.search,!0)?o.rawParams:!1:o.rawParams},this.getStoreConfig=t,e.pathParamsAllowedCharacters?.length&&(this.pathParamsDecoder=La(e.pathParamsAllowedCharacters)),this.update({defaultPreloadDelay:50,defaultPendingMs:1e3,defaultPendingMinMs:500,context:void 0,...e,caseSensitive:e.caseSensitive??!1,notFoundMode:e.notFoundMode??`fuzzy`,stringifySearch:e.stringifySearch??No,parseSearch:e.parseSearch??Mo,protocolAllowlist:e.protocolAllowlist??Ca}),self.__TSR_ROUTER__=this}isShell(){return!!this.options.isShell}get state(){return this.stores.__store.get()}setRoutes(e){Object.assign(this,e),this.lightweightCache=new WeakMap,this.staticLocations=new WeakMap;let t=this.options.notFoundRoute;t&&(t.init(99999999999),this.routesById[t.id]!==t&&(t._interpolation=Za(!1,t,0)),this.routesById[t.id]=t)}matchRoutesInternal(e,t){let[n,r,i]=this.getMatchedRoutes(e.pathname),a=n,o=!1;(i?i.path!==`/`&&r[`**`]:Na(e.pathname))&&(this.options.notFoundRoute?a=[...a,this.options.notFoundRoute]:o=!0);let s=o?ms(this.options.notFoundMode,a):void 0,c=Array(a.length),l=this._committed,u=(e,t)=>{let n=l[t];return n?.routeId===e.id?n:e===this.options.notFoundRoute?l.find(t=>t.routeId===e.id):void 0},d;for(let n=0;n<a.length;n++){let i=a[n],o=c[n-1],l,f,p;{let n=o?.search??e.search,r=o?._strictSearch??void 0;try{let e=cs(i.options.validateSearch,{...n})??void 0;l={...n,...e},f={...r,...e}}catch(e){let r=e;if(e instanceof os||(r=new os(e.message,{cause:e})),t?.throwOnError)throw r;l=n,f={},p=r}}let m=``,h=``;try{m=i.options.loaderDeps?.({search:l})??``,h=m&&JSON.stringify(m)||``}catch(e){if(t?.throwOnError)throw e;p??=e}let g=ma(),_=i._interpolation?Ba(i.fullPath,i._interpolation,r,this.pathParamsDecoder,g):i.fullPath,v=i.id+_+h,y=u(i,n),b=this._cache.get(v)??(y?.id===v?y:void 0);d=b?._strictParams??Object.assign(g,d);let x;if(!b)try{hs(i,d)}catch(e){if(x=Ha(e)||Ga(e)?e:new ss(e.message,{cause:e}),t?.throwOnError)throw x}let S=y?`stay`:`enter`,C;if(b)C={...b,cause:S,search:ha(y?y.search:b.search,l),_strictSearch:f,searchError:p};else{let e=$o(i)?`pending`:`success`;C={id:v,ssr:i.options.ssr,index:n,routeId:i.id,params:y?.params??d,_strictParams:d,pathname:_,updatedAt:Date.now(),search:y?ha(y.search,l):l,_strictSearch:f,searchError:p,status:e,isFetching:!1,error:void 0,paramsError:x,context:{},abortController:t?._controller??new AbortController,cause:S,loaderDeps:y?ga(y.loaderDeps,m):m,invalid:!1,preload:!1,staticData:i.options.staticData||{},fullPath:i.fullPath}}let w=s===i.id;C._notFound&&!w&&(C.error=void 0),C._notFound=w,c[n]=C}for(let e=0;e<c.length;e++){let n=c[e];n.params=n.cause===`stay`?ha(n.params,d):d,t?._controller&&(n.context={})}return c}matchRoutesLightweight(e){let t=ua(this.stores.ids.get()),n=t?this.stores.byRoute.get(t).get():void 0,r=n?.id,i=this.lightweightCache.get(e);if(i&&i[0]===r)return i[1];let[a,o]=this.getMatchedRoutes(e.pathname),s=ua(a),c={...e.search};for(let e of a)try{Object.assign(c,cs(e.options.validateSearch,c))}catch{}let l=n&&n.routeId===s.id&&n.pathname===e.pathname,u;if(l)u=n.params;else{let e=o;for(let t of a)try{hs(t,e)}catch{}u=e}let d=[a,s.fullPath,c,u];return this.lightweightCache.set(e,[r,d]),d}};async function as(e,t,{replace:n,ignoreBlocker:r}){if(!Ea(t,e.protocolAllowlist)){if(!r){let t=e.history._getBlockers();for(let r of t)if(r?.blockerFn&&await r.blockerFn({currentLocation:e.history.location,nextLocation:e.history.location,action:n?`REPLACE`:`PUSH`}))return}e.history._ignoreNextBeforeUnload?.(t),n?window.location.replace(t):window.location.href=t}}var os=class extends Error{},ss=class extends Error{};function cs(e,t){if(e==null)return{};if(`~standard`in e){let n=e[`~standard`].validate(t);if(n instanceof Promise)throw new os(`Async validation not supported`);if(n.issues)throw new os(JSON.stringify(n.issues,void 0,2),{cause:n});return n.value}return`parse`in e?e.parse(t):typeof e==`function`?e(t):{}}function ls(e,t){if(e===void 0||e===!0)return t;let n=Object.create(null);return e===!1||e===null?n:typeof e==`function`?(Object.assign(n,t),Object.assign(n,e(n))):Object.assign(n,t,e)}function us(e,t){return typeof e==`function`?!0:!t||e===!1||e===null?!1:e===void 0||e===!0||t.some(t=>typeof t!=`string`&&!fa.call(e,t[1]))}var ds=Object.freeze({});function fs(e,t){let n=[];for(let r=0;r<e.length;r++){let i=e[r].options;`search`in i?i.search?.middlewares&&n.push(...i.search.middlewares):(i.preSearchFilters||i.postSearchFilters)&&n.push(({search:e,next:t})=>{let n=t(i.preSearchFilters?i.preSearchFilters.reduce((e,t)=>t(e),e):e);return i.postSearchFilters?i.postSearchFilters.reduce((e,t)=>t(e),n):n});let a=i.validateSearch;t&&a&&n.push(({search:e,next:t,meta:n})=>{let r=t(e);try{let e=cs(a,r);if(n&&e)for(let t in e)t in r||(n.defaulted||=new Map).set(t,e[t]);return{...r,...e}}catch{}return r})}return n}function ps(e,t,n){let r=(t,i,a)=>{if(t>=e.length){if(!n.search)return{};if(n.search===!0)return i;let e=da(n.search,i);return a&&(a.explicit=e),e}return e[t]({search:i,next:(e,n)=>{if(n){let n=a||{};return{search:r(t+1,e,n),meta:n}}return r(t+1,e,a)},meta:a})};return r(0,t)}function ms(e,t){if(e!==`root`){let e;for(let n=t.length-1;n>=0;n--){let r=t[n];if(r.options.notFoundComponent)return r.id;e||=r.children&&r.id}if(e)return e}return Ua}function hs(e,t){let n=e.options.params?.parse??e.options.parseParams;n&&Object.assign(t,n(t))}function gs(e,t){return e.options[t]?.preload?.()}function _s(e,t){let n=gs(e,`component`),r=gs(e,`pendingComponent`);return t&&(r?r=r.then(t):t()),n&&r?Promise.all([n,r]).then(()=>{}):n??r}function vs(e,t,n){let r=()=>t===!1?void 0:t?gs(e,t):_s(e,n),i=e._lazy;if(i)return i===!0?r():i.then(r);if(!e.lazyFn)return r();let a=e.lazyFn().then(t=>{{let{id:n,...r}=t.options;Object.assign(e.options,r),e._lazy=!0}},t=>{throw e._lazy=void 0,t});return e._lazy=a,a.then(r)}function ys(e){let t=e.findIndex(e=>e.status!==`success`||e._notFound)+1;return t&&t<e.length?e.slice(0,t):e}function bs(e,t,n){let r=e._tx;return t&&r?.[2]===n&&!r[3].some(e=>e.routeId===t)}var xs=0,Ss=1,Cs=2,ws=3,Ts=[4];function Es(e){return typeof e[0]==`number`}function Ds(e,t){return t.aborted?Promise.race([Promise.reject(t),e]):new Promise((n,r)=>{let i=()=>r(t);t.addEventListener(`abort`,i,{once:!0}),Promise.resolve(e).then(n,r).then(()=>t.removeEventListener(`abort`,i))})}function Os(e,t){return e.routesById[t.routeId]}function ks(e,t,n){return Ga(e)?[ws,e]:Ha(e)?(e.routeId||=n,[Cs,e]):t?(typeof e?.then==`function`&&(e=Error(`A Promise was thrown`,{cause:e})),[Ss,e]):[xs,e]}function As(e,t){let n=ks(t,!0,e.id);if(n[0]!==Ss)return n;try{e.options.onError?.(n[1])}catch(t){n=ks(t,!0,e.id)}return n}function js(e,t,n,r,i){return i[0].signal.aborted?Ts:qs(e,t,n,As(n,r),i)}async function Ms(e,t,n,r,i,a){let[o,s]=t,c=n[0].signal,l=!!n[3];for(let i=n[6]??0;i<r;i++){let r=s[i],u=Os(e,r);r.abortController=n[0];let d=s[i-1]?.context??e.options.context??{},f={params:r.params,location:o,navigate:t=>e.navigate({...t,_fromLocation:o}),buildLocation:e.buildLocation,cause:l?`preload`:r.cause,abortController:n[0],preload:l,matches:s,routeId:u.id};try{let e=r._ctx||=u.options.context?u.options.context({...f,deps:r.loaderDeps,context:d})||{}:void 0;r.context={...d,...e}}catch(a){return Ps(e,r),[i,js(e,t,u,a,n)]}if(c.aborted)return[i,Ts];let p=r.paramsError??r.searchError;if(p!==void 0)return Ps(e,r),[i,js(e,t,u,p,n)];let m=u.options.beforeLoad;if(!m)continue;let h=r.status;i>=a&&(r.status=`pending`,n[7]?.());try{Ls(e,r,`beforeLoad`,n[0]);let a=m({...f,search:r.search,context:r.context,...e.options.additionalContext}),o=await(typeof a?.then==`function`?Ds(a,c):a);if(c.aborted)return[i,Ts];let s=qs(e,t,u,ks(o,!1,u.id),n);if(s[0]!==xs)return Ps(e,r),[i,s];r.context={...r.context,...o}}catch(a){return Ps(e,r),[i,js(e,t,u,a,n)]}finally{r.status=h,Ls(e,r,!1,n[0])}}i()}function Ns(e,t,n){if(!(!n||--n[2])){if(e._flights?.get(t.id)===n){let n=e._tx;if(n&&!n[0].signal.aborted&&!n[3].includes(t)&&n[3].some(e=>e.id===t.id)&&n[3].some(e=>e.isFetching===`beforeLoad`))return;e._flights.delete(t.id)}return n[1]}}function Ps(e,t){let n=t._flight;t._flight=void 0,Ns(e,t,n)?.abort()}function Fs(e,t,n,r){let i=[];for(let a of t)if(!n?.includes(a)){let t=a._flight;if(a._flight=void 0,r&&t?.[2]===1&&e._flights?.get(a.id)===t&&n?.some(e=>e.id===a.id))t[2]=0;else{let n=Ns(e,a,t);n&&i.push(n)}}for(let e of i)e.abort()}function Is(e){for(let t of e){let e=t._flight;e&&e[2]++}}function Ls(e,t,n,r){if(t.isFetching=n,r&&e._tx?.[0]!==r)return;let i=e.stores.byRoute.get(t.routeId),a=i?.get();a?.id===t.id&&i.set({...a,isFetching:n})}function Rs(e,t,n,r,i,a,o){let s=t[0];return{params:n.params,location:s,navigate:t=>e.navigate({...t,_fromLocation:s}),cause:o?`preload`:n.cause,abortController:i,preload:o,deps:n.loaderDeps,parentMatchPromise:a,context:n.context,route:r,...e.options.additionalContext}}async function zs(e,t,n,r,i,a,o){let s=o[0],c=s.signal;if(c.aborted)return Ts;if(!i)return[xs,void 0];let l=n._flight;Ls(e,n,`loader`,s);try{if(!l){let s=new AbortController;l=[Promise.resolve().then(()=>i(Rs(e,t,n,r,s,a,!!o[3]))).then(e=>ks(e,!1,r.id),e=>ks(e,!0,r.id)).then(t=>(t[0]!==xs&&e._flights?.get(n.id)===l&&(e._flights.delete(n.id),l[2]||s.abort()),t[0]===Ss&&l[2]?As(r,t[1]):t)),s,1],(e._flights??=new Map).set(n.id,l)}return n._flight=l,n.abortController=l[1],qs(e,t,r,await Ds(l[0],c),o)}catch(t){if(t!==c||!c.aborted)throw t;return Ps(e,n),Ts}finally{Ls(e,n,!1,s)}}function Bs(e,t,n){t[0]!==ws&&(e.status=`success`,e.error=void 0,t[0]===xs?(e.loaderData=t[1],e.invalid=!1,e.updatedAt=Date.now(),e.preload=n):e.invalid=!0)}function Vs(e,t,n){let r=e._cache.get(t.id);if(r!==n||e._committed.some(e=>e.id===t.id&&e._flight===t._flight))return;let i={...t,_notFound:void 0,context:{}};i._flight&&i._flight[2]++,e._cache.set(t.id,i),r&&Ps(e,r)}function Hs(e,t){return t[0]===Ss||t[0]===Cs?{...e,status:t[0]===Ss?`error`:`notFound`,error:t[1],_flight:void 0}:e}function Us(e,t,n,r,i,a,o){let s=t[1][n],c=Os(e,s),l=!!a[3],u=e._cache.get(s.id),d,f=!1,p;try{if(s.status===`success`&&(d=c.options.shouldReload,typeof d==`function`&&(d=d(Rs(e,t,s,c,a[0],i,l))),a[0].signal.aborted&&(p=Ts)),!p){if(s.status!==`success`)f=!0;else{let t=l||s.preload?c.options.preloadStaleTime??e.options.defaultPreloadStaleTime??3e4:c.options.staleTime??e.options.defaultStaleTime??0;f=!!(s.invalid||d||d===void 0&&Date.now()-s.updatedAt>=t&&(a[5]||s.cause===`enter`||a[2].some(e=>e.routeId===s.routeId&&e.id!==s.id)))}}}catch(n){s.invalid=!0,Ps(e,s),p=js(e,t,c,n,a)}let m=c.options.loader,h=typeof m==`function`,g=h?m:m?.handler,_=!l||c.options.preload!==!1,v=_&&m?e._flights?.get(s.id):void 0;v===s._flight||p?v=void 0:v&&!f&&!l&&d===void 0?f=!0:f||(v=void 0);let y=!(!m||!f||s.status!==`success`||l||a[4]||((h?void 0:m.staleReloadMode)??e.options.defaultStaleReloadMode)===`blocking`),b=f&&_,x=b&&!y&&(s.status!==`success`||!!m),S=n>=o?a[7]:void 0,C=c.lazyFn&&c._lazy!==!0?S:void 0;if(b&&!m&&(s.invalid=!1,s.updatedAt=Date.now()),v&&v[2]++,x){let t=s._flight;s._flight=v,Ns(e,s,t)?.abort(),n>=o&&(s.status=`pending`),S?.()}b||(s.isFetching=!1);let w=!p&&x?zs(e,t,s,c,g,i,a).then(t=>(Bs(s,t,l),t[0]===xs&&(m&&!a[0].signal.aborted&&Vs(e,s,u),n>=o&&(s.status=`pending`)),t)):Promise.resolve(p??[xs,s.loaderData]),ee=(async()=>{try{let e=vs(c,void 0,C);e&&await Ds(e,a[0].signal)}catch(r){if(!t[1].some((e,t)=>t<=n&&(e.status===`error`||e.status===`notFound`||e._notFound)))return[n,js(e,t,c,r,a)]}let r=await w;x&&r[0]===xs&&s.status===`pending`&&!a[0].signal.aborted&&(s.status=`success`,S?.())})();if(r.push([n,w,ee]),!y)return w.then(e=>Hs(s,e));let T={...s,status:`pending`,preload:!1,_flight:v};s.invalid=!1,s.isFetching=`loader`;let te=zs(e,t,T,c,g,i,a).then(e=>(s.isFetching=!1,Bs(T,e,!1),e));return(t[2]??=[]).push([n,te,ee,T]),te.then(e=>Hs(T,e))}async function Ws(e,t,n,r,i=0){let a=n?.[1][1],o=a?.routeId?t.findIndex(e=>e.routeId===a.routeId):n?.[0]??t.length-1;o<0&&(o=0);for(let n=o;n>=0;n--){let i=Os(e,t[n]);try{let e=vs(i,!1);e&&await Ds(e,r)}catch(e){if(e===r&&r.aborted)throw e}if(i.options.notFoundComponent)return n}return a?.routeId?o:i}function Gs(e,t){t[2]&&=(Fs(e,t[2].map(e=>e[3])),void 0)}async function Ks(e,t,n,r){let i;try{await Promise.all(e.map(e=>e[1].then(async t=>{let a=e[0];if(!(r&&a>=await r)){if(t[0]>=ws)throw[a,t];!i&&t[0]!==xs&&(i=[a,t],await Promise.all((n??[]).map(e=>{if(!(e[0]<=a))return e[1].then(t=>{if(t[0]===ws)throw[e[0],t]})})))}})))}catch(e){return e}return t??i}function qs(e,t,n,r,i,a){for(;r[0]===ws;){let o=r[1],s=o.options;try{if((s.href||o.headers.has(`Location`))&&(e.resolveRedirect(o),s.reloadDocument)||(s.reloadDocument?i[3]:i[1]>=20))return r;let n=e.buildLocation({...s,_fromLocation:t[0],_includeValidateSearch:!0}),a=n.maskedLocation??n;if(a.external){let t=o.clone();return t.options={...s},t.headers.set(`Location`,a.publicHref),e.resolveRedirect(t),i[3]?[ws,t]:[ws,t,a]}return[ws,o,n]}catch(e){r=a?[Ss,e]:As(n,e),a=!0}}return r}async function Js(e,t,n,r,i,a){let o=t[1],s=await i,c=!1,l=o.findIndex(e=>e._notFound),u=t=>t[1][0]===Cs?Ws(e,o,t,r.signal):t[0],d=l<0?o.length:l;if((s?.[1][0]??0)>=ws)d=0;else if(s){d=s[2]??=await u(s);for(let e of n){if(e[0]>=d)break;let t=await e[1];if(t[0]!==xs&&t[0]<ws&&!(`loaderData`in o[e[0]])){s=[e[0],t],d=s[2]=await u(s);break}}}for(let e of n){if(e[0]>=d)break;let t=await e[2];if(t){s=t;break}}if((s?.[1][0]??0)>=ws){let n=s[1];if(n[0]!==ws||n[1].options.reloadDocument||n[2])return Gs(e,t),n;c=!0,s=[0,[Ss,Error(`Too many redirects`)]]}let f=s?s[2]??await u(s):l;if(f>=0){let i=s?.[1],l=i?.[0],u=o[f],d=i?.[1],p=()=>{i&&(u._notFound=void 0,l===Ss?u.status=`error`:(d.routeId=u.routeId,u.routeId===e.routeTree.id?(u.status=`success`,u._notFound=!0):u.status=`notFound`),u.error=d,u.isFetching=!1)};p(),i||a?.();let m=Os(e,u);try{await Ds(i?Promise.resolve().then(()=>vs(m,l===Ss?`errorComponent`:`notFoundComponent`)):Promise.all([vs(m),vs(m,`notFoundComponent`)]),r.signal)}catch(n){if(n===r.signal&&r.signal.aborted)return Gs(e,t),Ts}i?c&&(r.abort(),await Promise.all([...n.map(e=>e[1]),...n.map(e=>e[2]),...(t[2]??[]).map(e=>e[1])]),Gs(e,t),Fs(e,o),p()):u.status=`success`}return t}async function Ys(e,t,n,r=0,i=t[1].length){let a=t[1];for(let t=r;t<i;t++){let r=a[t],i=Os(e,r).options;if(i.head||i.scripts)try{let t={ssr:e.options.ssr,matches:a,match:r,params:r.params,loaderData:r.loaderData},[o,s]=await Ds(Promise.all([i.head?.(t),i.scripts?.(t)]),n);r.meta=o?.meta,r.links=o?.links,r.headScripts=o?.scripts,r.styles=o?.styles,r.scripts=s}catch(e){if(e===n&&n.aborted)break;console.error(e)}if(r.status!==`success`||r._notFound)break}return t}async function Xs(e,t,n,r){let i=[t,n],a=r[0].signal,o;try{let t=e.stores.matches.get(),s=n.findIndex(e=>e._notFound);if(e.options.notFoundMode!==`root`&&s>=0){let t=await Ws(e,n,void 0,a,s);n[s]._notFound=void 0,n[t]._notFound=!0,s=t}let c=s<0?n.length:s+1,l=0;for(;l<c&&l!==s;){let e=n[l],i=r[2][l],a=t[l];if(i?.id!==e.id||i.status!==`success`||e.preload||a?.id!==e.id||a.status!==`success`||(l++,i._notFound||a._notFound))break}let u=[],d=r[6]??0,f=d?Promise.resolve(n[d-1]):void 0,p=()=>{for(let t=d;t<c&&!a.aborted;t++)f=Us(e,i,t,u,f,r,l)},m=await Ms(e,i,r,c,p,l);if(m){if(r[4]=!0,c=m[0],m[1][0]===Cs){let t=await Ws(e,n,m,a);m[2]=t,c=Math.min(c,t+1)}else m[1][0]>=ws&&(c=0);p()}if(!a.aborted&&!r[3]){let t=[];for(let[n,r]of e._flights??[])r[2]||(e._flights.delete(n),t.push(r[1]));for(let e of t)e.abort()}let h=Js(e,i,u,r[0],Ks(u,m,i[2]),r[7]);i[2]?.length&&(i[3]=Ks(i[2],void 0,void 0,h.then(e=>Es(e)?0:ys(n).length,()=>0))),o=await h}catch(t){if(Gs(e,i),t===a&&a.aborted)return Ts;throw t}return Es(o)?o:Ys(e,o,a,r[6]===n.length?r[6]:0)}function Zs(e,t){if(e._tx!==t)return;let n=t[3],r=e.stores.matches.get(),i=e._pending;for(let a=0;a<n.length;a++){let o=n[a],s=o.status===`success`&&!o._notFound,c=r[a]?.id===o.id&&r[a]?.status===`pending`;if(s&&!c)continue;let l=Os(e,o),u=s||o.invalid?0:l.options.pendingMs??e.options.defaultPendingMs,d=l.options.pendingComponent??e.options.defaultPendingComponent;if(!d||typeof u!=`number`||u===1/0){i&&(i[0]=t,i[2]=0,i[4]=!0);return}let f=l.options.pendingMinMs??e.options.defaultPendingMinMs??0,p=!1;if(i?.[1]===o.id?(p=i[0]!==t,i[0]=t):(clearTimeout(i?.[3]),e._pending=i=void 0),i||(e._pending=i=[t,o.id,c?Date.now()+f:t[4]+u,void 0,c||void 0,d]),i[4]&&!p&&i[5]===d)return;if(i[5]=d,!i[4]){clearTimeout(i[3]);let n=i[2]-Date.now();if(n>0){i[3]=setTimeout(()=>Zs(e,t),n);return}i[2]=0}let m=n.map(e=>({...e,_flight:void 0}));m[a].status=`pending`;let h=i[4]=e.startTransition(()=>e.stores.setMatches(m),m).then(t=>(t&&e._pending===i&&i[4]===h&&!i[2]&&(i[2]=Date.now()+f),t));return}}function Qs(e,t){let n=e._pending;e._tx!==t&&e._tx?.[3].some(e=>e.id===n?.[1])||(clearTimeout(n?.[3]),e._pending=void 0)}async function $s(e,t){let n=e._pending;if(!n)return;clearTimeout(n[3]);let r=n[2]-Date.now();if(!n[4]||r<=0||!ys(t[3]).some(e=>e.id===n[1]))return;let i;try{await Ds(new Promise(e=>{i=setTimeout(e,r)}),t[0].signal)}catch{}clearTimeout(i)}function ec(e,t){e._committed=t,e.stores.setMatches(t)}function tc(e,t,n,r){let i=e._committed,a=e._lifecycleEnd,o=e._cache;for(let e of n)e.preload=!1,r&&(e._assetEnd=void 0);let s=ys(n).length,c=new Map;{let t=Date.now(),r=new Set;for(let e=0;e<n.length;e++){let t=n[e];(e<s||t.status===`success`)&&r.add(t.id)}for(let n of[...i,...o.values()]){if(n.status!==`success`||r.has(n.id))continue;let i=Os(e,n);!i.options.loader||t-n.updatedAt>=(n.preload?i.options.preloadGcTime??e.options.defaultPreloadGcTime??3e5:i.options.gcTime??e.options.defaultGcTime??3e5)||c.set(n.id,o.get(n.id)===n?n:{...n,_flight:void 0,isFetching:!1,context:{}})}}t[3]=[],e._cache=c;let l=e._lifecycleEnd=ns(n);ec(e,n),Fs(e,[...o.values(),...i].filter(e=>e._flight&&c.get(e.id)!==e),n),rs(e,i,n,a,l,t)}async function nc(e,t){let n=e._tx;for(;n&&n!==t;)t=n,await n[5],n=e._tx}function rc(e,t,n){let r=n[1].options,i=n[2];if(!i)return e.navigate({...r,replace:!0,ignoreBlocker:!0});if(r.reloadDocument)return e.navigate({href:(i.maskedLocation??i).publicHref,reloadDocument:!0,replace:!0,ignoreBlocker:!0});i._redirects=t[1]+1,e._pendingLocation=i;let a=e.commitLocation({...i,viewTransition:r.viewTransition,replace:!0,resetScroll:r.resetScroll,hashScrollIntoView:r.hashScrollIntoView,ignoreBlocker:!0});return queueMicrotask(()=>{e._pendingLocation===i&&(e._pendingLocation=void 0)}),a}async function ic(e,t,n,r,i){let a=n.map(e=>({...e}));Is(a);for(let t of r)Ps(e,a[t[0]]),a[t[0]]=t[3];let o=[t[2],a],s;try{s=await Js(e,o,r,t[0],i)}catch(t){throw Fs(e,a),t}if(Es(s))Fs(e,a),s[0]===ws&&e._tx===t&&e._committed===n&&await rc(e,t,s);else if(await Ys(e,s,t[0].signal),e._tx!==t||e._committed!==n)Fs(e,a);else{for(let t of a){let n=e._cache.get(t.id);n?._flight&&n._flight===t._flight&&(e._cache.delete(t.id),Ps(e,n))}ec(e,a),Fs(e,n,a)}}async function ac(e,t,n,r,i,a){let o=await Xs(e,t[2],t[3],[t[0],t[1],e._committed,void 0,i,n,a,r]);if(Es(o)){let n=o[0]===ws&&e._tx===t;if((!n||o[1].options.reloadDocument)&&Qs(e,t),Fs(e,t[3]),t[3]=[],!n)return;if(e._tx!==t){Qs(e,t);return}await rc(e,t,o);return}let s=o[1];if(e._tx===t&&await $s(e,t),e._tx!==t){Qs(e,t),Fs(e,s),Gs(e,o);return}let c=t[2],l=es(c,e.stores.resolvedLocation.get()),u=o[2];await e.startViewTransition(async()=>{if(e._tx===t&&await $s(e,t),e._tx!==t){Qs(e,t),Fs(e,s),Gs(e,o);return}let n=await e.startTransition(()=>{Qs(e,t),tc(e,t,s,a),e._tx===t&&(e.emit({type:`onLoad`,...l}),e._tx===t&&e.emit({type:`onBeforeRouteMount`,...l}))},s);e._tx===t?(u?.length&&ic(e,t,s,u,o[3]).catch(console.error),e.batch(()=>{e.stores.resolvedLocation.set(c),e.stores.status.set(`idle`),e._tx===t&&e.emit({type:`onResolved`,...l}),n&&e._tx===t&&e.emit({type:`onRendered`,...l})}),e._tx===t&&(e._commitPromise?.resolve(),e._commitPromise=void 0)):Gs(e,o)})}async function oc(e,t){let n=e._tx,r=e.stores.resolvedLocation.get(),i=r??e.stores.location.get(),a=e.latestLocation,o=e._pendingLocation,s=o?.href===a.href?o._redirects??0:0,c=e._handoff,l=c?.[0](),u=new AbortController,d=e._preflight;if(e._preflight=u,l||c?.[1](),d?.abort(),!u.signal.aborted){let t=es(a,r);e.emit({type:`onBeforeNavigate`,...t}),u.signal.aborted||e.emit({type:`onBeforeLoad`,...t})}if(u.signal.aborted){await nc(e,n);return}let f=i.href===a.href,p=u,m=e.matchRoutes(a,{_controller:u});Is(m);let h=l?c[1](m):void 0;if(h?p=l:l?.abort(),u.signal.aborted){Fs(e,m),await nc(e,n);return}e._preflight=void 0;let g,_=()=>ac(e,y,f,()=>Zs(e,y),t?.sync,h),v=t?.sync?new Promise(e=>g=e):Promise.resolve().then(_),y=[p,s,a,m,Date.now(),v.then(()=>nc(e,y))];if(e._tx=y,n){for(let t of e.stores.matches.get()){if(e._tx!==y)break;t.isFetching&&Ls(e,t,!1)}n[0].abort(),Fs(e,n[3],y[3],!0)}e._tx===y?(e.batch(()=>{e.stores.status.set(`pending`),e.stores.location.set(a)}),(h||!e._committed.length&&m[0]?.status!==`success`&&!m.some(e=>e._notFound))&&Zs(e,y),g?.(_()),await y[5]):(Fs(e,y[3]),y[3]=[],g?.(),await nc(e,y))}async function sc(e,t){let n=e.buildLocation(t);for(let t=0;;t++){let r=e._committed,i=new AbortController,a,o,s;try{try{a=e.matchRoutes(n,{_controller:i}),Is(a),o=(e._preloads??=new Map).set(i,a),s=await Xs(e,n,a,[i,t,r,!0])}finally{o&&(o=o.delete(i),Fs(e,a)),i.abort()}if(!Es(s))return s[1];if(!o||s.length<3)return;n=s[2]}catch(e){Ha(e)||console.error(e);return}}}function cc(e,t){let n=e.stores.location,r=new Set,i,a,o=n=>{bs(e,t,n)||(i=n,r.forEach(e=>e()))};return[()=>i??n.get(),e=>(r.size||(i=n.get(),a=n.subscribe(o).unsubscribe),r.add(e),()=>{r.delete(e),r.size||(a(),i=void 0)})]}var lc=G.createContext(void 0),uc=G.createContext(void 0),dc=Qi();function fc(e,t){return e===t}function pc(e,t=e=>e,n){let r=n?.compare??fc,i=(0,G.useCallback)(t=>{let{unsubscribe:n}=e.subscribe(t);return n},[e]),a=(0,G.useCallback)(()=>e.get(),[e]);return(0,dc.useSyncExternalStoreWithSelector)(i,a,a,t,r)}function mc({update:e,notify:t,unwatched:n}){return{link:r,unlink:i,propagate:a,checkDirty:o,shallowPropagate:s};function r(e,t,n){let r=t.depsTail;if(r!==void 0&&r.dep===e)return;let i=r===void 0?t.deps:r.nextDep;if(i!==void 0&&i.dep===e){i.version=n,t.depsTail=i;return}let a=e.subsTail;if(a!==void 0&&a.version===n&&a.sub===t)return;let o=t.depsTail=e.subsTail={version:n,dep:e,sub:t,prevDep:r,nextDep:i,prevSub:a,nextSub:void 0};i!==void 0&&(i.prevDep=o),r===void 0?t.deps=o:r.nextDep=o,a===void 0?e.subs=o:a.nextSub=o}function i(e,t=e.sub){let r=e.dep,i=e.prevDep,a=e.nextDep,o=e.nextSub,s=e.prevSub;return a===void 0?t.depsTail=i:a.prevDep=i,i===void 0?t.deps=a:i.nextDep=a,o===void 0?r.subsTail=s:o.prevSub=s,s===void 0?(r.subs=o)===void 0&&n(r):s.nextSub=o,a}function a(e){let n=e.nextSub,r;top:do{let i=e.sub,a=i.flags;if(a&60?a&12?a&4?!(a&48)&&c(e,i)?(i.flags=a|40,a&=1):a=0:i.flags=a&-9|32:a=0:i.flags=a|32,a&2&&t(i),a&1){let t=i.subs;if(t!==void 0){let i=(e=t).nextSub;i!==void 0&&(r={value:n,prev:r},n=i);continue}}if((e=n)!==void 0)n=e.nextSub;else{for(;r!==void 0;)if(e=r.value,r=r.prev,e!==void 0){n=e.nextSub;continue top}break}}while(1)}function o(t,n){let r,i=0,a=!1;top:do{let o=t.dep,c=o.flags;if(n.flags&16)a=!0;else if((c&17)==17){if(e(o)){let e=o.subs;e.nextSub!==void 0&&s(e),a=!0}}else if((c&33)==33){(t.nextSub!==void 0||t.prevSub!==void 0)&&(r={value:t,prev:r}),t=o.deps,n=o,++i;continue}if(!a){let e=t.nextDep;if(e!==void 0){t=e;continue}}for(;i--;){let i=n.subs,o=i.nextSub!==void 0;if(o?(t=r.value,r=r.prev):t=i,a){if(e(n)){o&&s(i),n=t.sub;continue}a=!1}else n.flags&=-33;n=t.sub;let c=t.nextDep;if(c!==void 0){t=c;continue top}}return a}while(1)}function s(e){do{let n=e.sub,r=n.flags;(r&48)==32&&(n.flags=r|16,(r&6)==2&&t(n))}while((e=e.nextSub)!==void 0)}function c(e,t){let n=t.depsTail;for(;n!==void 0;){if(n===e)return!0;n=n.prevDep}return!1}}function hc(e,t,n){let r=typeof e==`object`,i=r?e:void 0;return{next:(r?e.next:e)?.bind(i),error:(r?e.error:t)?.bind(i),complete:(r?e.complete:n)?.bind(i)}}var gc=[],_c=0,{link:vc,unlink:yc,propagate:bc,checkDirty:xc,shallowPropagate:Sc}=mc({update(e){return e._update()},notify(e){gc[wc++]=e,e.flags&=-3},unwatched(e){e.depsTail!==void 0&&(e.depsTail=void 0,e.flags=17,Oc(e))}}),Cc=0,wc=0,Tc,Ec=0;function Dc(e){try{++Ec,e()}finally{--Ec||kc()}}function Oc(e){let t=e.depsTail,n=t===void 0?e.deps:t.nextDep;for(;n!==void 0;)n=yc(n,e)}function kc(){if(!(Ec>0)){for(;Cc<wc;){let e=gc[Cc];gc[Cc++]=void 0,e.notify()}Cc=0,wc=0}}function Ac(e,t){let n=typeof e==`function`,r=e,i={_snapshot:n?void 0:e,subs:void 0,subsTail:void 0,deps:void 0,depsTail:void 0,flags:+!n,get(){return Tc!==void 0&&vc(i,Tc,_c),i._snapshot},subscribe(e){let t=hc(e),n={current:!1},r=jc(()=>{i.get(),n.current?(Tc=void 0,t.next?.(i._snapshot)):n.current=!0});return{unsubscribe:()=>{r.stop()}}},_update(e){let a=Tc,o=t?.compare??Object.is;if(n)Tc=i,++_c,i.depsTail=void 0;else if(e===void 0)return!1;n&&(i.flags=5);try{let t=i._snapshot,a=typeof e==`function`?e(t):e===void 0&&n?r(t):e;return t===void 0||!o(t,a)?(i._snapshot=a,!0):!1}finally{Tc=a,n&&(i.flags&=-5),Oc(i)}}};return n?(i.flags=17,i.get=function(){let e=i.flags;if(e&16||e&32&&xc(i.deps,i)){if(i._update()){let e=i.subs;e!==void 0&&Sc(e)}}else e&32&&(i.flags=e&-33);return Tc!==void 0&&vc(i,Tc,_c),i._snapshot}):i.set=function(e){if(i._update(e)){let e=i.subs;e!==void 0&&(bc(e),Sc(e),kc())}},i}function jc(e){let t=()=>{let t=Tc;Tc=n,++_c,n.depsTail=void 0,n.flags=6;try{return e()}finally{Tc=t,n.flags&=-5,Oc(n)}},n={deps:void 0,depsTail:void 0,subs:void 0,subsTail:void 0,flags:6,notify(){let e=this.flags;e&16||e&32&&xc(this.deps,this)?t():this.flags=2},stop(){this.flags=0,this.depsTail=void 0,Oc(this)}};return t(),n}var K=n(),Mc=class extends G.Component{constructor(...e){super(...e),this.state={error:0},this.reset=()=>{this.setState({error:0})}}static getDerivedStateFromProps(e,t){let n=e.getResetKey();return t.error&&t.resetKey!==n?{resetKey:n,error:0}:{resetKey:n}}static getDerivedStateFromError(e){return{error:[e]}}componentDidCatch(e,t){this.props.onCatch?.(e,t)}render(){let e=this.state.error;return e?G.createElement(this.props.errorComponent??Nc,{error:e[0],reset:this.reset}):this.props.children}};function Nc({error:e}){let[t,n]=G.useState(!1);return(0,K.jsxs)(`div`,{style:{padding:`.5rem`,maxWidth:`100%`},children:[(0,K.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:`.5rem`},children:[(0,K.jsx)(`strong`,{style:{fontSize:`1rem`},children:`Something went wrong!`}),(0,K.jsx)(`button`,{style:{appearance:`none`,fontSize:`.6em`,border:`1px solid currentColor`,padding:`.1rem .2rem`,fontWeight:`bold`,borderRadius:`.25rem`},onClick:()=>n(e=>!e),children:t?`Hide Error`:`Show Error`})]}),(0,K.jsx)(`div`,{style:{height:`.25rem`}}),t?(0,K.jsx)(`div`,{children:(0,K.jsx)(`pre`,{style:{fontSize:`.7em`,border:`1px solid red`,borderRadius:`.25rem`,padding:`.3rem`,color:`red`,overflow:`auto`},children:e?.message?(0,K.jsx)(`code`,{children:e.message}):null})}):null]})}var Pc=()=>!0,Fc=()=>!1;function Ic({children:e,fallback:t=null}){return(0,K.jsx)(G.Fragment,{children:Lc()?e:t})}function Lc(e=!0){return G.useSyncExternalStore(Rc,Pc,e?Fc:Pc)}function Rc(){return()=>{}}function zc(e){let t=sa(),n=`not-found-${pc(t.stores.location,e=>e.pathname)}-${pc(t.stores.status)}`;return(0,K.jsx)(Mc,{getResetKey:()=>n,onCatch:(t,n)=>{if(Ha(t))e.onCatch?.(t,n);else throw t},errorComponent:({error:t})=>{if(Ha(t))return e.fallback?.(t);throw t},children:e.children})}function Bc(){return(0,K.jsx)(`p`,{children:`Not Found`})}function Vc(e,t,n){return t.options.notFoundComponent?(0,K.jsx)(t.options.notFoundComponent,{...n}):e.options.defaultNotFoundComponent?(0,K.jsx)(e.options.defaultNotFoundComponent,{...n}):(0,K.jsx)(Bc,{})}function Hc(e,t){let n=t?.options.pendingComponent??e.options.defaultPendingComponent;return n?(0,K.jsx)(n,{}):null}var Uc=(e,t)=>e[0]===t[0]&&e[1]===t[1],Wc=(e,t,n)=>!t.isRoot||t.options.shellComponent||t.options.wrapInSuspense||n===!1||n===`data-only`||!e.ssr,Gc=G.memo(function({routeId:e}){let t=sa();return Kc(t,pc(t.stores.getMatchStore(e)))});function Kc(e,t){let n=e.routesById[t.routeId],r=Hc(e,n),i=n.options.errorComponent??e.options.defaultErrorComponent,a=n.options.onCatch??e.options.defaultOnCatch,o=n.isRoot?n.options.notFoundComponent??e.options.notFoundRoute?.options.component:n.options.notFoundComponent,s=t.ssr===!1||t.ssr===`data-only`,c=Wc(e,n,t.ssr)&&(n.options.wrapInSuspense??r??(n.options.errorComponent?.preload||s)),l=(0,K.jsx)(qc,{match:t});s&&(l=(0,K.jsx)(Ic,{fallback:r,children:l})),o&&(l=(0,K.jsx)(zc,{fallback:e=>{if(e.routeId??=t.routeId,e.routeId!==t.routeId)throw e;return G.createElement(o,e)},children:l})),i&&(l=(0,K.jsx)(Mc,{getResetKey:()=>t,errorComponent:i,onCatch:(e,n)=>{if(Ha(e))throw e.routeId??=t.routeId,e;a?.(e,n)},children:l})),c&&(l=(0,K.jsx)(G.Suspense,{fallback:r,children:l}));let u=n.isRoot&&n.options.shellComponent;return u?(0,K.jsx)(lc.Provider,{value:t.routeId,children:(0,K.jsxs)(u,{children:[l,null]})}):(0,K.jsxs)(lc.Provider,{value:t.routeId,children:[l,null]})}var qc=G.memo(function({match:e}){let t=sa(),n=e.routeId,r=t.routesById[n],i=G.useMemo(()=>{let i=(r.options.remountDeps??t.options.defaultRemountDeps)?.({routeId:n,loaderDeps:e.loaderDeps,params:e._strictParams,search:e._strictSearch});return i?JSON.stringify(i):void 0},[n,e.loaderDeps,e._strictParams,e._strictSearch,r.options.remountDeps,t.options.defaultRemountDeps]),a=G.useMemo(()=>{let e=r.options.component??t.options.defaultComponent;return e?(0,K.jsx)(e,{},i):(0,K.jsx)(Jc,{})},[i,r.options.component,t.options.defaultComponent]);if(e.status===`pending`){if(t.ssr&&!Wc(t,r,e.ssr))return a;if(t._tx)throw t._tx[5];return Hc(t,r)}if(e.status===`notFound`)return Vc(t,r,e.error);if(e.status===`error`)throw e.error;return a}),Jc=G.memo(function(){let e=sa(),t=G.useContext(lc),n,r,i;{let a=e.stores.getMatchStore(t);[n,r]=pc(a,e=>[!!e._notFound,e.error],{compare:Uc}),i=pc(e.stores.ids,e=>e[e.indexOf(t)+1])}if(n)return Vc(e,e.routesById[t],r);if(!i)return null;let a=(0,K.jsx)(Gc,{routeId:i});return t===`__root__`?(0,K.jsx)(G.Suspense,{fallback:Hc(e),children:a}):a});function Yc(e,t){let n=e[1];e.length=0,n?.(t)}function Xc({t:e}){let t=sa(),n=t._rendered??=[];return t.startTransition=(r,i)=>new Promise(a=>{Yc(n,!1),n.push(i,a),e(t),G.startTransition(r)}),aa(()=>{let e=t.history.subscribe(t.load);t.updateLatestLocation();let r=t.latestLocation,i=t.buildLocation({to:r.pathname,search:!0,params:!0,hash:!0,state:!0,_includeValidateSearch:!0});if(Na(r.publicHref)!==Na(i.publicHref))return t.commitLocation({...i,replace:!0,ignoreBlocker:!0}),e;let a=t.stores.resolvedLocation.get();return a?.href===r.href&&a.state.__TSR_key===r.state.__TSR_key?n.push(t.stores.matches.get(),e=>{e&&t.emit({type:`onRendered`,...es(a,a)})}):t._tx||t.load({sync:!0}).catch(console.error),e},[t,t.history]),null}function Zc(){let e=sa(),t=e.routesById[Ua],n=Hc(e,t),r=(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Xc,{t:G.useState()[1]}),e.ssr?(0,K.jsx)(Qc,{}):(0,K.jsx)(G.Suspense,{fallback:n,children:(0,K.jsx)(Qc,{})})]});return e.options.InnerWrap?(0,K.jsx)(e.options.InnerWrap,{children:r}):r}function Qc(){let e=sa(),t=e._rendered,n=pc(e.stores.matches,e=>t[0]??e),r=n[0],i=r?.routeId;aa(()=>{t[0]===n&&Yc(t,!0)},[t,n]);let a=i?(0,K.jsx)(Gc,{routeId:i}):null;return e.options.disableGlobalCatchBoundary?a:(0,K.jsx)(Mc,{getResetKey:()=>r,onCatch:void 0,children:a})}function $c(){let e=sa();return G.useCallback(t=>{let{pending:n,caseSensitive:r,fuzzy:i,includeSearch:a,...o}=t;return e.matchRoute(o,{pending:n,caseSensitive:r,fuzzy:i,includeSearch:a})},[e,pc(e.stores.location,e=>e.href),pc(e.stores.resolvedLocation,e=>e?.href),pc(e.stores.status)])}var el=e=>({createMutableStore:Ac,createReadonlyStore:Ac,batch:Dc}),tl=e=>new nl(e),nl=class extends is{constructor(e){super(e,el)}};function rl({router:e,children:t,...n}){pa(n)&&e.update({...e.options,...n,context:{...e.options.context,...n.context}});let r=(0,K.jsx)(oa.Provider,{value:e,children:t});return e.options.Wrap?(0,K.jsx)(e.options.Wrap,{children:r}):r}function il({router:e,...t}){return(0,K.jsx)(rl,{router:e,...t,children:(0,K.jsx)(Zc,{})})}var al=new Map([[`bold`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M244,56v48a12,12,0,0,1-12,12H184a12,12,0,1,1,0-24H201.1l-19-17.38c-.13-.12-.26-.24-.38-.37A76,76,0,1,0,127,204h1a75.53,75.53,0,0,0,52.15-20.72,12,12,0,0,1,16.49,17.45A99.45,99.45,0,0,1,128,228h-1.37A100,100,0,1,1,198.51,57.06L220,76.72V56a12,12,0,0,1,24,0Z`}))],[`duotone`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M216,128a88,88,0,1,1-88-88A88,88,0,0,1,216,128Z`,opacity:`0.2`}),G.createElement(`path`,{d:`M240,56v48a8,8,0,0,1-8,8H184a8,8,0,0,1,0-16H211.4L184.81,71.64l-.25-.24a80,80,0,1,0-1.67,114.78,8,8,0,0,1,11,11.63A95.44,95.44,0,0,1,128,224h-1.32A96,96,0,1,1,195.75,60L224,85.8V56a8,8,0,1,1,16,0Z`}))],[`fill`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M240,56v48a8,8,0,0,1-8,8H184a8,8,0,0,1-5.66-13.66l17-17-10.55-9.65-.25-.24a80,80,0,1,0-1.67,114.78,8,8,0,1,1,11,11.63A95.44,95.44,0,0,1,128,224h-1.32A96,96,0,1,1,195.75,60l10.93,10L226.34,50.3A8,8,0,0,1,240,56Z`}))],[`light`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M238,56v48a6,6,0,0,1-6,6H184a6,6,0,0,1,0-12h32.55l-30.38-27.8c-.06-.06-.12-.13-.19-.19a82,82,0,1,0-1.7,117.65,6,6,0,0,1,8.24,8.73A93.46,93.46,0,0,1,128,222h-1.28A94,94,0,1,1,194.37,61.4L226,90.35V56a6,6,0,1,1,12,0Z`}))],[`regular`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M240,56v48a8,8,0,0,1-8,8H184a8,8,0,0,1,0-16H211.4L184.81,71.64l-.25-.24a80,80,0,1,0-1.67,114.78,8,8,0,0,1,11,11.63A95.44,95.44,0,0,1,128,224h-1.32A96,96,0,1,1,195.75,60L224,85.8V56a8,8,0,1,1,16,0Z`}))],[`thin`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M236,56v48a4,4,0,0,1-4,4H184a4,4,0,0,1,0-8h37.7L187.53,68.69l-.13-.12a84,84,0,1,0-1.75,120.51,4,4,0,0,1,5.5,5.82A91.43,91.43,0,0,1,128,220h-1.26A92,92,0,1,1,193,62.84l35,32.05V56a4,4,0,1,1,8,0Z`}))]]),ol=G.forwardRef((e,t)=>G.createElement(ra,{ref:t,...e,weights:al}));ol.displayName=`ArrowClockwiseIcon`;var sl=new Map([[`bold`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M222.14,105.85l-80-80a20,20,0,0,0-28.28,0l-80,80A19.86,19.86,0,0,0,28,120v96a12,12,0,0,0,12,12h64a12,12,0,0,0,12-12V164h24v52a12,12,0,0,0,12,12h64a12,12,0,0,0,12-12V120A19.86,19.86,0,0,0,222.14,105.85ZM204,204H164V152a12,12,0,0,0-12-12H104a12,12,0,0,0-12,12v52H52V121.65l76-76,76,76Z`}))],[`duotone`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M216,120v96H152V152H104v64H40V120a8,8,0,0,1,2.34-5.66l80-80a8,8,0,0,1,11.32,0l80,80A8,8,0,0,1,216,120Z`,opacity:`0.2`}),G.createElement(`path`,{d:`M219.31,108.68l-80-80a16,16,0,0,0-22.62,0l-80,80A15.87,15.87,0,0,0,32,120v96a8,8,0,0,0,8,8h64a8,8,0,0,0,8-8V160h32v56a8,8,0,0,0,8,8h64a8,8,0,0,0,8-8V120A15.87,15.87,0,0,0,219.31,108.68ZM208,208H160V152a8,8,0,0,0-8-8H104a8,8,0,0,0-8,8v56H48V120l80-80,80,80Z`}))],[`fill`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M224,120v96a8,8,0,0,1-8,8H160a8,8,0,0,1-8-8V164a4,4,0,0,0-4-4H108a4,4,0,0,0-4,4v52a8,8,0,0,1-8,8H40a8,8,0,0,1-8-8V120a16,16,0,0,1,4.69-11.31l80-80a16,16,0,0,1,22.62,0l80,80A16,16,0,0,1,224,120Z`}))],[`light`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M217.9,110.1l-80-80a14,14,0,0,0-19.8,0l-80,80A13.92,13.92,0,0,0,34,120v96a6,6,0,0,0,6,6h64a6,6,0,0,0,6-6V158h36v58a6,6,0,0,0,6,6h64a6,6,0,0,0,6-6V120A13.92,13.92,0,0,0,217.9,110.1ZM210,210H158V152a6,6,0,0,0-6-6H104a6,6,0,0,0-6,6v58H46V120a2,2,0,0,1,.58-1.42l80-80a2,2,0,0,1,2.84,0l80,80A2,2,0,0,1,210,120Z`}))],[`regular`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M219.31,108.68l-80-80a16,16,0,0,0-22.62,0l-80,80A15.87,15.87,0,0,0,32,120v96a8,8,0,0,0,8,8h64a8,8,0,0,0,8-8V160h32v56a8,8,0,0,0,8,8h64a8,8,0,0,0,8-8V120A15.87,15.87,0,0,0,219.31,108.68ZM208,208H160V152a8,8,0,0,0-8-8H104a8,8,0,0,0-8,8v56H48V120l80-80,80,80Z`}))],[`thin`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M216.49,111.51l-80-80a12,12,0,0,0-17,0l-80,80A12,12,0,0,0,36,120v96a4,4,0,0,0,4,4h64a4,4,0,0,0,4-4V156h40v60a4,4,0,0,0,4,4h64a4,4,0,0,0,4-4V120A12,12,0,0,0,216.49,111.51ZM212,212H156V152a4,4,0,0,0-4-4H104a4,4,0,0,0-4,4v60H44V120a4,4,0,0,1,1.17-2.83l80-80a4,4,0,0,1,5.66,0l80,80A4,4,0,0,1,212,120Z`}))]]),cl=G.forwardRef((e,t)=>G.createElement(ra,{ref:t,...e,weights:sl}));cl.displayName=`HouseIcon`;var ll=new Map([[`bold`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M208,76H180V56A52,52,0,0,0,76,56V76H48A20,20,0,0,0,28,96V208a20,20,0,0,0,20,20H208a20,20,0,0,0,20-20V96A20,20,0,0,0,208,76ZM100,56a28,28,0,0,1,56,0V76H100ZM204,204H52V100H204Zm-60-52a16,16,0,1,1-16-16A16,16,0,0,1,144,152Z`}))],[`duotone`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M216,96V208a8,8,0,0,1-8,8H48a8,8,0,0,1-8-8V96a8,8,0,0,1,8-8H208A8,8,0,0,1,216,96Z`,opacity:`0.2`}),G.createElement(`path`,{d:`M208,80H176V56a48,48,0,0,0-96,0V80H48A16,16,0,0,0,32,96V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V96A16,16,0,0,0,208,80ZM96,56a32,32,0,0,1,64,0V80H96ZM208,208H48V96H208V208Zm-68-56a12,12,0,1,1-12-12A12,12,0,0,1,140,152Z`}))],[`fill`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M208,80H176V56a48,48,0,0,0-96,0V80H48A16,16,0,0,0,32,96V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V96A16,16,0,0,0,208,80Zm-80,84a12,12,0,1,1,12-12A12,12,0,0,1,128,164Zm32-84H96V56a32,32,0,0,1,64,0Z`}))],[`light`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M208,82H174V56a46,46,0,0,0-92,0V82H48A14,14,0,0,0,34,96V208a14,14,0,0,0,14,14H208a14,14,0,0,0,14-14V96A14,14,0,0,0,208,82ZM94,56a34,34,0,0,1,68,0V82H94ZM210,208a2,2,0,0,1-2,2H48a2,2,0,0,1-2-2V96a2,2,0,0,1,2-2H208a2,2,0,0,1,2,2Zm-72-56a10,10,0,1,1-10-10A10,10,0,0,1,138,152Z`}))],[`regular`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M208,80H176V56a48,48,0,0,0-96,0V80H48A16,16,0,0,0,32,96V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V96A16,16,0,0,0,208,80ZM96,56a32,32,0,0,1,64,0V80H96ZM208,208H48V96H208V208Zm-68-56a12,12,0,1,1-12-12A12,12,0,0,1,140,152Z`}))],[`thin`,G.createElement(G.Fragment,null,G.createElement(`path`,{d:`M208,84H172V56a44,44,0,0,0-88,0V84H48A12,12,0,0,0,36,96V208a12,12,0,0,0,12,12H208a12,12,0,0,0,12-12V96A12,12,0,0,0,208,84ZM92,56a36,36,0,0,1,72,0V84H92ZM212,208a4,4,0,0,1-4,4H48a4,4,0,0,1-4-4V96a4,4,0,0,1,4-4H208a4,4,0,0,1,4,4Zm-76-56a8,8,0,1,1-8-8A8,8,0,0,1,136,152Z`}))]]),ul=G.forwardRef((e,t)=>G.createElement(ra,{ref:t,...e,weights:ll}));ul.displayName=`LockIcon`;var dl=G.forwardRef(function(e,t){let{render:n,className:r,disabled:i=!1,focusableWhenDisabled:a=!1,nativeButton:o=!0,style:s,...c}=e,{getButtonProps:l,buttonRef:u}=na({disabled:i,focusableWhenDisabled:a,native:o});return $i(`button`,e,{state:{disabled:i},ref:[t,u],props:[c,l]})}),fl=t(),pl=r(),ml=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,hl=ea,gl=(e,t)=>n=>{if(t?.variants==null)return hl(e,n?.class,n?.className);let{variants:r,defaultVariants:i}=t,a=Object.keys(r).map(e=>{let t=n?.[e],a=i?.[e];if(t===null)return null;let o=ml(t)||ml(a);return r[e][o]}),o=n&&Object.entries(n).reduce((e,t)=>{let[n,r]=t;return r===void 0||(e[n]=r),e},{});return hl(e,a,t?.compoundVariants?.reduce((e,t)=>{let{class:n,className:r,...a}=t;return Object.entries(a).every(e=>{let[t,n]=e;return Array.isArray(n)?n.includes({...i,...o}[t]):{...i,...o}[t]===n})?[...e,n,r]:e},[]),n?.class,n?.className)},_l=gl(`group/button inline-flex shrink-0 items-center justify-center rounded-none border border-transparent bg-clip-padding text-xs font-medium whitespace-nowrap outline-none select-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-1 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/80`,outline:`border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground`,ghost:`hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50`,bare:`bg-transparent hover:bg-transparent dark:hover:bg-transparent`,destructive:`bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,xs:`h-6 gap-1 rounded-none px-2 text-xs has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-7 gap-1 rounded-none px-2.5 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5`,lg:`h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,icon:`size-8`,"icon-xs":`size-6 rounded-none [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-7 rounded-none`,"icon-lg":`size-9`}},defaultVariants:{variant:`default`,size:`default`}});function vl(e){let t=(0,fl.c)(12),n,r,i,a;t[0]===e?(n=t[1],r=t[2],i=t[3],a=t[4]):({className:n,variant:i,size:a,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=a);let o=i===void 0?`default`:i,s=a===void 0?`default`:a,c;t[5]!==n||t[6]!==s||t[7]!==o?(c=ta(_l({variant:o,size:s,className:n})),t[5]=n,t[6]=s,t[7]=o,t[8]=c):c=t[8];let l;return t[9]!==r||t[10]!==c?(l=(0,K.jsx)(dl,{"data-slot":`button`,className:c,...r}),t[9]=r,t[10]=c,t[11]=l):l=t[11],l}function yl(e){let t=(0,fl.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=ta(`flex w-full min-w-0 flex-1 flex-col items-center justify-center gap-4 rounded-none border-dashed p-6 text-center text-balance`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,K.jsx)(`div`,{"data-slot":`empty`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var bl=gl(`mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0`,{variants:{variant:{default:`bg-transparent`,icon:`flex size-8 shrink-0 items-center justify-center rounded-none bg-muted text-foreground [&_svg:not([class*='size-'])]:size-4`,symbol:`mb-0 text-muted-foreground [&_svg]:size-4`}},defaultVariants:{variant:`default`}});function xl(e){let t=(0,fl.c)(11),n,r,i;t[0]===e?(n=t[1],r=t[2],i=t[3]):({className:n,variant:i,...r}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i);let a=i===void 0?`default`:i,o;t[4]!==n||t[5]!==a?(o=ta(bl({variant:a,className:n})),t[4]=n,t[5]=a,t[6]=o):o=t[6];let s;return t[7]!==r||t[8]!==o||t[9]!==a?(s=(0,K.jsx)(`div`,{"data-slot":`empty-icon`,"data-variant":a,className:o,...r}),t[7]=r,t[8]=o,t[9]=a,t[10]=s):s=t[10],s}function Sl(e){let t=(0,fl.c)(6),n;t[0]!==e.action||t[1]!==e.icon?(n=e.action??(0,K.jsx)(xl,{"aria-hidden":!0,variant:`symbol`,children:e.icon}),t[0]=e.action,t[1]=e.icon,t[2]=n):n=t[2];let r;return t[3]!==e.label||t[4]!==n?(r=(0,K.jsx)(yl,{role:`status`,"aria-label":e.label,children:n}),t[3]=e.label,t[4]=n,t[5]=r):r=t[5],r}function Cl(){let e=(0,fl.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,K.jsx)(`a`,{href:`/`,"aria-label":`Home`}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,K.jsx)(yl,{"aria-label":`Page not found`,children:(0,K.jsxs)(vl,{variant:`outline`,size:`sm`,render:t,nativeButton:!1,children:[(0,K.jsx)(cl,{}),`Home`]})}),e[1]=n):n=e[1],n}function wl(e){let t=(0,fl.c)(3),n,r;return t[0]===e.href?(n=t[1],r=t[2]):(n=()=>{location.replace(e.href)},r=[e.href],t[0]=e.href,t[1]=n,t[2]=r),(0,G.useEffect)(n,r),null}function Tl(){let e=(0,fl.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,K.jsx)(Sl,{label:`Access denied`,icon:(0,K.jsx)(ul,{weight:`light`})}),e[0]=t):t=e[0],t}function El(e){let t=(0,fl.c)(4),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,K.jsx)(ol,{}),t[0]=n):n=t[0];let r=e.label??`Can’t load this view`,i;return t[1]!==e.reset||t[2]!==r?(i=(0,K.jsx)(yl,{role:`alert`,children:(0,K.jsxs)(vl,{variant:`destructive`,size:`sm`,onClick:e.reset,children:[n,r]})}),t[1]=e.reset,t[2]=r,t[3]=i):i=t[3],i}var Dl=class extends Vr()(`@deslop/runtime/rpc/RpcStream`){};Xe(Dl,Dl.of((e,t)=>Kr(t.rpc.successSchema)?B(hi(`rpc.stream`,!0),e):e));var Ol=ui(Dl,e=>ce(function*(){return Kr(e.rpc.successSchema)&&(yield*hi(`rpc.stream`,!0)),yield*e.next(e.request)})),q=class extends $e()(`AuthError`,{cause:Ie(Ki()),error:M(Ri([`invalid_request`,`invalid_client`,`invalid_client_metadata`,`invalid_redirect_uri`,`invalid_grant`,`invalid_scope`,`unsupported_grant_type`,`unsupported_response_type`,`access_denied`,`authorization_pending`,`expired_token`,`temporarily_unavailable`])),message:F}){get name(){return this.error===`temporarily_unavailable`?`AuthUnavailable`:`AuthError`}},kl=A({id:D,name:D});A({aud:T(`deslop`),azp:D,exp:Wi,iat:Wi,iss:D,name:D,sid:D,sub:D});var Al=A({name:F,redirects:jt(D.check(Te(200))).check(Te(4))});A({client_id:D,code:D,code_verifier:D,redirect_uri:D}),A({session:D}),A({access_token:D,expires_in:wn,refresh_token:D});var jl=F.check(Be(e=>$r(Ht(Gr(e)),e=>Bi([`http:`,`https:`],e.protocol)&&e.username===``&&e.password===``&&e.hash===``),{expected:`an HTTP(S) URL without credentials or a fragment`})).check(Be(e=>$r(Ht(Gr(e)),e=>e.pathname===`/`&&e.search===``),{expected:`an HTTP(S) origin without a path or query`})),Ml=jl.check(Be(e=>$r(Ht(Gr(e)),e=>e.protocol===`https:`||Bi([`localhost`,`127.0.0.1`,`[::1]`],e.hostname)),{expected:`HTTPS outside loopback`}));F.check(Ft(/^\d{1,5}$/u),Be(e=>$r(oe(e),e=>e>=1&&e<=65535),{expected:`a port between 1 and 65535`}));var Nl=F.check(Ft(/^0\.1\.\d+$/u)),Pl=`/api/runtime`,Fl=A({auth:M(jl),name:F,traces:F,version:Nl}),Il=`/api/rpc`;A({...kl.fields,signOut:Ni}),A({config:A({port:Wi}),name:F,version:Nl});function Ll(e,t,n,r){return H(de(ce(function*(){let i=`${yield*ii}`,a=yield*rr,o={attributes:{"scope.run.started_unix_nano":i,"scope.runtime":n,"service.instance.id":i},serviceName:e,serviceVersion:Bn(si(r,e=>e!==`0.1.0`))};return H(f(Me({resource:o,url:new URL(`/v1/traces`,t).href}),Zt({resource:o,url:new URL(`/v1/logs`,t).href}),Xe(rr)([...a,`code`,`state`,`request`,`access_token`,`refresh_token`,`id_token`,`client_secret`,`client_assertion`,`code_verifier`,`session`,`token`])),gr([Kt,lt]))})),E(e=>En(e)?tt(re):tt(m(`Telemetry is unavailable`))))}function Rl(e){return de(ce(function*(){let t=yield*H((yield*a).get(Pl),U(Br),U(li(Fl)),sn(`3 seconds`),Yt(e=>m(`Telemetry is off: the runtime config did not load`,e)),pe);return vn(t,{onNone:()=>br,onSome:t=>t.traces===``?br:Ll(`${e}-client`,t.traces,`web`,t.version)})}))}var zl=`https://auth.mp281x.xyz`,Bl=Fr(or(Zr(`AUTH_URL`)),xi);ce(function*(){let e=Yn(F,`GITHUB_ADMINS`);return(yield*Bl)?yield*$n(e,[`0`]):yield*e});function Vl(e){return`${new URL(e).origin}/auth/sign-in?${new URLSearchParams({next:e})}`}function Hl(e){return Bt(q)(e)&&e.error!==`temporarily_unavailable`&&e.error!==`access_denied`}function Ul(e){return Bt(q)(e)&&e.error!==`temporarily_unavailable`}un()(`@deslop/runtime/auth/lib/utils/CurrentUser`);var Wl=class extends Vr()(`@deslop/runtime/auth/lib/utils/RpcAuth`,{error:q}){};function Gl(e,t,n=w){function r(e){let t=S(e.reasons,e=>wi(e)&&Ul(e.error));return hr(t)?z():kn(di(t))}let i=Vn(H(e.self(),Ne(g),Qt(e=>r(e.cause))));function a(e){return vn(ft(i),{onNone:()=>e,onSome:t=>di([...t.reasons,...S(e.reasons,e=>!wi(e)||!Ul(e.error))])})}let o=Vn(0),s=H(t,Rt(t=>O(()=>{zr(i,e=>mi(r(t),()=>e));let n=a(t);R(ft(i))?e.setSelf(le(n)):c(o)<2||e.setSelf(Ee(n,{previous:e.self()}))})));return H(n(s),y(()=>O(()=>{Si(i,z()),Si(o,0)})),Hi(e=>se(a(e))),C(Yi(()=>vn(ft(i),{onNone:()=>Ii,onSome:se}))))}var Kl=Vn(z()),ql=new WeakSet,Jl=Ai(e=>{let t=Sr(`Web error`,hn(e.error),...Or(rn(e.stack)));return vn(ft(Kl),{onNone:()=>t,onSome:n=>Ae(H(t,B(Qn(e.error)),lr(`Web.error`,{attributes:{"web.error.source":e.source,"web.route.id":e.route},root:!0}),Mi),n)})});function Yl(e){let t=(0,fl.c)(5);if(Hl(e.error)){let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,K.jsx)(wl,{href:Vl(location.href)}),t[0]=e):e=t[0],e}if(Ul(e.error)){let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,K.jsx)(Tl,{}),t[1]=e):e=t[1],e}let n;return t[2]!==e.error||t[3]!==e.reset?(n=(0,K.jsx)(El,{error:e.error,reset:e.reset}),t[2]=e.error,t[3]=e.reset,t[4]=n):n=t[4],n}function Xl(e){let t=document.querySelector(`#root`);if(dn(t))throw TypeError(`Missing application mount element with id "root"`);let n=tl({context:{},defaultErrorComponent:Yl,defaultNotFoundComponent:Cl,defaultPreload:`intent`,routeTree:e,scrollRestoration:!0}),r=Ke();function i(e,t,i){if(Ui(e)){if(ql.has(e))return;ql.add(e)}r.set(Jl,{error:e,route:H(Dt(n.state.matches,t=>t.error===e),mi(()=>ue(n.state.matches)),Qt(e=>si(e.routeId,nr)),o(()=>`__root__`)),source:t,stack:i})}return n.update({defaultOnCatch:(e,t)=>i(e,`route`,t.componentStack)}),(0,pl.createRoot)(t,{onCaughtError:(e,t)=>i(e,`caught`,t.componentStack),onUncaughtError:(e,t)=>i(e,`uncaught`,t.componentStack)}).render((0,K.jsx)(G.StrictMode,{children:(0,K.jsx)(il,{router:n})})),n}function Zl(e){return t=>o(Ge(e)(t),()=>vt(e)({}))}function Ql(e){return H(e,ke(e=>H(e(Ti(`1 second`)),Pn(e=>e.input._tag===`RpcClientError`||Bt(q)(e.input)&&e.input.error===`temporarily_unavailable`))))}function $l(e,t){return Gl(e,t,Ql)}var eu=H(Ci({pingTimeout:`15 seconds`,retryTransientErrors:!0}),gr(H(kr(O(()=>`${location.origin}${Il}`)),gr(er))),qe(Mn()),qe(Ol));function tu(e){return Pi.addGlobalLayer(H(Rl(e),gr(lt),at(e=>xi(Gi(e,nn))?L:fr(O(()=>Si(Kl,kn(e))),()=>O(()=>zr(Kl,Ne(t=>t!==e))))))),eu}function nu(e){let t=new Uint8Array(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}function ru(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=(4-t.length%4)%4,r=t.padEnd(t.length+n,`=`),i=atob(r),a=new ArrayBuffer(i.length),o=new Uint8Array(a);for(let e=0;e<i.length;e++)o[e]=i.charCodeAt(e);return a}function iu(){return au.stubThis(globalThis?.PublicKeyCredential!==void 0&&typeof globalThis.PublicKeyCredential==`function`)}var au={stubThis:e=>e};function ou(e){let{id:t}=e;return{...e,id:ru(t),transports:e.transports,type:e.type}}function su(e){return e===`localhost`||/^((xn--[a-z0-9-]+|[a-z0-9]+(-[a-z0-9]+)*)\.)+([a-z]{2,}|xn--[a-z0-9-]+)$/i.test(e)}var cu=class extends Error{constructor({message:e,code:t,cause:n,name:r}){super(e,{cause:n}),Object.defineProperty(this,"code",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=r??n.name,this.code=t}};function lu({error:e,options:t}){let{publicKey:n}=t;if(!n)throw Error(`options was missing required publicKey property`);if(e.name===`AbortError`){if(t.signal instanceof AbortSignal)return new cu({message:`Registration ceremony was sent an abort signal`,code:`ERROR_CEREMONY_ABORTED`,cause:e})}else if(e.name===`ConstraintError`){if(n.authenticatorSelection?.requireResidentKey===!0)return new cu({message:`Discoverable credentials were required but no available authenticator supported it`,code:`ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT`,cause:e});if(t.mediation===`conditional`&&n.authenticatorSelection?.userVerification===`required`)return new cu({message:`User verification was required during automatic registration but it could not be performed`,code:`ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE`,cause:e});if(n.authenticatorSelection?.userVerification===`required`)return new cu({message:`User verification was required but no available authenticator supported it`,code:`ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT`,cause:e})}else if(e.name===`InvalidStateError`)return new cu({message:`The authenticator was previously registered`,code:`ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED`,cause:e});else if(e.name===`NotAllowedError`)return new cu({message:e.message,code:`ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY`,cause:e});else if(e.name===`NotSupportedError`)return n.pubKeyCredParams.filter(e=>e.type===`public-key`).length===0?new cu({message:`No entry in pubKeyCredParams was of type "public-key"`,code:`ERROR_MALFORMED_PUBKEYCREDPARAMS`,cause:e}):new cu({message:`No available authenticator supported any of the specified pubKeyCredParams algorithms`,code:`ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG`,cause:e});else if(e.name===`SecurityError`){let t=globalThis.location.hostname;if(!su(t))return new cu({message:`${globalThis.location.hostname} is an invalid domain`,code:`ERROR_INVALID_DOMAIN`,cause:e});if(n.rp.id!==t)return new cu({message:`The RP ID "${n.rp.id}" is invalid for this domain`,code:`ERROR_INVALID_RP_ID`,cause:e})}else if(e.name===`TypeError`){if(n.user.id.byteLength<1||n.user.id.byteLength>64)return new cu({message:`User ID was not between 1 and 64 characters`,code:`ERROR_INVALID_USER_ID_LENGTH`,cause:e})}else if(e.name===`UnknownError`)return new cu({message:`The authenticator was unable to process the specified options, or could not create a new credential`,code:`ERROR_AUTHENTICATOR_GENERAL_ERROR`,cause:e});return e}var uu=new class{constructor(){Object.defineProperty(this,"controller",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}createNewAbortSignal(){if(this.controller){let e=Error(`Cancelling existing WebAuthn API call for new one`);e.name=`AbortError`,this.controller.abort(e)}let e=new AbortController;return this.controller=e,e.signal}cancelCeremony(){if(this.controller){let e=Error(`Manually cancelling existing WebAuthn API call`);e.name=`AbortError`,this.controller.abort(e),this.controller=void 0}}},du=[`cross-platform`,`platform`];function fu(e){if(e&&!(du.indexOf(e)<0))return e}async function pu(e){!e.optionsJSON&&e.challenge&&(console.warn(`startRegistration() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.`),e={optionsJSON:e});let{optionsJSON:t,useAutoRegister:n=!1}=e;if(!iu())throw Error(`WebAuthn is not supported in this browser`);let r={...t,challenge:ru(t.challenge),user:{...t.user,id:ru(t.user.id)},excludeCredentials:t.excludeCredentials?.map(ou)},i={};n&&(i.mediation=`conditional`),i.publicKey=r,i.signal=uu.createNewAbortSignal();let a;try{a=await navigator.credentials.create(i)}catch(e){throw lu({error:e,options:i})}if(!a)throw Error(`Registration was not completed`);let{id:o,rawId:s,response:c,type:l}=a,u;typeof c.getTransports==`function`&&(u=c.getTransports());let d;if(typeof c.getPublicKeyAlgorithm==`function`)try{d=c.getPublicKeyAlgorithm()}catch(e){mu(`getPublicKeyAlgorithm()`,e)}let f;if(typeof c.getPublicKey==`function`)try{let e=c.getPublicKey();e!==null&&(f=nu(e))}catch(e){mu(`getPublicKey()`,e)}let p;if(typeof c.getAuthenticatorData==`function`)try{p=nu(c.getAuthenticatorData())}catch(e){mu(`getAuthenticatorData()`,e)}return{id:o,rawId:nu(s),response:{attestationObject:nu(c.attestationObject),clientDataJSON:nu(c.clientDataJSON),transports:u,publicKeyAlgorithm:d,publicKey:f,authenticatorData:p},type:l,clientExtensionResults:a.getClientExtensionResults(),authenticatorAttachment:fu(a.authenticatorAttachment)}}function mu(e,t){console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${e}. You should report this error to them.\n`,t)}function hu(){if(!iu())return gu.stubThis(new Promise(e=>e(!1)));let e=globalThis.PublicKeyCredential;return e?.isConditionalMediationAvailable===void 0?gu.stubThis(new Promise(e=>e(!1))):gu.stubThis(e.isConditionalMediationAvailable())}var gu={stubThis:e=>e};function _u({error:e,options:t}){let{publicKey:n}=t;if(!n)throw Error(`options was missing required publicKey property`);if(e.name===`AbortError`){if(t.signal instanceof AbortSignal)return new cu({message:`Authentication ceremony was sent an abort signal`,code:`ERROR_CEREMONY_ABORTED`,cause:e})}else if(e.name===`NotAllowedError`)return new cu({message:e.message,code:`ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY`,cause:e});else if(e.name===`SecurityError`){let t=globalThis.location.hostname;if(!su(t))return new cu({message:`${globalThis.location.hostname} is an invalid domain`,code:`ERROR_INVALID_DOMAIN`,cause:e});if(n.rpId!==t)return new cu({message:`The RP ID "${n.rpId}" is invalid for this domain`,code:`ERROR_INVALID_RP_ID`,cause:e})}else if(e.name===`UnknownError`)return new cu({message:`The authenticator was unable to process the specified options, or could not create a new assertion signature`,code:`ERROR_AUTHENTICATOR_GENERAL_ERROR`,cause:e});return e}async function vu(e){!e.optionsJSON&&e.challenge&&(console.warn(`startAuthentication() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.`),e={optionsJSON:e});let{optionsJSON:t,useBrowserAutofill:n=!1,verifyBrowserAutofillInput:r=!0}=e;if(!iu())throw Error(`WebAuthn is not supported in this browser`);let i;t.allowCredentials?.length!==0&&(i=t.allowCredentials?.map(ou));let a={...t,challenge:ru(t.challenge),allowCredentials:i},o={};if(n){if(!await hu())throw Error(`Browser does not support WebAuthn autofill`);if(document.querySelectorAll(`input[autocomplete$='webauthn']`).length<1&&r)throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');o.mediation=`conditional`,a.allowCredentials=[]}o.publicKey=a,o.signal=uu.createNewAbortSignal();let s;try{s=await navigator.credentials.get(o)}catch(e){throw _u({error:e,options:o})}if(!s)throw Error(`Authentication was not completed`);let{id:c,rawId:l,response:u,type:d}=s,f;return u.userHandle&&(f=nu(u.userHandle)),{id:c,rawId:nu(l),response:{authenticatorData:nu(u.authenticatorData),clientDataJSON:nu(u.clientDataJSON),signature:nu(u.signature),userHandle:f},type:d,clientExtensionResults:s.getClientExtensionResults(),authenticatorAttachment:fu(s.authenticatorAttachment)}}Ar(`MachineSchemaEncodeError`);var J=class extends Ar(`MachineSchemaDecodeError`){},yu=class extends Ar(`InfiniteTransitionError`){},bu=class extends Ar(`StartupError`){},xu=class extends Ar(`ChildAlreadyExistsError`){};Ar(`ProcessLocalError`);var Su=class extends Ar(`StoppedError`){},Cu=e=>e instanceof yu||e instanceof J,wu=e=>Cu(e)?W(e):Qn(e),Tu=e=>Cu(e)||e instanceof bu?e:new bu({cause:cr(e)}),Y=e=>e,Eu=`~effect/Machine/Target`,Du=Symbol(`effect/Machine/TargetSnapshot`),Ou=Symbol(`effect/Machine/StateInput`),ku=Symbol(`effect/Machine/HistoryTarget`),Au=Symbol(`effect/Machine/InitialTarget`),ju=Symbol(`effect/Machine/ChoiceTarget`),Mu=Symbol(`effect/Machine/NoTarget`),Nu=Symbol(`effect/Machine/Declined`),Pu=Symbol(`effect/Machine/TargetSelection`),Fu=Symbol(`effect/Machine/StateUpdate`),Iu=Symbol(`effect/Machine/CombinedTarget`),Lu=Symbol(`effect/Machine/SelectedBranch`),Ru=(e,t,n,r)=>Object.freeze({[Pu]:Pu,kind:e,scope:n,path:t,...r===void 0?{}:{updatePath:r}}),zu=Ru(`none`,void 0,`local`),Bu=e=>N(e,Pu),Vu=(e,t)=>Object.freeze({[Fu]:Fu,path:e,value:t}),Hu=e=>N(e,Fu),Uu=(e,t)=>Object.freeze({[Iu]:Iu,target:e,update:t}),Wu=e=>N(e,Iu),Gu=(e,t,n,r)=>Object.freeze({[Lu]:Lu,owner:e,branchIndex:t,branchKey:n,result:r}),Ku=e=>N(e,Lu),qu=Object.freeze({[Mu]:Mu}),Ju=()=>qu,Yu=e=>N(e,Mu),Xu=Object.freeze({[Nu]:Nu}),Zu=()=>Xu,Qu=e=>N(e,Nu),$u=(e,t)=>({[ku]:ku,path:e,parent:t}),ed=e=>N(e,ku),td=(e,t,n)=>({[Au]:Au,_tag:`InitialTarget`,path:e,value:t,...n===void 0?{}:{values:n}}),nd=e=>N(e,Au),rd=(e,t,n)=>({[ju]:ju,path:e,parent:t,...n===void 0?{}:{values:n}}),id=e=>N(e,ju),ad=(e,t)=>{if(!j(t)&&t.type===`history`)return{schema:void 0,output:void 0,annotations:t.annotations,type:`history`,history:t.history===`deep`?`deep`:`shallow`,initial:void 0,states:void 0};if(!j(t)&&t.type===`choice`)return{schema:void 0,output:void 0,annotations:t.annotations,type:`choice`,history:void 0,initial:void 0,states:void 0};if(j(t))return{schema:t,output:void 0,annotations:Xt(t),type:`atomic`,history:void 0,initial:void 0,states:void 0};let n=N(t,`schema`)&&j(t.schema)?t.schema:void 0,r=n===void 0?t.annotations:Xt(n);if(t.type===`parallel`&&!N(t,`states`))throw Error(`Machine.make expected parallel state "${e}" to declare child regions`);if(N(t,`states`)){if(t.type===`final`)throw Error(`Machine.make expected compound state "${e}" to be active`);if(t.type===`parallel`)return{schema:n,output:j(t.output)?t.output:void 0,annotations:r,type:`parallel`,history:void 0,initial:void 0,states:t.states};let i=`initial`in t?t.initial:void 0;if(typeof i!=`string`)throw Error(`Machine.make expected compound state "${e}" to declare an initial child`);return{schema:n,output:void 0,annotations:r,type:`compound`,history:void 0,initial:i,states:t.states}}let i=j(t.output)?t.output:void 0;return t.type===`final`?{schema:n,output:i,annotations:r,type:`final`,history:void 0,initial:void 0,states:void 0}:{schema:n,output:void 0,annotations:r,type:`atomic`,history:void 0,initial:void 0,states:void 0}},od=e=>{let t=new Map,n=0,r=(e,i)=>{let a=[];for(let o of Object.keys(e)){if(o.includes(`.`))throw Error(`Machine state keys cannot contain ".": "${o}"`);let s=i===void 0||i===``?o:`${i}.${o}`,c=ad(s,e[o]),l,u,d={path:s,key:o,annotations:c.annotations,order:n};switch(c.type){case`atomic`:l={...d,type:`atomic`,schema:c.schema,output:void 0,history:void 0,parent:i,children:[],initial:void 0};break;case`compound`:l={...d,type:`compound`,schema:c.schema,output:void 0,history:void 0,parent:i,children:[],initial:s===``?c.initial:`${s}.${c.initial}`},u=c.states;break;case`parallel`:l={...d,type:`parallel`,schema:c.schema,output:c.output,history:void 0,parent:i,children:[],initial:void 0},u=c.states;break;case`final`:l={...d,type:`final`,schema:c.schema,output:c.output,history:void 0,parent:i,children:[],initial:void 0};break;case`history`:if(i===void 0)throw Error(`Machine history state "${s}" must belong to a parent state`);l={...d,type:`history`,schema:void 0,output:void 0,history:c.history,parent:i,children:[],initial:void 0};break;case`choice`:if(i===void 0)throw Error(`Machine choice state "${s}" must belong to a parent state`);l={...d,type:`choice`,schema:void 0,output:void 0,history:void 0,parent:i,children:[],initial:void 0}}if(t.set(s,l),n+=1,c.type!==`history`&&c.type!==`choice`&&(a.push(s),u!==void 0)){let e=r(u,s);if(l.type===`compound`){if(!e.includes(l.initial)&&t.get(l.initial)?.type!==`choice`)throw Error(`Machine.make expected compound state "${s}" initial child to exist`);l={...l,children:e}}else if(l.type===`parallel`)l={...l,children:e};else throw Error(`Machine state "${s}" cannot declare child states`);t.set(s,l)}}return a};return{byPath:t,roots:r(e,void 0)}},sd=e=>typeof e==`object`&&e&&`branches`in e&&Array.isArray(e.branches)?Array.from(e.branches):[],cd=e=>typeof e==`object`&&e&&`declinable`in e&&e.declinable===!0?`declinable`:`required`,ld=e=>{let t=[];for(let n of e.stateNodes.byPath.values()){let r=Y(e).handlers[n.path];if(r===void 0)continue;if(n.type===`choice`){let e=r.choice;e!==void 0&&t.push({source:n.path,trigger:{type:`choice`},reenter:!1,acceptance:`required`,branches:sd(e)});continue}for(let e of Reflect.ownKeys(r.on??{})){let i=r.on?.[e];t.push({source:n.path,trigger:{type:`event`,event:e},reenter:N(i,`reenter`)&&i.reenter===!0,acceptance:cd(i),branches:sd(i)})}r.always!==void 0&&t.push({source:n.path,trigger:{type:`always`},reenter:!1,acceptance:cd(r.always),branches:sd(r.always)}),r.onDone!==void 0&&t.push({source:n.path,trigger:{type:`done`},reenter:!1,acceptance:cd(r.onDone),branches:sd(r.onDone)});let i=r.invoke===void 0?[]:Array.isArray(r.invoke)?r.invoke:[r.invoke];for(let e of i){let r=`child`in e?String(e.child.id):String(e.id);for(let i of[`element`,`done`,`failure`,`snapshot`]){let a=i===`element`?e.onElement:i===`done`?e.onDone:i===`failure`?e.onFailure:e.onSnapshot;a!==void 0&&t.push({source:n.path,trigger:{type:`invoke`,id:r,outcome:i},reenter:typeof a==`object`&&!!a&&a.reenter===!0,acceptance:cd(a),branches:sd(a)})}}}return t},ud=(e,t,n)=>({[Eu]:Eu,[Du]:n?.snapshot,path:e,value:t,values:n?.values}),dd=e=>N(e,Eu),fd=e=>({[Ou]:Ou,input:e}),pd=e=>N(e,Ou),md=e=>N(e,`path`)&&N(e,`value`),hd=(e,t,n)=>{if(e.path===t)return kn(e);if(e.path!==``&&!t.startsWith(`${e.path}.`))return z();if(n!==void 0&&e.value!==void 0&&(n[e.path]=e.value),N(e,`state`)&&md(e.state))return hd(e.state,t,n);if(N(e,`states`)&&typeof e.states==`object`&&e.states!==null){for(let r of Object.values(e.states))if(md(r)){let e=hd(r,t,n);if(R(e))return e}}return z()},X=(e,t)=>{let n=e.stateNodes.byPath.get(t);if(n===void 0)throw Error(`Machine expected state path "${t}" to exist`);return n},gd=e=>{if(e.schema===void 0)throw Error(`Machine state "${e.path}" has no value schema`);return e.schema},_d=new WeakMap,vd=Symbol(`effect/Machine/EventConstruction`),yd=new WeakMap,bd=new WeakMap,xd=new WeakMap,Sd=e=>{let t=e,n=bd.get(t);if(n!==void 0)return n;let r=Zi(mt(e));return bd.set(t,r),r},Cd=e=>{let t=e,n=xd.get(t);if(n!==void 0)return n;let r=b(mt(e));return xd.set(t,r),r},wd=Symbol.for(`effect/Machine/protocol`),Td=e=>{let t=e[wd];if(t===void 0)throw Error(`Machine protocol is unavailable`);return t},Ed=(e,t)=>{Object.defineProperty(e,wd,{value:t,enumerable:!1})},Dd=e=>{let t=new Set,n=e=>{let r=e;if(!t.has(r)&&(t.add(r),N(e,`cases`)&&typeof e.cases==`object`&&e.cases!==null))for(let t of Object.values(e.cases))(typeof t==`object`&&t||typeof t==`function`)&&N(t,`make`)&&n(t)};for(let t of e)n(t);return t},Od=(e,t)=>{let n=_d.get(e);if(n===void 0)throw Error(`Machine expected an event protocol created with Machine.events, Machine.internalEvents, or Machine.emittedEvents`);if(t!==void 0&&n.kind!==t)throw Error(`Machine expected a ${t} event protocol`);return n},kd=e=>Od(e.events,`public`).schemas,Ad=e=>Od(e.internalEvents,`internal`).schemas,jd=e=>Od(e.emittedEvents,`emitted`).schemas,Md=e=>{let t=kd(e),n=Ad(e),r=jd(e),i=new Set(Reflect.ownKeys(e.events));for(let t of Reflect.ownKeys(e.internalEvents))if(i.has(t))throw Error(`Public and internal machine event tags must be disjoint: ${String(t)}`);let a=[...t,...n];Ed(e,{event:je(a),emit:je(r),eventConstructors:Dd(a),emissionConstructors:Dd(r)})},Nd=(e,t)=>Ed(t,Td(e)),Pd=e=>N(e,`_tag`)?String(e._tag):void 0,Fd=(e,t,n,r)=>{let i=r,a;if(typeof r==`object`&&r)try{i={...r}}catch(e){i=void 0,a=e}let o={[vd]:vd,_tag:n};return yd.set(o,{kind:e,schema:t,input:i,...a===void 0?{}:{inputError:a}}),Object.freeze(o)},Id=e=>typeof e==`object`&&!!e&&yd.has(e),Ld=(e,t)=>{let n=[],r=e=>{if(N(e,`cases`)&&typeof e.cases==`object`&&e.cases!==null)for(let t of Reflect.ownKeys(e.cases))r(Reflect.get(e.cases,t));else if(N(e,`members`)&&Array.isArray(e.members))for(let t of e.members)r(t);else n.push(e)};for(let e of t)r(e);let i=Object.create(null),a=e=>ur(e)?typeof e.literal==`string`||typeof e.literal==`number`?[e.literal]:[]:Jr(e)?[e.symbol]:oi(e)?e.enums.map(([,e])=>e):Kn(e)?e.types.flatMap(a):Dr(e)?a(e.thunk()):[],o=e=>{let t=Mr(e.ast);if(Wr(t)){let e=t.propertySignatures.find(({name:e})=>e===`_tag`),n=e===void 0?[]:a(e.type);if(n.length>0)return n}try{return je([e]).pipe(cn(`_tag`)).discriminants}catch{return[]}};for(let t of n){let n=o(t);if(n.length!==0)for(let r of n){if(N(i,r))throw Error(`Duplicate machine event constructor tag: ${String(r)}`);Object.defineProperty(i,r,{value:(...n)=>Fd(e,t,r,n.length===0?{}:n[0]),enumerable:!0})}}return i},Rd=(e,t)=>{let n=Object.freeze(Array.from(t)),r=Ld(e,n);return _d.set(r,{kind:e,schemas:n}),Object.freeze(r)},zd=(e,t,n,r)=>Sd(t)(n).pipe(Ye(t=>new J({machineId:e.id,boundary:r.boundary,cause:t,...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}}))),Bd=(e,t,n,r)=>{let i=Cd(t)(n);if(ge(i))throw new J({machineId:e.id,boundary:r.boundary,cause:i.failure,...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}});return i.success},Vd=(e,t,n,r)=>{try{return t.make(n)}catch(t){let n=t instanceof Error?t.cause:void 0;throw new J({machineId:e.id,boundary:r.boundary,cause:be(t)?t:N(n,`~effect/SchemaIssue/Issue`)?new h(n):cr(t),...r.state===void 0?{}:{state:r.state},...r.event===void 0?{}:{event:r.event}})}},Hd=(e,t,n)=>new J({machineId:e.id,boundary:n,event:String(t._tag),cause:cr(Error(`Constructed ${n} schema does not belong to the machine ${n} protocol`))}),Ud=(e,t)=>{if(t.inputError!==void 0)throw t.inputError;return typeof t.input==`object`&&t.input!==null?{...t.input,_tag:e._tag}:{_tag:e._tag}},Wd=(e,t,n,r)=>new J({machineId:e.id,boundary:n,event:String(t._tag),cause:cr(r)}),Gd=(e,t,n,r)=>{let i=yd.get(n),a=r===`event`?t.eventConstructors:t.emissionConstructors;return i===void 0||(r===`emission`?i.kind!==`emitted`:i.kind===`emitted`)||!a.has(i.schema)?W(Hd(e,n,r)):l({try:()=>Ud(n,i),catch:t=>Wd(e,n,r,t)}).pipe(U(t=>i.schema.makeEffect(t).pipe(Ye(t=>new J({machineId:e.id,boundary:r,event:String(n._tag),cause:new h(t)})))))},Kd=(e,t,n,r)=>{let i=yd.get(n),a=r===`event`?t.eventConstructors:t.emissionConstructors;if(i===void 0||(r===`emission`?i.kind!==`emitted`:i.kind===`emitted`)||!a.has(i.schema))throw Hd(e,n,r);let o;try{o=Ud(n,i)}catch(t){throw Wd(e,n,r,t)}return Vd(e,i.schema,o,{boundary:r,event:String(n._tag)})},qd=(e,t)=>{let n=Td(e);if(Id(t))return Gd(e,n,t,`event`);let r=Pd(t);return zd(e,n.event,t,r===void 0?{boundary:`event`}:{boundary:`event`,event:r})},Jd=(e,t)=>{let n=Td(e);if(Id(t))return Kd(e,n,t,`event`);let r=Pd(t);return Bd(e,n.event,t,r===void 0?{boundary:`event`}:{boundary:`event`,event:r})},Yd=(e,t)=>{let n=Td(e);if(Id(t))return Gd(e,n,t,`emission`);let r=Pd(t);return zd(e,n.emit,t,r===void 0?{boundary:`emission`}:{boundary:`emission`,event:r})},Xd=(e,t)=>{let n=Td(e);if(Id(t))return Kd(e,n,t,`emission`);let r=Pd(t);return Bd(e,n.emit,t,r===void 0?{boundary:`emission`}:{boundary:`emission`,event:r})},Zd=(e,t,n)=>Bd(e,t,n,{boundary:`input`}),Qd=(e,t,n)=>pd(n)?gd(t).makeEffect(n.input).pipe(Ye(n=>new J({machineId:e.id,boundary:`state`,state:t.path,cause:new h(n)}))):zd(e,gd(t),n,{boundary:`state`,state:t.path}),$d=(e,t,n)=>pd(n)?Vd(e,gd(t),n.input,{boundary:`state`,state:t.path}):Bd(e,gd(t),n,{boundary:`state`,state:t.path}),ef=(e,t,n)=>t.output===void 0?k(n):zd(e,t.output,n,{boundary:`output`,state:t.path}),tf=(e,t,n)=>t.output===void 0?n:Bd(e,t.output,n,{boundary:`output`,state:t.path}),nf=(e,t)=>{let n=new Set(Z(e,t.parent)),r=n=>{let i=X(e,n);if(i.type===`compound`){let e=i.children.filter(e=>t.active.has(e));if(e.length!==1)throw Error(`Machine history expected compound state "${n}" to retain one active child`);t.mode===`deep`&&r(e[0])}else if(i.type===`parallel`)for(let e of i.children){if(!t.active.has(e))throw Error(`Machine history expected parallel state "${n}" to retain region "${e}"`);t.mode===`deep`&&r(e)}};r(t.parent);for(let r of t.active){if(!n.has(r)&&!ff(r,t.parent))throw Error(`Machine history contains state "${r}" outside parent "${t.parent}"`);if(t.mode===`shallow`&&df(r,t.parent)&&X(e,r).parent!==t.parent)throw Error(`Machine shallow history contains deep descendant "${r}"`)}},rf=(e,t)=>{let n=new Map;for(let[r,i]of Object.entries(t.history??{})){let t=X(e,r);if(t.type!==`history`||t.parent===void 0||t.history!==i.mode)throw Error(`Machine snapshot contains invalid history record "${r}"`);let a=new Set,o=new Map;for(let n of i.active){if(a.has(n))throw Error(`Machine snapshot contains invalid remembered state "${n}"`);let r=X(e,n);if(r.type===`history`||r.type===`choice`||!(ff(n,t.parent)||Z(e,t.parent).includes(n)))throw Error(`Machine snapshot contains invalid remembered value for "${n}"`);a.add(n);let s=Object.prototype.hasOwnProperty.call(i.values,n);if(r.schema===void 0){if(s)throw Error(`Machine snapshot contains a value for structural state "${n}"`)}else{if(!s)throw Error(`Machine snapshot omits remembered value for "${n}"`);o.set(n,$d(e,r,i.values[n]))}}if(!a.has(t.parent)||Object.keys(i.values).length!==o.size)throw Error(`Machine snapshot contains incomplete history record "${r}"`);n.set(r,{mode:i.mode,parent:t.parent,active:a,values:o}),nf(e,n.get(r))}return n},af=wt(function*(e,t){let n=new Map;for(let[r,i]of Object.entries(t.history??{})){let t=e.stateNodes.byPath.get(r);if(t===void 0||t.type!==`history`||t.parent===void 0||t.history!==i.mode)return yield*W(new J({machineId:e.id,boundary:`history`,state:r,cause:cr(Error(`Machine snapshot contains invalid history record "${r}"`))}));let a=new Set,o=new Map;for(let n of i.active){let r=e.stateNodes.byPath.get(n);if(a.has(n)||r===void 0||r.type===`history`||r.type===`choice`||!(ff(n,t.parent)||Z(e,t.parent).includes(n)))return yield*W(new J({machineId:e.id,boundary:`history`,state:n,cause:cr(Error(`Machine snapshot contains invalid remembered state "${n}"`))}));a.add(n);let s=Object.prototype.hasOwnProperty.call(i.values,n);if(r.schema===void 0){if(s)return yield*W(new J({machineId:e.id,boundary:`history`,state:n,cause:cr(Error(`Machine snapshot contains a value for structural state "${n}"`))}))}else{if(!s)return yield*W(new J({machineId:e.id,boundary:`history`,state:n,cause:cr(Error(`Machine snapshot omits remembered value for "${n}"`))}));o.set(n,yield*zd(e,gd(r),i.values[n],{boundary:`history`,state:n}))}}if(!a.has(t.parent)||Object.keys(i.values).length!==o.size)return yield*W(new J({machineId:e.id,boundary:`history`,state:r,cause:cr(Error(`Machine snapshot contains incomplete history record "${r}"`))}));n.set(r,{mode:i.mode,parent:t.parent,active:a,values:o});try{nf(e,n.get(r))}catch(t){return yield*W(new J({machineId:e.id,boundary:`history`,state:r,cause:cr(t)}))}}return n}),of=(e,t)=>{let n={};for(let[r,i]of t){let t=Array.from(i.active).sort((t,n)=>mf(e,t,n));n[r]={mode:i.mode,active:t,values:Object.fromEntries(i.values)}}return n},sf=(e,t)=>({...e,machineReferences:{self:t.self,parent:t.parent}}),cf=e=>e.machineReferences,lf=new WeakMap,uf=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),df=(e,t)=>e!==t&&(t===``||e.startsWith(`${t}.`)),ff=(e,t)=>e===t||df(e,t),Z=(e,t)=>{let n=lf.get(e.stateNodes);n===void 0&&(n=new Map,lf.set(e.stateNodes,n));let r=n.get(t);if(r!==void 0)return r;let i=[],a=t;for(;a!==void 0;)i.unshift(a),a=X(e,a).parent;return n.set(t,i),i},pf=(e,t)=>Z(e,t).length,mf=(e,t,n)=>X(e,t).order-X(e,n).order,hf=(e,t,n)=>X(e,n).children.some(e=>t.active.has(e)),gf=(e,t)=>{let n=Array.from(t.active).filter(n=>!hf(e,t,n)).sort((t,n)=>mf(e,t,n));if(n.length===0)throw Error(`Machine expected an active leaf state`);return n},_f=(e,t)=>gf(e,t)[0],vf=(e,t,n)=>{let r=gf(e,t).filter(e=>ff(e,n));if(r.length===0)throw Error(`Machine expected state "${n}" to have an active leaf state`);return r[0]},yf=(e,t)=>{for(let n of t.active)if(X(e,n).parent===void 0)return n;throw Error(`Machine expected an active root state`)},bf=(e,t,n)=>{let r={},i=Z(e,n);for(let e=0;e<i.length-1;e++){let n=i[e];t.values.has(n)&&(r[n]=t.values.get(n))}return r},xf=(e,t,n)=>{let r=X(e,n).parent;return r===void 0?void 0:t.values.get(r)},Sf=(e,t)=>{let n=r=>t.active.has(r)?[r,...X(e,r).children.flatMap(n)]:[];return e.stateNodes.roots.flatMap(n)},Cf=(e,t,n)=>{let r=X(e,n),i={path:n,value:t.values.get(n)};if(r.type===`compound`){let a=r.children.find(e=>t.active.has(e));if(a===void 0)throw Error(`Machine expected compound state "${n}" to have an active child`);i.state=Cf(e,t,a)}if(r.type===`parallel`){let a={};for(let i of r.children){if(!t.active.has(i))throw Error(`Machine expected parallel state "${n}" to have active child region "${i}"`);let r=X(e,i);a[r.key]=Cf(e,t,i)}i.states=a}return i},wf=(e,t)=>{let n=Cf(e,t,yf(e,t)),r=Array.from(t.outputs).map(([e,t])=>({path:e,output:t}));return r.length>0&&(n.completed=r),t.history.size>0&&Object.assign(n,{history:of(e,t.history)}),n},Tf=(e,t,n)=>{let r=Cf(e,t,n);return t.history.size>0&&Object.assign(r,{history:of(e,t.history)}),r},Ef=(e,t,n)=>{if(!N(n,`state`)||!md(n.state))throw Error(`Machine expected compound snapshot "${t.path}" to include an active child state`);let r=X(e,String(n.state.path));if(r.parent!==t.path)throw Error(`Machine expected snapshot "${r.path}" to be a child of "${t.path}"`);return n.state},Df=(e,t)=>{if(!N(t,`states`)||typeof t.states!=`object`||t.states===null)throw Error(`Machine expected parallel snapshot "${e.path}" to include active child regions`);return t.states},Of=(e,t,n,r)=>{let i=X(e,n),a=r[i.key];if(!uf(r,i.key)||!md(a))throw Error(`Machine expected parallel snapshot "${t.path}" to include region "${i.key}"`);let o=X(e,String(a.path));if(o.path!==i.path)throw Error(`Machine expected snapshot "${o.path}" to be region "${i.path}"`);return a},kf=(e,t)=>{let n=new Set,r=new Map,i=t.completed,a=t=>{let i=X(e,String(t.path));if(n.add(i.path),i.schema===void 0){if(t.value!==void 0)throw Error(`Machine structural snapshot "${i.path}" cannot contain a value`)}else r.set(i.path,$d(e,i,t.value));if(i.type===`compound`&&a(Ef(e,i,t)),i.type===`parallel`){let n=Df(i,t);for(let t of i.children)a(Of(e,i,t,n))}};a(t);let o=new Map;if(i!==void 0)for(let{output:e,path:t}of i)n.has(t)&&o.set(t,e);return{active:n,values:r,outputs:o,history:rf(e,t)}},Af=(e,t)=>kf(e,t),jf=(e,t)=>{try{return kf(e,t)}catch(t){throw t instanceof J?t:new J({machineId:e.id,boundary:`configuration`,cause:cr(t)})}},Mf=wt(function*(e,t){let n=new Set,r=new Map,i=t.completed,a=wt(function*(t){let i=X(e,String(t.path));if(n.add(i.path),i.schema===void 0){if(t.value!==void 0)throw Error(`Machine structural snapshot "${i.path}" cannot contain a value`)}else r.set(i.path,yield*Qd(e,i,t.value));if(i.type===`compound`&&(yield*a(Ef(e,i,t))),i.type===`parallel`){let n=Df(i,t);for(let t of i.children)yield*a(Of(e,i,t,n))}});yield*a(t);let o=new Map;if(i!==void 0)for(let{output:e,path:t}of i)n.has(t)&&o.set(t,e);return{active:n,values:r,outputs:o,history:yield*af(e,t)}}),Nf=(e,t)=>Mf(e,t).pipe(Jn(t=>{if(En(t))return Cn(Wn(t,t=>t instanceof J?t:new J({machineId:e.id,boundary:`configuration`,cause:hn(t)})));let n=Hr(t);return R(n)&&n.value instanceof J?W(n.value):W(new J({machineId:e.id,boundary:`configuration`,cause:t}))})),Pf=(e,t,n,r)=>{if(r.length===0)return n;let i=new Set(r),a=new Map(n.history);for(let n of e.stateNodes.byPath.values()){if(n.type!==`history`||n.parent===void 0||!i.has(n.parent))continue;let r=n.history===`deep`?`deep`:`shallow`,o=new Set;for(let r of Z(e,n.parent))t.active.has(r)&&o.add(r);for(let i of t.active)(i===n.parent||r===`deep`&&df(i,n.parent)||r===`shallow`&&X(e,i).parent===n.parent)&&o.add(i);let s=new Map;for(let e of o)t.values.has(e)&&s.set(e,t.values.get(e));a.set(n.path,{mode:r,parent:n.parent,active:o,values:s})}return{active:n.active,values:n.values,outputs:n.outputs,history:a}},Ff=(e,t)=>e.history.get(t),If=(e,t,n)=>{let r=new Set(n.active),i=new Map(n.values),a=new Map,o=Z(e,n.parent),s=new Set(o);for(let c of o){let o=X(e,c);if(o.type===`parallel`){for(let e of o.children)if(!(s.has(e)||n.active.has(e)||!t.active.has(e)))for(let n of t.active)ff(n,e)&&(r.add(n),t.values.has(n)&&i.set(n,t.values.get(n)),t.outputs.has(n)&&a.set(n,t.outputs.get(n)))}}return{active:r,values:i,outputs:a,history:t.history}};wt(function*(e,t,n,r,i){let a=X(e,n),o=new Set,s=new Map,c=new Map,l=Z(e,a.path),u=new Set(l);for(let n of l){let c=X(e,n);if(o.add(n),c.schema===void 0){if((n===a.path?r:i!==void 0&&uf(i,n)?i[n]:void 0)!==void 0)throw Error(`Machine structural target "${n}" cannot contain a value`)}else if(n===a.path)s.set(n,yield*Qd(e,c,r));else if(i!==void 0&&uf(i,n))s.set(n,yield*Qd(e,c,i[n]));else if(t.values.has(n))s.set(n,t.values.get(n));else throw Error(`Machine target "${a.path}" requires a value for ancestor state "${n}"`)}for(let n of l){let r=X(e,n);if(r.type===`parallel`){for(let e of r.children)if(!u.has(e)&&t.active.has(e))for(let n of t.active)ff(n,e)&&(o.add(n),t.values.has(n)&&s.set(n,t.values.get(n)),t.outputs.has(n)&&c.set(n,t.outputs.get(n)))}}if(a.type===`compound`||a.type===`parallel`)throw Error(`Machine target "${a.path}" must include an active child state`);return{active:o,values:s,outputs:c,history:t.history}}),wt(function*(e,t,n,r){let i=yield*Mf(e,n),a=new Set(i.active),o=new Map(i.values),s=new Map(i.outputs),c=Z(e,String(n.path)),l=new Set(c);for(let i of c.slice(0,-1)){let s=X(e,i);if(a.add(i),s.schema===void 0){if(r!==void 0&&uf(r,i))throw Error(`Machine structural target "${i}" cannot contain a value`)}else if(r!==void 0&&uf(r,i))o.set(i,yield*Qd(e,s,r[i]));else if(t.values.has(i))o.set(i,t.values.get(i));else throw Error(`Machine target "${n.path}" requires a value for ancestor state "${i}"`)}for(let n of c.slice(0,-1)){let i=X(e,n);if(i.type===`parallel`){for(let n of i.children)if(!l.has(n)){if(t.active.has(n))for(let e of t.active)ff(e,n)&&(a.add(e),t.values.has(e)&&o.set(e,t.values.get(e)),t.outputs.has(e)&&s.set(e,t.outputs.get(e)));else if(r!==void 0&&uf(r,n))for(let[t,i]of Object.entries(r)){if(!ff(t,n))continue;let r=X(e,t);if(a.add(t),r.schema===void 0)throw Error(`Machine structural target "${t}" cannot contain a value`);o.set(t,yield*Qd(e,r,i))}}}}return{active:a,values:o,outputs:s,history:new Map([...t.history,...i.history])}});var Lf=(e,t,n,r,i,a=!1)=>{let o=X(e,n),s=new Set,c=new Map,l=new Map,u=Z(e,o.path),d=new Set(u);for(let n of u){let a=X(e,n);if(s.add(n),a.schema===void 0){if((n===o.path?r:i!==void 0&&uf(i,n)?i[n]:void 0)!==void 0)throw Error(`Machine structural target "${n}" cannot contain a value`)}else if(n===o.path)c.set(n,$d(e,a,r));else if(i!==void 0&&uf(i,n))c.set(n,$d(e,a,i[n]));else if(t.values.has(n))c.set(n,t.values.get(n));else throw Error(`Machine target "${o.path}" requires a value for ancestor state "${n}"`)}for(let n of u){let r=X(e,n);if(r.type===`parallel`&&n!==o.path){for(let e of r.children)if(!d.has(e)&&t.active.has(e))for(let n of t.active)ff(n,e)&&(s.add(n),t.values.has(n)&&c.set(n,t.values.get(n)),t.outputs.has(n)&&l.set(n,t.outputs.get(n)))}}if(!a&&(o.type===`compound`||o.type===`parallel`))throw Error(`Machine target "${o.path}" must include an active child state`);return{active:s,values:c,outputs:l,history:t.history}},Rf=(e,t,n)=>{let r=Lf(e,t,n.path,n.value,n.values,!0);if(n.children===void 0)return r;let i=new Set(r.active),a=new Map(r.values);for(let[t,r]of n.children){let n=X(e,t);i.add(t),n.schema!==void 0&&a.set(t,$d(e,n,r))}return{...r,active:i,values:a}},zf=(e,t,n,r)=>{let i=kf(e,n),a=new Set(i.active),o=new Map(i.values),s=new Map(i.outputs),c=Z(e,String(n.path)),l=new Set(c);for(let i of c.slice(0,-1)){let s=X(e,i);if(a.add(i),s.schema===void 0){if(r!==void 0&&uf(r,i))throw Error(`Machine structural target "${i}" cannot contain a value`)}else if(r!==void 0&&uf(r,i))o.set(i,$d(e,s,r[i]));else if(t.values.has(i))o.set(i,t.values.get(i));else throw Error(`Machine target "${n.path}" requires a value for ancestor state "${i}"`)}for(let n of c.slice(0,-1)){let i=X(e,n);if(i.type===`parallel`){for(let n of i.children)if(!l.has(n)){if(t.active.has(n))for(let e of t.active)ff(e,n)&&(a.add(e),t.values.has(e)&&o.set(e,t.values.get(e)),t.outputs.has(e)&&s.set(e,t.outputs.get(e)));else if(r!==void 0&&uf(r,n))for(let[t,i]of Object.entries(r)){if(!ff(t,n))continue;let r=X(e,t);if(a.add(t),r.schema===void 0)throw Error(`Machine structural target "${t}" cannot contain a value`);o.set(t,$d(e,r,i))}}}}return{active:a,values:o,outputs:s,history:new Map([...t.history,...i.history])}},Bf=(e,t,n)=>{if(dd(n)){let r=n[Du];if(r!==void 0){if(String(r.path)!==String(n.path))throw Error(`Machine expected target snapshot path to be "${n.path}"`);return zf(e,t,r,n.values)}return Lf(e,t,n.path,n.value,n.values)}if(md(n)){let r=jf(e,n);return{...r,history:new Map([...t.history,...r.history])}}throw Error(`Machine expected transition target to be a snapshot or target builder result`)},Vf=(e,t)=>Y(e).handlers[t],Hf=(e,t,n)=>X(e,n).children.find(e=>t.active.has(e)),Uf=(e,t)=>X(e,t).type===`final`,Wf=(e,t)=>Vf(e,t)?.onDone!==void 0,Gf=(e,t,n)=>{if(!t.active.has(n))return!1;let r=X(e,n);if(r.type===`compound`){let r=Hf(e,t,n);return r!==void 0&&(n===``?!Wf(e,r)&&Gf(e,t,r):Uf(e,r))}if(r.type===`parallel`){for(let n of r.children)if(!Gf(e,t,n))return!1;return!0}return Uf(e,n)},Kf=(e,t)=>{let n=yf(e,t);return Gf(e,t,n)&&!Wf(e,n)},qf=(e,t,n)=>e.has(t)?{path:t,output:e.get(t),isNew:!1}:(e.set(t,n),{path:t,output:n,isNew:!0}),Jf=wt(function*(e,t,n,r,i){let a=X(e,n),o=Vf(e,n)?.output?.({state:t.values.get(n),containingState:xf(e,t,n),ancestors:bf(e,t,n),event:r,outputs:i});return yield*ef(e,a,o)}),Yf=wt(function*(e,t,n,r,i,a){if(!t.active.has(n))return;if(i.has(n))return{path:n,output:i.get(n),isNew:!1};let o=X(e,n);if(o.type===`compound`){let o=Hf(e,t,n);if(o===void 0||(n===``?Wf(e,o):!Uf(e,o)))return;let s=yield*Yf(e,t,o,r,i,a);if(s===void 0)return;let c=qf(i,n,s.output);return c.isNew&&a.push(c),c}if(o.type===`parallel`){let s={},c=!0;for(let n of o.children){let o=yield*Yf(e,t,n,r,i,a);o===void 0?c=!1:s[X(e,n).key]=o.output}if(!c)return;let l=qf(i,n,yield*Jf(e,t,n,r,s));return l.isNew&&a.push(l),l}if(!Uf(e,n))return;let s=qf(i,n,yield*Jf(e,t,n,r));return s.isNew&&a.push(s),s}),Xf=wt(function*(e,t,n){let r=new Map(t.outputs),i=[],a={active:t.active,values:t.values,outputs:r,history:t.history};for(let t of Array.from(a.active).sort((t,n)=>{let r=pf(e,n)-pf(e,t);return r===0?mf(e,t,n):r}))yield*Yf(e,a,t,n,r,i);return{configuration:a,completions:i}}),Zf=(e,t,n,r,i)=>{let a=X(e,n),o=Vf(e,n)?.output?.({state:t.values.get(n),containingState:xf(e,t,n),ancestors:bf(e,t,n),event:r,outputs:i});return tf(e,a,o)},Qf=(e,t,n,r,i,a)=>{if(!t.active.has(n))return;if(i.has(n))return{path:n,output:i.get(n),isNew:!1};let o=X(e,n);if(o.type===`compound`){let o=Hf(e,t,n);if(o===void 0||(n===``?Wf(e,o):!Uf(e,o)))return;let s=Qf(e,t,o,r,i,a);if(s===void 0)return;let c=qf(i,n,s.output);return c.isNew&&a.push(c),c}if(o.type===`parallel`){let s={},c=!0;for(let n of o.children){let o=Qf(e,t,n,r,i,a);o===void 0?c=!1:s[X(e,n).key]=o.output}if(!c)return;let l=qf(i,n,Zf(e,t,n,r,s));return l.isNew&&a.push(l),l}if(!Uf(e,n))return;let s=qf(i,n,Zf(e,t,n,r));return s.isNew&&a.push(s),s},$f=(e,t,n)=>{let r=new Map(t.outputs),i=[],a={active:t.active,values:t.values,outputs:r,history:t.history};for(let t of Array.from(a.active).sort((t,n)=>{let r=pf(e,n)-pf(e,t);return r===0?mf(e,t,n):r}))Qf(e,a,t,n,r,i);return{configuration:a,completions:i}},ep=e=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine construction must be an object`);return e},tp=(e,t)=>{if(t.decoded!==void 0&&typeof t.decoded!=`boolean`)throw Error(`Machine decoded construction flag must be a boolean`);if(e.schema===void 0){if(Object.hasOwn(t,`data`)||Object.hasOwn(t,`decoded`))throw Error(`Machine structural state "${e.path}" cannot construct data`)}else{if(t.decoded===!0){if(!Object.hasOwn(t,`data`))throw Error(`Machine decoded construction requires data`);return t.data}return fd(Object.hasOwn(t,`data`)?t.data:{})}},np=(e,t,n={},r)=>{let i=e.byPath.get(t);if(i?.type===`atomic`||i?.type===`final`){let e=ep(n);if(Reflect.ownKeys(e).some(e=>e!==`data`&&e!==`decoded`))throw Error(`Machine leaf construction accepts only data and decoded`);return ud(t,tp(i,e))}let a=new Map,o=(t,n)=>{let i=ep(n);if(Reflect.ownKeys(i).some(e=>e!==`data`&&e!==`decoded`&&e!==`states`))throw Error(`Machine state construction accepts only data, decoded, and states`);let s=e.byPath.get(t);if(s===void 0||s.type===`history`)throw Error(`Machine invalid construction state "${t}"`);let c=tp(s,i);if(Object.hasOwn(i,`states`)){if(s.type!==`compound`&&s.type!==`parallel`)throw Error(`Machine state "${t}" has no child construction`);let n=ep(i.states),c=Reflect.ownKeys(n),l=s.children.filter(t=>e.byPath.get(t)?.type!==`history`);if(s.type===`compound`?c.length!==1:c.length!==l.length&&(c.length!==1||r===void 0||r!==t&&!r.startsWith(`${t}.`)))throw Error(`Machine explicit states for "${t}" must select ${s.type===`compound`?`one child`:`every region`}`);for(let r of c){let i=t===``?String(r):`${t}.${String(r)}`;if(typeof r!=`string`||e.byPath.get(i)?.parent!==t||e.byPath.get(i)?.type===`history`)throw Error(`Machine unknown child "${String(r)}"`);a.set(i,o(i,n[r]))}}return c},s=o(t,n),c=new Map(a);c.set(t,s);let l=t,u=ep(n);for(;u.states!==void 0;){let t=e.byPath.get(l),n=ep(u.states),i=Object.keys(n);if(i.length!==1||t.type===`parallel`&&(r===void 0||r!==l&&!r.startsWith(`${l}.`)))break;let a=i[0];l=l===``?a:`${l}.${a}`,u=ep(n[a])}let d=e.byPath.get(l),f=c.get(l),p=Object.fromEntries([...c].filter(([e,t])=>t!==void 0&&e!==l&&!e.startsWith(`${l}.`)));if(d.type===`choice`)return rd(l,d.parent??``,p);if(d.type===`atomic`||d.type===`final`)return ud(l,f,{values:p});let m=new Map([...a].filter(([e])=>e.startsWith(`${l}.`)));return{...td(l,f,p),...m.size===0?{}:{children:m}}},rp=(e,t,n)=>{let r=ep(n);if(Reflect.ownKeys(r).some(e=>e!==`data`&&e!==`decoded`))throw Error(`Machine update construction accepts only data and decoded`);let i=e.byPath.get(t);if(i?.schema===void 0)throw Error(`Machine update requires a valued state`);return Vu(t,tp(i,r))},ip=(e,t,n=``)=>{let r=ep(t),i=e.byPath.get(n);np(e,n,r);let a=tp(i,r);if(i.type===`choice`)return rd(n,i.parent);if(i.type===`atomic`||i.type===`final`)return{path:n,value:a};if(r.states===void 0)throw Error(`Machine history fallback requires a complete explicit tree`);let o=ep(r.states),s=Object.fromEntries(Object.entries(o).map(([t,r])=>[t,ip(e,r,n===``?t:`${n}.${t}`)]));return i.type===`parallel`?{path:n,value:a,states:s}:{path:n,value:a,state:Object.values(s)[0]}},ap=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(t);return e},op=`root`,sp=e=>{let t=new Map,n=(e,r)=>{let i=!j(e)&&`type`in e?e.type:void 0;if(t.set(r,i===`history`||i===`choice`?i:`state`),!j(e)&&`states`in e)for(let[t,i]of Object.entries(e.states))n(i,r===``?t:`${r}.${t}`)};if(n(e.node,``),t.has(`root`))throw Error(`Machine top-level state name "${op}" is reserved for the root`);return t},cp=(e,t)=>{let n=sp(e),r=t.input!==void 0,i=new Map;for(let e of[`effects`,`streams`,`timers`,`logic`,`children`])if(t[e]!==void 0)for(let[n,r]of Object.entries(ap(t[e],`Machine ${e} must be a source map`))){if(i.has(n))throw Error(`Machine source name "${n}" is registered more than once`);i.set(n,Object.freeze({kind:e,value:r}))}let a=new Map;if(t.branches!==void 0)for(let[o,s]of Object.entries(ap(t.branches,`Machine branches must be a map`))){let t=ap(s,`Machine branches "${o}" must be a branch record`);for(let e of Reflect.ownKeys(t)){if(typeof e!=`string`)throw Error(`Machine branches cannot use symbol keys`);if(e.length===0||String(Number(e))===e)throw Error(`Machine branches require non-index string branch keys`)}let c=Object.entries(t);if(c.length===0)throw Error(`Machine branches "${o}" requires a branch`);a.set(o,Object.freeze(Object.fromEntries(c.map(([t,s])=>{let c={...ap(s,`Machine branch "${o}.${t}" must be a declaration`)};for(let e of Reflect.ownKeys(c))if(typeof e!=`string`||![`target`,`update`,`history`,`none`,`initialize`,`title`].includes(e))throw Error(`Machine branch "${o}.${t}" contains an unknown declaration field`);if(c.initialize!==void 0&&c.initialize!==!0)throw Error(`Machine branch "${o}.${t}" declares initialize: true; its resolver supplies input`);if(c.title!==void 0&&(typeof c.title!=`string`||c.title.length===0))throw Error(`Machine branch title must be a non-empty string`);return up({root:e,input:r,paths:n,sources:i,branches:a},c),[t,Object.freeze(c)]}))))}return{root:e,input:r,paths:n,sources:i,branches:a}},lp=(e,t)=>{let n=e===`root`?``:typeof e==`string`&&e!==``?e:void 0,r=n===void 0?void 0:t.paths.get(n);if(n===void 0||r===void 0)throw Error(`Machine target ${String(e)} is not a declared state path`);return{path:n,kind:r}},up=(e,t)=>{let n=[`target`,`history`,`none`,`initialize`].filter(e=>t[e]!==void 0);if(n.length===0&&t.update!==void 0){let n=lp(t.update,e);if(n.kind!==`state`)throw Error(`Machine update requires an active state reference`);return Ru(`update`,n.path,`branch`)}if(n.length!==1)throw Error(`Machine transition must declare exactly one destination operation`);let r=n[0];if(r===`none`){if(t.none!==!0||t.update!==void 0)throw Error(`Machine targetless transition requires none: true`);return zu}if(r===`initialize`){if(t.update!==void 0)throw Error(`Machine initialize cannot update a retained owner`);return Ru(`state`,``,`branch`)}let i=lp(t[r],e);if(r===`target`&&i.path===``)throw Error(`Machine root is not a destination; use initialize to reconstruct it from machine input`);if(r===`history`!=(i.kind===`history`))throw Error(`Machine history references require a history transition`);let a=t.update===void 0?void 0:lp(t.update,e).path;if(a!==void 0&&r!==`target`)throw Error(`Machine owner updates require an ordinary destination`);return Ru(i.kind,i.path,r===`history`?`full`:`branch`,a)},dp=(e,t,n,r)=>{let i=ap(t,`Machine invocation for "${n}" must be an object`),a=typeof i.src==`string`?e.sources.get(i.src):void 0;if(a===void 0)throw Error(`Machine invocation for "${n}" names an unknown source`);let{src:o,input:s,...c}=i,l=typeof s==`function`?e=>s(r(e)):s;if(a.kind===`children`)return{...c,child:a.value,...l===void 0?{}:{input:l}};let u=typeof a.value==`function`&&!(a.kind===`effects`&&rt(a.value))&&!(a.kind===`streams`&&p(a.value));if(u!==(typeof l==`function`))throw Error(`Machine invocation "${o}" requires input exactly when its source takes an argument`);let d=u?e=>a.value(l(e)):()=>a.value,f={effects:`effect`,streams:`stream`,timers:`after`,logic:`logic`}[a.kind];return{...c,sourceName:o,id:c.id??o,[f]:!u&&(a.kind===`timers`||a.kind===`logic`)?a.value:d}},fp=Symbol(`effect/Machine/InitialEvent`),pp=Symbol(`effect/Machine/SnapshotBuilderState`),mp=Symbol(`effect/Machine/ChildMachineLogic`),hp=new WeakSet,gp=e=>hp.has(e),_p=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine ${t} must be an object`);return e},vp=e=>typeof e==`function`?e:()=>e,yp=e=>{if(typeof e==`object`&&e&&N(e,`decoded`)&&e.decoded===!0&&N(e,`data`)){let t=_p(e,`decoded construction`);if(Reflect.ownKeys(t).some(e=>e!==`decoded`&&e!==`data`))throw Error(`Machine decoded construction accepts only decoded and data`);return vp(t.data)}let t=vp(e);return n=>fd(e===void 0?{}:t(n))},bp=e=>{if(e.decoded!==void 0&&typeof e.decoded!=`boolean`)throw Error(`Machine decoded construction flag must be a boolean`);if(e.decoded===!0){if(!N(e,`data`))throw Error(`Machine decoded construction requires data`);return vp(e.data)}let t=vp(e.data);return n=>fd(N(e,`data`)?t(n):{})},xp=(e,t)=>{let n=(e,t,r)=>{if(N(t,`initialize`))throw Error(`Machine child construction belongs in initial declarations`);if(r!==``&&N(t,`root`))throw Error(`Machine root construction belongs at the root handler`);let{initial:i,root:a,states:o,...s}=t;if(j(e)||!(`states`in e)){if(i!==void 0)throw Error(`Machine state "${r}" cannot declare initial children`);if(o!==void 0)throw Error(`Machine state "${r}" has no children`);return{node:e,handlers:s}}let c=o===void 0?{}:_p(o,`child handlers`);for(let t of Object.keys(c))if(!Object.prototype.hasOwnProperty.call(e.states,t))throw Error(`Machine unknown child "${t}"`);let l=Object.create(null),u=Object.create(null),d=Object.create(null),f=e.type===`parallel`,p;if(f){let t=i===void 0?{}:_p(i,`parallel initial regions`);for(let[n,r]of Object.entries(t)){let t=e.states[n];if(t===void 0||!j(t)&&(t.type===`history`||t.type===`choice`))throw Error(`Machine invalid initial region "${n}"`);if(!j(t)&&(!(`schema`in t)||t.schema===void 0))throw Error(`Machine schema-less region "${n}" cannot construct data`);d[n]=yp(r)}}else{let t=_p(i,`initial edge for "${r}"`);if(Reflect.ownKeys(t).some(e=>![`target`,`data`,`decoded`].includes(String(e))))throw Error(`Machine initial edge accepts only target, data, and decoded`);let n=r===``?``:`${r}.`,a=typeof t.target==`string`&&t.target.startsWith(n)?t.target.slice(n.length):void 0,o=a===void 0||!Object.hasOwn(e.states,a)?void 0:e.states[a],s=o===void 0||j(o)?`state`:o.type;if(a===void 0||o===void 0||s===`history`)throw Error(`Machine initial target must be a direct child of "${r===``?`root`:r}"`);if(p=a,s===`choice`&&(N(t,`data`)||N(t,`decoded`)))throw Error(`Machine choice initial edges cannot construct data`);let c=bp(t),l=e.states[a];if(N(t,`data`)&&!j(l)&&(!(`schema`in l)||l.schema===void 0))throw Error(`Machine schema-less initial child "${a}" cannot construct data`);N(t,`data`)&&(d[a]=c)}for(let[t,i]of Object.entries(e.states)){let e=r===``?t:`${r}.${t}`,a=n(i,c[t]===void 0?{}:_p(c[t],`state handler`),e);l[t]=a.node,(j(i)||i.type!==`history`)&&(c[t]!==void 0||!j(i)&&`states`in i)&&(u[t]=a.handlers)}let m=Object.freeze({...e,states:Object.freeze(l),...f?{}:{initial:p}}),h=Object.entries(d),g=e=>{let t=typeof e.ancestors==`object`&&e.ancestors!==null?e.ancestors:{},n={...e,root:r===``?e.state:t[``]},i=Object.fromEntries(h.map(([e,t])=>[e,t(n)]));return{[pp]:i}};return hp.add(g),{node:m,handlers:{...s,...h.length===0?{}:{initialize:g},states:u}}};return n(e.node,t,``)},Sp=(e,t)=>{let n=[`effect`,`stream`,`after`,`logic`,`child`].filter(t=>t in e);if(n.length!==1)throw Error(`Machine invocation for state "${t}" must define exactly one source`);if(n[0]!==`child`&&typeof e.id!=`string`)throw Error(`Machine invocation for state "${t}" requires a string id`);if((n[0]===`effect`||n[0]===`stream`)&&typeof e[n[0]]!=`function`)throw Error(`Machine invocation for state "${t}" requires a source callback`);return Object.freeze(e)},Cp=e=>`child`in e?e.child.id:e.id,wp=(e,t)=>{let n=new Set;for(let r of e){let e=Cp(r);if(n.has(e))throw Error(`Machine invocations for state "${t}" must have distinct ids; "${e}" is declared twice`);n.add(e)}},Tp=e=>e===void 0?[]:Array.isArray(e)?e:[e],Ep=e=>{let t=[],n=[],r=[];return{commands:t,raisedEvents:n,emittedEvents:r,enqueue:{raise:t=>{n.push(Jd(e,t))},emit:t=>{r.push(Xd(e,t))},sendTo:(e,n)=>{t.push({_tag:`SendTo`,target:e,event:n})},stop:e=>{t.push({_tag:`Stop`,child:e})}}}},Dp=(e,t)=>{let n=e.stateNodes.byPath.get(t);if(n===void 0)throw Error(`Machine expected state path "${t}" to exist`);return n},Op=e=>{let t={};return Object.defineProperty(t,"decoded",{value:e,enumerable:!1}),Object.defineProperty(t,"from",{value:(...t)=>e(fd(t.length===0?{}:t[0])),enumerable:!1}),t},kp=e=>{let t={};return Object.defineProperty(t,pp,{value:e,enumerable:!1}),t},Ap=(e,t,n)=>{let r=kp(n);for(let i of t.children){let a=Dp(e,i);a.schema===void 0||N(n,a.key)||(r[a.key]=Op(r=>{let i=Object.assign({},n);return i[a.key]=r,Ap(e,t,i)}))}return r},jp=(e,t)=>{let n=Dp(e,t);if(n.type===`parallel`)return Ap(e,n,{});if(n.type!==`compound`)throw Error(`Machine state "${t}" cannot initialize child states`);let r=Dp(e,n.initial);if(r.schema===void 0)throw Error(`Machine state "${t}" has no schema-valued initial child`);return Op(e=>kp({[r.key]:e}))},Mp=(e,t)=>{if(typeof t!=`object`||!t||!N(t,pp))throw Error(`Machine initialize handler for "${e}" must return its builder result`);return t[pp]},Np=Symbol(`effect/Machine/InvocationEvent`),Pp=(e,t,n)=>({[Np]:!0,path:e,id:t,type:`done`,output:n}),Fp=(e,t,n)=>({[Np]:!0,path:e,id:t,type:`element`,element:n}),Ip=(e,t,n)=>({[Np]:!0,path:e,id:t,type:`failure`,error:n}),Lp=(e,t,n)=>({[Np]:!0,path:e,id:t,type:`snapshot`,snapshot:n}),Rp=e=>typeof e==`object`&&!!e&&Np in e,zp=new WeakMap,Bp=new WeakMap,Vp=(e,t)=>e.parent===void 0?{self:t.self}:{self:t.self,parent:t.parent},Hp=(e,t)=>{let n=Object.create(e);return Bp.set(n,Vp(e,t)),n},Up=(e,t)=>{let n=t.machineReferences;if(n!==void 0)return Vp(e,n);let r=Bp.get(e);if(r!==void 0)return r;let i=zp.get(e);if(i!==void 0)return i;let a=Vp(e,{self:{id:e.id??`Machine`,sessionId:`Machine.plan`,send:()=>W(new Su)},parent:void 0});return zp.set(e,a),a},Wp=e=>{if(e!==void 0)return typeof e==`function`?{reenter:!1,declinable:!1,targets:void 0,transition:e,evaluate:void 0}:{reenter:e.reenter===!0,declinable:e.declinable===!0,targets:e.targets,transition:e.transition,evaluate:e.evaluate}},Gp=(e,t,n)=>{let r=Ep(e);return t===void 0||t(n,r.enqueue),{commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents}},Kp=(e,t,n,r)=>{let i=Ep(e),a=r===void 0?{result:t(n,i.enqueue),branchIndex:0,branchKey:void 0}:r(n,i.enqueue);return Qu(a.result)?{declined:!0}:{declined:!1,state:Yu(a.result)?void 0:a.result,branchIndex:a.branchIndex,branchKey:a.branchKey,commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents}},qp=(e,t,n)=>{let r=Ep(e);return{value:t(n,r.enqueue),commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents}},Jp=(e,t,n,r)=>{let i=new Set(t.active),a=new Map(t.values),o=[],s=[],c=[],l=[],u=!0;for(;u;){u=!1;for(let d of Array.from(i).sort((t,n)=>mf(e,t,n))){let f=X(e,d);if(f.type===`compound`&&!f.children.some(e=>i.has(e))){if(f.initial===void 0)throw Error(`Machine shallow history expected compound state "${d}" to have an initial child`);let p=X(e,f.initial),m={active:i,values:a,outputs:t.outputs,history:t.history,machineReferences:t.machineReferences};if(p.type===`choice`){let t=wm(e,m,rd(p.path,d,Object.fromEntries(a)),n),r=m;for(let i of[t.target,...t.additionalTargets]){if(i===void 0)throw Error(`Machine initial choice "${p.path}" must resolve to an active state target`);let t=nd(i)?Xp(e,r,i,n):ed(i)?Zp(e,r,i,n):void 0;r=Bf(e,r,t?.target??i),t!==void 0&&(o.push(...t.commands),s.push(...t.raisedEvents),c.push(...t.emittedEvents),l.push(...t.transitions))}i.clear(),a.clear();for(let e of r.active)i.add(e);for(let[e,t]of r.values)a.set(e,t);o.push(...t.commands),s.push(...t.raisedEvents),c.push(...t.emittedEvents),l.push(...t.transitions),u=!0;continue}if(i.add(p.path),p.schema!==void 0){let t=Y(e).handlers[d]?.initialize;if(t===void 0){a.set(p.path,$d(e,p,fd({}))),u=!0;continue}let i=qp(e,t,{...Up(e,m),state:m.values.get(d),containingState:xf(e,m,d),ancestors:bf(e,m,d),event:n,...d===``&&r!==void 0?{input:r.value}:{},...gp(t)?{}:{builder:jp(e,d)}}),l=Mp(d,i.value);a.set(p.path,$d(e,p,l[p.key])),o.push(...i.commands),s.push(...i.raisedEvents),c.push(...i.emittedEvents)}u=!0}if(f.type===`parallel`){let l=f.children.filter(e=>!i.has(e));if(l.length>0){let f=l.filter(t=>X(e,t).schema!==void 0),p={active:i,values:a,outputs:t.outputs,history:t.history,machineReferences:t.machineReferences},m=f.length===0?void 0:Y(e).handlers[d]?.initialize,h=m===void 0?void 0:qp(e,m,{...Up(e,p),state:p.values.get(d),containingState:xf(e,p,d),ancestors:bf(e,p,d),event:n,...d===``&&r!==void 0?{input:r.value}:{},...gp(m)?{}:{builder:jp(e,d)}}),g=h===void 0?void 0:Mp(d,h.value);for(let t of l){let n=X(e,t);if(i.add(n.path),n.schema!==void 0){if(h===void 0){a.set(n.path,$d(e,n,fd({})));continue}if(g===void 0||!Object.prototype.hasOwnProperty.call(g,n.key)){if(m!==void 0&&gp(m)){a.set(n.path,$d(e,n,fd({})));continue}throw Error(`Machine parallel state initializer for "${d}" must return region "${n.key}"`)}a.set(n.path,$d(e,n,g[n.key]))}}h!==void 0&&(o.push(...h.commands),s.push(...h.raisedEvents),c.push(...h.emittedEvents)),u=!0}}}}return{configuration:{active:i,values:a,outputs:new Map,history:t.history},commands:o,raisedEvents:s,emittedEvents:c,transitions:l}};function Yp(e,t,n,r){let i=Rf(e,t,n);if(n.children===void 0||![...n.children.keys()].some(t=>X(e,t).type===`choice`))return Jp(e,i,r,n.input);let a=[],o=[],s=[],c=[];for(let t of n.children?.keys()??[]){let n=X(e,t);if(n.type!==`choice`)continue;let l=wm(e,i,rd(t,n.parent),r);for(let t of[l.target,...l.additionalTargets]){let n=nd(t)?Xp(e,i,t,r):ed(t)?Zp(e,i,t,r):void 0;i=Bf(e,i,n?.target??t),n!==void 0&&(a.push(...n.commands),o.push(...n.raisedEvents),s.push(...n.emittedEvents),c.push(...n.transitions))}a.push(...l.commands),o.push(...l.raisedEvents),s.push(...l.emittedEvents),c.push(...l.transitions)}let l=Jp(e,i,r,n.input);return c.length===0?l:{...l,commands:[...a,...l.commands],raisedEvents:[...o,...l.raisedEvents],emittedEvents:[...s,...l.emittedEvents],transitions:[...c,...l.transitions]}}function Xp(e,t,n,r){let i=Yp(e,t,n,r),a=Tf(e,i.configuration,n.path);return{target:ud(n.path,a.value,{snapshot:a,values:n.values}),commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents,transitions:i.transitions}}function Zp(e,t,n,r){let i=X(e,n.path);if(i.type!==`history`||i.parent!==n.parent)throw Error(`Machine expected history target "${n.path}" to resolve to its declared parent`);let a=Ff(t,n.path);if(a!==void 0){let i=Jp(e,If(e,t,a),r),o=Tf(e,i.configuration,n.parent),s=Object.fromEntries(i.configuration.values);return n.parent!==``&&t.active.has(``)&&delete s[``],{target:ud(n.parent,o.value,{snapshot:o,values:s}),commands:i.commands,raisedEvents:i.raisedEvents,emittedEvents:i.emittedEvents,transitions:i.transitions}}let o=i.key,s=Y(e).handlers[n.parent]?.history?.[o]?.default;if(s===void 0)throw Error(`Machine history state "${n.path}" requires a default implementation`);let c=Kp(e,s,{event:r,target:t=>ip(e.stateNodes,t),owner:n.parent});if(c.state===void 0||ed(c.state)||!md(c.state))throw Error(`Machine history default for "${n.path}" must return a complete snapshot containing its owner`);let l=Sm(c.state)===void 0?void 0:wm(e,{active:new Set,values:new Map,outputs:new Map,history:t.history},c.state,r),u=l===void 0?jf(e,c.state):Bf(e,{active:new Set,values:new Map,outputs:new Map,history:t.history},l.target);for(let t of l?.additionalTargets??[])u=Bf(e,u,t);if(!u.active.has(n.parent))throw Error(`Machine history default for "${n.path}" returned a configuration that does not contain owner state "${n.parent}"`);let d=Tf(e,u,n.parent),f=Object.fromEntries(u.values);return n.parent!==``&&t.active.has(``)&&delete f[``],{target:ud(n.parent,d.value,{snapshot:d,values:f}),commands:[...c.commands,...l?.commands??[]],raisedEvents:[...c.raisedEvents,...l?.raisedEvents??[]],emittedEvents:[...c.emittedEvents,...l?.emittedEvents??[]],transitions:l?.transitions??[]}}var Qp=(e,t)=>{if(!t.transition.declinable)return t;let n=Kp(e,t.transition.transition,t.context,t.transition.evaluate);return n.declined?void 0:{...t,collected:n}},$p=(e,t)=>[...Z(e,t)].reverse(),em=(e,t,n)=>{let r=Z(e,t),i=Z(e,n),a,o=Math.min(r.length,i.length);for(let e=0;e<o&&r[e]===i[e];e++)a=r[e];return a},tm=(e,t)=>{if(e!==void 0&&t!==void 0)return e===t||df(e,t)?t:e},nm=(e,t,n)=>am(e,Array.from(t.active).filter(e=>n===void 0||df(e,n))),rm=(e,t,n)=>om(e,Array.from(t.active).filter(e=>n===void 0||df(e,n))),im=(e,t)=>e.active.size===t.active.size&&Array.from(e.active).every(e=>t.active.has(e)),am=(e,t)=>Array.from(new Set(t)).sort((t,n)=>{let r=Z(e,n).length-Z(e,t).length;return r===0?X(e,n).order-X(e,t).order:r}),om=(e,t)=>Array.from(new Set(t)).sort((t,n)=>{let r=Z(e,t).length-Z(e,n).length;return r===0?mf(e,t,n):r}),sm=(e,t,n,r)=>({...Up(e,t),state:t.values.get(n),containingState:xf(e,t,n),ancestors:bf(e,t,n),event:r}),cm=(e,t,n,r,i)=>({...Up(e,t),state:t.values.get(n),containingState:xf(e,t,n),ancestors:bf(e,t,n),event:r,snapshot:i}),lm=(e,t,n,r,i,a)=>({...Up(e,t),state:t.values.get(n),containingState:xf(e,t,n),ancestors:bf(e,t,n),event:r,output:i,snapshot:a}),um=(e,t,n,r,i)=>{let a=[],o=[],s=[];for(let c of n){let n=Gp(e,Y(e).handlers[c]?.[i],sm(e,t,c,r));a.push(...n.commands),o.push(...n.raisedEvents),s.push(...n.emittedEvents)}return{commands:a,emittedEvents:s,raisedEvents:o}},dm=(e,t,n)=>{let r=[],i=new Set,a=new Map,o,s=()=>o??=wf(e,t);for(let o of gf(e,t))for(let c of $p(e,o)){let l=Wp(Y(e).handlers[c]?.always);if(l!==void 0){let u=a.get(c);if(a.has(c)||(u=Qp(e,{sourcePath:c,leafPath:o,trigger:{type:`always`},transition:l,context:{...Up(e,t),state:t.values.get(c),containingState:xf(e,t,c),ancestors:bf(e,t,c),event:n,snapshot:s()}}),a.set(c,u)),u===void 0)continue;i.has(c)||(i.add(c),r.push(u));break}}return r},fm=(e,t,n,r)=>{let i=[],a=new Set,o,s=()=>o??=wf(e,t);for(let o of r){let r=Wp(Y(e).handlers[o.path]?.onDone);if(r!==void 0&&!a.has(o.path)){a.add(o.path);let c=Qp(e,{sourcePath:o.path,leafPath:vf(e,t,o.path),trigger:{type:`done`},transition:r,context:lm(e,t,o.path,n,o.output,s())});c!==void 0&&i.push(c)}}return i},pm=(e,t,n)=>{let r=[],i=new Set,a=new Map,o,s=()=>o??=wf(e,t);for(let o of gf(e,t))for(let c of $p(e,o)){let l=Wp(Y(e).handlers[c]?.on?.[n._tag]);if(l!==void 0){let u=a.get(c);if(a.has(c)||(u=Qp(e,{sourcePath:c,leafPath:o,trigger:{type:`event`,event:n._tag},transition:l,context:cm(e,t,c,n,s())}),a.set(c,u)),u===void 0)continue;i.has(c)||(i.add(c),r.push(u));break}}return r},mm=(e,t,n)=>{if(!t.active.has(n.path))return[];let r=Y(e).handlers[n.path],i=Tp(r?.invoke).find(e=>{let t=`child`in e?e.child?.id:e.id;return String(t)===n.id});if(i===void 0)return[];let a=Wp(n.type===`element`?i.onElement:n.type===`done`?i.onDone:n.type===`failure`?i.onFailure:i.onSnapshot);if(a===void 0)return[];let o=wf(e,t),s={...Up(e,t),state:t.values.get(n.path),containingState:xf(e,t,n.path),ancestors:bf(e,t,n.path),snapshot:o,id:n.id,...n.type===`element`?{element:n.element}:n.type===`done`?{output:n.output}:n.type===`failure`?{error:n.error}:{snapshot:n.snapshot}},c=Qp(e,{sourcePath:n.path,leafPath:vf(e,t,n.path),trigger:{type:`invoke`,id:n.id,outcome:n.type},transition:a,context:s});return c===void 0?[]:[c]},hm=e=>{if(ed(e)||id(e)||dd(e)||md(e))return String(e.path);throw Error(`Machine expected transition target to be a snapshot or target builder result`)},gm=(e,t,n,r)=>{if(n===void 0||r===void 0)return;let i=typeof r==`object`&&r&&`path`in r?String(r.path):`<unknown>`;if(!n.some(e=>i===e||e===``||i.startsWith(`${e}.`))){let r=t.type===`event`?String(t.event):t.type;throw Error(`Machine transition from "${e}" on "${r}" returned target "${i}" outside declared targets: ${n.length===0?`none`:n.map(e=>`"${e}"`).join(`, `)}`)}},_m=(e,t)=>{for(let n of e)if(t.includes(n))return!0;return!1},vm=(e,t)=>Array.from(t).sort((t,n)=>mf(e,t.selection.sourcePath,n.selection.sourcePath)),ym=e=>e.filter(t=>!e.some(e=>e.sourcePath!==t.sourcePath&&df(e.sourcePath,t.sourcePath))),bm=(e,t)=>{let n=[];for(let r of vm(e,t)){let e=!1,t=new Set;for(let i of n){let n=r.update!==void 0&&i.update!==void 0&&r.update.path===i.update.path;if(_m(r.exitPaths,i.exitPaths)||n){if(df(r.selection.sourcePath,i.selection.sourcePath))t.add(i);else{e=!0;break}}}if(!e){for(let e of t){let t=n.indexOf(e);t>=0&&n.splice(t,1)}n.push(r)}}return n},xm=(e,t={})=>{let n={...t},r=[],i=e=>{if(id(e))Object.assign(n,e.values??{}),r.push(e);else if(typeof e==`object`&&e&&`path`in e&&`value`in e&&(e.value!==void 0&&(n[String(e.path)]=e.value),`state`in e&&i(e.state),`states`in e&&typeof e.states==`object`&&e.states!==null))for(let t of Object.values(e.states))i(t)};return i(e),r.map(e=>({target:rd(e.path,e.parent,n),values:n}))},Sm=(e,t={})=>xm(e,t)[0],Cm=(e,t)=>{if(id(e))return rd(e.path,e.parent,{...t,...e.values??{}});if(nd(e))return{...e,values:{...t,...e.values}};if(!dd(e)||Object.keys(t).length===0)return e;let n=e[Du];return ud(e.path,e.value,{...n===void 0?{}:{snapshot:n},values:{...t,...e.values??{}}})};function wm(e,t,n,r){let i=[n],a=[],o=[],s=[],c=[],l=[],u=0;for(;i.length>0;){let n=i.shift();for(;;){let a=xm(n),d=a[0];if(d===void 0)break;if(i.unshift(...a.slice(1).map(({target:e})=>e)),u+=1,u>1e3)throw new yu({machineId:e.id,state:d.target.path,maxIterations:Em});let f=X(e,d.target.path);if(f.type!==`choice`||f.parent!==d.target.parent)throw Error(`Machine expected choice target "${d.target.path}" to resolve to its declared parent`);let p=Y(e).handlers[f.path]?.choice;if(p===void 0||typeof p.transition!=`function`)throw Error(`Machine choice state "${f.path}" requires an implementation`);let m=new Map(t.values);for(let[t,n]of Object.entries(d.values)){let r=X(e,t);r.schema!==void 0&&m.set(t,$d(e,r,n))}let h={active:new Set([...t.active,...Object.keys(d.values)]),values:m,outputs:t.outputs,history:t.history,...t.machineReferences===void 0?{}:{machineReferences:t.machineReferences}},g=Kp(e,p.transition,{...Up(e,h),containingState:xf(e,h,f.path),ancestors:bf(e,h,f.path),event:r},p.evaluate);if(g.state===void 0)throw Error(`Machine choice resolver for "${f.path}" must return a target`);gm(f.path,{type:`choice`},p.targets,g.state);let _=hm(g.state);n=Cm(g.state,d.values);let v=Sm(n);l.push({source:f.path,trigger:{type:`choice`},reenter:!1,branchIndex:g.branchIndex,branchKey:g.branchKey,target:_,resolvedTarget:v?.target.path??_,updates:[]}),o.push(...g.commands),s.push(...g.raisedEvents),c.push(...g.emittedEvents)}if(!dd(n)&&!md(n)&&!ed(n)&&!nd(n))throw Error(`Machine choice resolver must return a concrete typed target`);a.push(n)}return{target:a[0],additionalTargets:a.slice(1),commands:o,raisedEvents:s,emittedEvents:c,transitions:l}}var Tm=(e,t,n)=>{let r=n.leafPath,i=n.collected??Kp(e,n.transition.transition,n.context,n.transition.evaluate);if(i.declined)throw Error(`Machine transition returned decline without declaring declinable: true`);let a=Wu(i.state)?i.state:void 0,o=a?.target??i.state,s=o===void 0||Hu(o)?void 0:o;gm(n.sourcePath,n.trigger,n.transition.targets,s);let c=a?.update??(Hu(o)?o:void 0),l=c===void 0?void 0:(()=>{let n=X(e,c.path);if(!t.active.has(n.path)||n.schema===void 0)throw Error(`Machine state update owner "${n.path}" must be an active valued state`);return{path:n.path,value:$d(e,n,c.value)}})(),u=l!==void 0&&(nd(s)||id(s))?{...t,values:new Map(t.values).set(l.path,l.value)}:t,d=s===void 0?void 0:wm(e,u,s,n.context.event),f=d?.target??s,p=f!==void 0&&nd(f)?Xp(e,u,f,n.context.event):void 0,m=p?.target??f,h,g=ed(m)&&n.transition.reenter&&t.active.has(m.parent)?m:void 0;if(m!==void 0&&ed(m)){let i=n.transition.reenter?X(e,n.sourcePath).parent:em(e,r,m.parent),a=g===void 0?nm(e,t,i):am(e,Array.from(t.active).filter(e=>ff(e,m.parent)));h=Zp(e,a.includes(m.parent)?Pf(e,t,t,a):t,m,n.context.event)}let _=h===void 0?m:h.target,v=[],y=[],b=[],x=[],S=[];for(let r of d?.additionalTargets??[]){if(nd(r)){let i=Xp(e,t,r,n.context.event);S.push(i.target),v.push(...i.commands),y.push(...i.raisedEvents),b.push(...i.emittedEvents),x.push(...i.transitions);continue}if(!ed(r)){S.push(r);continue}let i=Zp(e,t,r,n.context.event);S.push(i.target),v.push(...i.commands),y.push(...i.raisedEvents),b.push(...i.emittedEvents),x.push(...i.transitions)}let C=_===void 0?void 0:S.length===0||s===void 0?hm(_):hm(s),w=_===void 0?l===void 0?t:{...t,values:new Map(t.values).set(l.path,l.value)}:Bf(e,t,_);for(let t of S)w=Bf(e,w,t);if(a!==void 0&&l!==void 0&&!w.active.has(l.path))throw Error(`Machine combined target exited its updating owner "${l.path}"`);l!==void 0&&(w={...w,values:new Map(w.values).set(l.path,l.value)});let ee=n.transition.reenter||!im(t,w),T=ee||l!==void 0;if(!ee)return{selection:n,branchIndex:i.branchIndex,branchKey:i.branchKey,unresolvedTarget:s,target:_,update:l,commands:[...i.commands,...d?.commands??[],...p?.commands??[],...h?.commands??[],...v],raisedEvents:[...i.raisedEvents,...d?.raisedEvents??[],...p?.raisedEvents??[],...h?.raisedEvents??[],...y],emittedEvents:[...i.emittedEvents,...d?.emittedEvents??[],...p?.emittedEvents??[],...h?.emittedEvents??[],...b],changed:ee,stabilize:T,exitPaths:[],entryPaths:[],choiceTransitions:[...d?.transitions??[],...p?.transitions??[],...h?.transitions??[],...x]};let te=C===void 0?X(e,n.sourcePath).parent:em(e,r,C),E=X(e,n.sourcePath).parent,ne=n.transition.reenter?tm(te,E):te;return{selection:n,branchIndex:i.branchIndex,branchKey:i.branchKey,unresolvedTarget:s,target:_,update:l,commands:[...i.commands,...d?.commands??[],...p?.commands??[],...h?.commands??[],...v],raisedEvents:[...i.raisedEvents,...d?.raisedEvents??[],...p?.raisedEvents??[],...h?.raisedEvents??[],...y],emittedEvents:[...i.emittedEvents,...d?.emittedEvents??[],...p?.emittedEvents??[],...h?.emittedEvents??[],...b],changed:ee,stabilize:T,exitPaths:g===void 0?nm(e,t,ne):am(e,Array.from(t.active).filter(e=>ff(e,g.parent))),entryPaths:g===void 0?rm(e,w,ne):om(e,Array.from(w.active).filter(e=>ff(e,g.parent))),choiceTransitions:[...d?.transitions??[],...p?.transitions??[],...h?.transitions??[],...x]}},Em=1e3,Dm={_tag:fp},Om=(e,t)=>Kf(e,Af(e,t)),km=(e,t,n)=>Nf(e,t).pipe(U(t=>Xf(e,t,n)),U(t=>{let n=yf(e,t.configuration);return!Kf(e,t.configuration)||!t.configuration.outputs.has(n)?Qn(Error(`Machine attempted to read terminal output from a non-terminal configuration`)):k(t.configuration.outputs.get(n))})),Am=(e,...t)=>{let n=e.input===void 0?t:t.length===0?(Zd(e,e.input,void 0),t):[Zd(e,e.input,t[0])],r=e.initial(...n),i={active:new Set,values:new Map,outputs:new Map,history:new Map},a=Xp(e,i,r,Dm),o=Bf(e,i,a.target),s=wf(e,o),c=Sf(e,o),l=a.commands,u=a.raisedEvents,d=a.emittedEvents,f=um(e,o,c,Dm,`entry`),p=Mm(e,o,Dm,[...f.commands],[...u,...f.raisedEvents],[...d,...f.emittedEvents],a.transitions.length===0?[]:[{next:o,event:Dm,transitions:a.transitions,commands:l,raisedEvents:[...u],emittedEvents:d,exitPaths:[],entryPaths:[],changed:!1,stabilize:!1}]),m={startingState:s,initialEntryPaths:c,state:wf(e,p.next),commands:[...l,...p.commands],emittedEvents:p.emittedEvents,microsteps:p.microsteps.map(t=>({next:wf(e,t.next),event:t.event,transitions:t.transitions,commands:t.commands,raisedEvents:t.raisedEvents,emittedEvents:t.emittedEvents,exitPaths:t.exitPaths,entryPaths:t.entryPaths,changed:t.changed}))};return p.done?{...m,done:!0,output:p.output}:{...m,done:!1,output:void 0}},jm=(e,t,n,r)=>{if(r.length===0)return{next:t,event:n,transitions:[],commands:[],raisedEvents:[],emittedEvents:[],exitPaths:[],entryPaths:[],changed:!1,stabilize:!1};let i=ym(r),a=[];for(let n of i)a.push(Tm(e,t,n));let o=bm(e,a),s=vm(e,o),c=s.flatMap(e=>[{source:e.selection.sourcePath,trigger:e.selection.trigger,reenter:e.selection.transition.reenter,branchIndex:e.branchIndex,branchKey:e.branchKey,target:e.unresolvedTarget===void 0?void 0:hm(e.unresolvedTarget),resolvedTarget:e.target===void 0?void 0:hm(e.target),updates:e.update===void 0?[]:[e.update.path]},...e.choiceTransitions]),l=t;for(let e of s)e.update!==void 0&&(l={...l,values:new Map(l.values).set(e.update.path,e.update.value)});let u=[...s.filter(e=>!e.changed),...s.filter(e=>e.changed)];for(let t of u)t.target!==void 0&&(l=Bf(e,l,t.target));let d=o.some(e=>e.changed),f=o.some(e=>e.stabilize),p=s.flatMap(e=>e.commands),m=s.flatMap(e=>e.raisedEvents),h=s.flatMap(e=>e.emittedEvents);if(!d)return{next:l,event:n,transitions:c,commands:p,raisedEvents:m,emittedEvents:h,exitPaths:[],entryPaths:[],changed:!1,stabilize:f};let g=am(e,s.flatMap(e=>e.exitPaths)),_=om(e,s.flatMap(e=>e.entryPaths));l=Pf(e,t,l,g);let v=um(e,t,g,n,`exit`),y=um(e,l,_,n,`entry`);return{next:l,event:n,transitions:c,commands:[...v.commands,...p,...y.commands],raisedEvents:[...v.raisedEvents,...m,...y.raisedEvents],emittedEvents:[...v.emittedEvents,...h,...y.emittedEvents],exitPaths:g,entryPaths:_,changed:!0,stabilize:f}},Mm=(e,t,n,r,i,a,o)=>{let s=t,c=n,l=!0,u=0,d=0,f=!1,p,m=[];for(;;){if(u+=1,u>1e3)throw new yu({machineId:e.id,state:String(_f(e,s)),maxIterations:Em});let t=$f(e,s,c);for(s=t.configuration,m.push(...t.completions.filter(t=>Y(e).handlers[t.path]?.onDone!==void 0));m.length>0&&!s.active.has(m[0].path);)m.shift();let n=fm(e,s,c,m.length===0?[]:[m.shift()]);if(n.length>0){let t=jm(e,s,c,n);r.push(...t.commands),i.push(...t.raisedEvents),a.push(...t.emittedEvents),o.push(t),s=t.next,l=t.stabilize;continue}if(Kf(e,s)){let t=yf(e,s);if(!s.outputs.has(t))throw Error(`Machine reached a terminal configuration without a completed root output`);f=!0,p=s.outputs.get(t);break}let h=l?dm(e,s,c):[];if(h.length>0){let t=jm(e,s,c,h);r.push(...t.commands),i.push(...t.raisedEvents),a.push(...t.emittedEvents),o.push(t),s=t.next,l=t.stabilize;continue}let g=i[d];if(g===void 0)break;d+=1;let _=g;c=_;let v=pm(e,s,_);if(v.length===0){l=!0;continue}let y=jm(e,s,_,v);r.push(...y.commands),i.push(...y.raisedEvents),a.push(...y.emittedEvents),o.push(y),s=y.next,l=!0}let h={next:s,commands:r,emittedEvents:a,microsteps:o};return f?{...h,done:!0,output:p}:{...h,done:!1,output:void 0}},Nm=(e,t,n)=>{let r=Rp(n)?n:Jd(e,n);if(Kf(e,t)){let n=$f(e,t,r),i=yf(e,n.configuration);if(!n.configuration.outputs.has(i))throw Error(`Machine reached a terminal configuration without a completed root output`);return{event:r,next:n.configuration,commands:[],emittedEvents:[],microsteps:[],done:!0,output:n.configuration.outputs.get(i)}}let i=Rp(r)?mm(e,t,r):pm(e,t,r);if(i.length===0)return{event:r,next:t,commands:[],emittedEvents:[],microsteps:[],done:!1,output:void 0};let a=jm(e,t,r,i),o=[...a.commands],s=[...a.raisedEvents],c=[...a.emittedEvents],l=[a];return{...Mm(e,a.next,r,o,s,c,l),event:r}},Pm=(e,...t)=>l({try:()=>Am(e,...t),catch:Tu}),Fm=(e,t)=>({raise:n=>qd(e,n).pipe(U(e=>t.sendTo(t.self,e))),emit:n=>Yd(e,n).pipe(U(e=>t.emit(e)))}),Im=(e,t)=>ee(e,e=>e._tag===`SendTo`?t.sendTo(e.target,e.event):t.stopChild(e.child),{discard:!0}),Lm=(e,t)=>yn(Array.from(e,e=>t.emit(e)),{discard:!0}),Rm=new WeakMap,zm=e=>{let t=Rm.get(e);if(t!==void 0)return t;let n={self:{id:e.id??`Machine`,sessionId:`Machine.plan`,send:()=>W(new Su)},parent:void 0};return Rm.set(e,n),n},Bm=(e,t)=>{let n=t===void 0?zm(e):t;return e.parent===void 0?{self:n.self}:{self:n.self,parent:n.parent}},Vm=new Set([`initialize`,`invoke`,`on`,`output`]),Hm=e=>{if(e===void 0)return!0;for(let t of Reflect.ownKeys(e))if(!Vm.has(t))return!1;return!0},Um=e=>{let t=[],n=[],r=[],i=new Map;for(let a of e.stateNodes.byPath.values()){if(t.push(a),a.type===`choice`||a.type===`history`)return;(a.type===`atomic`||a.type===`final`)&&n.push(a.path),a.type===`final`&&r.push(a.path);let o=Y(e).handlers[a.path];if(!Hm(o))return;if(o?.on===void 0)continue;let s=new Map;for(let e of Reflect.ownKeys(o.on)){let t=Wp(o.on[e]);if(t!==void 0){if(t.declinable)return;s.set(e,t)}}s.size>0&&i.set(a.path,s)}n.sort((t,n)=>mf(e,t,n)),r.sort((t,n)=>mf(e,t,n)),t.sort((e,t)=>e.order-t.order);let a=new Map(t.map((e,t)=>[e.path,t])),o=e=>{let t=a.get(e);if(t===void 0)throw Error(`Machine expected compiled state path "${e}"`);return t},s=n.map(o),c=t.map(e=>e.parent===void 0?-1:o(e.parent)),l=t.map(e=>e.children.map(o)),u=t.map(t=>Z(e,t.path).slice(0,-1).map(o)),d=t.map(e=>i.get(e.path)),f=new Map;for(let e of s){let t=new Map,n=[e,...u[e].slice().reverse()];for(let e of n)for(let[n,r]of d[e]??[])t.has(n)||t.set(n,{sourceIndex:e,transition:r});f.set(e,t)}return{valued:Object.freeze(t.map(e=>e.schema!==void 0)),flat:t.every(e=>e.parent===void 0&&(e.type===`atomic`||e.type===`final`))||t[0]?.path===``&&t[0].type===`compound`&&t[0].schema===void 0&&(Y(e).handlers[``]===void 0||Reflect.ownKeys(Y(e).handlers[``]).every(e=>e===`initialize`))&&t.slice(1).every(e=>e.parent===``&&(e.type===`atomic`||e.type===`final`))&&[...i.values()].every(e=>[...e.values()].every(e=>e.targets!==void 0&&e.targets.every(e=>e!==``))),nodes:t,indexByPath:a,parentIndices:c,childIndices:l,ancestorIndices:u,rootIndices:t.flatMap((e,t)=>e.parent===void 0?[t]:[]),leafIndices:s,finalIndices:r.map(o),dispatchByLeaf:f}},Wm=e=>({active:e.active.slice(),activeLeaves:e.activeLeaves.slice(),values:e.values.slice(),completed:e.completed.slice(),outputs:e.outputs.slice(),completedOrder:e.completedOrder.slice()}),Gm=(e,t)=>t?{...e,next:Wm(e.next)}:e,Km=(e,t,n)=>{e.values[t]=n},qm=(e,t)=>{let n=new Uint8Array(e.nodes.length),r=Array(e.nodes.length),i=new Uint8Array(e.nodes.length),a=Array(e.nodes.length),o=[];for(let i of t.active){let a=e.indexByPath.get(i);if(a===void 0)throw Error(`Machine expected indexed active path "${i}"`);n[a]=1,e.valued[a]&&(r[a]=t.values.get(i))}for(let[n,r]of t.outputs){let t=e.indexByPath.get(n);if(t===void 0)throw Error(`Machine expected indexed completed path "${n}"`);i[t]=1,a[t]=r,o.push(t)}return{active:n,activeLeaves:e.leafIndices.filter(e=>n[e]===1),values:r,completed:i,outputs:a,completedOrder:o}},Jm=(e,t)=>{let n=new Set,r=new Map,i=new Map;for(let i=0;i<e.nodes.length;i++){if(t.active[i]!==1)continue;let a=e.nodes[i].path;n.add(a),e.valued[i]&&r.set(a,t.values[i])}for(let n of t.completedOrder)t.completed[n]===1&&i.set(e.nodes[n].path,t.outputs[n]);return{active:n,values:r,outputs:i,history:new Map}},Ym=(e,t,n)=>{let r=e.nodes[n],i={path:r.path,value:e.valued[n]?t.values[n]:void 0};if(r.type===`compound`){let a=e.childIndices[n].find(e=>t.active[e]===1);if(a===void 0)throw Error(`Machine expected indexed compound state "${r.path}" to have an active child`);i.state=Ym(e,t,a)}else if(r.type===`parallel`){let a={};for(let i of e.childIndices[n]){if(t.active[i]!==1)throw Error(`Machine expected indexed parallel state "${r.path}" to have active region "${e.nodes[i].path}"`);a[e.nodes[i].key]=Ym(e,t,i)}i.states=a}return i},Xm=(e,t)=>{let n=e.rootIndices.find(e=>t.active[e]===1);if(n===void 0)throw Error(`Machine expected an active indexed root state`);let r=Ym(e,t,n);return t.completedOrder.length>0&&(r.completed=t.completedOrder.map(n=>({path:e.nodes[n].path,output:t.outputs[n]}))),r},Zm=(e,t,n,r,i,a)=>{let o=t.parentIndices[r],s={};for(let e of t.ancestorIndices[r])t.valued[e]&&(s[t.nodes[e].path]=n.values[e]);return{...Bm(e,a),state:n.values[r],containingState:o<0?void 0:n.values[o],ancestors:s,event:i,snapshot:Xm(t,n)}},Qm=Object.freeze([]),$m=(e,t,n,r)=>{let i,a,o,s={raise:t=>{(a??=[]).push(Jd(e,t))},emit:t=>{(o??=[]).push(Xd(e,t))},sendTo:(e,t)=>{(i??=[]).push({_tag:`SendTo`,target:e,event:t})},stop:e=>{(i??=[]).push({_tag:`Stop`,child:e})}},c=r===void 0?{result:t(n,s),branchIndex:0,branchKey:void 0}:r(n,s);return{state:Yu(c.result)?void 0:c.result,branchIndex:c.branchIndex,branchKey:c.branchKey,commands:i??Qm,raisedEvents:a??Qm,emittedEvents:o??Qm}},eh=(e,t,n,r,i)=>{let a=[];for(let o of n.activeLeaves){let s=t.dispatchByLeaf.get(o).get(r._tag);if(s!==void 0){let{sourceIndex:c,transition:l}=s;if(!a.some(e=>e.sourceIndex===c)){let s=t.nodes[c].path;a.push({sourceIndex:c,leafIndex:o,sourcePath:s,leafPath:t.nodes[o].path,trigger:{type:`event`,event:r._tag},transition:l,context:Zm(e,t,n,c,r,i)})}}}return a},th=(e,t)=>{if(e.active===t.active)return!0;for(let n=0;n<e.active.length;n++)if(e.active[n]!==t.active[n])return!1;return!0},nh=(e,t,n,r,i)=>{if((dd(r)?t.indexByPath.get(String(r.path)):void 0)===i&&n.active[i]===1&&dd(r)&&r[Du]===void 0&&r.values===void 0&&n.completedOrder.length===0&&t.valued[i]){let a=n.values.slice();return a[i]=$d(e,t.nodes[i],r.value),{...n,values:a}}return qm(t,Bf(e,Jm(t,n),r))},rh=(e,t,n,r)=>{let i=$m(e,r.transition.transition,r.context,r.transition.evaluate),a=Wu(i.state)?i.state:void 0,o=a?.target??i.state,s=a?.update??(Hu(o)?o:void 0),c=s===void 0?void 0:(()=>{let r=t.indexByPath.get(s.path),i=r===void 0?void 0:t.nodes[r];if(r===void 0||i===void 0||n.active[r]!==1||i.schema===void 0)throw Error(`Machine state update owner "${s.path}" must be an active valued state`);return{path:i.path,value:$d(e,i,s.value)}})(),l=o===void 0||Hu(o)?void 0:o;gm(r.sourcePath,r.trigger,r.transition.targets,l);let u=l!==void 0&&nd(l)?Xp(e,(()=>{let e=Jm(t,n);return c===void 0?e:{...e,values:new Map(e.values).set(c.path,c.value)}})(),l,r.context.event):void 0,d=u?.target??l;if(d!==void 0&&!dd(d)&&!md(d))throw Error(`Machine expected indexed transition target to be a snapshot or target builder result`);let f=d===void 0?c===void 0?n:(()=>{let e=Wm(n);return e.values[t.indexByPath.get(c.path)]=c.value,e})():nh(e,t,n,d,r.leafIndex);if(a!==void 0&&c!==void 0){let e=t.indexByPath.get(c.path);if(f.active[e]!==1)throw Error(`Machine combined target exited its updating owner "${c.path}"`);let n=f.values.slice();n[e]=c.value,f={...f,values:n}}let p=r.transition.reenter||!th(n,f),m=p||c!==void 0;if(!p)return{selection:r,branchIndex:i.branchIndex,branchKey:i.branchKey,unresolvedTarget:l,target:d,update:c,next:f,commands:[...i.commands,...u?.commands??[]],raisedEvents:[...i.raisedEvents,...u?.raisedEvents??[]],emittedEvents:[...i.emittedEvents,...u?.emittedEvents??[]],changed:!1,stabilize:m,exitPaths:[],entryPaths:[],choiceTransitions:u?.transitions??[]};let h=d===void 0?void 0:hm(d),g=h===void 0?t.nodes[r.sourceIndex].parent:em(e,r.leafPath,h),_=t.nodes[r.sourceIndex].parent,v=r.transition.reenter?tm(g,_):g;return{selection:r,branchIndex:i.branchIndex,branchKey:i.branchKey,unresolvedTarget:l,target:d,update:c,next:f,commands:[...i.commands,...u?.commands??[]],raisedEvents:[...i.raisedEvents,...u?.raisedEvents??[]],emittedEvents:[...i.emittedEvents,...u?.emittedEvents??[]],changed:!0,stabilize:m,exitPaths:nm(e,Jm(t,n),v),entryPaths:rm(e,Jm(t,f),v),choiceTransitions:u?.transitions??[]}},ih=(e,t,n,r,i,a)=>{let o=e=>({source:e.selection.sourcePath,trigger:e.selection.trigger,reenter:e.selection.transition.reenter,branchIndex:e.branchIndex,branchKey:e.branchKey,target:e.unresolvedTarget===void 0?void 0:hm(e.unresolvedTarget),resolvedTarget:e.target===void 0?void 0:hm(e.target),updates:e.update===void 0?[]:[e.update.path]});if(i.length===1){let s=rh(e,t,n,i[0]);return{next:s.next,event:r,...a?{transitions:[o(s)]}:void 0,commands:s.commands,raisedEvents:s.raisedEvents,emittedEvents:s.emittedEvents,exitPaths:s.exitPaths,entryPaths:s.entryPaths,changed:s.changed}}let s=vm(e,bm(e,i.filter(e=>!i.some(t=>t.sourceIndex!==e.sourceIndex&&df(t.sourcePath,e.sourcePath))).map(r=>rh(e,t,n,r)))),c=n;if(s.length===1)c=s[0].next;else{for(let e of s)if(e.update!==void 0){let n=c.values.slice();n[t.indexByPath.get(e.update.path)]=e.update.value,c={...c,values:n}}let n=[...s.filter(e=>!e.changed),...s.filter(e=>e.changed)];for(let r of n)r.target!==void 0&&(c=nh(e,t,c,r.target,r.selection.leafIndex))}let l=s.flatMap(e=>e.commands),u=s.flatMap(e=>e.raisedEvents),d=s.flatMap(e=>e.emittedEvents),f=s.some(e=>e.changed);return{next:c,event:r,...a?{transitions:s.map(o)}:void 0,commands:l,raisedEvents:u,emittedEvents:d,exitPaths:f?am(e,s.flatMap(e=>e.exitPaths)):[],entryPaths:f?om(e,s.flatMap(e=>e.entryPaths)):[],changed:f}},ah=(e,t,n,r,i,a)=>{let o=n,s=r,c,l,u,d,f=0,p=0;for(;;){if(p+=1,p>1e3)throw new yu({machineId:e.id,state:t.nodes[o.activeLeaves[0]].path,maxIterations:Em});let n=o.activeLeaves[0];if(n===void 0)throw Error(`Machine expected an active indexed root state`);if(t.nodes[n].type===`final`){let n=$f(e,Jm(t,o),s).configuration,i=yf(e,n);if(!n.outputs.has(i))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:r,next:qm(t,n),commands:c??Qm,emittedEvents:u??Qm,microsteps:d??Qm,done:!0,output:n.outputs.get(i)}}let m=t.nodes[n].path,h=Wp(Y(e).handlers[m]?.on?.[s._tag]);if(h!==void 0){let r=$m(e,h.transition,{...Bm(e,a),state:o.values[n],containingState:void 0,ancestors:{},event:s,snapshot:Xm(t,o)},h.evaluate),f=Hu(r.state)?r.state:void 0,p=f===void 0?r.state:void 0;if(f!==void 0){let r=t.nodes[n];if(f.path!==m||r.schema===void 0)throw Error(`Machine state update owner "${f.path}" must be the active valued state`);Km(o,n,$d(e,r,f.value))}if(gm(m,{type:`event`,event:s._tag},h.targets,p),p!==void 0&&!dd(p)&&!md(p))throw Error(`Machine expected indexed transition target to be a snapshot or target builder result`);let g=o;if(p!==void 0){let r=t.indexByPath.get(String(p.path)),i=dd(p)?p[Du]===void 0&&p.values===void 0:!(`state`in p)&&!(`states`in p)&&!(`completed`in p)&&!(`history`in p);r===n&&i&&o.completedOrder.length===0&&t.valued[n]?Km(o,n,$d(e,t.nodes[n],p.value)):g=nh(e,t,o,p,n)}let _=h.reenter||!th(o,g),v=g.activeLeaves[0];if(v===void 0)throw Error(`Machine expected an active indexed transition target`);let y={next:g,event:s,...i?{transitions:[{source:m,trigger:{type:`event`,event:s._tag},reenter:h.reenter,branchIndex:r.branchIndex,branchKey:r.branchKey,target:p===void 0?void 0:hm(p),resolvedTarget:p===void 0?void 0:hm(p),updates:f===void 0?[]:[f.path]}]}:void 0,commands:r.commands,raisedEvents:r.raisedEvents,emittedEvents:r.emittedEvents,exitPaths:_?[m]:Qm,entryPaths:_?[t.nodes[v].path]:Qm,changed:_};o=g,(d??=[]).push(Gm(y,i)),r.commands.length>0&&(c??=[]).push(...r.commands),r.raisedEvents.length>0&&(l??=[]).push(...r.raisedEvents),r.emittedEvents.length>0&&(u??=[]).push(...r.emittedEvents)}if(t.nodes[o.activeLeaves[0]].type===`final`)continue;let g=l?.[f];if(g===void 0)return{event:r,next:o,commands:c??Qm,emittedEvents:u??Qm,microsteps:d??Qm,done:!1,output:void 0};f+=1,s=g}},oh=(e,t,n,r,i,a)=>{if(Rp(r)){let i=Nm(e,a===void 0?Jm(t,n):sf(Jm(t,n),a),r);return{event:i.event,next:qm(t,i.next),commands:i.commands,emittedEvents:i.emittedEvents,microsteps:i.microsteps.map(e=>({next:qm(t,e.next),event:e.event,transitions:e.transitions,commands:e.commands,raisedEvents:e.raisedEvents,emittedEvents:e.emittedEvents,exitPaths:e.exitPaths,entryPaths:e.entryPaths,changed:e.changed})),done:i.done,output:i.output}}let o=Jd(e,r);if(t.flat)return ah(e,t,n,o,i,a);if(t.finalIndices.some(e=>n.active[e]===1)){let r=Jm(t,n);if(Kf(e,r)){let n=$f(e,r,o).configuration,i=yf(e,n);if(!n.outputs.has(i))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:o,next:qm(t,n),commands:[],emittedEvents:[],microsteps:[],done:!0,output:n.outputs.get(i)}}}let s=eh(e,t,n,o,a);if(s.length===0)return{event:o,next:n,commands:[],emittedEvents:[],microsteps:[],done:!1,output:void 0};let c=ih(e,t,n,o,s,i),l=c.next,u=o,d=[...c.commands],f=[...c.raisedEvents],p=[...c.emittedEvents],m=[Gm(c,i)],h=0,g=0;for(;;){if(g+=1,g>1e3)throw new yu({machineId:e.id,state:t.nodes[t.leafIndices.find(e=>l.active[e]===1)].path,maxIterations:Em});if(t.finalIndices.some(e=>l.active[e]===1)){let n=$f(e,Jm(t,l),u).configuration;if(l=qm(t,n),Kf(e,n)){let t=yf(e,n);if(!n.outputs.has(t))throw Error(`Machine reached a terminal indexed configuration without a completed root output`);return{event:o,next:l,commands:d,emittedEvents:p,microsteps:m,done:!0,output:n.outputs.get(t)}}}let n=f[h];if(n===void 0)return{event:o,next:l,commands:d,emittedEvents:p,microsteps:m,done:!1,output:void 0};h+=1,u=n;let r=eh(e,t,l,n,a);if(r.length===0)continue;let s=ih(e,t,l,n,r,i);l=s.next,d.push(...s.commands),f.push(...s.raisedEvents),p.push(...s.emittedEvents),m.push(Gm(s,i))}},sh=new WeakMap,ch=e=>({fromConfiguration:e=>e,toConfiguration:e=>e,snapshot:t=>wf(e,t),plan:(t,n,r,i)=>Nm(e,i===void 0?t:sf(t,i),n)}),lh=(e,t)=>({fromConfiguration:e=>qm(t,e),toConfiguration:e=>Jm(t,e),snapshot:e=>Xm(t,e),plan:(n,r,i=!1,a)=>oh(e,t,n,r,i,a),...Object.values(Y(e).handlers).some(e=>e.initialize!==void 0&&!gp(e.initialize))?{}:{initial:(n,r)=>{let i=e.input===void 0?n:n.length===0?(Zd(e,e.input,void 0),n):[Zd(e,e.input,n[0])],a=e.initial(...i),o=nd(a)?Yp(e,{active:new Set,values:new Map,outputs:new Map,history:new Map,...r===void 0?{}:{machineReferences:r}},a,Dm).configuration:jf(e,a),s=$f(e,r===void 0?o:sf(o,r),Dm).configuration,c=qm(t,s),l=Xm(t,c);if(!Kf(e,s))return{state:l,configuration:c,activeConfiguration:s,initialEntryPaths:Sf(e,s),done:!1,output:void 0};let u=yf(e,s);if(!s.outputs.has(u))throw Error(`Machine reached a terminal configuration without a completed root output`);return{state:l,configuration:c,activeConfiguration:s,initialEntryPaths:Sf(e,s),done:!0,output:s.outputs.get(u)}}}}),uh=e=>{let t=sh.get(e);if(t!==void 0)return t;let n=Um(e),r=n===void 0?ch(e):lh(e,n);return sh.set(e,r),r},dh=`Machine.invocation:`,fh=e=>e.startsWith(dh),ph=(e,t)=>{if(e.values===void 0?e.values=[t]:e.values.push(t),e.waiter!==void 0){let t=e.waiter;e.waiter=void 0,Mt(t,L)}},mh=e=>V(()=>{if(e.values!==void 0){let t=e.values;return e.values=void 0,k(t)}let t=ei();return e.waiter=t,Lt(t).pipe(B(mh(e)))}),hh=(e,t)=>e._tag===`Started`&&(typeof t==`string`||e.descriptor!==void 0&&e.descriptor.id===t.id&&e.descriptor.machine===t.machine),gh=(e,t,n)=>{if(e.closed)return z();let r=e.children.get(t);return r!==void 0&&hh(r,n)?kn(r.ref):z()},_h=e=>{if(e.observers!==void 0)for(let t of e.observers)ph(t,gh(e,t.id,t.child))},vh=(e,t,n)=>{let r=e.children.get(t);r!==void 0&&r.token===n&&(e.children.delete(t),typeof t==`string`&&_h(e))},yh=(e,t,n,r,i)=>{let a=e.children.get(t);if(e.closed||a===void 0||a._tag!==`Starting`||a.token!==n)return!1;e.children.delete(t);let o=a.ownerKey===void 0?{_tag:`Started`,token:n,descriptor:i,ref:r}:{_tag:`Started`,token:n,descriptor:i,ref:r,ownerKey:a.ownerKey,ownerPath:a.ownerPath,ownerActive:a.ownerActive===!0};return e.children.set(t,o),typeof t==`string`&&_h(e),!0},bh=e=>ce(function*(){let t=yield*on(),n=0,r=0,i=0,a=0;return{rootSessionId:e,stream:xr(t).pipe(fe(O(()=>{n+=1})),Ot(O(()=>{--n}))),isActive:()=>n>0,nextDeliveryId:()=>i++,nextMacrostepId:()=>a++,publishUnsafe:i=>{n!==0&&ti(t,{...i,sequence:r++,rootSessionId:e})},close:Fe(t)}}),xh=e=>({id:e.id,sessionId:e.sessionId}),Sh=e=>e.flatMap(e=>{if(typeof e!=`object`||!e||!(`_tag`in e))return[];if(e._tag===`SendTo`&&`target`in e&&`event`in e){let t=e.target;return typeof t==`object`&&t&&`id`in t?[{_tag:`SendTo`,target:`sessionId`in t?xh(t):{id:String(t.id)},event:e.event}]:[]}if(e._tag===`Stop`&&`child`in e){let t=e.child;return typeof t==`string`?[{_tag:`Stop`,target:{id:t}}]:typeof t==`object`&&t&&`id`in t?[{_tag:`Stop`,target:`sessionId`in t?xh(t):{id:String(t.id)}}]:[]}return[]}),Ch=e=>typeof e!=`object`||!e||!(`microsteps`in e)||!Array.isArray(e.microsteps)?[]:e.microsteps.map(e=>({event:e.event,transitions:Array.isArray(e.transitions)?e.transitions:[],raisedEvents:Array.isArray(e.raisedEvents)?e.raisedEvents:[],emittedEvents:Array.isArray(e.emittedEvents)?e.emittedEvents:[],commands:Sh(Array.isArray(e.commands)?e.commands:[]),exitPaths:Array.isArray(e.exitPaths)?e.exitPaths:[],entryPaths:Array.isArray(e.entryPaths)?e.entryPaths:[],changed:e.changed===!0})),wh=Symbol.for(`effect/Machine/activeSnapshotObserver`),Th=Symbol.for(`effect/Machine/snapshotObserver`),Eh=e=>typeof e==`object`&&!!e&&Th in e,Dh=Symbol.for(`effect/Machine/sendParentOverride`),Oh=Symbol.for(`effect/Machine/acknowledgedSend`),kh=Symbol(`effect/Machine/AcknowledgedMessage`),Ah=e=>typeof e==`object`&&!!e&&kh in e,jh=e=>Ah(e)?e.event:e,Mh=(e,t)=>{e!==void 0&&Ah(e)&&(e.deferred!==void 0&&Mt(e.deferred,k(t)),e.inspection?.complete(t))},Nh=(e,t)=>{e!==void 0&&Ah(e)&&e.deferred!==void 0&&Mt(e.deferred,Cn(t))},Ph=e=>{e!==void 0&&Ah(e)&&e.deferred!==void 0&&Mt(e.deferred,W(new Su))},Fh=e=>typeof e==`object`&&!!e&&`send`in e&&typeof e.send==`function`,Ih=(e,t,n,r)=>`inspectionSubject`in e&&`sendInspected`in e&&typeof e.sendInspected==`function`?e.sendInspected(t,n,r):e.send(t),Lh=e=>e?._tag===`Childless`||e?.childless===!0,Rh=(e,t)=>{let n=e.items??[];e.items=n,n.push(t)},zh=e=>{if(e.items===void 0)return z();let t=e.items[e.index];return e.index+=1,e.index===e.items.length&&(e.items=void 0,e.index=0),kn(t)},Bh=e=>{if(e.items!==void 0)for(let t=e.index;t<e.items.length;t+=1)Ph(e.items[t]);e.closed=!0,e.items=void 0,e.index=0},Vh=()=>({items:void 0,index:0,closed:!1,receivers:new Set}),Hh=(e,t,n)=>{if(e.closed)return!1;for(Rh(e,t),n?.();e.items!==void 0&&e.receivers.size>0;){let t=e.receivers.values().next().value;e.receivers.delete(t),t(L)}return!0},Uh=e=>V(()=>{let t=zh(e);return R(t)?k(t.value):e.closed?re:In(t=>(e.receivers.add(t),O(()=>{e.receivers.delete(t)}))).pipe(B(Uh(e)))}),Wh=e=>{Bh(e);let t=Array.from(e.receivers);e.receivers.clear();for(let e of t)e(re)},Gh=class extends un()(`effect/Machine/MachineRuntime`){},Kh=(e,t)=>We(e,Gh,t),qh=e=>{switch(e.status){case`active`:return;case`done`:return{_tag:`Done`,output:e.output,snapshot:e};case`error`:{let t=e.cause.reasons.find(wi);if(t!==void 0)return{_tag:`Failure`,error:t.error,cause:e.cause,snapshot:e};let n=e.cause.reasons.find(Tr);return n===void 0?e.cause.reasons.find(Nn)===void 0?{_tag:`Cause`,cause:e.cause,snapshot:e}:{_tag:`Interrupted`,cause:e.cause,snapshot:e}:{_tag:`Defect`,defect:n.defect,cause:e.cause,snapshot:e}}case`stopped`:return{_tag:`Stopped`,snapshot:e}}},Jh=(e,t)=>V(()=>e(t)).pipe(Mi,I),Yh=(e,t)=>{class n{nextSessionId;constructor(){let e=0;this.nextSessionId=O(()=>`machine:${e++}`)}get start(){return e}get startCompiledSync(){return t}}return O(()=>new n)},Xh=(e,t,n)=>({id:t,sessionId:n,kind:e.inspection?.kind??`Logic`}),Zh=(e,t)=>t?{_tag:`Initialization`}:e!==void 0&&Ah(e)&&e.inspection!==void 0?{_tag:`Macrostep`,macrostepId:e.inspection.macrostepId}:void 0,Qh=(e,t,n,r,i,a)=>{let o=e.nextDeliveryId(),s=e.nextMacrostepId(),c={deliveryId:o,macrostepId:s,source:r,event:n,causedBy:i,complete:i=>{let a=Ch(i.plan);e.publishUnsafe({_tag:`EventProcessed`,subject:t,macrostepId:s,deliveryId:o,source:r,event:n,before:{status:`active`,state:i.before},after:{status:`active`,state:i.after},handled:a.some(e=>e.transitions.length>0),configurationChanged:a.some(e=>e.changed),microsteps:a})}};return{[kh]:!0,event:n,...a===void 0?void 0:{deferred:a},inspection:c}},$h=(e,t,n)=>{if(!Ah(n)||n.inspection===void 0)return;let r=n.inspection;e.publishUnsafe({_tag:`EventSent`,subject:t,deliveryId:r.deliveryId,source:r.source,target:xh(t),event:r.event,causedBy:r.causedBy})},eg=class{registry;self;runtime;services;sendAcknowledged;scopedServices;constructor(e,t,n,r,i){this.registry=e,this.self=t,this.runtime=n,this.services=r,this.sendAcknowledged=i}has(e){for(let t of this.registry.children.values())if(t.ownerActive&&t.ownerKey===e)return!0;return!1}stopEntry(e){return e.ownerActive=!1,e._tag===`Started`?e.ref.stop:L}spawn(e,t){let n=Symbol(),r,i=()=>{let e=this.registry.children.get(t.id);return e?.token===n&&e.ownerKey===t.key&&e.ownerActive===!0};return V(()=>{if(this.registry.closed)return re;if(this.has(t.key)||this.registry.children.has(t.id))return W(new xu({id:t.duplicateId}));let a=e(),o=this.registry.scope??=Ji(`parallel`);this.registry.children.set(t.id,{_tag:`Starting`,token:n,ownerKey:t.key,ownerPath:t.path,ownerActive:!0});let c={...this.self,send:e=>t.sendParent(i,e),sendInspected:(e,t,n)=>i()?Ih(this.self,e,t,n):L,...this.sendAcknowledged===void 0?void 0:{[Oh]:e=>i()?this.sendAcknowledged(e):re}},l={detached:!0,id:t.id,sendParent:e=>t.sendParent(i,e),onOutcome:e=>t.onOutcome(i,e,r?.sessionId),...t.onSnapshot===void 0?void 0:{onSnapshot:e=>t.onSnapshot(i,e)},onReadySync:e=>(r=e,yh(this.registry,t.id,n,e,t.descriptor)),onStopSync:()=>vh(this.registry,t.id,n),skipStoppedOutcome:!0,parent:c,runtime:this.runtime,origin:{_tag:`Invoke`,ownerPath:t.path,invokeId:t.duplicateId},...t.activityKind===void 0||this.runtime.inspection===void 0||this.self.inspectionSubject===void 0?void 0:{activity:{id:t.duplicateId,owner:this.self.inspectionSubject,ownerPath:t.path,kind:t.activityKind}}},u=a.execution,d=this.services!==void 0&&t.onSnapshot===void 0&&u?._tag===`Compiled`&&u.childless&&u.drain._tag===`Owned`&&u.initialSync!==void 0,f=(d?U(this.runtime.nextSessionId,e=>this.runtime.startCompiledSync(a,l,this.scopedServices??=ji(this.services,Oe,o),e)):this.runtime.start(a,l)).pipe(st(e=>s(e)?L:(vh(this.registry,t.id,n),r===void 0?L:r.stop)));return(d?f:v(f,o)).pipe(I)})}stopAll(){return V(()=>{let e=[];for(let t of this.registry.children.values())t.ownerActive&&e.push(this.stopEntry(t));return e.length===0?L:e.length===1?e[0]:yn(e,{concurrency:`unbounded`,discard:!0})})}stopPaths(e){if(e.length===0)return;let t=new Set(e),n=[];for(let e of this.registry.children.values())e.ownerActive&&e.ownerPath!==void 0&&t.has(e.ownerPath)&&n.push(this.stopEntry(e));return n.length===0?void 0:n.length===1?n[0]:yn(n,{concurrency:`unbounded`,discard:!0})}},tg=gt(z()).pipe(C(ot)),ng=e=>L,rg=(e,t)=>{},ig=()=>void 0,ag=Symbol(`effect/Machine/EmissionsClosed`),og=()=>{let e,t=V(()=>{let t=e;return t===ag?k(void 0):t===void 0?on().pipe(U(t=>O(()=>{let n=e;return n===ag?[void 0,!0]:n===void 0?(e=t,[t,!1]):[n,!0]}).pipe(U(([e,n])=>n?Fe(t).pipe(An(e)):k(e))))):k(t)});return{emit:t=>V(()=>e===void 0||e===ag?L:ze(e,t).pipe(I)),close:()=>{let t=e;return e=ag,t===void 0||t===ag?L:Fe(t)},stream:Nt(t.pipe(P(e=>e===void 0?Ii:xr(e))))}},sg={close:()=>L,spawn:(()=>Qn(Error(`Childless machine logic cannot spawn a process`))),get:()=>k(z()),changes:()=>tg,sendTo:()=>L,stop:()=>L,owned:{spawn:()=>Qn(Error(`Childless machine logic cannot spawn an owned process`)),stopAll:()=>L,stopPaths:()=>void 0}},cg=(e,t,n,r)=>{let i={closed:!1,children:new Map,observers:void 0,scope:void 0},a=e=>V(()=>{if(i.closed||(i.closed=!0,i.scope===void 0))return L;let t=ht(i.scope,e),n,r;for(let e of i.children.values())e._tag===`Started`&&(n===void 0?n=e.ref.stop:(r??=[n],r.push(e.ref.stop)));t!==void 0&&(n===void 0?n=t:(r??=[n],r.push(t)));let a=r??n;return a===void 0?L:Array.isArray(a)?yn(a,{concurrency:`unbounded`,discard:!0}):a}),o=(e,t)=>O(()=>vh(i,e,t)),s=(e,t,n,r)=>O(()=>yh(i,e,t,n,r)),c=e=>{let t=typeof e==`string`?e:e.id;return O(()=>{if(i.closed)return z();let n=i.children.get(t);return n!==void 0&&hh(n,e)?kn(n.ref):z()})},l=e=>{let t=typeof e==`string`?e:e.id;return nt(ve((n,r)=>O(()=>({child:e,id:t,values:void 0,waiter:void 0})).pipe(U(n=>{let a=O(()=>{i.observers!==void 0&&(i.observers.delete(n),i.observers.size===0&&(i.observers=void 0)),n.values=void 0,n.waiter=void 0});return He(r,a).pipe(B(O(()=>{!i.closed&&r.state._tag!==`Closed`&&(i.observers??=new Set,i.observers.add(n)),ph(n,gh(i,t,e))})),An(mh(n)))}))))},u=(e,t,n,r)=>{let a=typeof e==`string`?e:e.id;return V(()=>{if(i.closed)return L;let o=i.children.get(a);return o!==void 0&&hh(o,e)?Ih(o.ref,t,n,r):L})},d=e=>{let t=typeof e==`string`?e:e.id;return V(()=>{if(i.closed)return L;let n=i.children.get(t);return n!==void 0&&hh(n,e)?n.ref.stop:L})};function f(n,r){let a=typeof n==`object`&&n&&mp in n?n:void 0,c=a===void 0?n:a[mp](r?.input),l=a===void 0?r:{id:a.id,descriptor:a},u=Symbol(),d=l?.id??u,f;return V(()=>i.closed?re:typeof d==`string`&&(i.children.has(d)||fh(d))?W(new xu({id:d})):(i.scope??=Ji(`parallel`),i.children.set(d,{_tag:`Starting`,token:u}),t.start(c,{detached:!0,...l?.id===void 0?void 0:{id:l.id},...l?.onOutcome===void 0?void 0:{onOutcome:l.onOutcome},...l?.[wh]===void 0?void 0:{onSnapshot:l[wh]},...l?.[Dh]===void 0?void 0:{sendParent:l[Dh]},onReady:(e,t)=>O(()=>{f=e}).pipe(B(s(d,u,e,l?.descriptor)),U(e=>e?L:t)),onStop:o(d,u),parent:e,runtime:t,origin:{_tag:`Spawn`,address:l?.id}}).pipe(st(e=>dt(e)?o(d,u).pipe(B(f===void 0?L:f.stop)):L),v(i.scope))))}return{close:a,spawn:f,get:c,changes:l,sendTo:u,stop:d,owned:new eg(i,e,t,n,r)}},lg=(e,t,n,r)=>O(()=>cg(e,t,n,r)),ug=(e,t)=>`${e.length}:${e}${t}`,dg=(e,t)=>`${dh}${ug(e,t)}`,fg=e=>({initial:()=>L,run:()=>e}),pg=(e,t,n)=>({initial:()=>L,run:({parent:r})=>{let i=r?.[Oh];return i===void 0?Qn(Error(`Stream invocation requires an acknowledged parent machine`)):Ue(e,e=>i(Fp(t,n,e)).pipe(I,Jn(()=>re)))}}),mg=(e,t)=>typeof e==`function`?e(t):e,hg=e=>({spawn:((t,n)=>e.spawn(t,n)),sendTo:((t,n)=>e.sendTo(t,n)),stop:(t=>e.stopChild(t))}),gg=(e,t,n)=>{if(`effect`in e)return{id:String(e.id),sourceName:e.sourceName,src:()=>fg(e.effect(t)),onDone:e.onDone,onFailure:e.onFailure,onSnapshot:e.onSnapshot,activityKind:`Effect`};if(`after`in e)return{id:String(e.id),sourceName:e.sourceName,src:()=>fg(ye(mg(e.after,t))),onDone:e.onDone,activityKind:`Timer`};if(`stream`in e){let r=String(e.id);return{id:r,sourceName:e.sourceName,src:()=>pg(e.stream(t),n,r),onDone:e.onDone,onFailure:e.onFailure,activityKind:`Stream`}}if(`logic`in e)return{id:String(e.id),address:String(e.address),src:()=>mg(e.logic,t),onDone:e.onDone,onFailure:e.onFailure,onSnapshot:e.onSnapshot};if(`child`in e){let n=e.child;return{id:n.id,address:n.id,descriptor:n,src:()=>n[mp](`input`in e?mg(e.input,t):void 0),onDone:e.onDone,onFailure:e.onFailure,onSnapshot:e.onSnapshot}}throw Error(`Unsupported captured machine invocation: ${String(e)}`)},_g=e=>e.length===0?L:e.length===1?e[0]:yn(e,{discard:!0}),vg=(e,t,n)=>(n===void 0||e.self.sendInspected===void 0?e.self.send(t):e.self.sendInspected(t,e.self.inspectionSubject,{_tag:`Activity`,activitySessionId:n})).pipe(Pr(`StoppedError`,()=>L)),yg=e=>e instanceof yu||e instanceof J||e instanceof Su,bg=(e,t,n,r,i,a,o,s,c,l,u,d)=>V(()=>{let f=ug(n,r),p=u===void 0?o:()=>{let t=o();return{...t,run:i=>lr(V(()=>t.run(i)),`Machine.invoke`,{attributes:{"machine.id":e.self.id,"machine.sessionId":e.self.sessionId,"machine.state.path":n,"machine.invoke.id":r,"machine.invoke.source":d??r,"machine.invoke.kind":u,"machine.invoke.sessionId":i.self.sessionId},captureStackTrace:!1})}};return t.spawn(p,{key:f,path:n,id:i,duplicateId:r,...a===void 0?void 0:{descriptor:a},...u===void 0?void 0:{activityKind:u},sendParent:(t,n)=>t()?e.self.send(n):L,onOutcome:(t,i,o)=>B(gn,V(()=>i._tag===`Stopped`||!t()?L:i._tag===`Done`?s===void 0?e.failCause(cr(Error(`Invocation "${r}" completed without the required onDone handler`))):vg(e,Pp(n,r,i.output),u===void 0?void 0:o):i._tag===`Failure`&&c!==void 0&&(a===void 0||!yg(i.error))?vg(e,Ip(n,r,i.error),u===void 0?void 0:o):e.failCause(i.cause))),...l===void 0?void 0:{onSnapshot:(t,i)=>t()?vg(e,Lp(n,r,i)):L}})}),xg=(e,t)=>fh(e)?W(new xu({id:t})):void 0,Sg=(e,t,n,r)=>{let i=String(r.id),a=r.address===void 0?void 0:xg(String(r.address),i);return a===void 0?bg(e,t,n,i,r.address===void 0?dg(n,i):String(r.address),r.descriptor,r.src,r.onDone,r.onFailure,r.onSnapshot,r.activityKind,r.sourceName):a},Cg=(e,t,n,r)=>{let i=r.child,a=xg(i.id,i.id);return a===void 0?bg(e,t,n,i.id,i.id,i,i[mp],r.onDone,r.onFailure,r.onSnapshot,void 0):a},wg=(e,t,n,r,i,a)=>{let o=hg(t),s=om(e,i).filter(e=>r.active.has(e)).flatMap(i=>{let s={...cf(r)??{self:t.self,parent:t.parent},children:o,state:r.values.get(i),containingState:xf(e,r,i),ancestors:bf(e,r,i),event:a};return Tp(Vf(e,i)?.invoke).map(e=>`child`in e&&!(`input`in e)?Cg(t,n,i,e):Sg(t,n,i,gg(e,s,i)))});return s.length===0?void 0:_g(s)},Tg=Symbol(`effect/Machine/CompiledStoppedCompletion`),Eg=class{logic;options;services;id;sessionId;inspectionSubject;send;sendInspected(e,t,n){return this.offerEvent(e,t,n)}[Oh](e){return this.sendAcknowledgedEffect(e)}[Th](e){let t=this.snapshotObservers??=new Set;return t.add(e),()=>{t.delete(e)}}mailbox={items:void 0,index:0,closed:!1};address;childRuntime=sg;processScope;processContext;compiledContext;current;lifecycle=`Active`;runState=`Initializing`;completion;waiter;termination;terminationSnapshot;worker;interruptRequested=!1;offerRevision=0;snapshotObservers;changesFlushScheduled=!1;inFlightMessage;externalEmissions;emissionsPubSub;activity;initialEntryPaths;initialMicrosteps;initializing;constructor(e,t,n,r){this.logic=e,this.options=t,this.services=n,this.sessionId=r,this.id=t.id??r;let i=t.runtime.inspection;i!==void 0&&(this.inspectionSubject=Xh(e,this.id,r),this.initializing=!0,t.activity!==void 0&&(this.activity={...t.activity,sessionId:r})),this.externalEmissions=t.emissions,this.send=i===void 0?e=>this.offerMessage(e):e=>this.offerEvent(e,void 0,void 0),this.address={id:this.id,sessionId:r,stop:V(()=>this.stopFromProcess()),send:this.send,...i===void 0?void 0:{inspectionSubject:this.inspectionSubject,sendInspected:(e,t,n)=>this.offerEvent(e,t,n)}}}get inspector(){return this.options.runtime.inspection}causation(){return Zh(this.inFlightMessage,this.initializing===!0)}publishCreated(){let e=this.inspector,t=this.inspectionSubject;e!==void 0&&t!==void 0&&e.publishUnsafe(this.activity===void 0?{_tag:`Created`,subject:t,parent:this.options.parent?.inspectionSubject,origin:this.options.origin??{_tag:`Root`},definition:this.logic.inspection?.definition}:{_tag:`ActivityStarted`,subject:this.activity.owner,activity:this.activity})}publishInitialized(e){if(this.initializing=!1,this.activity!==void 0)return;let t=this.inspector,n=this.inspectionSubject;t!==void 0&&n!==void 0&&t.publishUnsafe({_tag:`Initialized`,subject:n,snapshot:{status:`active`,state:e},initialEntryPaths:this.initialEntryPaths??[],microsteps:Ch({microsteps:this.initialMicrosteps??[]})})}publishStartFailed(e){this.initializing=!1;let t=this.inspector,n=this.inspectionSubject;t!==void 0&&n!==void 0&&t.publishUnsafe(this.activity===void 0?{_tag:`StartFailed`,subject:n,cause:e}:{_tag:`ActivityStopped`,subject:this.activity.owner,activity:this.activity,exit:qt(e)})}get execution(){return this.logic.execution}initializeCompiledSync(){this.publishCreated(),this.execution.childless||(this.childRuntime=cg(this.address,this.options.runtime,this.services,e=>this.sendAcknowledgedEffect(e)));let e=this.options.parent,t=this.options.sendParent??(e===void 0?ng:this.inspector===void 0?e.send:t=>Ih(e,t,this.inspectionSubject,this.causation()));this.processScope={self:this.address,parent:e,spawn:this.childRuntime.spawn,sendParent:t,emit:e=>this.emitEvent(e),sendTo:((e,t)=>Fh(e)?this.inspector===void 0?e.send(t):Ih(e,t,this.inspectionSubject,this.causation()):this.childRuntime.sendTo(e,t,this.inspectionSubject,this.causation())),stopChild:this.childRuntime.stop,failCause:e=>this.failCause(e),inspectInitial:this.inspector===void 0?rg:(e,t=[])=>{this.initialEntryPaths=e,this.initialMicrosteps=t}};let n=this.execution.initialSync,r;try{r=n(this.processScope)}catch(e){return this.runState=`Idle`,this.publishStartFailed(hn(e)),W(e)}return this.runState=`Idle`,this.current={revision:0,terminalizing:!1,changes:void 0,snapshot:{status:`active`,state:r.state}},this.publishInitialized(r.state),this.compiledContext=new Dg(this.processScope,this.childRuntime.owned,this),`executionState`in r&&(this.compiledContext.executionState=r.executionState),this.options.onReadySync!==void 0&&!this.options.onReadySync(this)&&this.requestTerminationSync({_tag:`Stopped`}),r.done===!0&&this.lifecycle===`Active`&&this.requestTerminationSync({_tag:`Done`,output:r.output}),r.done===!1&&this.execution.childless&&this.lifecycle===`Active`&&this.mailbox.items===void 0?k(this):(this.runState=`Draining`,Ae(this.drainRuntime(),this.services).pipe(An(this)))}initialize(){let e=this;return ce(function*(){e.publishCreated(),e.execution.childless||(e.childRuntime=yield*lg(e.address,e.options.runtime,e.services,t=>e.sendAcknowledgedEffect(t)));let t=e.options.parent,n=e.options.sendParent??(t===void 0?ng:e.inspector===void 0?t.send:n=>Ih(t,n,e.inspectionSubject,e.causation()));e.processScope={self:e.address,parent:t,spawn:e.childRuntime.spawn,sendParent:n,emit:t=>e.emitEvent(t),sendTo:((t,n)=>Fh(t)?e.inspector===void 0?t.send(n):Ih(t,n,e.inspectionSubject,e.causation()):e.childRuntime.sendTo(t,n,e.inspectionSubject,e.causation())),stopChild:e.childRuntime.stop,failCause:t=>e.failCause(t),inspectInitial:e.inspector===void 0?rg:(t,n=[])=>{e.initialEntryPaths=t,e.initialMicrosteps=n}};let r=t=>dt(t)?e.childRuntime.close(t):L,i=e.execution.initial,a=yield*(i===void 0?e.logic.initial(e.processScope).pipe(P(e=>({state:e,done:void 0,output:void 0}))):i(e.processScope)).pipe(st(t=>(dt(t)&&e.publishStartFailed(t.cause),r(t))),fn(O(()=>{e.runState=`Idle`}))),o=a.state;return e.current={revision:0,terminalizing:!1,changes:void 0,snapshot:{status:`active`,state:o}},e.publishInitialized(o),e.execution.drain._tag===`Process`?e.processContext={...e.processScope,receive:Qe,poll:O(()=>dr(zh(e.mailbox),jh)),receiveMessage:Qe,pollMessage:O(()=>e.pollCompiledMessage()),completeMessage:t=>e.completeCompiledMessage(t),state:O(()=>e.current.snapshot.state),setState:t=>e.setActiveState(t),updateState:t=>e.updateState(t)}:(e.compiledContext=new Dg(e.processScope,e.childRuntime.owned,e),`executionState`in a&&(e.compiledContext.executionState=a.executionState)),e.options.onReadySync!==void 0&&!e.options.onReadySync(e)?yield*e.requestTermination({_tag:`Stopped`}):e.options.onReady!==void 0&&(yield*e.options.onReady(e,e.requestTermination({_tag:`Stopped`}).pipe(I))),e.options.onSnapshot!==void 0&&(yield*Jh(e.options.onSnapshot,{status:`active`,state:o})),a.done===!0&&e.lifecycle===`Active`&&(yield*e.requestTermination({_tag:`Done`,output:a.output})),a.done===!1&&e.execution.childless&&e.lifecycle===`Active`&&e.mailbox.items===void 0||(e.runState=`Draining`,yield*e.drainRuntime()),e})}get state(){return O(()=>this.current.snapshot.state)}get snapshot(){return O(()=>this.current.snapshot)}get changes(){return this.changesStream()}get emissions(){return this.externalEmissions?.stream??this.emissionsStream()}get join(){return V(()=>this.lifecycle===`Completed`?this.resolveCompletion(this.completion):(this.waiter??=ei(),Lt(this.waiter)))}get stop(){return Rn(this.stopEffect())}child(e){return this.childRuntime.get(e)}childChanges(e){return this.childRuntime.changes(e)}requestTermination(e){return O(()=>this.requestTerminationSync(e))}hasTerminationRequest(){return this.lifecycle===`TerminationRequested`}requestTerminationSync(e){return this.lifecycle===`Active`&&(this.lifecycle=`TerminationRequested`,this.termination=e,this.terminationSnapshot=this.reserveTermination(e),!0)}reserveTermination(e){let t=this.current;if(t===void 0||t.terminalizing||t.snapshot.status!==`active`)return;let n=e._tag===`Stopped`?{status:`stopped`,state:t.snapshot.state}:e._tag===`Done`?{status:`done`,state:t.snapshot.state,output:e.output}:{status:`error`,state:t.snapshot.state,cause:e.cause};return this.current={...t,terminalizing:!0},n}stopFromProcess(){let e=this.requestTermination({_tag:`Stopped`}).pipe(I);return this.runState===`Initializing`?e:e.pipe(B(re))}failCause(e){let t={_tag:`Failure`,cause:e};return this.requestTermination(t).pipe(U(e=>e?At(this.settleRequestedTermination()).pipe(I):L))}sendAcknowledgedEffect(e){return yi(t=>Re().pipe(U(n=>this.offerEvent(e,void 0,void 0,n).pipe(B(t(Lt(n)))))))}offerEvent(e,t,n,r){return V(()=>{let i=this.inspector,a=this.inspectionSubject,o=i?.isActive()===!0&&a!==void 0?Qh(i,a,e,t,n,r):r===void 0?e:{[kh]:!0,event:e,deferred:r};return this.offerMessage(o)})}offerMessage(e){return Rn(ai(t=>{if(this.mailbox.closed||this.lifecycle!==`Active`)return W(new Su);let n=this.inspector,r=this.inspectionSubject;n!==void 0&&r!==void 0&&$h(n,r,e),this.offerRevision+=1;let i=this.execution.drain,a=this.compiledContext,o=this.runState===`Idle`&&a!==void 0&&i._tag===`Owned`?i.runSync:void 0;if(o===void 0&&Rh(this.mailbox,e),this.runState!==`Idle`)return L;if(this.runState=`Draining`,o!==void 0){let n;try{n=o(a,e)}catch(e){n=Qn(e)}return n!==void 0||this.hasTerminationRequest()?this.startWorker(n):(this.runState=`Idle`,this.scheduleChangesFlush(t.currentDispatcher),L)}return this.startWorker(void 0)}))}startWorker(e){let t=Ae(this.drainRuntime(e),this.services);return(this.options.detached===!0?At(t,{startImmediately:!0}):Li(t,{startImmediately:!0})).pipe(U(e=>O(()=>(e.pollUnsafe()===void 0&&(this.worker=e),this.interruptRequested?(this.interruptRequested=!1,!0):!1)).pipe(U(t=>t?At(this.interruptAndFinish(e)):L))),I)}stopEffect(){return V(()=>this.lifecycle===`Completed`||this.finishIdleChildlessStop()?L:this.requestTermination({_tag:`Stopped`}).pipe(U(e=>e?this.settleRequestedTermination():this.awaitCompletion())))}finishIdleChildlessStop(){if(!this.execution.childless||this.runState!==`Idle`||this.worker!==void 0||this.lifecycle!==`Active`||this.options.onOutcome!==void 0&&this.options.skipStoppedOutcome!==!0||this.options.onStop!==void 0||this.inspector!==void 0||this.current.changes!==void 0||this.externalEmissions!==void 0||this.emissionsPubSub!==void 0&&this.emissionsPubSub!==ag||this.current.terminalizing||this.current.snapshot.status!==`active`)return!1;this.emissionsPubSub=ag;let e={status:`stopped`,state:this.current.snapshot.state};return this.lifecycle=`TerminationRequested`,this.termination={_tag:`Stopped`},this.terminationSnapshot=e,Bh(this.mailbox),this.current={revision:this.current.revision+1,terminalizing:!0,changes:void 0,snapshot:e},this.notifySnapshotObservers(),Ph(this.inFlightMessage),this.inFlightMessage=void 0,this.interruptRequested=!1,this.compiledContext!==void 0&&(this.compiledContext.executionState=void 0),this.options.onStopSync?.(this),this.completion=Tg,this.lifecycle=`Completed`,this.waiter!==void 0&&(Mt(this.waiter,this.resolveCompletion(Tg)),this.waiter=void 0),!0}settleRequestedTermination(){return V(()=>this.runState===`Draining`?this.worker===void 0?(this.interruptRequested=!0,this.awaitCompletion()):this.interruptAndFinish(this.worker).pipe(B(this.awaitCompletion())):this.finishRequestedTermination())}interruptAndFinish(e){return ci(e).pipe(B(V(()=>this.lifecycle===`Completed`?L:this.finishRequestedTermination())))}awaitCompletion(){return this.lifecycle===`Completed`?L:this.join.pipe(Mi,I)}resolveCompletion(e){if(e!==Tg)return e;let t=W(new Su);return this.completion=t,t}drainRuntime(e){let t=this;return yi(n=>ce(function*(){let r=t.offerRevision,i=e;for(;;){if(t.hasTerminationRequest())return yield*t.finishRequestedTermination();let e=yield*n(V(()=>{if(i!==void 0){let e=i;return i=void 0,e}let e=t.execution.drain;return e._tag===`Process`?e.run(t.processContext):e.run(t.compiledContext)})).pipe(Mi);if(t.flushPendingChanges(),dt(e))return t.lifecycle===`Active`&&(yield*t.requestTermination({_tag:`Failure`,cause:e.cause})),yield*t.finishRequestedTermination();if(R(e.value))return yield*t.requestTermination({_tag:`Done`,output:e.value.value}),yield*t.finishRequestedTermination();if(t.hasTerminationRequest())return yield*t.finishRequestedTermination();if(t.offerRevision!==r)r=t.offerRevision;else{t.runState=`Idle`,t.worker=void 0;return}}}))}finishRequestedTermination(){return V(()=>{if(this.lifecycle!==`TerminationRequested`)return L;let e=this.termination;if(e===void 0)return L;let t=this.terminationSnapshot??this.reserveTermination(e);if(t===void 0)return this.awaitCompletion();let n=e._tag===`Stopped`?vi:e._tag===`Done`?Ln(e.output):qt(e.cause),r=e._tag===`Stopped`?Tg:e._tag===`Done`?k(e.output):Cn(e.cause),i=this.options.onOutcome===void 0||e._tag===`Stopped`&&this.options.skipStoppedOutcome===!0?L:V(()=>this.options.onOutcome(qh(t))).pipe(Mi,I),a=this.inspector,o=this.inspectionSubject,s=a===void 0||o===void 0?this.closeEmissions():this.closeEmissions().pipe(B(O(()=>a.publishUnsafe(this.activity===void 0?{_tag:`Terminated`,subject:o,snapshot:t}:{_tag:`ActivityStopped`,subject:this.activity.owner,activity:this.activity,exit:t.status===`stopped`?an():n}))));return Rn(O(()=>{Bh(this.mailbox)}).pipe(B(this.childRuntime.close(n)),B(this.setAndPublishSnapshot(t)),B(s),B(O(()=>{e._tag===`Failure`?Nh(this.inFlightMessage,e.cause):Ph(this.inFlightMessage),this.inFlightMessage=void 0})),B(i),B(this.options.onStop??L),B(this.options.inspectionRoot===!0&&this.inspector!==void 0?this.inspector.close:L),B(O(()=>{this.options.onStopSync?.(this),this.runState=`Idle`,this.worker=void 0,this.interruptRequested=!1,this.compiledContext!==void 0&&(this.compiledContext.executionState=void 0),this.completion=r,this.lifecycle=`Completed`,this.waiter!==void 0&&(Mt(this.waiter,this.resolveCompletion(r)),this.waiter=void 0)}))))})}publishSnapshot(e){let t=e.changes===void 0?k(e):ze(e.changes,[e]).pipe(An(e)),n=e.snapshot;return this.options.onSnapshot===void 0||n.status!==`active`?t:t.pipe(tn(()=>Jh(this.options.onSnapshot,n)))}completeChanges(e){return e.changes===void 0?L:ze(e.changes,Ln(void 0)).pipe(I)}emitEvent(e){let t=this.externalEmissions===void 0?V(()=>this.emissionsPubSub===void 0||this.emissionsPubSub===ag?L:ze(this.emissionsPubSub,e).pipe(I)):this.externalEmissions.emit(e),n=this.inspector,r=this.inspectionSubject;return n===void 0||r===void 0?t:t.pipe(tn(()=>O(()=>n.publishUnsafe({_tag:`Emitted`,subject:r,emission:e,causedBy:this.causation()}))))}shutdownEmissions(){return this.closeEmissions()}closeEmissions(){if(this.externalEmissions!==void 0)return this.externalEmissions.close();let e=this.emissionsPubSub;return this.emissionsPubSub=ag,e===void 0||e===ag?L:Fe(e)}getOrCreateEmissions(){return V(()=>{let e=this.emissionsPubSub;return e===ag?k(void 0):e===void 0?on().pipe(U(e=>O(()=>{let t=this.emissionsPubSub;return t===ag?[void 0,!0]:t===void 0?(this.emissionsPubSub=e,[e,!1]):[t,!0]}).pipe(U(([t,n])=>n?Fe(e).pipe(An(t)):k(t))))):k(e)})}emissionsStream(){return Nt(this.getOrCreateEmissions().pipe(P(e=>e===void 0?Ii:xr(e))))}setAndPublishSnapshot(e){return V(()=>{this.flushPendingChanges();let t={revision:this.current.revision+1,snapshot:e,terminalizing:!0,changes:this.current.changes};return this.current=t,this.notifySnapshotObservers(),this.publishSnapshot(t).pipe(U(e=>this.completeChanges(e)),I)})}setActiveState(e){return V(()=>this.commitActiveState(e)??L)}pollCompiledMessage(){let e=zh(this.mailbox);return R(e)&&(this.inFlightMessage=Ah(e.value)?e.value:void 0),e}beginCompiledMessage(e){this.inFlightMessage=Ah(e)?e:void 0}completeCompiledMessage(e){Mh(this.inFlightMessage,e),this.inFlightMessage=void 0}compiledState(){return this.current.snapshot.state}commitCompiledState(e){return this.commitActiveState(e,!0)}commitActiveState(e,t=!1){let n=this.current;if(n.terminalizing||n.snapshot.status!==`active`)return;let r=n.pendingChanges;r!==void 0&&(n.pendingChanges=void 0);let i={status:`active`,state:e},a={revision:n.revision+1,snapshot:i,terminalizing:!1,changes:n.changes};return this.current=a,a.changes!==void 0&&(r===void 0?t?a.pendingChanges=[a]:ti(a.changes,[a]):(r.push(a),t?a.pendingChanges=r:ti(a.changes,r))),this.notifySnapshotObservers(),this.options.onSnapshot===void 0?void 0:Jh(this.options.onSnapshot,i)}notifySnapshotObservers(){if(this.snapshotObservers!==void 0)for(let e of this.snapshotObservers)e()}scheduleChangesFlush(e){this.changesFlushScheduled||this.current.pendingChanges===void 0||(this.changesFlushScheduled=!0,e.scheduleTask(()=>{this.changesFlushScheduled=!1,this.flushPendingChanges()},0))}flushPendingChanges(){let e=this.current,t=e?.pendingChanges;t!==void 0&&e.changes!==void 0&&(e.pendingChanges=void 0,ti(e.changes,t))}updateState(e){return V(()=>{let t=this.current;return t.terminalizing||t.snapshot.status!==`active`?L:e(t.snapshot.state).pipe(U(e=>{let n=this.current;return n.terminalizing||n.revision!==t.revision?L:this.setActiveState(e)}))})}getOrCreateChanges(){return V(()=>{let e=this.current;return e.snapshot.status===`active`?e.changes===void 0?on({replay:1}).pipe(U(e=>O(()=>{let t=this.current;return t.snapshot.status===`active`?t.changes===void 0?(this.current={...t,changes:e},[e,!1]):[t.changes,!0]:[void 0,!0]}).pipe(U(([t,n])=>n?Fe(e).pipe(An(t)):k(t))))):k(e.changes):k(void 0)})}changesStream(){let e=this;return Nt(ce(function*(){let t=yield*e.getOrCreateChanges();if(t===void 0)return gt(e.current.snapshot);let n=yield*en(t),r=e.current;return r.snapshot.status===`active`?gt(r.snapshot).pipe(C(nt(Wt(Jt(n))).pipe(ne(e=>e.revision>r.revision),Je(e=>e.snapshot)))):gt(r.snapshot)}))}},Dg=class{scope;ownedChildren;process;executionState;constructor(e,t,n){this.scope=e,this.ownedChildren=t,this.process=n}poll(){return dr(this.process.pollCompiledMessage(),jh)}pollMessage(){return this.process.pollCompiledMessage()}beginMessage(e){this.process.beginCompiledMessage(e)}state(){return this.process.compiledState()}completeMessage(e){this.process.completeCompiledMessage(e)}commit(e){return this.process.commitCompiledState(e)}runAfterChanges(e){return this.process.flushPendingChanges(),e}},Og=wt(function*(e,t){let n=t.sessionId??(yield*t.runtime.nextSessionId),r=yield*ar(),i=e.execution,a=new Eg(e,t,r,n);return yield*(i.initialSync!==void 0&&t.onReady===void 0&&t.onSnapshot===void 0?a.initializeCompiledSync():a.initialize()).pipe(st(e=>dt(e)?a.shutdownEmissions().pipe(B(t.inspectionRoot===!0&&t.runtime.inspection!==void 0?t.runtime.inspection.close:L)):L))}),kg=(e,t,n,r)=>new Eg(e,t,n,r).initializeCompiledSync(),Ag=wt(function*(e,t){let{detached:n,id:r,onOutcome:i,onReady:a,onReadySync:o,onSnapshot:c,onStop:l,onStopSync:u,parent:d,runtime:f,sendParent:p}=t,m=t.sessionId??(yield*f.nextSessionId),h=r??m,g=f.inspection,_=g===void 0?void 0:Xh(e,h,m),v=g===void 0||t.activity===void 0?void 0:{...t.activity,sessionId:m},y,b,x=Vh(),S=t.emissions??og(),w=yield*Re(),ee=yield*Re(),T=Lt(ee).pipe(Mi,I),te=!0,E,re=$t(w,{_tag:`Stopped`}).pipe(I),ie=(e,t)=>V(()=>Hh(x,e,t)?L:W(new Su)),ae=g===void 0?void 0:(e,t,n,r)=>V(()=>{let i=g.isActive()?Qh(g,_,e,t,n,r):r===void 0?e:{[kh]:!0,event:e,deferred:r};return ie(i,()=>$h(g,_,i))}),oe=e.execution?._tag===`Compiled`?e=>yi(t=>Re().pipe(U(n=>(g===void 0?ie({[kh]:!0,event:e,deferred:n}):ae(e,void 0,void 0,n)).pipe(B(t(Lt(n))))),P(e=>e))):void 0,se={id:h,sessionId:m,stop:V(()=>te?re:re.pipe(B(Qe))),send:g===void 0?e=>ie(e):e=>ae(e,void 0,void 0),...g===void 0?void 0:{inspectionSubject:_,sendInspected:ae}},{changes:D,close:le,get:ue,owned:de,sendTo:fe,spawn:pe,stop:me}=sg;Lh(e.execution)||({changes:D,close:le,get:ue,owned:de,sendTo:fe,spawn:pe,stop:me}=yield*lg(se,f,void 0,oe===void 0?void 0:e=>oe(e)));let he=e=>s(e)?L:(g!==void 0&&g.publishUnsafe(v===void 0?{_tag:`StartFailed`,subject:_,cause:e.cause}:{_tag:`ActivityStopped`,subject:v.owner,activity:v,exit:e}),le(e).pipe(B(S.close()),B(t.inspectionRoot===!0&&g!==void 0?g.close:L))),ge=u===void 0?l??L:O(()=>u(Xe)),ve=g===void 0?ig:()=>Zh(E,te),ye=p??(d===void 0?ng:g===void 0?d.send:e=>Ih(d,e,_,ve())),be=g===void 0?S.emit:e=>S.emit(e).pipe(tn(()=>O(()=>g.publishUnsafe({_tag:`Emitted`,subject:_,emission:e,causedBy:ve()})))),xe={self:se,parent:d,spawn:pe,sendParent:ye,emit:be,sendTo:g===void 0?((e,t)=>Fh(e)?e.send(t):fe(e,t)):((e,t)=>Fh(e)?Ih(e,t,_,ve()):fe(e,t,_,ve())),stopChild:me,failCause:e=>$t(w,{_tag:`Failure`,cause:e}).pipe(I),inspectInitial:g===void 0?rg:(e,t=[])=>{y=e,b=t}};g!==void 0&&g.publishUnsafe(v===void 0?{_tag:`Created`,subject:_,parent:d?.inspectionSubject,origin:t.origin??{_tag:`Root`},definition:e.inspection?.definition}:{_tag:`ActivityStarted`,subject:v.owner,activity:v});let Se=yield*e.initial(xe).pipe(st(he),fn(O(()=>{te=!1}))),Ce=yield*Ir({revision:0,terminalizing:!1,changes:void 0,snapshot:{status:`active`,state:Se}});v===void 0&&g?.publishUnsafe({_tag:`Initialized`,subject:_,snapshot:{status:`active`,state:Se},initialEntryPaths:y??[],microsteps:Ch({microsteps:b??[]})});let we=c===void 0?e=>e.changes===void 0?k(e):ze(e.changes,[e]).pipe(An(e)):e=>{let t=e.changes===void 0?k(e):ze(e.changes,[e]).pipe(An(e)),n=e.snapshot;return n.status===`active`?t.pipe(tn(()=>Jh(c,n))):t},Te=e=>e.changes===void 0?L:ze(e.changes,Ln(void 0)).pipe(I),Ee=e=>e.snapshot.status===`active`?k(e):Te(e).pipe(An(e)),De=e=>_i(Ce).pipe(U(t=>t.revision===e.revision?we(e).pipe(U(Ee)):k(void 0))),Oe=e=>sr(Ce,t=>t.terminalizing?k([void 0,t]):P(e(t.snapshot),e=>{if(e===void 0)return[void 0,t];let n={revision:t.revision+1,snapshot:e,terminalizing:!1,changes:t.changes};return[n,n]})).pipe(U(e=>e===void 0?k(void 0):De(e)),P(e=>e?.snapshot)),ke=e=>ri(Ce,t=>t.terminalizing||t.snapshot.status!==`active`?[void 0,t]:[{revision:t.revision+1,snapshot:e(t.snapshot),terminalizing:!0,changes:t.changes},{...t,terminalizing:!0}]).pipe(P(e=>e?.snapshot)),Ae=e=>mn(Ce,t=>({revision:t.revision+1,snapshot:e,terminalizing:!0,changes:t.changes})).pipe(U(we),U(Ee),I),je=g===void 0?e=>Oe(t=>k(t.status===`active`?{status:`active`,state:e}:void 0)).pipe(I):t=>_i(Ce).pipe(U(n=>Oe(e=>k(e.status===`active`?{status:`active`,state:t}:void 0)).pipe(tn(r=>O(()=>{e.inspection?.kind!==`Machine`&&r!==void 0&&g.publishUnsafe({_tag:`StateChanged`,subject:_,before:n.snapshot.state,after:t,causedByDeliveryId:E!==void 0&&Ah(E)?E.inspection?.deliveryId:void 0})})))),I),Me=(e,n,r)=>{let a=i===void 0||e.status===`stopped`&&t.skipStoppedOutcome===!0?L:V(()=>i(qh(e))).pipe(Mi,I),o=g===void 0?S.close():S.close().pipe(B(O(()=>g.publishUnsafe(v===void 0?{_tag:`Terminated`,subject:_,snapshot:e}:{_tag:`ActivityStopped`,subject:v.owner,activity:v,exit:e.status===`stopped`?an():n}))));return Rn(O(()=>Wh(x)).pipe(B(le(n)),B(Ae(e)),B(o),B(O(()=>{dt(n)?Nh(E,n.cause):Ph(E),E=void 0})),B(a),B(ge),B(t.inspectionRoot===!0&&g!==void 0?g.close:L),B(r)))},Ne=ke(e=>({status:`stopped`,state:e.state})),Fe=e=>ke(t=>({status:`error`,state:t.state,cause:e})),Ie=e=>ke(t=>({status:`done`,state:t.state,output:e})),Le=e=>Me(e,vi,Ut(ee,new Su)),Be=(e,t)=>{let n=qt(t);return Me(e,n,_e(ee,t))},Ve=(e,t)=>{let n=Ln(t);return Me(e,n,$t(ee,t))},He=Rn(re.pipe(B(T))),Ue=e.execution?._tag===`Compiled`?{receiveMessage:Uh(x).pipe(tn(e=>O(()=>{E=Ah(e)?e:void 0}))),pollMessage:O(()=>zh(x)).pipe(tn(e=>O(()=>{R(e)&&(E=Ah(e.value)?e.value:void 0)}))),completeMessage:e=>{Mh(E,e),E=void 0}}:void 0,We=g===void 0||e.execution?._tag===`Compiled`?Uh(x).pipe(P(jh)):Uh(x).pipe(tn(e=>O(()=>{E=e})),P(jh)),Ge=g===void 0||e.execution?._tag===`Compiled`?O(()=>zh(x)).pipe(P(dr(jh))):O(()=>zh(x)).pipe(tn(e=>O(()=>{R(e)&&(E=e.value)})),P(dr(jh))),Ke=g===void 0?e=>Oe(t=>t.status===`active`?e(t.state).pipe(P(e=>({status:`active`,state:e}))):k(void 0)).pipe(I):t=>_i(Ce).pipe(U(n=>Oe(e=>e.status===`active`?t(e.state).pipe(P(e=>({status:`active`,state:e}))):k(void 0)).pipe(tn(t=>O(()=>{e.inspection?.kind!==`Machine`&&t?.status===`active`&&g.publishUnsafe({_tag:`StateChanged`,subject:_,before:n.snapshot.state,after:t.state,causedByDeliveryId:E!==void 0&&Ah(E)?E.inspection?.deliveryId:void 0})})))),I),qe={...xe,...e.execution?._tag===`Compiled`&&!e.execution.childless?{ownedChildren:de}:void 0,...Ue,receive:We,poll:Ge,state:_i(Ce).pipe(P(e=>e.snapshot.state)),setState:je,updateState:Ke},Ye=sr(Ce,e=>e.snapshot.status===`active`?e.changes===void 0?on({replay:1}).pipe(P(t=>[t,{...e,changes:t}])):k([e.changes,e]):k([void 0,e])),A=Nt(ce(function*(){let e=yield*Ye;if(e===void 0)return gt((yield*_i(Ce)).snapshot);let t=yield*en(e),n=yield*_i(Ce);return n.snapshot.status===`active`?gt(n.snapshot).pipe(C(nt(Wt(Jt(t))).pipe(ne(e=>e.revision>n.revision),Je(e=>e.snapshot)))):gt(n.snapshot)})),Xe={id:h,sessionId:m,...g===void 0?void 0:{inspectionSubject:_,sendInspected:ae},state:_i(Ce).pipe(P(e=>e.snapshot.state)),snapshot:_i(Ce).pipe(P(e=>e.snapshot)),changes:A,emissions:S.stream,join:Lt(ee),stop:He,send:se.send,...oe===void 0?void 0:{[Oh]:oe},child:ue,childChanges:D};o!==void 0&&!o(Xe)?yield*re:a!==void 0&&(yield*a(Xe,re)),c!==void 0&&(yield*Jh(c,{status:`active`,state:Se}));let Ze=e=>{switch(e._tag){case`Stopped`:return Ne;case`Done`:return Ie(e.output);case`Failure`:return Fe(e.cause)}},$e=(e,t)=>{switch(e._tag){case`Stopped`:return Le(t);case`Done`:return Ve(t,e.output);case`Failure`:return Be(t,e.cause)}},et=e=>n===!0?At(e,{startImmediately:!0}):Li(e,{startImmediately:!0}),tt=yield*Pe(w),rt=xi(tt)?yield*yi(t=>t(V(()=>e.run(qe))).pipe(Mi,U(e=>$t(w,dt(e)?{_tag:`Failure`,cause:e.cause}:{_tag:`Done`,output:e.value})))).pipe(et):void 0;return yield*et(yi(e=>ce(function*(){let t=R(tt)?yield*tt.value:yield*e(Lt(w)),n=yield*Ze(t);return rt!==void 0&&(yield*ci(rt)),n===void 0?yield*T:yield*$e(t,n)}))),Xe}),jg=((e,t)=>e.execution?._tag===`Compiled`?Og(e,t):Ag(e,t)),Mg=Yh(jg,kg),Ng=new WeakMap,Pg=e=>V(()=>{e.closed=!0;let t=Array.from(e.live).reverse();return e.live.clear(),ee(t,e=>e.stop,{discard:!0})}),Fg=()=>{let e=new Set,t={live:e,hooks:{onReadySync:n=>!t.closed&&(e.add(n),!0),onStopSync:t=>{e.delete(t)}},closed:!1};return t},Ig=e=>U(Pt,t=>{let n=Ng.get(t);if(n!==void 0)return e(n.hooks);let r=Fg();return Ng.set(t,r),B(He(t,Pg(r)),e(r.hooks))});wt(function*(e,t,n){let r=yield*Mg,i=n===void 0?{detached:!0,runtime:r}:{...n,detached:!0,runtime:r};return t===`generic`?yield*Ig(t=>Ag(e,{...i,...t})):t===`compiled`?e.execution?._tag===`Compiled`?yield*Ig(t=>Og(e,{...i,...t})):yield*Qn(Error(`Machine cannot force the compiled runtime for generic process logic`)):yield*Ig(t=>jg(e,{...i,...t}))});var Lg=wt(function*(e,t){let n=yield*Mg;return yield*Ig(r=>jg(e,t===void 0?{detached:!0,runtime:n,...r}:{...t,detached:!0,runtime:n,...r}))}),Rg=wt(function*(e,t,n){let r=yield*Mg,i=yield*r.nextSessionId,a=yield*bh(i);r.inspection=a;let o=og(),s=yield*Re(),c=n===void 0?{detached:!0,emissions:o,runtime:r,sessionId:i,inspectionRoot:!0,origin:{_tag:`Root`}}:{...n,detached:!0,emissions:o,runtime:r,sessionId:i,inspectionRoot:!0,origin:{_tag:`Root`}},l=yield*Oi(Ig(n=>{let r={...c,...n};return t===`generic`?Ag(e,r):t===`compiled`?e.execution?._tag===`Compiled`?Og(e,r):Qn(Error(`Machine cannot force the compiled runtime for generic process logic`)):jg(e,r)}).pipe(st(e=>Se(s,e))));return{id:n?.id??i,sessionId:i,changes:Nt(Lt(s).pipe(P(e=>e.changes))),emissions:o.stream,inspection:a.stream,start:l}}),zg=((e,t)=>Rg(e,`auto`,t));A({_tag:T(`MachineSnapshot`),version:T(2),active:pn(A({path:F,value:M(Tt)})),completed:M(pn(A({path:F,output:M(Tt)}))),history:M(Cr(F,A({mode:Ri([`shallow`,`deep`]),active:pn(F),values:Cr(F,Tt)})))});var Bg=(e,t,n)=>{let r=X(e,n);if(r.type===`compound`){let r=Hf(e,t,n);if(r===void 0)throw Error(`Machine expected completed state "${n}" to have an active child`);return Bg(e,t,r)}return r.output},Vg=(e,t)=>ce(function*(){let n=yield*Nf(e,t),r=new Map,i=new Set,a=t.completed??[];if(!Array.isArray(a))throw Error(`Machine snapshot completion metadata must be an array`);for(let t of a){if(typeof t!=`object`||!t||typeof t.path!=`string`)throw Error(`Machine snapshot contains malformed completion metadata`);let a=t.path;if(i.has(a))throw Error(`Machine snapshot contains duplicate completion "${a}"`);if(!n.active.has(a)||!Gf(e,n,a))throw Error(`Machine snapshot contains invalid completion "${a}"`);i.add(a);let o=Bg(e,n,a);if(o===void 0){if(t.output!==void 0)throw Error(`Machine snapshot contains an output for state "${a}" without an output schema`);r.set(a,void 0)}else r.set(a,yield*zd(e,o,t.output,{boundary:`output`,state:a}))}return wf(e,{...n,outputs:r})}).pipe(Jn(t=>Hg(e,t))),Hg=(e,t)=>{if(En(t))return Cn(Wn(t,t=>t instanceof J?t:new J({machineId:e.id,boundary:`configuration`,cause:hn(t)})));let n=Hr(t);return R(n)&&n.value instanceof J?W(n.value):W(new J({machineId:e.id,boundary:`configuration`,cause:t}))},Ug=e=>e.length===0?L:e.length===1?e[0]:yn(e,{discard:!0}),Wg=(e,t)=>({event:e.event,next:t(e.next),commands:e.commands,emittedEvents:e.emittedEvents,microsteps:e.microsteps.map(e=>({...e,transitions:e.transitions??[],next:t(e.next)})),done:e.done,output:e.output}),Gg=new WeakMap,Kg=e=>{let t=Gg.get(e);if(t!==void 0)return t;let n=Object.values(Y(e).handlers).some(e=>e.invoke!==void 0);return Gg.set(e,n),n},qg=k(z()),Jg=(e,t)=>{let n=uh(e),r=new WeakMap,i=t=>{let n=r.get(t.scope);return n===void 0&&(n=Fm(e,t.scope),r.set(t.scope,n)),n},a=n=>{if(!t)return;let r=n.state();return Om(e,r)?km(e,r,Dm).pipe(P(kn)):void 0},o=e=>V(()=>c(e)??qg),s=(e,t,r,a,s)=>{let c=a.commands.length===0?void 0:Im(a.commands,e.scope),l=a.emittedEvents.length===0?void 0:Lm(a.emittedEvents,i(e)),u=()=>{let i=V(()=>(t&&e.completeMessage({before:r,plan:Wg(a,n.snapshot),after:s}),a.done?k(kn(a.output)):o(e)));return l===void 0?i:l.pipe(B(i))},d=()=>{let t=e.commit(s),n=u(),r=t===void 0?n:t.pipe(B(n));return t===void 0&&l===void 0?r:e.runAfterChanges(r)};return c===void 0?d():e.runAfterChanges(c.pipe(B(V(d))))},c=(t,r)=>{let i=r;for(;;){let r;if(i!==void 0)r=i,i=void 0,t.beginMessage(r);else{let e=t.pollMessage();if(xi(e))return;r=e.value}let a=Ah(r),c=a?r.event:r,l=t.state(),u;try{u=n.plan(t.executionState??n.fromConfiguration(jf(e,l)),c,a,t.scope)}catch(e){return wu(e)}if(t.executionState=u.next,u.microsteps.length===0){a&&t.completeMessage({before:l,plan:Wg(u,n.snapshot),after:l});continue}let d=n.snapshot(u.next);if(u.commands.length>0||u.emittedEvents.length>0||u.done)return s(t,a,l,u,d);let f=t.commit(d);if(f!==void 0)return t.runAfterChanges(f.pipe(B(V(()=>(a&&t.completeMessage({before:l,plan:Wg(u,n.snapshot),after:d}),o(t))))));a&&t.completeMessage({before:l,plan:Wg(u,n.snapshot),after:d})}};return{run:e=>Kh(a(e)??o(e),e.scope),runSync:(e,t)=>{let n=a(e);n!==void 0&&e.beginMessage(t);let r=n??c(e,t);return r===void 0?void 0:Kh(r,e.scope)}}},Yg=class{initialized=!1;initial;constructor(e){this.initial=e}},Xg=(e,t)=>{let n=uh(e);return r=>{let i=r.state();if(t&&Om(e,i))return km(e,i,Dm).pipe(P(kn));let a=r.scope,o=r.executionState,s=o instanceof Yg?o:new Yg;r.executionState=s;let c,l,u;return u=V(()=>{let t=r.pollMessage();if(xi(t))return l=void 0,k(z());let o=t.value,s=Ah(o),d=s?o.event:o,f=i,p;try{p=n.plan(l??n.fromConfiguration(jf(e,i)),d,s,a)}catch(e){return wu(e)}if(l=p.next,p.microsteps.length===0)return s&&r.completeMessage({before:f,plan:Wg(p,n.snapshot),after:i}),u;let m=p.microsteps.some(e=>e.changed),h=m?p.microsteps.flatMap(e=>e.exitPaths):[],g=new Map;if(m){for(let e of p.microsteps)if(e.changed)for(let t of e.entryPaths)g.set(t,e.event)}let _=n.toConfiguration(p.next),v=n.snapshot(p.next),y=[];if(p.commands.length>0&&y.push(Im(p.commands,a)),m){let e=r.ownedChildren.stopPaths(h);e!==void 0&&y.push(e)}let b=[];if(p.emittedEvents.length>0&&b.push(Lm(p.emittedEvents,c??=Fm(e,a))),p.done)b.push(r.ownedChildren.stopAll());else if(m)for(let[t,n]of g){let i=wg(e,a,r.ownedChildren,_,[t],n);i!==void 0&&b.push(i)}let x=()=>{let e=r.commit(v);return i=v,e},S=()=>{let e=V(()=>(s&&r.completeMessage({before:f,plan:Wg(p,n.snapshot),after:v}),p.done?k(kn(p.output)):u));return b.length===0?e:Ug(b).pipe(B(e))},C=()=>{let e=x(),t=S(),n=e===void 0?t:e.pipe(B(t));return e===void 0&&b.length===0?n:r.runAfterChanges(n)};return y.length===0?C():r.runAfterChanges(Ug(y).pipe(B(V(C))))}),Kh(V(()=>{if(s.initialized)return u;let t=s.initial,o=t?.activeConfiguration??jf(e,i);l=t?.configuration??n.fromConfiguration(o);let c=wg(e,a,r.ownedChildren,o,t?.entryPaths??Sf(e,o),Dm);return s.initial=void 0,s.initialized=!0,c===void 0?u:c.pipe(B(u))}),a)}},Zg=e=>e.done?{state:e.state,done:!0,output:e.output}:{state:e.state,done:!1,output:void 0},Qg=(e,t)=>{let n=Kg(e),r=uh(e),i=t._tag===`Initial`?t.args:[],a=t._tag===`Initial`?r.initial:void 0,o=a===void 0?void 0:e=>{try{let t=a(i,e);e.inspectInitial(t.initialEntryPaths);let r=Zg(t);return n?{...r,executionState:new Yg({configuration:t.configuration,activeConfiguration:t.activeConfiguration,entryPaths:t.initialEntryPaths})}:r}catch(e){throw Tu(e)}},s=t=>a===void 0?Kh(Pm(Hp(e,t),...i).pipe(U(n=>{t.inspectInitial(n.initialEntryPaths,n.microsteps);let r=n.commands.length===0?void 0:Im(n.commands,t),i=n.emittedEvents.length===0?void 0:Lm(n.emittedEvents,Fm(e,t)),a=k(Zg(n));return r===void 0?i===void 0?a:i.pipe(B(a)):i===void 0?r.pipe(B(a)):r.pipe(B(i),B(a))})),t):l({try:()=>o(t),catch:Tu});return{inspection:{kind:`Machine`,definition:e},execution:{_tag:`Compiled`,childless:!n,...t._tag===`Initial`?{initial:s}:{},...o===void 0?{}:{initialSync:o},drain:n?{_tag:`Owned`,run:Xg(e,t._tag===`Resume`)}:{_tag:`Owned`,...Jg(e,t._tag===`Resume`)}},initial:n=>t._tag===`Resume`?Kh(Vg(e,t.snapshot),n):s(n).pipe(P(e=>e.state)),run:t=>Kh(ce(function*(){let{completeMessage:r,pollMessage:i,receiveMessage:a,state:o,setState:s}=t;if(r===void 0||i===void 0||a===void 0)return yield*Qn(Error(`Machine statechart started without acknowledged mailbox access`));let c,l=yield*o;if(Om(e,l))return yield*km(e,l,Dm);if(!n){let n,o=z(),u;for(;c===void 0;){let d=R(o)?o.value:yield*a;o=z();let f=Ah(d),p=f?d.event:d,m=l,h;try{h=Nm(e,sf(n??jf(e,l),t),p)}catch(e){return yield*wu(e)}if(n=h.next,h.microsteps.length>0){let n=wf(e,h.next);yield*Im(h.commands,t),yield*s(n),l=n,h.emittedEvents.length>0&&(yield*Lm(h.emittedEvents,u??=Fm(e,t))),h.done&&(c={output:h.output})}f&&r({before:m,plan:Wg(h,t=>wf(e,t)),after:l}),c===void 0&&(o=yield*i,xi(o)&&(n=void 0))}return c===void 0?yield*Qn(Error(`Machine process stopped receiving events before reaching a terminal configuration`)):c.output}let u=t.ownedChildren;if(u===void 0)return yield*Qn(Error(`Invoking statechart started without an owned child runtime`));let d=(n,r,i)=>wg(e,t,u,n,r,i)??L,f=e=>u.stopPaths(e)??L;return yield*ce(function*(){let n=yield*Nf(e,l);yield*d(n,Sf(e,n),Dm),n=void 0;let o=z(),p;for(;c===void 0;){let m=R(o)?o.value:yield*a;o=z();let h=Ah(m),g=h?m.event:m,_=l,v;try{v=Nm(e,sf(n??jf(e,l),t),g)}catch(e){return yield*wu(e)}if(n=v.next,v.microsteps.length>0){let n=v.microsteps.some(e=>e.changed),r=v.microsteps.flatMap(e=>e.exitPaths),i=new Map;for(let e of v.microsteps)if(e.changed)for(let t of e.entryPaths)i.set(t,e.event);let a=wf(e,v.next);if(yield*Im(v.commands,t),n&&(yield*f(r)),yield*s(a),l=a,v.emittedEvents.length>0&&(yield*Lm(v.emittedEvents,p??=Fm(e,t))),v.done)c={output:v.output},yield*u.stopAll();else if(n)for(let[e,t]of i)yield*d(v.next,[e],t)}h&&r({before:_,plan:Wg(v,t=>wf(e,t)),after:l}),c===void 0&&(o=yield*i,xi(o)&&(n=void 0))}return c===void 0?yield*Qn(Error(`Machine process stopped receiving events before reaching a terminal configuration`)):c.output}).pipe(st(()=>u.stopAll()))}),t)}},$g=new WeakMap,e_=(e,...t)=>{if(t.length>0)return Qg(e,{_tag:`Initial`,args:t});let n=$g.get(e);if(n!==void 0)return n;let r=Qg(e,{_tag:`Initial`,args:t});return $g.set(e,r),r},t_=(e,t)=>Qg(e,{_tag:`Resume`,snapshot:t}),n_=(e,...t)=>zg(e_(e,...t),e.id===void 0?void 0:{id:e.id}),r_=(e,t)=>Lg(t_(e,t),e.id===void 0?void 0:{id:e.id}),i_={atomic:[`schema`,`type`,`annotations`],final:[`schema`,`type`,`output`,`annotations`],compound:[`schema`,`type`,`states`,`annotations`],parallel:[`schema`,`type`,`output`,`states`,`annotations`],history:[`type`,`history`,`annotations`],choice:[`type`,`annotations`]},a_=[`title`,`description`,`documentation`],o_=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s_=(e,t)=>{let n=typeof t==`symbol`?`[${String(t)}]`:t===``?`<empty>`:String(t);return e===``?n:`${e}.${n}`},Q=(e,t,n)=>{throw Error(`${e} invalid state definition at "${t}": ${n}`)},c_=e=>Number.isFinite(Number(e)),l_=e=>e.length===0||e.some(e=>e===`untagged`)?`untagged`:e.every(e=>e===`tagged`)?`tagged`:`opaque`,u_=(e,t)=>{if(t.has(e))return`opaque`;if(On(e)||_n(e)||Ei(e)||Fn(e)||Jr(e)||oi(e))return`tagged`;if(ur(e))return typeof e.literal==`string`||typeof e.literal==`number`?`tagged`:`untagged`;let n=new Set(t).add(e);return Kn(e)?l_(e.types.map(e=>u_(e,n))):Dr(e)?u_(e.thunk(),n):Rr(e)?`opaque`:`untagged`},d_=(e,t=new Set)=>{if(t.has(e))return`opaque`;if(Wr(e)){let n=e.propertySignatures.find(({name:e})=>e===`_tag`)?.type;return n===void 0||pi(n)?`untagged`:u_(n,new Set(t).add(e))}let n=new Set(t).add(e);return Kn(e)?l_(e.types.map(e=>d_(e,n))):Dr(e)?d_(e.thunk(),n):Rr(e)?`opaque`:`untagged`},f_=e=>j(e)&&d_(Mr(e.ast))!==`untagged`,p_=(e,t,n)=>{let r=s_(t,n);return typeof n==`symbol`?Q(e,r,`state keys must be strings, not symbols`):typeof n==`number`?Q(e,r,`state keys cannot use numeric forms`):n===``?Q(e,r,`state keys cannot be empty`):n===`__proto__`?Q(e,r,`the state key "__proto__" is not allowed`):n.includes(`.`)?Q(e,r,`state keys cannot contain "."`):c_(n)?Q(e,r,`state keys cannot use numeric forms`):r},m_=(e,t,n,r)=>{(typeof n!=`object`||!n||Array.isArray(n))&&Q(e,t,`${r} must be a plain record`);let i=Object.getPrototypeOf(n);i!==Object.prototype&&i!==null&&Q(e,s_(t===`<root>`?``:t,`__proto__`),`${r} must not declare an implicit "__proto__" state key`)},h_=(e,t,n,r,i)=>{if(typeof n!=`object`||!n||Array.isArray(n)||!o_(n,r))return;let a=n[r];(typeof a!=`object`||!a||j(a)||a.type!==`history`)&&Q(e,`${t}.${r}`,i)},g_=(e,t,n,r)=>{let i=i_[r];for(let a of Reflect.ownKeys(n))i.includes(a)||Q(e,t,`${r} states cannot declare property "${String(a)}"`)},__=(e,t,n)=>{m_(e,`${t}.annotations`,n,`schema-less state annotations`);for(let r of Reflect.ownKeys(n))a_.includes(r)||Q(e,`${t}.annotations`,`schema-less state annotations cannot declare property "${String(r)}"`),typeof n[r]!=`string`&&Q(e,`${t}.annotations.${String(r)}`,`schema-less state annotation values must be strings`)},v_=(e,t,n,r,i=!1)=>{m_(e,n===``?`<root>`:n,t,`state trees`);for(let a of Reflect.ownKeys(t)){let o=i&&a===``?``:p_(e,n,a),s=t[a];if(j(s)){f_(s)||Q(e,o,`state schemas must decode to an object with a required PropertyKey _tag`);continue}m_(e,o,s,`state nodes`);let c=s.type,l=c===`history`?`history`:c===`choice`?`choice`:c===`parallel`?`parallel`:c===`final`?`final`:o_(s,`states`)?`compound`:`atomic`;if(g_(e,o,s,l),l===`history`||l===`choice`){r||Q(e,o,`${l} states must be declared below an active parent state`),o_(s,`annotations`)&&__(e,o,s.annotations),l===`history`&&o_(s,`history`)&&s.history!==`shallow`&&s.history!==`deep`&&Q(e,`${o}.history`,`history must be "shallow" or "deep"`);continue}let u=o_(s,`schema`);u&&!f_(s.schema)&&Q(e,`${o}.schema`,`state schemas must decode to an object with a required PropertyKey _tag`),u&&o_(s,`annotations`)&&Q(e,`${o}.annotations`,`schema-backed states must declare annotations on their schema`),!u&&o_(s,`annotations`)&&__(e,o,s.annotations),l===`atomic`&&o_(s,`type`)&&s.type!==`active`&&Q(e,`${o}.type`,`atomic state type must be "active"`),l===`final`&&s.type!==`final`&&Q(e,`${o}.type`,`final state type must be "final"`),l===`compound`&&o_(s,`type`)&&s.type!==`active`&&Q(e,`${o}.type`,`compound state type must be "active"`),l===`parallel`&&s.type!==`parallel`&&Q(e,`${o}.type`,`parallel state type must be "parallel"`),(l===`final`||l===`parallel`)&&o_(s,`output`)&&!j(s.output)&&Q(e,`${o}.output`,`state output must be an Effect Schema`),l===`compound`?(h_(e,o,s.states,`initial`,`active and choice child states cannot use the reserved target selector key "initial"`),u&&h_(e,o,s.states,`with`,`schema-backed compound child states cannot use the reserved local target selector key "with"`),v_(e,s.states,o,!0)):l===`parallel`&&(o_(s,`states`)||Q(e,`${o}.states`,`parallel states must declare child regions`),h_(e,o,s.states,`initial`,`active and choice child states cannot use the reserved target selector key "initial"`),v_(e,s.states,o,!0))}},y_=e=>typeof e==`object`&&e?Object.freeze({...e}):e,b_=e=>{let t={};for(let n of Object.keys(e)){let r=e[n];if(j(r)){Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!1,writable:!1});continue}let i=r,a={...i};`states`in i&&(a.states=b_(i.states)),`annotations`in i&&(a.annotations=y_(i.annotations)),Object.defineProperty(t,n,{value:Object.freeze(a),enumerable:!0,configurable:!1,writable:!1})}return Object.freeze(t)},x_=e=>b_(e),S_=(e,t=``)=>{if(j(e)||typeof e!=`object`||!e)return e;if(`~effect/Machine/State`in e&&e[`~effect/Machine/State`]===`~effect/Machine/State`&&`node`in e)return e.node;let n=e,r={...n};if(o_(n,`fields`)&&(o_(n,`schema`)&&Q(`Machine.state`,t,`declare fields or schema, not both`),m_(`Machine.state`,t,n.fields,`state fields`),o_(n.fields,`_tag`)&&Q(`Machine.state`,t,`state fields cannot declare _tag`),r.schema=ct(t,n.fields),delete r.fields),o_(n,`states`)){m_(`Machine.state`,t,n.states,`child states`);let e=Object.create(null);for(let r of Reflect.ownKeys(n.states))p_(`Machine.state`,t,r),e[r]=S_(n.states[r],r);r.states=e}return t===``?(v_(`Machine.state`,{"":r},``,!1,!0),x_({"":r})[``]):r},C_=`~effect/Machine`,w_=`~effect/Machine/ChildMachine`,T_={...Nr,...kt,[C_]:C_,toJSON(){return{_id:`Machine`}}},E_=(e,t)=>{let n=Object.create(T_);return n.states=e.states,n.root=e.root,n.events=e.events,n.internalEvents=e.internalEvents,n.emittedEvents=e.emittedEvents,n.parent=e.parent,n.input=e.input,n.id=e.id,n.initial=e.initial,n.initialDefinition=e.initialDefinition,n.stateNodes=e.stateNodes,n.handlers=t,Nd(e,n),n},D_=e=>e.kind===`none`?zu:Ru(e.kind,e.path,e.scope,e.updatePath),O_=e=>Object.freeze({path:e.path,kind:e.kind,scope:e.scope}),k_=e=>e.updatePath===void 0?e.kind===`update`&&e.path!==void 0?[e.path]:[]:[e.updatePath],A_=(e,t,n,r,i)=>{if(typeof e!=`object`||!e||!N(e,`target`)||typeof e.target!=`function`)throw Error(`Machine transition for state "${r}" on "${String(i)}" requires a target selector`);let a=e.target(t);if(!Bu(a))throw Error(`Machine transition for state "${r}" on "${String(i)}" must select exactly one target`);if(a.updatePath!==void 0){let e=n.byPath.get(a.updatePath);if(a.kind!==`state`&&a.kind!==`choice`||a.scope!==`local`&&a.scope!==`branch`||a.path===void 0||e===void 0||e.schema===void 0||e.type!==`compound`&&e.type!==`parallel`||!df(r,e.path)||!df(a.path,e.path))throw Error(`Machine updating owner "${a.updatePath}" must be a valued ancestor retained by source "${r}" and target "${a.path}"`)}return{...e,selection:a}},j_=(e,t,n)=>{if(t.kind===`none`){if(e!==void 0)throw Error(`Machine targetless transition resolver must return undefined`);return}if(t.kind===`update`){if(!Hu(e)||e.path!==t.path)throw Error(`Machine state update for "${t.path}" must return its selected update builder`);return}if(t.updatePath!==void 0){if(!Wu(e)||e.update.path!==t.updatePath)throw Error(`Machine target updating "${t.updatePath}" must return target construction .update(...)`)}else if(Wu(e))throw Error(`Machine combined target requires an updating owner declaration`);if(e===void 0)return;let r=Wu(e)?e.target:e,i=typeof r==`object`&&r&&N(r,`path`)&&typeof r.path==`string`?r.path:void 0,a=t.path===void 0?void 0:n.byPath.get(t.path),o=(t.scope===`local`||t.scope===`branch`)&&(a?.type===`compound`||a?.type===`parallel`);if(i===void 0||i!==t.path&&!(o&&df(i,t.path)))throw Error(`Machine transition resolver selected "${t.path}" but constructed "${i??`<invalid>`}"`)},M_=(e,t,n,r,i)=>{let a={...t,root:i===``?t.state:t.ancestors[``],decline:Zu};delete a.target;let o=e.resolve(a,n);if(Qu(o)){if(e.declinable!==!0)throw Error(`Machine transition for state "${i}" returned decline without declaring declinable: true`);return o}return j_(o,e.selection,r),o},N_=e=>e.kind===`update`?void 0:e.path,P_=e=>{let t=Number(e);return Number.isInteger(t)&&t>=0&&t<4294967295&&String(t)===e},F_=(e,t,n)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Machine branching transition for state "${t}" on "${String(n)}" requires a branch record`);if(Object.getOwnPropertySymbols(e).length>0)throw Error(`Machine branching transition for state "${t}" on "${String(n)}" cannot use symbol keys`);let r=Object.keys(e);if(r.length===0)throw Error(`Machine branching transition for state "${t}" on "${String(n)}" requires a branch`);return Object.freeze(r.map(r=>{if(r.length===0||P_(r))throw Error(`Machine branching transition for state "${t}" on "${String(n)}" requires non-index string branch keys`);let i=e[r];if(typeof i!=`object`||!i||!N(i,`target`))throw Error(`Machine transition branch "${r}" requires a target selection`);let{target:a,title:o}=i;if(!Bu(a))throw Error(`Machine transition branch "${r}" must select exactly one target`);if(o!==void 0&&(typeof o!=`string`||o.length===0))throw Error(`Machine transition branch "${r}" title must be a non-empty string`);return Object.freeze({key:r,title:o??r,selection:D_(a)})}))},I_=(e,t,n,r={},i)=>{let a=ep(r);if(e.kind===`choice`&&e.updatePath!==void 0){let{update:n,...r}=a;if(Reflect.ownKeys(r).length>0)throw Error(`Machine pseudo-state construction accepts no data`);let i=t.byPath.get(e.path);return Uu(rd(i.path,i.parent),rp(t,e.updatePath,n))}if(e.kind===`none`||e.kind===`history`||e.kind===`choice`){if(Reflect.ownKeys(a).length>0)throw Error(`Machine pseudo-state construction accepts no data`);if(e.kind===`none`)return;let n=t.byPath.get(e.path);return e.kind===`history`?$u(n.path,n.parent):rd(n.path,n.parent)}if(e.kind===`update`)return rp(t,e.path,a);if(e.path===``){if(Reflect.ownKeys(a).some(e=>e!==`input`))throw Error(`Machine initialize branches accept input only`);if(n.initialize===void 0)throw Error(`Machine root initialization is unavailable`);return n.initialize(a.input)}if(e.updatePath!==void 0){let{update:n,...r}=a;return Uu(np(t,e.path,r,i),rp(t,e.updatePath,n))}return np(t,e.path,a,i)},L_=(e,t,n,r,i)=>Object.freeze(Object.fromEntries(e.map((e,a)=>[e.key,o=>Gu(t,a,e.key,e.selection.kind===`none`?Ju():I_(e.selection,n,r,o,i))]))),R_=(e,t,n)=>{if(t.kind===`none`){if(!Yu(e))throw Error(`Machine targetless branch must return its selected targetless builder`)}else{if(e===void 0)throw Error(`Machine transition branch selected "${t.path}" without constructing its target`);j_(e,t,n)}},z_=(e,t)=>({...e,root:t===``?e.state:e.ancestors[``]}),B_=(e,t,n,r)=>{if(typeof e!=`object`||!e)throw Error(`Machine transition for "${n}" must be an object`);let i={...e},a=[`target`,`update`,`initialize`,`history`,`none`,`branches`,`data`,`decoded`,`resolve`,`guard`,`reenter`,`declinable`];for(let e of Reflect.ownKeys(i))if(typeof e!=`string`||!a.includes(e))throw Error(`Machine transition contains an unknown field`);for(let e of[`resolve`,`guard`])if(i[e]!==void 0&&typeof i[e]!=`function`)throw Error(`Machine transition ${e} must be a function`);let o=typeof i.guard==`function`?i.guard:void 0,s=typeof i.resolve==`function`?i.resolve:void 0;if(i.decoded!==void 0&&typeof i.decoded!=`boolean`)throw Error(`Machine decoded must be a boolean construction flag`);let c=Object.prototype.hasOwnProperty.call(i,`data`);if(i.decoded===!0&&!c)throw Error(`Machine decoded construction requires data`);if(c&&s!==void 0)throw Error(`Machine data and resolve are mutually exclusive`);let l=i.data,u=typeof l==`function`?l:()=>l,d=o!==void 0,f=d||i.declinable===!0;if(typeof i.branches==`string`){let e=t.branches.get(i.branches);if(e===void 0||s===void 0)throw Error(`Machine branching transition requires a registered group and resolver`);if([`target`,`update`,`initialize`,`history`,`none`,`data`,`decoded`].some(e=>i[e]!==void 0))throw Error(`Machine branching transition cannot redeclare its destination`);let a=Object.fromEntries(Object.entries(e).map(([e,i])=>[e,{title:i.title,target:A_({target:()=>up(t,i)},void 0,r,n,e).selection}]));return{branches:()=>a,reenter:i.reenter,declinable:f,resolve:(e,t)=>d&&!o(e)?Zu():s(e,t)}}let p=up(t,i);if(s!==void 0&&p.kind!==`none`)throw Error(`Machine advanced construction requires a declared branch group`);let m=i.initialize,h=m!==void 0;if(h&&(c||i.decoded!==void 0))throw Error(`Machine initialize accepts machine input instead of data`);if(h&&!t.input&&m!==!0)throw Error(`Machine initialize requires true when the machine declares no input`);let g=t.input?typeof m==`function`?m:()=>m:()=>void 0;return{target:()=>p,reenter:i.reenter,declinable:f,resolve:(e,a)=>{if(d&&!o(e))return Zu();if(s!==void 0)return s(e,a);if(h)return I_(p,r,t,{input:g(e)});let l=u(e);return I_(p,r,t,p.updatePath===void 0?{...c?{data:l}:{},...i.decoded===void 0?{}:{decoded:i.decoded}}:p.kind===`choice`?{update:{data:l,decoded:i.decoded}}:{...l.target===void 0?{}:{data:l.target,decoded:i.decoded},update:{data:l.update,decoded:i.decoded}},n)}}},V_=(e,t,n,r,i)=>{let a=B_(e,r,n,t);if(typeof a!=`object`||!a)throw Error(`Machine transition for state "${n}" on "${String(i)}" must be an object`);let o=a,s=o.reenter===!0,c=o.declinable===!0;if(N(o,`branches`)){let e=o;if(typeof e.branches!=`function`||typeof e.resolve!=`function`)throw Error(`Machine branching transition for state "${n}" on "${String(i)}" requires branches and resolve`);let a=e.resolve,l=F_(e.branches(),n,i),u=Object.freeze({}),d=(e,o)=>{let s={...e,root:n===``?e.state:e.ancestors[``],decline:Zu};delete s.target,s.select=L_(l,u,t,r,n);let d=a(s,o);if(Qu(d)){if(!c)throw Error(`Machine branching transition for state "${n}" on "${String(i)}" returned decline without declaring declinable: true`);return{result:d,branchIndex:-1,branchKey:void 0}}if(!Ku(d)||d.owner!==u)throw Error(`Machine branching transition for state "${n}" on "${String(i)}" must select one declared branch`);let f=l[d.branchIndex];if(f===void 0||d.branchKey!==f.key)throw Error(`Machine branching transition returned invalid branch evidence`);return R_(d.result,f.selection,t),{result:d.result,branchIndex:d.branchIndex,branchKey:d.branchKey}};return{reenter:s,declinable:c,targets:[...new Set(l.flatMap(e=>N_(e.selection)===void 0?[]:[e.selection.path]))],branches:l.map(e=>Object.freeze({type:`branch`,key:e.key,title:e.title,target:N_(e.selection),selection:O_(e.selection),updates:k_(e.selection)})),evaluate:d,transition:(e,t)=>d(e,t).result}}let l=A_(a,void 0,t,n,i),u=(e,r)=>({result:M_(l,e,r,t,n),branchIndex:0,branchKey:void 0});return{reenter:s,declinable:c,targets:N_(l.selection)===void 0?[]:[l.selection.path],branches:[{type:`direct`,target:N_(l.selection),selection:O_(l.selection),updates:k_(l.selection)}],evaluate:u,transition:(e,t)=>u(e,t).result}},H_=(e,t,n,r)=>{let i=Object.create(null);for(let a of Reflect.ownKeys(e))i[a]=V_(e[a],t,n,r,a);return i},U_=(e,t,n,r)=>{let i=(Array.isArray(e)?e:[e]).map(e=>{let i=dp(r,e,n,e=>z_(e,n));for(let e of[`onElement`,`onDone`,`onFailure`,`onSnapshot`])i[e]!==void 0&&(i[e]=V_(i[e],t,n,r,e));return Sp(i,n)});return wp(i,n),Array.isArray(e)?Object.freeze(i):i[0]},W_=(e,t,n,r,i,a)=>{for(let o of Object.keys(a)){let s=r===``?o:`${r}.${o}`;if(!N(n,o))throw Error(`Machine received handler for unknown state "${s}"`);let c=a[o];if(typeof c!=`object`||!c)throw Error(`Machine expected state "${s}" handler to be an object`);let{states:l,...u}=c;typeof u.history==`object`&&u.history!==null&&(u.history=Object.freeze(Object.fromEntries(Object.entries(u.history).map(([e,t])=>[e,typeof t==`object`&&t?Object.freeze({...t}):t]))));let d=u.on;if(typeof d==`object`&&d&&(u.on=H_(d,t,s,i)),u.always!==void 0&&(u.always=V_(u.always,t,s,i,`always`)),u.onDone!==void 0&&(u.onDone=V_(u.onDone,t,s,i,`done`)),u.choice!==void 0&&(u.choice=V_(u.choice,t,s,i,`choice`)),u.invoke!==void 0&&(u.invoke=U_(u.invoke,t,s,i)),t.byPath.get(s)?.type===`choice`&&(typeof u.choice!=`object`||u.choice===null||!N(u.choice,`transition`)||typeof u.choice.transition!=`function`||!N(u.choice,`targets`)||!Array.isArray(u.choice.targets)||u.choice.targets.length===0))throw Error(`Machine choice state "${s}" requires a transition`);if(e[s]=u,l!==void 0){let r=ad(s,n[o]);if(r.states===void 0)throw Error(`Machine expected state "${s}" to declare child states`);if(typeof l!=`object`||!l)throw Error(`Machine expected state "${s}" child handlers to be an object`);W_(e,t,r.states,s,i,l)}}},G_=e=>e===``?op:e,K_=e=>{let t=!1;for(let n of e.stateNodes.byPath.values())if(n.type===`choice`){t=!0;break}if(!t)return;let n=ld(e),r=new Map;for(let e of n)e.trigger.type===`choice`&&r.set(e.source,e);for(let e of n)for(let t of e.branches){let n=t.updates[0],i=t.selection.path;if(t.selection.kind!==`choice`||n===void 0||i===void 0)continue;let a=[i],o=new Set;for(;a.length>0;){let t=a.shift();if(!o.has(t)){o.add(t);for(let i of r.get(t)?.branches??[]){let{kind:r,path:o}=i.selection;if(o!==void 0&&r!==`none`&&r!==`update`){if(r===`choice`)a.push(o);else if(!df(o,n)){let r=i.type===`branch`?`branch "${i.key}"`:`transition`;throw Error(`Machine transition from "${G_(e.source)}" updates "${G_(n)}" before choice "${t}", whose ${r} targets "${G_(o)}" outside that owner`)}}}}}}},q_=(e,t)=>(n=>{let r=xp(t.root,n),i=Object.assign(Object.create(T_),e);if(Nd(e,i),i.states=Object.freeze({"":r.node}),i.stateNodes=od(i.states),i.stateNodes.byPath.get(``).schema===void 0&&n.root!==void 0)throw Error(`Machine schema-less root cannot construct data`);let a=i.stateNodes.byPath.get(``).schema===void 0?()=>void 0:yp(n.root);i.initial=e=>({...td(``,a({input:e})),input:{value:e}}),i.initialDefinition=Object.freeze({target:``,selection:Object.freeze({path:``,kind:`initial`,scope:`initial`})});let o=Object.create(null);W_(o,i.stateNodes,i.states,``,{...t,initialize:e=>i.initial(i.input===void 0?void 0:Zd(i,i.input,e))},{"":r.handlers});let s=E_(i,o);return K_(s),s}),J_=e=>{let t=S_(e),n=Y_();return Object.freeze({...n,"~effect/Machine/State":`~effect/Machine/State`,node:t})},Y_=()=>({path:(e=>e),get:((e,t)=>hd(e,t).pipe(dr(e=>e.value))),getWithParents:((e,t)=>{let n={};return hd(e,t,n).pipe(dr(e=>({value:e.value,parents:n})))}),getSnapshot:hd,matches:((e,t)=>R(hd(e,t)))}),X_=e=>{if(Object.hasOwn(e,`initial`)||Object.hasOwn(e,`initialConfiguration`))throw Error(`Machine initial edges and root data belong in handle`);let t=Object.freeze({"":e.root.node}),n=Object.create(kt);return n.states=t,n.root=e.root,n.events=e.events,n.internalEvents=e.internalEvents??Rd(`internal`,[]),n.emittedEvents=e.emittedEvents??Rd(`emitted`,[]),n.parent=e.parent,n.input=e.input,n.id=e.id,n.handlers=Object.create(null),n.handle=q_(n,cp(e.root,e)),Md(n),n},Z_=e=>{for(let[t,n]of Object.entries(e))if(Object.hasOwn(n,`_tag`))throw Error(`Machine event "${t}" fields cannot declare _tag`);return Object.keys(e).length===0?[]:[me(e)]},Q_=e=>Rd(`public`,Z_(e)),$_=(e,t)=>ev(e,t,e=>t.input===void 0?e_(t):e_(t,e)),ev=(e,t,n)=>({[w_]:w_,id:e,machine:t,[mp]:n}),tv=n_,nv=r_,rv=J_,iv=X_,av=Q_,ov=(e,t)=>{try{let n=Am(e,...t);return{machine:e,snapshot:n.done?{status:`done`,state:n.state,output:n.output}:{status:`active`,state:n.state}}}catch{return}},sv=(e,t)=>{try{let n=we(Vg(e,t));if(n._tag===`Failure`)return;let r=n.value;if(!Om(e,r))return{machine:e,snapshot:{status:`active`,state:r}};let i=we(km(e,r,Dm));return i._tag===`Success`?{machine:e,snapshot:{status:`done`,state:r,output:i.value}}:void 0}catch{return}},cv={spawn:()=>Qn(Error(`Child operations are unavailable in a planned snapshot`)),sendTo:()=>W(new Su),stop:()=>L},lv=(e,t)=>{if(e.snapshot.status!==`active`)return z();try{let n=e.machine,r=jf(n,e.snapshot.state);for(let e of Sf(n,r)){let i=Vf(n,e);for(let a of Tp(i?.invoke)){if(!(`child`in a)||a.child.id!==t.id||a.child.machine!==t.machine)continue;let i=t.machine,o;`input`in a&&(o=typeof a.input==`function`?a.input({...cf(r)??Up(n,r),children:cv,state:r.values.get(e),containingState:xf(n,r,e),ancestors:bf(n,r,e),event:Dm}):a.input);let s=ov(i,i.input===void 0?[]:[o]);return s===void 0?void 0:kn(s)}}return z()}catch{return}},uv=class extends Ar(`ChildNotActiveError`){},dv=new WeakMap,fv=new WeakMap,pv=e=>typeof e==`object`&&!!e&&fv.has(e),mv=e=>{if(typeof WeakRef>`u`||typeof FinalizationRegistry>`u`)return ln(e);let t=Ur(),n=new FinalizationRegistry(({entry:e,key:n})=>{let r=fi(t,n);R(r)&&r.value===e&&Dn(t,n)});return r=>{let i=fi(t,r);if(R(i)){let e=i.value.ref.deref();if(e!==void 0)return e}let a=e(r),o={ref:new WeakRef(a)};return Er(t,r,o),n.register(a,{key:r,entry:o}),a}},hv=(e,t)=>Gt(fr(t,e=>e.stop).pipe(tn(t=>O(()=>e.setSelf(he(t)))),U(()=>Qe))),gv=(e,t)=>hv(e,e.result(t).pipe(U(e=>e.start))),_v=(e,t,n)=>hv(e,nv(t,n)),vv=(e,t)=>`~effect-atom/atom/Atom/ServerValue`in e?e[Xn](t):t(e),yv=(e,t)=>{let n;return r=>{let i=e(r);return n!==void 0&&n.inputs.length===i.length&&n.inputs.every((e,t)=>Object.is(e,i[t]))||(n={inputs:i,value:t(...i)}),n.value}},bv=e=>{let t;return()=>(t===void 0&&(t={value:e()}),t.value)},xv=e=>e.snapshot,Sv=x(e=>e.registry).pipe(xn),Cv=e=>V(()=>{let t=e.pending.shift();return t===void 0?(e.draining=!1,L):B(t,Cv(e))}),wv=(e,t)=>{let n=e.get(t);return n===void 0&&(n={pending:[],draining:!1},e.set(t,n)),n},Tv=(e,t,n)=>d(n=>{let r=Vt(n(e),()=>void 0),i=t.get(n.registry);return i===void 0||!i.draining?r:o(dr(n.self(),Qr),()=>qi(!0))},(r,i)=>{let a=r.get(e),o=r.get(Sv),s=wv(t,o);It(a)||s.draining?(r.setSelf(qi(!0)),s.pending.push(mr(o,e).pipe(U(e=>n(e,i)),Mi,P(e=>{let t=Ve(e);r.setSelf(s.pending.length===0?t:Qr(t))}))),s.draining||(s.draining=!0,Xi(Cv(s)))):g(a)?r.setSelf(Vt(a,()=>void 0)):_t(n(a.value,i),{onExit:e=>r.setSelf(Ve(e))})}).pipe(vr),Ev=e=>x(t=>{let n=t(e);return It(n)?qi(n.waiting):g(n)?Ee(n.cause,{previous:t.self(),waiting:n.waiting}):n.value.status===`error`?Ee(n.value.cause,{previous:t.self(),waiting:n.waiting}):he(n.value.state,{waiting:n.waiting})}).pipe(ae(ir),et(yv(t=>[vv(e,t)],e=>Vt(e,e=>e.state)))),Dv=e=>x(t=>{let n=t(e);if(It(n))return qi(n.waiting);if(g(n))return Ee(n.cause,{previous:t.self(),waiting:n.waiting});if(xi(n.value)){let e=t.self();return R(e)&&g(e.value)?e.value:he(z(),{waiting:n.waiting})}return n.value.value.status===`error`?Ee(n.value.value.cause,{previous:t.self(),waiting:n.waiting}):he(kn(n.value.value.state),{waiting:n.waiting})}).pipe(ae(ir),et(yv(t=>[vv(e,t)],e=>Vt(e,dr(e=>e.state))))),Ov=(e,t)=>x(n=>{let r=n(e);if(It(r))return qi(r.waiting);if(g(r))return Ee(r.cause,{previous:n.self(),waiting:r.waiting});if(xi(r.value))return he(z());let i=r.value.value,a=zt(i.child(t)),o=_t(gn.pipe(B(i.childChanges(t).pipe(Ue(e=>O(()=>n.setSelf(he(e))))))));return n.addFinalizer(o),he(a)}).pipe(vr),kv=(e,t)=>Eh(e)?e[Th](()=>t(zt(e.snapshot))):_t(e.changes.pipe(Ue(e=>O(()=>t(e))))),Av=(e,t,n)=>{let r=x(t=>{let n=t(e);if(It(n))return qi(n.waiting);if(g(n))return Ee(n.cause,{previous:t.self(),waiting:n.waiting});if(xi(n.value))return he(z());let r=n.value.value;return t.addFinalizer(kv(r,e=>t.setSelf(he(kn(e))))),he(kn(zt(r.snapshot)))}).pipe(et(yv(()=>[],()=>{let e=n();return e===void 0?qi(!0):he(dr(e,xv),{waiting:!0})}))),i=new WeakMap,a=e=>R(e)?k(e.value):W(new uv({id:t.id})),o=Tv(e,i,(e,t)=>U(a(e),e=>e.send(t))),s=Tv(e,i,(e,t)=>U(a(e),e=>e.stop)),c=jv(e,n);return{ref:e,snapshot:r,result:Dv(r),send:o,stop:s,child:c}},jv=(e,t)=>{let n=new WeakMap;return r=>{let i=n.get(r.machine);if(i===void 0){let a=r.machine,o=ln(n=>{let r=$_(n,a);return Av(Ov(e,r),r,bv(()=>{let e=t();return e===void 0||xi(e)?e:lv(e.value,r)}))});i=e=>o(e),n.set(a,i)}return i(r.id)}},Mv=(e,t,n)=>{let r=vr(e),i=x(e=>{let t=e(r);if(It(t))return qi(t.waiting);if(g(t))return Ee(t.cause,{previous:e.self(),waiting:t.waiting});let n=t.value;e.addFinalizer(kv(n,t=>e.setSelf(he(t,{waiting:t.status===`active`}))));let i=zt(n.snapshot);return he(i,{waiting:i.status===`active`})}).pipe(et(yv(()=>[],()=>{let e=n();return e===void 0?qi(!0):he(xv(e),{waiting:!0})}))),a=new WeakMap,o=Tv(r,a,(e,t)=>e.send(t)),s=Tv(r,a,(e,t)=>e.stop),c=jv(yt(r,kn),()=>{let e=n();return e===void 0?void 0:kn(e)}),l={ref:r,snapshot:i,result:Ev(i),send:o,stop:s,child:c};return fv.set(l,t),l},Nv=(e,t)=>hd(e,t).pipe(dr(e=>e.value)),Pv=(e,t)=>hd(e,t),Fv=(e,t)=>yt(e,t).pipe(ae(ir),et(yv(t=>[vv(e,t)],e=>Vt(e,t)))),Iv=new WeakMap,Lv=(e,t,n,r)=>{let i=Iv.get(e);i===void 0&&(i=new Map,Iv.set(e,i));let a=i.get(t);a===void 0&&(a=new Map,i.set(t,a));let o=a.get(n);if(o!==void 0)return o;let s=r();return a.set(n,s),s},Rv=(e,t)=>Lv(e,`select`,t,()=>Fv(e.result,e=>Nv(e,t))),zv=(e,t)=>Lv(e,`selectSnapshot`,t,()=>Fv(e.result,e=>Pv(e,t))),Bv=(e,t)=>Lv(e,`selectChild`,t,()=>Fv(e.result,Qt(e=>Nv(e,t)))),Vv=(e,t)=>Lv(e,`selectSnapshotChild`,t,()=>Fv(e.result,Qt(e=>Pv(e,t)))),Hv=(e,t)=>Lv(e,`matches`,t,()=>Fv(e.result,e=>R(hd(e,t)))),Uv=(e,t)=>Lv(e,`matchesChild`,t,()=>Fv(e.result,$r(e=>R(hd(e,t))))),Wv=(e,t,n)=>{let r=e.atom(()=>tv(t,...n)),i=Mv(e.atom(e=>gv(e,r)),t,bv(()=>ov(t,n)));return dv.set(i,r),i},Gv=(e,t,n)=>Mv(e.atom(e=>_v(e,t,n)),t,bv(()=>sv(t,n))),Kv=(e,t,n)=>{let r={owner:e,source:t},i=Et(t,e=>e(r.source),{initialValueTarget:t}).pipe(ae((e,t)=>r.source.equals(e,t)),et(e=>vv(r.source,e)));return n!==void 0&&(i=i.pipe(te(n))),i},qv=(e,t)=>{let n=mv(t=>({bridge:e(t)})),r={};for(let e of Object.keys(t.atoms)){let i=t.atoms[e];r[e]=mv(r=>{let a=n(r);return Kv(a,i(a.bridge),t.label?.(r,e))})}return r},Jv=e=>{let t=((t,...n)=>Wv(e,t,n));return{make:t,factory:(e=>(...n)=>t(e,...n)),resume:((t,n)=>Gv(e,t,n)),family:((t,n)=>qv(n=>Wv(e,t,[n]),n))}},Yv=pv;Ct(2,Rv);var Xv=Ct(2,zv);Ct(2,Bv);var Zv=Ct(2,Vv);Ct(2,Hv),Ct(2,Uv);var Qv=Jv,$v=A({name:D,origin:Ml}),ey=pn($v);A({origin:Ml});var ty=A({incarnation:D,user:kl});un()(`@deslop/auth/services/tokens/schema/CurrentOwner`);var ny=A({...ty.fields,incarnation:H(D,u(k(`legacy`)))});A({client_name:M(F.check(Te(100))),redirect_uris:Al.fields.redirects,token_endpoint_auth_method:M(T(`none`))}),A({client_id:D.check(Te(2048)),redirect_uri:M(F),state:M(F)}),A({code_challenge:M(D),code_challenge_method:M(F),response_type:M(F),scope:M(F)});var ry=A({challenge:D,clientId:D,clientName:F,parent:M(D),redirectUri:D,state:M(D)}),iy=A({clientId:D,clientName:F});A({client_id:D.check(Te(2048)),scope:M(F)}),A({client_id:D,device_code:D,grant_type:T(`urn:ietf:params:oauth:grant-type:device_code`)}),A({grant_type:F}),je([A({client_id:D,code:D,code_verifier:D,grant_type:T(`authorization_code`),redirect_uri:M(F)}),A({client_id:M(F),grant_type:T(`refresh_token`),refresh_token:D})]);var ay=A({access_token:D,expires_in:wn,refresh_token:D,scope:T(`deslop`),token_type:T(`Bearer`)});me({Granted:{tokens:ay},Replayed:{message:F}});var oy=A({address:M(F),userAgent:M(F)}),sy=Ri([`Code`,`GitHub`,`Passkey`]),cy=A({address:M(F)}),ly=A({...ty.fields,client:F,credential:me({App:{clientId:D,expiresAt:wn,generation:Wi,hash:F,replaced:pn(F)},Browser:{expiresAt:wn,hash:F,via:sy}}),device:F,lastActive:wn,origin:cy,parent:M(D)});Cr(F,ly);var uy=A({address:M(F),client:F,device:F,family:D,kind:Ri([`App`,`Browser`]),lastActive:wn,parent:M(D)});A({client_id:D,token:D});var dy=Ri([`ble`,`cable`,`hybrid`,`internal`,`nfc`,`smart-card`,`usb`]),fy=T(`public-key`),py=Ri([`required`,`preferred`,`discouraged`]),my=A({id:F,transports:M(ni(pn(dy))),type:fy}),hy=A({attestation:M(Ri([`direct`,`enterprise`,`indirect`,`none`])),authenticatorSelection:M(A({authenticatorAttachment:M(Ri([`cross-platform`,`platform`])),requireResidentKey:M(Ni),residentKey:M(Ri([`discouraged`,`preferred`,`required`])),userVerification:M(py)})),challenge:F,excludeCredentials:M(ni(pn(my))),pubKeyCredParams:ni(pn(A({alg:wn,type:fy}))),rp:A({id:M(F),name:F}),timeout:M(wn),user:A({displayName:F,id:F,name:F})}),gy=A({allowCredentials:M(ni(pn(my))),challenge:F,rpId:M(F),timeout:M(wn),userVerification:M(py)}),_y=M(Ri([`cross-platform`,`platform`])),vy=A({authenticatorAttachment:_y,clientExtensionResults:A({}),id:F,rawId:F,response:A({attestationObject:F,clientDataJSON:F,transports:M(pn(F))}),type:fy}),yy=A({authenticatorAttachment:_y,clientExtensionResults:A({}),id:F,rawId:F,response:A({authenticatorData:F,clientDataJSON:F,signature:F,userHandle:M(F)}),type:fy});A({challenge:F});var by=A({...ny.fields,addedFrom:F,counter:Wi,id:D,publicKey:D,synced:Ni,transports:pn(dy)});pn(by);var xy=A({addedFrom:F,id:D,synced:Ni});A({id:D});var Sy=A({response:vy}),Cy=A({next:M(D.check(Te(2048))),response:yy}),wy=Ri([`Admin`,`Member`,`Waiting`]),Ty=A({...kl.fields,fullName:M(F),role:wy}),Ey=A({...Ty.fields,via:sy}),Dy=A({...Ty.fields,since:wn}),Oy=Ri([`Waiting`,`Allowed`]),ky=A({fullName:F,id:D,incarnation:ny.fields.incarnation,name:D,since:wn,status:Oy});pn(ky),A({id:Wi,login:D,name:M(ie(F))});var Ay=A({allow:Ni,id:D}),jy=Ri([`App`,`Browser`]),My=A({address:M(F),clientName:F,device:F,expiresAt:wn,id:D,kind:jy}),Ny=me({Decided:{},Expired:{},Waiting:{request:My}}),Py=me({Browser:{next:M(F)},Client:{request:ry},Device:{request:iy}});me({Denied:{},Granted:{tokens:ay},Redirect:{url:D},Session:{next:M(F),seconds:Wi,token:D}}),A({delivery:Py,origin:oy}),A({next:M(D.check(Te(2048)))});var Fy=A({request:D.check(Te(20))}),Iy=A({code:D.check(Te(20))}),Ly=A({...Fy.fields,accept:Ni}),Ry=class extends Vr()(`@deslop/auth/rpcs/RpcOwner`,{error:q}){},zy=class extends Tn(Un(`auth.lookup`,{error:q,payload:Iy,stream:!0,success:it(My)}),Un(`auth.answer`,{error:q,payload:Ly}),Un(`auth.people`,{error:q,stream:!0,success:pn(Dy)}),Un(`auth.admit`,{error:q,payload:Ay,success:Dy}),Un(`auth.apps`,{error:q,stream:!0,success:pn(uy)}),Un(`auth.catalog`,{error:q,stream:!0,success:ey}),Un(`auth.passkeys`,{error:q,stream:!0,success:pn(xy)}),Un(`auth.passkeyOptions`,{error:q,success:hy}),Un(`auth.addPasskey`,{error:q,payload:Sy})).middleware(Wl).middleware(Ry).merge(Tn(Un(`auth.account`,{error:q,stream:!0,success:Ey}),Un(`auth.wait`,{error:q,payload:Fy,stream:!0,success:Ny}))){};tr(10);function By(e){return Fi(Sn(/[^a-z]/giu,``)(e))}function Vy(e){let t=yr(S(e,e=>e.parent!==void 0),e=>e.parent??``);return De(S(e,e=>e.parent===void 0),e=>{let n=_(o(xe(t,e.family),()=>[]),e,Yr(qn(Di,e=>e.lastActive)));return{...zn(e,[`address`]),lastActive:n.lastActive,...bi(n,[`address`])}})}function Hy(e){return Ne(ut(e),jr)}wt(function*(e,t,n){return xi(Hy(n.response_type))?yield*q.make({message:`Send response_type=code`}):n.response_type===`code`?n.code_challenge===void 0||n.code_challenge_method!==`S256`?yield*q.make({message:`Send a PKCE code_challenge with code_challenge_method=S256`}):bt(S(xt(n.scope??``,` `),jr),e=>e===`deslop`||e===`offline_access`)?ry.make({challenge:n.code_challenge,clientId:e.client_id,clientName:t.clientName,redirectUri:t.redirectUri,...vn(Hy(e.state),{onNone:()=>({}),onSome:e=>({state:e})})}):yield*q.make({error:`invalid_scope`,message:`Only the deslop scope is supported`}):yield*q.make({error:`unsupported_response_type`,message:`Only response_type=code is supported`})});function Uy(e,t){let n=`mp281x.xyz`;return Le(Gr(e),{onFailure:()=>!1,onSuccess:e=>(e.origin===new URL(t).origin||e.protocol===`https:`&&(e.hostname===n||Gn(`.${n}`)(e.hostname)))&&qr(e.username)&&qr(e.password)})}var Wy=Pi(lt),Gy=A({code:M(F),error:M(F),next:M(F),request:M(F),"sign-out":M(F)}),$=class extends wr()(`@deslop/auth/lib/utils/RpcClient`,{group:zy.middleware(Dl),protocol:tu(`@deslop/auth`)}){},Ky=xn($.runtime.atom(H($,P(e=>e(`auth.account`,void 0)),Nt,Ql,Je(kn),St(`AuthError`,()=>_r(z()))))),qy={accept:Ni,request:My},Jy=Qv($.runtime).make(iv({branches:{looked:{found:{target:`Code.Found`},missing:{target:`Code.Missing`}}},events:av({Answered:qy,Typed:{typed:F}}),root:rv({states:{Code:{fields:{code:F},states:{Failed:{fields:{message:F}},Found:{fields:{request:My}},Looking:{},Missing:{}}},Typing:{fields:{answered:M(A(qy)),typed:F}}}}),streams:{lookup:e=>Ql(Nt(P($,t=>t(`auth.lookup`,{code:e}))))}}).handle({initial:{data:{typed:``},target:`Typing`},on:{Answered:{data:e=>({answered:{accept:e.event.accept,request:e.event.request},typed:``}),target:`Typing`},Typed:{data:e=>({typed:e.event.typed}),target:`Typing`}},states:{Code:{initial:{target:`Code.Looking`},invoke:{input:e=>e.state.code,onDone:{none:!0},onElement:{branches:`looked`,resolve:e=>vn(e.element,{onNone:()=>e.select.missing(),onSome:t=>e.select.found({data:{request:t}})})},onFailure:{data:e=>({message:e.error.message}),target:`Code.Failed`},src:`lookup`},states:{Failed:{},Found:{},Looking:{},Missing:{}}},Typing:{always:{data:e=>({code:e.state.typed}),guard:e=>Zn(e.state.typed)>=8,target:`Code`}}}})),Yy=ln(e=>zi(t=>{t.set(Jy.send,{_tag:`Typed`,typed:By(e)})})),Xy=xn($.runtime.atom(e=>$l(e,H($,P(e=>e(`auth.people`,void 0)),Nt)))),Zy=xn($.runtime.atom(e=>$l(e,H($,P(e=>e(`auth.apps`,void 0)),Nt)))),Qy=ln(e=>$.runtime.fn(t=>U($,n=>n(`auth.admit`,{allow:t,id:e})))),$y=ln(e=>$.runtime.atom(H($,P(t=>t(`auth.wait`,{request:e})),Nt,Ql,y(t=>H(ki(t),jn(`Decided`,()=>O(()=>location.assign(`/auth/continue?${new URLSearchParams({request:e})}`))),gi(()=>L))))));function eb(e){return`${Vi(0,4)(e)}-${Vi(4)(e)}`}function tb(e){return`${location.origin}/?code=${e}`}var nb=xn($.runtime.atom(e=>$l(e,H($,P(e=>e(`auth.catalog`,void 0)),Nt)))),rb=zi(H(Ce(`1 minute`),Ze(()=>Lr))),ib=zi(H(Ce(`1 second`),Ze(()=>Lr))),ab=Ai(e=>H(pt({catch:e=>q.make({cause:e,message:`Cannot copy the code; type it in instead`}),try:()=>navigator.clipboard.writeText(e)}),B(ye(`1200 millis`))));function ob(e,t){return`${e} · ${t}`}var sb=$.runtime.fn((e,t)=>H($,U(t=>t(`auth.answer`,{accept:e.accept,request:e.request.id})),B(O(()=>t.set(Jy.send,{_tag:`Answered`,...e})))));function cb(e){return N(e.cause,`name`)&&e.cause.name===`NotAllowedError`}var lb=wt(function*(e){return e.status===429?yield*q.make({message:`Too many tries; wait a minute and try again`}):yield*q.make({message:(yield*li(A({error_description:F}))(e)).error_description})}),ub=Wy.fn(e=>H(ce(function*(){let t=yield*a,n=yield*t.get(`/auth/passkey`);if(n.status!==200)return yield*lb(n);let r=yield*li(gy)(n),i=yield*Xr(pt({catch:e=>q.make({cause:e,message:`No passkey was used`}),try:()=>vu({optionsJSON:r})}),cb,()=>re),o=yield*H(pr(`/auth/passkey`),bn(Cy)({...vn(ut(e),{onNone:()=>({}),onSome:e=>({next:e})}),response:i}),U(e=>t.execute(e)),U(wt(function*(e){return e.status===200?yield*li(A({next:M(F)}))(e):yield*lb(e)})));yield*O(()=>vn(ut(o.next),{onNone:()=>location.reload(),onSome:e=>location.assign(e)}))}),Ye(e=>Bt(q)(e)?e:q.make({cause:e,message:`Cannot sign in with a passkey`})))),db=xn($.runtime.atom(e=>$l(e,H($,P(e=>e(`auth.passkeys`,void 0)),Nt)))),fb=xn($.runtime.fn(wt(function*(){let e=yield*$,t=yield*e(`auth.passkeyOptions`,void 0);yield*e(`auth.addPasskey`,{response:yield*H(pt({catch:e=>q.make({cause:e,message:`No passkey was added`}),try:()=>pu({optionsJSON:t})}),Xr(cb,()=>re),U(Zi(vy)))})}))),pb=`adding-passkey`,mb=zi(!1),hb=Ai(()=>l({catch:e=>q.make({cause:e,message:`Cannot start GitHub sign-in`}),try:()=>{sessionStorage.setItem(pb,`true`),location.assign(`/auth/github`)}})),gb=Ai(()=>l({catch:e=>q.make({cause:e,message:`Cannot start GitHub sign-in`}),try:()=>location.assign(`/auth/github${location.search}`)})),_b=Ai(e=>l({catch:e=>q.make({cause:e,message:`Cannot start the sign-in`}),try:()=>location.assign(vn(ut(e),{onNone:()=>`/auth/code`,onSome:e=>`/auth/code?${new URLSearchParams({next:e})}`}))}));function vb(e){return H(a.use(e=>Hn(e).post(`/auth/sign-out`)),B(O(()=>location.replace(H(ut(e),Ne(e=>Uy(e,zl)),o(()=>location.pathname))))),Ye(e=>q.make({cause:e,message:`Cannot sign out: ${e.message}`})))}var yb=Wy.fn(vb),bb=Wy.fn(vb);export{Aa as $,Xv as A,$c as B,ib as C,Vy as D,yb as E,Sl as F,lc as G,pc as H,El as I,Va as J,Wa as K,vl as L,Yl as M,Xl as N,By as O,Zl as P,Na as Q,gl as R,eb as S,ob as T,cc as U,Jc as V,uc as W,Fa as X,ja as Y,Ma as Z,rb as _,fb as a,ga as at,Xy as b,Zy as c,sa as ct,_b as d,va as et,hb as f,bb as g,Yy as h,mb as i,ya as it,Zv as j,Yv as k,nb as l,ia as lt,ab as m,Gy as n,wa as nt,Qy as o,la as ot,sb as p,Ua as q,Ky as r,Ea as rt,tb as s,ca as st,pb as t,da as tt,Jy as u,ub as v,gb as w,$y as x,db as y,ol as z};
|