Back to AppStore (dev)
SOURCE / PINNED RELEASE

Made of little things.

AppStore (dev)

Release
049c743b1c61…
Author-recorded commit
Not provided
License
Check the original source

The hash-verified playable HTML, which may contain bundled or minified code. This view does not execute it.

index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
    <title>AppStore</title>
    <meta
      name="description"
      content="An app store for napplets: browse the feed and see what people around you have."
    />
    <script type="module" crossorigin>var No=Object.defineProperty;var Mo=(e,t,n)=>t in e?No(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var S=(e,t,n)=>Mo(e,typeof t!="symbol"?t+"":t,n);function Po(){const e=new Map;function t(i,s){if(e.has(i))throw new Error(`NAP domain "${i}" is already registered`);e.set(i,s)}function n(i){const s=i.type.indexOf(".");if(s<=0)return!1;const o=i.type.slice(0,s),a=e.get(o);return a?(a(i),!0):!1}function r(){return Array.from(e.keys())}return{registerNap:t,dispatch:n,getRegisteredDomains:r}}var Uo=Po(),wt=Uo.registerNap,Ho="relay";function Do(){var t;const e=window;if(!((t=e.napplet)!=null&&t.relay))throw new Error("window.napplet.relay is unavailable -- runtime did not inject the relay domain");return e.napplet.relay}function jo(e,t,n,r){return Do().subscribe(e,t,n,r)}wt(Ho,e=>{});var Fo="identity";function Er(){var t;const e=window;if(!((t=e.napplet)!=null&&t.identity))throw new Error("window.napplet.identity is unavailable -- runtime did not inject this domain");return e.napplet.identity}function qo(){return Er().getPublicKey()}function zo(e){return Er().onChanged(e)}function Ko(){return Er().getFollows()}wt(Fo,e=>{});var Vo="theme";function Wi(){var t;const e=window;if(!((t=e.napplet)!=null&&t.theme))throw new Error("window.napplet.theme is unavailable -- runtime did not inject this domain");return e.napplet.theme}function Wo(){return Wi().get()}function Go(e){return Wi().onChanged(e)}wt(Vo,e=>{});var Zo="resource";function Gi(){var t;const e=window;if(!((t=e.napplet)!=null&&t.resource))throw new Error("window.napplet.resource is unavailable -- runtime did not inject this domain");return e.napplet.resource}function Yo(){return Gi().info()}function yn(e,t){return Gi().bytes(e,t)}wt(Zo,e=>{});var Xo="outbox";function Zi(){var t;const e=window;if(!((t=e.napplet)!=null&&t.outbox))throw new Error("window.napplet.outbox is unavailable -- runtime did not inject this domain");return e.napplet.outbox}function Jo(e,t){return Zi().subscribe(e,t)}function Qo(e,t){return Zi().publish(e,t)}wt(Xo,e=>{});var ea="link";function ta(){var t;const e=window;if(!((t=e.napplet)!=null&&t.link))throw new Error("window.napplet.link is unavailable -- runtime did not inject this domain");return e.napplet.link}function Yi(e,t){return ta().open(e,t)}wt(ea,e=>{});function na(e,t){return!!(e!=null&&e[t])}function ra(e){return na(window.napplet,e)}function ie(e,t){var r;const n=(r=window.napplet)==null?void 0:r[e];return typeof(n==null?void 0:n[t])=="function"}function ia(e){return e<1e4&&e!==0&&e!==3}function Xi(e){return e===0||e===3||1e4<=e&&e<2e4}function Ji(e){return 3e4<=e&&e<4e4}var Qi=0,sa=3,oa=4,es=5,aa=13,ca=1059,ua=1e4,la=10002,fa=10003,da=10004,ha=10005,pa=10007,ya=10015,ma=3e4,ba=30002,ga=30003,va=30004,wa=30015,xa=30024,ka=31990;function ri(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function ts(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function Ea(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");ri(e.outputLen),ri(e.blockLen)}function an(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Sa(e,t){ts(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Tn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ns=e=>e instanceof Uint8Array,On=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),fe=(e,t)=>e<<32-t|e>>>t,Aa=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Aa)throw new Error("Non little-endian hardware is not supported");function Ia(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Sr(e){if(typeof e=="string"&&(e=Ia(e)),!ns(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}function $a(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!ns(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}let rs=class{clone(){return this._cloneInto()}};function _a(e){const t=r=>e().update(Sr(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function is(e=32){if(Tn&&typeof Tn.getRandomValues=="function")return Tn.getRandomValues(new Uint8Array(e));throw new Error("crypto.getRandomValues must be defined")}function Ba(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,u=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+u,a,r)}let Ca=class extends rs{constructor(t,n,r,i){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=On(this.buffer)}update(t){an(this);const{view:n,buffer:r,blockLen:i}=this;t=Sr(t);const s=t.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=On(t);for(;i<=s-o;o+=i)this.process(c,o);continue}r.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){an(this),Sa(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(r,0),o=0);for(let l=o;l<i;l++)n[l]=0;Ba(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=On(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=c/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,d[l],s)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:a}=this;return t.length=i,t.pos=a,t.finished=s,t.destroyed=o,i%n&&t.buffer.set(r),t}};const Ta=(e,t,n)=>e&t^~e&n,Oa=(e,t,n)=>e&t^e&n^t&n,La=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ce=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Te=new Uint32Array(64);let Ra=class extends Ca{constructor(){super(64,32,8,!1),this.A=Ce[0]|0,this.B=Ce[1]|0,this.C=Ce[2]|0,this.D=Ce[3]|0,this.E=Ce[4]|0,this.F=Ce[5]|0,this.G=Ce[6]|0,this.H=Ce[7]|0}get(){const{A:t,B:n,C:r,D:i,E:s,F:o,G:a,H:c}=this;return[t,n,r,i,s,o,a,c]}set(t,n,r,i,s,o,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(t,n){for(let l=0;l<16;l++,n+=4)Te[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const y=Te[l-15],p=Te[l-2],g=fe(y,7)^fe(y,18)^y>>>3,h=fe(p,17)^fe(p,19)^p>>>10;Te[l]=h+Te[l-7]+g+Te[l-16]|0}let{A:r,B:i,C:s,D:o,E:a,F:c,G:u,H:d}=this;for(let l=0;l<64;l++){const y=fe(a,6)^fe(a,11)^fe(a,25),p=d+y+Ta(a,c,u)+La[l]+Te[l]|0,h=(fe(r,2)^fe(r,13)^fe(r,22))+Oa(r,i,s)|0;d=u,u=c,c=a,a=o+p|0,o=s,s=i,i=r,r=p+h|0}r=r+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(r,i,s,o,a,c,u,d)}roundClean(){Te.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Yn=_a(()=>new Ra);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */BigInt(0);const Na=BigInt(1),Ma=BigInt(2),mn=e=>e instanceof Uint8Array,Pa=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function mt(e){if(!mn(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=Pa[e[n]];return t}function Ar(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return BigInt(e===""?"0":`0x${e}`)}function Nt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);const t=e.length;if(t%2)throw new Error("padded hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(t/2);for(let r=0;r<n.length;r++){const i=r*2,s=e.slice(i,i+2),o=Number.parseInt(s,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");n[r]=o}return n}function G(e){return Ar(mt(e))}function Ir(e){if(!mn(e))throw new Error("Uint8Array expected");return Ar(mt(Uint8Array.from(e).reverse()))}function Pe(e,t){return Nt(e.toString(16).padStart(t*2,"0"))}function $r(e,t){return Pe(e,t).reverse()}function q(e,t,n){let r;if(typeof t=="string")try{r=Nt(t)}catch(s){throw new Error(`${e} must be valid hex string, got "${t}". Cause: ${s}`)}else if(mn(t))r=Uint8Array.from(t);else throw new Error(`${e} must be hex string or Uint8Array`);const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(`${e} expected ${n} bytes, got ${i}`);return r}function Qe(...e){const t=new Uint8Array(e.reduce((r,i)=>r+i.length,0));let n=0;return e.forEach(r=>{if(!mn(r))throw new Error("Uint8Array expected");t.set(r,n),n+=r.length}),t}const _r=e=>(Ma<<BigInt(e-1))-Na,Ln=e=>new Uint8Array(e),ii=e=>Uint8Array.from(e);function ss(e,t,n){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof n!="function")throw new Error("hmacFn must be a function");let r=Ln(e),i=Ln(e),s=0;const o=()=>{r.fill(1),i.fill(0),s=0},a=(...l)=>n(i,r,...l),c=(l=Ln())=>{i=a(ii([0]),l),r=a(),l.length!==0&&(i=a(ii([1]),l),r=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0;const y=[];for(;l<t;){r=a();const p=r.slice();y.push(p),l+=r.length}return Qe(...y)};return(l,y)=>{o(),c(l);let p;for(;!(p=y(u()));)c();return o(),p}}const Ua={bigint:e=>typeof e=="bigint",function:e=>typeof e=="function",boolean:e=>typeof e=="boolean",string:e=>typeof e=="string",stringOrUint8Array:e=>typeof e=="string"||e instanceof Uint8Array,isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>typeof e=="function"&&Number.isSafeInteger(e.outputLen)};function qt(e,t,n={}){const r=(i,s,o)=>{const a=Ua[s];if(typeof a!="function")throw new Error(`Invalid validator "${s}", expected function`);const c=e[i];if(!(o&&c===void 0)&&!a(c,e))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${s}`)};for(const[i,s]of Object.entries(t))r(i,s,!1);for(const[i,s]of Object.entries(n))r(i,s,!0);return e}const Ha=Object.freeze(Object.defineProperty({__proto__:null,bitMask:_r,bytesToHex:mt,bytesToNumberBE:G,bytesToNumberLE:Ir,concatBytes:Qe,createHmacDrbg:ss,ensureBytes:q,hexToBytes:Nt,hexToNumber:Ar,numberToBytesBE:Pe,numberToBytesLE:$r,validateObject:qt},Symbol.toStringTag,{value:"Module"}));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const j=BigInt(0),M=BigInt(1),Ge=BigInt(2),Da=BigInt(3),Xn=BigInt(4),si=BigInt(5),oi=BigInt(8);BigInt(9);BigInt(16);function F(e,t){const n=e%t;return n>=j?n:t+n}function ja(e,t,n){if(n<=j||t<j)throw new Error("Expected power/modulo > 0");if(n===M)return j;let r=M;for(;t>j;)t&M&&(r=r*e%n),e=e*e%n,t>>=M;return r}function te(e,t,n){let r=e;for(;t-- >j;)r*=r,r%=n;return r}function Jn(e,t){if(e===j||t<=j)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=F(e,t),r=t,i=j,s=M;for(;n!==j;){const a=r/n,c=r%n,u=i-s*a;r=n,n=c,i=s,s=u}if(r!==M)throw new Error("invert: does not exist");return F(i,t)}function Fa(e){const t=(e-M)/Ge;let n,r,i;for(n=e-M,r=0;n%Ge===j;n/=Ge,r++);for(i=Ge;i<e&&ja(i,t,e)!==e-M;i++);if(r===1){const o=(e+M)/Xn;return function(c,u){const d=c.pow(u,o);if(!c.eql(c.sqr(d),u))throw new Error("Cannot find square root");return d}}const s=(n+M)/Ge;return function(a,c){if(a.pow(c,t)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=r,d=a.pow(a.mul(a.ONE,i),n),l=a.pow(c,s),y=a.pow(c,n);for(;!a.eql(y,a.ONE);){if(a.eql(y,a.ZERO))return a.ZERO;let p=1;for(let h=a.sqr(y);p<u&&!a.eql(h,a.ONE);p++)h=a.sqr(h);const g=a.pow(d,M<<BigInt(u-p-1));d=a.sqr(g),l=a.mul(l,g),y=a.mul(y,d),u=p}return l}}function qa(e){if(e%Xn===Da){const t=(e+M)/Xn;return function(r,i){const s=r.pow(i,t);if(!r.eql(r.sqr(s),i))throw new Error("Cannot find square root");return s}}if(e%oi===si){const t=(e-si)/oi;return function(r,i){const s=r.mul(i,Ge),o=r.pow(s,t),a=r.mul(i,o),c=r.mul(r.mul(a,Ge),o),u=r.mul(a,r.sub(c,r.ONE));if(!r.eql(r.sqr(u),i))throw new Error("Cannot find square root");return u}}return Fa(e)}const za=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ka(e){const t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=za.reduce((r,i)=>(r[i]="function",r),t);return qt(e,n)}function Va(e,t,n){if(n<j)throw new Error("Expected power > 0");if(n===j)return e.ONE;if(n===M)return t;let r=e.ONE,i=t;for(;n>j;)n&M&&(r=e.mul(r,i)),i=e.sqr(i),n>>=M;return r}function Wa(e,t){const n=new Array(t.length),r=t.reduce((s,o,a)=>e.is0(o)?s:(n[a]=s,e.mul(s,o)),e.ONE),i=e.inv(r);return t.reduceRight((s,o,a)=>e.is0(o)?s:(n[a]=e.mul(s,n[a]),e.mul(s,o)),i),n}function os(e,t){const n=t!==void 0?t:e.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Ga(e,t,n=!1,r={}){if(e<=j)throw new Error(`Expected Field ORDER > 0, got ${e}`);const{nBitLength:i,nByteLength:s}=os(e,t);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");const o=qa(e),a=Object.freeze({ORDER:e,BITS:i,BYTES:s,MASK:_r(i),ZERO:j,ONE:M,create:c=>F(c,e),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return j<=c&&c<e},is0:c=>c===j,isOdd:c=>(c&M)===M,neg:c=>F(-c,e),eql:(c,u)=>c===u,sqr:c=>F(c*c,e),add:(c,u)=>F(c+u,e),sub:(c,u)=>F(c-u,e),mul:(c,u)=>F(c*u,e),pow:(c,u)=>Va(a,c,u),div:(c,u)=>F(c*Jn(u,e),e),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Jn(c,e),sqrt:r.sqrt||(c=>o(a,c)),invertBatch:c=>Wa(a,c),cmov:(c,u,d)=>d?u:c,toBytes:c=>n?$r(c,s):Pe(c,s),fromBytes:c=>{if(c.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${c.length}`);return n?Ir(c):G(c)}});return Object.freeze(a)}function as(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function cs(e){const t=as(e);return t+Math.ceil(t/2)}function Za(e,t,n=!1){const r=e.length,i=as(t),s=cs(t);if(r<16||r<s||r>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${r}`);const o=n?G(e):Ir(e),a=F(o,t-M)+M;return n?$r(a,i):Pe(a,i)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ya=BigInt(0),Rn=BigInt(1);function Xa(e,t){const n=(i,s)=>{const o=s.negate();return i?o:s},r=i=>{const s=Math.ceil(t/i)+1,o=2**(i-1);return{windows:s,windowSize:o}};return{constTimeNegate:n,unsafeLadder(i,s){let o=e.ZERO,a=i;for(;s>Ya;)s&Rn&&(o=o.add(a)),a=a.double(),s>>=Rn;return o},precomputeWindow(i,s){const{windows:o,windowSize:a}=r(s),c=[];let u=i,d=u;for(let l=0;l<o;l++){d=u,c.push(d);for(let y=1;y<a;y++)d=d.add(u),c.push(d);u=d.double()}return c},wNAF(i,s,o){const{windows:a,windowSize:c}=r(i);let u=e.ZERO,d=e.BASE;const l=BigInt(2**i-1),y=2**i,p=BigInt(i);for(let g=0;g<a;g++){const h=g*c;let m=Number(o&l);o>>=p,m>c&&(m-=y,o+=Rn);const v=h,k=h+Math.abs(m)-1,E=g%2!==0,B=m<0;m===0?d=d.add(n(E,s[v])):u=u.add(n(B,s[k]))}return{p:u,f:d}},wNAFCached(i,s,o,a){const c=i._WINDOW_SIZE||1;let u=s.get(i);return u||(u=this.precomputeWindow(i,c),c!==1&&s.set(i,a(u))),this.wNAF(c,u,o)}}}function us(e){return Ka(e.Fp),qt(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...os(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Ja(e){const t=us(e);qt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:n,Fp:r,a:i}=t;if(n){if(!r.eql(i,r.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}const{bytesToNumberBE:Qa,hexToBytes:ec}=Ha,Ze={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(e){const{Err:t}=Ze;if(e.length<2||e[0]!==2)throw new t("Invalid signature integer tag");const n=e[1],r=e.subarray(2,n+2);if(!n||r.length!==n)throw new t("Invalid signature integer: wrong length");if(r[0]&128)throw new t("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:Qa(r),l:e.subarray(n+2)}},toSig(e){const{Err:t}=Ze,n=typeof e=="string"?ec(e):e;if(!(n instanceof Uint8Array))throw new Error("ui8a expected");let r=n.length;if(r<2||n[0]!=48)throw new t("Invalid signature tag");if(n[1]!==r-2)throw new t("Invalid signature: incorrect length");const{d:i,l:s}=Ze._parseInt(n.subarray(2)),{d:o,l:a}=Ze._parseInt(s);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:i,s:o}},hexFromSig(e){const t=u=>Number.parseInt(u[0],16)&8?"00"+u:u,n=u=>{const d=u.toString(16);return d.length&1?`0${d}`:d},r=t(n(e.s)),i=t(n(e.r)),s=r.length/2,o=i.length/2,a=n(s),c=n(o);return`30${n(o+s+4)}02${c}${i}02${a}${r}`}},ge=BigInt(0),re=BigInt(1);BigInt(2);const ai=BigInt(3);BigInt(4);function tc(e){const t=Ja(e),{Fp:n}=t,r=t.toBytes||((g,h,m)=>{const v=h.toAffine();return Qe(Uint8Array.from([4]),n.toBytes(v.x),n.toBytes(v.y))}),i=t.fromBytes||(g=>{const h=g.subarray(1),m=n.fromBytes(h.subarray(0,n.BYTES)),v=n.fromBytes(h.subarray(n.BYTES,2*n.BYTES));return{x:m,y:v}});function s(g){const{a:h,b:m}=t,v=n.sqr(g),k=n.mul(v,g);return n.add(n.add(k,n.mul(g,h)),m)}if(!n.eql(n.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function o(g){return typeof g=="bigint"&&ge<g&&g<t.n}function a(g){if(!o(g))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(g){const{allowedPrivateKeyLengths:h,nByteLength:m,wrapPrivateKey:v,n:k}=t;if(h&&typeof g!="bigint"){if(g instanceof Uint8Array&&(g=mt(g)),typeof g!="string"||!h.includes(g.length))throw new Error("Invalid key");g=g.padStart(m*2,"0")}let E;try{E=typeof g=="bigint"?g:G(q("private key",g,m))}catch{throw new Error(`private key must be ${m} bytes, hex or bigint, not ${typeof g}`)}return v&&(E=F(E,k)),a(E),E}const u=new Map;function d(g){if(!(g instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(h,m,v){if(this.px=h,this.py=m,this.pz=v,h==null||!n.isValid(h))throw new Error("x required");if(m==null||!n.isValid(m))throw new Error("y required");if(v==null||!n.isValid(v))throw new Error("z required")}static fromAffine(h){const{x:m,y:v}=h||{};if(!h||!n.isValid(m)||!n.isValid(v))throw new Error("invalid affine point");if(h instanceof l)throw new Error("projective point not allowed");const k=E=>n.eql(E,n.ZERO);return k(m)&&k(v)?l.ZERO:new l(m,v,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){const m=n.invertBatch(h.map(v=>v.pz));return h.map((v,k)=>v.toAffine(m[k])).map(l.fromAffine)}static fromHex(h){const m=l.fromAffine(i(q("pointHex",h)));return m.assertValidity(),m}static fromPrivateKey(h){return l.BASE.multiply(c(h))}_setWindowSize(h){this._WINDOW_SIZE=h,u.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!n.is0(this.py))return;throw new Error("bad point: ZERO")}const{x:h,y:m}=this.toAffine();if(!n.isValid(h)||!n.isValid(m))throw new Error("bad point: x or y not FE");const v=n.sqr(m),k=s(h);if(!n.eql(v,k))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){const{y:h}=this.toAffine();if(n.isOdd)return!n.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){d(h);const{px:m,py:v,pz:k}=this,{px:E,py:B,pz:I}=h,x=n.eql(n.mul(m,I),n.mul(E,k)),A=n.eql(n.mul(v,I),n.mul(B,k));return x&&A}negate(){return new l(this.px,n.neg(this.py),this.pz)}double(){const{a:h,b:m}=t,v=n.mul(m,ai),{px:k,py:E,pz:B}=this;let I=n.ZERO,x=n.ZERO,A=n.ZERO,_=n.mul(k,k),ee=n.mul(E,E),N=n.mul(B,B),T=n.mul(k,E);return T=n.add(T,T),A=n.mul(k,B),A=n.add(A,A),I=n.mul(h,A),x=n.mul(v,N),x=n.add(I,x),I=n.sub(ee,x),x=n.add(ee,x),x=n.mul(I,x),I=n.mul(T,I),A=n.mul(v,A),N=n.mul(h,N),T=n.sub(_,N),T=n.mul(h,T),T=n.add(T,A),A=n.add(_,_),_=n.add(A,_),_=n.add(_,N),_=n.mul(_,T),x=n.add(x,_),N=n.mul(E,B),N=n.add(N,N),_=n.mul(N,T),I=n.sub(I,_),A=n.mul(N,ee),A=n.add(A,A),A=n.add(A,A),new l(I,x,A)}add(h){d(h);const{px:m,py:v,pz:k}=this,{px:E,py:B,pz:I}=h;let x=n.ZERO,A=n.ZERO,_=n.ZERO;const ee=t.a,N=n.mul(t.b,ai);let T=n.mul(m,E),Z=n.mul(v,B),Y=n.mul(k,I),Ie=n.add(m,v),b=n.add(E,B);Ie=n.mul(Ie,b),b=n.add(T,Z),Ie=n.sub(Ie,b),b=n.add(m,k);let w=n.add(E,I);return b=n.mul(b,w),w=n.add(T,Y),b=n.sub(b,w),w=n.add(v,k),x=n.add(B,I),w=n.mul(w,x),x=n.add(Z,Y),w=n.sub(w,x),_=n.mul(ee,b),x=n.mul(N,Y),_=n.add(x,_),x=n.sub(Z,_),_=n.add(Z,_),A=n.mul(x,_),Z=n.add(T,T),Z=n.add(Z,T),Y=n.mul(ee,Y),b=n.mul(N,b),Z=n.add(Z,Y),Y=n.sub(T,Y),Y=n.mul(ee,Y),b=n.add(b,Y),T=n.mul(Z,b),A=n.add(A,T),T=n.mul(w,b),x=n.mul(Ie,x),x=n.sub(x,T),T=n.mul(Ie,Z),_=n.mul(w,_),_=n.add(_,T),new l(x,A,_)}subtract(h){return this.add(h.negate())}is0(){return this.equals(l.ZERO)}wNAF(h){return p.wNAFCached(this,u,h,m=>{const v=n.invertBatch(m.map(k=>k.pz));return m.map((k,E)=>k.toAffine(v[E])).map(l.fromAffine)})}multiplyUnsafe(h){const m=l.ZERO;if(h===ge)return m;if(a(h),h===re)return this;const{endo:v}=t;if(!v)return p.unsafeLadder(this,h);let{k1neg:k,k1:E,k2neg:B,k2:I}=v.splitScalar(h),x=m,A=m,_=this;for(;E>ge||I>ge;)E&re&&(x=x.add(_)),I&re&&(A=A.add(_)),_=_.double(),E>>=re,I>>=re;return k&&(x=x.negate()),B&&(A=A.negate()),A=new l(n.mul(A.px,v.beta),A.py,A.pz),x.add(A)}multiply(h){a(h);let m=h,v,k;const{endo:E}=t;if(E){const{k1neg:B,k1:I,k2neg:x,k2:A}=E.splitScalar(m);let{p:_,f:ee}=this.wNAF(I),{p:N,f:T}=this.wNAF(A);_=p.constTimeNegate(B,_),N=p.constTimeNegate(x,N),N=new l(n.mul(N.px,E.beta),N.py,N.pz),v=_.add(N),k=ee.add(T)}else{const{p:B,f:I}=this.wNAF(m);v=B,k=I}return l.normalizeZ([v,k])[0]}multiplyAndAddUnsafe(h,m,v){const k=l.BASE,E=(I,x)=>x===ge||x===re||!I.equals(k)?I.multiplyUnsafe(x):I.multiply(x),B=E(this,m).add(E(h,v));return B.is0()?void 0:B}toAffine(h){const{px:m,py:v,pz:k}=this,E=this.is0();h==null&&(h=E?n.ONE:n.inv(k));const B=n.mul(m,h),I=n.mul(v,h),x=n.mul(k,h);if(E)return{x:n.ZERO,y:n.ZERO};if(!n.eql(x,n.ONE))throw new Error("invZ was invalid");return{x:B,y:I}}isTorsionFree(){const{h,isTorsionFree:m}=t;if(h===re)return!0;if(m)return m(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h,clearCofactor:m}=t;return h===re?this:m?m(l,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return this.assertValidity(),r(l,this,h)}toHex(h=!0){return mt(this.toRawBytes(h))}}l.BASE=new l(t.Gx,t.Gy,n.ONE),l.ZERO=new l(n.ZERO,n.ONE,n.ZERO);const y=t.nBitLength,p=Xa(l,t.endo?Math.ceil(y/2):y);return{CURVE:t,ProjectivePoint:l,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:o}}function nc(e){const t=us(e);return qt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function rc(e){const t=nc(e),{Fp:n,n:r}=t,i=n.BYTES+1,s=2*n.BYTES+1;function o(b){return ge<b&&b<n.ORDER}function a(b){return F(b,r)}function c(b){return Jn(b,r)}const{ProjectivePoint:u,normPrivateKeyToScalar:d,weierstrassEquation:l,isWithinCurveOrder:y}=tc({...t,toBytes(b,w,$){const R=w.toAffine(),O=n.toBytes(R.x),H=Qe;return $?H(Uint8Array.from([w.hasEvenY()?2:3]),O):H(Uint8Array.from([4]),O,n.toBytes(R.y))},fromBytes(b){const w=b.length,$=b[0],R=b.subarray(1);if(w===i&&($===2||$===3)){const O=G(R);if(!o(O))throw new Error("Point is not on curve");const H=l(O);let X=n.sqrt(H);const J=(X&re)===re;return($&1)===1!==J&&(X=n.neg(X)),{x:O,y:X}}else if(w===s&&$===4){const O=n.fromBytes(R.subarray(0,n.BYTES)),H=n.fromBytes(R.subarray(n.BYTES,2*n.BYTES));return{x:O,y:H}}else throw new Error(`Point of length ${w} was invalid. Expected ${i} compressed bytes or ${s} uncompressed bytes`)}}),p=b=>mt(Pe(b,t.nByteLength));function g(b){const w=r>>re;return b>w}function h(b){return g(b)?a(-b):b}const m=(b,w,$)=>G(b.slice(w,$));class v{constructor(w,$,R){this.r=w,this.s=$,this.recovery=R,this.assertValidity()}static fromCompact(w){const $=t.nByteLength;return w=q("compactSignature",w,$*2),new v(m(w,0,$),m(w,$,2*$))}static fromDER(w){const{r:$,s:R}=Ze.toSig(q("DER",w));return new v($,R)}assertValidity(){if(!y(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!y(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(w){return new v(this.r,this.s,w)}recoverPublicKey(w){const{r:$,s:R,recovery:O}=this,H=A(q("msgHash",w));if(O==null||![0,1,2,3].includes(O))throw new Error("recovery id invalid");const X=O===2||O===3?$+t.n:$;if(X>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const J=(O&1)===0?"02":"03",$e=u.fromHex(J+p(X)),_e=c(X),at=a(-H*_e),St=a(R*_e),Be=u.BASE.multiplyAndAddUnsafe($e,at,St);if(!Be)throw new Error("point at infinify");return Be.assertValidity(),Be}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new v(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return Nt(this.toDERHex())}toDERHex(){return Ze.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Nt(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}const k={isValidPrivateKey(b){try{return d(b),!0}catch{return!1}},normPrivateKeyToScalar:d,randomPrivateKey:()=>{const b=cs(t.n);return Za(t.randomBytes(b),t.n)},precompute(b=8,w=u.BASE){return w._setWindowSize(b),w.multiply(BigInt(3)),w}};function E(b,w=!0){return u.fromPrivateKey(b).toRawBytes(w)}function B(b){const w=b instanceof Uint8Array,$=typeof b=="string",R=(w||$)&&b.length;return w?R===i||R===s:$?R===2*i||R===2*s:b instanceof u}function I(b,w,$=!0){if(B(b))throw new Error("first arg must be private key");if(!B(w))throw new Error("second arg must be public key");return u.fromHex(w).multiply(d(b)).toRawBytes($)}const x=t.bits2int||function(b){const w=G(b),$=b.length*8-t.nBitLength;return $>0?w>>BigInt($):w},A=t.bits2int_modN||function(b){return a(x(b))},_=_r(t.nBitLength);function ee(b){if(typeof b!="bigint")throw new Error("bigint expected");if(!(ge<=b&&b<_))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Pe(b,t.nByteLength)}function N(b,w,$=T){if(["recovered","canonical"].some(qe=>qe in $))throw new Error("sign() legacy options not supported");const{hash:R,randomBytes:O}=t;let{lowS:H,prehash:X,extraEntropy:J}=$;H==null&&(H=!0),b=q("msgHash",b),X&&(b=q("prehashed msgHash",R(b)));const $e=A(b),_e=d(w),at=[ee(_e),ee($e)];if(J!=null){const qe=J===!0?O(n.BYTES):J;at.push(q("extraEntropy",qe))}const St=Qe(...at),Be=$e;function Cn(qe){const ct=x(qe);if(!y(ct))return;const ei=c(ct),ut=u.BASE.multiply(ct).toAffine(),ae=a(ut.x);if(ae===ge)return;const lt=a(ei*a(Be+ae*_e));if(lt===ge)return;let ti=(ut.x===ae?0:2)|Number(ut.y&re),ni=lt;return H&&g(lt)&&(ni=h(lt),ti^=1),new v(ae,ni,ti)}return{seed:St,k2sig:Cn}}const T={lowS:t.lowS,prehash:!1},Z={lowS:t.lowS,prehash:!1};function Y(b,w,$=T){const{seed:R,k2sig:O}=N(b,w,$),H=t;return ss(H.hash.outputLen,H.nByteLength,H.hmac)(R,O)}u.BASE._setWindowSize(8);function Ie(b,w,$,R=Z){var ut;const O=b;if(w=q("msgHash",w),$=q("publicKey",$),"strict"in R)throw new Error("options.strict was renamed to lowS");const{lowS:H,prehash:X}=R;let J,$e;try{if(typeof O=="string"||O instanceof Uint8Array)try{J=v.fromDER(O)}catch(ae){if(!(ae instanceof Ze.Err))throw ae;J=v.fromCompact(O)}else if(typeof O=="object"&&typeof O.r=="bigint"&&typeof O.s=="bigint"){const{r:ae,s:lt}=O;J=new v(ae,lt)}else throw new Error("PARSE");$e=u.fromHex($)}catch(ae){if(ae.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(H&&J.hasHighS())return!1;X&&(w=t.hash(w));const{r:_e,s:at}=J,St=A(w),Be=c(at),Cn=a(St*Be),qe=a(_e*Be),ct=(ut=u.BASE.multiplyAndAddUnsafe($e,Cn,qe))==null?void 0:ut.toAffine();return ct?a(ct.x)===_e:!1}return{CURVE:t,getPublicKey:E,getSharedSecret:I,sign:Y,verify:Ie,ProjectivePoint:u,Signature:v,utils:k}}class ls extends rs{constructor(t,n){super(),this.finished=!1,this.destroyed=!1,Ea(t);const r=Sr(n);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,s=new Uint8Array(i);s.set(r.length>i?t.create().update(r).digest():r);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=t.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(t){return an(this),this.iHash.update(t),this}digestInto(t){an(this),ts(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:n,iHash:r,finished:i,destroyed:s,blockLen:o,outputLen:a}=this;return t=t,t.finished=i,t.destroyed=s,t.blockLen=o,t.outputLen=a,t.oHash=n._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const fs=(e,t,n)=>new ls(e,t).update(n).digest();fs.create=(e,t)=>new ls(e,t);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */function ic(e){return{hash:e,hmac:(t,...n)=>fs(e,t,$a(...n)),randomBytes:is}}function sc(e,t){const n=r=>rc({...e,...ic(r)});return Object.freeze({...n(t),create:n})}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const bn=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),cn=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),ds=BigInt(1),un=BigInt(2),ci=(e,t)=>(e+t/un)/t;function hs(e){const t=bn,n=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,d=u*u*e%t,l=te(d,n,t)*d%t,y=te(l,n,t)*d%t,p=te(y,un,t)*u%t,g=te(p,i,t)*p%t,h=te(g,s,t)*g%t,m=te(h,a,t)*h%t,v=te(m,c,t)*m%t,k=te(v,a,t)*h%t,E=te(k,n,t)*d%t,B=te(E,o,t)*g%t,I=te(B,r,t)*u%t,x=te(I,un,t);if(!Qn.eql(Qn.sqr(x),e))throw new Error("Cannot find square root");return x}const Qn=Ga(bn,void 0,void 0,{sqrt:hs}),Br=sc({a:BigInt(0),b:BigInt(7),Fp:Qn,n:cn,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=cn,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-ds*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,o=BigInt("0x100000000000000000000000000000000"),a=ci(s*e,t),c=ci(-r*e,t);let u=F(e-a*n-c*i,t),d=F(-a*r-c*s,t);const l=u>o,y=d>o;if(l&&(u=t-u),y&&(d=t-d),u>o||d>o)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:l,k1:u,k2neg:y,k2:d}}}},Yn),gn=BigInt(0),ps=e=>typeof e=="bigint"&&gn<e&&e<bn,oc=e=>typeof e=="bigint"&&gn<e&&e<cn,ui={};function ln(e,...t){let n=ui[e];if(n===void 0){const r=Yn(Uint8Array.from(e,i=>i.charCodeAt(0)));n=Qe(r,r),ui[e]=n}return Yn(Qe(n,...t))}const Cr=e=>e.toRawBytes(!0).slice(1),er=e=>Pe(e,32),Nn=e=>F(e,bn),Mt=e=>F(e,cn),Tr=Br.ProjectivePoint,ac=(e,t,n)=>Tr.BASE.multiplyAndAddUnsafe(e,t,n);function tr(e){let t=Br.utils.normPrivateKeyToScalar(e),n=Tr.fromPrivateKey(t);return{scalar:n.hasEvenY()?t:Mt(-t),bytes:Cr(n)}}function ys(e){if(!ps(e))throw new Error("bad x: need 0 < x < p");const t=Nn(e*e),n=Nn(t*e+BigInt(7));let r=hs(n);r%un!==gn&&(r=Nn(-r));const i=new Tr(e,r,ds);return i.assertValidity(),i}function ms(...e){return Mt(G(ln("BIP0340/challenge",...e)))}function cc(e){return tr(e).bytes}function uc(e,t,n=is(32)){const r=q("message",e),{bytes:i,scalar:s}=tr(t),o=q("auxRand",n,32),a=er(s^G(ln("BIP0340/aux",o))),c=ln("BIP0340/nonce",a,i,r),u=Mt(G(c));if(u===gn)throw new Error("sign failed: k is zero");const{bytes:d,scalar:l}=tr(u),y=ms(d,i,r),p=new Uint8Array(64);if(p.set(d,0),p.set(er(Mt(l+y*s)),32),!bs(p,r,i))throw new Error("sign: Invalid signature produced");return p}function bs(e,t,n){const r=q("signature",e,64),i=q("message",t),s=q("publicKey",n,32);try{const o=ys(G(s)),a=G(r.subarray(0,32));if(!ps(a))return!1;const c=G(r.subarray(32,64));if(!oc(c))return!1;const u=ms(er(a),Cr(o),i),d=ac(o,c,Mt(-u));return!(!d||!d.hasEvenY()||d.toAffine().x!==a)}catch{return!1}}const At={getPublicKey:cc,sign:uc,verify:bs,utils:{randomPrivateKey:Br.utils.randomPrivateKey,lift_x:ys,pointToBytes:Cr,numberToBytesBE:Pe,bytesToNumberBE:G,taggedHash:ln,mod:F}};/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const gs=e=>e instanceof Uint8Array,Mn=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),de=(e,t)=>e<<32-t|e>>>t,lc=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!lc)throw new Error("Non little-endian hardware is not supported");const fc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Qt(e){if(!gs(e))throw new Error("Uint8Array expected");let t="";for(let n=0;n<e.length;n++)t+=fc[e[n]];return t}function dc(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function vs(e){if(typeof e=="string"&&(e=dc(e)),!gs(e))throw new Error(`expected Uint8Array, got ${typeof e}`);return e}class hc{clone(){return this._cloneInto()}}function ws(e){const t=r=>e().update(vs(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function nr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`Wrong positive integer: ${e}`)}function pc(e){if(typeof e!="boolean")throw new Error(`Expected boolean, not ${e}`)}function xs(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}function yc(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");nr(e.outputLen),nr(e.blockLen)}function mc(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function bc(e,t){xs(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const Pn={number:nr,bool:pc,bytes:xs,hash:yc,exists:mc,output:bc};function gc(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,u=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+u,a,r)}class vc extends hc{constructor(t,n,r,i){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=Mn(this.buffer)}update(t){Pn.exists(this);const{view:n,buffer:r,blockLen:i}=this;t=vs(t);const s=t.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=Mn(t);for(;i<=s-o;o+=i)this.process(c,o);continue}r.set(t.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Pn.exists(this),Pn.output(t,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(r,0),o=0);for(let l=o;l<i;l++)n[l]=0;gc(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=Mn(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=c/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,d[l],s)}digest(){const{buffer:t,outputLen:n}=this;this.digestInto(t);const r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:a}=this;return t.length=i,t.pos=a,t.finished=s,t.destroyed=o,i%n&&t.buffer.set(r),t}}const wc=(e,t,n)=>e&t^~e&n,xc=(e,t,n)=>e&t^e&n^t&n,kc=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Oe=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Le=new Uint32Array(64);class ks extends vc{constructor(){super(64,32,8,!1),this.A=Oe[0]|0,this.B=Oe[1]|0,this.C=Oe[2]|0,this.D=Oe[3]|0,this.E=Oe[4]|0,this.F=Oe[5]|0,this.G=Oe[6]|0,this.H=Oe[7]|0}get(){const{A:t,B:n,C:r,D:i,E:s,F:o,G:a,H:c}=this;return[t,n,r,i,s,o,a,c]}set(t,n,r,i,s,o,a,c){this.A=t|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(t,n){for(let l=0;l<16;l++,n+=4)Le[l]=t.getUint32(n,!1);for(let l=16;l<64;l++){const y=Le[l-15],p=Le[l-2],g=de(y,7)^de(y,18)^y>>>3,h=de(p,17)^de(p,19)^p>>>10;Le[l]=h+Le[l-7]+g+Le[l-16]|0}let{A:r,B:i,C:s,D:o,E:a,F:c,G:u,H:d}=this;for(let l=0;l<64;l++){const y=de(a,6)^de(a,11)^de(a,25),p=d+y+wc(a,c,u)+kc[l]+Le[l]|0,h=(de(r,2)^de(r,13)^de(r,22))+xc(r,i,s)|0;d=u,u=c,c=a,a=o+p|0,o=s,s=i,i=r,r=p+h|0}r=r+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(r,i,s,o,a,c,u,d)}roundClean(){Le.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class Ec extends ks{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}const Sc=ws(()=>new ks);ws(()=>new Ec);var Ve=Symbol("verified"),Ac=e=>e instanceof Object;function Ic(e){if(!Ac(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){let n=e.tags[t];if(!Array.isArray(n))return!1;for(let r=0;r<n.length;r++)if(typeof n[r]!="string")return!1}return!0}new TextDecoder("utf-8");var $c=new TextEncoder,_c=class{generateSecretKey(){return At.utils.randomPrivateKey()}getPublicKey(e){return Qt(At.getPublicKey(e))}finalizeEvent(e,t){const n=e;return n.pubkey=Qt(At.getPublicKey(t)),n.id=Un(n),n.sig=Qt(At.sign(Un(n),t)),n[Ve]=!0,n}verifyEvent(e){if(typeof e[Ve]=="boolean")return e[Ve];const t=Un(e);if(t!==e.id)return e[Ve]=!1,!1;try{const n=At.verify(e.sig,t,e.pubkey);return e[Ve]=n,n}catch{return e[Ve]=!1,!1}}};function Bc(e){if(!Ic(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function Un(e){let t=Sc($c.encode(Bc(e)));return Qt(t)}var vn=new _c;vn.generateSecretKey;vn.getPublicKey;vn.finalizeEvent;var Cc=vn.verifyEvent;function it(e,t,n){if(Reflect.has(e,t))return Reflect.get(e,t);{const r=n();return Reflect.set(e,t,r),r}}new TextDecoder("utf-8");new TextEncoder;function en(e,t){const[n,r]=tn(e,i=>t.id===i.id?0:t.created_at===i.created_at?-1:i.created_at-t.created_at);return r||e.splice(n,0,t),e}function tn(e,t){let n=0,r=e.length-1;for(;n<=r;){const i=Math.floor((n+r)/2),s=t(e[i]);if(s===0)return[i,!0];s<0?r=i-1:n=i+1}return[n,!1]}const li=Symbol.for("event-store"),fi=Symbol.for("event-uid"),Tc=Symbol.for("replaceable-address"),Oc=Symbol.for("from-cache"),Lc=Symbol.for("replaceable-identifier");function pe(e){return Xi(e)||Ji(e)}function Rc(e){let t=Reflect.get(e,fi);return t||(pe(e.kind)?t=Nc(e)??e.id:t=e.id,Reflect.set(e,fi,t)),t}function Nc(e){return pe(e.kind)?it(e,Tc,()=>dt(e.kind,e.pubkey,Ye(e))):null}function dt(e,t,n){return e+":"+t+":"+(n??"")}function Ye(e){return it(e,Lc,()=>{var t;return((t=e.tags.find(n=>n[0]==="d"))==null?void 0:t[1])??""})}const Or=Symbol.for("encrypted-content"),Es={[oa]:"nip04",[aa]:"nip44",[ca]:"nip44"};function Ss(e,t){return Es[e]=t,e}function Mc(e){return Es[e]!==void 0}function Pc(e){return Reflect.get(e,Or)}function nn(){return Math.round(Date.now()/1e3)}function wn(e,t){return e[0]!==void 0&&e[1]!==void 0&&(t?e[0]===t:!0)}function Uc(e){return wn(e,"e")}function As(e){return wn(e,"p")}function Is(e){return wn(e,"r")}function Hc(e){return wn(e,"a")}const $s=(e,...t)=>t.reduce((n,r)=>{const i=[];for(const s of n)try{const o=r(s);if(o===void 0)continue;i.push(o)}catch{}return i},e);function zt(e){let t=new URL(e);return t.pathname=t.pathname.replace(/\/+/g,"/"),(t.port==="80"&&(t.protocol==="ws:"||t.protocol==="http:")||t.port==="443"&&(t.protocol==="wss:"||t.protocol==="https:"))&&(t.port=""),typeof e=="string"?t.toString():t}const rr=Symbol.for("seen-relays");function di(e,t){let n=Reflect.get(e,rr);return n?(n.add(t),n):(n=new Set([t]),Reflect.set(e,rr,n),n)}function Dc(e){return Reflect.get(e,rr)}const jc=/^wss?:\/\/([-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}|localhost)\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)$/;function Kt(e){return e.length>=8&&jc.test(e)}function Lr(e){return!e||e.length!==64?!1:!!e.toLowerCase().match(/^[0-9a-f]{64}$/)}function Fc(e,t=!1){const n=e.split(":"),r=n[0]?parseInt(n[0]):void 0,i=n[1];if(r===void 0||i===void 0||i===""||!Lr(i))return null;const s=n.slice(2).join(":");return t&&s===""?null:{kind:r,pubkey:i,identifier:s}}function qc(e){const t=e[1];if(!t||!Lr(t))return null;const n={id:t};return e[2]&&Kt(e[2])&&(n.relays=[zt(e[2])]),n}function zc(e){if(!e[1])return null;const t=Fc(e[1]);return t?(e[2]&&Kt(e[2])&&(t.relays=[zt(e[2])]),t):null}function _s(e){const t=e[1];if(!t||!Lr(t))return null;const n={pubkey:t};return e[2]&&Kt(e[2])&&(n.relays=[zt(e[2])]),n}function Kc(e){return typeof e=="object"&&e!==null&&"identifier"in e&&"pubkey"in e&&"kind"in e&&typeof e.identifier=="string"&&typeof e.pubkey=="string"&&typeof e.kind=="number"}function _t(e){return typeof e=="object"&&e!==null&&"id"in e&&typeof e.id=="string"}function hi(e,t){return _t(t)?e.id===t.id&&(t.author?e.pubkey===t.author:!0):e.kind===t.kind&&e.pubkey===t.pubkey&&Ye(e)===(t.identifier??"")}const pi=Or,Bs=new Set([Ss(xa,"nip04")]);function ne(e,t){return Bs.add(Ss(e,t)),e}function Cs(e){return Mc(e)&&Bs.has(e)}function Vc(e){if(Cs(e.kind))return pi in e?Reflect.get(e,pi):Pc(e)}const Wc=10009,Hn=Symbol.for("hidden-tags"),Gc=new Set([ne(fa,"nip04"),ne(ya,"nip04"),ne(ua,"nip04"),ne(da,"nip04"),ne(ha,"nip04"),ne(pa,"nip04"),ne(Wc,"nip04"),ne(ga,"nip04"),ne(ba,"nip04"),ne(ma,"nip04"),ne(va,"nip04"),ne(wa,"nip04")]);function Zc(e){return Cs(e)&&Gc.has(e)}function Yc(e){if(!Zc(e.kind))return;if(Hn in e)return e[Hn];const t=Vc(e);if(t===void 0)return;const n=JSON.parse(t);if(!Array.isArray(n))throw new Error("Content is not an array of tags");const r=n.filter(i=>Array.isArray(i)).map(i=>i.map(s=>String(s)));return Reflect.set(e,Hn,r),r}const Xc=Symbol.for("public-contacts"),Dn=Symbol.for("hidden-contacts");function Jc(...e){const t=new Map;for(const n of e)if(Array.isArray(n))for(const r of n)r&&t.set(r.pubkey,r);else n&&t.set(n.pubkey,n);return Array.from(t.values())}function Qc(e){return Jc(eu(e),tu(e))}function eu(e){return it(e,Xc,()=>$s(e.tags,t=>As(t)?t:void 0,t=>_s(t)??void 0))}function tu(e){if(Dn in e)return e[Dn];const t=Yc(e);if(!t)return;const n=$s(t,r=>As(r)?r:void 0,r=>_s(r)??void 0);return Reflect.set(e,Dn,n),n}function nu(e){return e.tags.filter(Uc).map(qc).filter(t=>t!==null).map(t=>(t.author=e.pubkey,t))}function ru(e){return e.tags.filter(Hc).map(zc).filter(t=>t!==null).filter(t=>t.pubkey===e.pubkey)}var ir=function(e,t){return ir=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(n[i]=r[i])},ir(e,t)};function be(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");ir(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}function iu(e,t,n,r){function i(s){return s instanceof n?s:new n(function(o){o(s)})}return new(n||(n=Promise))(function(s,o){function a(d){try{u(r.next(d))}catch(l){o(l)}}function c(d){try{u(r.throw(d))}catch(l){o(l)}}function u(d){d.done?s(d.value):i(d.value).then(a,c)}u((r=r.apply(e,t||[])).next())})}function Ts(e,t){var n={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,i,s,o=Object.create((typeof Iterator=="function"?Iterator:Object).prototype);return o.next=a(0),o.throw=a(1),o.return=a(2),typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(u){return function(d){return c([u,d])}}function c(u){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(n=0)),n;)try{if(r=1,i&&(s=u[0]&2?i.return:u[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,u[1])).done)return s;switch(i=0,s&&(u=[u[0]&2,s.value]),u[0]){case 0:case 1:s=u;break;case 4:return n.label++,{value:u[1],done:!1};case 5:n.label++,i=u[1],u=[0];continue;case 7:u=n.ops.pop(),n.trys.pop();continue;default:if(s=n.trys,!(s=s.length>0&&s[s.length-1])&&(u[0]===6||u[0]===2)){n=0;continue}if(u[0]===3&&(!s||u[1]>s[0]&&u[1]<s[3])){n.label=u[1];break}if(u[0]===6&&n.label<s[1]){n.label=s[1],s=u;break}if(s&&n.label<s[2]){n.label=s[2],n.ops.push(u);break}s[2]&&n.ops.pop(),n.trys.pop();continue}u=t.call(e,n)}catch(d){u=[6,d],i=0}finally{r=s=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function bt(e){var t=typeof Symbol=="function"&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ue(e,t){var n=typeof Symbol=="function"&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),i,s=[],o;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return s}function He(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,s;r<i;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}function ht(e){return this instanceof ht?(this.v=e,this):new ht(e)}function su(e,t,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(e,t||[]),i,s=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",o),i[Symbol.asyncIterator]=function(){return this},i;function o(p){return function(g){return Promise.resolve(g).then(p,l)}}function a(p,g){r[p]&&(i[p]=function(h){return new Promise(function(m,v){s.push([p,h,m,v])>1||c(p,h)})},g&&(i[p]=g(i[p])))}function c(p,g){try{u(r[p](g))}catch(h){y(s[0][3],h)}}function u(p){p.value instanceof ht?Promise.resolve(p.value.v).then(d,l):y(s[0][2],p)}function d(p){c("next",p)}function l(p){c("throw",p)}function y(p,g){p(g),s.shift(),s.length&&c(s[0][0],s[0][1])}}function ou(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof bt=="function"?bt(e):e[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(s){n[s]=e[s]&&function(o){return new Promise(function(a,c){o=e[s](o),i(a,c,o.done,o.value)})}}function i(s,o,a,c){Promise.resolve(c).then(function(u){s({value:u,done:a})},o)}}function P(e){return typeof e=="function"}function Os(e){var t=function(r){Error.call(r),r.stack=new Error().stack},n=e(t);return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var jn=Os(function(e){return function(n){e(this),this.message=n?n.length+` errors occurred during unsubscription:
`+n.map(function(r,i){return i+1+") "+r.toString()}).join(`
  `):"",this.name="UnsubscriptionError",this.errors=n}});function fn(e,t){if(e){var n=e.indexOf(t);0<=n&&e.splice(n,1)}}var xt=(function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,n,r,i,s;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var a=bt(o),c=a.next();!c.done;c=a.next()){var u=c.value;u.remove(this)}}catch(h){t={error:h}}finally{try{c&&!c.done&&(n=a.return)&&n.call(a)}finally{if(t)throw t.error}}else o.remove(this);var d=this.initialTeardown;if(P(d))try{d()}catch(h){s=h instanceof jn?h.errors:[h]}var l=this._finalizers;if(l){this._finalizers=null;try{for(var y=bt(l),p=y.next();!p.done;p=y.next()){var g=p.value;try{yi(g)}catch(h){s=s??[],h instanceof jn?s=He(He([],Ue(s)),Ue(h.errors)):s.push(h)}}}catch(h){r={error:h}}finally{try{p&&!p.done&&(i=y.return)&&i.call(y)}finally{if(r)throw r.error}}}if(s)throw new jn(s)}},e.prototype.add=function(t){var n;if(t&&t!==this)if(this.closed)yi(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(n=this._finalizers)!==null&&n!==void 0?n:[]).push(t)}},e.prototype._hasParent=function(t){var n=this._parentage;return n===t||Array.isArray(n)&&n.includes(t)},e.prototype._addParent=function(t){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(t),n):n?[n,t]:t},e.prototype._removeParent=function(t){var n=this._parentage;n===t?this._parentage=null:Array.isArray(n)&&fn(n,t)},e.prototype.remove=function(t){var n=this._finalizers;n&&fn(n,t),t instanceof e&&t._removeParent(this)},e.EMPTY=(function(){var t=new e;return t.closed=!0,t})(),e})(),Ls=xt.EMPTY;function Rs(e){return e instanceof xt||e&&"closed"in e&&P(e.remove)&&P(e.add)&&P(e.unsubscribe)}function yi(e){P(e)?e():e.unsubscribe()}var au={Promise:void 0},cu={setTimeout:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setTimeout.apply(void 0,He([e,t],Ue(n)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function Ns(e){cu.setTimeout(function(){throw e})}function sr(){}function rn(e){e()}var Rr=(function(e){be(t,e);function t(n){var r=e.call(this)||this;return r.isStopped=!1,n?(r.destination=n,Rs(n)&&n.add(r)):r.destination=fu,r}return t.create=function(n,r,i){return new Pt(n,r,i)},t.prototype.next=function(n){this.isStopped||this._next(n)},t.prototype.error=function(n){this.isStopped||(this.isStopped=!0,this._error(n))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(n){this.destination.next(n)},t.prototype._error=function(n){try{this.destination.error(n)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t})(xt),uu=(function(){function e(t){this.partialObserver=t}return e.prototype.next=function(t){var n=this.partialObserver;if(n.next)try{n.next(t)}catch(r){Jt(r)}},e.prototype.error=function(t){var n=this.partialObserver;if(n.error)try{n.error(t)}catch(r){Jt(r)}else Jt(t)},e.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(n){Jt(n)}},e})(),Pt=(function(e){be(t,e);function t(n,r,i){var s=e.call(this)||this,o;return P(n)||!n?o={next:n??void 0,error:r??void 0,complete:i??void 0}:o=n,s.destination=new uu(o),s}return t})(Rr);function Jt(e){Ns(e)}function lu(e){throw e}var fu={closed:!0,next:sr,error:lu,complete:sr},Nr=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Se(e){return e}function du(e){return e.length===0?Se:e.length===1?e[0]:function(n){return e.reduce(function(r,i){return i(r)},n)}}var U=(function(){function e(t){t&&(this._subscribe=t)}return e.prototype.lift=function(t){var n=new e;return n.source=this,n.operator=t,n},e.prototype.subscribe=function(t,n,r){var i=this,s=pu(t)?t:new Pt(t,n,r);return rn(function(){var o=i,a=o.operator,c=o.source;s.add(a?a.call(s,c):c?i._subscribe(s):i._trySubscribe(s))}),s},e.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(n){t.error(n)}},e.prototype.forEach=function(t,n){var r=this;return n=mi(n),new n(function(i,s){var o=new Pt({next:function(a){try{t(a)}catch(c){s(c),o.unsubscribe()}},error:s,complete:i});r.subscribe(o)})},e.prototype._subscribe=function(t){var n;return(n=this.source)===null||n===void 0?void 0:n.subscribe(t)},e.prototype[Nr]=function(){return this},e.prototype.pipe=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return du(t)(this)},e.prototype.toPromise=function(t){var n=this;return t=mi(t),new t(function(r,i){var s;n.subscribe(function(o){return s=o},function(o){return i(o)},function(){return r(s)})})},e.create=function(t){return new e(t)},e})();function mi(e){var t;return(t=e??au.Promise)!==null&&t!==void 0?t:Promise}function hu(e){return e&&P(e.next)&&P(e.error)&&P(e.complete)}function pu(e){return e&&e instanceof Rr||hu(e)&&Rs(e)}function yu(e){return P(e==null?void 0:e.lift)}function V(e){return function(t){if(yu(t))return t.lift(function(n){try{return e(n,this)}catch(r){this.error(r)}});throw new TypeError("Unable to lift unknown Observable type")}}function W(e,t,n,r,i){return new mu(e,t,n,r,i)}var mu=(function(e){be(t,e);function t(n,r,i,s,o,a){var c=e.call(this,n)||this;return c.onFinalize=o,c.shouldUnsubscribe=a,c._next=r?function(u){try{r(u)}catch(d){n.error(d)}}:e.prototype._next,c._error=s?function(u){try{s(u)}catch(d){n.error(d)}finally{this.unsubscribe()}}:e.prototype._error,c._complete=i?function(){try{i()}catch(u){n.error(u)}finally{this.unsubscribe()}}:e.prototype._complete,c}return t.prototype.unsubscribe=function(){var n;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;e.prototype.unsubscribe.call(this),!r&&((n=this.onFinalize)===null||n===void 0||n.call(this))}},t})(Rr),bu=Os(function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),xe=(function(e){be(t,e);function t(){var n=e.call(this)||this;return n.closed=!1,n.currentObservers=null,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return t.prototype.lift=function(n){var r=new bi(this,this);return r.operator=n,r},t.prototype._throwIfClosed=function(){if(this.closed)throw new bu},t.prototype.next=function(n){var r=this;rn(function(){var i,s;if(r._throwIfClosed(),!r.isStopped){r.currentObservers||(r.currentObservers=Array.from(r.observers));try{for(var o=bt(r.currentObservers),a=o.next();!a.done;a=o.next()){var c=a.value;c.next(n)}}catch(u){i={error:u}}finally{try{a&&!a.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}}})},t.prototype.error=function(n){var r=this;rn(function(){if(r._throwIfClosed(),!r.isStopped){r.hasError=r.isStopped=!0,r.thrownError=n;for(var i=r.observers;i.length;)i.shift().error(n)}})},t.prototype.complete=function(){var n=this;rn(function(){if(n._throwIfClosed(),!n.isStopped){n.isStopped=!0;for(var r=n.observers;r.length;)r.shift().complete()}})},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var n;return((n=this.observers)===null||n===void 0?void 0:n.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(n){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,n)},t.prototype._subscribe=function(n){return this._throwIfClosed(),this._checkFinalizedStatuses(n),this._innerSubscribe(n)},t.prototype._innerSubscribe=function(n){var r=this,i=this,s=i.hasError,o=i.isStopped,a=i.observers;return s||o?Ls:(this.currentObservers=null,a.push(n),new xt(function(){r.currentObservers=null,fn(a,n)}))},t.prototype._checkFinalizedStatuses=function(n){var r=this,i=r.hasError,s=r.thrownError,o=r.isStopped;i?n.error(s):o&&n.complete()},t.prototype.asObservable=function(){var n=new U;return n.source=this,n},t.create=function(n,r){return new bi(n,r)},t})(U),bi=(function(e){be(t,e);function t(n,r){var i=e.call(this)||this;return i.destination=n,i.source=r,i}return t.prototype.next=function(n){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.next)===null||i===void 0||i.call(r,n)},t.prototype.error=function(n){var r,i;(i=(r=this.destination)===null||r===void 0?void 0:r.error)===null||i===void 0||i.call(r,n)},t.prototype.complete=function(){var n,r;(r=(n=this.destination)===null||n===void 0?void 0:n.complete)===null||r===void 0||r.call(n)},t.prototype._subscribe=function(n){var r,i;return(i=(r=this.source)===null||r===void 0?void 0:r.subscribe(n))!==null&&i!==void 0?i:Ls},t})(xe),Vt=(function(e){be(t,e);function t(n){var r=e.call(this)||this;return r._value=n,r}return Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),t.prototype._subscribe=function(n){var r=e.prototype._subscribe.call(this,n);return!r.closed&&n.next(this._value),r},t.prototype.getValue=function(){var n=this,r=n.hasError,i=n.thrownError,s=n._value;if(r)throw i;return this._throwIfClosed(),s},t.prototype.next=function(n){e.prototype.next.call(this,this._value=n)},t})(xe),Mr={now:function(){return(Mr.delegate||Date).now()},delegate:void 0},gi=(function(e){be(t,e);function t(n,r,i){n===void 0&&(n=1/0),r===void 0&&(r=1/0),i===void 0&&(i=Mr);var s=e.call(this)||this;return s._bufferSize=n,s._windowTime=r,s._timestampProvider=i,s._buffer=[],s._infiniteTimeWindow=!0,s._infiniteTimeWindow=r===1/0,s._bufferSize=Math.max(1,n),s._windowTime=Math.max(1,r),s}return t.prototype.next=function(n){var r=this,i=r.isStopped,s=r._buffer,o=r._infiniteTimeWindow,a=r._timestampProvider,c=r._windowTime;i||(s.push(n),!o&&s.push(a.now()+c)),this._trimBuffer(),e.prototype.next.call(this,n)},t.prototype._subscribe=function(n){this._throwIfClosed(),this._trimBuffer();for(var r=this._innerSubscribe(n),i=this,s=i._infiniteTimeWindow,o=i._buffer,a=o.slice(),c=0;c<a.length&&!n.closed;c+=s?1:2)n.next(a[c]);return this._checkFinalizedStatuses(n),r},t.prototype._trimBuffer=function(){var n=this,r=n._bufferSize,i=n._timestampProvider,s=n._buffer,o=n._infiniteTimeWindow,a=(o?1:2)*r;if(r<1/0&&a<s.length&&s.splice(0,s.length-a),!o){for(var c=i.now(),u=0,d=1;d<s.length&&s[d]<=c;d+=2)u=d;u&&s.splice(0,u+1)}},t})(xe),gu=(function(e){be(t,e);function t(n,r){return e.call(this)||this}return t.prototype.schedule=function(n,r){return this},t})(xt),vi={setInterval:function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return setInterval.apply(void 0,He([e,t],Ue(n)))},clearInterval:function(e){return clearInterval(e)},delegate:void 0},vu=(function(e){be(t,e);function t(n,r){var i=e.call(this,n,r)||this;return i.scheduler=n,i.work=r,i.pending=!1,i}return t.prototype.schedule=function(n,r){var i;if(r===void 0&&(r=0),this.closed)return this;this.state=n;var s=this.id,o=this.scheduler;return s!=null&&(this.id=this.recycleAsyncId(o,s,r)),this.pending=!0,this.delay=r,this.id=(i=this.id)!==null&&i!==void 0?i:this.requestAsyncId(o,this.id,r),this},t.prototype.requestAsyncId=function(n,r,i){return i===void 0&&(i=0),vi.setInterval(n.flush.bind(n,this),i)},t.prototype.recycleAsyncId=function(n,r,i){if(i===void 0&&(i=0),i!=null&&this.delay===i&&this.pending===!1)return r;r!=null&&vi.clearInterval(r)},t.prototype.execute=function(n,r){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var i=this._execute(n,r);if(i)return i;this.pending===!1&&this.id!=null&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},t.prototype._execute=function(n,r){var i=!1,s;try{this.work(n)}catch(o){i=!0,s=o||new Error("Scheduled action threw falsy error")}if(i)return this.unsubscribe(),s},t.prototype.unsubscribe=function(){if(!this.closed){var n=this,r=n.id,i=n.scheduler,s=i.actions;this.work=this.state=this.scheduler=null,this.pending=!1,fn(s,this),r!=null&&(this.id=this.recycleAsyncId(i,r,null)),this.delay=null,e.prototype.unsubscribe.call(this)}},t})(gu),wi=(function(){function e(t,n){n===void 0&&(n=e.now),this.schedulerActionCtor=t,this.now=n}return e.prototype.schedule=function(t,n,r){return n===void 0&&(n=0),new this.schedulerActionCtor(this,t).schedule(r,n)},e.now=Mr.now,e})(),wu=(function(e){be(t,e);function t(n,r){r===void 0&&(r=wi.now);var i=e.call(this,n,r)||this;return i.actions=[],i._active=!1,i}return t.prototype.flush=function(n){var r=this.actions;if(this._active){r.push(n);return}var i;this._active=!0;do if(i=n.execute(n.state,n.delay))break;while(n=r.shift());if(this._active=!1,i){for(;n=r.shift();)n.unsubscribe();throw i}},t})(wi),xu=new wu(vu),ku=xu,xn=new U(function(e){return e.complete()});function Eu(e){return e&&P(e.schedule)}function Pr(e){return e[e.length-1]}function Su(e){return P(Pr(e))?e.pop():void 0}function kt(e){return Eu(Pr(e))?e.pop():void 0}function Ms(e,t){return typeof Pr(e)=="number"?e.pop():t}var Ps=(function(e){return e&&typeof e.length=="number"&&typeof e!="function"});function Us(e){return P(e==null?void 0:e.then)}function Hs(e){return P(e[Nr])}function Ds(e){return Symbol.asyncIterator&&P(e==null?void 0:e[Symbol.asyncIterator])}function js(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Au(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Fs=Au();function qs(e){return P(e==null?void 0:e[Fs])}function zs(e){return su(this,arguments,function(){var n,r,i,s;return Ts(this,function(o){switch(o.label){case 0:n=e.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,ht(n.read())];case 3:return r=o.sent(),i=r.value,s=r.done,s?[4,ht(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,ht(i)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return n.releaseLock(),[7];case 10:return[2]}})})}function Ks(e){return P(e==null?void 0:e.getReader)}function oe(e){if(e instanceof U)return e;if(e!=null){if(Hs(e))return Iu(e);if(Ps(e))return $u(e);if(Us(e))return _u(e);if(Ds(e))return Vs(e);if(qs(e))return Bu(e);if(Ks(e))return Cu(e)}throw js(e)}function Iu(e){return new U(function(t){var n=e[Nr]();if(P(n.subscribe))return n.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function $u(e){return new U(function(t){for(var n=0;n<e.length&&!t.closed;n++)t.next(e[n]);t.complete()})}function _u(e){return new U(function(t){e.then(function(n){t.closed||(t.next(n),t.complete())},function(n){return t.error(n)}).then(null,Ns)})}function Bu(e){return new U(function(t){var n,r;try{for(var i=bt(e),s=i.next();!s.done;s=i.next()){var o=s.value;if(t.next(o),t.closed)return}}catch(a){n={error:a}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}t.complete()})}function Vs(e){return new U(function(t){Tu(e,t).catch(function(n){return t.error(n)})})}function Cu(e){return Vs(zs(e))}function Tu(e,t){var n,r,i,s;return iu(this,void 0,void 0,function(){var o,a;return Ts(this,function(c){switch(c.label){case 0:c.trys.push([0,5,6,11]),n=ou(e),c.label=1;case 1:return[4,n.next()];case 2:if(r=c.sent(),!!r.done)return[3,4];if(o=r.value,t.next(o),t.closed)return[2];c.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return a=c.sent(),i={error:a},[3,11];case 6:return c.trys.push([6,,9,10]),r&&!r.done&&(s=n.return)?[4,s.call(n)]:[3,8];case 7:c.sent(),c.label=8;case 8:return[3,10];case 9:if(i)throw i.error;return[7];case 10:return[7];case 11:return t.complete(),[2]}})})}function Me(e,t,n,r,i){r===void 0&&(r=0),i===void 0&&(i=!1);var s=t.schedule(function(){n(),i?e.add(this.schedule(null,r)):this.unsubscribe()},r);if(e.add(s),!i)return s}function Ws(e,t){return t===void 0&&(t=0),V(function(n,r){n.subscribe(W(r,function(i){return Me(r,e,function(){return r.next(i)},t)},function(){return Me(r,e,function(){return r.complete()},t)},function(i){return Me(r,e,function(){return r.error(i)},t)}))})}function Gs(e,t){return t===void 0&&(t=0),V(function(n,r){r.add(e.schedule(function(){return n.subscribe(r)},t))})}function Ou(e,t){return oe(e).pipe(Gs(t),Ws(t))}function Lu(e,t){return oe(e).pipe(Gs(t),Ws(t))}function Ru(e,t){return new U(function(n){var r=0;return t.schedule(function(){r===e.length?n.complete():(n.next(e[r++]),n.closed||this.schedule())})})}function Nu(e,t){return new U(function(n){var r;return Me(n,t,function(){r=e[Fs](),Me(n,t,function(){var i,s,o;try{i=r.next(),s=i.value,o=i.done}catch(a){n.error(a);return}o?n.complete():n.next(s)},0,!0)}),function(){return P(r==null?void 0:r.return)&&r.return()}})}function Zs(e,t){if(!e)throw new Error("Iterable cannot be null");return new U(function(n){Me(n,t,function(){var r=e[Symbol.asyncIterator]();Me(n,t,function(){r.next().then(function(i){i.done?n.complete():n.next(i.value)})},0,!0)})})}function Mu(e,t){return Zs(zs(e),t)}function Pu(e,t){if(e!=null){if(Hs(e))return Ou(e,t);if(Ps(e))return Ru(e,t);if(Us(e))return Lu(e,t);if(Ds(e))return Zs(e,t);if(qs(e))return Nu(e,t);if(Ks(e))return Mu(e,t)}throw js(e)}function Q(e,t){return t?Pu(e,t):oe(e)}function gt(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=kt(e);return Q(e,n)}function Uu(e){return e instanceof Date&&!isNaN(e)}function Ae(e,t){return V(function(n,r){var i=0;n.subscribe(W(r,function(s){r.next(e.call(t,s,i++))}))})}var Hu=Array.isArray;function Du(e,t){return Hu(t)?e.apply(void 0,He([],Ue(t))):e(t)}function ju(e){return Ae(function(t){return Du(e,t)})}var Fu=Array.isArray,qu=Object.getPrototypeOf,zu=Object.prototype,Ku=Object.keys;function Vu(e){if(e.length===1){var t=e[0];if(Fu(t))return{args:t,keys:null};if(Wu(t)){var n=Ku(t);return{args:n.map(function(r){return t[r]}),keys:n}}}return{args:e,keys:null}}function Wu(e){return e&&typeof e=="object"&&qu(e)===zu}function Gu(e,t){return e.reduce(function(n,r,i){return n[r]=t[i],n},{})}function sn(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=kt(e),r=Su(e),i=Vu(e),s=i.args,o=i.keys;if(s.length===0)return Q([],n);var a=new U(Zu(s,n,o?function(c){return Gu(o,c)}:Se));return r?a.pipe(ju(r)):a}function Zu(e,t,n){return n===void 0&&(n=Se),function(r){xi(t,function(){for(var i=e.length,s=new Array(i),o=i,a=i,c=function(d){xi(t,function(){var l=Q(e[d],t),y=!1;l.subscribe(W(r,function(p){s[d]=p,y||(y=!0,a--),a||r.next(n(s.slice()))},function(){--o||r.complete()}))},r)},u=0;u<i;u++)c(u)},r)}}function xi(e,t,n){e?Me(n,e,t):t()}function Yu(e,t,n,r,i,s,o,a){var c=[],u=0,d=0,l=!1,y=function(){l&&!c.length&&!u&&t.complete()},p=function(h){return u<r?g(h):c.push(h)},g=function(h){u++;var m=!1;oe(n(h,d++)).subscribe(W(t,function(v){t.next(v)},function(){m=!0},void 0,function(){if(m)try{u--;for(var v=function(){var k=c.shift();o||g(k)};c.length&&u<r;)v();y()}catch(k){t.error(k)}}))};return e.subscribe(W(t,p,function(){l=!0,y()})),function(){}}function Ur(e,t,n){return n===void 0&&(n=1/0),P(t)?Ur(function(r,i){return Ae(function(s,o){return t(r,s,i,o)})(oe(e(r,i)))},n):(typeof t=="number"&&(n=t),V(function(r,i){return Yu(r,i,e,n)}))}function Hr(e){return e===void 0&&(e=1/0),Ur(Se,e)}function Xu(){return Hr(1)}function ki(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Xu()(Q(e,kt(e)))}function et(e){return new U(function(t){oe(e()).subscribe(t)})}function Ut(e,t,n){return e===void 0&&(e=0),n===void 0&&(n=ku),new U(function(r){var i=Uu(e)?+e-n.now():e;i<0&&(i=0);var s=0;return n.schedule(function(){r.closed||(r.next(s++),r.complete())},i)})}function De(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=kt(e),r=Ms(e,1/0),i=e;return i.length?i.length===1?oe(i[0]):Hr(r)(Q(i,n)):xn}function ye(e,t){return V(function(n,r){var i=0;n.subscribe(W(r,function(s){return e.call(t,s,i++)&&r.next(s)}))})}function Ju(e,t,n,r,i){return function(s,o){var a=n,c=t,u=0;s.subscribe(W(o,function(d){var l=u++;c=a?e(c,d,l):(a=!0,d),o.next(c)},i))}}function Ys(e){return e<=0?function(){return xn}:V(function(t,n){var r=0;t.subscribe(W(n,function(i){++r<=e&&(n.next(i),e<=r&&n.complete())}))})}function Ht(e,t){return t===void 0&&(t=Se),e=e??Qu,V(function(n,r){var i,s=!0;n.subscribe(W(r,function(o){var a=t(o);(s||!e(i,a))&&(s=!1,i=a,r.next(o))}))})}function Qu(e,t){return e===t}function kn(e){return V(function(t,n){try{t.subscribe(n)}finally{n.add(e)}})}function el(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=kt(e),r=Ms(e,1/0);return V(function(i,s){Hr(r)(Q(He([i],Ue(e)),n)).subscribe(s)})}function or(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return el.apply(void 0,He([],Ue(e)))}function Xs(e){e===void 0&&(e=1/0);var t;e&&typeof e=="object"?t=e:t={count:e};var n=t.count,r=n===void 0?1/0:n,i=t.delay,s=t.resetOnSuccess,o=s===void 0?!1:s;return r<=0?Se:V(function(a,c){var u=0,d,l=function(){var y=!1;d=a.subscribe(W(c,function(p){o&&(u=0),c.next(p)},void 0,function(p){if(u++<r){var g=function(){d?(d.unsubscribe(),d=null,l()):y=!0};if(i!=null){var h=typeof i=="number"?Ut(i):oe(i(p,u)),m=W(c,function(){m.unsubscribe(),g()},function(){c.complete()});h.subscribe(m)}else g()}else c.error(p)})),y&&(d.unsubscribe(),d=null,l())};l()})}function tl(e,t){return V(Ju(e,t,arguments.length>=2,!0))}function Js(e){e===void 0&&(e={});var t=e.connector,n=t===void 0?function(){return new xe}:t,r=e.resetOnError,i=r===void 0?!0:r,s=e.resetOnComplete,o=s===void 0?!0:s,a=e.resetOnRefCountZero,c=a===void 0?!0:a;return function(u){var d,l,y,p=0,g=!1,h=!1,m=function(){l==null||l.unsubscribe(),l=void 0},v=function(){m(),d=y=void 0,g=h=!1},k=function(){var E=d;v(),E==null||E.unsubscribe()};return V(function(E,B){p++,!h&&!g&&m();var I=y=y??n();B.add(function(){p--,p===0&&!h&&!g&&(l=Fn(k,c))}),I.subscribe(B),!d&&p>0&&(d=new Pt({next:function(x){return I.next(x)},error:function(x){h=!0,m(),l=Fn(v,i,x),I.error(x)},complete:function(){g=!0,m(),l=Fn(v,o),I.complete()}}),oe(E).subscribe(d))})(u)}}function Fn(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(t===!0){e();return}if(t!==!1){var i=new Pt({next:function(){i.unsubscribe(),e()}});return oe(t.apply(void 0,He([],Ue(n)))).subscribe(i)}}function nl(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=kt(e);return V(function(r,i){(n?ki(e,r,n):ki(e,r)).subscribe(i)})}function dn(e,t){return V(function(n,r){var i=null,s=0,o=!1,a=function(){return o&&!i&&r.complete()};n.subscribe(W(r,function(c){i==null||i.unsubscribe();var u=0,d=s++;oe(e(c,d)).subscribe(i=W(r,function(l){return r.next(t?t(c,l,d,u++):l)},function(){i=null,a()}))},function(){o=!0,a()}))})}function rl(e){return V(function(t,n){oe(e).subscribe(W(n,function(){return n.complete()},sr)),!n.closed&&t.subscribe(n)})}function En(e,t,n){var r=P(e)||t||n?{next:e,error:t,complete:n}:e;return r?V(function(i,s){var o;(o=r.subscribe)===null||o===void 0||o.call(r);var a=!0;i.subscribe(W(s,function(c){var u;(u=r.next)===null||u===void 0||u.call(r,c),s.next(c)},function(){var c;a=!1,(c=r.complete)===null||c===void 0||c.call(r),s.complete()},function(c){var u;a=!1,(u=r.error)===null||u===void 0||u.call(r,c),s.error(c)},function(){var c,u;a&&((c=r.unsubscribe)===null||c===void 0||c.call(r)),(u=r.finalize)===null||u===void 0||u.call(r)}))}):Se}function Wt(e){const t=(()=>{});return t.enabled=!1,t.namespace=e,t.log=()=>{},t.extend=(n,r=":")=>Wt(`${e}${r}${n}`),t.destroy=()=>!0,t}Wt.enable=e=>{};Wt.disable=()=>"";Wt.enabled=e=>!1;const Qs=Wt("applesauce");Qs.extend("event-cache");const il=Symbol("expiration-timestamp");function ar(e){return it(e,il,()=>{var n;const t=(n=e.tags.find(r=>r[0]==="expiration"))==null?void 0:n[1];return t?parseInt(t):void 0})}function sl(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}const Ei="abcdefghijklmnopqrstuvwxyz",cr=new Set((Ei+Ei.toUpperCase()).split("")),Si=Symbol.for("indexable-tags");function Bt(e){let t=Reflect.get(e,Si);if(!t){const n=new Set;for(const r of e.tags)r.length>=2&&r[0].length===1&&cr.has(r[0])&&n.add(r[0]+":"+r[1]);t=n,Reflect.set(e,Si,n)}return t}function ol(e,t){if(e.ids&&e.ids.indexOf(t.id)===-1||e.kinds&&e.kinds.indexOf(t.kind)===-1||e.authors&&e.authors.indexOf(t.pubkey)===-1||e.since&&t.created_at<e.since||e.until&&t.created_at>e.until)return!1;for(let n in e)if(n[0]==="&"){let r=n.slice(1),i=e[n];if(i&&i.length>0){const s=Bt(t);for(const o of i)if(!s.has(r+":"+o))return!1}}for(let n in e)if(n[0]==="#"){let r=n.slice(1),i=e[n];if(i){const s=`&${r}`,o=e[s],a=o?i.filter(u=>!o.includes(u)):i;if(a.length===0)continue;const c=Bt(t);if(a.some(u=>c.has(r+":"+u))===!1)return!1}}return!0}function ur(e,t){for(let n=0;n<e.length;n++)if(ol(e[n],t))return!0;return!1}function al(e){try{return JSON.parse(e)}catch{return}}class Ai{constructor(t=0,n=0,r=!1){S(this,"first",null);S(this,"items",Object.create(null));S(this,"last",null);S(this,"max");S(this,"resetTtl");S(this,"size");S(this,"ttl");this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=r,this.size=0,this.ttl=n}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.has(t)){const n=this.items[t];delete this.items[t],this.size--,n.prev!==null&&(n.prev.next=n.next),n.next!==null&&(n.next.prev=n.prev),this.first===n&&(this.first=n.next),this.last===n&&(this.last=n.prev)}return this}entries(t=this.keys()){return t.map(n=>[n,this.get(n)])}evict(t=!1){if(t||this.size>0){const n=this.first;delete this.items[n.key],--this.size===0?(this.first=null,this.last=null):(this.first=n.next,this.first.prev=null)}return this}expiresAt(t){let n;return this.has(t)&&(n=this.items[t].expiry),n}get(t){let n;if(this.has(t)){const r=this.items[t];this.ttl>0&&r.expiry<=Date.now()?this.delete(t):(n=r.value,this.set(t,n,!0))}return n}has(t){return t in this.items}keys(){const t=[];let n=this.first;for(;n!==null;)t.push(n.key),n=n.next;return t}set(t,n,r=!1,i=this.resetTtl){let s;if(r||this.has(t)){if(s=this.items[t],s.value=n,r===!1&&i&&(s.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==s){const o=this.last,a=s.next,c=s.prev;this.first===s&&(this.first=s.next),s.next=null,s.prev=this.last,o.next=s,c!==null&&(c.next=a),a!==null&&(a.prev=c)}}else this.max>0&&this.size===this.max&&this.evict(!0),s=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:n},++this.size===1?this.first=s:this.last.next=s;return this.last=s,this}values(t=this.keys()){return t.map(n=>this.get(n))}}const cl=Symbol.for("mailboxes-inboxes"),ul=Symbol.for("mailboxes-outboxes");function ll(e){return it(e,cl,()=>{const t=[];for(const n of e.tags)if(Is(n))try{const[,r,i]=n;r&&Kt(r)&&!t.includes(r)&&(i==="read"||i===void 0)&&t.push(zt(r))}catch{}return t})}function fl(e){return it(e,ul,()=>{const t=[];for(const n of e.tags)if(Is(n))try{const[r,i,s]=n;r==="r"&&Kt(i)&&!t.includes(i)&&(s==="write"||s===void 0)&&t.push(zt(i))}catch{}return t})}const dl=Symbol.for("profile-content");function eo(e){return it(e,dl,()=>{var n,r;const t=al(e.content);if(t)return t.nip05&&typeof t.nip05!="string"&&(t.nip05=String(t.nip05)),t.website&&((n=t.website)==null?void 0:n.length)>0&&((r=t.website)==null?void 0:r.startsWith("http"))===!1&&(t.website="https://"+t.website),t})}function hl(e){return!(!e||e.kind!==Qi&&e.kind!==ka||!eo(e))}var qn,Ii;function pl(){if(Ii)return qn;Ii=1;function e(o,a){for(;o.length<a;)o="0"+o;return o}function t(o,a){var c,u,d;if(a.length===0)return o;for(c=0,d=a.length;c<d;c++)u=a.charCodeAt(c),o=(o<<5)-o+u,o|=0;return o<0?o*-2:o}function n(o,a,c){return Object.keys(a).sort().reduce(u,o);function u(d,l){return r(d,a[l],l,c)}}function r(o,a,c,u){var d=t(t(t(o,c),i(a)),typeof a);if(a===null)return t(d,"null");if(a===void 0)return t(d,"undefined");if(typeof a=="object"||typeof a=="function"){if(u.indexOf(a)!==-1)return t(d,"[Circular]"+c);u.push(a);var l=n(d,a,u);if(!("valueOf"in a)||typeof a.valueOf!="function")return l;try{return t(l,String(a.valueOf()))}catch(y){return t(l,"[valueOf exception]"+(y.stack||y.message))}}return t(d,a.toString())}function i(o){return Object.prototype.toString.call(o)}function s(o){return e(r(0,o,"",[]).toString(16),8)}return qn=s,qn}var yl=pl();const ml=sl(yl);class bl{constructor(){S(this,"deleted$");S(this,"deletedSubject",new xe);S(this,"deletedIds",new Map);S(this,"deletedIdentifiers",new Map);this.deleted$=this.deletedSubject.asObservable()}add(t){if(t.kind!==es)return[];const n=t.pubkey,r=[],i=nu(t);if(i.length>0){let o=this.deletedIds.get(n);o||(o=new Set,this.deletedIds.set(n,o));for(const a of i){o.add(a.id);const c={pointer:a,until:t.created_at};r.push(c),this.deletedSubject.next(c)}}const s=ru(t);if(s.length>0){let o=this.deletedIdentifiers.get(n);o||(o=new Map,this.deletedIdentifiers.set(n,o));for(const a of s){const c=a.kind+"|"+a.identifier;o.set(c,t.created_at);const u={pointer:a,until:t.created_at};r.push(u),this.deletedSubject.next(u)}}return r}check(t){const n=t.pubkey;if(Xi(t.kind)||Ji(t.kind)){const r=this.deletedIdentifiers.get(n);if(!r)return!1;const i=Ye(t),s=t.kind+"|"+i,o=r.get(s);return o===void 0?!1:o>=t.created_at}else{const r=this.deletedIds.get(n);return r?r.has(t.id):!1}}filter(t){return t.filter(n=>this.check(n)===!1)}}class $i{constructor(){S(this,"log",Qs.extend("EventMemory"));S(this,"kinds",new Map);S(this,"authors",new Map);S(this,"tags",new Ai);S(this,"created_at",[]);S(this,"kindAuthor",new Map);S(this,"events",new Ai);S(this,"replaceable",new Map);S(this,"claims",new WeakMap)}get size(){return this.events.size}hasEvent(t){return this.events.has(t)}getEvent(t){return this.events.get(t)}hasReplaceable(t,n,r){const i=this.replaceable.get(dt(t,n,r));return!!i&&i.length>0}getReplaceable(t,n,r){const i=dt(t,n,r),s=this.replaceable.get(i);return s==null?void 0:s[0]}getReplaceableHistory(t,n,r){const i=dt(t,n,r);return this.replaceable.get(i)}getByFilters(t){return Array.from(this.getEventsForFilters(Array.isArray(t)?t:[t]))}getTimeline(t){const n=[],r=this.getByFilters(t);for(const i of r)en(n,i);return n}add(t){var i;const n=t.id,r=this.events.get(n);if(r)return r;this.events.set(n,t),this.getKindIndex(t.kind).add(t),this.getAuthorsIndex(t.pubkey).add(t),this.getKindAuthorIndex(t.kind,t.pubkey).add(t);for(const s of Bt(t))this.tags.has(s)&&this.getTagIndex(s).add(t);if(en(this.created_at,t),pe(t.kind)){const s=(i=t.tags.find(c=>c[0]==="d"))==null?void 0:i[1],o=dt(t.kind,t.pubkey,s);let a=this.replaceable.get(o);this.replaceable.has(o)||(a=[],this.replaceable.set(o,a)),en(a,t)}return t}remove(t){var c;let n=typeof t=="string"?this.events.get(t):t;if(!n)return!1;const r=n.id;if(!this.events.has(r))return!1;const i=this.authors.get(n.pubkey);i&&(i.delete(n),i.size===0&&this.authors.delete(n.pubkey));const s=this.kinds.get(n.kind);s&&(s.delete(n),s.size===0&&this.kinds.delete(n.kind));const o=`${n.kind}:${n.pubkey}`,a=this.kindAuthor.get(o);a&&(a.delete(n),a.size===0&&this.kindAuthor.delete(o));for(const u of Bt(n))if(this.tags.has(u)){const d=this.getTagIndex(u);d.delete(n),d.size===0&&this.tags.delete(u)}if(this.removeFromSortedArray(this.created_at,n),this.events.delete(r),pe(n.kind)){const u=(c=n.tags.find(y=>y[0]==="d"))==null?void 0:c[1],d=dt(n.kind,n.pubkey,u),l=this.replaceable.get(d);l&&(this.removeFromSortedArray(l,n),l.length===0&&this.replaceable.delete(d))}return this.claims.delete(n),!0}removeByFilters(t){const n=this.getByFilters(t);let r=0;for(const i of n)this.remove(i)&&r++;return r}update(t){}touch(t){this.events.has(t.id)&&this.events.set(t.id,t)}claim(t){const n=this.claims.get(t)||0;this.claims.set(t,n+1),this.touch(t)}isClaimed(t){const n=this.claims.get(t);return n!==void 0&&n>0}removeClaim(t){const n=this.claims.get(t);if(n!==void 0&&n>0){const r=n-1;r===0?this.claims.delete(t):this.claims.set(t,r)}}clearClaim(t){this.claims.delete(t)}*unclaimed(){let t=0,n=this.events.first;for(;n;){const r=n.value;this.isClaimed(r)||(yield r),n=n.next}return t}prune(t){let n=0;const r=this.unclaimed();for(const i of r)if(this.remove(i),n++,t&&n>=t)break;return n}getKindIndex(t){return this.kinds.has(t)||this.kinds.set(t,new Set),this.kinds.get(t)}getAuthorsIndex(t){return this.authors.has(t)||this.authors.set(t,new Set),this.authors.get(t)}getKindAuthorIndex(t,n){const r=`${t}:${n}`;return this.kindAuthor.has(r)||this.kindAuthor.set(r,new Set),this.kindAuthor.get(r)}getTagIndex(t){if(!this.tags.has(t)){const n=new Set,r=Date.now();for(const s of this.events.values())Bt(s).has(t)&&n.add(s);const i=Date.now()-r;i>100&&this.log(`Built index ${t} took ${i}ms`),this.tags.set(t,n)}return this.tags.get(t)}removeFromSortedArray(t,n){if(t.length===0)return;const r=tn(t,s=>s.created_at-n.created_at);if(r){let s=r[0],o=!1;if(t[s]===n){t.splice(s,1);return}for(let a=s-1;a>=0&&t[a].created_at===n.created_at;a--)if(t[a]===n){t.splice(a,1),o=!0;break}if(o)return;for(let a=s+1;a<t.length&&t[a].created_at===n.created_at;a++)if(t[a]===n){t.splice(a,1);return}}const i=t.indexOf(n);i!==-1&&t.splice(i,1)}*iterateAuthors(t){for(const n of t){const r=this.authors.get(n);if(r)for(const i of r)yield i}}*iterateTag(t,n){for(const r of n){const i=this.getTagIndex(t+":"+r);if(i)for(const s of i)yield s}}*iterateKinds(t){for(const n of t){const r=this.kinds.get(n);if(r)for(const i of r)yield i}}*iterateTime(t,n){if(this.created_at.length===0)return;let r=0,i=this.created_at.length-1,s=n?tn(this.created_at,a=>a.created_at-n):void 0;s&&(r=Math.max(0,Math.min(s[0],this.created_at.length-1)));const o=t?tn(this.created_at,a=>a.created_at-t):void 0;if(o&&(i=Math.max(0,Math.min(o[0],this.created_at.length-1))),!(r>i))for(let a=r;a<=i;a++){const c=this.created_at[a];if(!(n!==void 0&&c.created_at>n)){if(t!==void 0&&c.created_at<t)break;yield c}}}*iterateIds(t){for(const n of t)this.events.has(n)&&(yield this.events.get(n))}getEventsForFilter(t){if(t.search)return new Set;let n=!0,r=new Set;const i=o=>{const a=o instanceof Set?o:new Set(o);if(n)r=a,n=!1;else for(const c of r)a.has(c)||r.delete(c);return r};t.ids&&i(this.iterateIds(t.ids));let s=null;t.since!==void 0&&(s=Array.from(this.iterateTime(t.since,t.until)),i(s));for(const o of cr){const a=`&${o}`,c=t[a];if(c!=null&&c.length)for(const u of c)i(this.iterateTag(o,[u]))}for(const o of cr){const a=`#${o}`,c=t[a];if(c!=null&&c.length){const u=`&${o}`,d=t[u],l=d?c.filter(y=>!d.includes(y)):c;l.length>0&&i(this.iterateTag(o,l))}}if(t.authors&&t.kinds&&t.authors.length*t.kinds.length<=20){const o=new Set;for(const a of t.kinds)for(const c of t.authors){const u=`${a}:${c}`,d=this.kindAuthor.get(u);if(d)for(const l of d)o.add(l)}i(o)}else t.authors&&i(this.iterateAuthors(t.authors)),t.kinds&&i(this.iterateKinds(t.kinds));if(t.since===void 0&&t.until!==void 0&&(s=Array.from(this.iterateTime(t.since,t.until)),i(s)),n)return new Set(this.events.values());if(t.limit&&s){const o=new Set;for(const a of s){if(o.size>=t.limit)break;r.has(a)&&o.add(a)}return o}return r}getEventsForFilters(t){if(t.length===0)return new Set;let n=new Set;for(const r of t){const i=this.getEventsForFilter(r);for(const s of i)n.add(s)}return n}reset(){this.events.clear(),this.kinds.clear(),this.authors.clear(),this.kindAuthor.clear(),this.tags.clear(),this.created_at=[],this.replaceable.clear(),this.claims=new WeakMap}}function _i(e){return t=>{const n=new Set;return t.pipe(En(r=>{if(r!==void 0)if(Array.isArray(r))for(const i of r)n.has(i)||(n.add(i),e.claim(i));else n.has(r)||(n.add(r),e.claim(r))}),kn(()=>{for(const r of n)e.removeClaim(r)}))}}function to(e){return t=>{let n;return t.pipe(En(r=>{n!==r&&(n&&e.removeClaim(n),r&&e.claim(r),n=r)}),kn(()=>{n&&e.removeClaim(n)}))}}function gl(e,t){const n=e.getEvent(t.id);return n instanceof Promise?Q(n):gt(n)}function vl(e,t){const n=e.getReplaceable(t.kind,t.pubkey,t.identifier);return n instanceof Promise?Q(n):gt(n)}function wl(e,t){const n=e.getByFilters(t);return n instanceof Promise?Q(n).pipe(Ur(r=>Q(r))):Q(n)}function no(e,t){return dn(n=>n||!e.eventLoader?gt(n):Q(e.eventLoader(t)).pipe(nl(void 0)))}function xl(e){return typeof e=="string"&&(e={id:e}),t=>De(et(()=>gl(t,e)).pipe(t.eventLoader?no(t,e):Se),t.insert$.pipe(ye(n=>n.id===e.id)),t.remove$.pipe(ye(n=>n.id===e.id),Ys(1),Ae(()=>{}))).pipe(Ht((n,r)=>(n==null?void 0:n.id)===(r==null?void 0:r.id)),to(t))}function kl(e){return t=>{let n;return De(et(()=>vl(t,e)).pipe(t.eventLoader?no(t,e):Se),t.insert$.pipe(ye(r=>r.pubkey==e.pubkey&&r.kind===e.kind&&(e.identifier!==void 0?Ye(r)===e.identifier:!0)))).pipe(En(r=>n=r),or(t.remove$.pipe(ye(r=>r.id===(n==null?void 0:n.id)),Ae(()=>{}))),Ht((r,i)=>r===void 0||i===void 0?r===i:i.created_at<r.created_at),to(t))}}function El(e,t){return e=Array.isArray(e)?e:[e],n=>{const r=new Map,i=s=>t?s.id:Rc(s);return et(()=>{const s=n.getTimeline(e);return s instanceof Promise?Q(s):gt(s)}).pipe(_i(n),or(n.insert$.pipe(ye(s=>ur(e,s)),_i(n))),or(n.remove$.pipe(ye(s=>ur(e,s)),Ae(s=>s.id))),tl((s,o)=>{var d;if(typeof o=="string"){const l=s.find(y=>y.id===o);if(l){const y=i(l);((d=r.get(y))==null?void 0:d.id)===o&&r.delete(y)}return s.filter(y=>y.id!==o)}if(Array.isArray(o)){r.clear();for(const l of o)r.set(i(l),l);return[...o]}let a=[...s];const c=i(o),u=r.get(c);if(u&&(!pe(o.kind)||!t&&o.created_at<u.created_at))return[...s];if(!t&&pe(o.kind)){if(r.set(c,o),u){const l=a.indexOf(u);l!==-1&&a.splice(l,1)}}else r.set(c,o);return en(a,o),a},[]),Ht(),kn(()=>r.clear()))}}function Sl(e,t=!1){return e=Array.isArray(e)?e:[e],n=>{const r=t?xn:et(()=>wl(n,e)),i=n.insert$.pipe(ye(s=>ur(e,s)));return De(r,i)}}function Al(e){return t=>{let n;return De(t.pipe(En(r=>n=r)),e.update$.pipe(ye(r=>r.id===(n==null?void 0:n.id))))}}function Il(e){return typeof e=="string"&&(e={pubkey:e}),t=>t.replaceable({kind:sa,pubkey:e.pubkey,relays:e.relays}).pipe(Al(t),Ae(n=>n?Qc(n):[]))}function $l(e){return typeof e=="string"&&(e={pubkey:e}),t=>t.replaceable({kind:la,pubkey:e.pubkey,relays:e.relays}).pipe(Ae(n=>n&&{inboxes:ll(n),outboxes:fl(n)}))}function _l(e){return typeof e=="string"&&(e={pubkey:e}),t=>t.replaceable({kind:Qi,pubkey:e.pubkey,relays:e.relays}).pipe(ye(hl),Ae(n=>n&&eo(n)))}class Bl{constructor(){S(this,"models",new Map);S(this,"modelKeepWarm",6e4);S(this,"destroy$",new gi(1))}model(t,...n){let r=this.models.get(t);r||(r=new Map,this.models.set(t,r));const i=t.getKey?t.getKey(...n):ml(n);let s=r.get(i);if(!s){const o=()=>{r.get(i)===s&&r.delete(i)};s=t(...n)(this).pipe(kn(o),Js({connector:()=>new gi(1),resetOnComplete:()=>De(Ut(this.modelKeepWarm),this.destroy$),resetOnRefCountZero:()=>De(Ut(this.modelKeepWarm),this.destroy$)}),rl(this.destroy$)),r.set(i,s)}return s}filters(t,n=!1){return Array.isArray(t)||(t=[t]),this.model(Sl,t,n)}event(t){return typeof t=="string"||_t(t)?this.model(xl,t):this.replaceable(t)}replaceable(...t){let n;if(t.length===1)n=t[0];else if(t.length===3||t.length===2){let[r,i,s]=t;n={kind:r,pubkey:i,identifier:s}}if(!n)throw new Error("Invalid arguments, expected address pointer or kind, pubkey, identifier");return this.model(kl,n)}addressable(t){return this.replaceable(t)}timeline(t,n=!1){return this.model(El,t,n)}profile(t){return this.model(_l,t)}contacts(t){return typeof t=="string"&&(t={pubkey:t}),this.model(Il,t)}mailboxes(t){return typeof t=="string"&&(t={pubkey:t}),this.model($l,t)}dispose(){this.destroy$.next(),this.destroy$.complete()}}class Cl{constructor(){S(this,"expired$");S(this,"expiredSubject");S(this,"expirations",new Map);S(this,"timer",null);S(this,"nextCheck",null);this.expiredSubject=new xe,this.expired$=this.expiredSubject.asObservable()}track(t){const n=ar(t);if(!n||!Number.isFinite(n))return;const r=nn();if(n<=r||(this.expirations.set(t.id,n),this.timer&&this.nextCheck&&this.nextCheck<=n))return;this.timer&&clearTimeout(this.timer);const i=n-r;i>0&&(this.timer=setTimeout(this.emitNotifications.bind(this),i*1e3+10),this.nextCheck=n)}forget(t){this.expirations.delete(t)}check(t){const n=ar(t);return n?n<=nn():!1}dispose(){this.timer&&clearTimeout(this.timer),this.timer=null,this.nextCheck=null,this.expirations.clear(),this.expiredSubject.complete()}[Symbol.dispose](){this.dispose()}emitNotifications(){const t=nn();let n=1/0;for(const[r,i]of this.expirations)i<=t?(this.expirations.delete(r),this.expiredSubject.next(r)):i<n&&(n=i);if(n!==1/0){this.timer&&clearTimeout(this.timer),this.nextCheck=null,this.timer=null;const r=n-t;r>0&&(this.timer=setTimeout(this.emitNotifications.bind(this),r*1e3+10),this.nextCheck=n)}}}class Ct extends Bl{constructor(n){super();S(this,"database");S(this,"memory");S(this,"deletes");S(this,"expiration");S(this,"keepOldVersions",!1);S(this,"keepExpired",!1);S(this,"keepDeleted",!1);S(this,"_verifyEventMethod",Cc);S(this,"insert$",new xe);S(this,"update$",new xe);S(this,"remove$",new xe);S(this,"eventLoader");S(this,"internalSubscriptions",new xt);n!=null&&n.database?(this.database=n.database,this.memory=new $i):this.database=this.memory=new $i,(n==null?void 0:n.keepDeleted)!==void 0&&(this.keepDeleted=n.keepDeleted),(n==null?void 0:n.keepExpired)!==void 0&&(this.keepExpired=n.keepExpired),(n==null?void 0:n.keepOldVersions)!==void 0&&(this.keepOldVersions=n.keepOldVersions),n!=null&&n.verifyEvent&&(this.verifyEvent=n.verifyEvent),this.deletes=(n==null?void 0:n.deleteManager)??new bl,this.internalSubscriptions.add(this.deletes.deleted$.subscribe(this.handleDeleteNotification.bind(this))),this.expiration=(n==null?void 0:n.expirationManager)??new Cl,this.internalSubscriptions.add(this.expiration.expired$.subscribe(this.handleExpiredNotification.bind(this)))}get verifyEvent(){return this._verifyEventMethod}set verifyEvent(n){this._verifyEventMethod=n,n===void 0&&console.warn("[applesauce-core] EventStore.verifyEvent is undefined; signature checks are disabled.")}mapToMemory(n){if(n!==void 0)return this.memory?this.memory.add(n):n}handleDeleteNotification({pointer:n,until:r}){if(!this.keepDeleted){if(_t(n)){const i=this.getEvent(n.id);i&&r>=i.created_at&&hi(i,n)&&this.remove(i)}else if(Kc(n)){const i=this.getReplaceableHistory(n.kind,n.pubkey,n.identifier);if(i)for(const s of i)r>=s.created_at&&hi(s,n)&&this.remove(s)}}}handleExpiredNotification(n){this.keepExpired||this.remove(n)}static copySymbolsToDuplicateEvent(n,r){if(n.kind!==r.kind)throw new Error("Source and destination events must have the same kind");if(ia(n.kind)&&n.id!==r.id)throw new Error("Source and destination events must have the same ID");if(pe(n.kind)&&n.pubkey!==r.pubkey&&Ye(n)!==Ye(r))throw new Error("Source and destination events must have the same pubkey and replaceable identifier");let i=!1;const s=Dc(n);if(s){for(const a of s)di(r,a);i=!0}const o=[Oc,Ve,Or];for(const a of o)a in n&&!(a in r)&&(Reflect.set(r,a,Reflect.get(n,a)),i=!0);return i}add(n,r){if(n.kind===es)return this.deletes.add(n),n;if(this.deletes.check(n))return n;const i=ar(n);if(this.keepExpired===!1&&i&&i<=nn())return null;r&&di(n,r);const s=pe(n.kind)?Ye(n):void 0;if(this.keepOldVersions===!1&&pe(n.kind)){const c=this.database.getReplaceableHistory(n.kind,n.pubkey,s);if(c&&c.length>0){let u=c[0];for(const l of c)(l.created_at>u.created_at||l.created_at===u.created_at&&l.id<u.id)&&(u=l);if(!(n.created_at>u.created_at||n.created_at===u.created_at&&n.id<u.id))return Ct.copySymbolsToDuplicateEvent(n,u)&&this.update(u),u}}if(this.verifyEvent&&this.verifyEvent(n)===!1)return null;const o=this.memory.add(n);if(o&&o!==n)return Ct.copySymbolsToDuplicateEvent(n,o)&&this.update(o),o;const a=this.mapToMemory(this.database.add(n));if(a===n?(Reflect.set(a,li,this),this.insert$.next(a)):Ct.copySymbolsToDuplicateEvent(n,a)&&this.update(a),this.keepOldVersions===!1&&pe(n.kind)){const c=this.database.getReplaceableHistory(n.kind,n.pubkey,s);if(c&&c.length>0){let u=c[0];for(const l of c)(l.created_at>u.created_at||l.created_at===u.created_at&&l.id<u.id)&&(u=l);const d=c.filter(l=>l!==u);for(const l of d)this.remove(l);if(d.length>0)return u}}return this.keepExpired===!1&&i!==void 0&&this.expiration.track(a),a}remove(n){const r=typeof n=="string"?n:n.id;let i=this.memory.getEvent(r);this.expiration.forget(r),i&&Reflect.deleteProperty(i,li),this.memory!==this.database&&this.memory.remove(n);const s=this.database.remove(n);return s&&i&&this.remove$.next(i),s}removeByFilters(n){const r=this.getByFilters(n);for(const s of r)this.expiration.forget(s.id);this.memory!==this.database&&this.memory.removeByFilters(n);const i=this.database.removeByFilters(n);for(const s of r)this.remove$.next(s);return i}update(n){var i,s;return this.database.add(n)?((s=(i=this.database).update)==null||s.call(i,n),this.update$.next(n),!0):!1}hasEvent(n){return typeof n=="string"?this.memory.hasEvent(n)||this.database.hasEvent(n):_t(n)?this.memory.hasEvent(n.id)||this.database.hasEvent(n.id):this.hasReplaceable(n.kind,n.pubkey,n.identifier)}getEvent(n){return typeof n=="string"?this.memory.getEvent(n)??this.mapToMemory(this.database.getEvent(n)):_t(n)?this.memory.getEvent(n.id)??this.mapToMemory(this.database.getEvent(n.id)):this.getReplaceable(n.kind,n.pubkey,n.identifier)}hasReplaceable(n,r,i){return this.memory.hasReplaceable(n,r,i)||this.database.hasReplaceable(n,r,i)}getReplaceable(n,r,i){return this.memory.getReplaceable(n,r,i)??this.mapToMemory(this.database.getReplaceable(n,r,i))}getReplaceableHistory(n,r,i){var s;return this.memory.getReplaceableHistory(n,r,i)??((s=this.database.getReplaceableHistory(n,r,i))==null?void 0:s.map(o=>this.mapToMemory(o)??o))}getByFilters(n){const r=this.database.getByFilters(n);return this.memory?r.map(i=>this.mapToMemory(i)):r}getTimeline(n){const r=this.database.getTimeline(n);return this.memory?r.map(i=>this.mapToMemory(i)):r}touch(n){return this.memory.touch(n)}claim(n){return this.memory.claim(n)}isClaimed(n){return this.memory.isClaimed(n)??!1}removeClaim(n){return this.memory.removeClaim(n)}clearClaim(n){return this.memory.clearClaim(n)}unclaimed(){return this.memory.unclaimed()||(function*(){})()}prune(n){return this.memory.prune(n)??0}dispose(){var r,i;const n=this.eventLoader;n&&typeof n[Symbol.dispose]=="function"&&n[Symbol.dispose](),this.eventLoader=void 0,super.dispose(),this.internalSubscriptions.unsubscribe(),(i=(r=this.expiration).dispose)==null||i.call(r),this.insert$.complete(),this.update$.complete(),this.remove$.complete()}[Symbol.dispose](){this.dispose()}}const ro=35129,io=15129,ke=[ro,io],lr=/^[0-9a-f]{64}$/,Tl=/(^|\/)(icon|favicon|logo|apple-touch-icon)[^/]*\.(png|svg|webp|jpe?g|ico|gif)$/i,Ol=/(^|\/)screenshots?\/[^/]+\.(png|webp|jpe?g|gif)$/i;function We(e,t){return e.tags.filter(n=>n[0]===t&&typeof n[1]=="string").map(n=>n[1])}function It(e,t){return We(e,t).find(n=>n.trim()!=="")}function zn(e){const t=e.trim();if(lr.test(t))return`blossom:sha256:${t}`;if(/^(blossom|https?|data|nostr):/i.test(t))return t}function Ll(e){const t=e.replace(/[-_.]+/g," ").trim();return t?t.charAt(0).toUpperCase()+t.slice(1):"Untitled napplet"}function Rl(e){return e.replace(/\s+/g," ").trim().slice(0,300)}function Nl(e,t,n=[]){var d;if(!ke.includes(e.kind)||!lr.test(e.pubkey))return;const r=e.kind===io?"":It(e,"d")??"";if(e.kind===ro&&!r)return;const i=e.tags.filter(l=>l[0]==="path"&&typeof l[1]=="string"&&lr.test(l[2]??"")).map(l=>({path:l[1],sha256:l[2]}));if(i.length===0)return;const s=(It(e,"description")??e.content??"").trim(),o=(It(e,"summary")??"").trim()||Rl(s),a=[...We(e,"icon").map(zn),...i.filter(l=>Tl.test(l.path)).map(l=>`blossom:sha256:${l.sha256}`)].filter(l=>!!l),c=[...We(e,"image").map(zn),...We(e,"screenshot").map(zn),...i.filter(l=>Ol.test(l.path)).map(l=>`blossom:sha256:${l.sha256}`)].filter(l=>!!l),u=(d=e.tags.find(l=>l[0]==="x"&&l[2]==="aggregate"))==null?void 0:d[1];return{key:`${e.kind}:${e.pubkey}:${r}`,kind:e.kind,pubkey:e.pubkey,d:r,title:(It(e,"title")??It(e,"name")??"").trim()||Ll(r),summary:o,description:s,createdAt:e.created_at,requires:[...new Set(We(e,"requires"))],archetypes:[...new Set(We(e,"archetype"))],paths:i,servers:[...new Set(We(e,"server"))],aggregate:u,icons:[...new Set(a)],screenshots:[...new Set(c)],relayHints:[...new Set(n)],origins:new Set([t]),event:e}}const Ml="qpzry9x8gf2tvdw0s3jn54khce6mua7l",Pl=[996825010,642813549,513874426,1027748829,705979059];function Ul(e){let t=1;for(const n of e){const r=t>>>25;t=(t&33554431)<<5^n;for(let i=0;i<5;i++)r>>>i&1&&(t^=Pl[i])}return t}function Hl(e){const t=[];for(const n of e)t.push(n.charCodeAt(0)>>>5);t.push(0);for(const n of e)t.push(n.charCodeAt(0)&31);return t}function Dl(e){let t=0,n=0;const r=[];for(const i of e)for(t=t<<8|i,n+=8;n>=5;)n-=5,r.push(t>>>n&31);return n>0&&r.push(t<<5-n&31),r}function so(e,t){const n=Dl(t),r=Ul([...Hl(e),...n,0,0,0,0,0,0])^1,i=Array.from({length:6},(s,o)=>r>>>5*(5-o)&31);return e+"1"+[...n,...i].map(s=>Ml[s]).join("")}function oo(e){const t=new Uint8Array(e.length/2);for(let n=0;n<t.length;n++)t[n]=parseInt(e.slice(n*2,n*2+2),16);return t}function ao(e){return so("npub",oo(e))}function co(e){const t=ao(e);return`${t.slice(0,10)}…${t.slice(-4)}`}function jl(e){const t=new TextEncoder,n=[],r=(s,o)=>{n.push(s,o.length,...o)};r(0,t.encode(e.d));for(const s of e.relayHints.filter(o=>/^wss?:\/\//.test(o)).slice(0,2)){const o=t.encode(s);o.length<256&&r(1,o)}r(2,oo(e.pubkey));const i=new Uint8Array(4);return new DataView(i.buffer).setUint32(0,e.kind),r(3,i),so("naddr",Uint8Array.from(n))}function Fl(e){if(e.kind===0)try{const t=JSON.parse(e.content),n=r=>typeof t[r]=="string"&&t[r].trim()||void 0;return{name:n("display_name")??n("displayName")??n("name"),picture:n("picture"),nip05:n("nip05")}}catch{return}}function uo(e,t=Date.now()/1e3){const n=Math.max(0,Math.round(t-e));if(n<60)return"just now";const r=[[3600*24*365,"y"],[3600*24*30,"mo"],[3600*24*7,"w"],[3600*24,"d"],[3600,"h"],[60,"m"]];for(const[i,s]of r)if(n>=i)return`${Math.floor(n/i)}${s} ago`;return"just now"}function ql(e){return new Date(e*1e3).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}function lo(){const e=globalThis.napplet,t=e==null?void 0:e.mesh;if(t&&typeof t.publish=="function"&&typeof t.subscribe=="function"&&typeof t.info=="function")return t}const fo=5e3;class ho extends Error{constructor(t,n){super(n||`${t} subscription closed`),this.source=t}}function po(e){return/not granted|permission|denied|not allowed/i.test(e??"")}const yo=10;function zl(e,t,n){return new U(r=>{const i=Jo(e,{...t!=null&&t.length?{authors:t}:{},...n!=null&&n.length?{relays:n.slice(0,yo)}:{}});let s=!0;return i.on("event",o=>r.next(o)),i.on("closed",o=>{s&&r.error(new ho("outbox",o??""))}),()=>{s=!1,i.close()}})}function Kl(e){return new U(t=>{const n=jo(e,r=>t.next(r),()=>{});return()=>n.close()})}function vt(e,t={}){const n=[],r=(s,o)=>s.pipe(Xs({delay:a=>{var u;const c=a instanceof Error?a.message:String(a);return(u=t.onNotice)==null||u.call(t,{source:o,reason:c,denied:po(c)}),Ut(fo)}})),i=ie("outbox","subscribe");return i&&n.push(r(et(()=>zl(e,t.authors,t.relays)),"outbox")),ie("relay","subscribe")&&(t.catalogue||!i)&&n.push(r(et(()=>Kl(e)),"relay")),n.length===0?new U(()=>{var s;(s=t.onNotice)==null||s.call(t,{source:"relay",reason:"This app runtime offers no way to read relays.",denied:!1})}):De(...n)}function mo(e,t,n=200){const r=[];for(let i=0;i<t.length;i+=n)r.push({...e,authors:t.slice(i,i+n)});return r}function Vl(e,t){const n=lo();if(!n)return new U(()=>t({type:"unsupported"}));const r=new U(i=>{const s=n.subscribe(e);let o=!0;return s.on("event",a=>i.next(a)),s.on("eose",()=>t({type:"open"})),s.on("closed",a=>{o&&(po(a)?(t({type:"denied",reason:a??""}),i.complete()):i.error(new ho("mesh",a??"")))}),()=>{o=!1,s.close()}});return et(()=>r).pipe(Xs({delay:i=>(t({type:"closed",reason:i instanceof Error?i.message:String(i)}),Ut(fo))}))}function Wl(e=1e4){return new U(t=>{const n=lo();if(!n)return;const r=()=>n.info().then(s=>t.next(s)).catch(()=>{});r();const i=window.setInterval(r,e);return()=>window.clearInterval(i)}).pipe(Js())}const Bi=200,Dt=/^[0-9a-f]{64}$/,pt=new Ct,fr=new Set;let Kn=!1;function ve(){if(Kn)return;Kn=!0;const e=()=>{Kn=!1,fr.forEach(t=>t())};typeof requestAnimationFrame=="function"?requestAnimationFrame(e):setTimeout(e,16)}function Gl(e){return fr.add(e),()=>fr.delete(e)}const dr=new Map,hr=new Map,pr=new Vt(0);function bo(e){var n;if(!ke.includes(e.kind))return;const t=e.kind===ke[1]?"":((n=e.tags.find(r=>r[0]==="d"))==null?void 0:n[1])??"";return`${e.kind}:${e.pubkey}:${t}`}function Sn(e,t="feed"){var c;const n=e.event;if(!n||!Dt.test(n.pubkey))return;pt.add(n);const r=bo(n);if(!r)return;let i=dr.get(r);i||dr.set(r,i=new Set);const s=i.size;i.add(t);let o=hr.get(r);o||hr.set(r,o=new Set);const a=o.size;for(const u of((c=e.sidecar)==null?void 0:c.relayHints)??[])o.add(u);(i.size!==s||o.size!==a)&&pr.next(pr.value+1)}function Ci(e,t="feed"){return e.subscribe(n=>Sn(n,t))}const le=new Map,yr=new Map,mr=new Set;function Zl(e){return mr.add(e),()=>mr.delete(e)}function go(e){return yr.get(e)}const we=new Vt(void 0),$t=new Vt(new Set),on=new Vt(!1);class Dr{constructor(t,n="feed",r=1500,i=3){S(this,"covered",new Set);S(this,"queued",new Set);S(this,"timer");S(this,"batches",[]);this.open=t,this.origin=n,this.batchMs=r,this.maxBatches=i}has(t){return this.covered.has(t)||this.queued.has(t)}add(t){let n=!1;for(const r of t)this.has(r)||(this.queued.add(r),n=!0);n&&this.timer===void 0&&(this.timer=setTimeout(()=>this.flush(),this.batchMs))}flush(){this.timer=void 0;const t=[...this.queued].filter(n=>!this.covered.has(n));if(this.queued.clear(),t.length!==0){for(const n of t)this.covered.add(n);if(this.batches.length>=this.maxBatches){const n=[...this.covered],r=this.subscribe(n),i=this.batches;this.batches=[{keys:n,sub:r}],i.forEach(s=>s.sub.unsubscribe())}else this.batches.push({keys:t,sub:this.subscribe(t)})}}subscribe(t){return this.open(t).subscribe(n=>Sn(n,this.origin))}close(){this.timer!==void 0&&clearTimeout(this.timer),this.timer=void 0,this.batches.splice(0).forEach(t=>t.sub.unsubscribe()),this.covered.clear(),this.queued.clear()}}const jr=new Dr(e=>{const t=we.value;return vt([...mo({kinds:[0,30267]},e),...t&&e.includes(t)?[{kinds:[3],authors:[t]}]:[]],{authors:e})}),vo=new Dr(e=>vt(mo({kinds:[0]},e),{authors:e}));function wo(e){jr.add([...e].filter(t=>Dt.test(t)))}function An(e){vo.add([...e].filter(t=>Dt.test(t)&&!jr.has(t)))}const br=new Vt(void 0);function Fr(e){e&&An([e]),br.value!==e&&br.next(e)}function Yl(e){return e?[...new Set(e.tags.filter(t=>t[0]==="r"&&typeof t[1]=="string"&&/^wss?:\/\//.test(t[1])&&t[2]!=="read").map(t=>t[1].trim()))].slice(0,yo):[]}function Xl(e){const t=[{kinds:ke,authors:[e],limit:200},{kinds:[30267],authors:[e]}],n=vt([{kinds:[10002],authors:[e]},...t],{authors:[e]}),r=pt.replaceable(10002,e).pipe(Ae(Yl),ye(i=>i.length>0),Ys(1),dn(i=>vt(t,{authors:[e],relays:i})));return De(n,r)}const z={feed:[],around:{type:"starting"},openedAt:Date.now()};function Jl(e){z.feed=[...z.feed.filter(t=>t.source!==e.source),e],ve()}let gr=!1;const Tt=[];function Ql(){if(!gr){if(gr=!0,z.openedAt=Date.now(),Tt.push(sn([pt.timeline({kinds:ke}),pr]).subscribe(([e])=>{le.clear();for(const t of e){const n=bo(t);if(!n)continue;const r=Nl(t,"feed",[...hr.get(n)??[]]);r&&(r.origins=new Set(dr.get(n)??["feed"]),le.set(r.key,r))}An([...le.values()].map(t=>t.pubkey)),ve()}),pt.timeline({kinds:[0]}).subscribe(e=>{const t=[];for(const n of e){const r=Fl(n);if(!r)continue;const i=yr.get(n.pubkey);i&&i.name===r.name&&i.picture===r.picture||(yr.set(n.pubkey,r),t.push(n.pubkey))}for(const n of t)mr.forEach(r=>r(n));t.length&&ve()})),ie("identity","getPublicKey")){if(qo().then(e=>e&&we.next(e)).catch(()=>{}).finally(()=>on.next(!0)),ie("identity","onChanged"))try{const e=zo(t=>we.next(t||void 0));Tt.push({unsubscribe:()=>e.close()})}catch{}}else on.next(!0);ie("identity","getFollows")&&Ko().then(e=>$t.next(new Set(e.filter(t=>Dt.test(t))))).catch(()=>{}),Tt.push(we.pipe(Ht(),dn(e=>e?pt.replaceable(3,e):gt(void 0))).subscribe(e=>{e&&$t.next(new Set(e.tags.filter(t=>t[0]==="p"&&Dt.test(t[1]??"")).map(t=>t[1])))}),sn([we,$t]).subscribe(([e,t])=>wo([...e?[e]:[],...t])),sn([we,$t,on]).subscribe(()=>ve()),Ci(vt([{kinds:ke,limit:Bi}],{catalogue:!0,onNotice:Jl})),Ci(Vl([{kinds:ke,limit:Bi}],e=>{z.around=e,ve()}),"around"),Wl().subscribe(e=>{z.mesh=e,ve()}),br.pipe(Ht(),dn(e=>e?Xl(e):xn)).subscribe(e=>Sn(e)),{unsubscribe:()=>(jr.close(),vo.close())})}}function ef(){Tt.splice(0).forEach(e=>e.unsubscribe()),gr=!1}function tf(e){Tt.push(e)}const xo=30267,st="napplets",nf="Recommended napplets",C={follows:new Set,byApp:new Map,ready:!1},vr=new Map,Ee=new Map,Ti="bbb5dda0e15567979f0543407bdc2033d6f0bbb30f72512a981cfdb2f09e2747",qr=[{pubkey:Ti,d:st},{pubkey:Ti,d:"mesh"}];function ko(e){return[...C.byApp.get(e.key)??[]]}function rf(e){var t;return!!(C.me&&((t=C.byApp.get(e.key))!=null&&t.has(C.me)))}function ue(e,t){var n;return(((n=e.tags.find(r=>r[0]===t&&typeof r[1]=="string"))==null?void 0:n[1])??"").trim()}function sf(e,t){return qr.some(n=>n.pubkey===e&&n.d===t)}function jt(e){const t=ue(e,"d");return{key:`${e.pubkey}:${t}`,pubkey:e.pubkey,d:t,title:ue(e,"title")||ue(e,"name")||t,description:ue(e,"description")||ue(e,"summary")||e.content.trim(),addresses:[...new Set(In(e))],createdAt:e.created_at,isDefault:t===st,featured:sf(e.pubkey,t)}}function zr(){const e=qr.map(n=>Ee.get(`${n.pubkey}:${n.d}`)).filter(n=>!!n).map(jt),t=[...Ee.values()].filter(n=>n.pubkey===C.me||C.follows.has(n.pubkey)).map(jt).filter(n=>!n.featured).sort((n,r)=>r.addresses.length-n.addresses.length||r.createdAt-n.createdAt);return[...e,...t].filter(n=>n.addresses.length>0)}function Eo(e){return ue(e,"d")!==st&&!ue(e,"title")&&!ue(e,"name")&&In(e).length===0}function Kr(){const e=C.me;return e?[...Ee.values()].filter(t=>t.pubkey===e&&!Eo(t)).map(jt).sort((t,n)=>Number(n.isDefault)-Number(t.isDefault)||n.createdAt-t.createdAt):[]}function of(e){return[...Ee.values()].filter(t=>t.pubkey===e&&!Eo(t)).map(jt).filter(t=>t.addresses.length>0).sort((t,n)=>Number(n.isDefault)-Number(t.isDefault)||n.addresses.length-t.addresses.length)}function af(e){const t=Ee.get(e);return t?jt(t):void 0}function In(e){return e.tags.filter(t=>t[0]==="a"&&typeof t[1]=="string").map(t=>t[1]).filter(t=>ke.includes(Number(t.split(":")[0])))}function cf(){C.byApp.clear();for(const[e,t]of vr)if(!(e!==C.me&&!C.follows.has(e)))for(const n of In(t)){let r=C.byApp.get(n);r||C.byApp.set(n,r=new Set),r.add(e)}}const uf=new Dr(e=>{const t=[...new Set(e.map(n=>n.split(":")[1]??""))].filter(Boolean);return vt(lf(e),{authors:t})});function lf(e){const t=new Map;for(const n of e){const[r,i,s=""]=n.split(":");if(!i)continue;const o=`${r}:${i}`,a=t.get(o)??{kind:Number(r),author:i,ds:[]};a.ds.push(s),t.set(o,a)}return[...t.values()].map(n=>n.kind===ke[1]?{kinds:[n.kind],authors:[n.author]}:{kinds:[n.kind],authors:[n.author],"#d":n.ds})}let Oi=!1;function ff(){Oi||(Oi=!0,tf(sn([pt.timeline({kinds:[xo]}),we,$t,on]).subscribe(([e,t,n,r])=>{var s;C.me=t,C.follows=n,C.ready=r,Ee.clear(),vr.clear();for(const o of e){const a=ue(o,"d");Ee.set(`${o.pubkey}:${a}`,o),a===st&&vr.set(o.pubkey,o)}for(const[o,a]of yt)t&&(((s=Ee.get(`${t}:${o}`))==null?void 0:s.created_at)??0)>a&&yt.delete(o);cf();const i=zr();An([...i.map(o=>o.pubkey),...[...C.byApp.values()].flatMap(o=>[...o])]),uf.add([...C.byApp.keys(),...i.flatMap(o=>o.addresses)]),ve()})),wo(qr.map(e=>e.pubkey)))}function Gt(){return ie("outbox","publish")}const df=3*6e4,yt=new Map;function hf(e,t){yt.set(e,t),window.setTimeout(()=>{yt.get(e)===t&&(yt.delete(e),ve())},df)}function So(e){return yt.has(e)}function pf(){return So(st)}async function Zt(e,t){if(!Gt())return{ok:!1,error:"This shell cannot publish."};const n=C.me?Ee.get(`${C.me}:${e}`):void 0,{tags:r,content:i}=t(n),s=await Qo({kind:xo,content:i,tags:[["d",e],...r.filter(o=>o[0]!=="d")],created_at:Math.max(Math.floor(Date.now()/1e3),((n==null?void 0:n.created_at)??0)+1)}).catch(o=>({ok:!1,error:String(o),event:void 0}));if(!s.ok){const o=s.error??"Publish failed.";return/timed out/i.test(o)&&C.me?(hf(e,(n==null?void 0:n.created_at)??0),ve(),{ok:!1,pending:!0,error:o}):{ok:!1,error:o}}return s.event&&(we.value||we.next(s.event.pubkey),Sn({event:s.event})),{ok:!0}}function Vr(e,t){return((e==null?void 0:e.tags)??[]).filter(n=>n[0]!=="d"&&n[0]!=="title"&&!(t!==void 0&&n[0]==="a"&&n[1]===t))}function yf(e){return wr(st,e)}function wr(e,t){return Zt(e,n=>{const r=!!(n&&In(n).includes(t.key)),i=n?ue(n,"title"):"",s=[["title",e===st?nf:i||e],...Vr(n,t.key)];return r||s.push(["a",t.key,...t.relayHints.slice(0,1)]),{tags:s,content:(n==null?void 0:n.content)??""}})}function mf(e,t){return Zt(e,n=>({tags:[["title",n&&ue(n,"title")||e],...Vr(n,t)],content:(n==null?void 0:n.content)??""}))}function bf(e,t){return Zt(e,n=>({tags:[["title",t.trim()||e],...Vr(n)],content:(n==null?void 0:n.content)??""}))}function gf(e){return Zt(e,()=>({tags:[],content:""}))}async function Ao(e){const n=`${e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,32)||"stack"}-${Math.random().toString(16).slice(2,6)}`;return{...await Zt(n,()=>({tags:[["title",e.trim()]],content:""})),d:n}}const Li=new Map,Ri=[];let Vn=0;const vf=4;function Io(e){return new Promise((t,n)=>{const r=()=>{Vn++,e().then(t,n).finally(()=>{var i;Vn--,(i=Ri.shift())==null||i()})};Vn<vf?r():Ri.push(r)})}let Ni;function wf(){return Ni??(Ni=ie("resource","info")?Yo().then(e=>new Set(e.schemes.filter(t=>t.enabled).map(t=>t.scheme))).catch(()=>{}):Promise.resolve(void 0)),Ni}const xf=/(^|\.)nostr\.build$/i,$o=new Set,kf=/^([0-9a-f]{64})(?:\.[a-z0-9]+)?$/i;function Ef(e,t,n){var r;if(e.startsWith("blossom:"))return[{url:e,servers:t}];try{const i=new URL(e),s=i.pathname.split("/").pop()??"",o=(r=kf.exec(s))==null?void 0:r[1],a=i.hostname.toLowerCase();if(o&&(i.protocol==="https:"||i.protocol==="http:")&&!xf.test(a)&&!$o.has(a)){const c={url:`blossom:sha256:${o.toLowerCase()}`,servers:[i.origin],rewroteHost:a};return n?[{url:e},c]:[c,{url:e}]}}catch{}return[{url:e}]}function Wr(e,t=[]){if(!ie("resource","bytes")||e.length===0)return Promise.resolve(void 0);const n=e.join(`
`);let r=Li.get(n);return r||(r=(async()=>{const i=await wf(),s=i?i.has("https"):void 0;for(const o of e.flatMap(a=>Ef(a,t,s))){const a=o.url.split(":")[0];if(!(i&&!i.has(a)))try{const c=await Io(()=>{var u;return yn(o.url,o.url.startsWith("blossom:")&&((u=o.servers)!=null&&u.length)?{servers:o.servers}:void 0)});if(c.size>0&&(c.type===""||c.type.startsWith("image/")))return URL.createObjectURL(c)}catch{o.rewroteHost&&$o.add(o.rewroteHost)}}})(),Li.set(n,r)),r}const Mi=new Map;function Sf(e,t,n){let r=Mi.get(e);return r||(r=(async()=>{if(!ie("resource","bytes")||t.length===0)return;let i=0;for(const{sha256:s}of t)try{const o=await Io(()=>yn(`blossom:sha256:${s}`,n.length?{servers:n}:void 0));i+=o.size}catch{return}return i})(),Mi.set(e,r)),r}function Af(e){if(e<1024)return`${e} B`;const t=["KB","MB","GB"];let n=e/1024,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r++;return`${n<10?n.toFixed(1):Math.round(n)} ${t[r]}`}const If={title:"Myco Light",colors:{background:"#ffffff",text:"#0f172a",primary:"#059669"}},$f={title:"Myco AMOLED",colors:{background:"#000000",text:"#ffffff",primary:"#34d399"}},_f=/^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;function Bf(){var t;return((t=window.matchMedia)==null?void 0:t.call(window,"(prefers-color-scheme: dark)").matches)??!1?$f:If}function hn(e){let t=e.slice(1);return t.length===3&&(t=[...t].map(n=>n+n).join("")),[0,2,4].map(n=>parseInt(t.slice(n,n+2),16))}function Pi(e){const[t,n,r]=hn(e).map(i=>{const s=i/255;return s<=.03928?s/12.92:((s+.055)/1.055)**2.4});return .2126*t+.7152*n+.0722*r}function he(e,t,n){const[r,i]=[hn(e),hn(n)],s=o=>Math.round((r[o]*t+i[o]*(100-t))/100);return`rgb(${s(0)}, ${s(1)}, ${s(2)})`}function Re(e,t){const[n,r,i]=hn(e);return`rgba(${n}, ${r}, ${i}, ${t/100})`}function Cf(e,t,n,r){return{"--surface":he(t,r?7:4,e),"--surface-2":he(t,r?11:8,e),"--border":Re(t,r?16:12),"--muted":he(t,62,e),"--faint":he(t,40,e),"--primary-soft":Re(n,15),"--primary-ink":he(n,70,t),"--sk-a":he(t,7,e),"--sk-b":he(t,13,e),"--shadow":`0 2px 8px ${Re("#000000",r?40:10)}`,"--bg-clear":Re(e,0),"--text-strong":he(t,85,e),"--text-soft":he(t,80,e),"--text-half":he(t,50,e),"--text-wash":Re(t,10),"--primary-edge":Re(n,60),"--primary-edge-soft":Re(n,40),"--primary-tint":Re(n,30)}}const Ui=new Map;let ze;async function Hi(e,t){var o;const n=document.documentElement,r=(o=t.fonts)==null?void 0:o[e],i=e==="body"?"--font-body":"--font-title";if(!(r!=null&&r.name)){n.style.removeProperty(i);return}const s=`theme-${e}-${r.name}`;try{if(!Ui.has(s)){const a=await yn(r.url),c=new FontFace(s,await a.arrayBuffer());await c.load(),document.fonts.add(c),Ui.set(s,c)}n.style.setProperty(i,`"${s}", ${e==="body"?"var(--font-system)":"var(--font-body)"}`)}catch{n.style.setProperty(i,`"${r.name.replace(/"/g,"")}", var(--font-system)`)}}async function Tf(e){var r;const t=e.background,n=document.body;if(!(t!=null&&t.url)||!((r=t.mime)!=null&&r.startsWith("image/"))){n.style.removeProperty("background-image");return}try{if((ze==null?void 0:ze.source)!==t.url){const i=await yn(t.url);ze&&URL.revokeObjectURL(ze.objectUrl),ze={source:t.url,objectUrl:URL.createObjectURL(i)}}n.style.backgroundImage=`url("${ze.objectUrl}")`,n.style.backgroundSize=/^[a-z0-9 %.-]+$/i.test(t.mode)?t.mode:"cover"}catch{n.style.removeProperty("background-image")}}function ft(e){var o,a,c;const t=Bf(),n=(u,d)=>u&&_f.test(u)?u:d,r={background:n((o=e==null?void 0:e.colors)==null?void 0:o.background,t.colors.background),text:n((a=e==null?void 0:e.colors)==null?void 0:a.text,t.colors.text),primary:n((c=e==null?void 0:e.colors)==null?void 0:c.primary,t.colors.primary)},i=document.documentElement;i.style.setProperty("--bg",r.background),i.style.setProperty("--text",r.text),i.style.setProperty("--primary",r.primary),i.style.setProperty("--on-primary",Pi(r.primary)>.45?"#000000":"#ffffff"),i.dataset.scheme=Pi(r.background)<.35?"dark":"light",i.style.colorScheme=i.dataset.scheme;const s=Cf(r.background,r.text,r.primary,i.dataset.scheme==="dark");for(const[u,d]of Object.entries(s))i.style.setProperty(u,d);e&&(Hi("body",e),Hi("title",e),Tf(e))}function Of(){var e;if(ft(void 0),!ie("theme","get")){const t=(e=window.matchMedia)==null?void 0:e.call(window,"(prefers-color-scheme: dark)"),n=()=>ft(void 0);return t==null||t.addEventListener("change",n),()=>t==null?void 0:t.removeEventListener("change",n)}try{Wo().then(ft).catch(()=>ft(void 0))}catch{ft(void 0)}try{const t=Go(ft);return()=>t.close()}catch{return()=>{}}}const K={tab:"feed",query:"",stack:[]},Lf=2500,_o=e=>Date.now()-e<Lf,xr=new Map;function L(e){const t=document.querySelector(e);if(!t)throw new Error(`Missing element: ${e}`);return t}const $n=L("#app"),Ot=L("#search"),kr=L("#searchClear"),Rf=L("#feedList"),Nf=L("#feedState"),Mf=L("#communitySection"),Wn=L("#stacksRow"),Pf=L("#aroundList"),Uf=L("#aroundState"),Di=L("#aroundBadge"),Ke=L("#meshStatus"),Hf=L("#meshBanner"),se=L("#detail"),Df={feed:L("#panel-feed"),around:L("#panel-around"),profile:L("#panel-profile")},Ft={feed:L("#tab-feed"),around:L("#tab-around"),profile:L("#tab-profile")},jf=L("#profileHeader"),ji=L("#myStacks"),Xe=L("#newStackTitle"),Lt=L("#newStackButton"),Fi=L("#profileNote");function f(e,t={},...n){const r=document.createElement(e);for(const[i,s]of Object.entries(t))s===void 0||s===!1||(i==="class"?r.className=String(s):r.setAttribute(i,s===!0?"":s));for(const i of n)i!==!1&&i!==null&&i!==void 0&&r.append(i);return r}function ot(e,t="icon"){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");return n.setAttribute("viewBox","0 0 24 24"),n.setAttribute("class",t),n.setAttribute("aria-hidden","true"),n.innerHTML=e,n}const D={back:'<path d="M15 5l-7 7 7 7"/>',heart:'<path d="M12 20s-7-4.4-7-10a4 4 0 0 1 7-2.6A4 4 0 0 1 19 10c0 5.6-7 10-7 10z"/>',stack:'<path d="M12 3 3 7.5 12 12l9-4.5L12 3zM3 12l9 4.5 9-4.5M3 16.5 12 21l9-4.5"/>',nearby:'<circle cx="12" cy="12" r="2.2"/><path d="M7.8 7.8a6 6 0 0 0 0 8.4M16.2 7.8a6 6 0 0 1 0 8.4"/>',download:'<path d="M12 4v11m0 0 4.5-4.5M12 15l-4.5-4.5M5 19.5h14"/>',empty:'<circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5M8.5 11h5"/>',alert:'<path d="M12 8v5m0 3.2v.3"/><circle cx="12" cy="12" r="9"/>',lock:'<rect x="5" y="10.5" width="14" height="10" rx="2.5"/><path d="M8 10.5V8a4 4 0 0 1 8 0v2.5"/>'};function Bo(e){let t=0;for(const n of e)t=t*31+n.charCodeAt(0)|0;return Math.abs(t)%360}function Co(e){const t=e.replace(/[^\p{L}\p{N} ]/gu," ").trim().split(/\s+/);return(t.length>1?t[0][0]+t[1][0]:(t[0]??"?").slice(0,1)).toUpperCase()}function _n(e,t){const n=f("div",{class:`app-icon app-icon-${t}`,"aria-hidden":"true"});return n.style.setProperty("--hue",String(Bo(e.key))),n.append(f("span",{class:"app-icon-letters"},Co(e.title))),Wr(e.icons,e.servers).then(r=>{if(!r)return;const i=f("img",{src:r,alt:""});n.replaceChildren(i),n.classList.add("has-image")}),n}function me(e){var t;return((t=go(e))==null?void 0:t.name)??co(e)}function Yt(e,t="sm"){const n=f("span",{class:`avatar avatar-${t}`,"data-avatar":e,"aria-hidden":"true"});return n.style.setProperty("--hue",String(Bo(e))),To(n,e),n}function To(e,t){const n=go(t);e.textContent=Co((n==null?void 0:n.name)??"n"),n!=null&&n.picture&&Wr([n.picture]).then(r=>{r&&e.replaceChildren(f("img",{src:r,alt:""}))})}Zl(e=>{document.querySelectorAll(`[data-author="${e}"]`).forEach(t=>{t.textContent=me(e)}),document.querySelectorAll(`[data-avatar="${e}"]`).forEach(t=>To(t,e))});function Ff(e){return e===C.me?"you":me(e)}function Oo(e){return ko(e).sort((t,n)=>+(t===C.me)-+(n===C.me))}function qf(e){const t=Oo(e);if(t.length===0)return null;const n=t.slice(0,2).map(i=>Vf(i,Ff(i))),r=f("span",{class:"proof-text"},"Recommended by ");return n.forEach((i,s)=>{s>0&&r.append(t.length===2?" and ":", "),r.append(i)}),t.length>2&&r.append(` and ${t.length-2} ${t.length-2===1?"other":"others"}`),f("div",{class:"proof"},f("span",{class:"avatar-stack","aria-hidden":"true"},...t.slice(0,3).map(i=>Yt(i))),r)}function je(e,t,n=""){return f("span",{class:`pill ${n}`.trim()},t?ot(t,"pill-icon"):null,e)}function Gr(e){const t=e.origins.has("around"),n=f("div",{class:"card"},_n(e,"card"),f("div",{class:"card-main"},f("div",{class:"card-title-row"},f("span",{class:"card-title"},e.title),f("span",{class:"by"},"by ",tt(e.pubkey))),f("div",{class:"pills"},je(uo(e.createdAt)),t&&je("Nearby",D.nearby,"pill-nearby")),f("p",{class:"card-summary"},e.summary||"No description available"),qf(e)));return Yr(n,`${e.title} by ${me(e.pubkey)}`,()=>Ro(e.key)),f("li",{},n)}function Zr(e){return Array.from({length:e},()=>f("li",{"aria-hidden":"true"},f("div",{class:"card skeleton"},f("div",{class:"app-icon app-icon-card sk"}),f("div",{class:"card-main"},f("div",{class:"sk sk-title"}),f("div",{class:"sk sk-pill"}),f("div",{class:"sk sk-line"}),f("div",{class:"sk sk-line short"})))))}function ce(e,t,n,r){return f("div",{class:"empty"},ot(e,"empty-icon"),f("strong",{},t),f("p",{},n),r)}function zf(e,t){if(!t)return!0;const n=[e.title,e.summary,e.d,me(e.pubkey),...e.archetypes].join(" ").toLowerCase();return t.toLowerCase().split(/\s+/).every(r=>n.includes(r))}function Kf(e){return[...le.values()].filter(t=>t.origins.has(e)&&zf(t,K.query)).sort((t,n)=>n.createdAt-t.createdAt)}function qi(e){const t=e==="feed"?Rf:Pf,n=e==="feed"?Nf:Uf,r=Kf(e);if(r.length>0){t.replaceChildren(...r.map(Gr)),n.hidden=!0;return}const i=z.around,s=i.type==="unsupported"||i.type==="denied";if(_o(z.openedAt)&&!K.query&&!(e==="around"&&s)){t.replaceChildren(...Zr(3)),n.hidden=!0;return}if(t.replaceChildren(),n.hidden=!1,K.query)n.replaceChildren(ce(D.empty,"No results found",`Nothing matches “${K.query}”.`));else if(e==="feed"){const o=z.feed.find(c=>c.denied),a=z.feed[0];n.replaceChildren(o?ce(D.lock,"Reading relays is off",o.reason):a?ce(D.alert,"Still trying to reach relays",`${a.reason} New napplets appear here as soon as one answers.`):ce(D.empty,"No napplets yet","None turned up on your relays or this device so far. New ones appear here as they arrive."))}else i.type==="unsupported"?n.replaceChildren(Qf()):i.type==="denied"?n.replaceChildren(ed()):i.type==="closed"?n.replaceChildren(ce(D.alert,"Reconnecting to the mesh",i.reason||"The mesh subscription closed; it reopens by itself.")):n.replaceChildren(ce(D.nearby,"Nothing nearby yet",z.mesh&&z.mesh.peers>0?"Devices around you have not shared any napplets yet. New ones appear here as they arrive.":"No devices in range. Napplets held by people around you will appear here."))}function tt(e,t="sm"){const n=f("button",{class:"author-link",type:"button","aria-label":`Open ${me(e)}'s profile`},Yt(e,t),f("span",{class:"by-name","data-author":e},me(e)));return n.addEventListener("click",r=>{r.stopPropagation(),Fe({type:"person",pubkey:e})}),n.addEventListener("keydown",r=>r.stopPropagation()),n}function Vf(e,t){const n=f("button",{class:"author-link proof-name",type:"button","data-author":e===C.me?void 0:e},t);return n.addEventListener("click",r=>{r.stopPropagation(),Fe({type:"person",pubkey:e})}),n.addEventListener("keydown",r=>r.stopPropagation()),n}function Yr(e,t,n){return e.tabIndex=0,e.setAttribute("role","button"),e.setAttribute("aria-label",t),e.addEventListener("click",n),e.addEventListener("keydown",r=>{r.target===e&&(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),n())}),e}function Xr(e,t,n){t.addEventListener("click",n),e.addEventListener("keydown",r=>{r.key==="Enter"&&!r.isComposing&&(r.preventDefault(),t.disabled||n())})}function Rt(e){return e.ok?"":e.pending?"Still waiting for your signer. This updates once you approve.":`Could not publish: ${e.error??"unknown error"}`}const zi=8;function Wf(e){const t=f("div",{class:"stack-tiles","aria-hidden":"true"}),n=e.addresses.length>4?3:4;for(const r of e.addresses.slice(0,n)){const i=le.get(r);t.append(i?_n(i,"mini"):f("div",{class:"app-icon app-icon-mini sk"}))}return e.addresses.length>4&&t.append(f("div",{class:"app-icon app-icon-mini stack-more"},`+${e.addresses.length-3}`)),t}function Bn(e,t=()=>Fe({type:"stack",key:e.key}),n=!1){const r=me(e.pubkey),i=e.isDefault?n?f("div",{},f("span",{class:"stack-title"},"Recommended by you"),f("span",{class:"stack-by"},`${e.addresses.length} ${e.addresses.length===1?"napplet":"napplets"}`)):f("div",{},f("span",{class:"stack-kicker"},"Recommended by"),f("span",{class:"stack-person stack-title"},tt(e.pubkey))):f("div",{},f("span",{class:"stack-title"},e.title),n?f("span",{class:"stack-by"},`${e.addresses.length} ${e.addresses.length===1?"napplet":"napplets"}`):f("span",{class:"stack-by"},"by ",tt(e.pubkey))),s=e.isDefault?`Recommended by ${r}`:`${e.title} by ${r}`,o=f("div",{class:"stack-card"},i,Wf(e));return Yr(o,`${s}, ${e.addresses.length} napplets`,t),f("div",{role:"listitem",class:"stack-cell"},o)}function Gf(e){const t=f("button",{class:"stack-card stack-see-more",type:"button",role:"listitem"},f("span",{},"See more"),f("span",{class:"stack-by"},`${e} stacks`));return t.addEventListener("click",()=>Fe({type:"stacks"})),t}function Zf(){const e=zr();if(Wn.hidden=e.length===0||!!K.query,Wn.hidden)return!1;An(e.map(n=>n.pubkey));const t=e.slice(0,zi).map(n=>Bn(n));return e.length>zi&&t.push(Gf(e.length)),Wn.replaceChildren(...t),!0}function Yf(e){const t=af(e);if(!t){rt(f("div",{class:"detail-top"},nt()),f("div",{class:"detail-scroll"},ce(D.empty,"Stack not found","This stack is gone or has not arrived yet.")));return}const n=t.addresses.map(i=>le.get(i)).filter(i=>!!i),r=t.addresses.length-n.length;rt(f("div",{class:"detail-top"},nt()),f("div",{class:"detail-scroll"},t.isDefault?f("header",{class:"hero person-hero"},Yt(t.pubkey,"lg"),f("div",{class:"hero-text"},f("p",{class:"hero-kicker"},"Recommended by"),f("h1",{class:"hero-title","data-author":t.pubkey},me(t.pubkey)),f("div",{class:"stack-by"},tt(t.pubkey)),f("div",{class:"pills"},je(`${t.addresses.length} ${t.addresses.length===1?"napplet":"napplets"}`)))):f("header",{class:"hero stack-hero"},f("div",{class:"hero-text"},f("p",{class:"hero-kicker"},"App stack"),f("h1",{class:"hero-title"},t.title),f("div",{class:"stack-by"},"by ",tt(t.pubkey)),f("div",{class:"pills"},je(`${t.addresses.length} ${t.addresses.length===1?"napplet":"napplets"}`)))),t.description&&f("p",{class:"stack-description"},t.description),Je("Napplets"),n.length>0?f("ul",{class:"cards"},...n.map(Gr)):null,r>0&&(n.length===0?f("ul",{class:"cards"},...Zr(Math.min(r,3))):f("p",{class:"person-pending"},`${r} more still loading…`))))}function Xf(){rt(f("div",{class:"detail-top"},nt()),f("div",{class:"detail-scroll"},f("header",{class:"hero"},f("div",{class:"hero-text"},f("h1",{class:"hero-title"},"App stacks"))),f("div",{class:"stacks-grid",role:"list"},...zr().map(e=>Bn(e)))))}function Jf(){Mf.hidden=!Zf()}const Ki="https://zapstore.dev/apps/app.myco";function Qf(){const e=ce(D.nearby,"No mesh in this app runtime","Seeing what people around you have needs a runtime with a mesh, one that talks to nearby phones directly. Myco does, over Bluetooth and Wi-Fi, with no internet.");if(ie("link","open")){const t=f("button",{class:"btn btn-primary btn-small",type:"button"},"Get Myco on Zapstore");t.addEventListener("click",()=>void Yi(Ki,{label:"Myco on Zapstore"}).catch(()=>{})),e.append(t)}else e.append(f("p",{class:"mono selectable-url"},Ki));return e}function ed(){return f("div",{class:"empty"},ot(D.lock,"empty-icon"),f("strong",{},"Mesh is switched off for AppStore"),f("p",{},"AppStore needs the Mesh permission to ask nearby phones what they have. To turn it on in Myco:"),f("ol",{class:"steps"},f("li",{},"Go to your Apps screen."),f("li",{},"Press and hold AppStore."),f("li",{},"Tap ",f("strong",{},"Manage permissions"),"."),f("li",{},"Turn on ",f("strong",{},"Mesh"),". AppStore restarts with it.")))}function td(){const e=[...le.values()].filter(n=>n.origins.has("around")).length;Di.hidden=e===0,Di.textContent=e>99?"99+":String(e);const t=z.mesh;Hf.dataset.live=String(!!(t!=null&&t.online&&t.peers>0)),z.around.type==="unsupported"?Ke.textContent="No mesh in this app runtime":z.around.type==="denied"?Ke.textContent="Mesh permission is off":z.around.type==="closed"?Ke.textContent="Reconnecting…":t?t.online?t.peers===0?Ke.textContent="No devices in range":Ke.textContent=`${t.peers} ${t.peers===1?"device":"devices"} nearby`:Ke.textContent="Mesh is off":Ke.textContent="Looking around…"}let Gn=!1;function Xt(){Gn||(Gn=!0,requestAnimationFrame(()=>{Gn=!1,Jf(),ld(),qi("feed"),qi("around"),td()}))}function Jr(e){K.tab=e,$n.dataset.tab=e;for(const t of Object.keys(Ft))Ft[t].setAttribute("aria-selected",String(t===e)),Df[t].hidden=t!==e;K.stack.length>0&&rd(),L(".list-view").scrollTop=0}Ft.feed.addEventListener("click",()=>Jr("feed"));Ft.around.addEventListener("click",()=>Jr("around"));Ft.profile.addEventListener("click",()=>Jr("profile"));Ot.addEventListener("input",()=>{K.query=Ot.value.trim(),kr.hidden=Ot.value==="",Xt()});kr.addEventListener("click",()=>{Ot.value="",K.query="",kr.hidden=!0,Xt(),Ot.focus()});const nd={mesh:["Nearby devices","Publishes and reads events over the local mesh, as you, with no per-event prompt."],relay:["Relays","Reads and publishes Nostr events on your relays."],outbox:["Your network","Reads and publishes Nostr events, routed by your relays."],identity:["Your profile","Reads your public key, profile and follows."],resource:["Files","Loads images and files through the shell."],storage:["Storage","Keeps its own data on this device."],theme:["Theme","Follows your shell theme."],link:["Links","Asks the shell to open links."],notify:["Notifications","Can show notifications."],dm:["Direct messages","Reads and sends your direct messages."],upload:["Uploads","Uploads files on your behalf."],lists:["Lists","Edits your Nostr lists."],common:["Social actions","Follows, reacts and reports on your behalf."],intent:["Other apps","Opens other napplets."],inc:["App messages","Talks to other napplets."],ble:["Bluetooth","Talks to Bluetooth devices."],serial:["Serial","Talks to serial devices."],webrtc:["Peer connections","Opens direct connections to other people."]};function Lo(){return K.stack[K.stack.length-1]}function Ro(e){Fe({type:"app",key:e})}function Fe(e){var t;K.stack.push(e),e.type==="person"&&(xr.has(e.pubkey)||xr.set(e.pubkey,Date.now())),se.replaceChildren(),Et(),$n.dataset.view="detail",se.hidden=!1,(t=se.querySelector(".back"))==null||t.focus({preventScroll:!0})}function Qr(){var t;const e=K.stack.pop();if(K.stack.length>0){se.replaceChildren(),Et();return}if($n.dataset.view="list",se.hidden=!0,se.replaceChildren(),Fr(void 0),(e==null?void 0:e.type)==="app"){const n=((t=le.get(e.key))==null?void 0:t.title)??"\0",r=[...document.querySelectorAll(".card")].find(i=>{var s;return(s=i.getAttribute("aria-label"))==null?void 0:s.startsWith(n)});r==null||r.focus({preventScroll:!1})}}function rd(){K.stack=[],$n.dataset.view="list",se.hidden=!0,se.replaceChildren(),Fr(void 0)}function Et(){const e=Lo();Fr((e==null?void 0:e.type)==="person"?e.pubkey:void 0),(e==null?void 0:e.type)==="app"?ud(e.key):(e==null?void 0:e.type)==="person"?ad(e.pubkey):(e==null?void 0:e.type)==="stack"?Yf(e.key):(e==null?void 0:e.type)==="stacks"?Xf():(e==null?void 0:e.type)==="editStack"&&fd(e.d)}document.addEventListener("keydown",e=>{var t;if(!(e.key!=="Escape"||e.defaultPrevented)){if(pn!==void 0&&((t=Lo())==null?void 0:t.type)==="app"){e.preventDefault(),pn=void 0,Et();return}K.stack.length>0&&(e.preventDefault(),Qr())}});function Ne(e,t,n=!1){return f("div",{class:"info-row"},f("dt",{},e),f("dd",{class:n?"mono":void 0},t))}function Zn(e){const t=f("span",{class:"selectable mono",tabindex:"0",title:"Tap to select"},e),n=()=>{const r=document.createRange();r.selectNodeContents(t);const i=window.getSelection();i==null||i.removeAllRanges(),i==null||i.addRange(r)};return t.addEventListener("click",n),t.addEventListener("focus",n),t}function id(e){const t=f("div",{class:"description"}),n=e.split(/\n{2,}/).map(s=>s.trim()).filter(Boolean);n.length===0&&n.push("No description available.");for(const s of n)t.append(f("p",{},s));if(!(e.length>600||n.length>4))return t;t.classList.add("collapsed");const i=f("button",{class:"read-more",type:"button"},"Read more");return i.addEventListener("click",()=>{t.classList.remove("collapsed"),i.remove()}),f("div",{class:"description-wrap"},t,i)}function sd(e){if(e.screenshots.length===0)return null;const t=f("div",{class:"shots",role:"list","aria-label":"Screenshots"});for(const n of e.screenshots){const r=f("div",{class:"shot sk",role:"listitem"});t.append(r),Wr([n],e.servers).then(i=>{var s;r.classList.remove("sk"),i?r.replaceChildren(f("img",{src:i,alt:`${e.title} screenshot`,loading:"lazy"})):r.remove(),t.children.length||(s=t.closest(".shots-section"))==null||s.remove()})}return f("section",{class:"shots-section"},t)}function od(e){const t=f("ul",{class:"perms"});e.requires.length===0&&t.append(f("li",{class:"perm"},f("div",{},f("strong",{},"Nothing extra"),f("p",{},"Runs with the shell’s default access only."))));for(const n of e.requires){const[r,i]=nd[n]??[n,"A capability this shell may not offer."];t.append(f("li",{class:`perm${n==="mesh"?" perm-notable":""}`},f("span",{class:"perm-tag mono"},n),f("div",{},f("strong",{},r),f("p",{},i))))}return t}function Je(e){return f("h2",{class:"section-header"},f("span",{},e))}function nt(){const e=f("button",{class:"back",type:"button","aria-label":"Back"},ot(D.back),"Back");return e.addEventListener("click",Qr),e}function rt(...e){var r;const t=((r=se.querySelector(".detail-scroll"))==null?void 0:r.scrollTop)??0;se.replaceChildren(...e.filter(i=>!!i));const n=se.querySelector(".detail-scroll");n&&(n.scrollTop=t)}function ad(e){const t=of(e),n=[...le.values()].filter(i=>i.pubkey===e).sort((i,s)=>s.createdAt-i.createdAt),r=_o(xr.get(e)??0);rt(f("div",{class:"detail-top"},nt()),f("div",{class:"detail-scroll"},f("header",{class:"hero person-hero"},Yt(e,"lg"),f("div",{class:"hero-text"},f("h1",{class:"hero-title","data-author":e},me(e)),f("p",{class:"hero-sub mono"},co(e)),f("div",{class:"pills"},je(`${n.length} published`),t.length>0&&je(`${t.length} ${t.length===1?"stack":"stacks"}`)))),t.length>0&&Je("Stacks"),t.length>0&&f("div",{class:"stacks",role:"list"},...t.map(i=>Bn(i))),Je("Published napplets"),n.length>0?f("ul",{class:"cards"},...n.map(Gr)):r?f("ul",{class:"cards"},...Zr(2)):ce(D.empty,"Nothing published yet","No napplets from this person have turned up so far. They appear here as they arrive.")))}function cd(e){const t=f("span",{},"…");return Sf(e.aggregate??e.key,e.paths,e.servers).then(n=>{t.textContent=n===void 0?"Unknown":Af(n)}),t}function ud(e){const t=le.get(e);if(!t)return;const n=jl(t),r=t.origins.has("around"),i=f("header",{class:"hero"},_n(t,"hero"),f("div",{class:"hero-text"},f("h1",{class:"hero-title"},t.title),f("div",{class:"pills"},je(`Updated ${uo(t.createdAt)}`),r&&je("Nearby",D.nearby,"pill-nearby")))),s=f("div",{class:"author-row"},"Published by ",tt(t.pubkey)),o=dd(t),a=f("dl",{class:"info-table"},Ne("Identifier",t.kind===35129?t.d:"(root napplet)",!0),Ne("Updated",ql(t.createdAt)),Ne("Size",cd(t)),t.archetypes.length>0&&Ne("Archetypes",t.archetypes.join(", ")),Ne("Author",Zn(ao(t.pubkey))),t.aggregate&&Ne("Build hash",Zn(t.aggregate)),Ne("Address",Zn(n)),Ne("Found",[t.origins.has("feed")&&"Your relays",r&&"Nearby devices"].filter(Boolean).join(" · ")));rt(f("div",{class:"detail-top"},nt()),f("div",{class:"detail-scroll"},i,s,o,sd(t),Je("About"),id(t.description||t.summary),Je("Permissions"),od(t),Je("Information"),a),pd(t,n))}function ld(){const e=C.me;jf.replaceChildren(e?f("p",{class:"signed-in"},"Signed in as ",tt(e)):f("p",{class:"signed-in"},C.ready?"No account in this app runtime.":"Loading your account…"));const t=Kr(),n=t.some(s=>s.isDefault),r=t.map(s=>Bn(s,()=>Fe({type:"editStack",d:s.d}),!0));ji.replaceChildren(...r),n||ji.prepend(f("div",{class:"stack-cell"},f("div",{class:"stack-card stack-placeholder"},f("span",{class:"stack-kicker"},"Recommended by you"),f("span",{class:"stack-by"},"Your default stack starts the first time you tap Recommend on an app."))));const i=Gt()&&!!e;Xe.disabled=!i,Lt.disabled=!i||Xe.value.trim()===""}Xe.addEventListener("input",()=>{Lt.disabled=Xe.value.trim()===""||!Gt()});Xr(Xe,Lt,async()=>{const e=Xe.value.trim();if(!e)return;Lt.disabled=!0,Fi.textContent="Waiting for your signature…";const t=await Ao(e);Fi.textContent=Rt(t),t.ok?(Xe.value="",Xt(),t.d&&Fe({type:"editStack",d:t.d})):Lt.disabled=!1});function fd(e){const t=Kr().find(u=>u.d===e),n=se.querySelector(".stack-title-input"),r=n&&document.activeElement===n?n.value:void 0;if(!t){rt(f("div",{class:"detail-top"},nt()),f("div",{class:"detail-scroll"},ce(D.empty,"Stack not found","It was deleted, or has not arrived yet.")));return}const i=f("p",{class:"recommend-note",role:"status","aria-live":"polite"});So(e)&&(i.textContent="Still waiting for your signer. This updates once you approve.");const s=async(u,d)=>{u.disabled=!0,i.textContent="Waiting for your signature…";const l=await d();i.textContent=Rt(l),l.ok||(u.disabled=!1)};let o;if(t.isDefault)o=f("div",{class:"hero-text"},f("p",{class:"hero-kicker"},"Your default stack"),f("h1",{class:"hero-title"},"Recommended by you"),f("p",{class:"hero-sub"},"Tap Recommend on an app to add it here."));else{const u=f("input",{class:"stack-title-input",type:"text",maxlength:"60","aria-label":"Stack name"});u.value=r??t.title;const d=f("button",{class:"btn btn-primary btn-small",type:"button"},"Rename");d.disabled=u.value.trim()===t.title||!u.value.trim(),u.addEventListener("input",()=>{d.disabled=u.value.trim()===t.title||!u.value.trim()});const l=f("div",{class:"new-stack"},u,d);Xr(u,d,()=>void s(d,()=>bf(e,u.value))),o=f("div",{class:"hero-text"},f("p",{class:"hero-kicker"},"App stack"),l),r!==void 0&&queueMicrotask(()=>u.focus())}const a=t.addresses.map(u=>{const d=le.get(u),l=f("button",{class:"btn btn-ghost btn-small",type:"button","aria-label":"Remove from stack"},"Remove");l.addEventListener("click",()=>void s(l,()=>mf(e,u)));const y=d?Yr(f("div",{class:"edit-row-app"},_n(d,"mini"),f("span",{class:"edit-row-title"},d.title)),`Open ${d.title}`,()=>Ro(d.key)):f("div",{class:"edit-row-app"},f("div",{class:"app-icon app-icon-mini sk"}),f("span",{class:"edit-row-title mono"},u.split(":")[2]||"napplet"));return f("li",{class:"edit-row"},y,l)});let c=null;if(!t.isDefault){const u=f("button",{class:"btn btn-danger",type:"button"},"Delete stack");let d=!1;u.addEventListener("click",()=>{if(!d){d=!0,u.textContent="Tap again to delete";return}s(u,async()=>{const l=await gf(e);return l.ok&&Qr(),l})}),c=f("div",{class:"danger-zone"},u)}rt(f("div",{class:"detail-top"},nt()),f("div",{class:"detail-scroll"},f("header",{class:"hero stack-hero"},o),i,Je(`${t.addresses.length} ${t.addresses.length===1?"napplet":"napplets"}`),a.length>0?f("ul",{class:"edit-rows"},...a):ce(D.empty,"Empty stack",'Open an app and tap "Add to stack" to put it here.'),c))}function dd(e){const t=rf(e),n=ko(e).length,r=f("button",{class:`btn btn-recommend${t?" is-on":""}`,type:"button","aria-pressed":String(t)},ot(D.heart,"btn-icon"),t?"Recommended":"Recommend",n>0&&f("span",{class:"count"},String(n))),i=f("p",{class:"recommend-note",role:"status","aria-live":"polite"});Gt()?pf()&&(r.disabled=!0,i.textContent="Still waiting for your signer. This updates once you approve."):(r.disabled=!0,i.textContent="This shell cannot publish recommendations."),r.addEventListener("click",async()=>{r.disabled=!0,i.textContent="Waiting for your signature…";const c=await yf(e);c.ok?Et():c.pending?i.textContent="Still waiting for your signer. This updates once you approve.":(r.disabled=!1,i.textContent=`Could not publish: ${c.error??"unknown error"}`)});const s=Oo(e),o=s.length>0&&f("ul",{class:"recommenders","aria-label":"Recommended by"},...s.map(c=>{const u=f("button",{class:"recommender",type:"button"},Yt(c),f("span",{class:"by-name","data-author":c===C.me?void 0:c},c===C.me?"You":me(c)));return u.addEventListener("click",()=>Fe({type:"person",pubkey:c})),f("li",{},u)})),a=C.ready?s.length===0?C.follows.size>0?"Nobody you follow has recommended this yet.":"Follow people to see who recommends what.":`Recommended by ${s.length} ${s.length===1?"person":"people"} in your community`:"Checking who you follow…";return f("section",{class:"social"},f("div",{class:"social-row"},r,f("p",{class:"social-caption"},a)),i,hd(e),o)}let pn;function hd(e){if(!Gt()||!C.me)return null;const t=pn===e.key,n=f("button",{class:"btn btn-recommend",type:"button","aria-expanded":String(t)},ot(D.stack,"btn-icon"),"Add to stack");if(n.addEventListener("click",()=>{pn=t?void 0:e.key,Et()}),!t)return f("div",{class:"picker"},n);const r=f("p",{class:"recommend-note",role:"status","aria-live":"polite"}),s=Kr().filter(u=>!u.isDefault).map(u=>{const d=u.addresses.includes(e.key),l=f("button",{class:`picker-row${d?" is-on":""}`,type:"button","aria-pressed":String(d)},f("span",{class:"picker-check","aria-hidden":"true"},d?"✓":""),f("span",{},u.title),f("span",{class:"picker-count"},String(u.addresses.length)));return l.addEventListener("click",async()=>{l.disabled=!0,r.textContent="Waiting for your signature…";const y=await wr(u.d,e);r.textContent=Rt(y),l.disabled=!1}),l}),o=f("input",{type:"text",placeholder:"New stack name",maxlength:"60","aria-label":"New stack name"}),a=f("button",{class:"btn btn-primary btn-small",type:"button"},"Create & add"),c=f("div",{class:"new-stack"},o,a);return Xr(o,a,async()=>{const u=o.value.trim();if(!u)return;a.disabled=!0,r.textContent="Waiting for your signature…";const d=await Ao(u);if(!d.ok||!d.d){r.textContent=Rt(d),a.disabled=!1;return}r.textContent="Waiting for your signature to add it…",r.textContent=Rt(await wr(d.d,e))}),f("div",{class:"picker"},n,f("div",{class:"picker-list"},...s,s.length===0&&f("p",{class:"picker-empty"},"No stacks yet. Name one below."),c),r)}function pd(e,t){const n=f("div",{class:"install-bar"}),r=f("p",{class:"install-note",role:"status","aria-live":"polite"});if(!ie("link","open"))return r.append("This shell cannot open installs. Select the address above and paste it into Myco."),n.append(f("button",{class:"btn btn-primary",type:"button",disabled:!0},"Install"),r),n;const i=f("button",{class:"btn btn-primary",type:"button"},ot(D.download,"btn-icon"),"Install");return i.addEventListener("click",async()=>{i.disabled=!0,r.textContent="";try{const s=await Yi(`nostr:${t}`,{label:`Install ${e.title}`});s.status==="opened"?r.textContent="Review and confirm in the install sheet.":r.textContent=Vi(s.error)}catch(s){r.textContent=Vi(String(s))}finally{i.disabled=!1}}),n.append(i,r),n}function Vi(e){switch(e){case"user-denied":return"Install cancelled.";case"unsupported-scheme":return"This shell cannot install napplets from a link.";case"blocked-by-policy":return"This shell does not allow installs from AppStore.";default:return e?`Could not start the install: ${e}`:"Could not start the install."}}Gl(()=>{Xt(),Et()});function yd(){const e=!!window.napplet,t=window.__NAPPLET_ALLOW_STANDALONE__===!0,n=Of();if(!e&&!t){L("#guard").hidden=!1;return}Xt(),Ql(),ff(),ra("mesh")||(z.around={type:"unsupported"}),window.addEventListener("beforeunload",()=>{ef(),n()})}yd();
</script>
    <style>:root{--bg: #ffffff;--text: #0f172a;--primary: #059669;--on-primary: #ffffff;--surface: rgb(245, 246, 246);--surface-2: rgb(236, 236, 238);--border: rgba(15, 23, 42, .12);--muted: rgb(106, 111, 123);--faint: rgb(159, 162, 170);--primary-soft: rgba(5, 150, 105, .15);--primary-ink: rgb(8, 112, 86);--sk-a: rgb(238, 239, 240);--sk-b: rgb(224, 225, 227);--shadow: 0 2px 8px rgba(0, 0, 0, .1);--bg-clear: rgba(255, 255, 255, 0);--text-strong: rgb(51, 58, 74);--text-soft: rgb(63, 69, 85);--text-half: rgb(135, 139, 149);--text-wash: rgba(15, 23, 42, .1);--primary-edge: rgba(5, 150, 105, .6);--primary-edge-soft: rgba(5, 150, 105, .4);--primary-tint: rgba(5, 150, 105, .3);--font-system: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;--font-body: var(--font-system);--font-title: var(--font-body);--mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;--tabbar-h: 64px;color-scheme:light}*,*:before,*:after{box-sizing:border-box}html,body,#app{height:100%}html,body{margin:0;background-color:var(--bg);background-position:center;background-attachment:fixed;color:var(--text);font-family:var(--font-body);font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased;-webkit-tap-highlight-color:transparent}button,input{font:inherit;color:inherit}button{cursor:pointer}:focus-visible{outline:2px solid var(--primary);outline-offset:2px}.mono{font-family:var(--mono);font-size:12px}[hidden]{display:none!important}.app{position:relative;display:flex;flex-direction:column;background:transparent;overflow:hidden}.list-view,.detail-view{flex:1;min-height:0;overflow-y:auto;overscroll-behavior:contain}.app[data-view=detail] .list-view{display:none}.list-view{padding-bottom:16px}.searchbar{position:sticky;top:0;z-index:2;padding:12px 12px 14px;background:linear-gradient(var(--bg) 75%,var(--bg-clear))}.search{display:flex;align-items:center;gap:8px;height:48px;padding:0 8px 0 14px;border-radius:16px;background:var(--surface);border:1px solid var(--border)}.search:focus-within{border-color:var(--primary-edge)}.search-icon svg{display:block;width:20px;height:20px;fill:none;stroke:var(--muted);stroke-width:2;stroke-linecap:round}.search input{flex:1;min-width:0;height:100%;border:0;background:transparent;outline:none;font-size:15px}.search input::placeholder{color:var(--faint)}.search input::-webkit-search-cancel-button{display:none}.search-clear{width:32px;height:32px;border:0;border-radius:10px;background:transparent;color:var(--muted);font-size:20px;line-height:1}.section-header{display:flex;align-items:center;gap:12px;margin:4px 16px 8px;font-size:12px;font-weight:700;letter-spacing:1.5px;text-transform:uppercase;color:var(--text-soft)}.section-header:before,.section-header:after{content:"";flex:1;height:1px;background:var(--border)}.mesh-banner{display:flex;align-items:center;gap:10px;margin:0 12px 14px;padding:10px 14px;border-radius:14px;background:var(--surface);border:1px solid var(--border);color:var(--muted);font-weight:600}.pulse{position:relative;width:10px;height:10px;border-radius:50%;background:var(--faint);flex:none}.mesh-banner[data-live=true]{color:var(--text)}.mesh-banner[data-live=true] .pulse{background:var(--primary)}.mesh-banner[data-live=true] .pulse:after{content:"";position:absolute;top:-4px;right:-4px;bottom:-4px;left:-4px;border-radius:50%;border:2px solid var(--primary);animation:ping 1.8s ease-out infinite}@keyframes ping{0%{transform:scale(.6);opacity:.9}to{transform:scale(1.8);opacity:0}}.cards{list-style:none;margin:0;padding:0}.card{display:flex;gap:14px;width:calc(100% - 24px);margin:2px 12px 8px;padding:16px;border-radius:20px;background:var(--surface);border:1px solid var(--border);text-align:left;transition:background-color .12s ease}.card[role=button]:hover,.card[role=button]:active{background:var(--surface-2)}.card-main{flex:1;min-width:0}.card-title-row{display:flex;flex-wrap:wrap;align-items:baseline;column-gap:6px}.card-title{font-family:var(--font-title);font-size:19px;font-weight:800;line-height:1.25;letter-spacing:-.2px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:100%}.by{display:inline-flex;align-items:center;gap:5px;min-width:0;font-size:13px;color:var(--muted)}.by-name{font-weight:600;color:var(--text-strong);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:14em}.card-summary{margin:10px 0 0;color:var(--muted);line-height:1.5;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.pills{display:flex;flex-wrap:wrap;gap:6px;margin-top:8px}.pill{display:inline-flex;align-items:center;gap:4px;padding:4px 9px;border-radius:8px;background:var(--surface-2);font-size:11px;font-weight:700;color:var(--text-soft)}.pill-nearby{background:var(--primary-soft);color:var(--primary-ink)}.pill-icon{width:12px;height:12px;fill:none;stroke:currentColor;stroke-width:2.2;stroke-linecap:round}.app-icon{--hue: 160;flex:none;display:grid;place-items:center;overflow:hidden;border-radius:14px;box-shadow:var(--shadow);background:linear-gradient(var(--primary-tint),var(--primary-tint)),linear-gradient(135deg,hsl(var(--hue),65%,50%),hsl(calc(var(--hue) + 40),65%,40%));color:#fff}.app-icon.has-image{background:var(--surface-2)}.app-icon img{width:100%;height:100%;object-fit:cover}.app-icon-card{width:clamp(50px,21vw,64px);height:clamp(50px,21vw,64px)}.app-icon-hero{width:80px;height:80px;border-radius:18px}.app-icon-letters{font-family:var(--font-title);font-weight:800;font-size:20px;letter-spacing:.5px}.app-icon-hero .app-icon-letters{font-size:28px}.avatar{--hue: 200;flex:none;display:inline-grid;place-items:center;width:20px;height:20px;border-radius:50%;overflow:hidden;background:hsl(var(--hue) 45% 45%);color:#fff;font-size:8px;font-weight:800}.avatar img{width:100%;height:100%;object-fit:cover}.sk{background:linear-gradient(90deg,var(--sk-a),var(--sk-b),var(--sk-a));background-size:200% 100%;animation:shimmer 1s linear infinite;box-shadow:none}@keyframes shimmer{0%{background-position:200% 0}to{background-position:0 0}}.skeleton .sk-title{width:min(180px,70%);height:20px;border-radius:4px}.skeleton .sk-pill{width:60px;height:20px;margin-top:8px;border-radius:8px}.skeleton .sk-line{height:14px;margin-top:10px;border-radius:4px}.skeleton .sk-line.short{width:60%;margin-top:6px}.state{padding:24px 16px}.empty{display:flex;flex-direction:column;align-items:center;text-align:center;gap:8px;padding:24px 12px;color:var(--muted)}.empty strong{color:var(--text);font-family:var(--font-title);font-size:18px}.empty p{margin:0;max-width:32em}.empty-icon{width:48px;height:48px;margin-bottom:8px;fill:none;stroke:var(--faint);stroke-width:1.6;stroke-linecap:round}.tabbar{flex:none;display:flex;justify-content:space-around;align-items:center;height:calc(var(--tabbar-h) + env(safe-area-inset-bottom,0px));padding-bottom:env(safe-area-inset-bottom,0px);background:linear-gradient(var(--bg),var(--surface));border-top:1px solid var(--border)}.app[data-view=detail] .tabbar{display:none}.tab{position:relative;display:flex;flex-direction:column;align-items:center;gap:2px;min-width:96px;padding:6px 8px;border:0;background:transparent;color:var(--text-half);font-size:11px;font-weight:700}.tab-pill{display:grid;place-items:center;width:60px;height:32px;border-radius:16px;transition:background-color .15s ease}.tab svg{width:24px;height:24px;fill:none;stroke:currentColor;stroke-width:1.9;stroke-linecap:round;stroke-linejoin:round}.tab[aria-selected=true]{color:var(--primary)}.tab[aria-selected=true] .tab-pill{background:var(--primary-soft)}.badge{position:absolute;top:2px;left:calc(50% + 12px);min-width:18px;height:18px;padding:0 5px;border-radius:9px;background:var(--primary);color:var(--on-primary);font-size:10px;line-height:18px;text-align:center}.detail-view{display:flex;flex-direction:column;overflow:hidden}.detail-top{flex:none;padding:8px 8px 0}.back{display:inline-flex;align-items:center;gap:2px;height:36px;padding:0 12px 0 6px;border:0;border-radius:12px;background:transparent;font-weight:600;color:var(--muted)}.back .icon{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:2.2;stroke-linecap:round;stroke-linejoin:round}.detail-scroll{flex:1;min-height:0;overflow-y:auto;padding:8px 0 24px}.hero{display:flex;align-items:center;gap:16px;padding:0 16px}.hero-text{min-width:0}.hero-title{margin:0;font-family:var(--font-title);font-size:clamp(20px,6.5vw,28px);font-weight:800;line-height:1.15;letter-spacing:-.3px;overflow-wrap:anywhere;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.author-row{display:flex;align-items:center;gap:6px;margin:16px 16px 8px;color:var(--muted)}.shots-section{padding:8px 0}.shots{display:flex;gap:8px;overflow-x:auto;padding:0 16px;scroll-snap-type:x mandatory;scrollbar-width:none}.shots::-webkit-scrollbar{display:none}.shot{flex:none;width:120px;height:214px;border-radius:10px;overflow:hidden;background:var(--surface-2);scroll-snap-align:start}.shot img{width:100%;height:100%;object-fit:cover}.detail-scroll .section-header{margin-top:20px}.description-wrap{position:relative}.description{padding:0 20px;font-size:15px;line-height:1.6;overflow-wrap:anywhere}.description p{margin:0 0 10px;white-space:pre-line}.description.collapsed{max-height:170px;overflow:hidden;mask-image:linear-gradient(#000 70%,transparent);-webkit-mask-image:linear-gradient(#000 70%,transparent)}.read-more{display:block;margin:4px auto 0;padding:6px 12px;border:0;border-radius:12px;background:var(--surface-2);font-size:12px;font-weight:600}.perms{list-style:none;margin:0 16px;padding:4px 16px;border-radius:12px;background:var(--surface);border:1px solid var(--border)}.perm{display:flex;gap:12px;align-items:flex-start;padding:10px 0}.perm+.perm{border-top:1px solid var(--border)}.perm strong{display:block;font-size:14px}.perm p{margin:2px 0 0;color:var(--muted);font-size:13px}.perm-tag{flex:none;min-width:64px;padding:2px 8px;border-radius:6px;background:var(--surface-2);text-align:center;font-size:11px}.perm-notable .perm-tag{background:var(--primary-soft);color:var(--primary-ink)}.info-table{margin:0 16px;padding:4px 16px;border-radius:12px;background:var(--surface);border:1px solid var(--border)}.info-row{display:flex;justify-content:space-between;gap:16px;padding:9px 0}.info-row+.info-row{border-top:1px solid var(--border)}.info-row dt{flex:none;color:var(--muted)}.info-row dd{margin:0;min-width:0;text-align:right;overflow-wrap:anywhere}.selectable{display:inline-block;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;vertical-align:bottom;cursor:text;user-select:all;-webkit-user-select:all}.selectable:focus{white-space:normal;overflow-wrap:anywhere}.install-bar{flex:none;padding:12px 16px calc(12px + env(safe-area-inset-bottom,0px));background:linear-gradient(var(--bg-clear),var(--bg) 30%);border-top:1px solid var(--border)}.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;height:48px;padding:0 24px;border:0;border-radius:12px;font-size:16px;font-weight:700}.btn-primary{width:100%;background:var(--primary);color:var(--on-primary)}.btn-primary:disabled{opacity:.55;cursor:default}.btn-ghost{height:36px;margin-top:8px;padding:0 16px;font-size:13px;background:var(--surface-2)}.btn-icon{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:2.2;stroke-linecap:round;stroke-linejoin:round}.install-note{margin:8px 0 0;min-height:1em;text-align:center;font-size:12px;color:var(--muted)}.install-note:empty{display:none}.guard{position:fixed;top:0;right:0;bottom:0;left:0;display:grid;place-items:center;padding:16px;background:var(--bg)}.guard-card{max-width:320px;padding:20px;border-radius:16px;background:var(--surface);border:1px solid var(--border);text-align:center}.guard-card p{margin:8px 0 0;color:var(--muted)}@media(min-width:720px){.list-view,.detail-scroll,.detail-top{padding-left:calc((100% - 720px)/2);padding-right:calc((100% - 720px)/2)}.install-bar{display:flex;flex-direction:column;align-items:center}.install-bar .btn-primary{max-width:480px}}@media(max-width:300px){.card{padding:12px;gap:10px}.by,.tab-label{display:none}.card-summary{-webkit-line-clamp:1}}@media(prefers-reduced-motion:reduce){.sk,.mesh-banner[data-live=true] .pulse:after{animation:none}}.proof{display:flex;align-items:center;gap:8px;margin-top:10px;font-size:12px;color:var(--muted);min-width:0}.proof-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.proof-name{font-weight:700;color:var(--text-strong)}.avatar-stack{display:inline-flex;flex:none}.avatar-stack .avatar{box-shadow:0 0 0 2px var(--surface)}.avatar-stack .avatar+.avatar{margin-left:-6px}.social{margin:12px 16px 4px}.social-row{display:flex;align-items:center;gap:12px}.btn-recommend{flex:none;height:40px;padding:0 14px;font-size:14px;border-radius:12px;background:var(--surface-2);color:var(--text);border:1px solid var(--border)}.btn-recommend.is-on{background:var(--primary-soft);color:var(--primary-ink);border-color:var(--primary-edge-soft)}.btn-recommend.is-on .btn-icon{fill:currentColor}.btn-recommend:disabled{opacity:.6;cursor:default}.btn-recommend .btn-icon{width:18px;height:18px}.btn-recommend .count{min-width:20px;padding:0 6px;border-radius:10px;background:var(--text-wash);font-size:12px;line-height:20px}.social-caption{margin:0;font-size:13px;color:var(--muted);line-height:1.35}.recommend-note{margin:6px 0 0;font-size:12px;color:var(--muted)}.recommend-note:empty{display:none}.recommenders{list-style:none;display:flex;flex-wrap:wrap;gap:6px;margin:10px 0 0;padding:0}.recommender{display:inline-flex;align-items:center;gap:6px;padding:4px 10px 4px 4px;border-radius:999px;background:var(--surface);border:1px solid var(--border);font-size:13px}.avatar-md{width:52px;height:52px;font-size:16px}.avatar-lg{width:80px;height:80px;font-size:24px}.person-hero .avatar-lg{flex:none}.hero-kicker{margin:0 0 2px;font-size:12px;font-weight:700;letter-spacing:1px;text-transform:uppercase;color:var(--muted)}.person-pending{margin:8px 16px;text-align:center;color:var(--muted);font-size:13px}button.recommender{font:inherit;color:inherit;cursor:pointer}button.recommender:active{background:var(--surface-2)}#stacksRow{margin:0 0 12px}.stacks{display:grid;grid-auto-flow:column;grid-template-rows:repeat(2,auto);grid-auto-columns:160px;gap:10px;padding:2px 12px 4px;overflow-x:auto;scroll-snap-type:x proximity;scrollbar-width:none}.stacks::-webkit-scrollbar{display:none}.stacks-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:10px;padding:8px 16px}.stack-card{display:flex;flex-direction:column;justify-content:space-between;gap:8px;min-width:0;min-height:108px;padding:12px;border-radius:14px;border:1px solid var(--border);background:var(--surface);text-align:left;scroll-snap-align:start}.stack-card:active{background:var(--surface-2)}.stack-title{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;font-family:var(--font-title);font-size:15px;font-weight:700;line-height:1.25}.stack-kicker{display:block;margin-bottom:4px;font-size:11px;font-weight:700;letter-spacing:.4px;text-transform:uppercase;color:var(--muted)}.stack-person{display:flex;align-items:center;gap:6px;min-width:0}.stack-person .stack-title{-webkit-line-clamp:1}.stack-by{display:flex;align-items:center;gap:5px;min-width:0;margin-top:3px;font-size:12px;color:var(--muted)}.stack-tiles{display:flex;gap:6px}.app-icon-mini{width:29px;height:29px;border-radius:9px;box-shadow:none}.app-icon-mini .app-icon-letters{font-size:12px}.stack-more{background:var(--surface-2);color:var(--text);font-size:11px;font-weight:800}.stack-see-more{justify-content:center;align-items:flex-start;color:var(--primary);font-weight:800;font-size:15px}.stack-see-more .stack-by{color:var(--muted);font-weight:600}.stack-description{margin:12px 20px 0;color:var(--muted);font-size:14px;line-height:1.5;white-space:pre-line}.stack-hero .stack-by{margin:4px 0 0;font-size:13px}.author-link{display:inline-flex;align-items:center;gap:5px;min-width:0;max-width:100%;padding:0;border:0;background:transparent;color:inherit;font:inherit;cursor:pointer}.author-link:hover .by-name,.author-link.proof-name:hover{text-decoration:underline}.proof-name.author-link{display:inline;font-weight:700;color:var(--text-strong)}.card[role=button],.stack-card[role=button]{cursor:pointer}.stack-cell{display:flex;min-width:0}.stack-cell>.stack-card{flex:1}.stack-person.stack-title .by-name{font-weight:700;font-size:15px;color:var(--text)}.stack-placeholder{justify-content:flex-start;border-style:dashed;background:transparent}.app[data-tab=profile] .searchbar{display:none}#panel-profile{padding-top:12px}.profile-header{margin:4px 16px 12px}.page-title{margin:0;font-family:var(--font-title);font-size:clamp(22px,6.5vw,28px);font-weight:800;line-height:1.15;letter-spacing:-.3px}.signed-in{display:flex;align-items:center;gap:6px;margin:4px 0 0;color:var(--muted);font-size:13px}.signed-in .by-name{font-weight:700;color:var(--text-strong)}.hero-sub{margin:2px 0 0;color:var(--muted);font-size:13px}.profile-note{margin:8px 16px;color:var(--muted);font-size:13px}.profile-note:empty{display:none}.new-stack{display:flex;gap:8px;margin:8px 16px}.new-stack input{flex:1;min-width:0;height:40px;padding:0 12px;border-radius:12px;border:1px solid var(--border);background:var(--surface);outline:none}.new-stack input:focus{border-color:var(--primary-edge)}.btn-small{width:auto;height:40px;padding:0 14px;font-size:14px}.btn-small.btn-primary{width:auto}.btn-danger{width:100%;background:#ef444424;color:#ef4444}.danger-zone{margin:24px 16px 8px}.stack-title-input{width:100%;font-family:var(--font-title);font-size:20px!important;font-weight:800}.stack-hero .hero-text{flex:1;min-width:0}.stack-hero .new-stack{margin:4px 0 0}.edit-rows{list-style:none;margin:0 16px;padding:4px 12px;border-radius:12px;border:1px solid var(--border);background:var(--surface)}.edit-row{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:8px 0}.edit-row+.edit-row{border-top:1px solid var(--border)}.edit-row-app{display:flex;align-items:center;gap:10px;min-width:0}.edit-row-title{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600}.edit-row .btn-ghost{margin-top:0;height:32px}.picker{margin-top:10px}.picker-list{margin-top:8px;padding:6px;border-radius:12px;border:1px solid var(--border);background:var(--surface)}.picker-row{display:flex;align-items:center;gap:10px;width:100%;padding:10px 8px;border:0;border-radius:10px;background:transparent;text-align:left;font-weight:600}.picker-row:active,.picker-row.is-on{background:var(--primary-soft)}.picker-check{display:grid;place-items:center;width:20px;height:20px;border-radius:6px;border:1.5px solid var(--border);color:var(--primary-ink);font-size:13px;font-weight:800}.picker-row.is-on .picker-check{border-color:var(--primary);background:var(--primary-soft)}.picker-count{margin-left:auto;color:var(--muted);font-size:12px}.picker-empty{margin:6px 8px;color:var(--muted);font-size:13px}.picker .new-stack{margin:6px 0 2px}.steps{margin:4px 0 0;padding-left:1.4em;text-align:left;max-width:28em;line-height:1.7}.empty .btn-small{margin-top:12px}.selectable-url{user-select:all;-webkit-user-select:all}.steps strong{font-family:inherit;font-size:inherit;color:var(--text)}
</style>
  </head>
  <body>
    <!--
      The runtime shows the napplet's name, so there is no masthead: the frame
      opens on the search bar. Two views share the surface — the list (Feed /
      Around you) and an app's detail page — switched by `data-view` on #app.
    -->
    <main id="app" class="app" data-view="list" data-tab="feed">
      <section class="list-view" aria-label="Apps">
        <div class="searchbar">
          <label class="search">
            <span class="search-icon" aria-hidden="true">
              <svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7" /><path d="m20 20-3.5-3.5" /></svg>
            </span>
            <input id="search" type="search" placeholder="Search napplets" autocomplete="off" spellcheck="false" />
            <button id="searchClear" class="search-clear" type="button" aria-label="Clear search" hidden>×</button>
          </label>
        </div>

        <div id="panel-feed" class="panel" role="tabpanel" aria-labelledby="tab-feed">
          <section id="communitySection" aria-label="Recommended by your community" hidden>
            <h2 class="section-header"><span>Recommended by your community</span></h2>
            <div id="stacksRow" class="stacks" role="list" aria-label="App stacks" hidden></div>
          </section>
          <h2 class="section-header"><span>Latest napplets</span></h2>
          <ul id="feedList" class="cards" aria-live="polite"></ul>
          <div id="feedState" class="state" hidden></div>
        </div>

        <div id="panel-around" class="panel" role="tabpanel" aria-labelledby="tab-around" hidden>
          <div id="meshBanner" class="mesh-banner">
            <span class="pulse" aria-hidden="true"></span>
            <span id="meshStatus">Looking around…</span>
          </div>
          <h2 class="section-header"><span>Held nearby</span></h2>
          <ul id="aroundList" class="cards" aria-live="polite"></ul>
          <div id="aroundState" class="state" hidden></div>
        </div>
        <div id="panel-profile" class="panel" role="tabpanel" aria-labelledby="tab-profile" aria-label="My stacks" hidden>
          <div class="profile-header">
            <h1 class="page-title">My stacks</h1>
            <div id="profileHeader"></div>
          </div>
          <div id="myStacks" class="stacks-grid" role="list"></div>
          <!-- No <form>: the napplet frame is sandboxed without allow-forms, so a
               form submit is blocked and never fires. Button + Enter instead. -->
          <div class="new-stack">
            <input id="newStackTitle" type="text" placeholder="New stack name" maxlength="60" autocomplete="off" enterkeyhint="done" aria-label="New stack name" />
            <button id="newStackButton" type="button" class="btn btn-primary btn-small">Create</button>
          </div>
          <p id="profileNote" class="profile-note" role="status" aria-live="polite"></p>
        </div>
      </section>

      <section id="detail" class="detail-view" aria-label="App details" hidden></section>

      <nav class="tabbar" role="tablist" aria-label="Sections">
        <button id="tab-feed" class="tab" type="button" role="tab" aria-selected="true" aria-controls="panel-feed" data-tab="feed">
          <span class="tab-pill" aria-hidden="true">
            <svg viewBox="0 0 24 24"><rect x="3.5" y="3.5" width="7" height="7" rx="2" /><rect x="13.5" y="3.5" width="7" height="7" rx="2" /><rect x="3.5" y="13.5" width="7" height="7" rx="2" /><rect x="13.5" y="13.5" width="7" height="7" rx="2" /></svg>
          </span>
          <span class="tab-label">Feed</span>
        </button>
        <button id="tab-around" class="tab" type="button" role="tab" aria-selected="false" aria-controls="panel-around" data-tab="around">
          <span class="tab-pill" aria-hidden="true">
            <svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="2.2" /><path d="M7.8 7.8a6 6 0 0 0 0 8.4M16.2 7.8a6 6 0 0 1 0 8.4M4.9 4.9a10 10 0 0 0 0 14.2M19.1 4.9a10 10 0 0 1 0 14.2" /></svg>
          </span>
          <span class="tab-label">Around you</span>
          <span id="aroundBadge" class="badge" hidden></span>
        </button>
        <button id="tab-profile" class="tab" type="button" role="tab" aria-selected="false" aria-controls="panel-profile" data-tab="profile">
          <span class="tab-pill" aria-hidden="true">
            <svg viewBox="0 0 24 24"><path d="M12 3 3 7.5 12 12l9-4.5L12 3zM3 12l9 4.5 9-4.5M3 16.5 12 21l9-4.5" /></svg>
          </span>
          <span class="tab-label">My stacks</span>
        </button>
      </nav>
    </main>

    <div id="guard" class="guard" role="alert" hidden>
      <div class="guard-card">
        <strong>Needs a napplet runtime</strong>
        <p>AppStore runs inside a napplet shell such as Myco. Open it from there.</p>
      </div>
    </div>

  </body>
</html>