UNPKG

@e280/authlocal

Version:

User-sovereign login system for everybody

18 lines 82.2 kB
const t=t=>({v1:{hello:async()=>{},login:t}});var e;!function(t){t.version="2.0",t.getId=function(t){return"id"in t?t.id:null},t.errorCodes={serverError:-32e3,unexposedError:-32001}}(e||(e={}));class s extends Error{name=this.constructor.name}class n extends Error{name=this.constructor.name}const r=Object.freeze({eq(t,e){if(t.length!==e.length)return!1;for(let s=0;s<=t.length;s++)if(t.at(s)!==e.at(s))return!1;return!0},random:t=>crypto.getRandomValues(new Uint8Array(t))}),i=Object.freeze({fromBytes:t=>[...t].map((t=>t.toString(16).padStart(2,"0"))).join(""),toBytes(t){if(t.length%2!=0)throw new Error("must have even number of hex characters");const e=new Uint8Array(t.length/2);for(let s=0;s<t.length;s+=2)e[s/2]=parseInt(t.slice(s,s+2),16);return e},random(t=32){return this.fromBytes(r.random(t))},string:t=>i.fromBytes(t),bytes:t=>i.toBytes(t)}),o=["doz","mar","bin","wan","sam","lit","sig","hid","fid","lis","sog","dir","wac","sab","wis","sib","rig","sol","dop","mod","fog","lid","hop","dar","dor","lor","hod","fol","rin","tog","sil","mir","hol","pas","lac","rov","liv","dal","sat","lib","tab","han","tic","pid","tor","bol","fos","dot","los","dil","for","pil","ram","tir","win","tad","bic","dif","roc","wid","bis","das","mid","lop","ril","nar","dap","mol","san","loc","nov","sit","nid","tip","sic","rop","wit","nat","pan","min","rit","pod","mot","tam","tol","sav","pos","nap","nop","som","fin","fon","ban","mor","wor","sip","ron","nor","bot","wic","soc","wat","dol","mag","pic","dav","bid","bal","tim","tas","mal","lig","siv","tag","pad","sal","div","dac","tan","sid","fab","tar","mon","ran","nis","wol","mis","pal","las","dis","map","rab","tob","rol","lat","lon","nod","nav","fig","nom","nib","pag","sop","ral","bil","had","doc","rid","moc","pac","rav","rip","fal","tod","til","tin","hap","mic","fan","pat","tac","lab","mog","sim","son","pin","lom","ric","tap","fir","has","bos","bat","poc","hac","tid","hav","sap","lin","dib","hos","dab","bit","bar","rac","par","lod","dos","bor","toc","hil","mac","tom","dig","fil","fas","mit","hob","har","mig","hin","rad","mas","hal","rag","lag","fad","top","mop","hab","nil","nos","mil","fop","fam","dat","nol","din","hat","nac","ris","fot","rib","hoc","nim","lar","fit","wal","rap","sar","nal","mos","lan","don","dan","lad","dov","riv","bac","pol","lap","tal","pit","nam","bon","ros","ton","fod","pon","sov","noc","sor","lav","mat","mip","fip"],a=["zod","nec","bud","wes","sev","per","sut","let","ful","pen","syt","dur","wep","ser","wyl","sun","ryp","syx","dyr","nup","heb","peg","lup","dep","dys","put","lug","hec","ryt","tyv","syd","nex","lun","mep","lut","sep","pes","del","sul","ped","tem","led","tul","met","wen","byn","hex","feb","pyl","dul","het","mev","rut","tyl","wyd","tep","bes","dex","sef","wyc","bur","der","nep","pur","rys","reb","den","nut","sub","pet","rul","syn","reg","tyd","sup","sem","wyn","rec","meg","net","sec","mul","nym","tev","web","sum","mut","nyx","rex","teb","fus","hep","ben","mus","wyx","sym","sel","ruc","dec","wex","syr","wet","dyl","myn","mes","det","bet","bel","tux","tug","myr","pel","syp","ter","meb","set","dut","deg","tex","sur","fel","tud","nux","rux","ren","wyt","nub","med","lyt","dus","neb","rum","tyn","seg","lyx","pun","res","red","fun","rev","ref","mec","ted","rus","bex","leb","dux","ryn","num","pyx","ryg","ryx","fep","tyr","tus","tyc","leg","nem","fer","mer","ten","lus","nus","syl","tec","mex","pub","rym","tuc","fyl","lep","deb","ber","mug","hut","tun","byl","sud","pem","dev","lur","def","bus","bep","run","mel","pex","dyt","byt","typ","lev","myl","wed","duc","fur","fex","nul","luc","len","ner","lex","rup","ned","lec","ryd","lyd","fen","wel","nyd","hus","rel","rud","nes","hes","fet","des","ret","dun","ler","nyr","seb","hul","ryl","lud","rem","lys","fyn","wer","ryc","sug","nys","nyl","lyn","dyn","dem","lux","fed","sed","bec","mun","lyr","tes","mud","nyt","byr","sen","weg","fyr","mur","tel","rep","teg","pec","nel","nev","fes"],c={defaults:{groupSize:4,wordSeparator:".",groupSeparator:" "},random(t,e){const s=r.random(t);return this.fromBytes(s,e)},fromBytes(t,e={}){const{groupSize:s=c.defaults.groupSize,wordSeparator:n=c.defaults.wordSeparator,groupSeparator:r=c.defaults.groupSeparator}=e,i=[];let l=[];t.forEach(((t,e)=>{const s=e%2==0?o:a;l.push(s[t]),2===l.length&&(i.push(l.join("")),l=[])})),l.length&&i.push(l.join(""));const u=[];for(let t=0;t<i.length;t+=s)u.push(i.slice(t,t+s).join(n));return u.join(r)},toBytes(t){const e=t.toLowerCase().replace(/[^a-z]/g,"");if(e.length/3%1!=0)throw new Error(`invalid triplet count, ${e.length} does not divide into triplets`);const s=[];for(let t=0;t<e.length;t+=3)s.push(e.slice(t,t+3));return new Uint8Array(s.map(((t,e)=>{const s=(e%2==0?o:a).findIndex((e=>e===t));if(-1===s)throw new Error(`unknown triplet ${t}`);return s})))},toHex:t=>i.fromBytes(c.toBytes(t)),fromHex:(t,e)=>c.fromBytes(i.toBytes(t),e)},l="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",u=Object.freeze({fromBytes(t){let e=BigInt("0x"+i.fromBytes(t)),s="";for(;e>0;){const t=e%BigInt(58);e/=BigInt(58),s=l[Number(t)]+s}for(const e of t){if(0!==e)break;s=l[0]+s}return s},toBytes(t){let e=BigInt(0);for(const s of t){const t=l.indexOf(s);if(-1===t)throw new Error(`Invalid character '${s}' in base58 string`);e=e*BigInt(58)+BigInt(t)}let s=e.toString(16);s.length%2!=0&&(s="0"+s);const n=i.toBytes(s);let r=0;for(const e of t){if(e!==l[0])break;r++}const o=new Uint8Array(r+n.length);return o.set(n,r),o},random(t=32){return this.fromBytes(r.random(t))},string:t=>u.fromBytes(t),bytes:t=>u.toBytes(t)}),h={defaults:{delimiter:".",sigilBytes:4,previewBytes:8},build:{fromBytes(t,e={}){const{delimiter:s,previewBytes:n,sigilBytes:r}={...h.defaults,...e},i=e=>t.length>0?c.fromBytes(t.slice(0,e),{wordSeparator:s,groupSeparator:s}):"",o=i(r),a=i(n),l=t.length>n?u.fromBytes(t.slice(n)):"",d=[a,l].filter((t=>t.length>0)).join(s);return{bytes:t,thumbprint:d,preview:a,bulk:l,sigil:o}},fromHex(t,e){const s=i.toBytes(t);return h.build.fromBytes(s,e)}}},d=Object.freeze({fromBytes:t=>"function"==typeof btoa?btoa(String.fromCharCode(...t)):Buffer.from(t).toString("base64"),toBytes:t=>"function"==typeof atob?Uint8Array.from(atob(t),(t=>t.charCodeAt(0))):Uint8Array.from(Buffer.from(t,"base64")),random(t=32){return this.fromBytes(r.random(t))},string:t=>d.fromBytes(t),bytes:t=>d.toBytes(t)}),p={fromBytes:t=>d.fromBytes(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/g,""),toBytes(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");return e.length%4!=0&&(e=e.padEnd(e.length+(4-e.length%4)%4,"=")),d.toBytes(e)},random(t=32){return this.fromBytes(r.random(t))},string:t=>p.fromBytes(t),bytes:t=>p.toBytes(t)},f=Object.freeze({fromBytes:t=>(new TextDecoder).decode(t),toBytes:t=>(new TextEncoder).encode(t),string:t=>f.fromBytes(t),bytes:t=>f.toBytes(t)});const m=Object.freeze({set:t=>null!=t,unset:t=>null==t,boolean:t=>"boolean"==typeof t,number:t=>"number"==typeof t,string:t=>"string"==typeof t,bigint:t=>"bigint"==typeof t,object:t=>"object"==typeof t&&null!==t,array:t=>Array.isArray(t),fn:t=>"function"==typeof t,symbol:t=>"symbol"==typeof t});class g extends Error{milliseconds;name=this.constructor.name;constructor(t,e){super(`${e}, timed out in ${(t/1e3).toFixed(1)} seconds`),this.milliseconds=t}}function y(){let t,e;const s=new Promise(((s,n)=>{t=s,e=n}));return{promise:s,resolve:t,reject:e,entangle:function(n){return n.then(t).catch(e),s}}}function w(t){return{map:e=>b(t,e),filter:e=>v(t,e)}}w.pipe=Object.freeze({map:t=>e=>b(e,t),filter:t=>e=>v(e,t)});const b=(t,e)=>Object.fromEntries(Object.entries(t).map((([t,s])=>[t,e(s,t)]))),v=(t,e)=>Object.fromEntries(Object.entries(t).filter((([t,s])=>e(s,t))));let _=class t{static with(t){return new this(t)}#t;constructor(t){this.#t=t}to(e){return new t(e(this.#t))}done(){return this.#t}};function x(){const t=new Set;function e(e){return t.add(e),()=>{t.delete(e)}}async function s(...e){await Promise.all([...t].map((t=>t(...e))))}async function n(){const{promise:t,resolve:s}=y(),n=e(((...t)=>{s(t),n()}));return t}function r(){t.clear()}return e.pub=s,e.sub=e,e.on=e,e.once=n,e.clear=r,s.pub=s,s.sub=e,s.on=e,s.once=n,s.clear=r,[s,e]}function $(t){return x()[1]}function A(t){return x()[0]}class k{#e=[];add(...t){return this.#e.push(...t),this}disposable(t){return this.bag(t,(()=>t.dispose()))}bag(t,e){return this.add((()=>e(t))),t}dispose(){for(const t of this.#e.reverse())t();this.#e=[]}}function S({fns:t,tap:n}){return async r=>{const i=r.method.split("."),o=function(t,e){let s=t;for(const t of e)if(s=s[t],m.unset(s))break;return s}(t,i);n&&await n.request({request:r});const a=await async function({request:t,action:n,tap:r}){const i=e.getId(t);try{const t=await n();return null===i?null:{id:i,result:t,jsonrpc:e.version}}catch(n){return r&&r.rpcError({request:t,error:n}),"id"in t?{id:t.id,jsonrpc:e.version,error:n instanceof s?{code:e.errorCodes.serverError,message:n.message}:{code:e.errorCodes.unexposedError,message:"unexposed error"}}:null}}({request:r,action:async()=>await o(...r.params),tap:n});return a}}const E=Symbol("tune"),C=Symbol("query"),O=Symbol("notify"),B=Symbol("settings");function j(t){const{endpoint:e,tap:s}=t;let r=1;return i=async(i,o,a)=>{const c=a.notify??t.notify??!1,l=a.transfer,u={jsonrpc:"2.0",method:i.join("."),params:o},h=c?u:{...u,id:r++};s&&await s.request({request:h});const d=await e(h,{transfer:l});if(c&&!d)return null;if(!d)throw new n("response was null, but shouldn't be, because the request was not a notification");if("error"in d)throw new n(t.label?`${t.label}: ${d.error.message}`:d.error.message);return d.result},function t(e){const s={notify:void 0};return new Proxy((()=>{}),{apply:(t,n,r)=>i(e,r,s),get:(n,r)=>{if("then"!==r)return r===E?t=>(...n)=>i(e,n,{...s,...t}):r===O?(...t)=>i(e,t,{...s,notify:!0}):r===C?(...t)=>i(e,t,{...s,notify:!1}):r===B?s:(n[r]||(n[r]=t([...e,r])),n[r])},set:(t,e,s)=>(t[e]=s,!0)})}([]);var i}class M{recv=A();sendRequest=A();sendResponse=A();static makeEntangledPair({origin:t="example.e280.org"}={}){const e=new this,s=new this,n=[e.sendRequest.sub((e=>s.recv(e,{origin:t}))),e.sendResponse.sub((e=>s.recv(e,{origin:t}))),s.sendRequest.sub((s=>e.recv(s,{origin:t}))),s.sendResponse.sub((s=>e.recv(s,{origin:t})))];return[e,s,()=>n.forEach((t=>t()))]}}class P{transfer=void 0}class T extends M{targetOrigin;#s=new k;constructor(t,e,s,n){var r,i;super(),this.targetOrigin=s,this.#s.add(this.sendRequest.sub(((t,s)=>e.postMessage(t,this.targetOrigin,s))),this.sendResponse.sub(((t,s)=>e.postMessage(t,this.targetOrigin,s))),(i=t=>{n(t)&&this.recv(t.data,t)},(r=t).addEventListener("message",i),()=>r.removeEventListener("message",i)))}dispose(){this.#s.dispose()}}const z=Object.freeze({timeout:6e4,maxRequestBytes:1e7});class R{timeout;pending=new Map;constructor(t){this.timeout=t}async wait(t,e){const s=y();return this.pending.set(t,{method:e,deferred:s}),await(n=this.timeout,r=`request #${t} ${e}()`,i=()=>s.promise,n<=0||n===1/0?i():new Promise(((t,e)=>{const s=setTimeout((()=>e(new g(n,r))),n);i().then(t).catch(e).finally((()=>clearTimeout(s)))})));var n,r,i}deliverResponse(t){const e=this.pending.get(t.id);e&&("error"in t?e.deferred.reject(new n(t.error.message)):e.deferred.resolve(t))}}class U{options;waiter;remoteEndpoint;remote;constructor(t){this.options=t;const{conduit:e}=t;var s,n;this.waiter=new R(t.timeout??z.timeout),this.remoteEndpoint=(s=this.waiter,n=e.sendRequest.pub.bind(e.sendRequest),async(t,{transfer:e}={})=>{if("id"in t){const r=y();return n(t,e,r.promise),s.wait(t.id,t.method).then((t=>(r.resolve(t),t)))}{const s=Promise.resolve(null);return n(t,e,s),s}}),this.remote=j({endpoint:this.remoteEndpoint,tap:t.tap}),e.recv.sub((t=>this.recv(t)))}async recv(t){const e=new P,{conduit:s,getLocalEndpoint:n}=this.options,{requests:r,responses:i}=function(t){const e=[],s=[];for(const n of Array.isArray(t)?t:[t])"method"in n?e.push(n):s.push(n);return{requests:e,responses:s}}(t);for(const t of i)this.waiter.deliverResponse(t);if(!n)return;const o=await async function(t,e){const s=(await Promise.all(e.map((async e=>t(e))))).filter((t=>null!==t));return 0===s.length?null:1===s.length?s[0]:s}(n(this.remote,e),r);o&&await s.sendResponse(o,e.transfer)}}const q=Object.freeze({black:"",red:"",green:"",yellow:"",blue:"",magenta:"",cyan:"",white:"",brightBlack:"",brightRed:"",brightGreen:"",brightYellow:"",brightBlue:"",brightMagenta:"",brightCyan:"",brightWhite:"",bgBlack:"",bgRed:"",bgGreen:"",bgYellow:"",bgBlue:"",bgMagenta:"",bgCyan:"",bgWhite:"",bgBrightBlack:"",bgBrightRed:"",bgBrightGreen:"",bgBrightYellow:"",bgBrightBlue:"",bgBrightMagenta:"",bgBrightCyan:"",bgBrightWhite:"",bold:"",dim:"",italic:"",underline:"",inverse:"",hidden:"",strikethrough:"",reset:""});function N(e,s,n,r){const i=new T(e,s,n,(({origin:t})=>t===n));return new U({conduit:i,timeout:1/0,getLocalEndpoint:()=>S({fns:t(r)})}),{dispose:()=>i.dispose()}}Object.fromEntries(Object.entries(q).map((([t])=>[t,t=>t]))),Object.fromEntries(Object.entries(q).map((([t,e])=>[t,t=>`${e}${t}${q.reset}`])));const D={typ:"JWT",alg:"EdDSA"},{p:H,n:L,Gx:I,Gy:V,a:W,d:J}={p:0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffedn,n:0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3edn,a:0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffecn,d:0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3n,Gx:0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,Gy:0x6666666666666666666666666666666666666666666666666666666666666658n},Z=32,F=(t="")=>{throw new Error(t)},G=t=>"string"==typeof t,K=(t,e)=>!(t=>t instanceof Uint8Array||ArrayBuffer.isView(t)&&"Uint8Array"===t.constructor.name)(t)||"number"==typeof e&&e>0&&t.length!==e?F("Uint8Array expected"):t,Y=t=>new Uint8Array(t),Q=t=>Uint8Array.from(t),X=(t,e)=>t.toString(16).padStart(e,"0"),tt=t=>Array.from(K(t)).map((t=>X(t,2))).join(""),et=48,st=57,nt=65,rt=70,it=97,ot=102,at=t=>t>=et&&t<=st?t-et:t>=nt&&t<=rt?t-(nt-10):t>=it&&t<=ot?t-(it-10):void 0,ct=t=>{const e="hex invalid";if(!G(t))return F(e);const s=t.length,n=s/2;if(s%2)return F(e);const r=Y(n);for(let s=0,i=0;s<n;s++,i+=2){const n=at(t.charCodeAt(i)),o=at(t.charCodeAt(i+1));if(void 0===n||void 0===o)return F(e);r[s]=16*n+o}return r},lt=(t,e)=>K(G(t)?ct(t):Q(K(t)),e),ut=()=>globalThis?.crypto,ht=(...t)=>{const e=Y(t.reduce(((t,e)=>t+K(e).length),0));let s=0;return t.forEach((t=>{e.set(t,s),s+=t.length})),e},dt=BigInt,pt=(t,e,s,n="bad number: out of range")=>(t=>"bigint"==typeof t)(t)&&e<=t&&t<s?t:F(n),ft=(t,e=H)=>{const s=t%e;return s>=0n?s:e+s},mt=t=>ft(t,L),gt=(t,e)=>{(0n===t||e<=0n)&&F("no inverse n="+t+" mod="+e);let s=ft(t,e),n=e,r=0n,i=1n;for(;0n!==s;){const t=n%s,e=r-i*(n/s);n=s,s=t,r=i,i=e}return 1n===n?ft(r,e):F("no inverse")},yt=t=>t instanceof bt?t:F("Point expected"),wt=2n**256n; /*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */class bt{static BASE;static ZERO;ex;ey;ez;et;constructor(t,e,s,n){const r=wt;this.ex=pt(t,0n,r),this.ey=pt(e,0n,r),this.ez=pt(s,1n,r),this.et=pt(n,0n,r),Object.freeze(this)}static fromAffine(t){return new bt(t.x,t.y,1n,ft(t.x*t.y))}static fromBytes(t,e=!1){const s=J,n=Q(K(t,Z)),r=t[31];n[31]=-129&r;const i=$t(n);pt(i,0n,e?wt:H);const o=ft(i*i),a=ft(o-1n),c=ft(s*o+1n);let{isValid:l,value:u}=St(a,c);l||F("bad point: y not sqrt");const h=1n==(1n&u),d=!!(128&r);return!e&&0n===u&&d&&F("bad point: x==0, isLastByteOdd"),d!==h&&(u=ft(-u)),new bt(u,i,1n,ft(u*i))}assertValidity(){const t=W,e=J;if(this.is0())throw new Error("bad point: ZERO");const{ex:s,ey:n,ez:r,et:i}=this,o=ft(s*s),a=ft(n*n),c=ft(r*r),l=ft(c*c),u=ft(o*t);if(ft(c*ft(u+a))!==ft(l+ft(e*ft(o*a))))throw new Error("bad point: equation left != right (1)");if(ft(s*n)!==ft(r*i))throw new Error("bad point: equation left != right (2)");return this}equals(t){const{ex:e,ey:s,ez:n}=this,{ex:r,ey:i,ez:o}=yt(t),a=ft(e*o),c=ft(r*n),l=ft(s*o),u=ft(i*n);return a===c&&l===u}is0(){return this.equals(_t)}negate(){return new bt(ft(-this.ex),this.ey,this.ez,ft(-this.et))}double(){const{ex:t,ey:e,ez:s}=this,n=W,r=ft(t*t),i=ft(e*e),o=ft(2n*ft(s*s)),a=ft(n*r),c=t+e,l=ft(ft(c*c)-r-i),u=a+i,h=u-o,d=a-i,p=ft(l*h),f=ft(u*d),m=ft(l*d),g=ft(h*u);return new bt(p,f,g,m)}add(t){const{ex:e,ey:s,ez:n,et:r}=this,{ex:i,ey:o,ez:a,et:c}=yt(t),l=W,u=J,h=ft(e*i),d=ft(s*o),p=ft(r*u*c),f=ft(n*a),m=ft((e+s)*(i+o)-h-d),g=ft(f-p),y=ft(f+p),w=ft(d-l*h),b=ft(m*g),v=ft(y*w),_=ft(m*w),x=ft(g*y);return new bt(b,v,x,_)}multiply(t,e=!0){if(!e&&(0n===t||this.is0()))return _t;if(pt(t,1n,L),1n===t)return this;if(this.equals(vt))return qt(t).p;let s=_t,n=vt;for(let r=this;t>0n;r=r.double(),t>>=1n)1n&t?s=s.add(r):e&&(n=n.add(r));return s}toAffine(){const{ex:t,ey:e,ez:s}=this;if(this.equals(_t))return{x:0n,y:1n};const n=gt(s,H);return 1n!==ft(s*n)&&F("invalid inverse"),{x:ft(t*n),y:ft(e*n)}}toBytes(){const{x:t,y:e}=this.assertValidity().toAffine(),s=xt(e);return s[31]|=1n&t?128:0,s}toHex(){return tt(this.toBytes())}clearCofactor(){return this.multiply(dt(8n),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let t=this.multiply(L/2n,!1).double();return L%2n&&(t=t.add(this)),t.is0()}static fromHex(t,e){return bt.fromBytes(lt(t),e)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}toRawBytes(){return this.toBytes()}}const vt=new bt(I,V,1n,ft(I*V)),_t=new bt(0n,1n,1n,0n);bt.BASE=vt,bt.ZERO=_t;const xt=t=>ct(X(pt(t,0n,wt),64)).reverse(),$t=t=>dt("0x"+tt(Q(K(t)).reverse())),At=(t,e)=>{let s=t;for(;e-- >0n;)s*=s,s%=H;return s},kt=0x2b8324804fc1df0b2b4d00993dfbd7a72f431806ad2fe478c4ee1b274a0ea0b0n,St=(t,e)=>{const s=ft(e*e*e),n=(t=>{const e=t*t%H*t%H,s=At(e,2n)*e%H,n=At(s,1n)*t%H,r=At(n,5n)*n%H,i=At(r,10n)*r%H,o=At(i,20n)*i%H,a=At(o,40n)*o%H,c=At(a,80n)*a%H,l=At(c,80n)*a%H,u=At(l,10n)*r%H;return{pow_p_5_8:At(u,2n)*t%H,b2:e}})(t*ft(s*s*e)).pow_p_5_8;let r=ft(t*s*n);const i=ft(e*r*r),o=r,a=ft(r*kt),c=i===t,l=i===ft(-t),u=i===ft(-t*kt);return c&&(r=o),(l||u)&&(r=a),1n==(1n&ft(r))&&(r=ft(-r)),{isValid:c||l,value:r}},Et=t=>mt($t(t)),Ct=(...t)=>Tt.sha512Async(...t),Ot=t=>{const e=t.slice(0,Z);e[0]&=248,e[31]&=127,e[31]|=64;const s=t.slice(Z,64),n=Et(e),r=vt.multiply(n),i=r.toBytes();return{head:e,prefix:s,scalar:n,point:r,pointBytes:i}},Bt=t=>Ct(t.hashable).then(t.finish),jt=async(t,e)=>{const s=lt(t),n=await(r=e,Ct(lt(r,Z)).then(Ot));var r;const i=await Ct(n.prefix,s);return Bt(((t,e,s)=>{const{pointBytes:n,scalar:r}=t,i=Et(e),o=vt.multiply(i).toBytes();return{hashable:ht(o,n,s),finish:t=>{const e=mt(i+Et(t)*r);return K(ht(o,xt(e)),64)}}})(n,i,s))},Mt={zip215:!0},Pt=async(t,e,s,n=Mt)=>Bt(((t,e,s,n=Mt)=>{t=lt(t,64),e=lt(e),s=lt(s,Z);const{zip215:r}=n;let i,o,a,c,l=Uint8Array.of();try{i=bt.fromHex(s,r),o=bt.fromHex(t.slice(0,Z),r),a=$t(t.slice(Z,64)),c=vt.multiply(a,!1),l=ht(o.toBytes(),i.toBytes(),e)}catch(t){}return{hashable:l,finish:t=>{if(null==c)return!1;if(!r&&i.isSmallOrder())return!1;const e=Et(t);return o.add(i.multiply(e,!1)).add(c.negate()).clearCofactor().is0()}}})(t,e,s,n)),Tt={sha512Async:async(...t)=>{const e=ut()?.subtle??F("crypto.subtle must be defined"),s=ht(...t);return Y(await e.digest("SHA-512",s.buffer))},sha512Sync:void 0,bytesToHex:tt,hexToBytes:ct,concatBytes:ht,mod:ft,invert:gt,randomBytes:(t=32)=>ut().getRandomValues(Y(t))},zt=Math.ceil(32)+1;let Rt;const Ut=(t,e)=>{const s=e.negate();return t?s:e},qt=t=>{const e=Rt||(Rt=(()=>{const t=[];let e=vt,s=e;for(let n=0;n<zt;n++){s=e,t.push(s);for(let n=1;n<128;n++)s=s.add(e),t.push(s);e=s.double()}return t})());let s=_t,n=vt;const r=dt(255),i=dt(8);for(let o=0;o<zt;o++){let a=Number(t&r);t>>=i,a>128&&(a-=256,t+=1n);const c=128*o,l=c,u=c+Math.abs(a)-1,h=o%2!=0,d=a<0;0===a?n=n.add(Ut(h,e[l])):s=s.add(Ut(d,e[u]))}return{p:s,f:n}};function Nt(t){const e=i.bytes(t);if(32!==e.length)throw new Error("invalid key");return e}async function Dt(t,e){const s=f.bytes(JSON.stringify(D)),n=p.string(s),r=f.bytes(JSON.stringify(e)),i=`${n}.${p.string(r)}`,o=(new TextEncoder).encode(i),a=p.string(await async function(t,e){return jt(t,Nt(e))}(o,t));return`${i}.${a}`}function Ht(t){const[e,s,n]=t.split(".");if(!e||!s||!n)throw new Error("invalid jwt structure");const r=p.bytes(e),i=f.string(r),o=JSON.parse(i),a=p.bytes(s),c=f.string(a);return{header:o,payload:JSON.parse(c),signature:p.bytes(n)}}const Lt={toMs:t=>1e3*t,at:t=>t/1e3,maybe:t=>void 0!==t?t/1e3:void 0,readExpiresAt(t){const{exp:e}=Ht(t).payload;return void 0===e?void 0:Lt.toMs(e)},readIssuedAt(t){const{iat:e}=Ht(t).payload;return void 0===e?void 0:Lt.toMs(e)},isExpired(t,e=Date.now()){const s=this.readExpiresAt(t);return void 0!==s&&e>=s},fuzz({time:t,randomness:e,additive:s}){const n=e/10,r=Math.floor(s?Math.ceil(t/n)*n:Math.floor(t/n)*n),i=Math.floor(Math.random()*e);return s?r+i:r-i}};class It extends Error{name=this.constructor.name}async function Vt(t,e,s={}){const[n,r]=e.split("."),{payload:i,signature:o}=Ht(e),a=`${n}.${r}`,c=(new TextEncoder).encode(a);if(!await async function(t,e,s){return Pt(e,t,Nt(s))}(c,o,t))throw new It("token signature invalid");if(null!==s.atTime){const t=s.atTime??Date.now();if(i.exp){if(t>Lt.toMs(i.exp))throw new It("token expired")}if(i.nbf){if(t<Lt.toMs(i.nbf))throw new It("token not ready")}}if(s.allowedIssuers){if(!i.iss)throw new It("required iss (issuer) is missing");if(!s.allowedIssuers.includes(i.iss))throw new It(`invalid iss (issuer) "${i.iss}"`)}if(s.allowedAudiences){if(!i.aud)throw new It("required aud (audience) is missing");if(!s.allowedAudiences.includes(i.aud))throw new It(`invalid aud (audience) "${i.aud}"`)}if(i.aud&&!s.allowedAudiences)throw new It('allowedAudiences verification option was not provided, but is required because the token included "aud"');return i}async function Wt({proofToken:t,appOrigins:e,atTime:s}){const n=Ht(t),{data:r}=await Vt(n.payload.data.nametag.id,t,{atTime:s,allowedAudiences:e});return r}async function Jt({claimToken:t,appOrigins:e,allowedAudiences:s,atTime:n}){const r=Ht(t).payload,{proofToken:i}=r.data,o=Ht(i).payload;if(!r.iss)throw new Error('claim token is lacking "iss" field');if(!o.aud)throw new Error('proof token is lacking "aud" field');if(r.iss!==o.aud)throw new Error(`claim token iss "${r.iss}" does not match proof token aud "${o.aud}"`);const a=await Wt({proofToken:i,appOrigins:e,atTime:n}),{data:{claim:c}}=await Vt(a.sessionId,t,{atTime:n,allowedIssuers:e,allowedAudiences:s});return{claim:c,proof:a,proofToken:i}}class Zt{session;proof;proofAppOrigin;static async verify({session:t,appOrigins:e}){const{proofToken:s}=t,n=await Wt({proofToken:s,appOrigins:e}),r=function(t){const e=Ht(t).payload.aud;if(!e)throw new Error("proof token is missing audience aud");return e}(s);return new this(t,n,r)}constructor(t,e,s){this.session=t,this.proof=e,this.proofAppOrigin=s}get nametag(){return this.proof.nametag}get sessionId(){return this.proof.sessionId}get proofToken(){return this.session.proofToken}get expiresAt(){const t=Lt.readExpiresAt(this.proofToken);if(void 0===t)throw new Error("misconfigured proof token will never expire");return t}isExpired(t=Date.now()){return Lt.isExpired(this.proofToken,t)}async signClaim(t){const e=await async function({claim:t,session:e,appOrigin:s,audience:n,expiresAt:r}){const o=Ht(e.proofToken).payload.data;return Dt(e.secret,{jti:i.random(32),exp:Lt.maybe(r),sub:o.nametag.id,aud:n,iss:s,data:{claim:t,proofToken:e.proofToken}})}({...t,session:this.session,appOrigin:this.proofAppOrigin});return await Jt({claimToken:e,atTime:t.atTime,appOrigins:[this.proofAppOrigin],allowedAudiences:t.audience?[t.audience]:void 0}),e}}function Ft(t,e=-1){const s=i.bytes(t).at(e);if(void 0===s)throw new Error(`id didn't have byte at ${e}`);return Math.floor(s/255*359)}function Gt(t,e=-1){return`hsl(${Ft(t,e)}deg, 100%, 75%)`}const Kt=32;function Yt(t){if(t!==t.trim())return!1;const e=t.replaceAll(" ","");return["string"==typeof t,t.length>=1,t.length<=32,!t.includes('"'),!/[ ]{2,}/u.test(t),!/\s/.test(e),!/\p{Z}\p{C}/u.test(e)].every((t=>t))}const Qt={seconds:t=>1e3*t,minutes:t=>t*Qt.seconds(60),hours:t=>t*Qt.minutes(60),days:t=>t*Qt.hours(24),future:{seconds:t=>Date.now()+Qt.seconds(t),minutes:t=>Date.now()+Qt.minutes(t),hours:t=>Date.now()+Qt.hours(t),days:t=>Date.now()+Qt.days(t)},past:{seconds:t=>Date.now()-Qt.seconds(t),minutes:t=>Date.now()-Qt.minutes(t),hours:t=>Date.now()-Qt.hours(t),days:t=>Date.now()-Qt.days(t)}};class Xt{#n=!1;lock(t){this.#n=!0;const e=t();return this.#n=!1,e}get locked(){return this.#n}}const te=()=>new Map,ee=()=>new Set;function se(t){return{guarantee:(e,s)=>function(t,e,s){if(t.has(e))return t.get(e);{const n=s();return t.set(e,n),n}}(t,e,s)}}class ne{#r=new WeakMap;grab_keymap(t){const e=se(this.#r).guarantee(t,te);return{keymap:e,grab_symbolmap:t=>se(e).guarantee(t,te)}}clear(){this.#r=new WeakMap}}class re{#i=new Map;stop(t){const e=this.#i.get(t);e&&(this.#i.delete(t),e())}add(t,e){this.#i.set(t,e)}}class ie{#o=[];record(t){const e=te();this.#o.push(e);const s=t();return this.#o.pop(),{payload:s,recording:e}}record_that_key_was_accessed(t,e){const s=this.#o.at(-1);if(s){se(s).guarantee(t,ee).add(e)}}}class oe extends Error{name=this.constructor.name}class ae extends oe{constructor(t){super(`forbidden circularity, rejected assignment to "${t}"`)}}class ce extends oe{constructor(t){super(`forbidden assignment to readonly property "${t}"`)}}function le(t){return new Proxy(t,{get:(t,e)=>t[e],set(t,e){throw new ce(e)}})}function ue(t,e){let s,n,r=[];function i(){s=[],n&&clearTimeout(n),n=void 0,r=[]}return i(),(...o)=>{s=o,n&&clearTimeout(n);const a=new Promise(((t,e)=>{r.push({resolve:t,reject:e})}));return n=setTimeout((()=>{Promise.resolve().then((()=>e(...s))).then((t=>{for(const{resolve:e}of r)e(t);i()})).catch((t=>{for(const{reject:e}of r)e(t);i()}))}),t),a}}class he{#a=new Map;#c=Promise.resolve();#l=ue(0,(()=>{const t=[...this.#a.values()];this.#a.clear();for(const e of t)e()}));get wait(){return this.#c}add(t,e){this.#a.set(t,e),this.#c=this.#l()}}function de(t){return function(e){return()=>{const s="function"==typeof t?t():t;return e(s)}}}function pe(t,e,s,n){const r=[];for(const[i,o]of e){const{grab_symbolmap:e}=s.grab_keymap(i);for(const s of o){const i=e(s);i.set(t,n),r.push((()=>i.delete(t)))}}return()=>r.forEach((t=>t()))}function fe(t,e){return me.on_change(t,(()=>t.requestUpdate())),me.proxy(t,e)}var me;!function(t){t.proxy=(t,e)=>new Proxy(e,{get:(s,n)=>{const r=e[n],i=t.getAttribute(n);switch(r){case String:return i??void 0;case Number:return null!==i?Number(i):void 0;case Boolean:return null!==i;default:throw new Error(`invalid attribute type for "${n}"`)}},set:(s,n,r)=>{switch(e[n]){case String:return t.setAttribute(n,r),!0;case Number:return t.setAttribute(n,r.toString()),!0;case Boolean:return r?t.setAttribute(n,""):t.removeAttribute(n),!0;default:throw new Error(`invalid attribute type for "${n}"`)}}}),t.on_change=function(t,e){const s=new MutationObserver(e);return s.observe(t,{attributes:!0}),()=>s.disconnect()}}(me||(me={}));class ge{#u;constructor(t){this.#u=t}get state(){return this.#u.getter(this.#u.parent.state)}transmute(t){this.#u.parent.transmute((e=>{const s=this.#u.getter(e),n=t(s);return this.#u.setter(e,n)}))}slice({getter:t,setter:e}){return new ge({parent:this,getter:t,setter:e})}}const ye=t=>"object"==typeof t&&null!==t;const we={clone:function t(e,s=new Set){if(s.has(e))throw new Error("cannot clone circular reference");let n;return"function"==typeof e||null!==e&&"object"==typeof e?(s.add(e),n=Array.isArray(e)?e.map((e=>t(e,new Set(s)))):e.constructor===Object?Object.fromEntries(Object.entries(e).map((([e,n])=>[e,t(n,new Set(s))]))):e instanceof Map?new Map(Array.from(e,(([e,n])=>[e,t(n,new Set(s))]))):e instanceof Set?new Set(Array.from(e,(e=>t(e,new Set(s))))):e instanceof Date?new Date(e.getTime()):e,s.delete(e)):n=e,n},equal:(t,e)=>function t(e,s,n){if(!ye(e)||!ye(s))return e===s;if(n.includes(e))throw new Error("forbidden circularity detected in deep equal comparison");const r=[...n,e];if(e instanceof Map&&s instanceof Map){if(e.size!==s.size)return!1;for(const[n,i]of e)if(!s.has(n)||!t(i,s.get(n),r))return!1}else if(e instanceof Set&&s instanceof Set){if(e.size!==s.size)return!1;for(const n of e)if(!Array.from(s).some((e=>t(n,e,r))))return!1}else{const n=Object.keys(e),i=Object.keys(s);if(n.length!==i.length)return!1;for(const o of n){if(!i.includes(o))return!1;if(!t(e[o],s[o],r))return!1}}return!0}(t,e,[]),freeze:function(t){return function t(e,s){if(!ye(e)||s.includes(e))return e;const n=[...s,e];if(e instanceof Map)for(const s of e.entries())for(const e of s)t(e,n);else if(e instanceof Set)for(const s of e)t(s,n);else if(Array.isArray(e))for(const s of e)t(s,n);else for(const s of Object.values(e))t(s,n);return Object.freeze(e)}(t,[])}};class be{#h;#d;#p;#f=!1;#m(){return we.freeze(structuredClone(this.#h))}constructor(t,e=()=>{}){this.#h=structuredClone(t),this.#d=this.#m(),this.#p=e}get state(){return this.#d}transmute(t){if(this.#f)throw new Error("circular error");this.#f=!0,this.#h=t(structuredClone(this.#h)),this.#d=this.#m(),this.#p(),this.#f=!1}slice({getter:t,setter:e}){return new ge({parent:this,getter:t,setter:e})}}const ve=Error;var _e;function xe(t){return{map:e=>$e(t,e),filter:e=>Ae(t,e)}}!function(t){function e(t){return"ready"===t.status?t.payload:void 0}function s(t,e){switch(t.status){case"loading":return e.loading();case"error":return e.error(t.reason);case"ready":return e.ready(t.payload);default:throw console.error("op",t),new ve("invalid op status")}}t.loading=()=>({status:"loading"}),t.error=t=>({status:"error",reason:t}),t.ready=t=>({status:"ready",payload:t}),t.is=Object.freeze({loading:t=>"loading"===t.status,error:t=>"error"===t.status,ready:t=>"ready"===t.status}),t.payload=e,t.reason=function(t){return"error"===t.status?t.reason:void 0},t.select=s,t.load=async function(e,s){e(t.loading());try{const n=await s();return e(t.ready(n)),n}catch(s){const n=s instanceof ve?s.message:"string"==typeof s?s:"error";throw e(t.error(n)),s}},t.morph=function(e,n){return s(e,{loading:()=>t.loading(),error:e=>t.error(e),ready:e=>t.ready(n(e))})},t.all=function(...s){const n=s.find(t.is.error);return n||(s.every(t.is.ready)?t.ready(s.map(e)):t.loading())}}(_e||(_e={})),xe.pipe=Object.freeze({map:t=>e=>$e(e,t),filter:t=>e=>Ae(e,t)});const $e=(t,e)=>Object.fromEntries(Object.entries(t).map((([t,s])=>[t,e(s,t)]))),Ae=(t,e)=>Object.fromEntries(Object.entries(t).filter((([t,s])=>e(s,t)))),ke=Symbol();class Se extends Error{name=this.constructor.name}class Ee{static unwrap=t=>t instanceof Ee?t.value:t;#g;#y=!1;#c;#w=new Set;[ke]=!1;constructor(t){this.#g=t,this.#c=Promise.resolve(t)}subscribe(t){return this.on(t)}on(t){return this.#w.add(t),()=>{this.#w.delete(t)}}once(t){const e=s=>{t(s),this.#w.delete(e)};return this.#w.add(e),()=>{this.#w.delete(e)}}clear(){return this.#w.clear()}#b=ue(0,(()=>{const t=this.#g;this.#y=!0;for(const e of this.#w)e(t);return this.#y=!1,t}));async publish(){this.#c=this.#b(),await this.#c}get wait(){return this.#c}get value(){return this[ke]=!0,this.#g}set value(t){if(this.#y)throw new Se("you can't set a signal in a signal's subscription listener (infinite loop forbidden)");this.#g!==t&&(this.#g=t,this.publish())}setDeep(t){if(this.#y)throw new Se("you can't set a signal in a signal's subscription listener (infinite loop forbidden)");we.equal(t,this.#g)||(this.#g=t,this.publish())}setAndPublish(t){if(this.#y)throw new Se("you can't set a signal in a signal's subscription listener (infinite loop forbidden)");this.#g=t,this.publish()}setWithoutPublish(t){if(this.#y)throw new Se("you can't set a signal in a signal's subscription listener (infinite loop forbidden)");this.#g=t}setValueNoPublish(t){return this.setWithoutPublish(t)}}class Ce extends Ee{#v=0;constructor(t){super(t)}async load(t){const e=++this.#v;return _e.load((t=>{this.#v===e&&(this.value=t)}),t)}setLoading(){this.value=_e.loading()}setError(t){this.value=_e.error(t)}setReady(t){this.value=_e.ready(t)}isLoading(){return _e.is.loading(this.value)}isError(){return _e.is.error(this.value)}isReady(){return _e.is.ready(this.value)}get payload(){return _e.payload(this.value)}select(t){return _e.select(this.value,t)}}class Oe{#_=!0;#x;#$;#A=new Set;#k=new Set;constructor({all_signals:t,waiters:e}){this.#x=t,this.#$=e}#l=ue(0,(t=>{if(this.#_)if("lean"in t)t.actor();else{const{payload:e,recording:s}=this.observe(t.collector);this.add_listeners(t,s),t.responder&&t.responder(e)}}));#S(){for(const t of this.#x)t[ke]=!1}get#E(){return[...this.#x].filter((t=>t[ke]&&!this.#A.has(t)))}observe(t){this.#S();return{payload:t(),recording:this.#E}}add_listeners(t,e){for(const s of e)this.#A.add(s),this.#k.add(s.on((()=>this.#$.add(this.#l(t)))))}shutdown(){this.#_=!1,this.#k.forEach((t=>t()))}}const Be=new class{static readonly=le;static collectivize=de;#C=new ne;#O=new ie;#B=new Xt;#j=new re;#M=new he;#P=function(t,e,s,n,r){function i([s,r]){if("lean"in r)r.actor();else{const{payload:i,recording:o}=e.record(r.collector);n.add(s,pe(s,o,t,r)),r.responder&&r.responder(i)}}return{get:(t,s)=>(e.record_that_key_was_accessed(t,s),t[s]),set:(e,n,o)=>{if(s.locked)throw new ae(n);e[n]=o;const a=[...t.grab_keymap(e).grab_symbolmap(n)];for(const t of a){const[e]=t;r.add(e,(()=>s.lock((()=>i(t)))))}return!0}}}(this.#C,this.#O,this.#B,this.#j,this.#M);get wait(){return this.#M.wait}state(t){return new Proxy(t,this.#P)}reaction(t,e){const s=Symbol(),{recording:n}=this.#O.record((()=>this.#B.lock(t)));return this.#j.add(s,pe(s,n,this.#C,{collector:t,responder:e})),()=>this.#j.stop(s)}lean(t){const e=Symbol();return{stop:()=>this.#j.stop(e),collect:s=>{const{payload:n,recording:r}=this.#O.record((()=>this.#B.lock(s)));return this.#j.add(e,pe(e,r,this.#C,{lean:!0,actor:t})),n}}}clear(){this.#C.clear()}},je=new class{#T=new Set;#$=new Set;signal(t){const e=new Ee(t);return this.#T.add(e),e}computed(t){const e=this.signal(t());return this.reaction((()=>{e.value=t()})),e}async computedAsync(t,e){const s=await e(t()),n=this.signal(s);return this.reaction(t,(async t=>{n.value=await e(t)})),n}op(t=_e.loading()){const e=new Ce(t);return this.#T.add(e),e}load(t){const e=this.op(_e.loading());return e.load(t),e}many(t){return xe(t).map((t=>this.signal(t)))}reaction(t,e){const s=new Oe({waiters:this.#$,all_signals:this.#T}),n={collector:t,responder:e},{recording:r}=s.observe(n.collector);return s.add_listeners(n,r),()=>s.shutdown()}lean(t){const e=new Oe({waiters:this.#$,all_signals:this.#T}),s={lean:!0,actor:t};return{stop:()=>e.shutdown(),collect:t=>{const{payload:n,recording:r}=e.observe(t);return e.add_listeners(s,r),n}}}async#z(){return await Promise.all([...this.#T].map((t=>t.wait))).then((()=>Promise.all([...this.#$]))).then((()=>{this.#$.clear()}))}get wait(){return Promise.resolve().then((()=>this.#z())).then((()=>this.#z()))}},Me=new class{#T;#R=new Set;#w=new Set;#U=new Map;#q=Promise.resolve();constructor(t){this.#T=t}get wait(){return this.#q}#N=ue(0,(()=>{for(const t of this.#R)t();for(const t of this.#w)t()}));dispatch(){this.#q=this.#N()}computed(t){const e=this.#T.signal(t());return this.#R.add((()=>{e.value=t()})),e}track(t,e){let s=!0;const n=()=>{const n=t(),r=this.#U.get(t);!s&&we.equal(n,r)||(s=!1,this.#U.set(t,n),e(n))};n(),this.#w.add(n);return()=>this.#w.delete(n)}stateTree(t){return new be(t,(()=>this.dispatch()))}}(je);Be.state.bind(Be);const Pe=je.signal.bind(je);je.computed.bind(je),je.op.bind(je);const Te=new class{flat;signals;#c=Promise.resolve();constructor(t,e){this.flat=t,this.signals=e}get wait(){return Promise.all([this.flat.wait,this.signals.wait]).then((()=>this.#c))}reaction(t,e){const s=e?()=>e(r()):()=>r(),n=this.lean(s),r=()=>n.collect(t);return r(),n.stop}lean(t){const e=this.flat.lean(t),s=this.signals.lean(t);return{stop(){e.stop(),s.stop()},collect:t=>e.collect((()=>s.collect(t)))}}}(Be,je);class ze{static with(t){return new this(t)}#t;constructor(t){this.#t=t}to(t){return new ze(t(this.#t))}done(){return this.#t}}var Re;function Ue(t){return[t].flat().filter((t=>!!t))}!function(t){function e(...t){return function(e){return class extends e{static get styles(){return Ne(e.styles,t)}}}}function s(t=Te){return function(e){return class extends e{#D=null;render(){return this.#D?.collect((()=>super.render()))}connectedCallback(){super.connectedCallback(),this.#D=t.lean((()=>this.requestUpdate()))}disconnectedCallback(){super.disconnectedCallback(),this.#D&&(this.#D.stop(),this.#D=null)}}}}t.css=e,t.css_deferred=function(t){return function(e){return class extends e{static get styles(){return Ne(e.styles,t())}}}},t.signals=function(t){return function(e){return class extends e{#D=null;render(){return this.#D?.collect((()=>super.render()))}connectedCallback(){super.connectedCallback(),this.#D=t.lean((()=>this.requestUpdate()))}disconnectedCallback(){super.disconnectedCallback(),this.#D&&(this.#D.stop(),this.#D=null)}}}},t.flat=function(t){return function(e){return class extends e{#D=null;render(){return this.#D?.collect((()=>super.render()))}connectedCallback(){super.connectedCallback(),this.#D=t.lean((()=>this.requestUpdate()))}disconnectedCallback(){super.disconnectedCallback(),this.#D&&(this.#D.stop(),this.#D=null)}}}},t.reactive=s,t.reactor=s,t.setup=function(...t){return function(n){return ze.with(n).to(e(...t)).to(s()).done()}}}(Re||(Re={}));const qe=t=>void 0!==t;function Ne(t,e){return[...Ue(t)??[],...Ue(e)].flat().filter(qe)}var De;function He(t,e={}){const{soft:s=!1,upgrade:n=!0}=e;for(const[e,r]of Object.entries(t)){const t=e.replace(/([a-zA-Z])(?=[A-Z])/g,"$1-").toLowerCase(),i=customElements.get(t);s&&i||(customElements.define(t,r),n&&document.querySelectorAll(t).forEach((t=>{t.constructor===HTMLElement&&customElements.upgrade(t)})))}}!function(t){t.css=t=>e=>xe(e).map((e=>Re.css(t)(e))),t.flat=t=>e=>xe(e).map((e=>Re.flat(t)(e))),t.signals=t=>e=>xe(e).map((e=>Re.signals(t)(e))),t.reactive=(t=Te)=>e=>xe(e).map((e=>Re.reactive(t)(e))),t.reactor=t.reactive,t.context=e=>s=>ze.with(s).to(t.css(e.theme)).to(t.reactive()).done(),t.setup=(...t)=>e=>xe(e).map((e=>Re.setup(...t)(e)))}(De||(De={}));const Le=He,Ie=globalThis,Ve=Ie.ShadowRoot&&(void 0===Ie.ShadyCSS||Ie.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,We=Symbol(),Je=new WeakMap; /** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: BSD-3-Clause */let Ze=class{constructor(t,e,s){if(this._$cssResult$=!0,s!==We)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(Ve&&void 0===t){const s=void 0!==e&&1===e.length;s&&(t=Je.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),s&&Je.set(e,t))}return t}toString(){return this.cssText}};const Fe=(t,...e)=>{const s=1===t.length?t[0]:e.reduce(((e,s,n)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(s)+t[n+1]),t[0]);return new Ze(s,t,We)},Ge=(t,e)=>{if(Ve)t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const s of e){const e=document.createElement("style"),n=Ie.litNonce;void 0!==n&&e.setAttribute("nonce",n),e.textContent=s.cssText,t.appendChild(e)}},Ke=Ve?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return(t=>new Ze("string"==typeof t?t:t+"",void 0,We))(e)})(t):t,{is:Ye,defineProperty:Qe,getOwnPropertyDescriptor:Xe,getOwnPropertyNames:ts,getOwnPropertySymbols:es,getPrototypeOf:ss}=Object,ns=globalThis,rs=ns.trustedTypes,is=rs?rs.emptyScript:"",os=ns.reactiveElementPolyfillSupport,as=(t,e)=>t,cs={toAttribute(t,e){switch(e){case Boolean:t=t?is:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let s=t;switch(e){case Boolean:s=null!==t;break;case Number:s=null===t?null:Number(t);break;case Object:case Array:try{s=JSON.parse(t)}catch(t){s=null}}return s}},ls=(t,e)=>!Ye(t,e),us={attribute:!0,type:String,converter:cs,reflect:!1,useDefault:!1,hasChanged:ls}; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */Symbol.metadata??=Symbol("metadata"),ns.litPropertyMetadata??=new WeakMap;let hs=class extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,e=us){if(e.state&&(e.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((e=Object.create(e)).wrapped=!0),this.elementProperties.set(t,e),!e.noAccessor){const s=Symbol(),n=this.getPropertyDescriptor(t,s,e);void 0!==n&&Qe(this.prototype,t,n)}}static getPropertyDescriptor(t,e,s){const{get:n,set:r}=Xe(this.prototype,t)??{get(){return this[e]},set(t){this[e]=t}};return{get:n,set(e){const i=n?.call(this);r?.call(this,e),this.requestUpdate(t,i,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??us}static _$Ei(){if(this.hasOwnProperty(as("elementProperties")))return;const t=ss(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(as("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(as("properties"))){const t=this.properties,e=[...ts(t),...es(t)];for(const s of e)this.createProperty(s,t[s])}const t=this[Symbol.metadata];if(null!==t){const e=litPropertyMetadata.get(t);if(void 0!==e)for(const[t,s]of e)this.elementProperties.set(t,s)}this._$Eh=new Map;for(const[t,e]of this.elementProperties){const s=this._$Eu(t,e);void 0!==s&&this._$Eh.set(s,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const s=new Set(t.flat(1/0).reverse());for(const t of s)e.unshift(Ke(t))}else void 0!==t&&e.push(Ke(t));return e}static _$Eu(t,e){const s=e.attribute;return!1===s?void 0:"string"==typeof s?s:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)))}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.()}removeController(t){this._$EO?.delete(t)}_$E_(){const t=new Map,e=this.constructor.elementProperties;for(const s of e.keys())this.hasOwnProperty(s)&&(t.set(s,this[s]),delete this[s]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return Ge(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach((t=>t.hostConnected?.()))}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach((t=>t.hostDisconnected?.()))}attributeChangedCallback(t,e,s){this._$AK(t,s)}_$ET(t,e){const s=this.constructor.elementProperties.get(t),n=this.constructor._$Eu(t,s);if(void 0!==n&&!0===s.reflect){const r=(void 0!==s.converter?.toAttribute?s.converter:cs).toAttribute(e,s.type);this._$Em=t,null==r?this.removeAttribute(n):this.setAttribute(n,r),this._$Em=null}}_$AK(t,e){const s=this.constructor,n=s._$Eh.get(t);if(void 0!==n&&this._$Em!==n){const t=s.getPropertyOptions(n),r="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:cs;this._$Em=n,this[n]=r.fromAttribute(e,t.type)??this._$Ej?.get(n)??null,this._$Em=null}}requestUpdate(t,e,s){if(void 0!==t){const n=this.constructor,r=this[t];if(s??=n.getPropertyOptions(t),!((s.hasChanged??ls)(r,e)||s.useDefault&&s.reflect&&r===this._$Ej?.get(t)&&!this.hasAttribute(n._$Eu(t,s))))return;this.C(t,e,s)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(t,e,{useDefault:s,reflect:n,wrapped:r},i){s&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,i??e??this[t]),!0!==r||void 0!==i)||(this._$AL.has(t)||(this.hasUpdated||s||(e=void 0),this._$AL.set(t,e)),!0===n&&this._$Em!==t&&(this._$Eq??=new Set).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,e]of this._$Ep)this[t]=e;this._$Ep=void 0}const t=this.constructor.elementProperties;if(t.size>0)for(const[e,s]of t){const{wrapped:t}=s,n=this[e];!0!==t||this._$AL.has(e)||void 0===n||this.C(e,void 0,s,n)}}let t=!1;const e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),this._$EO?.forEach((t=>t.hostUpdate?.())),this.update(e)):this._$EM()}catch(e){throw t=!1,this._$EM(),e}t&&this._$AE(e)}willUpdate(t){}_$AE(t){this._$EO?.forEach((t=>t.hostUpdated?.())),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&=this._$Eq.forEach((t=>this._$ET(t,this[t]))),this._$EM()}updated(t){}firstUpdated(t){}};hs.elementStyles=[],hs.shadowRootOptions={mode:"open"},hs[as("elementProperties")]=new Map,hs[as("finalized")]=new Map,os?.({ReactiveElement:hs}),(ns.reactiveElementVersions??=[]).push("2.1.0"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const ds=globalThis,ps=ds.trustedTypes,fs=ps?ps.createPolicy("lit-html",{createHTML:t=>t}):void 0,ms="$lit$",gs=`lit$${Math.random().toFixed(9).slice(2)}$`,ys="?"+gs,ws=`<${ys}>`,bs=document,vs=()=>bs.createComment(""),_s=t=>null===t||"object"!=typeof t&&"function"!=typeof t,xs=Array.isArray,$s="[ \t\n\f\r]",As=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,ks=/-->/g,Ss=/>/g,Es=RegExp(`>|${$s}(?:([^\\s"'>=/]+)(${$s}*=${$s}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),Cs=/'/g,Os=/"/g,Bs=/^(?:script|style|textarea|title)$/i,js=t=>(e,...s)=>({_$litType$:t,strings:e,values:s}),Ms=js(1),Ps=js(2),Ts=Symbol.for("lit-noChange"),zs=Symbol.for("lit-nothing"),Rs=new WeakMap,Us=bs.createTreeWalker(bs,129);function qs(t,e){if(!xs(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==fs?fs.createHTML(e):e}const Ns=(t,e)=>{const s=t.length-1,n=[];let r,i=2===e?"<svg>":3===e?"<math>":"",o=As;for(let e=0;e<s;e++){const s=t[e];let a,c,l=-1,u=0;for(;u<s.length&&(o.lastIndex=u,c=o.exec(s),null!==c);)u=o.lastIndex,o===As?"!--"===c[1]?o=ks:void 0!==c[1]?o=Ss:void 0!==c[2]?(Bs.test(c[2])&&(r=RegExp("</"+c[2],"g")),o=Es):void 0!==c[3]&&(o=Es):o===Es?">"===c[0]?(o=r??As,l=-1):void 0===c[1]?l=-2:(l=o.lastIndex-c[2].length,a=c[1],o=void 0===c[3]?Es:'"'===c[3]?Os:Cs):o===Os||o===Cs?o=Es:o===ks||o===Ss?o=As:(o=Es,r=void 0);const h=o===Es&&t[e+1].startsWith("/>")?" ":"";i+=o===As?s+ws:l>=0?(n.push(a),s.slice(0,l)+ms+s.slice(l)+gs+h):s+gs+(-2===l?e:h)}return[qs(t,i+(t[s]||"<?>")+(2===e?"</svg>":3===e?"</math>":"")),n]};class Ds{constructor({strings:t,_$litType$:e},s){let n;this.parts=[];let r=0,i=0;const o=t.length-1,a=this.parts,[c,l]=Ns(t,e);if(this.el=Ds.createElement(c,s),Us.currentNode=this.el.content,2===e||3===e){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes)}for(;null!==(n=Us.nextNode())&&a.length<o;){if(1===n.nodeType){if(n.hasAttributes())for(const t of n.getAttributeNames())if(t.endsWith(ms)){const e=l[i++],s=n.getAttribute(t).split(gs),o=/([.?@])?(.*)/.exec(e);a.push({type:1,index:r,name:o[2],strings:s,ctor:"."===o[1]?Ws:"?"===o[1]?Js:"@"===o[1]?Zs:Vs}),n.removeAttribute(t)}else t.startsWith(gs)&&(a.push({type:6,index:r}),n.removeAttribute(t));if(Bs.test(n.tagName)){const t=n.textContent.split(gs),e=t.length-1;if(e>0){n.textContent=ps?ps.emptyScript:"";for(let s=0;s<e;s++)n.append(t[s],vs()),Us.nextNode(),a.push({type:2,index:++r});n.append(t[e],vs())}}}else if(8===n.nodeType)if(n.data===ys)a.push({type:2,index:r});else{let t=-1;for(;-1!==(t=n.data.indexOf(gs,t+1));)a.push({type:7,index:r}),t+=gs.length-1}r++}}static createElement(t,e){const s=bs.createElement("template");return s.innerHTML=t,s}}function Hs(t,e,s=t,n){if(e===Ts)return e;let r=void 0!==n?s._$Co?.[n]:s._$Cl;const i=_s(e)?void 0:e._$litDirective$;return r?.constructor!==i&&(r?._$AO?.(!1),void 0===i?r=void 0:(r=new i(t),r._$AT(t,s,n)),void 0!==n?(s._$Co??=[])[n]=r:s._$Cl=r),void 0!==r&&(e=Hs(t,r._$AS(t,e.values),r,n)),e}class Ls{constructor(t,e){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:e},parts:s}=this._$AD,n=(t?.creationScope??bs).importNode(e,!0);Us.currentNode=n;let r=Us.nextNode(),i=0,o=0,a=s[0];for(;void 0!==a;){if(i===a.index){let e;2===a.type?e=new Is(r,r.nextSibling,this,t):1===a.type?e=new a.ctor(r,a.name,a.strings,this,t):6===a.type&&(e=new Fs(r,this,t)),this._$AV.push(e),a=s[++o]}i!==a?.index&&(r=Us.nextNode(),i++)}return Us.currentNode=bs,n}p(t){let e=0;for(const s of this._$AV)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,e),e+=s.strings.length-2):s._$AI(t[e])),e++}}class Is{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,e,s,n){this.type=2,this._$AH=zs,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=s,this.options=n,this._$Cv=n?.isConnected??!0}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t?.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=Hs(this,t,e),_s(t)?t===zs||null==t||""===t?(this._$AH!==zs&&this._$AR(),this._$AH=zs):t!==this._$AH&&t!==Ts&&this._(t):void 0!==t