From ebb11686d560c74d418243002c87ef7381ab41f0 Mon Sep 17 00:00:00 2001 From: mleku Date: Mon, 27 Oct 2025 11:59:54 +0000 Subject: [PATCH] Update Role-Based Permissions and Increment Version - Modified role-based permissions in App.svelte and EventsView.svelte to include "read" access for viewing events, enhancing user access control. - Updated conditional rendering logic to reflect the new permission structure, ensuring users with "read", "write", "admin", or "owner" roles can view events. - Incremented the version number to v0.19.4 to reflect these changes. --- app/web/dist/bundle.js | 2 +- app/web/dist/bundle.js.map | 2 +- app/web/src/App.svelte | 3 ++- app/web/src/EventsView.svelte | 6 +++--- pkg/version/version | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/web/dist/bundle.js b/app/web/dist/bundle.js index df7255d..6bef67f 100644 --- a/app/web/dist/bundle.js +++ b/app/web/dist/bundle.js @@ -18,5 +18,5 @@ Object.defineProperty(e,"__esModule",{value:!0}),e.bytes=e.stringToBytes=e.str=e /*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */ const rf=BigInt(0),of=BigInt(1),sf=BigInt(2),af=BigInt(3),cf=BigInt(8),lf=Object.freeze({a:rf,b:BigInt(7),P:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:of,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee")}),uf=(e,t)=>(e+t/sf)/t,df={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar(e){const{n:t}=lf,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-of*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=n,s=BigInt("0x100000000000000000000000000000000"),a=uf(i*e,t),c=uf(-r*e,t);let l=jf(e-a*n-c*o,t),u=jf(-a*r-c*i,t);const d=l>s,f=u>s;if(d&&(l=t-l),f&&(u=t-u),l>s||u>s)throw new Error("splitScalarEndo: Endomorphism failed, k="+e);return{k1neg:d,k1:l,k2neg:f,k2:u}}},ff=32;function hf(e){const{a:t,b:n}=lf,r=jf(e*e),o=jf(r*e);return jf(o+t*e+n)}const pf=lf.a===rf;function gf(e){if(!(e instanceof yf))throw new TypeError("JacobianPoint expected")}class yf{constructor(e,t,n){this.x=e,this.y=t,this.z=n}static fromAffine(e){if(!(e instanceof wf))throw new TypeError("JacobianPoint#fromAffine: expected Point");return e.equals(wf.ZERO)?yf.ZERO:new yf(e.x,e.y,of)}static toAffineBatch(e){const t=function(e,t=lf.P){const n=new Array(e.length),r=e.reduce((e,r,o)=>r===rf?e:(n[o]=e,jf(e*r,t)),of),o=Uf(r,t);return e.reduceRight((e,r,o)=>r===rf?e:(n[o]=jf(e*n[o],t),jf(e*r,t)),o),n}(e.map(e=>e.z));return e.map((e,n)=>e.toAffine(t[n]))}static normalizeZ(e){return yf.toAffineBatch(e).map(yf.fromAffine)}equals(e){gf(e);const{x:t,y:n,z:r}=this,{x:o,y:i,z:s}=e,a=jf(r*r),c=jf(s*s),l=jf(t*c),u=jf(o*a),d=jf(jf(n*s)*c),f=jf(jf(i*r)*a);return l===u&&d===f}negate(){return new yf(this.x,jf(-this.y),this.z)}double(){const{x:e,y:t,z:n}=this,r=jf(e*e),o=jf(t*t),i=jf(o*o),s=e+o,a=jf(sf*(jf(s*s)-r-i)),c=jf(af*r),l=jf(c*c),u=jf(l-sf*a),d=jf(c*(a-u)-cf*i),f=jf(sf*t*n);return new yf(u,d,f)}add(e){gf(e);const{x:t,y:n,z:r}=this,{x:o,y:i,z:s}=e;if(o===rf||i===rf)return this;if(t===rf||n===rf)return e;const a=jf(r*r),c=jf(s*s),l=jf(t*c),u=jf(o*a),d=jf(jf(n*s)*c),f=jf(jf(i*r)*a),h=jf(u-l),p=jf(f-d);if(h===rf)return p===rf?this.double():yf.ZERO;const g=jf(h*h),y=jf(h*g),v=jf(l*g),m=jf(p*p-y-sf*v),w=jf(p*(v-m)-d*y),b=jf(r*s*h);return new yf(m,w,b)}subtract(e){return this.add(e.negate())}multiplyUnsafe(e){const t=yf.ZERO;if("bigint"==typeof e&&e===rf)return t;let n=Bf(e);if(n===of)return this;if(!pf){let e=t,r=this;for(;n>rf;)n&of&&(e=e.add(r)),r=r.double(),n>>=of;return e}let{k1neg:r,k1:o,k2neg:i,k2:s}=df.splitScalar(n),a=t,c=t,l=this;for(;o>rf||s>rf;)o&of&&(a=a.add(l)),s&of&&(c=c.add(l)),l=l.double(),o>>=of,s>>=of;return r&&(a=a.negate()),i&&(c=c.negate()),c=new yf(jf(c.x*df.beta),c.y,c.z),a.add(c)}precomputeWindow(e){const t=pf?128/e+1:256/e+1,n=[];let r=this,o=r;for(let i=0;i>=u,s>a&&(s-=l,e+=of);const d=n,f=n+Math.abs(s)-1,h=t%2!=0,p=s<0;0===s?i=i.add(vf(h,r[d])):o=o.add(vf(p,r[f]))}return{p:o,f:i}}multiply(e,t){let n,r,o=Bf(e);if(pf){const{k1neg:e,k1:i,k2neg:s,k2:a}=df.splitScalar(o);let{p:c,f:l}=this.wNAF(i,t),{p:u,f:d}=this.wNAF(a,t);c=vf(e,c),u=vf(s,u),u=new yf(jf(u.x*df.beta),u.y,u.z),n=c.add(u),r=l.add(d)}else{const{p:e,f:i}=this.wNAF(o,t);n=e,r=i}return yf.normalizeZ([n,r])[0]}toAffine(e){const{x:t,y:n,z:r}=this,o=this.equals(yf.ZERO);null==e&&(e=o?cf:Uf(r));const i=e,s=jf(i*i),a=jf(s*i),c=jf(t*s),l=jf(n*a),u=jf(r*i);if(o)return wf.ZERO;if(u!==of)throw new Error("invZ was invalid");return new wf(c,l)}}function vf(e,t){const n=t.negate();return e?n:t}yf.BASE=new yf(lf.Gx,lf.Gy,of),yf.ZERO=new yf(rf,of,rf);const mf=new WeakMap;class wf{constructor(e,t){this.x=e,this.y=t}_setWindowSize(e){this._WINDOW_SIZE=e,mf.delete(this)}hasEvenY(){return this.y%sf===rf}static fromCompressedHex(e){const t=32===e.length,n=Lf(t?e:e.subarray(1));if(!Ff(n))throw new Error("Point is not on curve");let r=function(e){const{P:t}=lf,n=BigInt(6),r=BigInt(11),o=BigInt(22),i=BigInt(23),s=BigInt(44),a=BigInt(88),c=e*e*e%t,l=c*c*e%t,u=Nf(l,af)*l%t,d=Nf(u,af)*l%t,f=Nf(d,sf)*c%t,h=Nf(f,r)*f%t,p=Nf(h,o)*h%t,g=Nf(p,s)*p%t,y=Nf(g,a)*g%t,v=Nf(y,s)*p%t,m=Nf(v,af)*l%t,w=Nf(m,i)*h%t,b=Nf(w,n)*c%t,E=Nf(b,sf);if(E*E%t!==e)throw new Error("Cannot find square root");return E}(hf(n));const o=(r&of)===of;if(t)o&&(r=jf(-r));else{!(1&~e[0])!==o&&(r=jf(-r))}const i=new wf(n,r);return i.assertValidity(),i}static fromUncompressedHex(e){const t=Lf(e.subarray(1,33)),n=Lf(e.subarray(33,65)),r=new wf(t,n);return r.assertValidity(),r}static fromHex(e){const t=Pf(e),n=t.length,r=t[0];if(n===ff)return this.fromCompressedHex(t);if(33===n&&(2===r||3===r))return this.fromCompressedHex(t);if(65===n&&4===r)return this.fromUncompressedHex(t);throw new Error(`Point.fromHex: received invalid point. Expected 32-33 compressed bytes or 65 uncompressed bytes, not ${n}`)}static fromPrivateKey(e){return wf.BASE.multiply(function(e){let t;if("bigint"==typeof e)t=e;else if("number"==typeof e&&Number.isSafeInteger(e)&&e>0)t=BigInt(e);else if("string"==typeof e){if(64!==e.length)throw new Error("Expected 32 bytes of private key");t=Of(e)}else{if(!xf(e))throw new TypeError("Expected valid private key");if(32!==e.length)throw new Error("Expected 32 bytes of private key");t=Lf(e)}if(!Mf(t))throw new Error("Expected private key: 0 < key < n");return t}(e))}static fromSignature(e,t,n){const{r:r,s:o}=function(e){if(e instanceof kf)return e.assertValidity(),e;try{return kf.fromDER(e)}catch(t){return kf.fromCompact(e)}}(t);if(![0,1,2,3].includes(n))throw new Error("Cannot recover: invalid recovery bit");const i=function(e,t=!1){const n=function(e){const t=8*e.length-256,n=Lf(e);return t>0?n>>BigInt(t):n}(e);if(t)return n;const{n:r}=lf;return n>=r?n-r:n}(Pf(e)),{n:s}=lf,a=2===n||3===n?r+s:r,c=Uf(a,s),l=jf(-i*c,s),u=jf(o*c,s),d=1&n?"03":"02",f=wf.fromHex(d+_f(a)),h=wf.BASE.multiplyAndAddUnsafe(f,l,u);if(!h)throw new Error("Cannot recover signature: point at infinify");return h.assertValidity(),h}toRawBytes(e=!1){return Tf(this.toHex(e))}toHex(e=!1){const t=_f(this.x);if(e){return`${this.hasEvenY()?"02":"03"}${t}`}return`04${t}${_f(this.y)}`}toHexX(){return this.toHex(!0).slice(2)}toRawX(){return this.toRawBytes(!0).slice(1)}assertValidity(){const e="Point is not on elliptic curve",{x:t,y:n}=this;if(!Ff(t)||!Ff(n))throw new Error(e);const r=jf(n*n);if(jf(r-hf(t))!==rf)throw new Error(e)}equals(e){return this.x===e.x&&this.y===e.y}negate(){return new wf(this.x,jf(-this.y))}double(){return yf.fromAffine(this).double().toAffine()}add(e){return yf.fromAffine(this).add(yf.fromAffine(e)).toAffine()}subtract(e){return this.add(e.negate())}multiply(e){return yf.fromAffine(this).multiply(e,this).toAffine()}multiplyAndAddUnsafe(e,t,n){const r=yf.fromAffine(this),o=t===rf||t===of||this!==wf.BASE?r.multiplyUnsafe(t):r.multiply(t),i=yf.fromAffine(e).multiplyUnsafe(n),s=o.add(i);return s.equals(yf.ZERO)?void 0:s.toAffine()}}function bf(e){return Number.parseInt(e[0],16)>=8?"00"+e:e}function Ef(e){if(e.length<2||2!==e[0])throw new Error(`Invalid signature integer tag: ${Cf(e)}`);const t=e[1],n=e.subarray(2,t+2);if(!t||n.length!==t)throw new Error("Invalid signature integer: wrong length");if(0===n[0]&&n[1]<=127)throw new Error("Invalid signature integer: trailing length");return{data:Lf(n),left:e.subarray(t+2)}}wf.BASE=new wf(lf.Gx,lf.Gy),wf.ZERO=new wf(rf,rf);class kf{constructor(e,t){this.r=e,this.s=t,this.assertValidity()}static fromCompact(e){const t=xf(e),n="Signature.fromCompact";if("string"!=typeof e&&!t)throw new TypeError(`${n}: Expected string or Uint8Array`);const r=t?Cf(e):e;if(128!==r.length)throw new Error(`${n}: Expected 64-byte hex`);return new kf(Of(r.slice(0,64)),Of(r.slice(64,128)))}static fromDER(e){const t=xf(e);if("string"!=typeof e&&!t)throw new TypeError("Signature.fromDER: Expected string or Uint8Array");const{r:n,s:r}=function(e){if(e.length<2||48!=e[0])throw new Error(`Invalid signature tag: ${Cf(e)}`);if(e[1]!==e.length-2)throw new Error("Invalid signature: incorrect length");const{data:t,left:n}=Ef(e.subarray(2)),{data:r,left:o}=Ef(n);if(o.length)throw new Error(`Invalid signature: left bytes after parsing: ${Cf(o)}`);return{r:t,s:r}}(t?e:Tf(e));return new kf(n,r)}static fromHex(e){return this.fromDER(e)}assertValidity(){const{r:e,s:t}=this;if(!Mf(e))throw new Error("Invalid Signature: r must be 0 < r < n");if(!Mf(t))throw new Error("Invalid Signature: s must be 0 < s < n")}hasHighS(){const e=lf.n>>of;return this.s>e}normalizeS(){return this.hasHighS()?new kf(this.r,jf(-this.s,lf.n)):this}toDERRawBytes(){return Tf(this.toDERHex())}toDERHex(){const e=bf(Rf(this.s)),t=bf(Rf(this.r)),n=e.length/2,r=t.length/2,o=Rf(n),i=Rf(r);return`30${Rf(r+n+4)}02${i}${t}02${o}${e}`}toRawBytes(){return this.toDERRawBytes()}toHex(){return this.toDERHex()}toCompactRawBytes(){return Tf(this.toCompactHex())}toCompactHex(){return _f(this.r)+_f(this.s)}}function xf(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}const Sf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Cf(e){!function(e){if(!xf(e))throw new Error("Uint8Array expected")}(e);let t="";for(let n=0;n=Af._0&&e<=Af._9?e-Af._0:e>=Af.A&&e<=Af.F?e-(Af.A-10):e>=Af.a&&e<=Af.f?e-(Af.a-10):void 0}function Tf(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,o=0;t0)return BigInt(e);if("bigint"==typeof e&&Mf(e))return e;throw new TypeError("Expected valid private scalar: 0 < scalar < curve.n")}function jf(e,t=lf.P){const n=e%t;return n>=rf?n:t+n}function Nf(e,t){const{P:n}=lf;let r=e;for(;t-- >rf;)r*=r,r%=n;return r}function Uf(e,t=lf.P){if(e===rf||t<=rf)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let n=jf(e,t),r=t,o=rf,i=of;for(;n!==rf;){const e=r%n,t=o-i*(r/n);r=n,n=e,o=i,i=t}if(r!==of)throw new Error("invert: does not exist");return jf(o,t)}function Mf(e){return rf"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function qf(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function zf(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Kf(e){if(!Array.isArray(e))throw new Error("array expected")}function Wf(e,t){if(!Hf(!0,t))throw new Error(`${e}: array of strings expected`)}wf.BASE._setWindowSize(8);const Vf=(e,t)=>0===t?e:Vf(t,e%t),Jf=(e,t)=>e+(t-Vf(e,t)),Gf=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Zf(e,t,n,r){if(Kf(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(Jf(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${Jf(t,n)}`);let o=0,i=0;const s=Gf[t],a=Gf[n]-1,c=[];for(const r of e){if(zf(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(o=o<32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${t}`);for(i+=t;i>=n;i-=n)c.push((o>>i-n&a)>>>0);const e=Gf[i];if(void 0===e)throw new Error("invalid carry");o&=e-1}if(o=o<=t)throw new Error("Excess padding");if(!r&&o>0)throw new Error(`Non-zero padding: ${o}`);return r&&i>0&&c.push(o>>>0),c}const Qf=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(function(e,...t){if(!Df(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}(e),e.toBase64()),decode:e=>((e,t)=>{qf("base64",e);const n=t?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,r=t?"base64url":"base64";if(e.length>0&&!n.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:r,lastChunkHandling:"strict"})})(e,!1)}:function(...e){const t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}(function(e,t=!1){if(zf(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Jf(8,e)>32||Jf(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!Df(n))throw new Error("radix2.encode input should be Uint8Array");return Zf(Array.from(n),8,e,!t)},decode:n=>(function(e,t){if(!Hf(!1,t))throw new Error(`${e}: array of numbers expected`)}("radix2.decode",n),Uint8Array.from(Zf(n,e,8,t)))}}(6),function(e){const t="string"==typeof e?e.split(""):e,n=t.length;Wf("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(Kf(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(Kf(t),t.map(t=>{qf("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),function(e,t="="){return zf(e),qf("padding",t),{encode(n){for(Wf("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){Wf("padding.decode",n);let r=n.length;if(r*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--){if((r-1)*e%8==0)throw new Error("padding: invalid, string has too much padding")}return n.slice(0,r)}}}(6),function(e=""){return qf("join",e),{encode:t=>(Wf("join.decode",t),t.join(e)),decode:t=>(qf("join.decode",t),t.split(e))}}(""));function Yf(e){return wf.fromHex(e).toHex().substring(2)}const Xf=new TextDecoder("utf-8"),eh=new TextEncoder;class th{log=Vu.extend("SerialPortSigner");writer=null;pubkey;get isConnected(){return!!this.writer}verifyEvent=ao;nip04;constructor(){this.nip04={encrypt:this.nip04Encrypt.bind(this),decrypt:this.nip04Decrypt.bind(this)}}lastCommand=null;async callMethodOnDevice(e,t,n={}){if(!th.SUPPORTED)throw new Error("Serial devices are not supported");if(this.writer||await this.connectToDevice(n),this.lastCommand)throw new Error("Previous command to device still pending!");const r=Fd();return this.lastCommand=r,this.sendCommand(e,t),setTimeout(()=>{r.reject(new Error("Device timeout")),this.lastCommand===r&&(this.lastCommand=null)},6e3),this.lastCommand}async connectToDevice({onConnect:e,onDisconnect:t,onError:n,onDone:r}){let o,i=await window.navigator.serial.requestPort();await i.open({baudRate:9600}),await(e=>new Promise(t=>setTimeout(t,e)))(1e3),(async()=>{for(;i&&i.readable;){const e=new window.TextDecoderStream;i.readable.pipeTo(e.writable),o=e.readable.getReader();const t=this.readFromSerialPort(o);try{for(;;){const{value:e,done:n}=await t("\n");if(e){const{method:t,data:n}=this.parseResponse(e);if("/ping"===t&&this.log("Pong"),-1===th.PUBLIC_METHODS.indexOf(t))continue;this.log("Received: ",t,n),this.lastCommand&&(this.lastCommand.resolve(n),this.lastCommand=null)}if(n)return this.lastCommand=null,this.writer=null,void(r&&r())}}catch(e){if(e instanceof Error)throw this.writer=null,n&&n(e),this.lastCommand&&(this.lastCommand.reject(e),this.lastCommand=null),e}}})();const s=new window.TextEncoderStream;s.readable.pipeTo(i.writable),this.writer=s.writable.getWriter(),await this.sendCommand(th.METHOD_PING),await this.sendCommand(th.METHOD_PING,[window.location.host]),e&&e(),i.addEventListener("disconnect",()=>{this.log("Disconnected"),this.lastCommand=null,this.writer=null,t&&t()})}async sendCommand(e,t=[]){if(!this.writer)return;this.log("Send command",e,t);const n=[e].concat(t).join(" ");await this.writer.write(n+"\n")}readFromSerialPort(e){let t,n=[];return async(r="\n")=>{if(n.length)return{value:n.shift().trim(),done:!1};const o=[];for(t&&(o.push(t),t=void 0);;){const{value:i,done:s}=await e.read();if(i){const e=i.split(r);if(e.length>1)return o.push(e.shift()),t=e.pop(),n=e,{value:o.join("").trim(),done:!1};o.push(i)}if(s)return{value:o.join("").trim(),done:!0}}}}parseResponse(e){const t=e.split(" ")[0];return{method:t,data:e.substring(t.length).trim()}}async nip04Encrypt(e,t){const n=nf(await this.callMethodOnDevice(th.METHOD_SHARED_SECRET,[Yf(e)]));let r=Uint8Array.from(function(e=32){if(zd&&"function"==typeof zd.getRandomValues)return zd.getRandomValues(new Uint8Array(e));if(zd&&"function"==typeof zd.randomBytes)return Uint8Array.from(zd.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}(16)),o=eh.encode(t),i=await crypto.subtle.importKey("raw",n,{name:"AES-CBC"},!1,["encrypt"]),s=await crypto.subtle.encrypt({name:"AES-CBC",iv:r},i,o);return`${Qf.encode(new Uint8Array(s))}?iv=${Qf.encode(new Uint8Array(r.buffer))}`}async nip04Decrypt(e,t){let[n,r]=t.split("?iv=");const o=nf(await this.callMethodOnDevice(th.METHOD_SHARED_SECRET,[Yf(e)]));let i=await crypto.subtle.importKey("raw",o,{name:"AES-CBC"},!1,["decrypt"]),s=Qf.decode(n),a=Qf.decode(r),c=await crypto.subtle.decrypt({name:"AES-CBC",iv:a},i,s);return Xf.decode(c)}async getPublicKey(){const e=await this.callMethodOnDevice(th.METHOD_PUBLIC_KEY,[]);return this.pubkey=e,e}async restore(e){await this.callMethodOnDevice(th.METHOD_RESTORE,[Jd(e)])}async signEvent(e){const t=e.pubkey||this.pubkey;if(!t)throw new Error("Unknown signer pubkey");const n={...e,id:no({...e,pubkey:t})},r=await this.callMethodOnDevice(th.METHOD_SIGN_MESSAGE,[n.id]),o={...n,sig:r,pubkey:t};if(!this.verifyEvent(o))throw new Error("Invalid signature");return o}ping(){this.sendCommand(th.METHOD_PING,[window.location.host])}static SUPPORTED="navigator"in globalThis&&!!navigator.serial;static METHOD_PING="/ping";static METHOD_LOG="/log";static METHOD_SIGN_MESSAGE="/sign-message";static METHOD_SHARED_SECRET="/shared-secret";static METHOD_PUBLIC_KEY="/public-key";static METHOD_RESTORE="/restore";static PUBLIC_METHODS=[th.METHOD_PUBLIC_KEY,th.METHOD_SIGN_MESSAGE,th.METHOD_SHARED_SECRET,th.METHOD_RESTORE]}const nh=[`wss://${window.location.host}/`];class rh{constructor(){this.pool=new _n,this.eventStore=new Md,this.isConnected=!1,this.signer=null,this.relays=[...nh]}async connect(){console.log("Starting connection to",this.relays.length,"relays...");try{this.isConnected=!0,console.log("✓ Successfully initialized relay pool"),await new Promise(e=>setTimeout(e,1e3))}catch(e){throw console.error("✗ Connection failed:",e),e}}async connectToRelay(e){console.log(`Adding relay: ${e}`);try{return this.relays.includes(e)||this.relays.push(e),console.log(`✓ Successfully added relay ${e}`),!0}catch(t){return console.error(`✗ Failed to add relay ${e}:`,t),!1}}subscribe(e,t){console.log("Creating subscription with filters:",e);const n=this.pool.subscribeMany(this.relays,e,{onevent(e){console.log("Event received:",e),t(e)},oneose(){console.log("EOSE received"),window.dispatchEvent(new CustomEvent("nostr-eose",{detail:{subscriptionId:n.id}}))}});return n}unsubscribe(e){console.log("Closing subscription"),e&&e.close&&e.close()}disconnect(){console.log("Disconnecting relay pool"),this.pool&&this.pool.close(this.relays),this.isConnected=!1}async publish(e,t=null){this.isConnected||(console.warn("Not connected to any relays, attempting to connect first"),await this.connect());try{const n=t||this.relays,r=this.pool.publish(n,e);return await Promise.allSettled(r),console.log("✓ Event published successfully"),await uh([e]),console.log("Event stored in IndexedDB"),{success:!0,okCount:1,errorCount:0}}catch(e){throw console.error("✗ Failed to publish event:",e),e}}getPool(){return this.pool}getEventStore(){return this.eventStore}getSigner(){return this.signer}setSigner(e){this.signer=e}}const oh=new rh,ih="nostrCache",sh=2,ah="events";function ch(){return new Promise((e,t)=>{try{const n=indexedDB.open(ih,sh);n.onupgradeneeded=e=>{const t=n.result;e.oldVersion;let r;r=t.objectStoreNames.contains(ah)?n.transaction.objectStore(ah):t.createObjectStore(ah,{keyPath:"id"}),r.indexNames.contains("byKindAuthor")||r.createIndex("byKindAuthor",["kind","pubkey"],{unique:!1}),r.indexNames.contains("byKindAuthorCreated")||r.createIndex("byKindAuthorCreated",["kind","pubkey","created_at"],{unique:!1}),r.indexNames.contains("byKind")||r.createIndex("byKind","kind",{unique:!1}),r.indexNames.contains("byAuthor")||r.createIndex("byAuthor","pubkey",{unique:!1}),r.indexNames.contains("byCreatedAt")||r.createIndex("byCreatedAt","created_at",{unique:!1})},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}catch(e){console.error("Failed to open IndexedDB",e),t(e)}})}async function lh(e){try{const t=await ch();await new Promise((n,r)=>{const o=t.transaction(ah,"readwrite");o.oncomplete=()=>n(),o.onerror=()=>r(o.error),o.objectStore(ah).put(e)})}catch(e){console.warn("IDB putEvent failed",e)}}async function uh(e){if(e&&0!==e.length)try{const t=await ch();await new Promise((n,r)=>{const o=t.transaction(ah,"readwrite");o.oncomplete=()=>n(),o.onerror=()=>r(o.error);const i=o.objectStore(ah);for(const t of e)i.put(t)}),console.log(`Stored ${e.length} events in IndexedDB`)}catch(e){console.warn("IDB putEvents failed",e)}}async function dh(e){try{const t=await ch(),n=[];console.log("QueryEventsFromDB: Starting query with filters:",e);for(const r of e){console.log("QueryEventsFromDB: Processing filter:",r);const e=await new Promise((e,n)=>{const o=t.transaction(ah,"readonly").objectStore(ah),i=[];let s;if(r.kinds&&r.kinds.length>0&&r.authors&&r.authors.length>0){const e=r.kinds[0],t=r.authors[0];console.log(`QueryEventsFromDB: Using byKindAuthorCreated index for kind=${e}, author=${t.substring(0,8)}...`);const n=o.index("byKindAuthorCreated"),i=IDBKeyRange.bound([e,t,-1/0],[e,t,1/0]);s=n.openCursor(i,"prev")}else if(r.kinds&&r.kinds.length>0){console.log(`QueryEventsFromDB: Using byKind index for kind=${r.kinds[0]}`);const e=o.index("byKind");s=e.openCursor(IDBKeyRange.only(r.kinds[0]))}else if(r.authors&&r.authors.length>0){console.log(`QueryEventsFromDB: Using byAuthor index for author=${r.authors[0].substring(0,8)}...`);const e=o.index("byAuthor");s=e.openCursor(IDBKeyRange.only(r.authors[0]))}else console.log("QueryEventsFromDB: Scanning all events (no specific index)"),s=o.openCursor();s.onsuccess=t=>{const n=t.target.result;if(n){const t=n.value;let o=!0;if(r.kinds&&r.kinds.length>0&&!r.kinds.includes(t.kind)&&(o=!1),r.authors&&r.authors.length>0&&!r.authors.includes(t.pubkey)&&(o=!1),r.since&&t.created_atr.until&&(o=!1),r.ids&&r.ids.length>0&&!r.ids.includes(t.id)&&(o=!1),o&&i.push(t),r.limit&&i.length>=r.limit)return console.log(`QueryEventsFromDB: Reached limit of ${r.limit}, found ${i.length} matching events`),void e(i);n.continue()}else console.log(`QueryEventsFromDB: Cursor exhausted, found ${i.length} matching events`),e(i)},s.onerror=()=>{console.error("QueryEventsFromDB: Cursor error:",s.error),n(s.error)}});console.log(`QueryEventsFromDB: Found ${e.length} events for this filter`),n.push(...e)}return n.sort((e,t)=>t.created_at-e.created_at),console.log(`QueryEventsFromDB: Returning ${n.length} total events`),n}catch(e){return console.error("QueryEventsFromDB failed:",e),[]}}function fh(e){try{const t=JSON.parse(e.content||"{}");return{name:t.name||t.display_name||"",picture:t.picture||"",banner:t.banner||"",about:t.about||"",nip05:t.nip05||"",lud16:t.lud16||t.lud06||""}}catch(e){return{name:"",picture:"",banner:"",about:"",nip05:"",lud16:""}}}async function hh(e){console.log(`Starting profile fetch for pubkey: ${e}`);try{const t=await async function(e){try{const t=await ch();return await new Promise((n,r)=>{const o=t.transaction(ah,"readonly").objectStore(ah).index("byKindAuthorCreated"),i=IDBKeyRange.bound([0,e,-1/0],[0,e,1/0]),s=o.openCursor(i,"prev");s.onsuccess=()=>{const e=s.result;n(e?e.value:null)},s.onerror=()=>r(s.error)})}catch(e){return console.warn("IDB getLatestProfileEvent failed",e),null}}(e);if(t){console.log("Using cached profile event");return fh(t)}}catch(e){console.warn("Failed to load cached profile",e)}try{const t=[{kinds:[0],authors:[e],limit:1}],n=await ph(t,{timeout:1e4});if(n.length>0){const t=n[0];console.log("Profile fetched:",t),await lh(t);try{console.log("Publishing profile event to local relay:",t.id),await oh.publish(t),console.log("Profile event successfully saved to local relay")}catch(e){console.warn("Failed to publish profile to local relay:",e)}const r=fh(t);try{"undefined"!=typeof window&&window.dispatchEvent&&window.dispatchEvent(new CustomEvent("profile-updated",{detail:{pubkey:e,profile:r,event:t}}))}catch(e){console.warn("Failed to dispatch profile-updated event",e)}return r}throw new Error("No profile found")}catch(e){throw console.error("Failed to fetch profile:",e),e}}async function ph(e,t={}){console.log("Starting event fetch with filters:",JSON.stringify(e,null,2)),console.log("Current relays:",oh.relays),oh.isConnected&&0!==oh.relays.length||(console.warn("Client not connected, initializing..."),await vh());const{timeout:n=3e4,useCache:r=!0}=t;if(r)try{const t=await dh(e);t.length>0&&console.log(`Found ${t.length} cached events in IndexedDB`)}catch(e){console.warn("Failed to query cached events",e)}return new Promise((t,r)=>{const o=[],i=setTimeout(()=>{console.log(`Timeout reached after ${n}ms, returning ${o.length} events`),sub.close(),o.length>0&&uh(o).catch(e=>console.warn("Failed to cache events",e)),t(o)},n);try{const n=Math.random().toString(36).substring(7);console.log(`📤 REQ [${n}]:`,JSON.stringify(["REQ",n,...e],null,2));const r=oh.pool.subscribeMany(oh.relays,e,{onevent(e){console.log(`📥 EVENT received for REQ [${n}]:`,{id:e.id?.substring(0,8)+"...",kind:e.kind,pubkey:e.pubkey?.substring(0,8)+"...",created_at:e.created_at,content_preview:e.content?.substring(0,50)}),o.push(e),lh(e).catch(e=>console.warn("Failed to cache event",e))},oneose(){console.log(`✅ EOSE received for REQ [${n}], got ${o.length} events`),clearTimeout(i),r.close(),o.length>0&&uh(o).catch(e=>console.warn("Failed to cache events",e)),t(o)}})}catch(e){clearTimeout(i),console.error("Failed to fetch events:",e),r(e)}})}async function gh(e,t={}){const{timeout:n=1e4}=t;console.log(`Fetching event by ID: ${e}`);try{const t=[{ids:[e]}];console.log("Fetching event with filters:",t);const r=await ph(t,{timeout:n});return console.log(`Fetched ${r.length} events`),r.length>0?r[0]:null}catch(e){throw console.error("Failed to fetch event by ID:",e),e}}async function yh(e,t={}){const{timeout:n=1e4}=t;console.log(`Fetching delete events for target: ${e}`);try{const t=[{kinds:[5],"#e":[e]}];console.log("Fetching delete events with filters:",t);const r=await ph(t,{timeout:n});return console.log(`Fetched ${r.length} delete events`),r}catch(e){throw console.error("Failed to fetch delete events:",e),e}}async function vh(){await oh.connect()}async function mh(){try{const e=await ch(),t=e.transaction(ah,"readonly").objectStore(ah),n=await new Promise((e,n)=>{const r=t.getAll();r.onsuccess=()=>e(r.result),r.onerror=()=>n(r.error)}),r=n.reduce((e,t)=>(e[t.kind]=(e[t.kind]||0)+1,e),{});return console.log("===== IndexedDB Contents ====="),console.log(`Total events: ${n.length}`),console.log("Events by kind:",r),console.log("Kind 0 events:",n.filter(e=>0===e.kind)),console.log("All event IDs:",n.map(e=>({id:e.id.substring(0,8),kind:e.kind,pubkey:e.pubkey.substring(0,8)}))),console.log("=============================="),{total:n.length,byKind:r,events:n}}catch(e){return console.error("Failed to debug IndexedDB:",e),null}}const{window:wh}=c;function bh(e){let t,n,o,i,s,a,c,f,p,y,b,E,k,x,C,A,$,T;function I(e,t){return"extension"===e[2]?kh:Eh}let _=I(e),R=_(e),O=e[5]&&xh(e),L=e[6]&&Sh(e);return{c(){t=h("div"),n=h("div"),o=h("div"),i=h("h2"),i.textContent="Login to Nostr",s=g(),a=h("button"),a.textContent="×",c=g(),f=h("div"),p=h("div"),y=h("button"),y.textContent="Extension",b=g(),E=h("button"),E.textContent="Nsec",k=g(),x=h("div"),R.c(),C=g(),O&&O.c(),A=g(),L&&L.c(),w(i,"class","svelte-1cle6o2"),w(a,"class","close-btn svelte-1cle6o2"),w(o,"class","modal-header svelte-1cle6o2"),w(y,"class","tab-btn svelte-1cle6o2"),S(y,"active","extension"===e[2]),w(E,"class","tab-btn svelte-1cle6o2"),S(E,"active","nsec"===e[2]),w(p,"class","tabs svelte-1cle6o2"),w(x,"class","tab-content svelte-1cle6o2"),w(f,"class","tab-container svelte-1cle6o2"),w(n,"class","modal svelte-1cle6o2"),S(n,"dark-theme",e[1]),w(t,"class","modal-overlay svelte-1cle6o2"),w(t,"role","button"),w(t,"tabindex","0")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(o,i),l(o,s),l(o,a),l(n,c),l(n,f),l(f,p),l(p,y),l(p,b),l(p,E),l(f,k),l(f,x),R.m(x,null),l(x,C),O&&O.m(x,null),l(x,A),L&&L.m(x,null),$||(T=[v(a,"click",e[7]),v(y,"click",e[14]),v(E,"click",e[15]),v(n,"click",m(e[12])),v(n,"keydown",m(e[13])),v(t,"click",e[7]),v(t,"keydown",e[17])],$=!0)},p(e,t){4&t&&S(y,"active","extension"===e[2]),4&t&&S(E,"active","nsec"===e[2]),_===(_=I(e))&&R?R.p(e,t):(R.d(1),R=_(e),R&&(R.c(),R.m(x,C))),e[5]?O?O.p(e,t):(O=xh(e),O.c(),O.m(x,A)):O&&(O.d(1),O=null),e[6]?L?L.p(e,t):(L=Sh(e),L.c(),L.m(x,null)):L&&(L.d(1),L=null),2&t&&S(n,"dark-theme",e[1])},d(e){e&&d(t),R.d(),O&&O.d(),L&&L.d(),$=!1,r(T)}}}function Eh(e){let t,n,o,i,s,a,c,f,y,m,b=e[4]?"Logging in...":"Log in with nsec";return{c(){t=h("div"),n=h("p"),n.textContent="Enter your nsec (private key) to login. This\n will be stored securely in your browser.",o=g(),i=h("input"),s=g(),a=h("button"),c=p(b),w(n,"class","svelte-1cle6o2"),w(i,"type","password"),w(i,"placeholder","nsec1..."),i.disabled=e[4],w(i,"class","nsec-input svelte-1cle6o2"),w(a,"class","login-nsec-btn svelte-1cle6o2"),a.disabled=f=e[4]||!e[3].trim(),w(t,"class","nsec-login svelte-1cle6o2")},m(r,d){u(r,t,d),l(t,n),l(t,o),l(t,i),k(i,e[3]),l(t,s),l(t,a),l(a,c),y||(m=[v(i,"input",e[16]),v(a,"click",e[10])],y=!0)},p(e,t){16&t&&(i.disabled=e[4]),8&t&&i.value!==e[3]&&k(i,e[3]),16&t&&b!==(b=e[4]?"Logging in...":"Log in with nsec")&&E(c,b),24&t&&f!==(f=e[4]||!e[3].trim())&&(a.disabled=f)},d(e){e&&d(t),y=!1,r(m)}}}function kh(e){let t,n,r,o,i,s,a,c=e[4]?"Connecting...":"Log in using extension";return{c(){t=h("div"),n=h("p"),n.textContent="Login using a NIP-07 compatible browser\n extension like nos2x or Alby.",r=g(),o=h("button"),i=p(c),w(n,"class","svelte-1cle6o2"),w(o,"class","login-extension-btn svelte-1cle6o2"),o.disabled=e[4],w(t,"class","extension-login svelte-1cle6o2")},m(c,d){u(c,t,d),l(t,n),l(t,r),l(t,o),l(o,i),s||(a=v(o,"click",e[9]),s=!0)},p(e,t){16&t&&c!==(c=e[4]?"Connecting...":"Log in using extension")&&E(i,c),16&t&&(o.disabled=e[4])},d(e){e&&d(t),s=!1,a()}}}function xh(e){let t,n;return{c(){t=h("div"),n=p(e[5]),w(t,"class","message error-message svelte-1cle6o2")},m(e,r){u(e,t,r),l(t,n)},p(e,t){32&t&&E(n,e[5])},d(e){e&&d(t)}}}function Sh(e){let t,n;return{c(){t=h("div"),n=p(e[6]),w(t,"class","message success-message svelte-1cle6o2")},m(e,r){u(e,t,r),l(t,n)},p(e,t){64&t&&E(n,e[6])},d(e){e&&d(t)}}}function Ch(t){let n,r,o,i=t[0]&&bh(t);return{c(){i&&i.c(),n=y()},m(e,s){i&&i.m(e,s),u(e,n,s),r||(o=v(wh,"keydown",t[11]),r=!0)},p(e,[t]){e[0]?i?i.p(e,t):(i=bh(e),i.c(),i.m(n.parentNode,n)):i&&(i.d(1),i=null)},i:e,o:e,d(e){i&&i.d(e),e&&d(n),r=!1,o()}}}function Ah(e,t,n){const r=T();let{showModal:o=!1}=t,{isDarkTheme:i=!1}=t,s="extension",a="",c=!1,l="",u="";function d(){n(0,o=!1),n(3,a=""),n(5,l=""),n(6,u=""),r("close")}function f(e){n(2,s=e),n(5,l=""),n(6,u="")}async function h(){n(4,c=!0),n(5,l=""),n(6,u="");try{if(!a.trim())throw new Error("Please enter your nsec");if(!(e=a.trim()).startsWith("nsec1")||(e.length<60||e.length>70))throw new Error('Invalid nsec format. Must start with "nsec1"');const t=qd.fromKey(a.trim()),o=await t.getPublicKey();localStorage.setItem("nostr_auth_method","nsec"),localStorage.setItem("nostr_pubkey",o),localStorage.setItem("nostr_privkey",a.trim()),n(6,u="Successfully logged in with nsec!"),r("login",{method:"nsec",pubkey:o,privateKey:a.trim(),signer:t}),setTimeout(()=>{d()},1500)}catch(e){n(5,l=e.message)}finally{n(4,c=!1)}var e}return e.$$set=e=>{"showModal"in e&&n(0,o=e.showModal),"isDarkTheme"in e&&n(1,i=e.isDarkTheme)},[o,i,s,a,c,l,u,d,f,async function(){n(4,c=!0),n(5,l=""),n(6,u="");try{if(!window.nostr)throw new Error("No Nostr extension found. Please install a NIP-07 compatible extension like nos2x or Alby.");const e=await window.nostr.getPublicKey();e&&(localStorage.setItem("nostr_auth_method","extension"),localStorage.setItem("nostr_pubkey",e),n(6,u="Successfully logged in with extension!"),r("login",{method:"extension",pubkey:e,signer:window.nostr}),setTimeout(()=>{d()},1500))}catch(e){n(5,l=e.message)}finally{n(4,c=!1)}},h,function(e){"Escape"===e.key&&d(),"Enter"===e.key&&"nsec"===s&&h()},function(t){I.call(this,e,t)},function(t){I.call(this,e,t)},()=>f("extension"),()=>f("nsec"),function(){a=this.value,n(3,a)},e=>"Escape"===e.key&&d()]}class $h extends ee{constructor(e){super(),X(this,e,Ah,Ch,i,{showModal:0,isDarkTheme:1})}}function Th(e,t,n){const r=e.slice();return r[72]=t[n],r}function Ih(e,t,n){const r=e.slice();return r[75]=t[n],r}function _h(e,t,n){const r=e.slice();return r[72]=t[n],r}function Rh(e,t,n){const r=e.slice();return r[72]=t[n],r}function Oh(e,t,n){const r=e.slice();return r[72]=t[n],r}function Lh(e,t,n){const r=e.slice();return r[72]=t[n],r}function Ph(e,t,n){const r=e.slice();return r[72]=t[n],r}function Bh(e){let t,n,r;return{c(){t=h("div"),n=p(e[3]),w(t,"class",r="message "+e[4]+" svelte-1y8wjwc")},m(e,r){u(e,t,r),l(t,n)},p(e,o){8&o[0]&&E(n,e[3]),16&o[0]&&r!==(r="message "+e[4]+" svelte-1y8wjwc")&&w(t,"class",r)},d(e){e&&d(t)}}}function jh(e){let t,n,o,i,s,a,c,f,y,m,b,E,x,S,C,A,$,T,I,_,R,O,L,P,B,j,N,U;function M(e,t){return e[5]&&e[5].length>0?Uh:Nh}let F=M(e),D=F(e);function H(e,t){return e[8]&&e[8].length>0?Hh:Dh}let q=H(e),z=q(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Banned Pubkeys",i=g(),s=h("div"),a=h("input"),c=g(),f=h("input"),y=g(),m=h("button"),b=p("Ban Pubkey"),E=g(),x=h("div"),D.c(),S=g(),C=h("div"),A=h("h3"),A.textContent="Allowed Pubkeys",$=g(),T=h("div"),I=h("input"),_=g(),R=h("input"),O=g(),L=h("button"),P=p("Allow Pubkey"),B=g(),j=h("div"),z.c(),w(o,"class","svelte-1y8wjwc"),w(a,"type","text"),w(a,"placeholder","Pubkey (64 hex chars)"),w(a,"class","svelte-1y8wjwc"),w(f,"type","text"),w(f,"placeholder","Reason (optional)"),w(f,"class","svelte-1y8wjwc"),m.disabled=e[2],w(m,"class","svelte-1y8wjwc"),w(s,"class","add-form svelte-1y8wjwc"),w(x,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(A,"class","svelte-1y8wjwc"),w(I,"type","text"),w(I,"placeholder","Pubkey (64 hex chars)"),w(I,"class","svelte-1y8wjwc"),w(R,"type","text"),w(R,"placeholder","Reason (optional)"),w(R,"class","svelte-1y8wjwc"),L.disabled=e[2],w(L,"class","svelte-1y8wjwc"),w(T,"class","add-form svelte-1y8wjwc"),w(j,"class","list svelte-1y8wjwc"),w(C,"class","section svelte-1y8wjwc"),w(t,"class","pubkeys-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),k(a,e[6]),l(s,c),l(s,f),k(f,e[7]),l(s,y),l(s,m),l(m,b),l(n,E),l(n,x),D.m(x,null),l(t,S),l(t,C),l(C,A),l(C,$),l(C,T),l(T,I),k(I,e[9]),l(T,_),l(T,R),k(R,e[10]),l(T,O),l(T,L),l(L,P),l(C,B),l(C,j),z.m(j,null),N||(U=[v(a,"input",e[43]),v(f,"input",e[44]),v(m,"click",e[25]),v(I,"input",e[45]),v(R,"input",e[46]),v(L,"click",e[26])],N=!0)},p(e,t){64&t[0]&&a.value!==e[6]&&k(a,e[6]),128&t[0]&&f.value!==e[7]&&k(f,e[7]),4&t[0]&&(m.disabled=e[2]),F===(F=M(e))&&D?D.p(e,t):(D.d(1),D=F(e),D&&(D.c(),D.m(x,null))),512&t[0]&&I.value!==e[9]&&k(I,e[9]),1024&t[0]&&R.value!==e[10]&&k(R,e[10]),4&t[0]&&(L.disabled=e[2]),q===(q=H(e))&&z?z.p(e,t):(z.d(1),z=q(e),z&&(z.c(),z.m(j,null)))},d(e){e&&d(t),D.d(),z.d(),N=!1,r(U)}}}function Nh(t){let n;return{c(){n=h("div"),n.innerHTML="

No banned pubkeys configured.

",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Uh(e){let t,n=e[5],r=[];for(let t=0;tNo allowed pubkeys configured.

",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Hh(e){let t,n=e[8],r=[];for(let t=0;t0?Vh:Wh}let F=M(e),D=F(e);let H=function(e){return e[22]&&e[22].length>0?Qh:Zh}(e),q=H(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Banned Events",i=g(),s=h("div"),a=h("input"),c=g(),f=h("input"),y=g(),m=h("button"),b=p("Ban Event"),E=g(),x=h("div"),D.c(),S=g(),C=h("div"),A=h("h3"),A.textContent="Allowed Events",$=g(),T=h("div"),I=h("input"),_=g(),R=h("input"),O=g(),L=h("button"),P=p("Allow Event"),B=g(),j=h("div"),q.c(),w(o,"class","svelte-1y8wjwc"),w(a,"type","text"),w(a,"placeholder","Event ID (64 hex chars)"),w(a,"class","svelte-1y8wjwc"),w(f,"type","text"),w(f,"placeholder","Reason (optional)"),w(f,"class","svelte-1y8wjwc"),m.disabled=e[2],w(m,"class","svelte-1y8wjwc"),w(s,"class","add-form svelte-1y8wjwc"),w(x,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(A,"class","svelte-1y8wjwc"),w(I,"type","text"),w(I,"placeholder","Event ID (64 hex chars)"),w(I,"class","svelte-1y8wjwc"),w(R,"type","text"),w(R,"placeholder","Reason (optional)"),w(R,"class","svelte-1y8wjwc"),L.disabled=e[2],w(L,"class","svelte-1y8wjwc"),w(T,"class","add-form svelte-1y8wjwc"),w(j,"class","list svelte-1y8wjwc"),w(C,"class","section svelte-1y8wjwc"),w(t,"class","events-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),k(a,e[12]),l(s,c),l(s,f),k(f,e[13]),l(s,y),l(s,m),l(m,b),l(n,E),l(n,x),D.m(x,null),l(t,S),l(t,C),l(C,A),l(C,$),l(C,T),l(T,I),k(I,e[14]),l(T,_),l(T,R),k(R,e[15]),l(T,O),l(T,L),l(L,P),l(C,B),l(C,j),q.m(j,null),N||(U=[v(a,"input",e[47]),v(f,"input",e[48]),v(m,"click",e[27]),v(I,"input",e[49]),v(R,"input",e[50]),v(L,"click",e[28])],N=!0)},p(e,t){4096&t[0]&&a.value!==e[12]&&k(a,e[12]),8192&t[0]&&f.value!==e[13]&&k(f,e[13]),4&t[0]&&(m.disabled=e[2]),F===(F=M(e))&&D?D.p(e,t):(D.d(1),D=F(e),D&&(D.c(),D.m(x,null))),16384&t[0]&&I.value!==e[14]&&k(I,e[14]),32768&t[0]&&R.value!==e[15]&&k(R,e[15]),4&t[0]&&(L.disabled=e[2]),q.p(e,t)},d(e){e&&d(t),D.d(),q.d(),N=!1,r(U)}}}function Wh(t){let n;return{c(){n=h("div"),n.innerHTML="

No banned events configured.

",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Vh(e){let t,n=e[11],r=[];for(let t=0;tNo allowed events configured.

",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Qh(e){let t,n=e[22],r=[];for(let t=0;t0?tp:ep}let $=A(e),T=$(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Blocked IPs",i=g(),s=h("div"),a=h("input"),c=g(),f=h("input"),y=g(),m=h("button"),b=p("Block IP"),E=g(),x=h("div"),T.c(),w(o,"class","svelte-1y8wjwc"),w(a,"type","text"),w(a,"placeholder","IP Address"),w(a,"class","svelte-1y8wjwc"),w(f,"type","text"),w(f,"placeholder","Reason (optional)"),w(f,"class","svelte-1y8wjwc"),m.disabled=e[2],w(m,"class","svelte-1y8wjwc"),w(s,"class","add-form svelte-1y8wjwc"),w(x,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(t,"class","ips-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),k(a,e[17]),l(s,c),l(s,f),k(f,e[18]),l(s,y),l(s,m),l(m,b),l(n,E),l(n,x),T.m(x,null),S||(C=[v(a,"input",e[51]),v(f,"input",e[52]),v(m,"click",e[29])],S=!0)},p(e,t){131072&t[0]&&a.value!==e[17]&&k(a,e[17]),262144&t[0]&&f.value!==e[18]&&k(f,e[18]),4&t[0]&&(m.disabled=e[2]),$===($=A(e))&&T?T.p(e,t):(T.d(1),T=$(e),T&&(T.c(),T.m(x,null)))},d(e){e&&d(t),T.d(),S=!1,r(C)}}}function ep(t){let n;return{c(){n=h("div"),n.innerHTML="

No blocked IPs configured.

",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function tp(e){let t,n=e[16],r=[];for(let t=0;t0?sp:ip}let A=C(e),$=A(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Allowed Event Kinds",i=g(),s=h("div"),a=h("input"),c=g(),f=h("button"),y=p("Allow Kind"),m=g(),E=h("div"),$.c(),w(o,"class","svelte-1y8wjwc"),w(a,"type","number"),w(a,"placeholder","Kind number"),w(a,"class","svelte-1y8wjwc"),f.disabled=e[2],w(f,"class","svelte-1y8wjwc"),w(s,"class","add-form svelte-1y8wjwc"),w(E,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(t,"class","kinds-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),k(a,e[20]),l(s,c),l(s,f),l(f,y),l(n,m),l(n,E),$.m(E,null),x||(S=[v(a,"input",e[53]),v(f,"click",e[30])],x=!0)},p(e,t){1048576&t[0]&&b(a.value)!==e[20]&&k(a,e[20]),4&t[0]&&(f.disabled=e[2]),A===(A=C(e))&&$?$.p(e,t):($.d(1),$=A(e),$&&($.c(),$.m(E,null)))},d(e){e&&d(t),$.d(),x=!1,r(S)}}}function ip(t){let n;return{c(){n=h("div"),n.innerHTML="

No allowed kinds configured. All kinds are\n allowed by default.

",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function sp(e){let t,n=e[19],r=[];for(let t=0;t0?up:lp}let b=m(e),E=b(e);return{c(){t=h("div"),n=h("div"),r=h("h3"),r.textContent="Events Needing Moderation",o=g(),i=h("button"),s=p("Refresh"),a=g(),c=h("div"),E.c(),w(r,"class","svelte-1y8wjwc"),i.disabled=e[2],w(c,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(t,"class","moderation-section")},m(d,h){u(d,t,h),l(t,n),l(n,r),l(n,o),l(n,i),l(i,s),l(n,a),l(n,c),E.m(c,null),f||(y=v(i,"click",e[24]),f=!0)},p(e,t){4&t[0]&&(i.disabled=e[2]),b===(b=m(e))&&E?E.p(e,t):(E.d(1),E=b(e),E&&(E.c(),E.m(c,null)))},d(e){e&&d(t),E.d(),f=!1,y()}}}function lp(t){let n;return{c(){n=h("div"),n.innerHTML="

No events need moderation at this time.

",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function up(e){let t,n=e[21],r=[];for(let t=0;tManaged ACL Configuration \n

Configure access control using NIP-86 management API

\n
Owner Only: This interface is restricted to relay owners\n only.
',i=g(),J&&J.c(),s=g(),a=h("div"),c=h("button"),f=p("Pubkeys"),m=g(),b=h("button"),E=p("Events"),x=g(),S=h("button"),C=p("IPs"),$=g(),T=h("button"),I=p("Kinds"),R=g(),O=h("button"),L=p("Moderation"),B=g(),j=h("button"),N=p("Relay Config"),M=g(),F=h("div"),G&&G.c(),D=g(),Z&&Z.c(),H=g(),Q&&Q.c(),q=g(),Y&&Y.c(),z=g(),X&&X.c(),K=g(),ee&&ee.c(),w(o,"class","header svelte-1y8wjwc"),w(c,"class",y="tab "+("pubkeys"===t[1]?"active":"")+" svelte-1y8wjwc"),w(b,"class",k="tab "+("events"===t[1]?"active":"")+" svelte-1y8wjwc"),w(S,"class",A="tab "+("ips"===t[1]?"active":"")+" svelte-1y8wjwc"),w(T,"class",_="tab "+("kinds"===t[1]?"active":"")+" svelte-1y8wjwc"),w(O,"class",P="tab "+("moderation"===t[1]?"active":"")+" svelte-1y8wjwc"),w(j,"class",U="tab "+("relay"===t[1]?"active":"")+" svelte-1y8wjwc"),w(a,"class","tabs svelte-1y8wjwc"),w(F,"class","tab-content svelte-1y8wjwc")},m(e,r){u(e,n,r),l(n,o),l(n,i),J&&J.m(n,null),l(n,s),l(n,a),l(a,c),l(c,f),l(a,m),l(a,b),l(b,E),l(a,x),l(a,S),l(S,C),l(a,$),l(a,T),l(T,I),l(a,R),l(a,O),l(O,L),l(a,B),l(a,j),l(j,N),l(n,M),l(n,F),G&&G.m(F,null),l(F,D),Z&&Z.m(F,null),l(F,H),Q&&Q.m(F,null),l(F,q),Y&&Y.m(F,null),l(F,z),X&&X.m(F,null),l(F,K),ee&&ee.m(F,null),W||(V=[v(c,"click",t[37]),v(b,"click",t[38]),v(S,"click",t[39]),v(T,"click",t[40]),v(O,"click",t[41]),v(j,"click",t[42])],W=!0)},p(e,t){e[3]?J?J.p(e,t):(J=Bh(e),J.c(),J.m(n,s)):J&&(J.d(1),J=null),2&t[0]&&y!==(y="tab "+("pubkeys"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(c,"class",y),2&t[0]&&k!==(k="tab "+("events"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(b,"class",k),2&t[0]&&A!==(A="tab "+("ips"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(S,"class",A),2&t[0]&&_!==(_="tab "+("kinds"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(T,"class",_),2&t[0]&&P!==(P="tab "+("moderation"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(O,"class",P),2&t[0]&&U!==(U="tab "+("relay"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(j,"class",U),"pubkeys"===e[1]?G?G.p(e,t):(G=jh(e),G.c(),G.m(F,D)):G&&(G.d(1),G=null),"events"===e[1]?Z?Z.p(e,t):(Z=Kh(e),Z.c(),Z.m(F,H)):Z&&(Z.d(1),Z=null),"ips"===e[1]?Q?Q.p(e,t):(Q=Xh(e),Q.c(),Q.m(F,q)):Q&&(Q.d(1),Q=null),"kinds"===e[1]?Y?Y.p(e,t):(Y=op(e),Y.c(),Y.m(F,z)):Y&&(Y.d(1),Y=null),"moderation"===e[1]?X?X.p(e,t):(X=cp(e),X.c(),X.m(F,K)):X&&(X.d(1),X=null),"relay"===e[1]?ee?ee.p(e,t):(ee=hp(e),ee.c(),ee.m(F,null)):ee&&(ee.d(1),ee=null)},i:e,o:e,d(e){e&&d(n),J&&J.d(),G&&G.d(),Z&&Z.d(),Q&&Q.d(),Y&&Y.d(),X&&X.d(),ee&&ee.d(),W=!1,r(V)}}}function vp(e,t,n){let{userSigner:r}=t,{userPubkey:o}=t,i="pubkeys",s=!1,a="",c="info",l=[],u="",d="",f=[],h="",p="",g=[],y="",v="",m="",w="",E=[],k="",x="",S=[],C="",A=[],T={relay_name:"",relay_description:"",relay_icon:""};var I;async function _(){try{n(2,s=!0),console.log("Fetching relay info from /");const e=await fetch(window.location.origin+"/",{headers:{Accept:"application/nostr+json"}});if(console.log("Response status:",e.status),console.log("Response headers:",e.headers),e.ok){const t=await e.json();console.log("Raw relay info:",t),n(0,T={relay_name:t.name||"",relay_description:t.description||"",relay_icon:t.icon||""}),console.log("Updated relayConfig:",T),console.log("Loaded relay info:",t),n(3,a="Relay configuration loaded successfully"),n(4,c="success")}else console.error("Failed to fetch relay info, status:",e.status),n(3,a=`Failed to fetch relay info: ${e.status}`),n(4,c="error")}catch(e){console.error("Failed to fetch relay info:",e),n(3,a=`Failed to fetch relay info: ${e.message}`),n(4,c="error")}finally{n(2,s=!1)}}async function R(e,t=[]){try{n(2,s=!0),n(3,a="");const i={method:e,params:t},c=await async function(e,t){if(!r)throw new Error("No signer available for authentication. Please log in with a Nostr extension.");if(!o)throw new Error("No user pubkey available for authentication.");const n=window.location.origin+t,i={kind:27235,created_at:Math.floor(Date.now()/1e3),tags:[["u",n],["method",e]],content:"",pubkey:o},s=await r.signEvent(i),a=JSON.stringify(s);return`Nostr ${btoa(a)}`}("POST","/api/nip86"),l=await fetch("/api/nip86",{method:"POST",headers:{"Content-Type":"application/nostr+json+rpc",Authorization:c},body:JSON.stringify(i)});if(!l.ok)throw new Error(`HTTP ${l.status}: ${l.statusText}`);const u=await l.json();if(u.error)throw new Error(u.error);return u.result}catch(e){throw console.error("NIP-86 API error:",e),n(3,a=e.message),n(4,c="error"),e}finally{n(2,s=!1)}}async function O(){try{n(5,l=await R("listbannedpubkeys"))}catch(e){console.error("Failed to load banned pubkeys:",e)}}async function L(){try{n(8,f=await R("listallowedpubkeys"))}catch(e){console.error("Failed to load allowed pubkeys:",e)}}async function P(){try{n(11,g=await R("listbannedevents"))}catch(e){console.error("Failed to load banned events:",e)}}async function B(){try{n(16,E=await R("listblockedips"))}catch(e){console.error("Failed to load blocked IPs:",e)}}async function j(){try{n(19,S=await R("listallowedkinds"))}catch(e){console.error("Failed to load allowed kinds:",e)}}async function N(){try{n(2,s=!0),n(21,A=await R("listeventsneedingmoderation")),console.log("Loaded events needing moderation:",A)}catch(e){console.error("Failed to load events needing moderation:",e),n(3,a=`Failed to load moderation events: ${e.message}`),n(4,c="error"),n(21,A=[])}finally{n(2,s=!1)}}async function U(e){try{await R("disallowkind",[e]),n(3,a="Kind disallowed successfully"),n(4,c="success"),await j()}catch(e){console.error("Failed to disallow kind:",e)}}async function M(e){try{await R("allowevent",[e,"Approved from moderation queue"]),n(3,a="Event allowed successfully"),n(4,c="success"),await N()}catch(e){console.error("Failed to allow event from moderation:",e)}}async function F(e){try{await R("banevent",[e,"Banned from moderation queue"]),n(3,a="Event banned successfully"),n(4,c="success"),await N()}catch(e){console.error("Failed to ban event from moderation:",e)}}I=()=>{setTimeout(()=>{_()},100)},$().$$.on_mount.push(I),async function(){await Promise.all([O(),L(),P(),B(),j()])}();return e.$$set=e=>{"userSigner"in e&&n(35,r=e.userSigner),"userPubkey"in e&&n(36,o=e.userPubkey)},e.$$.update=()=>{1&e.$$.dirty[0]&&console.log("relayConfig changed:",T)},[T,i,s,a,c,l,u,d,f,h,p,g,y,v,m,w,E,k,x,S,C,A,[],_,N,async function(){if(u)try{await R("banpubkey",[u,d]),n(3,a="Pubkey banned successfully"),n(4,c="success"),n(6,u=""),n(7,d=""),await O()}catch(e){console.error("Failed to ban pubkey:",e)}},async function(){if(h)try{await R("allowpubkey",[h,p]),n(3,a="Pubkey allowed successfully"),n(4,c="success"),n(9,h=""),n(10,p=""),await L()}catch(e){console.error("Failed to allow pubkey:",e)}},async function(){if(y)try{await R("banevent",[y,v]),n(3,a="Event banned successfully"),n(4,c="success"),n(12,y=""),n(13,v=""),await P()}catch(e){console.error("Failed to ban event:",e)}},async function(){if(m)try{await R("allowevent",[m,w]),n(3,a="Event allowed successfully"),n(4,c="success"),n(14,m=""),n(15,w="")}catch(e){console.error("Failed to allow event:",e)}},async function(){if(k)try{await R("blockip",[k,x]),n(3,a="IP blocked successfully"),n(4,c="success"),n(17,k=""),n(18,x=""),await B()}catch(e){console.error("Failed to block IP:",e)}},async function(){if(!C)return;const e=parseInt(C);if(isNaN(e))return n(3,a="Invalid kind number"),void n(4,c="error");try{await R("allowkind",[e]),n(3,a="Kind allowed successfully"),n(4,c="success"),n(20,C=""),await j()}catch(e){console.error("Failed to allow kind:",e)}},U,async function(){try{n(2,s=!0),n(3,a="");const e=[];if(T.relay_name&&e.push(R("changerelayname",[T.relay_name])),T.relay_description&&e.push(R("changerelaydescription",[T.relay_description])),T.relay_icon&&e.push(R("changerelayicon",[T.relay_icon])),0===e.length)return n(3,a="No changes to update"),void n(4,c="info");await Promise.all(e),n(3,a="Relay configuration updated successfully"),n(4,c="success"),await _()}catch(e){console.error("Failed to update relay configuration:",e),n(3,a=`Failed to update relay configuration: ${e.message}`),n(4,c="error")}finally{n(2,s=!1)}},M,F,r,o,()=>n(1,i="pubkeys"),()=>n(1,i="events"),()=>n(1,i="ips"),()=>n(1,i="kinds"),()=>{n(1,i="moderation"),A&&0!==A.length||N()},()=>n(1,i="relay"),function(){u=this.value,n(6,u)},function(){d=this.value,n(7,d)},function(){h=this.value,n(9,h)},function(){p=this.value,n(10,p)},function(){y=this.value,n(12,y)},function(){v=this.value,n(13,v)},function(){m=this.value,n(14,m)},function(){w=this.value,n(15,w)},function(){k=this.value,n(17,k)},function(){x=this.value,n(18,x)},function(){C=b(this.value),n(20,C)},e=>U(e),e=>M(e.id),e=>F(e.id),function(){T.relay_name=this.value,n(0,T)},function(){T.relay_description=this.value,n(0,T)},function(){T.relay_icon=this.value,n(0,T)}]}class mp extends ee{constructor(e){super(),X(this,e,vp,yp,i,{userSigner:35,userPubkey:36},null,[-1,-1,-1])}}function wp(e){let t,n,r,o=e[3]&&e[4]&&Ep(e);return{c(){t=h("div"),n=h("span"),r=p("ORLY? dashboard\n "),o&&o.c(),w(n,"class","app-title svelte-1mrm2k6"),w(t,"class","header-title svelte-1mrm2k6")},m(e,i){u(e,t,i),l(t,n),l(n,r),o&&o.m(n,null)},p(e,t){e[3]&&e[4]?o?o.p(e,t):(o=Ep(e),o.c(),o.m(n,null)):o&&(o.d(1),o=null)},d(e){e&&d(t),o&&o.d()}}}function bp(e){let t,n,o,i;return{c(){t=h("div"),n=h("input"),w(n,"type","text"),w(n,"class","search-input svelte-1mrm2k6"),w(n,"placeholder","Search..."),w(t,"class","search-input-container svelte-1mrm2k6")},m(r,s){u(r,t,s),l(t,n),k(n,e[0]),o||(i=[v(n,"input",e[13]),v(n,"keydown",e[8])],o=!0)},p(e,t){1&t&&n.value!==e[0]&&k(n,e[0])},d(e){e&&d(t),o=!1,r(i)}}}function Ep(e){let t,n;return{c(){t=h("span"),n=p(e[5]),w(t,"class","permission-badge svelte-1mrm2k6")},m(e,r){u(e,t,r),l(t,n)},p(e,t){32&t&&E(n,e[5])},d(e){e&&d(t)}}}function kp(t){let n,r,o;return{c(){n=h("button"),n.textContent="Log in",w(n,"class","login-btn svelte-1mrm2k6")},m(e,i){u(e,n,i),r||(o=v(n,"click",t[12]),r=!0)},p:e,d(e){e&&d(n),r=!1,o()}}}function xp(e){let t,n,r,o,i,s,a=(e[6]?.name||e[7].slice(0,8)+"...")+"";function c(e,t){return e[6]?.picture?Cp:Sp}let f=c(e),y=f(e);return{c(){t=h("button"),y.c(),n=g(),r=h("span"),o=p(a),w(r,"class","user-name svelte-1mrm2k6"),w(t,"class","user-profile-btn svelte-1mrm2k6")},m(a,c){u(a,t,c),y.m(t,null),l(t,n),l(t,r),l(r,o),i||(s=v(t,"click",e[11]),i=!0)},p(e,r){f===(f=c(e))&&y?y.p(e,r):(y.d(1),y=f(e),y&&(y.c(),y.m(t,n))),192&r&&a!==(a=(e[6]?.name||e[7].slice(0,8)+"...")+"")&&E(o,a)},d(e){e&&d(t),y.d(),i=!1,s()}}}function Sp(t){let n;return{c(){n=h("div"),n.textContent="👤",w(n,"class","user-avatar-placeholder svelte-1mrm2k6")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Cp(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[6].picture)||w(t,"src",n),w(t,"alt","User avatar"),w(t,"class","user-avatar svelte-1mrm2k6")},m(e,n){u(e,t,n)},p(e,r){64&r&&!a(t.src,n=e[6].picture)&&w(t,"src",n)},d(e){e&&d(t)}}}function Ap(t){let n,o,i,s,c,f,y,m,b,k,x,C,A,$,T=t[1]?"☀️":"🌙";function I(e,t){return e[2]?bp:wp}let _=I(t),R=_(t);function O(e,t){return e[3]?xp:kp}let L=O(t),P=L(t);return{c(){n=h("header"),o=h("div"),i=h("img"),c=g(),R.c(),f=g(),y=h("div"),m=h("button"),m.textContent="🔍",b=g(),k=h("button"),x=p(T),C=g(),P.c(),a(i.src,s="/orly.png")||w(i,"src","/orly.png"),w(i,"alt","ORLY Logo"),w(i,"class","logo svelte-1mrm2k6"),w(m,"class","search-btn svelte-1mrm2k6"),w(k,"class","theme-toggle-btn svelte-1mrm2k6"),w(y,"class","header-buttons svelte-1mrm2k6"),w(o,"class","header-content svelte-1mrm2k6"),w(n,"class","main-header svelte-1mrm2k6"),S(n,"dark-theme",t[1])},m(e,r){u(e,n,r),l(n,o),l(o,i),l(o,c),R.m(o,null),l(o,f),l(o,y),l(y,m),l(y,b),l(y,k),l(k,x),l(y,C),P.m(y,null),A||($=[v(m,"click",t[9]),v(k,"click",t[10])],A=!0)},p(e,[t]){_===(_=I(e))&&R?R.p(e,t):(R.d(1),R=_(e),R&&(R.c(),R.m(o,f))),2&t&&T!==(T=e[1]?"☀️":"🌙")&&E(x,T),L===(L=O(e))&&P?P.p(e,t):(P.d(1),P=L(e),P&&(P.c(),P.m(y,null))),2&t&&S(n,"dark-theme",e[1])},i:e,o:e,d(e){e&&d(n),R.d(),P.d(),A=!1,r($)}}}function $p(e,t,n){let{isDarkTheme:r=!1}=t,{isSearchMode:o=!1}=t,{searchQuery:i=""}=t,{isLoggedIn:s=!1}=t,{userRole:a=""}=t,{currentEffectiveRole:c=""}=t,{userProfile:l=null}=t,{userPubkey:u=""}=t;const d=T();return e.$$set=e=>{"isDarkTheme"in e&&n(1,r=e.isDarkTheme),"isSearchMode"in e&&n(2,o=e.isSearchMode),"searchQuery"in e&&n(0,i=e.searchQuery),"isLoggedIn"in e&&n(3,s=e.isLoggedIn),"userRole"in e&&n(4,a=e.userRole),"currentEffectiveRole"in e&&n(5,c=e.currentEffectiveRole),"userProfile"in e&&n(6,l=e.userProfile),"userPubkey"in e&&n(7,u=e.userPubkey)},[i,r,o,s,a,c,l,u,function(e){d("searchKeydown",e)},function(){d("toggleSearchMode")},function(){d("toggleTheme")},function(){d("openSettingsDrawer")},function(){d("openLoginModal")},function(){i=this.value,n(0,i)}]}class Tp extends ee{constructor(e){super(),X(this,e,$p,Ap,i,{isDarkTheme:1,isSearchMode:2,searchQuery:0,isLoggedIn:3,userRole:4,currentEffectiveRole:5,userProfile:6,userPubkey:7})}}function Ip(e,t,n){const r=e.slice();return r[9]=t[n],r}function _p(e){let t,n,o;function i(){return e[5](e[9])}function s(...t){return e[6](e[9],...t)}return{c(){t=h("span"),t.textContent="✕",w(t,"class","tab-close-icon svelte-1tm0fmz"),w(t,"role","button"),w(t,"tabindex","0")},m(e,r){u(e,t,r),n||(o=[v(t,"click",m(i)),v(t,"keydown",s)],n=!0)},p(t,n){e=t},d(e){e&&d(t),n=!1,r(o)}}}function Rp(e){let t,n,r,o,i,s,a,c,f,y,m=e[9].icon+"",b=e[9].label+"",k=e[9].isSearchTab&&_p(e);function x(){return e[7](e[9])}return{c(){t=h("button"),n=h("span"),r=p(m),o=g(),i=h("span"),s=p(b),a=g(),k&&k.c(),c=g(),w(n,"class","tab-icon svelte-1tm0fmz"),w(i,"class","tab-label svelte-1tm0fmz"),w(t,"class","tab svelte-1tm0fmz"),S(t,"active",e[2]===e[9].id)},m(e,d){u(e,t,d),l(t,n),l(n,r),l(t,o),l(t,i),l(i,s),l(t,a),k&&k.m(t,null),l(t,c),f||(y=v(t,"click",x),f=!0)},p(n,o){e=n,2&o&&m!==(m=e[9].icon+"")&&E(r,m),2&o&&b!==(b=e[9].label+"")&&E(s,b),e[9].isSearchTab?k?k.p(e,o):(k=_p(e),k.c(),k.m(t,c)):k&&(k.d(1),k=null),6&o&&S(t,"active",e[2]===e[9].id)},d(e){e&&d(t),k&&k.d(),f=!1,y()}}}function Op(t){let n,r,o,i=t[1],s=[];for(let e=0;e{"isDarkTheme"in e&&n(0,r=e.isDarkTheme),"tabs"in e&&n(1,o=e.tabs),"selectedTab"in e&&n(2,i=e.selectedTab)},[r,o,i,a,c,e=>c(e.id),(e,t)=>"Enter"===t.key&&c(e.id),e=>a(e.id)]}class Pp extends ee{constructor(e){super(),X(this,e,Lp,Op,i,{isDarkTheme:0,tabs:1,selectedTab:2})}}function Bp(t){let n,r,o,i,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in to access export functionality.",o=g(),i=h("button"),i.textContent="Log In",w(r,"class","svelte-1qkvicp"),w(i,"class","login-btn svelte-1qkvicp"),w(n,"class","login-prompt svelte-1qkvicp")},m(e,c){u(e,n,c),l(n,r),l(n,o),l(n,i),s||(a=v(i,"click",t[4]),s=!0)},p:e,d(e){e&&d(n),s=!1,a()}}}function jp(e){let t,n,r,o,i,s,a,c,f,p,m=("admin"===e[1]||"owner"===e[1])&&Np(e);return{c(){t=h("div"),n=h("h3"),n.textContent="Export My Events",r=g(),o=h("p"),o.textContent="Download your personal events as a JSONL file.",i=g(),s=h("button"),s.textContent="📤 Export My Events",a=g(),m&&m.c(),c=y(),w(n,"class","svelte-1qkvicp"),w(o,"class","svelte-1qkvicp"),w(s,"class","export-btn svelte-1qkvicp"),w(t,"class","export-section svelte-1qkvicp")},m(d,h){u(d,t,h),l(t,n),l(t,r),l(t,o),l(t,i),l(t,s),u(d,a,h),m&&m.m(d,h),u(d,c,h),f||(p=v(s,"click",e[2]),f=!0)},p(e,t){"admin"===e[1]||"owner"===e[1]?m?m.p(e,t):(m=Np(e),m.c(),m.m(c.parentNode,c)):m&&(m.d(1),m=null)},d(e){e&&d(t),e&&d(a),m&&m.d(e),e&&d(c),f=!1,p()}}}function Np(t){let n,r,o,i,s,a,c,f;return{c(){n=h("div"),r=h("h3"),r.textContent="Export All Events",o=g(),i=h("p"),i.textContent="Download the complete database as a JSONL file. This includes\n all events from all users.",s=g(),a=h("button"),a.textContent="📤 Export All Events",w(r,"class","svelte-1qkvicp"),w(i,"class","svelte-1qkvicp"),w(a,"class","export-btn svelte-1qkvicp"),w(n,"class","export-section svelte-1qkvicp")},m(e,d){u(e,n,d),l(n,r),l(n,o),l(n,i),l(n,s),l(n,a),c||(f=v(a,"click",t[3]),c=!0)},p:e,d(e){e&&d(n),c=!1,f()}}}function Up(t){let n;function r(e,t){return e[0]?jp:Bp}let o=r(t),i=o(t);return{c(){i.c(),n=y()},m(e,t){i.m(e,t),u(e,n,t)},p(e,[t]){o===(o=r(e))&&i?i.p(e,t):(i.d(1),i=o(e),i&&(i.c(),i.m(n.parentNode,n)))},i:e,o:e,d(e){i.d(e),e&&d(n)}}}function Mp(e,t,n){let{isLoggedIn:r=!1}=t,{currentEffectiveRole:o=""}=t;const i=T();return e.$$set=e=>{"isLoggedIn"in e&&n(0,r=e.isLoggedIn),"currentEffectiveRole"in e&&n(1,o=e.currentEffectiveRole)},[r,o,function(){i("exportMyEvents")},function(){i("exportAllEvents")},function(){i("openLoginModal")}]}class Fp extends ee{constructor(e){super(),X(this,e,Mp,Up,i,{isLoggedIn:0,currentEffectiveRole:1})}}function Dp(t){let n,r,o,i,s,a,c,f;return{c(){n=h("div"),r=h("h3"),r.textContent="Import Events",o=g(),i=h("p"),i.textContent="Please log in to access import functionality.",s=g(),a=h("button"),a.textContent="Log In",w(r,"class","recovery-header svelte-1nvu2m9"),w(i,"class","recovery-description svelte-1nvu2m9"),w(a,"class","login-btn svelte-1nvu2m9"),w(n,"class","login-prompt svelte-1nvu2m9")},m(e,d){u(e,n,d),l(n,r),l(n,o),l(n,i),l(n,s),l(n,a),c||(f=v(a,"click",t[5]),c=!0)},p:e,d(e){e&&d(n),c=!1,f()}}}function Hp(t){let n;return{c(){n=h("div"),n.innerHTML='

Import Events

\n

❌ Admin or owner permission required for import functionality.

',w(n,"class","permission-denied svelte-1nvu2m9")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function qp(e){let t,n,o,i,s,a,c,f,y,m,b,E;return{c(){t=h("h3"),t.textContent="Import Events",n=g(),o=h("p"),o.textContent="Upload a JSONL file to import events into the database.",i=g(),s=h("div"),a=h("input"),c=g(),f=h("button"),y=p("Import Events"),w(t,"class","svelte-1nvu2m9"),w(o,"class","svelte-1nvu2m9"),w(a,"type","file"),w(a,"id","import-file"),w(a,"accept",".jsonl,.txt"),w(a,"class","svelte-1nvu2m9"),w(f,"class","import-btn svelte-1nvu2m9"),f.disabled=m=!e[2],w(s,"class","recovery-controls-card svelte-1nvu2m9")},m(r,d){u(r,t,d),u(r,n,d),u(r,o,d),u(r,i,d),u(r,s,d),l(s,a),l(s,c),l(s,f),l(f,y),b||(E=[v(a,"change",e[3]),v(f,"click",e[4])],b=!0)},p(e,t){4&t&&m!==(m=!e[2])&&(f.disabled=m)},d(e){e&&d(t),e&&d(n),e&&d(o),e&&d(i),e&&d(s),b=!1,r(E)}}}function zp(t){let n;function r(e,t){return!e[0]||"admin"!==e[1]&&"owner"!==e[1]?e[0]?Hp:Dp:qp}let o=r(t),i=o(t);return{c(){n=h("div"),i.c(),w(n,"class","import-section svelte-1nvu2m9")},m(e,t){u(e,n,t),i.m(n,null)},p(e,[t]){o===(o=r(e))&&i?i.p(e,t):(i.d(1),i=o(e),i&&(i.c(),i.m(n,null)))},i:e,o:e,d(e){e&&d(n),i.d()}}}function Kp(e,t,n){let{isLoggedIn:r=!1}=t,{currentEffectiveRole:o=""}=t,{selectedFile:i=null}=t;const s=T();return e.$$set=e=>{"isLoggedIn"in e&&n(0,r=e.isLoggedIn),"currentEffectiveRole"in e&&n(1,o=e.currentEffectiveRole),"selectedFile"in e&&n(2,i=e.selectedFile)},[r,o,i,function(e){s("fileSelect",e)},function(){s("importEvents")},function(){s("openLoginModal")}]}class Wp extends ee{constructor(e){super(),X(this,e,Kp,zp,i,{isLoggedIn:0,currentEffectiveRole:1,selectedFile:2})}}function Vp(e,t,n){const r=e.slice();return r[22]=t[n],r}function Jp(e,t,n){const r=e.slice();return r[25]=t[n],r}function Gp(t){let n;return{c(){n=h("div"),n.innerHTML="

❌ Write, admin, or owner permission required to view all\n events.

",w(n,"class","permission-denied svelte-kvggf0")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Zp(e){let t,n,r,o;function i(e,t){return e[4].length>0?Yp:e[6]?void 0:Qp}let s=i(e),a=s&&s(e),c=e[6]&&sg();return{c(){t=h("div"),a&&a.c(),n=g(),c&&c.c(),w(t,"class","events-view-content svelte-kvggf0")},m(i,s){u(i,t,s),a&&a.m(t,null),l(t,n),c&&c.m(t,null),r||(o=v(t,"scroll",e[7]),r=!0)},p(e,r){s===(s=i(e))&&a?a.p(e,r):(a&&a.d(1),a=s&&s(e),a&&(a.c(),a.m(t,n))),e[6]?c||(c=sg(),c.c(),c.m(t,null)):c&&(c.d(1),c=null)},d(e){e&&d(t),a&&a.d(),c&&c.d(),r=!1,o()}}}function Qp(t){let n;return{c(){n=h("div"),n.innerHTML="

No events found.

",w(n,"class","no-events svelte-kvggf0")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Yp(e){let t,n=e[4],r=[];for(let t=0;t0&&tg(e);return{c(){t=h("div"),n=h("span"),n.textContent="🗑️ Delete Event",r=g(),o&&o.c(),w(n,"class","delete-event-label svelte-kvggf0"),w(t,"class","delete-event-info svelte-kvggf0")},m(e,i){u(e,t,i),l(t,n),l(t,r),o&&o.m(t,null)},p(e,n){e[22].tags&&e[22].tags.length>0?o?o.p(e,n):(o=tg(e),o.c(),o.m(t,null)):o&&(o.d(1),o=null)},d(e){e&&d(t),o&&o.d()}}}function tg(e){let t,n=e[22].tags.filter(gg),r=[];for(let t=0;t👤',i=g(),s=h("div"),a=h("div"),c=p(j),f=g(),y=h("div"),m=h("span"),b=p(N),k=g(),x=h("span"),C=p(U),A=g(),$=h("div"),T=h("div"),I=p(M),_=g(),q.c(),R=g(),z&&z.c(),O=g(),V&&V.c(),L=g(),w(o,"class","events-view-avatar svelte-kvggf0"),w(a,"class","events-view-author svelte-kvggf0"),w(m,"class","kind-number svelte-kvggf0"),S(m,"delete-event",5===e[22].kind),w(x,"class","kind-name svelte-kvggf0"),w(y,"class","events-view-kind svelte-kvggf0"),w(s,"class","events-view-info svelte-kvggf0"),w(T,"class","event-timestamp svelte-kvggf0"),w($,"class","events-view-content svelte-kvggf0"),w(n,"class","events-view-row svelte-kvggf0"),w(n,"role","button"),w(n,"tabindex","0"),w(t,"class","events-view-item svelte-kvggf0"),S(t,"expanded",e[5].has(e[22].id))},m(e,r){u(e,t,r),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(s,f),l(s,y),l(y,m),l(m,b),l(y,k),l(y,x),l(x,C),l(n,A),l(n,$),l($,T),l(T,I),l($,_),q.m($,null),l(n,R),z&&z.m(n,null),l(t,O),V&&V.m(t,null),l(t,L),P||(B=[v(n,"click",K),v(n,"keydown",W)],P=!0)},p(r,o){e=r,16&o&&j!==(j=dg(e[22].pubkey)+"")&&E(c,j),16&o&&N!==(N=e[22].kind+"")&&E(b,N),16&o&&S(m,"delete-event",5===e[22].kind),16&o&&U!==(U=fg(e[22].kind)+"")&&E(C,U),16&o&&M!==(M=hg(e[22].created_at)+"")&&E(I,M),H===(H=D(e))&&q?q.p(e,o):(q.d(1),q=H(e),q&&(q.c(),q.m($,null))),5!==e[22].kind&&("admin"===e[2]||"owner"===e[2]||"write"===e[2]&&e[22].pubkey&&e[22].pubkey===e[3])?z?z.p(e,o):(z=rg(e),z.c(),z.m(n,null)):z&&(z.d(1),z=null),48&o&&(F=e[5].has(e[22].id)),F?V?V.p(e,o):(V=og(e),V.c(),V.m(t,L)):V&&(V.d(1),V=null),48&o&&S(t,"expanded",e[5].has(e[22].id))},d(e){e&&d(t),q.d(),z&&z.d(),V&&V.d(),P=!1,r(B)}}}function sg(e){let t;return{c(){t=h("div"),t.innerHTML='
\n

Loading events...

',w(t,"class","loading-events svelte-kvggf0")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function ag(e){let t,n,o,i,s,a,c,f,y,m,b,E,k,x,S,C;function A(e,t){return e[6]?lg:cg}let $=A(e),T=$(e);return{c(){t=h("div"),n=h("div"),o=h("label"),i=h("input"),s=g(),a=h("span"),c=g(),f=h("span"),f.textContent="Only show my events",y=g(),m=h("div"),b=h("button"),E=p("🔄 Load More"),k=g(),x=h("button"),T.c(),w(i,"type","checkbox"),w(i,"class","svelte-kvggf0"),w(a,"class","toggle-slider svelte-kvggf0"),w(f,"class","toggle-label svelte-kvggf0"),w(o,"class","toggle-container svelte-kvggf0"),w(n,"class","events-view-toggle svelte-kvggf0"),w(b,"class","refresh-btn svelte-kvggf0"),b.disabled=e[6],w(x,"class","reload-btn svelte-kvggf0"),x.disabled=e[6],w(m,"class","events-view-buttons svelte-kvggf0"),w(t,"class","events-view-header svelte-kvggf0")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(o,i),i.checked=e[0],l(o,s),l(o,a),l(o,c),l(o,f),l(t,y),l(t,m),l(m,b),l(b,E),l(m,k),l(m,x),T.m(x,null),S||(C=[v(i,"change",e[17]),v(i,"change",e[18]),v(b,"click",e[19]),v(x,"click",e[20])],S=!0)},p(e,t){1&t&&(i.checked=e[0]),64&t&&(b.disabled=e[6]),$!==($=A(e))&&(T.d(1),T=$(e),T&&(T.c(),T.m(x,null))),64&t&&(x.disabled=e[6])},d(e){e&&d(t),T.d(),S=!1,r(C)}}}function cg(e){let t;return{c(){t=p("🔄")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function lg(e){let t;return{c(){t=h("div"),w(t,"class","spinner svelte-kvggf0")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function ug(t){let n,r;function o(e,t){return!e[1]||"write"!==e[2]&&"admin"!==e[2]&&"owner"!==e[2]?Gp:Zp}let i=o(t),s=i(t),a=t[1]&&("write"===t[2]||"admin"===t[2]||"owner"===t[2])&&ag(t);return{c(){n=h("div"),s.c(),r=g(),a&&a.c(),w(n,"class","events-view-container svelte-kvggf0")},m(e,t){u(e,n,t),s.m(n,null),l(n,r),a&&a.m(n,null)},p(e,[t]){i===(i=o(e))&&s?s.p(e,t):(s.d(1),s=i(e),s&&(s.c(),s.m(n,r))),!e[1]||"write"!==e[2]&&"admin"!==e[2]&&"owner"!==e[2]?a&&(a.d(1),a=null):a?a.p(e,t):(a=ag(e),a.c(),a.m(n,null))},i:e,o:e,d(e){e&&d(n),s.d(),a&&a.d()}}}function dg(e){return e?e.slice(0,8)+"..."+e.slice(-8):""}function fg(e){return{0:"Profile",1:"Text Note",2:"Recommend Relay",3:"Contacts",4:"Encrypted DM",5:"Delete",6:"Repost",7:"Reaction",8:"Badge Award",16:"Generic Repost",40:"Channel Creation",41:"Channel Metadata",42:"Channel Message",43:"Channel Hide Message",44:"Channel Mute User",1984:"Reporting",9734:"Zap Request",9735:"Zap",1e4:"Mute List",10001:"Pin List",10002:"Relay List",22242:"Client Auth",24133:"Nostr Connect",27235:"HTTP Auth",3e4:"Categorized People",30001:"Categorized Bookmarks",30008:"Profile Badges",30009:"Badge Definition",30017:"Create or update a stall",30018:"Create or update a product",30023:"Long-form Content",30024:"Draft Long-form Content",30078:"Application-specific Data",30311:"Live Event",30315:"User Statuses",30402:"Classified Listing",30403:"Draft Classified Listing",31922:"Date-Based Calendar Event",31923:"Time-Based Calendar Event",31924:"Calendar",31925:"Calendar Event RSVP",31989:"Handler recommendation",31990:"Handler information",34550:"Community Definition"}[e]||`Kind ${e}`}function hg(e){return new Date(1e3*e).toLocaleString()}function pg(e){return e?e.length>100?e.slice(0,100)+"...":e:""}const gg=e=>"e"===e[0];function yg(e,t,n){let{isLoggedIn:r=!1}=t,{userRole:o=""}=t,{userPubkey:i=""}=t,{filteredEvents:s=[]}=t,{expandedEvents:a=new Set}=t,{isLoadingEvents:c=!1}=t,{showOnlyMyEvents:l=!1}=t;const u=T();function d(e){u("toggleEventExpansion",e)}function f(e){u("deleteEvent",e)}function h(e,t){u("copyEventToClipboard",{event:e,e:t})}function p(){u("toggleChange")}function g(e,t){u("loadAllEvents",{refresh:e,authors:t})}return e.$$set=e=>{"isLoggedIn"in e&&n(1,r=e.isLoggedIn),"userRole"in e&&n(2,o=e.userRole),"userPubkey"in e&&n(3,i=e.userPubkey),"filteredEvents"in e&&n(4,s=e.filteredEvents),"expandedEvents"in e&&n(5,a=e.expandedEvents),"isLoadingEvents"in e&&n(6,c=e.isLoadingEvents),"showOnlyMyEvents"in e&&n(0,l=e.showOnlyMyEvents)},[l,r,o,i,s,a,c,function(e){u("scroll",e)},d,f,h,p,g,e=>f(e.id),e=>d(e.id),(e,t)=>"Enter"===t.key&&d(e.id),(e,t)=>h(e,t),function(){l=this.checked,n(0,l)},()=>p(),()=>{g(!1,l&&i?[i]:null)},()=>{g(!0,l&&i?[i]:null)}]}class vg extends ee{constructor(e){super(),X(this,e,yg,ug,i,{isLoggedIn:1,userRole:2,userPubkey:3,filteredEvents:4,expandedEvents:5,isLoadingEvents:6,showOnlyMyEvents:0})}}function mg(t){let n,o,i,s,a,c,f,p,y,m,b,E;return{c(){n=h("div"),o=h("div"),i=h("button"),i.textContent="Reformat",s=g(),a=h("button"),a.textContent="Sign",c=g(),f=h("button"),f.textContent="Publish",p=g(),y=h("div"),m=h("textarea"),w(i,"class","compose-btn reformat-btn svelte-mkdcsl"),w(a,"class","compose-btn sign-btn svelte-mkdcsl"),w(f,"class","compose-btn publish-btn svelte-mkdcsl"),w(o,"class","compose-header svelte-mkdcsl"),w(m,"class","compose-textarea svelte-mkdcsl"),w(m,"placeholder","Enter your Nostr event JSON here..."),w(m,"spellcheck","false"),w(y,"class","compose-editor svelte-mkdcsl"),w(n,"class","compose-view svelte-mkdcsl")},m(e,r){u(e,n,r),l(n,o),l(o,i),l(o,s),l(o,a),l(o,c),l(o,f),l(n,p),l(n,y),l(y,m),k(m,t[0]),b||(E=[v(i,"click",t[1]),v(a,"click",t[2]),v(f,"click",t[3]),v(m,"input",t[4])],b=!0)},p(e,[t]){1&t&&k(m,e[0])},i:e,o:e,d(e){e&&d(n),b=!1,r(E)}}}function wg(e,t,n){let{composeEventJson:r=""}=t;const o=T();return e.$$set=e=>{"composeEventJson"in e&&n(0,r=e.composeEventJson)},[r,function(){o("reformatJson")},function(){o("signEvent")},function(){o("publishEvent")},function(){r=this.value,n(0,r)}]}class bg extends ee{constructor(e){super(),X(this,e,wg,mg,i,{composeEventJson:0})}}function Eg(e,t,n){const r=e.slice();return r[23]=t[n],r}function kg(t){let n,r,o,i,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in to access sprocket management.",o=g(),i=h("button"),i.textContent="Log In",w(r,"class","svelte-fiaj1r"),w(i,"class","login-btn svelte-fiaj1r"),w(n,"class","login-prompt svelte-fiaj1r")},m(e,c){u(e,n,c),l(n,r),l(n,o),l(n,i),s||(a=v(i,"click",t[18]),s=!0)},p:e,d(e){e&&d(n),s=!1,a()}}}function xg(e){let t,n,r,o,i,s,a,c,f,y=(e[2]||"none")+"";return{c(){t=h("div"),n=h("p"),n.textContent="❌ Owner permission required for sprocket management.",r=g(),o=h("p"),o.innerHTML='To enable sprocket functionality, set the ORLY_OWNERS environment variable with your npub when starting the relay.',i=g(),s=h("p"),a=p("Current user role: "),c=h("strong"),f=p(y),w(n,"class","svelte-fiaj1r"),w(o,"class","svelte-fiaj1r"),w(s,"class","svelte-fiaj1r"),w(t,"class","permission-denied svelte-fiaj1r")},m(e,d){u(e,t,d),l(t,n),l(t,r),l(t,o),l(t,i),l(t,s),l(s,a),l(s,c),l(c,f)},p(e,t){4&t&&y!==(y=(e[2]||"none")+"")&&E(f,y)},d(e){e&&d(t)}}}function Sg(e){let t,n,o,i,s,a,c,y,m,b,x,C,A,$,T,I,_,R,O,L,P,B,j,N,U,M,F,D,H,q,z,K,W,V,J,G,Z,Q,Y,X,ee,te,ne,re,oe,ie,se,ae,ce,le,ue,de,fe,he,pe,ge,ye=e[3]?.is_running?"🟢 Running":"🔴 Stopped",ve=e[3]?.script_exists?"✅ Exists":"❌ Not found",me=e[3]?.pid&&Cg(e),we=e[6]&&Ag(e),be=e[8],Ee=[];for(let t=0;t{"isLoggedIn"in e&&n(1,r=e.isLoggedIn),"userRole"in e&&n(2,o=e.userRole),"sprocketStatus"in e&&n(3,i=e.sprocketStatus),"isLoadingSprocket"in e&&n(4,s=e.isLoadingSprocket),"sprocketUploadFile"in e&&n(5,a=e.sprocketUploadFile),"sprocketScript"in e&&n(0,c=e.sprocketScript),"sprocketMessage"in e&&n(6,l=e.sprocketMessage),"sprocketMessageType"in e&&n(7,u=e.sprocketMessageType),"sprocketVersions"in e&&n(8,d=e.sprocketVersions)},[c,r,o,i,s,a,l,u,d,function(){f("restartSprocket")},function(){f("deleteSprocket")},function(e){f("sprocketFileSelect",e)},function(){f("uploadSprocketScript")},function(){f("saveSprocket")},function(){f("loadSprocket")},function(){f("loadVersions")},h,p,function(){f("openLoginModal")},function(){c=this.value,n(0,c)},e=>h(e),e=>p(e.name)]}class Og extends ee{constructor(e){super(),X(this,e,Rg,_g,i,{isLoggedIn:1,userRole:2,sprocketStatus:3,isLoadingSprocket:4,sprocketUploadFile:5,sprocketScript:0,sprocketMessage:6,sprocketMessageType:7,sprocketVersions:8})}}class Lg{constructor(e,t,n){this.relayUrl=e,this.userSigner=t,this.userPubkey=n,this.ws=null,this.challenge=null,this.isAuthenticated=!1,this.authPromise=null}async connect(){return new Promise((e,t)=>{this.ws=new WebSocket(this.relayUrl),this.ws.onopen=()=>{console.log("WebSocket connected to relay:",this.relayUrl),e()},this.ws.onmessage=async e=>{try{const t=JSON.parse(e.data);await this.handleMessage(t)}catch(e){console.error("Error parsing relay message:",e)}},this.ws.onerror=e=>{console.error("WebSocket error:",e),t(new Error("Failed to connect to relay"))},this.ws.onclose=()=>{console.log("WebSocket connection closed"),this.isAuthenticated=!1,this.challenge=null},setTimeout(()=>{this.ws.readyState!==WebSocket.OPEN&&t(new Error("Connection timeout"))},1e4)})}async handleMessage(e){const[t,...n]=e;switch(t){case"AUTH":this.challenge=n[0],console.log("Received AUTH challenge:",this.challenge),await this.authenticate();break;case"OK":const[e,r,o]=n;e&&r?(console.log("Authentication successful for event:",e),this.isAuthenticated=!0,this.authPromise&&(this.authPromise.resolve(),this.authPromise=null)):e&&!r&&(console.error("Authentication failed:",o),this.authPromise&&(this.authPromise.reject(new Error(o||"Authentication failed")),this.authPromise=null));break;case"NOTICE":console.log("Relay notice:",n[0]);break;default:console.log("Unhandled message type:",t,n)}}async authenticate(){if(!this.challenge)throw new Error("No challenge received from relay");if(!this.userSigner)throw new Error("No signer available for authentication");try{const e={kind:22242,created_at:Math.floor(Date.now()/1e3),tags:[["relay",this.relayUrl],["challenge",this.challenge]],content:"",pubkey:this.userPubkey},t=["AUTH",await this.userSigner.signEvent(e)];return this.ws.send(JSON.stringify(t)),console.log("Sent authentication event to relay"),new Promise((e,t)=>{this.authPromise={resolve:e,reject:t},setTimeout(()=>{this.authPromise&&(this.authPromise.reject(new Error("Authentication timeout")),this.authPromise=null)},1e4)})}catch(e){throw console.error("Authentication error:",e),e}}async publishEvent(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("WebSocket not connected");return new Promise((t,n)=>{const r=["EVENT",e];this.ws.send(JSON.stringify(r));const o=this.ws.onmessage,i=setTimeout(()=>{this.ws.onmessage=o,n(new Error("Publish timeout"))},15e3);this.ws.onmessage=async r=>{try{const s=JSON.parse(r.data),[a,c,l,u]=s;if("OK"===a&&c===e.id)if(clearTimeout(i),this.ws.onmessage=o,l)console.log("Event published successfully:",c),t({success:!0,eventId:c,reason:u});else{if(console.error("Event publish failed:",u),u&&u.includes("auth-required")){console.log("Authentication required, attempting to authenticate...");try{await this.authenticate();const t=["EVENT",e];return void this.ws.send(JSON.stringify(t))}catch(e){return void n(new Error(`Authentication failed: ${e.message}`))}}n(new Error(`Publish failed: ${u}`))}else await this.handleMessage(s)}catch(e){clearTimeout(i),this.ws.onmessage=o,n(e)}}})}close(){this.ws&&(this.ws.close(),this.ws=null),this.isAuthenticated=!1,this.challenge=null}getAuthenticated(){return this.isAuthenticated}}async function Pg(e,t,n,r){const o=new Lg(e,n,r);try{await o.connect();return await o.publishEvent(t)}finally{o.close()}}function Bg(e,t,n){const r=e.slice();return r[147]=t[n],r}function jg(e,t,n){const r=e.slice();return r[157]=t[n],r}function Ng(e,t,n){const r=e.slice();return r[150]=t[n],r}function Ug(e,t,n){const r=e.slice();r[150]=t[n];const o=r[44](r[150]);return r[151]=o,r}function Mg(e,t,n){const r=e.slice();return r[154]=t[n],r}function Fg(t){let n;function r(e,t){return e[1]?Zg:Gg}let o=r(t),i=o(t);return{c(){n=h("div"),i.c(),w(n,"class","welcome-message svelte-14c8ed4")},m(e,t){u(e,n,t),i.m(n,null)},p(e,t){o===(o=r(e))&&i?i.p(e,t):(i.d(1),i=o(e),i&&(i.c(),i.m(n,null)))},i:e,o:e,d(e){e&&d(n),i.d()}}}function Dg(t){let n,r=t[6],o=[];for(let e=0;e=0||""!==t[27]&&parseInt(t[27])>=0,L=t[34],P=[];for(let e=0;eEvent Recovery \n

Search and recover old versions of replaceable events

',i=g(),s=h("div"),a=h("div"),c=h("div"),p=h("label"),p.textContent="Select Event Kind:",y=g(),m=h("select"),E=h("option"),E.textContent="Choose a replaceable kind...";for(let e=0;et[97].call(m)),w(c,"class","kind-selector svelte-14c8ed4"),w(A,"for","custom-kind"),w(A,"class","svelte-14c8ed4"),w(T,"id","custom-kind"),w(T,"type","number"),w(T,"placeholder","e.g., 10001"),w(T,"min","0"),w(T,"class","svelte-14c8ed4"),w(C,"class","custom-kind-input svelte-14c8ed4"),w(a,"class","recovery-controls svelte-14c8ed4"),w(s,"class","recovery-controls-card svelte-14c8ed4"),w(n,"class","recovery-tab svelte-14c8ed4")},m(e,r){u(e,n,r),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(c,p),l(c,y),l(c,m),l(m,E);for(let e=0;e=0||""!==e[27]&&parseInt(e[27])>=0),O?B?B.p(e,t):(B=ay(e),B.c(),B.m(n,null)):B&&(B.d(1),B=null)},i:e,o:e,d(e){e&&d(n),f(P,e),B&&B.d(),_=!1,r(R)}}}function qg(e){let t,n,r;function o(t){e[94](t)}let i={isLoggedIn:e[1],userRole:e[4],sprocketStatus:e[19],isLoadingSprocket:e[21],sprocketUploadFile:e[24],sprocketMessage:e[22],sprocketMessageType:e[23],sprocketVersions:e[20]};return void 0!==e[18]&&(i.sprocketScript=e[18]),t=new Og({props:i}),R.push(()=>J(t,"sprocketScript",o)),t.$on("restartSprocket",e[47]),t.$on("deleteSprocket",e[48]),t.$on("sprocketFileSelect",e[52]),t.$on("uploadSprocketScript",e[53]),t.$on("saveSprocket",e[46]),t.$on("loadSprocket",e[45]),t.$on("loadVersions",e[49]),t.$on("loadVersion",e[95]),t.$on("deleteVersion",e[96]),t.$on("openLoginModal",e[56]),{c(){G(t.$$.fragment)},m(e,n){Z(t,e,n),r=!0},p(e,r){const o={};2&r[0]&&(o.isLoggedIn=e[1]),16&r[0]&&(o.userRole=e[4]),524288&r[0]&&(o.sprocketStatus=e[19]),2097152&r[0]&&(o.isLoadingSprocket=e[21]),16777216&r[0]&&(o.sprocketUploadFile=e[24]),4194304&r[0]&&(o.sprocketMessage=e[22]),8388608&r[0]&&(o.sprocketMessageType=e[23]),1048576&r[0]&&(o.sprocketVersions=e[20]),!n&&262144&r[0]&&(n=!0,o.sprocketScript=e[18],N(()=>n=!1)),t.$set(o)},i(e){r||(W(t.$$.fragment,e),r=!0)},o(e){V(t.$$.fragment,e),r=!1},d(e){Q(t,e)}}}function zg(e){let t,n,r,o;const i=[my,vy,yy],s=[];function a(e,t){return"managed"!==e[7]?0:e[1]&&"owner"===e[4]?1:2}return n=a(e),r=s[n]=i[n](e),{c(){t=h("div"),r.c(),w(t,"class","managed-acl-view svelte-14c8ed4")},m(e,r){u(e,t,r),s[n].m(t,null),o=!0},p(e,o){let c=n;n=a(e),n===c?s[n].p(e,o):(z(),V(s[c],1,1,()=>{s[c]=null}),K(),r=s[n],r?r.p(e,o):(r=s[n]=i[n](e),r.c()),W(r,1),r.m(t,null))},i(e){o||(W(r),o=!0)},o(e){V(r),o=!1},d(e){e&&d(t),s[n].d()}}}function Kg(e){let t,n,r;function o(t){e[93](t)}let i={};return void 0!==e[25]&&(i.composeEventJson=e[25]),t=new bg({props:i}),R.push(()=>J(t,"composeEventJson",o)),t.$on("reformatJson",e[74]),t.$on("signEvent",e[75]),t.$on("publishEvent",e[76]),{c(){G(t.$$.fragment)},m(e,n){Z(t,e,n),r=!0},p(e,r){const o={};!n&&33554432&r[0]&&(n=!0,o.composeEventJson=e[25],N(()=>n=!1)),t.$set(o)},i(e){r||(W(t.$$.fragment,e),r=!0)},o(e){V(t.$$.fragment,e),r=!1},d(e){Q(t,e)}}}function Wg(e){let t,n;return t=new vg({props:{isLoggedIn:e[1],userRole:e[4],userPubkey:e[2],filteredEvents:e[32],expandedEvents:e[16],isLoadingEvents:e[17],showOnlyMyEvents:_y}}),t.$on("scroll",e[73]),t.$on("toggleEventExpansion",e[89]),t.$on("deleteEvent",e[90]),t.$on("copyEventToClipboard",e[91]),t.$on("toggleChange",e[37]),t.$on("loadAllEvents",e[92]),{c(){G(t.$$.fragment)},m(e,r){Z(t,e,r),n=!0},p(e,n){const r={};2&n[0]&&(r.isLoggedIn=e[1]),16&n[0]&&(r.userRole=e[4]),4&n[0]&&(r.userPubkey=e[2]),2&n[1]&&(r.filteredEvents=e[32]),65536&n[0]&&(r.expandedEvents=e[16]),131072&n[0]&&(r.isLoadingEvents=e[17]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){V(t.$$.fragment,e),n=!1},d(e){Q(t,e)}}}function Vg(e){let t,n;return t=new Wp({props:{isLoggedIn:e[1],currentEffectiveRole:e[8],selectedFile:e[15]}}),t.$on("fileSelect",e[70]),t.$on("importEvents",e[71]),t.$on("openLoginModal",e[56]),{c(){G(t.$$.fragment)},m(e,r){Z(t,e,r),n=!0},p(e,n){const r={};2&n[0]&&(r.isLoggedIn=e[1]),256&n[0]&&(r.currentEffectiveRole=e[8]),32768&n[0]&&(r.selectedFile=e[15]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){V(t.$$.fragment,e),n=!1},d(e){Q(t,e)}}}function Jg(e){let t,n;return t=new Fp({props:{isLoggedIn:e[1],currentEffectiveRole:e[8]}}),t.$on("exportMyEvents",e[69]),t.$on("exportAllEvents",e[68]),t.$on("openLoginModal",e[56]),{c(){G(t.$$.fragment)},m(e,r){Z(t,e,r),n=!0},p(e,n){const r={};2&n[0]&&(r.isLoggedIn=e[1]),256&n[0]&&(r.currentEffectiveRole=e[8]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){V(t.$$.fragment,e),n=!1},d(e){Q(t,e)}}}function Gg(t){let n;return{c(){n=h("p"),n.textContent="Log in to access your user dashboard",w(n,"class","svelte-14c8ed4")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Zg(e){let t,n,r,o=(e[3]?.name||e[2].slice(0,8)+"...")+"";return{c(){t=h("p"),n=p("Welcome "),r=p(o),w(t,"class","svelte-14c8ed4")},m(e,o){u(e,t,o),l(t,n),l(t,r)},p(e,t){12&t[0]&&o!==(o=(e[3]?.name||e[2].slice(0,8)+"...")+"")&&E(r,o)},d(e){e&&d(t)}}}function Qg(e){let t,n,o,i,s,a,c,f,y,m,b,k,x,S,C,A,$,T,I,_=e[157].query+"",R=e[33].get(e[157].id)?.isLoading,O=!e[33].get(e[157].id)?.hasMore&&e[33].get(e[157].id)?.events?.length>0;function L(){return e[102](e[157])}function P(e,t){return 64&t[0]&&(x=null),64&t[0]&&(S=null),null==x&&(x=!!(e[33].get(e[157].id)?.events?.length>0)),x?Xg:(null==S&&(S=!e[33].get(e[157].id)?.isLoading),S?Yg:void 0)}let B=P(e,[-1,-1,-1,-1,-1,-1]),j=B&&B(e),N=R&&ry(),U=O&&oy();function M(...t){return e[107](e[157],...t)}return{c(){t=h("div"),n=h("div"),o=h("h2"),i=p('🔍 Search Results: "'),s=p(_),a=p('"'),c=g(),f=h("button"),y=p("🔄 Refresh"),b=g(),k=h("div"),j&&j.c(),C=g(),N&&N.c(),A=g(),U&&U.c(),$=g(),w(o,"class","svelte-14c8ed4"),w(f,"class","refresh-btn svelte-14c8ed4"),f.disabled=m=e[33].get(e[157].id)?.isLoading,w(n,"class","search-results-header svelte-14c8ed4"),w(k,"class","search-results-content svelte-14c8ed4"),w(t,"class","search-results-view svelte-14c8ed4")},m(e,r){u(e,t,r),l(t,n),l(n,o),l(o,i),l(o,s),l(o,a),l(n,c),l(n,f),l(f,y),l(t,b),l(t,k),j&&j.m(k,null),l(k,C),N&&N.m(k,null),l(k,A),U&&U.m(k,null),l(t,$),T||(I=[v(f,"click",L),v(k,"scroll",M)],T=!0)},p(t,n){e=t,64&n[0]&&_!==(_=e[157].query+"")&&E(s,_),64&n[0]&&m!==(m=e[33].get(e[157].id)?.isLoading)&&(f.disabled=m),B===(B=P(e,n))&&j?j.p(e,n):(j&&j.d(1),j=B&&B(e),j&&(j.c(),j.m(k,C))),64&n[0]&&(R=e[33].get(e[157].id)?.isLoading),R?N||(N=ry(),N.c(),N.m(k,A)):N&&(N.d(1),N=null),64&n[0]&&(O=!e[33].get(e[157].id)?.hasMore&&e[33].get(e[157].id)?.events?.length>0),O?U||(U=oy(),U.c(),U.m(k,null)):U&&(U.d(1),U=null)},d(e){e&&d(t),j&&j.d(),N&&N.d(),U&&U.d(),T=!1,r(I)}}}function Yg(e){let t,n,r,o,i,s=e[157].query+"";return{c(){t=h("div"),n=h("p"),r=p('No search results found for "'),o=p(s),i=p('".'),w(n,"class","svelte-14c8ed4"),w(t,"class","no-search-results svelte-14c8ed4")},m(e,s){u(e,t,s),l(t,n),l(n,r),l(n,o),l(n,i)},p(e,t){64&t[0]&&s!==(s=e[157].query+"")&&E(o,s)},d(e){e&&d(t)}}}function Xg(e){let t,n=e[33].get(e[157].id).events,r=[];for(let t=0;t👤',i=g(),s=h("div"),a=h("div"),c=p(U),f=g(),y=h("div"),m=h("span"),b=p(M),k=g(),x=h("span"),C=p(F),A=g(),$=h("div"),T=h("div"),I=p(D),_=g(),R=h("div"),O=p(H),L=g(),z&&z.c(),P=g(),V&&V.c(),B=g(),w(o,"class","search-result-avatar svelte-14c8ed4"),w(a,"class","search-result-author svelte-14c8ed4"),w(m,"class","kind-number svelte-14c8ed4"),w(x,"class","kind-name svelte-14c8ed4"),w(y,"class","search-result-kind svelte-14c8ed4"),w(s,"class","search-result-info svelte-14c8ed4"),w(T,"class","event-timestamp svelte-14c8ed4"),w(R,"class","event-content-single-line svelte-14c8ed4"),w($,"class","search-result-content svelte-14c8ed4"),w(n,"class","search-result-row svelte-14c8ed4"),w(n,"role","button"),w(n,"tabindex","0"),w(t,"class","search-result-item svelte-14c8ed4"),S(t,"expanded",e[16].has(e[150].id))},m(e,r){u(e,t,r),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(s,f),l(s,y),l(y,m),l(m,b),l(y,k),l(y,x),l(x,C),l(n,A),l(n,$),l($,T),l(T,I),l($,_),l($,R),l(R,O),l(n,L),z&&z.m(n,null),l(t,P),V&&V.m(t,null),l(t,B),j||(N=[v(n,"click",K),v(n,"keydown",W)],j=!0)},p(r,o){e=r,64&o[0]&&U!==(U=Ry(e[150].pubkey)+"")&&E(c,U),64&o[0]&&M!==(M=e[150].kind+"")&&E(b,M),64&o[0]&&F!==(F=e[35](e[150].kind)+"")&&E(C,F),64&o[0]&&D!==(D=Ly(e[150].created_at)+"")&&E(I,D),64&o[0]&&H!==(H=Oy(e[150].content)+"")&&E(O,H),5!==e[150].kind&&("admin"===e[4]||"owner"===e[4]||"write"===e[4]&&e[150].pubkey&&e[150].pubkey===e[2])?z?z.p(e,o):(z=ey(e),z.c(),z.m(n,null)):z&&(z.d(1),z=null),65600&o[0]&&(q=e[16].has(e[150].id)),q?V?V.p(e,o):(V=ty(e),V.c(),V.m(t,B)):V&&(V.d(1),V=null),65600&o[0]|4&o[1]&&S(t,"expanded",e[16].has(e[150].id))},d(e){e&&d(t),z&&z.d(),V&&V.d(),j=!1,r(N)}}}function ry(e){let t;return{c(){t=h("div"),t.innerHTML='
\n

Searching...

',w(t,"class","loading-search-results svelte-14c8ed4")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function oy(e){let t;return{c(){t=h("div"),t.innerHTML='

No more search results to load.

',w(t,"class","end-of-search-results svelte-14c8ed4")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function iy(e){let t,n=e[157].id===e[5]&&Qg(e);return{c(){n&&n.c(),t=y()},m(e,r){n&&n.m(e,r),u(e,t,r)},p(e,r){e[157].id===e[5]?n?n.p(e,r):(n=Qg(e),n.c(),n.m(t.parentNode,t)):n&&(n.d(1),n=null)},d(e){n&&n.d(e),e&&d(t)}}}function sy(t){let n,r,o=t[154].label+"";return{c(){n=h("option"),r=p(o),n.__value=t[154].value,n.value=n.__value},m(e,t){u(e,n,t),l(n,r)},p:e,d(e){e&&d(n)}}}function ay(e){let t;function n(e,t){return e[29]?uy:0===e[28].length?ly:cy}let r=n(e),o=r(e);return{c(){t=h("div"),o.c(),w(t,"class","recovery-results svelte-14c8ed4")},m(e,n){u(e,t,n),o.m(t,null)},p(e,i){r===(r=n(e))&&o?o.p(e,i):(o.d(1),o=r(e),o&&(o.c(),o.m(t,null)))},d(e){e&&d(t),o.d()}}}function cy(e){let t,n,r,o=e[28],i=[];for(let t=0;tORLY_ACL_MODE=managed in your\n environment variables and restart the relay.',w(r,"class","svelte-14c8ed4"),w(i,"class","svelte-14c8ed4"),w(a,"class","svelte-14c8ed4"),w(m,"class","svelte-14c8ed4"),w(n,"class","acl-mode-warning svelte-14c8ed4")},m(e,t){u(e,n,t),l(n,r),l(n,o),l(n,i),l(n,s),l(n,a),l(a,c),l(a,f),l(f,y),l(n,v),l(n,m)},p(e,t){128&t[0]&&b!==(b=(e[7]||"unknown")+"")&&E(y,b)},i:e,o:e,d(e){e&&d(n)}}}function wy(e){let t,n,o,i,s,a,c,f,p,y;function b(e,t){return e[3]?Ey:e[1]&&e[2]?by:void 0}let E=b(e),k=E&&E(e);return{c(){t=h("div"),n=h("div"),o=h("div"),i=h("h2"),i.textContent="Settings",s=g(),a=h("button"),a.textContent="✕",c=g(),f=h("div"),k&&k.c(),w(i,"class","svelte-14c8ed4"),w(a,"class","close-btn svelte-14c8ed4"),w(o,"class","drawer-header svelte-14c8ed4"),w(f,"class","drawer-content"),w(n,"class","settings-drawer svelte-14c8ed4"),S(n,"dark-theme",e[0]),w(t,"class","drawer-overlay svelte-14c8ed4"),w(t,"role","button"),w(t,"tabindex","0")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(o,i),l(o,s),l(o,a),l(n,c),l(n,f),k&&k.m(f,null),p||(y=[v(a,"click",e[61]),v(n,"click",m(e[83])),v(n,"keydown",m(e[84])),v(t,"click",e[61]),v(t,"keydown",e[109])],p=!0)},p(e,t){E===(E=b(e))&&k?k.p(e,t):(k&&k.d(1),k=E&&E(e),k&&(k.c(),k.m(f,null))),1&t[0]&&S(n,"dark-theme",e[0])},d(e){e&&d(t),k&&k.d(),p=!1,r(y)}}}function by(e){let t,n,r,o,i,s,a,c,f,y,m,b,k,x,S,C=e[2].slice(0,16)+"",A=e[2].slice(-8)+"";return{c(){t=h("div"),n=h("h3"),n.textContent="Profile Loading",r=g(),o=h("p"),o.textContent="Your profile metadata is being loaded...",i=g(),s=h("button"),s.textContent="Retry Loading Profile",a=g(),c=h("div"),f=h("strong"),f.textContent="Public Key:",y=g(),m=p(C),b=p("..."),k=p(A),w(n,"class","svelte-14c8ed4"),w(o,"class","svelte-14c8ed4"),w(s,"class","retry-profile-btn svelte-14c8ed4"),w(c,"class","user-pubkey-display svelte-14c8ed4"),w(t,"class","profile-loading-section svelte-14c8ed4")},m(d,h){u(d,t,h),l(t,n),l(t,r),l(t,o),l(t,i),l(t,s),l(t,a),l(t,c),l(c,f),l(c,y),l(c,m),l(c,b),l(c,k),x||(S=v(s,"click",e[67]),x=!0)},p(e,t){4&t[0]&&C!==(C=e[2].slice(0,16)+"")&&E(m,C),4&t[0]&&A!==(A=e[2].slice(-8)+"")&&E(k,A)},d(e){e&&d(t),x=!1,S()}}}function Ey(e){let t,n,r,o,i,s,a,c,f,m,b,k,x,S,C,A=(e[3].name||"Unknown User")+"",$=e[3].banner&&ky(e);function T(e,t){return e[3].picture?Sy:xy}let I=T(e),_=I(e),R=e[3].nip05&&Cy(e),O=e[3].about&&Ay(e),L=e[4]&&"read"!==e[4]&&$y(e);return{c(){t=h("div"),n=h("div"),$&&$.c(),r=g(),o=h("button"),o.textContent="Log out",i=g(),_.c(),s=g(),a=h("div"),c=h("h3"),f=p(A),m=g(),R&&R.c(),b=g(),O&&O.c(),k=g(),L&&L.c(),x=y(),w(o,"class","logout-btn floating svelte-14c8ed4"),w(c,"class","profile-username svelte-14c8ed4"),w(a,"class","name-row svelte-14c8ed4"),w(n,"class","profile-hero svelte-14c8ed4"),w(t,"class","profile-section svelte-14c8ed4")},m(d,h){u(d,t,h),l(t,n),$&&$.m(n,null),l(n,r),l(n,o),l(n,i),_.m(n,null),l(n,s),l(n,a),l(a,c),l(c,f),l(a,m),R&&R.m(a,null),l(t,b),O&&O.m(t,null),u(d,k,h),L&&L.m(d,h),u(d,x,h),S||(C=v(o,"click",e[58]),S=!0)},p(e,o){e[3].banner?$?$.p(e,o):($=ky(e),$.c(),$.m(n,r)):$&&($.d(1),$=null),I===(I=T(e))&&_?_.p(e,o):(_.d(1),_=I(e),_&&(_.c(),_.m(n,s))),8&o[0]&&A!==(A=(e[3].name||"Unknown User")+"")&&E(f,A),e[3].nip05?R?R.p(e,o):(R=Cy(e),R.c(),R.m(a,null)):R&&(R.d(1),R=null),e[3].about?O?O.p(e,o):(O=Ay(e),O.c(),O.m(t,null)):O&&(O.d(1),O=null),e[4]&&"read"!==e[4]?L?L.p(e,o):(L=$y(e),L.c(),L.m(x.parentNode,x)):L&&(L.d(1),L=null)},d(e){e&&d(t),$&&$.d(),_.d(),R&&R.d(),O&&O.d(),e&&d(k),L&&L.d(e),e&&d(x),S=!1,C()}}}function ky(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[3].banner)||w(t,"src",n),w(t,"alt","Profile banner"),w(t,"class","profile-banner svelte-14c8ed4")},m(e,n){u(e,t,n)},p(e,r){8&r[0]&&!a(t.src,n=e[3].banner)&&w(t,"src",n)},d(e){e&&d(t)}}}function xy(t){let n;return{c(){n=h("div"),n.textContent="👤",w(n,"class","profile-avatar-placeholder overlap svelte-14c8ed4")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Sy(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[3].picture)||w(t,"src",n),w(t,"alt","User avatar"),w(t,"class","profile-avatar overlap svelte-14c8ed4")},m(e,n){u(e,t,n)},p(e,r){8&r[0]&&!a(t.src,n=e[3].picture)&&w(t,"src",n)},d(e){e&&d(t)}}}function Cy(e){let t,n,r=e[3].nip05+"";return{c(){t=h("span"),n=p(r),w(t,"class","profile-nip05-inline svelte-14c8ed4")},m(e,r){u(e,t,r),l(t,n)},p(e,t){8&t[0]&&r!==(r=e[3].nip05+"")&&E(n,r)},d(e){e&&d(t)}}}function Ay(e){let t,n;return{c(){t=h("div"),n=h("p"),w(n,"class","profile-about svelte-14c8ed4"),w(t,"class","about-card svelte-14c8ed4")},m(r,o){u(r,t,o),l(t,n),n.innerHTML=e[31]},p(e,t){1&t[1]&&(n.innerHTML=e[31])},d(e){e&&d(t)}}}function $y(e){let t,n,r,o,i,s,a=e[78](),c=[];for(let t=0;tJ(t,"searchQuery",k)),t.$on("searchKeydown",e[63]),t.$on("toggleSearchMode",e[62]),t.$on("toggleTheme",e[55]),t.$on("openSettingsDrawer",e[60]),t.$on("openLoginModal",e[56]),i=new Pp({props:{isDarkTheme:e[0],tabs:e[9],selectedTab:e[5]}}),i.$on("selectTab",e[87]),i.$on("closeSearchTab",e[88]);const C=[Jg,Vg,Wg,Kg,zg,qg,Hg,Dg,Fg],A=[];function $(e,t){return 96&t[0]&&(c=null),"export"===e[5]?0:"import"===e[5]?1:"events"===e[5]?2:"compose"===e[5]?3:"managed-acl"===e[5]?4:"sprocket"===e[5]?5:"recovery"===e[5]?6:(null==c&&(c=!!e[6].some(e[85])),c?7:8)}f=$(e,[-1,-1,-1,-1,-1,-1]),p=A[f]=C[f](e);let T=e[12]&&wy(e);function I(t){e[110](t)}let _={isDarkTheme:e[0]};return void 0!==e[10]&&(_.showModal=e[10]),m=new $h({props:_}),R.push(()=>J(m,"showModal",I)),m.$on("login",e[57]),m.$on("close",e[59]),{c(){G(t.$$.fragment),r=g(),o=h("div"),G(i.$$.fragment),s=g(),a=h("main"),p.c(),y=g(),T&&T.c(),v=g(),G(m.$$.fragment),w(a,"class","main-content svelte-14c8ed4"),w(o,"class","app-container svelte-14c8ed4"),S(o,"dark-theme",e[0])},m(e,n){Z(t,e,n),u(e,r,n),u(e,o,n),Z(i,o,null),l(o,s),l(o,a),A[f].m(a,null),u(e,y,n),T&&T.m(e,n),u(e,v,n),Z(m,e,n),E=!0},p(e,r){const s={};1&r[0]&&(s.isDarkTheme=e[0]),8192&r[0]&&(s.isSearchMode=e[13]),2&r[0]&&(s.isLoggedIn=e[1]),16&r[0]&&(s.userRole=e[4]),256&r[0]&&(s.currentEffectiveRole=e[8]),8&r[0]&&(s.userProfile=e[3]),4&r[0]&&(s.userPubkey=e[2]),!n&&16384&r[0]&&(n=!0,s.searchQuery=e[14],N(()=>n=!1)),t.$set(s);const c={};1&r[0]&&(c.isDarkTheme=e[0]),512&r[0]&&(c.tabs=e[9]),32&r[0]&&(c.selectedTab=e[5]),i.$set(c);let l=f;f=$(e,r),f===l?A[f].p(e,r):(z(),V(A[l],1,1,()=>{A[l]=null}),K(),p=A[f],p?p.p(e,r):(p=A[f]=C[f](e),p.c()),W(p,1),p.m(a,null)),(!E||1&r[0])&&S(o,"dark-theme",e[0]),e[12]?T?T.p(e,r):(T=wy(e),T.c(),T.m(v.parentNode,v)):T&&(T.d(1),T=null);const u={};1&r[0]&&(u.isDarkTheme=e[0]),!b&&1024&r[0]&&(b=!0,u.showModal=e[10],N(()=>b=!1)),m.$set(u)},i(e){E||(W(t.$$.fragment,e),W(i.$$.fragment,e),W(p),W(m.$$.fragment,e),E=!0)},o(e){V(t.$$.fragment,e),V(i.$$.fragment,e),V(p),V(m.$$.fragment,e),E=!1},d(e){Q(t,e),e&&d(r),e&&d(o),Q(i),A[f].d(),e&&d(y),T&&T.d(e),e&&d(v),Q(m,e)}}}let _y=!1;function Ry(e){return e?e.slice(0,8)+"..."+e.slice(-8):"unknown"}function Oy(e,t=100){return e?e.length>t?e.slice(0,t)+"...":e:""}function Ly(e){return e?new Date(1e3*e).toLocaleString():""}async function Py(e,t){try{const n=JSON.stringify(e);await navigator.clipboard.writeText(n);const r=t.target.closest(".copy-json-btn");if(r){const e=r.textContent;r.textContent="✅",r.style.backgroundColor="#4CAF50",setTimeout(()=>{r.textContent=e,r.style.backgroundColor=""},2e3)}}catch(n){console.error("Failed to copy to clipboard:",n);try{const n=document.createElement("textarea");n.value=JSON.stringify(e),document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n);const r=t.target.closest(".copy-json-btn");if(r){const e=r.textContent;r.textContent="✅",r.style.backgroundColor="#4CAF50",setTimeout(()=>{r.textContent=e,r.style.backgroundColor=""},2e3)}}catch(e){console.error("Fallback copy also failed:",e),alert("Failed to copy to clipboard. Please copy manually.")}}}function By(e,t,n){let r,o,i,s,a;"undefined"!=typeof window&&(window.debugIndexedDB=mh);let c=!1,l=!1,u=!1,d="",f="",h=null,p="",g=null,y=!1,v=localStorage.getItem("selectedTab")||"export",m=!1,w="",E=[],k=[],x=null,S=new Set,C=!1,A=!0,$=null,T="",_=new Map,R=[],O=0;const L=3e5;let P=[],B=!0,j=null,N="",U=null,M=[],F=!1,D="",H="info",q=!1,z=null,K="",W="",V=null,J="",G=[],Z=!1,Q=!0,Y=null;const X=[{value:0,label:"User Metadata (0)"},{value:3,label:"Follows (3)"},{value:1e4,label:"Mute list (10000)"},{value:10001,label:"Pin list (10001)"},{value:10002,label:"Relay List Metadata (10002)"},{value:10003,label:"Bookmark list (10003)"},{value:10004,label:"Communities list (10004)"},{value:10005,label:"Public chats list (10005)"},{value:10006,label:"Blocked relays list (10006)"},{value:10007,label:"Search relays list (10007)"},{value:10009,label:"User groups (10009)"},{value:10012,label:"Favorite relays list (10012)"},{value:10013,label:"Private event relay list (10013)"},{value:10015,label:"Interests list (10015)"},{value:10019,label:"Nutzap Mint Recommendation (10019)"},{value:10020,label:"Media follows (10020)"},{value:10030,label:"User emoji list (10030)"},{value:10050,label:"Relay list to receive DMs (10050)"},{value:10051,label:"KeyPackage Relays List (10051)"},{value:10063,label:"User server list (10063)"},{value:10096,label:"File storage server list (10096)"},{value:10166,label:"Relay Monitor Announcement (10166)"},{value:10312,label:"Room Presence (10312)"},{value:10377,label:"Proxy Announcement (10377)"},{value:11111,label:"Transport Method Announcement (11111)"},{value:13194,label:"Wallet Info (13194)"},{value:17375,label:"Cashu Wallet Event (17375)"},{value:3e4,label:"Follow sets (30000)"},{value:30001,label:"Generic lists (30001)"},{value:30002,label:"Relay sets (30002)"},{value:30003,label:"Bookmark sets (30003)"},{value:30004,label:"Curation sets (30004)"},{value:30005,label:"Video sets (30005)"},{value:30007,label:"Kind mute sets (30007)"},{value:30008,label:"Profile Badges (30008)"},{value:30009,label:"Badge Definition (30009)"},{value:30015,label:"Interest sets (30015)"},{value:30017,label:"Create or update a stall (30017)"},{value:30018,label:"Create or update a product (30018)"},{value:30019,label:"Marketplace UI/UX (30019)"},{value:30020,label:"Product sold as an auction (30020)"},{value:30023,label:"Long-form Content (30023)"},{value:30024,label:"Draft Long-form Content (30024)"},{value:30030,label:"Emoji sets (30030)"},{value:30040,label:"Curated Publication Index (30040)"},{value:30041,label:"Curated Publication Content (30041)"},{value:30063,label:"Release artifact sets (30063)"},{value:30078,label:"Application-specific Data (30078)"},{value:30166,label:"Relay Discovery (30166)"},{value:30267,label:"App curation sets (30267)"},{value:30311,label:"Live Event (30311)"},{value:30312,label:"Interactive Room (30312)"},{value:30313,label:"Conference Event (30313)"},{value:30315,label:"User Statuses (30315)"},{value:30388,label:"Slide Set (30388)"},{value:30402,label:"Classified Listing (30402)"},{value:30403,label:"Draft Classified Listing (30403)"},{value:30617,label:"Repository announcements (30617)"},{value:30618,label:"Repository state announcements (30618)"},{value:30818,label:"Wiki article (30818)"},{value:30819,label:"Redirects (30819)"},{value:31234,label:"Draft Event (31234)"},{value:31388,label:"Link Set (31388)"},{value:31890,label:"Feed (31890)"},{value:31922,label:"Date-Based Calendar Event (31922)"},{value:31923,label:"Time-Based Calendar Event (31923)"},{value:31924,label:"Calendar (31924)"},{value:31925,label:"Calendar Event RSVP (31925)"},{value:31989,label:"Handler recommendation (31989)"},{value:31990,label:"Handler information (31990)"},{value:32267,label:"Software Application (32267)"},{value:34550,label:"Community Definition (34550)"},{value:37516,label:"Geocache listing (37516)"},{value:38172,label:"Cashu Mint Announcement (38172)"},{value:38173,label:"Fedimint Announcement (38173)"},{value:38383,label:"Peer-to-peer Order events (38383)"},{value:39089,label:"Starter packs (39089)"},{value:39092,label:"Media starter packs (39092)"},{value:39701,label:"Web bookmarks (39701)"}],ee={0:"User Metadata",1:"Short Text Note",2:"Recommend Relay",3:"Follows",4:"Encrypted Direct Messages",5:"Event Deletion Request",6:"Repost",7:"Reaction",8:"Badge Award",9:"Chat Message",10:"Group Chat Threaded Reply",11:"Thread",12:"Group Thread Reply",13:"Seal",14:"Direct Message",15:"File Message",16:"Generic Repost",17:"Reaction to a website",20:"Picture",40:"Channel Creation",41:"Channel Metadata",42:"Channel Message",43:"Channel Hide Message",44:"Channel Mute User",1021:"Bid",1022:"Bid Confirmation",1040:"OpenTimestamps",1063:"File Metadata",1311:"Live Chat Message",1971:"Problem Tracker",1984:"Reporting",1985:"Label",4550:"Community Post Approval",5e3:"Job Request",5999:"Job Request",6e3:"Job Result",6999:"Job Result",7e3:"Job Feedback",9041:"Zap Goal",9734:"Zap Request",9735:"Zap",9882:"Highlights",1e4:"Mute list",10001:"Pin list",10002:"Relay List Metadata",10003:"Bookmarks list",10004:"Communities list",10005:"Public Chats list",10006:"Blocked Relays list",10007:"Search Relays list",10015:"Interests",10030:"User Emoji list",10050:"DM relays",10096:"File Storage Server List",13194:"Wallet Service Info",21e3:"Lightning pub RPC",22242:"Client Authentication",23194:"Wallet Request",23195:"Wallet Response",23196:"Wallet Notification",23197:"Wallet Notification",24133:"Nostr Connect",27235:"HTTP Auth",3e4:"Follow sets",30001:"Generic lists",30002:"Relay sets",30003:"Bookmark sets",30004:"Curation sets",30008:"Profile Badges",30009:"Badge Definition",30015:"Interest sets",30017:"Stall Definition",30018:"Product Definition",30019:"Marketplace UI/UX",30020:"Product sold as an auction",30023:"Long-form Content",30024:"Draft Long-form Content",30030:"Emoji sets",30078:"Application-specific Data",30311:"Live Event",30315:"User Statuses",30402:"Classified Listing",30403:"Draft Classified Listing",31922:"Date-Based Calendar Event",31923:"Time-Based Calendar Event",31924:"Calendar",31925:"Calendar Event RSVP",31989:"Handler recommendation",31990:"Handler information",34235:"Video Event Horizontal",34236:"Video Event Vertical",34550:"Community Definition"};function te(e){S.has(e)?S.delete(e):S.add(e),n(16,S)}async function ne(e){if(!u)return void alert("Please log in first");const t=k.find(t=>t.id===e);if(!t)return void alert("Event not found");if("admin"===p||"owner"===p||"write"===p&&t.pubkey&&t.pubkey===d){if(confirm("Are you sure you want to delete this event?"))try{if(!g)throw new Error("Signer not available for signing");const r={kind:5,created_at:Math.floor(Date.now()/1e3),tags:[["e",e]],content:""};console.log("Created delete event template:",r),console.log("User pubkey:",d),console.log("Target event:",t),console.log("Target event pubkey:",t.pubkey);const o=await g.signEvent(r);console.log("Signed delete event:",o),console.log("Signed delete event pubkey:",o.pubkey),console.log("Delete event tags:",o.tags);const i=`wss://${window.location.host}`;try{const e=await Pg(i,o,g,d);e.success?console.log("Delete event published successfully to ORLY relay"):console.error("Failed to publish delete event:",e.reason)}catch(e){console.error("Error publishing delete event:",e)}const s=t.pubkey&&t.pubkey===d;if(s){const t=await oh.publish(o);if(console.log("Delete event published:",t),!(t.success&&t.okCount>0))throw new Error("No relays accepted the delete event");{await new Promise(e=>setTimeout(e,2e3));try{const n=await gh(e,{timeout:5e3});n?(console.warn("Event still exists after deletion attempt:",n),alert(`Warning: Delete event was accepted by ${t.okCount} relay(s), but the event still exists on the relay. This may indicate the relay does not properly handle delete events.`)):console.log("Event successfully deleted and verified")}catch(e){console.log("Could not fetch event after deletion (likely deleted):",e.message)}try{const t=await yh(e,{timeout:5e3});if(t.length>0){console.log(`Delete event verification: Found ${t.length} delete event(s) targeting ${e}`);const n=t.find(e=>e.pubkey&&e.pubkey===d);n?console.log("Our delete event found in database:",n.id):console.warn("Our delete event not found in database, but other delete events exist")}else console.warn("No delete events found in database for target event:",e)}catch(e){console.log("Could not verify delete event in database:",e.message)}n(79,k=k.filter(t=>t.id!==e)),P=P.filter(t=>t.id!==e),R=R.filter(t=>t.id!==e);for(const[t,n]of _)n.events&&(n.events=n.events.filter(t=>t.id!==e),_.set(t,n));se(),console.log("Reloading events to show delete event...");const r=_y&&u&&d?[d]:null;await xe(!0,r),alert(`Event deleted successfully (accepted by ${t.okCount} relay(s))`)}}else{const t=`wss://${window.location.host}/`,r=new rh;await r.connectToRelay(t);const i=await r.publish(o);if(console.log("Delete event published to local relay only:",i),!(i.success&&i.okCount>0))throw new Error("Local relay did not accept the delete event");{await new Promise(e=>setTimeout(e,2e3));try{const t=await gh(e,{timeout:5e3});t?(console.warn("Event still exists after deletion attempt:",t),alert(`Warning: Delete event was accepted by ${i.okCount} relay(s), but the event still exists on the relay. This may indicate the relay does not properly handle delete events.`)):console.log("Event successfully deleted and verified")}catch(e){console.log("Could not fetch event after deletion (likely deleted):",e.message)}try{const t=await yh(e,{timeout:5e3});if(t.length>0){console.log(`Delete event verification: Found ${t.length} delete event(s) targeting ${e}`);const n=t.find(e=>e.pubkey&&e.pubkey===d);n?console.log("Our delete event found in database:",n.id):console.warn("Our delete event not found in database, but other delete events exist")}else console.warn("No delete events found in database for target event:",e)}catch(e){console.log("Could not verify delete event in database:",e.message)}n(79,k=k.filter(t=>t.id!==e)),P=P.filter(t=>t.id!==e),R=R.filter(t=>t.id!==e);for(const[t,n]of _)n.events&&(n.events=n.events.filter(t=>t.id!==e),_.set(t,n));se(),console.log("Reloading events to show delete event...");const t=_y&&u&&d?[d]:null;await xe(!0,t),alert("Event deleted successfully (local relay only - admin/owner deleting other user's event)")}}}catch(e){console.error("Failed to delete event:",e),alert("Failed to delete event: "+e.message)}}else alert("You do not have permission to delete this event")}async function re(){const e=J?parseInt(J):V;if(null==e||isNaN(e))console.log("No valid kind to load, kindToUse:",e);else if(u){console.log("Loading recovery events for kind:",e,"user:",d),n(29,Z=!0);try{const t=[{kinds:[e],authors:[d],limit:100}];Y&&(t[0].until=Y),console.log("Recovery filters:",t);const r=await async function(e,t={}){const{timeout:n=3e4,cacheFirst:r=!0,cacheOnly:o=!1}=t;let i=[];if(r||o)try{if(i=await dh(e),console.log(`Found ${i.length} events in cache`),o||i.length>0)return i}catch(e){console.warn("Failed to query cache",e)}if(!o){const t=await ph(e,{timeout:n,useCache:!1});return console.log(`Fetched ${t.length} events from relay`),t}return i}(t,{timeout:3e4,cacheFirst:!0});console.log("Recovery events received:",r.length),console.log("Recovery events kinds:",r.map(e=>e.kind)),n(28,G=Y?[...G,...r]:r),r.length>0?(Y=Math.min(...r.map(e=>e.created_at)),n(30,Q=100===r.length)):n(30,Q=!1)}catch(e){console.error("Failed to load recovery events:",e)}finally{n(29,Z=!1)}}else console.log("Not logged in, cannot load recovery events")}async function oe(e){if(confirm("Are you sure you want to repost this event?"))try{const t=`wss://${window.location.host}/`;console.log("Reposting event to local relay:",t,e);const r={...e};if(r.created_at=Math.floor(Date.now()/1e3),r.id="",r.sig="",e.kind>=3e4&&e.kind<=39999){const t=e.tags.find(e=>"d"===e[0]);t&&(r.tags=r.tags.filter(e=>"d"!==e[0]),r.tags.push(t))}if(g){const e=await g.signEvent(r);console.log("Signed event for repost:",e);const o=await oh.publish(e,[t]);console.log("Repost publish result:",o),o.success&&o.okCount>0?(alert("Event reposted successfully!"),n(30,Q=!1),await re()):alert("Failed to repost event. Check console for details.")}else alert("No signer available. Please log in.")}catch(e){console.error("Error reposting event:",e),alert("Error reposting event: "+e.message)}}async function ie(e){if(confirm("Are you sure you want to repost this event to all your write relays?"))try{const t=await async function(){if(!d)return[];try{const e=await dh([{kinds:[10002],authors:[d],limit:1}]);if(0===e.length)return console.log("No relay list event found for user"),[];const t=e[0];console.log("Found relay list event:",t);const n=[];for(const e of t.tags)if("r"===e[0]&&e.length>=2){const t=e[1],r=e.length>=3?e[2]:null;r&&"write"!==r||n.push(t)}return console.log("Found write relays:",n),n}catch(e){return console.error("Error fetching user write relays:",e),[]}}(),r=`wss://${window.location.host}/`,o=[r,...t.filter(e=>e!==r)];1===o.length&&alert("No write relays found in your relay list. Only posting to local relay."),console.log("Reposting event to all relays:",o,e);const i={...e};if(i.created_at=Math.floor(Date.now()/1e3),i.id="",i.sig="",e.kind>=3e4&&e.kind<=39999){const t=e.tags.find(e=>"d"===e[0]);t&&(i.tags=i.tags.filter(e=>"d"!==e[0]),i.tags.push(t))}if(g){const e=await g.signEvent(i);console.log("Signed event for repost to all:",e);const t=await oh.publish(e,o);console.log("Repost to all publish result:",t),t.success&&t.okCount>0?(alert(`Event reposted successfully to ${o.length} relays!`),n(30,Q=!1),await re()):alert("Failed to repost event. Check console for details.")}else alert("No signer available. Please log in.")}catch(e){console.error("Error reposting event to all:",e),alert("Error reposting event to all: "+e.message)}}if("undefined"!=typeof localStorage){const e=localStorage.getItem("isDarkTheme");null!==e&&(c=JSON.parse(e));const t=localStorage.getItem("nostr_auth_method"),r=localStorage.getItem("nostr_pubkey");t&&r&&(u=!0,d=r,f=t,"extension"===t&&window.nostr&&(g=window.nostr),be(),Ee()),function(){if("undefined"==typeof localStorage)return;try{const t=localStorage.getItem("app_state");if(t){const r=JSON.parse(t);r.selectedTab&&he.some(e=>e.id===r.selectedTab)&&n(5,v=r.selectedTab),r.expandedEvents&&n(16,S=new Set(r.expandedEvents)),r.globalEventsCache&&(R=r.globalEventsCache),r.globalCacheTimestamp&&(O=r.globalCacheTimestamp),void 0!==r.hasMoreEvents&&(A=r.hasMoreEvents),r.oldestEventTimestamp&&($=r.oldestEventTimestamp),void 0!==r.hasMoreMyEvents&&(B=r.hasMoreMyEvents),r.oldestMyEventTimestamp&&(j=r.oldestMyEventTimestamp),R.length>0&&((e=O)&&Date.now()-et.created_at-e.created_at),O=Date.now(),se()}async function ce(){if(u&&"owner"===p&&q)try{n(21,F=!0);const e=await fetch("/api/sprocket/status",{method:"GET",headers:{Authorization:`Nostr ${await Ae("GET","/api/sprocket/status")}`,"Content-Type":"application/json"}});e.ok?n(19,U=await e.json()):fe("Failed to load sprocket status","error")}catch(e){fe(`Error loading sprocket status: ${e.message}`,"error")}finally{n(21,F=!1)}}async function le(){if(u&&"owner"===p)try{n(21,F=!0);const e=await fetch("/api/sprocket/versions",{method:"GET",headers:{Authorization:`Nostr ${await Ae("GET","/api/sprocket/versions")}`,"Content-Type":"application/json"}});e.ok?n(20,M=await e.json()):fe("Failed to load versions","error")}catch(e){fe(`Error loading versions: ${e.message}`,"error")}finally{n(21,F=!1)}}async function ue(e){u&&"owner"===p&&(n(18,N=e.content),fe(`Loaded version: ${e.name}`,"success"))}async function de(e){if(u&&"owner"===p&&confirm(`Are you sure you want to delete version ${e}?`))try{n(21,F=!0);const t=await fetch("/api/sprocket/delete-version",{method:"POST",headers:{Authorization:`Nostr ${await Ae("POST","/api/sprocket/delete-version")}`,"Content-Type":"application/json"},body:JSON.stringify({filename:e})});if(t.ok)fe(`Version ${e} deleted successfully`,"success"),await le();else{fe(`Failed to delete version: ${await t.text()}`,"error")}}catch(e){fe(`Error deleting version: ${e.message}`,"error")}finally{n(21,F=!1)}}function fe(e,t="info"){n(22,D=e),n(23,H=t),setTimeout(()=>{n(22,D="")},5e3)}const he=[{id:"export",icon:"📤",label:"Export"},{id:"import",icon:"💾",label:"Import",requiresAdmin:!0},{id:"events",icon:"📡",label:"Events"},{id:"compose",icon:"✏️",label:"Compose",requiresWrite:!0},{id:"recovery",icon:"🔄",label:"Recovery"},{id:"managed-acl",icon:"🛡️",label:"Managed ACL",requiresOwner:!0},{id:"sprocket",icon:"⚙️",label:"Sprocket",requiresOwner:!0}];function pe(e){n(5,v=e),"sprocket"===e&&u&&"owner"===p&&q&&(ce(),le()),se()}function ge(){n(12,y=!1)}function ye(e){n(6,E=E.filter(t=>t.id!==e)),_.delete(e),v===e&&n(5,v="export")}async function ve(e,t,n=!0){const r=_.get(e);if(r&&!r.isLoading){r.isLoading=!0,_.set(e,r);try{const o={limit:n?100:200,until:n?Math.floor(Date.now()/1e3):r.oldestTimestamp};console.log("Loading search results for query:",t,"with options:",o);const i=await async function(e,t={}){const{limit:n=100,since:r=null,until:o=null,kinds:i=null}=t,s=[{search:e}];return r&&(s[0].since=r),o&&(s[0].until=o),i&&(s[0].kinds=i),n&&(s[0].limit=n),await ph(s,{timeout:3e4})}(t,o);if(console.log("Received search results:",i.length,"events"),r.events=n?i.sort((e,t)=>t.created_at-e.created_at):[...r.events,...i].sort((e,t)=>t.created_at-e.created_at),i.length>0){const e=Math.min(...i.map(e=>e.created_at));(!r.oldestTimestamp||et.id===e);t&&await ve(e,t.query,!1)}(t)}}async function we(){if(u&&d&&!h)try{console.log("Auto-fetching profile for:",d),await vh(),n(3,h=await hh(d)),console.log("Profile auto-loaded:",h)}catch(e){console.error("Failed to auto-load profile:",e)}}async function be(){if(u&&d)try{const e=await fetch(`/api/permissions/${d}`);if(e.ok){const t=await e.json();n(4,p=t.permission||""),console.log("User role loaded:",p),console.log("Is owner?","owner"===p)}else console.error("Failed to fetch user role:",e.status),n(4,p="")}catch(e){console.error("Error fetching user role:",e),n(4,p="")}else n(4,p="")}async function Ee(){try{const e=await fetch("/api/acl-mode");if(e.ok){const t=await e.json();n(7,K=t.acl_mode||""),console.log("ACL mode loaded:",K)}else console.error("Failed to fetch ACL mode:",e.status),n(7,K="")}catch(e){console.error("Error fetching ACL mode:",e),n(7,K="")}}async function ke(e=[]){if(u)if(0!==e.length||"admin"===a||"owner"===a)try{const t=await Ce("/api/export","POST"),n=await fetch("/api/export",{method:"POST",headers:{Authorization:t,"Content-Type":"application/json"},body:JSON.stringify({pubkeys:e})});if(!n.ok)throw new Error(`Export failed: ${n.status} ${n.statusText}`);const r=await n.blob(),o=window.URL.createObjectURL(r),i=document.createElement("a");i.href=o;const s=n.headers.get("Content-Disposition");let a="events.jsonl";if(s){const e=s.match(/filename="([^"]+)"/);e&&(a=e[1])}i.download=a,document.body.appendChild(i),i.click(),document.body.removeChild(i),window.URL.revokeObjectURL(o)}catch(e){console.error("Export failed:",e),alert("Export failed: "+e.message)}else alert("Admin or owner permission required to export all events");else alert("Please log in first")}async function xe(e=!1,t=null){if(!u||"write"!==p&&"admin"!==p&&"owner"!==p)alert("Write, admin, or owner permission required");else if(!C){n(17,C=!0),e&&($=null);try{console.log("Loading events with authors filter:",t,"including delete events");const r=await async function(e={}){const{limit:t=100,since:n=null,until:r=null,authors:o=null,kinds:i=null,...s}=e,a=[{...s}];return n&&(a[0].since=n),r&&(a[0].until=r),o&&(a[0].authors=o),i&&(a[0].kinds=i),t&&(a[0].limit=t),await ph(a,{timeout:3e4})}({limit:e?100:200,until:e?Math.floor(Date.now()/1e3):$,authors:t});if(console.log("Received events:",r.length,"events"),t&&r.length>0){const e=r.filter(e=>e.pubkey&&e.pubkey!==d);e.length>0&&console.warn("Server returned non-user events:",e.length,"out of",r.length)}if(e?(n(79,k=r.sort((e,t)=>t.created_at-e.created_at)),ae(r)):(n(79,k=[...k,...r].sort((e,t)=>t.created_at-e.created_at)),ae(k)),r.length>0){const e=Math.min(...r.map(e=>e.created_at));(!$||e<$)&&($=e)}A=r.length===(e?1e3:200),e&&A&&setTimeout(()=>{if("events"===v){const e=document.querySelectorAll(".events-view-content")[0];e&&e.scrollHeight<=e.clientHeight&&Se()}},100)}catch(e){console.error("Failed to load events:",e),alert("Failed to load events: "+e.message)}finally{n(17,C=!1)}}}async function Se(){await xe(!1)}async function Ce(e,t){if(!u||!d)throw new Error("Not logged in");const n={kind:27235,created_at:Math.floor(Date.now()/1e3),tags:[["u",window.location.origin+e],["method",t.toUpperCase()]],content:"",pubkey:d};let r;if(g&&"extension"===f)try{r=await g.signEvent(n)}catch(e){throw new Error("Failed to sign with extension: "+e.message)}else{if("nsec"!==f)throw new Error("No valid signer available");n.id="mock-id-"+Date.now(),n.sig="mock-signature-"+Date.now(),r=n}const o=JSON.stringify(r);return`Nostr ${btoa(o)}`}async function Ae(e,t){if(!u||!d)throw new Error("Not logged in");const n={kind:27235,created_at:Math.floor(Date.now()/1e3),tags:[["u",window.location.origin+t],["method",e.toUpperCase()]],content:"",pubkey:d};let r;if(g&&"extension"===f)try{r=await g.signEvent(n)}catch(e){throw new Error("Failed to sign with extension: "+e.message)}else{if("nsec"!==f)throw new Error("No valid signer available");n.id="mock-id-"+Date.now(),n.sig="mock-signature-"+Date.now(),r=n}const o=JSON.stringify(r);return btoa(o)}function $e(e){n(80,T=e),localStorage.setItem("viewAsRole",e),console.log("View as role changed to:",e,"Current effective role:",a)}T=localStorage.getItem("viewAsRole")||"";return e.$$.update=()=>{var t;if(6&e.$$.dirty[0]|131072&e.$$.dirty[2]&&n(32,r=k.sort((e,t)=>t.created_at-e.created_at)),8&e.$$.dirty[0]&&n(31,o=h?.about?(t=h.about,String(t).replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")).replace(/\n{2,}/g,"
"):""),16&e.$$.dirty[0]|262144&e.$$.dirty[2]&&n(8,a=T&&""!==T?T:p),402&e.$$.dirty[0]|786432&e.$$.dirty[2]&&n(82,i=he.filter(e=>{const t=a;return!(e.requiresAdmin&&(!u||"admin"!==t&&"owner"!==t))&&(!(e.requiresOwner&&(!u||"owner"!==t))&&(!(e.requiresWrite&&(!u||"read"===t))&&(!("sprocket"===e.id&&!q)&&(("managed-acl"!==e.id||"managed"===K)&&(console.log(`Tab ${e.id} filter check:`,{isLoggedIn:u,userRole:p,viewAsRole:T,currentRole:t,requiresAdmin:e.requiresAdmin,requiresOwner:e.requiresOwner,requiresWrite:e.requiresWrite,visible:!0}),!0)))))})),64&e.$$.dirty[0]|1048576&e.$$.dirty[2]&&n(9,s=[...i,...E]),658&e.$$.dirty[0]|1048576&e.$$.dirty[2]&&console.log("Tabs debug:",{isLoggedIn:u,userRole:p,aclMode:K,filteredBaseTabs:i.map(e=>e.id),allTabs:s.map(e=>e.id)}),1&e.$$.dirty[0]&&"undefined"!=typeof document&&(c?document.body.classList.add("dark-theme"):document.body.classList.remove("dark-theme")),14&e.$$.dirty[0]&&u&&d&&!h&&we(),54&e.$$.dirty[0]|131072&e.$$.dirty[2]&&"events"===v&&u&&("write"===p||"admin"===p||"owner"===p)&&0===k.length){xe(!0,null)}32&e.$$.dirty[0]&&localStorage.setItem("selectedTab",v)},[c,u,d,h,p,v,E,K,a,s,l,g,y,m,w,x,S,C,N,U,M,F,D,H,z,W,V,J,G,Z,Q,o,r,_,X,function(e){return ee[e]||`Kind ${e}`},te,async function(){console.log("Toggle changed, showOnlyMyEvents:",_y),await xe(!0,null)},ne,re,oe,ie,function(){console.log("selectRecoveryKind called, recoverySelectedKind:",V),null!=V?(n(27,J=""),n(28,G=[]),Y=null,n(30,Q=!0),re()):console.log("No kind selected, skipping load")},function(){console.log("handleCustomKindInput called, recoveryCustomKind:",J);const e=parseInt(J);""!==J&&!isNaN(e)&&e>=0&&(n(26,V=null),n(28,G=[]),Y=null,n(30,Q=!0),re())},function(e){const t=G.filter(t=>t.kind===e.kind&&t.pubkey===e.pubkey),n=Math.max(...t.map(e=>e.created_at));return e.created_at===n},async function(){if(u&&"owner"===p)try{n(21,F=!0);const e=await fetch("/api/sprocket/status",{method:"GET",headers:{Authorization:`Nostr ${await Ae("GET","/api/sprocket/status")}`,"Content-Type":"application/json"}});if(e.ok){const t=await e.json();n(18,N=t.script_content||""),n(19,U=t),fe("Script loaded successfully","success")}else fe("Failed to load script","error")}catch(e){fe(`Error loading script: ${e.message}`,"error")}finally{n(21,F=!1)}},async function(){if(u&&"owner"===p)try{n(21,F=!0);const e=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await Ae("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:N});if(e.ok)fe("Script saved and updated successfully","success"),await ce(),await le();else{fe(`Failed to save script: ${await e.text()}`,"error")}}catch(e){fe(`Error saving script: ${e.message}`,"error")}finally{n(21,F=!1)}},async function(){if(u&&"owner"===p)try{n(21,F=!0);const e=await fetch("/api/sprocket/restart",{method:"POST",headers:{Authorization:`Nostr ${await Ae("POST","/api/sprocket/restart")}`,"Content-Type":"application/json"}});if(e.ok)fe("Sprocket restarted successfully","success"),await ce();else{fe(`Failed to restart sprocket: ${await e.text()}`,"error")}}catch(e){fe(`Error restarting sprocket: ${e.message}`,"error")}finally{n(21,F=!1)}},async function(){if(u&&"owner"===p&&confirm("Are you sure you want to delete the sprocket script? This will stop the current process."))try{n(21,F=!0);const e=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await Ae("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:""});if(e.ok)n(18,N=""),fe("Sprocket script deleted successfully","success"),await ce(),await le();else{fe(`Failed to delete script: ${await e.text()}`,"error")}}catch(e){fe(`Error deleting script: ${e.message}`,"error")}finally{n(21,F=!1)}},le,ue,de,function(e){n(24,z=e.target.files[0])},async function(){if(u&&"owner"===p&&z)try{n(21,F=!0);const e=await z.text(),t=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await Ae("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:e});if(t.ok)n(18,N=e),fe("Script uploaded and updated successfully","success"),await ce(),await le();else{fe(`Failed to upload script: ${await t.text()}`,"error")}}catch(e){fe(`Error uploading script: ${e.message}`,"error")}finally{n(21,F=!1),n(24,z=null);const e=document.getElementById("sprocket-upload-file");e&&(e.value="")}},pe,function(){n(0,c=!c),"undefined"!=typeof localStorage&&localStorage.setItem("isDarkTheme",JSON.stringify(c))},function(){u||n(10,l=!0)},async function(e){const{method:t,pubkey:r,privateKey:o,signer:i}=e.detail;n(1,u=!0),n(2,d=r),f=t,n(11,g=i),n(10,l=!1);try{if(await vh(),"extension"===t&&i)oh.setSigner(i);else if("nsec"===t&&o){const e=new qd(o);oh.setSigner(e)}n(3,h=await hh(r)),console.log("Profile loaded:",h)}catch(e){console.error("Failed to load profile:",e)}await be(),await Ee()},function(){n(1,u=!1),n(2,d=""),f="",n(3,h=null),n(4,p=""),n(11,g=null),n(12,y=!1),P=[],n(79,k=[]),R=[],O=0,se(),"undefined"!=typeof localStorage&&(localStorage.removeItem("nostr_auth_method"),localStorage.removeItem("nostr_pubkey"),localStorage.removeItem("nostr_privkey"))},function(){n(10,l=!1)},function(){n(12,y=!0)},ge,function(){n(13,m=!m),m||n(14,w="")},function(e){"Enter"===e.key&&w.trim()?(!function(e){const t=`search-${Date.now()}`,r={id:t,icon:"🔍",label:e,isSearchTab:!0,query:e};n(6,E=[...E,r]),n(5,v=t),_.set(t,{events:[],isLoading:!1,hasMore:!0,oldestTimestamp:null}),ve(t,e)}(w.trim()),n(14,w=""),n(13,m=!1)):"Escape"===e.key&&(n(13,m=!1),n(14,w=""))},ye,ve,me,we,async function(){await ke([])},async function(){await ke([d])},function(e){n(15,x=e.target.files[0])},async function(){if(!u||"admin"!==p&&"owner"!==p)alert("Admin or owner permission required");else if(x)try{const e=await Ce("/api/import","POST"),t=new FormData;t.append("file",x);const r=await fetch("/api/import",{method:"POST",headers:{Authorization:e},body:t});if(!r.ok)throw new Error(`Import failed: ${r.status} ${r.statusText}`);await r.json();alert("Import started successfully"),n(15,x=null),document.getElementById("import-file").value=""}catch(e){console.error("Import failed:",e),alert("Import failed: "+e.message)}else alert("Please select a file")},xe,function(e){const{scrollTop:t,scrollHeight:n,clientHeight:r}=e.target;n-t-r<100&&Se()},function(){try{if(!W.trim())return void alert("Please enter some JSON to reformat");const e=JSON.parse(W);n(25,W=JSON.stringify(e,null,2))}catch(e){alert("Invalid JSON: "+e.message)}},async function(){try{if(!W.trim())return void alert("Please enter an event to sign");if(!u||!d)return void alert("Please log in to sign events");if(!g)return void alert("No signer available. Please log in with a valid authentication method.");const e=JSON.parse(W);e.pubkey=d,e.created_at=Math.floor(Date.now()/1e3),delete e.id,delete e.sig;const t=await g.signEvent(e);n(25,W=JSON.stringify(t,null,2)),alert("Event signed successfully!")}catch(e){console.error("Error signing event:",e),alert("Error signing event: "+e.message)}},async function(){try{if(!W.trim())return void alert("Please enter an event to publish");if(!u)return void alert("Please log in to publish events");if(!g)return void alert("No signer available. Please log in with a valid authentication method.");const e=JSON.parse(W);if(!e.id||!e.sig)return void alert('Event must be signed before publishing. Please click "Sign" first.');const t=`wss://${window.location.host}`,n=await Pg(t,e,g,d);n.success?alert("Event published successfully to ORLY relay!"):alert(`Event publishing failed: ${n.reason||"Unknown error"}`)}catch(e){console.error("Error publishing event:",e),alert("Error publishing event: "+e.message)}},$e,function(){const e=["owner","admin","write","read"],t=e.indexOf(p);return-1===t?["read"]:e.slice(t)},k,T,q,i,function(t){I.call(this,e,t)},function(t){I.call(this,e,t)},e=>e.id===v,function(e){w=e,n(14,w)},e=>pe(e.detail),e=>ye(e.detail),e=>te(e.detail),e=>ne(e.detail),e=>Py(e.detail.event,e.detail.e),e=>xe(e.detail.refresh,e.detail.authors),function(e){W=e,n(25,W)},function(e){N=e,n(18,N)},e=>ue(e.detail),e=>de(e.detail),function(){V=function(e){const t=e.querySelector(":checked");return t&&t.__value}(this),n(26,V),n(34,X)},function(){J=b(this.value),n(27,J)},e=>ie(e),e=>oe(e),(e,t)=>Py(e,t),e=>ve(e.id,e.query,!0),e=>ne(e.id),e=>te(e.id),(e,t)=>"Enter"===t.key&&te(e.id),(e,t)=>Py(e,t),(e,t)=>me(t,e.id),e=>$e(e===p?"":e),e=>"Escape"===e.key&&ge(),function(e){l=e,n(10,l)}]}return new class extends ee{constructor(e){super(),X(this,e,By,Iy,i,{},null,[-1,-1,-1,-1,-1,-1])}}({target:document.body,props:{name:"world"}})}(); +function Df(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Hf(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every(e=>"string"==typeof e):t.every(e=>Number.isSafeInteger(e))))}function qf(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function zf(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Kf(e){if(!Array.isArray(e))throw new Error("array expected")}function Wf(e,t){if(!Hf(!0,t))throw new Error(`${e}: array of strings expected`)}wf.BASE._setWindowSize(8);const Vf=(e,t)=>0===t?e:Vf(t,e%t),Jf=(e,t)=>e+(t-Vf(e,t)),Gf=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Zf(e,t,n,r){if(Kf(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(Jf(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${Jf(t,n)}`);let o=0,i=0;const s=Gf[t],a=Gf[n]-1,c=[];for(const r of e){if(zf(r),r>=s)throw new Error(`convertRadix2: invalid data word=${r} from=${t}`);if(o=o<32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${t}`);for(i+=t;i>=n;i-=n)c.push((o>>i-n&a)>>>0);const e=Gf[i];if(void 0===e)throw new Error("invalid carry");o&=e-1}if(o=o<=t)throw new Error("Excess padding");if(!r&&o>0)throw new Error(`Non-zero padding: ${o}`);return r&&i>0&&c.push(o>>>0),c}const Qf=(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()?{encode:e=>(function(e,...t){if(!Df(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}(e),e.toBase64()),decode:e=>((e,t)=>{qf("base64",e);const n=t?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,r=t?"base64url":"base64";if(e.length>0&&!n.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:r,lastChunkHandling:"strict"})})(e,!1)}:function(...e){const t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}(function(e,t=!1){if(zf(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Jf(8,e)>32||Jf(e,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!Df(n))throw new Error("radix2.encode input should be Uint8Array");return Zf(Array.from(n),8,e,!t)},decode:n=>(function(e,t){if(!Hf(!1,t))throw new Error(`${e}: array of numbers expected`)}("radix2.decode",n),Uint8Array.from(Zf(n,e,8,t)))}}(6),function(e){const t="string"==typeof e?e.split(""):e,n=t.length;Wf("alphabet",t);const r=new Map(t.map((e,t)=>[e,t]));return{encode:r=>(Kf(r),r.map(r=>{if(!Number.isSafeInteger(r)||r<0||r>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${r}". Allowed: ${e}`);return t[r]})),decode:t=>(Kf(t),t.map(t=>{qf("alphabet.decode",t);const n=r.get(t);if(void 0===n)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return n}))}}("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),function(e,t="="){return zf(e),qf("padding",t),{encode(n){for(Wf("padding.encode",n);n.length*e%8;)n.push(t);return n},decode(n){Wf("padding.decode",n);let r=n.length;if(r*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;r>0&&n[r-1]===t;r--){if((r-1)*e%8==0)throw new Error("padding: invalid, string has too much padding")}return n.slice(0,r)}}}(6),function(e=""){return qf("join",e),{encode:t=>(Wf("join.decode",t),t.join(e)),decode:t=>(qf("join.decode",t),t.split(e))}}(""));function Yf(e){return wf.fromHex(e).toHex().substring(2)}const Xf=new TextDecoder("utf-8"),eh=new TextEncoder;class th{log=Vu.extend("SerialPortSigner");writer=null;pubkey;get isConnected(){return!!this.writer}verifyEvent=ao;nip04;constructor(){this.nip04={encrypt:this.nip04Encrypt.bind(this),decrypt:this.nip04Decrypt.bind(this)}}lastCommand=null;async callMethodOnDevice(e,t,n={}){if(!th.SUPPORTED)throw new Error("Serial devices are not supported");if(this.writer||await this.connectToDevice(n),this.lastCommand)throw new Error("Previous command to device still pending!");const r=Fd();return this.lastCommand=r,this.sendCommand(e,t),setTimeout(()=>{r.reject(new Error("Device timeout")),this.lastCommand===r&&(this.lastCommand=null)},6e3),this.lastCommand}async connectToDevice({onConnect:e,onDisconnect:t,onError:n,onDone:r}){let o,i=await window.navigator.serial.requestPort();await i.open({baudRate:9600}),await(e=>new Promise(t=>setTimeout(t,e)))(1e3),(async()=>{for(;i&&i.readable;){const e=new window.TextDecoderStream;i.readable.pipeTo(e.writable),o=e.readable.getReader();const t=this.readFromSerialPort(o);try{for(;;){const{value:e,done:n}=await t("\n");if(e){const{method:t,data:n}=this.parseResponse(e);if("/ping"===t&&this.log("Pong"),-1===th.PUBLIC_METHODS.indexOf(t))continue;this.log("Received: ",t,n),this.lastCommand&&(this.lastCommand.resolve(n),this.lastCommand=null)}if(n)return this.lastCommand=null,this.writer=null,void(r&&r())}}catch(e){if(e instanceof Error)throw this.writer=null,n&&n(e),this.lastCommand&&(this.lastCommand.reject(e),this.lastCommand=null),e}}})();const s=new window.TextEncoderStream;s.readable.pipeTo(i.writable),this.writer=s.writable.getWriter(),await this.sendCommand(th.METHOD_PING),await this.sendCommand(th.METHOD_PING,[window.location.host]),e&&e(),i.addEventListener("disconnect",()=>{this.log("Disconnected"),this.lastCommand=null,this.writer=null,t&&t()})}async sendCommand(e,t=[]){if(!this.writer)return;this.log("Send command",e,t);const n=[e].concat(t).join(" ");await this.writer.write(n+"\n")}readFromSerialPort(e){let t,n=[];return async(r="\n")=>{if(n.length)return{value:n.shift().trim(),done:!1};const o=[];for(t&&(o.push(t),t=void 0);;){const{value:i,done:s}=await e.read();if(i){const e=i.split(r);if(e.length>1)return o.push(e.shift()),t=e.pop(),n=e,{value:o.join("").trim(),done:!1};o.push(i)}if(s)return{value:o.join("").trim(),done:!0}}}}parseResponse(e){const t=e.split(" ")[0];return{method:t,data:e.substring(t.length).trim()}}async nip04Encrypt(e,t){const n=nf(await this.callMethodOnDevice(th.METHOD_SHARED_SECRET,[Yf(e)]));let r=Uint8Array.from(function(e=32){if(zd&&"function"==typeof zd.getRandomValues)return zd.getRandomValues(new Uint8Array(e));if(zd&&"function"==typeof zd.randomBytes)return Uint8Array.from(zd.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}(16)),o=eh.encode(t),i=await crypto.subtle.importKey("raw",n,{name:"AES-CBC"},!1,["encrypt"]),s=await crypto.subtle.encrypt({name:"AES-CBC",iv:r},i,o);return`${Qf.encode(new Uint8Array(s))}?iv=${Qf.encode(new Uint8Array(r.buffer))}`}async nip04Decrypt(e,t){let[n,r]=t.split("?iv=");const o=nf(await this.callMethodOnDevice(th.METHOD_SHARED_SECRET,[Yf(e)]));let i=await crypto.subtle.importKey("raw",o,{name:"AES-CBC"},!1,["decrypt"]),s=Qf.decode(n),a=Qf.decode(r),c=await crypto.subtle.decrypt({name:"AES-CBC",iv:a},i,s);return Xf.decode(c)}async getPublicKey(){const e=await this.callMethodOnDevice(th.METHOD_PUBLIC_KEY,[]);return this.pubkey=e,e}async restore(e){await this.callMethodOnDevice(th.METHOD_RESTORE,[Jd(e)])}async signEvent(e){const t=e.pubkey||this.pubkey;if(!t)throw new Error("Unknown signer pubkey");const n={...e,id:no({...e,pubkey:t})},r=await this.callMethodOnDevice(th.METHOD_SIGN_MESSAGE,[n.id]),o={...n,sig:r,pubkey:t};if(!this.verifyEvent(o))throw new Error("Invalid signature");return o}ping(){this.sendCommand(th.METHOD_PING,[window.location.host])}static SUPPORTED="navigator"in globalThis&&!!navigator.serial;static METHOD_PING="/ping";static METHOD_LOG="/log";static METHOD_SIGN_MESSAGE="/sign-message";static METHOD_SHARED_SECRET="/shared-secret";static METHOD_PUBLIC_KEY="/public-key";static METHOD_RESTORE="/restore";static PUBLIC_METHODS=[th.METHOD_PUBLIC_KEY,th.METHOD_SIGN_MESSAGE,th.METHOD_SHARED_SECRET,th.METHOD_RESTORE]}const nh=[`wss://${window.location.host}/`];class rh{constructor(){this.pool=new _n,this.eventStore=new Md,this.isConnected=!1,this.signer=null,this.relays=[...nh]}async connect(){console.log("Starting connection to",this.relays.length,"relays...");try{this.isConnected=!0,console.log("✓ Successfully initialized relay pool"),await new Promise(e=>setTimeout(e,1e3))}catch(e){throw console.error("✗ Connection failed:",e),e}}async connectToRelay(e){console.log(`Adding relay: ${e}`);try{return this.relays.includes(e)||this.relays.push(e),console.log(`✓ Successfully added relay ${e}`),!0}catch(t){return console.error(`✗ Failed to add relay ${e}:`,t),!1}}subscribe(e,t){console.log("Creating subscription with filters:",e);const n=this.pool.subscribeMany(this.relays,e,{onevent(e){console.log("Event received:",e),t(e)},oneose(){console.log("EOSE received"),window.dispatchEvent(new CustomEvent("nostr-eose",{detail:{subscriptionId:n.id}}))}});return n}unsubscribe(e){console.log("Closing subscription"),e&&e.close&&e.close()}disconnect(){console.log("Disconnecting relay pool"),this.pool&&this.pool.close(this.relays),this.isConnected=!1}async publish(e,t=null){this.isConnected||(console.warn("Not connected to any relays, attempting to connect first"),await this.connect());try{const n=t||this.relays,r=this.pool.publish(n,e);return await Promise.allSettled(r),console.log("✓ Event published successfully"),await uh([e]),console.log("Event stored in IndexedDB"),{success:!0,okCount:1,errorCount:0}}catch(e){throw console.error("✗ Failed to publish event:",e),e}}getPool(){return this.pool}getEventStore(){return this.eventStore}getSigner(){return this.signer}setSigner(e){this.signer=e}}const oh=new rh,ih="nostrCache",sh=2,ah="events";function ch(){return new Promise((e,t)=>{try{const n=indexedDB.open(ih,sh);n.onupgradeneeded=e=>{const t=n.result;e.oldVersion;let r;r=t.objectStoreNames.contains(ah)?n.transaction.objectStore(ah):t.createObjectStore(ah,{keyPath:"id"}),r.indexNames.contains("byKindAuthor")||r.createIndex("byKindAuthor",["kind","pubkey"],{unique:!1}),r.indexNames.contains("byKindAuthorCreated")||r.createIndex("byKindAuthorCreated",["kind","pubkey","created_at"],{unique:!1}),r.indexNames.contains("byKind")||r.createIndex("byKind","kind",{unique:!1}),r.indexNames.contains("byAuthor")||r.createIndex("byAuthor","pubkey",{unique:!1}),r.indexNames.contains("byCreatedAt")||r.createIndex("byCreatedAt","created_at",{unique:!1})},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}catch(e){console.error("Failed to open IndexedDB",e),t(e)}})}async function lh(e){try{const t=await ch();await new Promise((n,r)=>{const o=t.transaction(ah,"readwrite");o.oncomplete=()=>n(),o.onerror=()=>r(o.error),o.objectStore(ah).put(e)})}catch(e){console.warn("IDB putEvent failed",e)}}async function uh(e){if(e&&0!==e.length)try{const t=await ch();await new Promise((n,r)=>{const o=t.transaction(ah,"readwrite");o.oncomplete=()=>n(),o.onerror=()=>r(o.error);const i=o.objectStore(ah);for(const t of e)i.put(t)}),console.log(`Stored ${e.length} events in IndexedDB`)}catch(e){console.warn("IDB putEvents failed",e)}}async function dh(e){try{const t=await ch(),n=[];console.log("QueryEventsFromDB: Starting query with filters:",e);for(const r of e){console.log("QueryEventsFromDB: Processing filter:",r);const e=await new Promise((e,n)=>{const o=t.transaction(ah,"readonly").objectStore(ah),i=[];let s;if(r.kinds&&r.kinds.length>0&&r.authors&&r.authors.length>0){const e=r.kinds[0],t=r.authors[0];console.log(`QueryEventsFromDB: Using byKindAuthorCreated index for kind=${e}, author=${t.substring(0,8)}...`);const n=o.index("byKindAuthorCreated"),i=IDBKeyRange.bound([e,t,-1/0],[e,t,1/0]);s=n.openCursor(i,"prev")}else if(r.kinds&&r.kinds.length>0){console.log(`QueryEventsFromDB: Using byKind index for kind=${r.kinds[0]}`);const e=o.index("byKind");s=e.openCursor(IDBKeyRange.only(r.kinds[0]))}else if(r.authors&&r.authors.length>0){console.log(`QueryEventsFromDB: Using byAuthor index for author=${r.authors[0].substring(0,8)}...`);const e=o.index("byAuthor");s=e.openCursor(IDBKeyRange.only(r.authors[0]))}else console.log("QueryEventsFromDB: Scanning all events (no specific index)"),s=o.openCursor();s.onsuccess=t=>{const n=t.target.result;if(n){const t=n.value;let o=!0;if(r.kinds&&r.kinds.length>0&&!r.kinds.includes(t.kind)&&(o=!1),r.authors&&r.authors.length>0&&!r.authors.includes(t.pubkey)&&(o=!1),r.since&&t.created_atr.until&&(o=!1),r.ids&&r.ids.length>0&&!r.ids.includes(t.id)&&(o=!1),o&&i.push(t),r.limit&&i.length>=r.limit)return console.log(`QueryEventsFromDB: Reached limit of ${r.limit}, found ${i.length} matching events`),void e(i);n.continue()}else console.log(`QueryEventsFromDB: Cursor exhausted, found ${i.length} matching events`),e(i)},s.onerror=()=>{console.error("QueryEventsFromDB: Cursor error:",s.error),n(s.error)}});console.log(`QueryEventsFromDB: Found ${e.length} events for this filter`),n.push(...e)}return n.sort((e,t)=>t.created_at-e.created_at),console.log(`QueryEventsFromDB: Returning ${n.length} total events`),n}catch(e){return console.error("QueryEventsFromDB failed:",e),[]}}function fh(e){try{const t=JSON.parse(e.content||"{}");return{name:t.name||t.display_name||"",picture:t.picture||"",banner:t.banner||"",about:t.about||"",nip05:t.nip05||"",lud16:t.lud16||t.lud06||""}}catch(e){return{name:"",picture:"",banner:"",about:"",nip05:"",lud16:""}}}async function hh(e){console.log(`Starting profile fetch for pubkey: ${e}`);try{const t=await async function(e){try{const t=await ch();return await new Promise((n,r)=>{const o=t.transaction(ah,"readonly").objectStore(ah).index("byKindAuthorCreated"),i=IDBKeyRange.bound([0,e,-1/0],[0,e,1/0]),s=o.openCursor(i,"prev");s.onsuccess=()=>{const e=s.result;n(e?e.value:null)},s.onerror=()=>r(s.error)})}catch(e){return console.warn("IDB getLatestProfileEvent failed",e),null}}(e);if(t){console.log("Using cached profile event");return fh(t)}}catch(e){console.warn("Failed to load cached profile",e)}try{const t=[{kinds:[0],authors:[e],limit:1}],n=await ph(t,{timeout:1e4});if(n.length>0){const t=n[0];console.log("Profile fetched:",t),await lh(t);try{console.log("Publishing profile event to local relay:",t.id),await oh.publish(t),console.log("Profile event successfully saved to local relay")}catch(e){console.warn("Failed to publish profile to local relay:",e)}const r=fh(t);try{"undefined"!=typeof window&&window.dispatchEvent&&window.dispatchEvent(new CustomEvent("profile-updated",{detail:{pubkey:e,profile:r,event:t}}))}catch(e){console.warn("Failed to dispatch profile-updated event",e)}return r}throw new Error("No profile found")}catch(e){throw console.error("Failed to fetch profile:",e),e}}async function ph(e,t={}){console.log("Starting event fetch with filters:",JSON.stringify(e,null,2)),console.log("Current relays:",oh.relays),oh.isConnected&&0!==oh.relays.length||(console.warn("Client not connected, initializing..."),await vh());const{timeout:n=3e4,useCache:r=!0}=t;if(r)try{const t=await dh(e);t.length>0&&console.log(`Found ${t.length} cached events in IndexedDB`)}catch(e){console.warn("Failed to query cached events",e)}return new Promise((t,r)=>{const o=[],i=setTimeout(()=>{console.log(`Timeout reached after ${n}ms, returning ${o.length} events`),sub.close(),o.length>0&&uh(o).catch(e=>console.warn("Failed to cache events",e)),t(o)},n);try{const n=Math.random().toString(36).substring(7);console.log(`📤 REQ [${n}]:`,JSON.stringify(["REQ",n,...e],null,2));const r=oh.pool.subscribeMany(oh.relays,e,{onevent(e){console.log(`📥 EVENT received for REQ [${n}]:`,{id:e.id?.substring(0,8)+"...",kind:e.kind,pubkey:e.pubkey?.substring(0,8)+"...",created_at:e.created_at,content_preview:e.content?.substring(0,50)}),o.push(e),lh(e).catch(e=>console.warn("Failed to cache event",e))},oneose(){console.log(`✅ EOSE received for REQ [${n}], got ${o.length} events`),clearTimeout(i),r.close(),o.length>0&&uh(o).catch(e=>console.warn("Failed to cache events",e)),t(o)}})}catch(e){clearTimeout(i),console.error("Failed to fetch events:",e),r(e)}})}async function gh(e,t={}){const{timeout:n=1e4}=t;console.log(`Fetching event by ID: ${e}`);try{const t=[{ids:[e]}];console.log("Fetching event with filters:",t);const r=await ph(t,{timeout:n});return console.log(`Fetched ${r.length} events`),r.length>0?r[0]:null}catch(e){throw console.error("Failed to fetch event by ID:",e),e}}async function yh(e,t={}){const{timeout:n=1e4}=t;console.log(`Fetching delete events for target: ${e}`);try{const t=[{kinds:[5],"#e":[e]}];console.log("Fetching delete events with filters:",t);const r=await ph(t,{timeout:n});return console.log(`Fetched ${r.length} delete events`),r}catch(e){throw console.error("Failed to fetch delete events:",e),e}}async function vh(){await oh.connect()}async function mh(){try{const e=await ch(),t=e.transaction(ah,"readonly").objectStore(ah),n=await new Promise((e,n)=>{const r=t.getAll();r.onsuccess=()=>e(r.result),r.onerror=()=>n(r.error)}),r=n.reduce((e,t)=>(e[t.kind]=(e[t.kind]||0)+1,e),{});return console.log("===== IndexedDB Contents ====="),console.log(`Total events: ${n.length}`),console.log("Events by kind:",r),console.log("Kind 0 events:",n.filter(e=>0===e.kind)),console.log("All event IDs:",n.map(e=>({id:e.id.substring(0,8),kind:e.kind,pubkey:e.pubkey.substring(0,8)}))),console.log("=============================="),{total:n.length,byKind:r,events:n}}catch(e){return console.error("Failed to debug IndexedDB:",e),null}}const{window:wh}=c;function bh(e){let t,n,o,i,s,a,c,f,p,y,b,E,k,x,C,A,$,T;function I(e,t){return"extension"===e[2]?kh:Eh}let _=I(e),R=_(e),O=e[5]&&xh(e),L=e[6]&&Sh(e);return{c(){t=h("div"),n=h("div"),o=h("div"),i=h("h2"),i.textContent="Login to Nostr",s=g(),a=h("button"),a.textContent="×",c=g(),f=h("div"),p=h("div"),y=h("button"),y.textContent="Extension",b=g(),E=h("button"),E.textContent="Nsec",k=g(),x=h("div"),R.c(),C=g(),O&&O.c(),A=g(),L&&L.c(),w(i,"class","svelte-1cle6o2"),w(a,"class","close-btn svelte-1cle6o2"),w(o,"class","modal-header svelte-1cle6o2"),w(y,"class","tab-btn svelte-1cle6o2"),S(y,"active","extension"===e[2]),w(E,"class","tab-btn svelte-1cle6o2"),S(E,"active","nsec"===e[2]),w(p,"class","tabs svelte-1cle6o2"),w(x,"class","tab-content svelte-1cle6o2"),w(f,"class","tab-container svelte-1cle6o2"),w(n,"class","modal svelte-1cle6o2"),S(n,"dark-theme",e[1]),w(t,"class","modal-overlay svelte-1cle6o2"),w(t,"role","button"),w(t,"tabindex","0")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(o,i),l(o,s),l(o,a),l(n,c),l(n,f),l(f,p),l(p,y),l(p,b),l(p,E),l(f,k),l(f,x),R.m(x,null),l(x,C),O&&O.m(x,null),l(x,A),L&&L.m(x,null),$||(T=[v(a,"click",e[7]),v(y,"click",e[14]),v(E,"click",e[15]),v(n,"click",m(e[12])),v(n,"keydown",m(e[13])),v(t,"click",e[7]),v(t,"keydown",e[17])],$=!0)},p(e,t){4&t&&S(y,"active","extension"===e[2]),4&t&&S(E,"active","nsec"===e[2]),_===(_=I(e))&&R?R.p(e,t):(R.d(1),R=_(e),R&&(R.c(),R.m(x,C))),e[5]?O?O.p(e,t):(O=xh(e),O.c(),O.m(x,A)):O&&(O.d(1),O=null),e[6]?L?L.p(e,t):(L=Sh(e),L.c(),L.m(x,null)):L&&(L.d(1),L=null),2&t&&S(n,"dark-theme",e[1])},d(e){e&&d(t),R.d(),O&&O.d(),L&&L.d(),$=!1,r(T)}}}function Eh(e){let t,n,o,i,s,a,c,f,y,m,b=e[4]?"Logging in...":"Log in with nsec";return{c(){t=h("div"),n=h("p"),n.textContent="Enter your nsec (private key) to login. This\n will be stored securely in your browser.",o=g(),i=h("input"),s=g(),a=h("button"),c=p(b),w(n,"class","svelte-1cle6o2"),w(i,"type","password"),w(i,"placeholder","nsec1..."),i.disabled=e[4],w(i,"class","nsec-input svelte-1cle6o2"),w(a,"class","login-nsec-btn svelte-1cle6o2"),a.disabled=f=e[4]||!e[3].trim(),w(t,"class","nsec-login svelte-1cle6o2")},m(r,d){u(r,t,d),l(t,n),l(t,o),l(t,i),k(i,e[3]),l(t,s),l(t,a),l(a,c),y||(m=[v(i,"input",e[16]),v(a,"click",e[10])],y=!0)},p(e,t){16&t&&(i.disabled=e[4]),8&t&&i.value!==e[3]&&k(i,e[3]),16&t&&b!==(b=e[4]?"Logging in...":"Log in with nsec")&&E(c,b),24&t&&f!==(f=e[4]||!e[3].trim())&&(a.disabled=f)},d(e){e&&d(t),y=!1,r(m)}}}function kh(e){let t,n,r,o,i,s,a,c=e[4]?"Connecting...":"Log in using extension";return{c(){t=h("div"),n=h("p"),n.textContent="Login using a NIP-07 compatible browser\n extension like nos2x or Alby.",r=g(),o=h("button"),i=p(c),w(n,"class","svelte-1cle6o2"),w(o,"class","login-extension-btn svelte-1cle6o2"),o.disabled=e[4],w(t,"class","extension-login svelte-1cle6o2")},m(c,d){u(c,t,d),l(t,n),l(t,r),l(t,o),l(o,i),s||(a=v(o,"click",e[9]),s=!0)},p(e,t){16&t&&c!==(c=e[4]?"Connecting...":"Log in using extension")&&E(i,c),16&t&&(o.disabled=e[4])},d(e){e&&d(t),s=!1,a()}}}function xh(e){let t,n;return{c(){t=h("div"),n=p(e[5]),w(t,"class","message error-message svelte-1cle6o2")},m(e,r){u(e,t,r),l(t,n)},p(e,t){32&t&&E(n,e[5])},d(e){e&&d(t)}}}function Sh(e){let t,n;return{c(){t=h("div"),n=p(e[6]),w(t,"class","message success-message svelte-1cle6o2")},m(e,r){u(e,t,r),l(t,n)},p(e,t){64&t&&E(n,e[6])},d(e){e&&d(t)}}}function Ch(t){let n,r,o,i=t[0]&&bh(t);return{c(){i&&i.c(),n=y()},m(e,s){i&&i.m(e,s),u(e,n,s),r||(o=v(wh,"keydown",t[11]),r=!0)},p(e,[t]){e[0]?i?i.p(e,t):(i=bh(e),i.c(),i.m(n.parentNode,n)):i&&(i.d(1),i=null)},i:e,o:e,d(e){i&&i.d(e),e&&d(n),r=!1,o()}}}function Ah(e,t,n){const r=T();let{showModal:o=!1}=t,{isDarkTheme:i=!1}=t,s="extension",a="",c=!1,l="",u="";function d(){n(0,o=!1),n(3,a=""),n(5,l=""),n(6,u=""),r("close")}function f(e){n(2,s=e),n(5,l=""),n(6,u="")}async function h(){n(4,c=!0),n(5,l=""),n(6,u="");try{if(!a.trim())throw new Error("Please enter your nsec");if(!(e=a.trim()).startsWith("nsec1")||(e.length<60||e.length>70))throw new Error('Invalid nsec format. Must start with "nsec1"');const t=qd.fromKey(a.trim()),o=await t.getPublicKey();localStorage.setItem("nostr_auth_method","nsec"),localStorage.setItem("nostr_pubkey",o),localStorage.setItem("nostr_privkey",a.trim()),n(6,u="Successfully logged in with nsec!"),r("login",{method:"nsec",pubkey:o,privateKey:a.trim(),signer:t}),setTimeout(()=>{d()},1500)}catch(e){n(5,l=e.message)}finally{n(4,c=!1)}var e}return e.$$set=e=>{"showModal"in e&&n(0,o=e.showModal),"isDarkTheme"in e&&n(1,i=e.isDarkTheme)},[o,i,s,a,c,l,u,d,f,async function(){n(4,c=!0),n(5,l=""),n(6,u="");try{if(!window.nostr)throw new Error("No Nostr extension found. Please install a NIP-07 compatible extension like nos2x or Alby.");const e=await window.nostr.getPublicKey();e&&(localStorage.setItem("nostr_auth_method","extension"),localStorage.setItem("nostr_pubkey",e),n(6,u="Successfully logged in with extension!"),r("login",{method:"extension",pubkey:e,signer:window.nostr}),setTimeout(()=>{d()},1500))}catch(e){n(5,l=e.message)}finally{n(4,c=!1)}},h,function(e){"Escape"===e.key&&d(),"Enter"===e.key&&"nsec"===s&&h()},function(t){I.call(this,e,t)},function(t){I.call(this,e,t)},()=>f("extension"),()=>f("nsec"),function(){a=this.value,n(3,a)},e=>"Escape"===e.key&&d()]}class $h extends ee{constructor(e){super(),X(this,e,Ah,Ch,i,{showModal:0,isDarkTheme:1})}}function Th(e,t,n){const r=e.slice();return r[72]=t[n],r}function Ih(e,t,n){const r=e.slice();return r[75]=t[n],r}function _h(e,t,n){const r=e.slice();return r[72]=t[n],r}function Rh(e,t,n){const r=e.slice();return r[72]=t[n],r}function Oh(e,t,n){const r=e.slice();return r[72]=t[n],r}function Lh(e,t,n){const r=e.slice();return r[72]=t[n],r}function Ph(e,t,n){const r=e.slice();return r[72]=t[n],r}function Bh(e){let t,n,r;return{c(){t=h("div"),n=p(e[3]),w(t,"class",r="message "+e[4]+" svelte-1y8wjwc")},m(e,r){u(e,t,r),l(t,n)},p(e,o){8&o[0]&&E(n,e[3]),16&o[0]&&r!==(r="message "+e[4]+" svelte-1y8wjwc")&&w(t,"class",r)},d(e){e&&d(t)}}}function jh(e){let t,n,o,i,s,a,c,f,y,m,b,E,x,S,C,A,$,T,I,_,R,O,L,P,B,j,N,U;function M(e,t){return e[5]&&e[5].length>0?Uh:Nh}let F=M(e),D=F(e);function H(e,t){return e[8]&&e[8].length>0?Hh:Dh}let q=H(e),z=q(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Banned Pubkeys",i=g(),s=h("div"),a=h("input"),c=g(),f=h("input"),y=g(),m=h("button"),b=p("Ban Pubkey"),E=g(),x=h("div"),D.c(),S=g(),C=h("div"),A=h("h3"),A.textContent="Allowed Pubkeys",$=g(),T=h("div"),I=h("input"),_=g(),R=h("input"),O=g(),L=h("button"),P=p("Allow Pubkey"),B=g(),j=h("div"),z.c(),w(o,"class","svelte-1y8wjwc"),w(a,"type","text"),w(a,"placeholder","Pubkey (64 hex chars)"),w(a,"class","svelte-1y8wjwc"),w(f,"type","text"),w(f,"placeholder","Reason (optional)"),w(f,"class","svelte-1y8wjwc"),m.disabled=e[2],w(m,"class","svelte-1y8wjwc"),w(s,"class","add-form svelte-1y8wjwc"),w(x,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(A,"class","svelte-1y8wjwc"),w(I,"type","text"),w(I,"placeholder","Pubkey (64 hex chars)"),w(I,"class","svelte-1y8wjwc"),w(R,"type","text"),w(R,"placeholder","Reason (optional)"),w(R,"class","svelte-1y8wjwc"),L.disabled=e[2],w(L,"class","svelte-1y8wjwc"),w(T,"class","add-form svelte-1y8wjwc"),w(j,"class","list svelte-1y8wjwc"),w(C,"class","section svelte-1y8wjwc"),w(t,"class","pubkeys-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),k(a,e[6]),l(s,c),l(s,f),k(f,e[7]),l(s,y),l(s,m),l(m,b),l(n,E),l(n,x),D.m(x,null),l(t,S),l(t,C),l(C,A),l(C,$),l(C,T),l(T,I),k(I,e[9]),l(T,_),l(T,R),k(R,e[10]),l(T,O),l(T,L),l(L,P),l(C,B),l(C,j),z.m(j,null),N||(U=[v(a,"input",e[43]),v(f,"input",e[44]),v(m,"click",e[25]),v(I,"input",e[45]),v(R,"input",e[46]),v(L,"click",e[26])],N=!0)},p(e,t){64&t[0]&&a.value!==e[6]&&k(a,e[6]),128&t[0]&&f.value!==e[7]&&k(f,e[7]),4&t[0]&&(m.disabled=e[2]),F===(F=M(e))&&D?D.p(e,t):(D.d(1),D=F(e),D&&(D.c(),D.m(x,null))),512&t[0]&&I.value!==e[9]&&k(I,e[9]),1024&t[0]&&R.value!==e[10]&&k(R,e[10]),4&t[0]&&(L.disabled=e[2]),q===(q=H(e))&&z?z.p(e,t):(z.d(1),z=q(e),z&&(z.c(),z.m(j,null)))},d(e){e&&d(t),D.d(),z.d(),N=!1,r(U)}}}function Nh(t){let n;return{c(){n=h("div"),n.innerHTML="

No banned pubkeys configured.

",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Uh(e){let t,n=e[5],r=[];for(let t=0;tNo allowed pubkeys configured.

",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Hh(e){let t,n=e[8],r=[];for(let t=0;t0?Vh:Wh}let F=M(e),D=F(e);let H=function(e){return e[22]&&e[22].length>0?Qh:Zh}(e),q=H(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Banned Events",i=g(),s=h("div"),a=h("input"),c=g(),f=h("input"),y=g(),m=h("button"),b=p("Ban Event"),E=g(),x=h("div"),D.c(),S=g(),C=h("div"),A=h("h3"),A.textContent="Allowed Events",$=g(),T=h("div"),I=h("input"),_=g(),R=h("input"),O=g(),L=h("button"),P=p("Allow Event"),B=g(),j=h("div"),q.c(),w(o,"class","svelte-1y8wjwc"),w(a,"type","text"),w(a,"placeholder","Event ID (64 hex chars)"),w(a,"class","svelte-1y8wjwc"),w(f,"type","text"),w(f,"placeholder","Reason (optional)"),w(f,"class","svelte-1y8wjwc"),m.disabled=e[2],w(m,"class","svelte-1y8wjwc"),w(s,"class","add-form svelte-1y8wjwc"),w(x,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(A,"class","svelte-1y8wjwc"),w(I,"type","text"),w(I,"placeholder","Event ID (64 hex chars)"),w(I,"class","svelte-1y8wjwc"),w(R,"type","text"),w(R,"placeholder","Reason (optional)"),w(R,"class","svelte-1y8wjwc"),L.disabled=e[2],w(L,"class","svelte-1y8wjwc"),w(T,"class","add-form svelte-1y8wjwc"),w(j,"class","list svelte-1y8wjwc"),w(C,"class","section svelte-1y8wjwc"),w(t,"class","events-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),k(a,e[12]),l(s,c),l(s,f),k(f,e[13]),l(s,y),l(s,m),l(m,b),l(n,E),l(n,x),D.m(x,null),l(t,S),l(t,C),l(C,A),l(C,$),l(C,T),l(T,I),k(I,e[14]),l(T,_),l(T,R),k(R,e[15]),l(T,O),l(T,L),l(L,P),l(C,B),l(C,j),q.m(j,null),N||(U=[v(a,"input",e[47]),v(f,"input",e[48]),v(m,"click",e[27]),v(I,"input",e[49]),v(R,"input",e[50]),v(L,"click",e[28])],N=!0)},p(e,t){4096&t[0]&&a.value!==e[12]&&k(a,e[12]),8192&t[0]&&f.value!==e[13]&&k(f,e[13]),4&t[0]&&(m.disabled=e[2]),F===(F=M(e))&&D?D.p(e,t):(D.d(1),D=F(e),D&&(D.c(),D.m(x,null))),16384&t[0]&&I.value!==e[14]&&k(I,e[14]),32768&t[0]&&R.value!==e[15]&&k(R,e[15]),4&t[0]&&(L.disabled=e[2]),q.p(e,t)},d(e){e&&d(t),D.d(),q.d(),N=!1,r(U)}}}function Wh(t){let n;return{c(){n=h("div"),n.innerHTML="

No banned events configured.

",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Vh(e){let t,n=e[11],r=[];for(let t=0;tNo allowed events configured.

",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Qh(e){let t,n=e[22],r=[];for(let t=0;t0?tp:ep}let $=A(e),T=$(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Blocked IPs",i=g(),s=h("div"),a=h("input"),c=g(),f=h("input"),y=g(),m=h("button"),b=p("Block IP"),E=g(),x=h("div"),T.c(),w(o,"class","svelte-1y8wjwc"),w(a,"type","text"),w(a,"placeholder","IP Address"),w(a,"class","svelte-1y8wjwc"),w(f,"type","text"),w(f,"placeholder","Reason (optional)"),w(f,"class","svelte-1y8wjwc"),m.disabled=e[2],w(m,"class","svelte-1y8wjwc"),w(s,"class","add-form svelte-1y8wjwc"),w(x,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(t,"class","ips-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),k(a,e[17]),l(s,c),l(s,f),k(f,e[18]),l(s,y),l(s,m),l(m,b),l(n,E),l(n,x),T.m(x,null),S||(C=[v(a,"input",e[51]),v(f,"input",e[52]),v(m,"click",e[29])],S=!0)},p(e,t){131072&t[0]&&a.value!==e[17]&&k(a,e[17]),262144&t[0]&&f.value!==e[18]&&k(f,e[18]),4&t[0]&&(m.disabled=e[2]),$===($=A(e))&&T?T.p(e,t):(T.d(1),T=$(e),T&&(T.c(),T.m(x,null)))},d(e){e&&d(t),T.d(),S=!1,r(C)}}}function ep(t){let n;return{c(){n=h("div"),n.innerHTML="

No blocked IPs configured.

",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function tp(e){let t,n=e[16],r=[];for(let t=0;t0?sp:ip}let A=C(e),$=A(e);return{c(){t=h("div"),n=h("div"),o=h("h3"),o.textContent="Allowed Event Kinds",i=g(),s=h("div"),a=h("input"),c=g(),f=h("button"),y=p("Allow Kind"),m=g(),E=h("div"),$.c(),w(o,"class","svelte-1y8wjwc"),w(a,"type","number"),w(a,"placeholder","Kind number"),w(a,"class","svelte-1y8wjwc"),f.disabled=e[2],w(f,"class","svelte-1y8wjwc"),w(s,"class","add-form svelte-1y8wjwc"),w(E,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(t,"class","kinds-section")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),k(a,e[20]),l(s,c),l(s,f),l(f,y),l(n,m),l(n,E),$.m(E,null),x||(S=[v(a,"input",e[53]),v(f,"click",e[30])],x=!0)},p(e,t){1048576&t[0]&&b(a.value)!==e[20]&&k(a,e[20]),4&t[0]&&(f.disabled=e[2]),A===(A=C(e))&&$?$.p(e,t):($.d(1),$=A(e),$&&($.c(),$.m(E,null)))},d(e){e&&d(t),$.d(),x=!1,r(S)}}}function ip(t){let n;return{c(){n=h("div"),n.innerHTML="

No allowed kinds configured. All kinds are\n allowed by default.

",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function sp(e){let t,n=e[19],r=[];for(let t=0;t0?up:lp}let b=m(e),E=b(e);return{c(){t=h("div"),n=h("div"),r=h("h3"),r.textContent="Events Needing Moderation",o=g(),i=h("button"),s=p("Refresh"),a=g(),c=h("div"),E.c(),w(r,"class","svelte-1y8wjwc"),i.disabled=e[2],w(c,"class","list svelte-1y8wjwc"),w(n,"class","section svelte-1y8wjwc"),w(t,"class","moderation-section")},m(d,h){u(d,t,h),l(t,n),l(n,r),l(n,o),l(n,i),l(i,s),l(n,a),l(n,c),E.m(c,null),f||(y=v(i,"click",e[24]),f=!0)},p(e,t){4&t[0]&&(i.disabled=e[2]),b===(b=m(e))&&E?E.p(e,t):(E.d(1),E=b(e),E&&(E.c(),E.m(c,null)))},d(e){e&&d(t),E.d(),f=!1,y()}}}function lp(t){let n;return{c(){n=h("div"),n.innerHTML="

No events need moderation at this time.

",w(n,"class","no-items svelte-1y8wjwc")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function up(e){let t,n=e[21],r=[];for(let t=0;tManaged ACL Configuration \n

Configure access control using NIP-86 management API

\n
Owner Only: This interface is restricted to relay owners\n only.
',i=g(),J&&J.c(),s=g(),a=h("div"),c=h("button"),f=p("Pubkeys"),m=g(),b=h("button"),E=p("Events"),x=g(),S=h("button"),C=p("IPs"),$=g(),T=h("button"),I=p("Kinds"),R=g(),O=h("button"),L=p("Moderation"),B=g(),j=h("button"),N=p("Relay Config"),M=g(),F=h("div"),G&&G.c(),D=g(),Z&&Z.c(),H=g(),Q&&Q.c(),q=g(),Y&&Y.c(),z=g(),X&&X.c(),K=g(),ee&&ee.c(),w(o,"class","header svelte-1y8wjwc"),w(c,"class",y="tab "+("pubkeys"===t[1]?"active":"")+" svelte-1y8wjwc"),w(b,"class",k="tab "+("events"===t[1]?"active":"")+" svelte-1y8wjwc"),w(S,"class",A="tab "+("ips"===t[1]?"active":"")+" svelte-1y8wjwc"),w(T,"class",_="tab "+("kinds"===t[1]?"active":"")+" svelte-1y8wjwc"),w(O,"class",P="tab "+("moderation"===t[1]?"active":"")+" svelte-1y8wjwc"),w(j,"class",U="tab "+("relay"===t[1]?"active":"")+" svelte-1y8wjwc"),w(a,"class","tabs svelte-1y8wjwc"),w(F,"class","tab-content svelte-1y8wjwc")},m(e,r){u(e,n,r),l(n,o),l(n,i),J&&J.m(n,null),l(n,s),l(n,a),l(a,c),l(c,f),l(a,m),l(a,b),l(b,E),l(a,x),l(a,S),l(S,C),l(a,$),l(a,T),l(T,I),l(a,R),l(a,O),l(O,L),l(a,B),l(a,j),l(j,N),l(n,M),l(n,F),G&&G.m(F,null),l(F,D),Z&&Z.m(F,null),l(F,H),Q&&Q.m(F,null),l(F,q),Y&&Y.m(F,null),l(F,z),X&&X.m(F,null),l(F,K),ee&&ee.m(F,null),W||(V=[v(c,"click",t[37]),v(b,"click",t[38]),v(S,"click",t[39]),v(T,"click",t[40]),v(O,"click",t[41]),v(j,"click",t[42])],W=!0)},p(e,t){e[3]?J?J.p(e,t):(J=Bh(e),J.c(),J.m(n,s)):J&&(J.d(1),J=null),2&t[0]&&y!==(y="tab "+("pubkeys"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(c,"class",y),2&t[0]&&k!==(k="tab "+("events"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(b,"class",k),2&t[0]&&A!==(A="tab "+("ips"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(S,"class",A),2&t[0]&&_!==(_="tab "+("kinds"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(T,"class",_),2&t[0]&&P!==(P="tab "+("moderation"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(O,"class",P),2&t[0]&&U!==(U="tab "+("relay"===e[1]?"active":"")+" svelte-1y8wjwc")&&w(j,"class",U),"pubkeys"===e[1]?G?G.p(e,t):(G=jh(e),G.c(),G.m(F,D)):G&&(G.d(1),G=null),"events"===e[1]?Z?Z.p(e,t):(Z=Kh(e),Z.c(),Z.m(F,H)):Z&&(Z.d(1),Z=null),"ips"===e[1]?Q?Q.p(e,t):(Q=Xh(e),Q.c(),Q.m(F,q)):Q&&(Q.d(1),Q=null),"kinds"===e[1]?Y?Y.p(e,t):(Y=op(e),Y.c(),Y.m(F,z)):Y&&(Y.d(1),Y=null),"moderation"===e[1]?X?X.p(e,t):(X=cp(e),X.c(),X.m(F,K)):X&&(X.d(1),X=null),"relay"===e[1]?ee?ee.p(e,t):(ee=hp(e),ee.c(),ee.m(F,null)):ee&&(ee.d(1),ee=null)},i:e,o:e,d(e){e&&d(n),J&&J.d(),G&&G.d(),Z&&Z.d(),Q&&Q.d(),Y&&Y.d(),X&&X.d(),ee&&ee.d(),W=!1,r(V)}}}function vp(e,t,n){let{userSigner:r}=t,{userPubkey:o}=t,i="pubkeys",s=!1,a="",c="info",l=[],u="",d="",f=[],h="",p="",g=[],y="",v="",m="",w="",E=[],k="",x="",S=[],C="",A=[],T={relay_name:"",relay_description:"",relay_icon:""};var I;async function _(){try{n(2,s=!0),console.log("Fetching relay info from /");const e=await fetch(window.location.origin+"/",{headers:{Accept:"application/nostr+json"}});if(console.log("Response status:",e.status),console.log("Response headers:",e.headers),e.ok){const t=await e.json();console.log("Raw relay info:",t),n(0,T={relay_name:t.name||"",relay_description:t.description||"",relay_icon:t.icon||""}),console.log("Updated relayConfig:",T),console.log("Loaded relay info:",t),n(3,a="Relay configuration loaded successfully"),n(4,c="success")}else console.error("Failed to fetch relay info, status:",e.status),n(3,a=`Failed to fetch relay info: ${e.status}`),n(4,c="error")}catch(e){console.error("Failed to fetch relay info:",e),n(3,a=`Failed to fetch relay info: ${e.message}`),n(4,c="error")}finally{n(2,s=!1)}}async function R(e,t=[]){try{n(2,s=!0),n(3,a="");const i={method:e,params:t},c=await async function(e,t){if(!r)throw new Error("No signer available for authentication. Please log in with a Nostr extension.");if(!o)throw new Error("No user pubkey available for authentication.");const n=window.location.origin+t,i={kind:27235,created_at:Math.floor(Date.now()/1e3),tags:[["u",n],["method",e]],content:"",pubkey:o},s=await r.signEvent(i),a=JSON.stringify(s);return`Nostr ${btoa(a)}`}("POST","/api/nip86"),l=await fetch("/api/nip86",{method:"POST",headers:{"Content-Type":"application/nostr+json+rpc",Authorization:c},body:JSON.stringify(i)});if(!l.ok)throw new Error(`HTTP ${l.status}: ${l.statusText}`);const u=await l.json();if(u.error)throw new Error(u.error);return u.result}catch(e){throw console.error("NIP-86 API error:",e),n(3,a=e.message),n(4,c="error"),e}finally{n(2,s=!1)}}async function O(){try{n(5,l=await R("listbannedpubkeys"))}catch(e){console.error("Failed to load banned pubkeys:",e)}}async function L(){try{n(8,f=await R("listallowedpubkeys"))}catch(e){console.error("Failed to load allowed pubkeys:",e)}}async function P(){try{n(11,g=await R("listbannedevents"))}catch(e){console.error("Failed to load banned events:",e)}}async function B(){try{n(16,E=await R("listblockedips"))}catch(e){console.error("Failed to load blocked IPs:",e)}}async function j(){try{n(19,S=await R("listallowedkinds"))}catch(e){console.error("Failed to load allowed kinds:",e)}}async function N(){try{n(2,s=!0),n(21,A=await R("listeventsneedingmoderation")),console.log("Loaded events needing moderation:",A)}catch(e){console.error("Failed to load events needing moderation:",e),n(3,a=`Failed to load moderation events: ${e.message}`),n(4,c="error"),n(21,A=[])}finally{n(2,s=!1)}}async function U(e){try{await R("disallowkind",[e]),n(3,a="Kind disallowed successfully"),n(4,c="success"),await j()}catch(e){console.error("Failed to disallow kind:",e)}}async function M(e){try{await R("allowevent",[e,"Approved from moderation queue"]),n(3,a="Event allowed successfully"),n(4,c="success"),await N()}catch(e){console.error("Failed to allow event from moderation:",e)}}async function F(e){try{await R("banevent",[e,"Banned from moderation queue"]),n(3,a="Event banned successfully"),n(4,c="success"),await N()}catch(e){console.error("Failed to ban event from moderation:",e)}}I=()=>{setTimeout(()=>{_()},100)},$().$$.on_mount.push(I),async function(){await Promise.all([O(),L(),P(),B(),j()])}();return e.$$set=e=>{"userSigner"in e&&n(35,r=e.userSigner),"userPubkey"in e&&n(36,o=e.userPubkey)},e.$$.update=()=>{1&e.$$.dirty[0]&&console.log("relayConfig changed:",T)},[T,i,s,a,c,l,u,d,f,h,p,g,y,v,m,w,E,k,x,S,C,A,[],_,N,async function(){if(u)try{await R("banpubkey",[u,d]),n(3,a="Pubkey banned successfully"),n(4,c="success"),n(6,u=""),n(7,d=""),await O()}catch(e){console.error("Failed to ban pubkey:",e)}},async function(){if(h)try{await R("allowpubkey",[h,p]),n(3,a="Pubkey allowed successfully"),n(4,c="success"),n(9,h=""),n(10,p=""),await L()}catch(e){console.error("Failed to allow pubkey:",e)}},async function(){if(y)try{await R("banevent",[y,v]),n(3,a="Event banned successfully"),n(4,c="success"),n(12,y=""),n(13,v=""),await P()}catch(e){console.error("Failed to ban event:",e)}},async function(){if(m)try{await R("allowevent",[m,w]),n(3,a="Event allowed successfully"),n(4,c="success"),n(14,m=""),n(15,w="")}catch(e){console.error("Failed to allow event:",e)}},async function(){if(k)try{await R("blockip",[k,x]),n(3,a="IP blocked successfully"),n(4,c="success"),n(17,k=""),n(18,x=""),await B()}catch(e){console.error("Failed to block IP:",e)}},async function(){if(!C)return;const e=parseInt(C);if(isNaN(e))return n(3,a="Invalid kind number"),void n(4,c="error");try{await R("allowkind",[e]),n(3,a="Kind allowed successfully"),n(4,c="success"),n(20,C=""),await j()}catch(e){console.error("Failed to allow kind:",e)}},U,async function(){try{n(2,s=!0),n(3,a="");const e=[];if(T.relay_name&&e.push(R("changerelayname",[T.relay_name])),T.relay_description&&e.push(R("changerelaydescription",[T.relay_description])),T.relay_icon&&e.push(R("changerelayicon",[T.relay_icon])),0===e.length)return n(3,a="No changes to update"),void n(4,c="info");await Promise.all(e),n(3,a="Relay configuration updated successfully"),n(4,c="success"),await _()}catch(e){console.error("Failed to update relay configuration:",e),n(3,a=`Failed to update relay configuration: ${e.message}`),n(4,c="error")}finally{n(2,s=!1)}},M,F,r,o,()=>n(1,i="pubkeys"),()=>n(1,i="events"),()=>n(1,i="ips"),()=>n(1,i="kinds"),()=>{n(1,i="moderation"),A&&0!==A.length||N()},()=>n(1,i="relay"),function(){u=this.value,n(6,u)},function(){d=this.value,n(7,d)},function(){h=this.value,n(9,h)},function(){p=this.value,n(10,p)},function(){y=this.value,n(12,y)},function(){v=this.value,n(13,v)},function(){m=this.value,n(14,m)},function(){w=this.value,n(15,w)},function(){k=this.value,n(17,k)},function(){x=this.value,n(18,x)},function(){C=b(this.value),n(20,C)},e=>U(e),e=>M(e.id),e=>F(e.id),function(){T.relay_name=this.value,n(0,T)},function(){T.relay_description=this.value,n(0,T)},function(){T.relay_icon=this.value,n(0,T)}]}class mp extends ee{constructor(e){super(),X(this,e,vp,yp,i,{userSigner:35,userPubkey:36},null,[-1,-1,-1])}}function wp(e){let t,n,r,o=e[3]&&e[4]&&Ep(e);return{c(){t=h("div"),n=h("span"),r=p("ORLY? dashboard\n "),o&&o.c(),w(n,"class","app-title svelte-1mrm2k6"),w(t,"class","header-title svelte-1mrm2k6")},m(e,i){u(e,t,i),l(t,n),l(n,r),o&&o.m(n,null)},p(e,t){e[3]&&e[4]?o?o.p(e,t):(o=Ep(e),o.c(),o.m(n,null)):o&&(o.d(1),o=null)},d(e){e&&d(t),o&&o.d()}}}function bp(e){let t,n,o,i;return{c(){t=h("div"),n=h("input"),w(n,"type","text"),w(n,"class","search-input svelte-1mrm2k6"),w(n,"placeholder","Search..."),w(t,"class","search-input-container svelte-1mrm2k6")},m(r,s){u(r,t,s),l(t,n),k(n,e[0]),o||(i=[v(n,"input",e[13]),v(n,"keydown",e[8])],o=!0)},p(e,t){1&t&&n.value!==e[0]&&k(n,e[0])},d(e){e&&d(t),o=!1,r(i)}}}function Ep(e){let t,n;return{c(){t=h("span"),n=p(e[5]),w(t,"class","permission-badge svelte-1mrm2k6")},m(e,r){u(e,t,r),l(t,n)},p(e,t){32&t&&E(n,e[5])},d(e){e&&d(t)}}}function kp(t){let n,r,o;return{c(){n=h("button"),n.textContent="Log in",w(n,"class","login-btn svelte-1mrm2k6")},m(e,i){u(e,n,i),r||(o=v(n,"click",t[12]),r=!0)},p:e,d(e){e&&d(n),r=!1,o()}}}function xp(e){let t,n,r,o,i,s,a=(e[6]?.name||e[7].slice(0,8)+"...")+"";function c(e,t){return e[6]?.picture?Cp:Sp}let f=c(e),y=f(e);return{c(){t=h("button"),y.c(),n=g(),r=h("span"),o=p(a),w(r,"class","user-name svelte-1mrm2k6"),w(t,"class","user-profile-btn svelte-1mrm2k6")},m(a,c){u(a,t,c),y.m(t,null),l(t,n),l(t,r),l(r,o),i||(s=v(t,"click",e[11]),i=!0)},p(e,r){f===(f=c(e))&&y?y.p(e,r):(y.d(1),y=f(e),y&&(y.c(),y.m(t,n))),192&r&&a!==(a=(e[6]?.name||e[7].slice(0,8)+"...")+"")&&E(o,a)},d(e){e&&d(t),y.d(),i=!1,s()}}}function Sp(t){let n;return{c(){n=h("div"),n.textContent="👤",w(n,"class","user-avatar-placeholder svelte-1mrm2k6")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Cp(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[6].picture)||w(t,"src",n),w(t,"alt","User avatar"),w(t,"class","user-avatar svelte-1mrm2k6")},m(e,n){u(e,t,n)},p(e,r){64&r&&!a(t.src,n=e[6].picture)&&w(t,"src",n)},d(e){e&&d(t)}}}function Ap(t){let n,o,i,s,c,f,y,m,b,k,x,C,A,$,T=t[1]?"☀️":"🌙";function I(e,t){return e[2]?bp:wp}let _=I(t),R=_(t);function O(e,t){return e[3]?xp:kp}let L=O(t),P=L(t);return{c(){n=h("header"),o=h("div"),i=h("img"),c=g(),R.c(),f=g(),y=h("div"),m=h("button"),m.textContent="🔍",b=g(),k=h("button"),x=p(T),C=g(),P.c(),a(i.src,s="/orly.png")||w(i,"src","/orly.png"),w(i,"alt","ORLY Logo"),w(i,"class","logo svelte-1mrm2k6"),w(m,"class","search-btn svelte-1mrm2k6"),w(k,"class","theme-toggle-btn svelte-1mrm2k6"),w(y,"class","header-buttons svelte-1mrm2k6"),w(o,"class","header-content svelte-1mrm2k6"),w(n,"class","main-header svelte-1mrm2k6"),S(n,"dark-theme",t[1])},m(e,r){u(e,n,r),l(n,o),l(o,i),l(o,c),R.m(o,null),l(o,f),l(o,y),l(y,m),l(y,b),l(y,k),l(k,x),l(y,C),P.m(y,null),A||($=[v(m,"click",t[9]),v(k,"click",t[10])],A=!0)},p(e,[t]){_===(_=I(e))&&R?R.p(e,t):(R.d(1),R=_(e),R&&(R.c(),R.m(o,f))),2&t&&T!==(T=e[1]?"☀️":"🌙")&&E(x,T),L===(L=O(e))&&P?P.p(e,t):(P.d(1),P=L(e),P&&(P.c(),P.m(y,null))),2&t&&S(n,"dark-theme",e[1])},i:e,o:e,d(e){e&&d(n),R.d(),P.d(),A=!1,r($)}}}function $p(e,t,n){let{isDarkTheme:r=!1}=t,{isSearchMode:o=!1}=t,{searchQuery:i=""}=t,{isLoggedIn:s=!1}=t,{userRole:a=""}=t,{currentEffectiveRole:c=""}=t,{userProfile:l=null}=t,{userPubkey:u=""}=t;const d=T();return e.$$set=e=>{"isDarkTheme"in e&&n(1,r=e.isDarkTheme),"isSearchMode"in e&&n(2,o=e.isSearchMode),"searchQuery"in e&&n(0,i=e.searchQuery),"isLoggedIn"in e&&n(3,s=e.isLoggedIn),"userRole"in e&&n(4,a=e.userRole),"currentEffectiveRole"in e&&n(5,c=e.currentEffectiveRole),"userProfile"in e&&n(6,l=e.userProfile),"userPubkey"in e&&n(7,u=e.userPubkey)},[i,r,o,s,a,c,l,u,function(e){d("searchKeydown",e)},function(){d("toggleSearchMode")},function(){d("toggleTheme")},function(){d("openSettingsDrawer")},function(){d("openLoginModal")},function(){i=this.value,n(0,i)}]}class Tp extends ee{constructor(e){super(),X(this,e,$p,Ap,i,{isDarkTheme:1,isSearchMode:2,searchQuery:0,isLoggedIn:3,userRole:4,currentEffectiveRole:5,userProfile:6,userPubkey:7})}}function Ip(e,t,n){const r=e.slice();return r[9]=t[n],r}function _p(e){let t,n,o;function i(){return e[5](e[9])}function s(...t){return e[6](e[9],...t)}return{c(){t=h("span"),t.textContent="✕",w(t,"class","tab-close-icon svelte-1tm0fmz"),w(t,"role","button"),w(t,"tabindex","0")},m(e,r){u(e,t,r),n||(o=[v(t,"click",m(i)),v(t,"keydown",s)],n=!0)},p(t,n){e=t},d(e){e&&d(t),n=!1,r(o)}}}function Rp(e){let t,n,r,o,i,s,a,c,f,y,m=e[9].icon+"",b=e[9].label+"",k=e[9].isSearchTab&&_p(e);function x(){return e[7](e[9])}return{c(){t=h("button"),n=h("span"),r=p(m),o=g(),i=h("span"),s=p(b),a=g(),k&&k.c(),c=g(),w(n,"class","tab-icon svelte-1tm0fmz"),w(i,"class","tab-label svelte-1tm0fmz"),w(t,"class","tab svelte-1tm0fmz"),S(t,"active",e[2]===e[9].id)},m(e,d){u(e,t,d),l(t,n),l(n,r),l(t,o),l(t,i),l(i,s),l(t,a),k&&k.m(t,null),l(t,c),f||(y=v(t,"click",x),f=!0)},p(n,o){e=n,2&o&&m!==(m=e[9].icon+"")&&E(r,m),2&o&&b!==(b=e[9].label+"")&&E(s,b),e[9].isSearchTab?k?k.p(e,o):(k=_p(e),k.c(),k.m(t,c)):k&&(k.d(1),k=null),6&o&&S(t,"active",e[2]===e[9].id)},d(e){e&&d(t),k&&k.d(),f=!1,y()}}}function Op(t){let n,r,o,i=t[1],s=[];for(let e=0;e{"isDarkTheme"in e&&n(0,r=e.isDarkTheme),"tabs"in e&&n(1,o=e.tabs),"selectedTab"in e&&n(2,i=e.selectedTab)},[r,o,i,a,c,e=>c(e.id),(e,t)=>"Enter"===t.key&&c(e.id),e=>a(e.id)]}class Pp extends ee{constructor(e){super(),X(this,e,Lp,Op,i,{isDarkTheme:0,tabs:1,selectedTab:2})}}function Bp(t){let n,r,o,i,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in to access export functionality.",o=g(),i=h("button"),i.textContent="Log In",w(r,"class","svelte-1qkvicp"),w(i,"class","login-btn svelte-1qkvicp"),w(n,"class","login-prompt svelte-1qkvicp")},m(e,c){u(e,n,c),l(n,r),l(n,o),l(n,i),s||(a=v(i,"click",t[4]),s=!0)},p:e,d(e){e&&d(n),s=!1,a()}}}function jp(e){let t,n,r,o,i,s,a,c,f,p,m=("admin"===e[1]||"owner"===e[1])&&Np(e);return{c(){t=h("div"),n=h("h3"),n.textContent="Export My Events",r=g(),o=h("p"),o.textContent="Download your personal events as a JSONL file.",i=g(),s=h("button"),s.textContent="📤 Export My Events",a=g(),m&&m.c(),c=y(),w(n,"class","svelte-1qkvicp"),w(o,"class","svelte-1qkvicp"),w(s,"class","export-btn svelte-1qkvicp"),w(t,"class","export-section svelte-1qkvicp")},m(d,h){u(d,t,h),l(t,n),l(t,r),l(t,o),l(t,i),l(t,s),u(d,a,h),m&&m.m(d,h),u(d,c,h),f||(p=v(s,"click",e[2]),f=!0)},p(e,t){"admin"===e[1]||"owner"===e[1]?m?m.p(e,t):(m=Np(e),m.c(),m.m(c.parentNode,c)):m&&(m.d(1),m=null)},d(e){e&&d(t),e&&d(a),m&&m.d(e),e&&d(c),f=!1,p()}}}function Np(t){let n,r,o,i,s,a,c,f;return{c(){n=h("div"),r=h("h3"),r.textContent="Export All Events",o=g(),i=h("p"),i.textContent="Download the complete database as a JSONL file. This includes\n all events from all users.",s=g(),a=h("button"),a.textContent="📤 Export All Events",w(r,"class","svelte-1qkvicp"),w(i,"class","svelte-1qkvicp"),w(a,"class","export-btn svelte-1qkvicp"),w(n,"class","export-section svelte-1qkvicp")},m(e,d){u(e,n,d),l(n,r),l(n,o),l(n,i),l(n,s),l(n,a),c||(f=v(a,"click",t[3]),c=!0)},p:e,d(e){e&&d(n),c=!1,f()}}}function Up(t){let n;function r(e,t){return e[0]?jp:Bp}let o=r(t),i=o(t);return{c(){i.c(),n=y()},m(e,t){i.m(e,t),u(e,n,t)},p(e,[t]){o===(o=r(e))&&i?i.p(e,t):(i.d(1),i=o(e),i&&(i.c(),i.m(n.parentNode,n)))},i:e,o:e,d(e){i.d(e),e&&d(n)}}}function Mp(e,t,n){let{isLoggedIn:r=!1}=t,{currentEffectiveRole:o=""}=t;const i=T();return e.$$set=e=>{"isLoggedIn"in e&&n(0,r=e.isLoggedIn),"currentEffectiveRole"in e&&n(1,o=e.currentEffectiveRole)},[r,o,function(){i("exportMyEvents")},function(){i("exportAllEvents")},function(){i("openLoginModal")}]}class Fp extends ee{constructor(e){super(),X(this,e,Mp,Up,i,{isLoggedIn:0,currentEffectiveRole:1})}}function Dp(t){let n,r,o,i,s,a,c,f;return{c(){n=h("div"),r=h("h3"),r.textContent="Import Events",o=g(),i=h("p"),i.textContent="Please log in to access import functionality.",s=g(),a=h("button"),a.textContent="Log In",w(r,"class","recovery-header svelte-1nvu2m9"),w(i,"class","recovery-description svelte-1nvu2m9"),w(a,"class","login-btn svelte-1nvu2m9"),w(n,"class","login-prompt svelte-1nvu2m9")},m(e,d){u(e,n,d),l(n,r),l(n,o),l(n,i),l(n,s),l(n,a),c||(f=v(a,"click",t[5]),c=!0)},p:e,d(e){e&&d(n),c=!1,f()}}}function Hp(t){let n;return{c(){n=h("div"),n.innerHTML='

Import Events

\n

❌ Admin or owner permission required for import functionality.

',w(n,"class","permission-denied svelte-1nvu2m9")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function qp(e){let t,n,o,i,s,a,c,f,y,m,b,E;return{c(){t=h("h3"),t.textContent="Import Events",n=g(),o=h("p"),o.textContent="Upload a JSONL file to import events into the database.",i=g(),s=h("div"),a=h("input"),c=g(),f=h("button"),y=p("Import Events"),w(t,"class","svelte-1nvu2m9"),w(o,"class","svelte-1nvu2m9"),w(a,"type","file"),w(a,"id","import-file"),w(a,"accept",".jsonl,.txt"),w(a,"class","svelte-1nvu2m9"),w(f,"class","import-btn svelte-1nvu2m9"),f.disabled=m=!e[2],w(s,"class","recovery-controls-card svelte-1nvu2m9")},m(r,d){u(r,t,d),u(r,n,d),u(r,o,d),u(r,i,d),u(r,s,d),l(s,a),l(s,c),l(s,f),l(f,y),b||(E=[v(a,"change",e[3]),v(f,"click",e[4])],b=!0)},p(e,t){4&t&&m!==(m=!e[2])&&(f.disabled=m)},d(e){e&&d(t),e&&d(n),e&&d(o),e&&d(i),e&&d(s),b=!1,r(E)}}}function zp(t){let n;function r(e,t){return!e[0]||"admin"!==e[1]&&"owner"!==e[1]?e[0]?Hp:Dp:qp}let o=r(t),i=o(t);return{c(){n=h("div"),i.c(),w(n,"class","import-section svelte-1nvu2m9")},m(e,t){u(e,n,t),i.m(n,null)},p(e,[t]){o===(o=r(e))&&i?i.p(e,t):(i.d(1),i=o(e),i&&(i.c(),i.m(n,null)))},i:e,o:e,d(e){e&&d(n),i.d()}}}function Kp(e,t,n){let{isLoggedIn:r=!1}=t,{currentEffectiveRole:o=""}=t,{selectedFile:i=null}=t;const s=T();return e.$$set=e=>{"isLoggedIn"in e&&n(0,r=e.isLoggedIn),"currentEffectiveRole"in e&&n(1,o=e.currentEffectiveRole),"selectedFile"in e&&n(2,i=e.selectedFile)},[r,o,i,function(e){s("fileSelect",e)},function(){s("importEvents")},function(){s("openLoginModal")}]}class Wp extends ee{constructor(e){super(),X(this,e,Kp,zp,i,{isLoggedIn:0,currentEffectiveRole:1,selectedFile:2})}}function Vp(e,t,n){const r=e.slice();return r[22]=t[n],r}function Jp(e,t,n){const r=e.slice();return r[25]=t[n],r}function Gp(t){let n;return{c(){n=h("div"),n.innerHTML="

❌ Read, write, admin, or owner permission required to view all\n events.

",w(n,"class","permission-denied svelte-kvggf0")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Zp(e){let t,n,r,o;function i(e,t){return e[4].length>0?Yp:e[6]?void 0:Qp}let s=i(e),a=s&&s(e),c=e[6]&&sg();return{c(){t=h("div"),a&&a.c(),n=g(),c&&c.c(),w(t,"class","events-view-content svelte-kvggf0")},m(i,s){u(i,t,s),a&&a.m(t,null),l(t,n),c&&c.m(t,null),r||(o=v(t,"scroll",e[7]),r=!0)},p(e,r){s===(s=i(e))&&a?a.p(e,r):(a&&a.d(1),a=s&&s(e),a&&(a.c(),a.m(t,n))),e[6]?c||(c=sg(),c.c(),c.m(t,null)):c&&(c.d(1),c=null)},d(e){e&&d(t),a&&a.d(),c&&c.d(),r=!1,o()}}}function Qp(t){let n;return{c(){n=h("div"),n.innerHTML="

No events found.

",w(n,"class","no-events svelte-kvggf0")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Yp(e){let t,n=e[4],r=[];for(let t=0;t0&&tg(e);return{c(){t=h("div"),n=h("span"),n.textContent="🗑️ Delete Event",r=g(),o&&o.c(),w(n,"class","delete-event-label svelte-kvggf0"),w(t,"class","delete-event-info svelte-kvggf0")},m(e,i){u(e,t,i),l(t,n),l(t,r),o&&o.m(t,null)},p(e,n){e[22].tags&&e[22].tags.length>0?o?o.p(e,n):(o=tg(e),o.c(),o.m(t,null)):o&&(o.d(1),o=null)},d(e){e&&d(t),o&&o.d()}}}function tg(e){let t,n=e[22].tags.filter(gg),r=[];for(let t=0;t👤',i=g(),s=h("div"),a=h("div"),c=p(j),f=g(),y=h("div"),m=h("span"),b=p(N),k=g(),x=h("span"),C=p(U),A=g(),$=h("div"),T=h("div"),I=p(M),_=g(),q.c(),R=g(),z&&z.c(),O=g(),V&&V.c(),L=g(),w(o,"class","events-view-avatar svelte-kvggf0"),w(a,"class","events-view-author svelte-kvggf0"),w(m,"class","kind-number svelte-kvggf0"),S(m,"delete-event",5===e[22].kind),w(x,"class","kind-name svelte-kvggf0"),w(y,"class","events-view-kind svelte-kvggf0"),w(s,"class","events-view-info svelte-kvggf0"),w(T,"class","event-timestamp svelte-kvggf0"),w($,"class","events-view-content svelte-kvggf0"),w(n,"class","events-view-row svelte-kvggf0"),w(n,"role","button"),w(n,"tabindex","0"),w(t,"class","events-view-item svelte-kvggf0"),S(t,"expanded",e[5].has(e[22].id))},m(e,r){u(e,t,r),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(s,f),l(s,y),l(y,m),l(m,b),l(y,k),l(y,x),l(x,C),l(n,A),l(n,$),l($,T),l(T,I),l($,_),q.m($,null),l(n,R),z&&z.m(n,null),l(t,O),V&&V.m(t,null),l(t,L),P||(B=[v(n,"click",K),v(n,"keydown",W)],P=!0)},p(r,o){e=r,16&o&&j!==(j=dg(e[22].pubkey)+"")&&E(c,j),16&o&&N!==(N=e[22].kind+"")&&E(b,N),16&o&&S(m,"delete-event",5===e[22].kind),16&o&&U!==(U=fg(e[22].kind)+"")&&E(C,U),16&o&&M!==(M=hg(e[22].created_at)+"")&&E(I,M),H===(H=D(e))&&q?q.p(e,o):(q.d(1),q=H(e),q&&(q.c(),q.m($,null))),5!==e[22].kind&&("admin"===e[2]||"owner"===e[2]||"write"===e[2]&&e[22].pubkey&&e[22].pubkey===e[3])?z?z.p(e,o):(z=rg(e),z.c(),z.m(n,null)):z&&(z.d(1),z=null),48&o&&(F=e[5].has(e[22].id)),F?V?V.p(e,o):(V=og(e),V.c(),V.m(t,L)):V&&(V.d(1),V=null),48&o&&S(t,"expanded",e[5].has(e[22].id))},d(e){e&&d(t),q.d(),z&&z.d(),V&&V.d(),P=!1,r(B)}}}function sg(e){let t;return{c(){t=h("div"),t.innerHTML='
\n

Loading events...

',w(t,"class","loading-events svelte-kvggf0")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function ag(e){let t,n,o,i,s,a,c,f,y,m,b,E,k,x,S,C;function A(e,t){return e[6]?lg:cg}let $=A(e),T=$(e);return{c(){t=h("div"),n=h("div"),o=h("label"),i=h("input"),s=g(),a=h("span"),c=g(),f=h("span"),f.textContent="Only show my events",y=g(),m=h("div"),b=h("button"),E=p("🔄 Load More"),k=g(),x=h("button"),T.c(),w(i,"type","checkbox"),w(i,"class","svelte-kvggf0"),w(a,"class","toggle-slider svelte-kvggf0"),w(f,"class","toggle-label svelte-kvggf0"),w(o,"class","toggle-container svelte-kvggf0"),w(n,"class","events-view-toggle svelte-kvggf0"),w(b,"class","refresh-btn svelte-kvggf0"),b.disabled=e[6],w(x,"class","reload-btn svelte-kvggf0"),x.disabled=e[6],w(m,"class","events-view-buttons svelte-kvggf0"),w(t,"class","events-view-header svelte-kvggf0")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(o,i),i.checked=e[0],l(o,s),l(o,a),l(o,c),l(o,f),l(t,y),l(t,m),l(m,b),l(b,E),l(m,k),l(m,x),T.m(x,null),S||(C=[v(i,"change",e[17]),v(i,"change",e[18]),v(b,"click",e[19]),v(x,"click",e[20])],S=!0)},p(e,t){1&t&&(i.checked=e[0]),64&t&&(b.disabled=e[6]),$!==($=A(e))&&(T.d(1),T=$(e),T&&(T.c(),T.m(x,null))),64&t&&(x.disabled=e[6])},d(e){e&&d(t),T.d(),S=!1,r(C)}}}function cg(e){let t;return{c(){t=p("🔄")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function lg(e){let t;return{c(){t=h("div"),w(t,"class","spinner svelte-kvggf0")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function ug(t){let n,r;function o(e,t){return!e[1]||"read"!==e[2]&&"write"!==e[2]&&"admin"!==e[2]&&"owner"!==e[2]?Gp:Zp}let i=o(t),s=i(t),a=t[1]&&("read"===t[2]||"write"===t[2]||"admin"===t[2]||"owner"===t[2])&&ag(t);return{c(){n=h("div"),s.c(),r=g(),a&&a.c(),w(n,"class","events-view-container svelte-kvggf0")},m(e,t){u(e,n,t),s.m(n,null),l(n,r),a&&a.m(n,null)},p(e,[t]){i===(i=o(e))&&s?s.p(e,t):(s.d(1),s=i(e),s&&(s.c(),s.m(n,r))),!e[1]||"read"!==e[2]&&"write"!==e[2]&&"admin"!==e[2]&&"owner"!==e[2]?a&&(a.d(1),a=null):a?a.p(e,t):(a=ag(e),a.c(),a.m(n,null))},i:e,o:e,d(e){e&&d(n),s.d(),a&&a.d()}}}function dg(e){return e?e.slice(0,8)+"..."+e.slice(-8):""}function fg(e){return{0:"Profile",1:"Text Note",2:"Recommend Relay",3:"Contacts",4:"Encrypted DM",5:"Delete",6:"Repost",7:"Reaction",8:"Badge Award",16:"Generic Repost",40:"Channel Creation",41:"Channel Metadata",42:"Channel Message",43:"Channel Hide Message",44:"Channel Mute User",1984:"Reporting",9734:"Zap Request",9735:"Zap",1e4:"Mute List",10001:"Pin List",10002:"Relay List",22242:"Client Auth",24133:"Nostr Connect",27235:"HTTP Auth",3e4:"Categorized People",30001:"Categorized Bookmarks",30008:"Profile Badges",30009:"Badge Definition",30017:"Create or update a stall",30018:"Create or update a product",30023:"Long-form Content",30024:"Draft Long-form Content",30078:"Application-specific Data",30311:"Live Event",30315:"User Statuses",30402:"Classified Listing",30403:"Draft Classified Listing",31922:"Date-Based Calendar Event",31923:"Time-Based Calendar Event",31924:"Calendar",31925:"Calendar Event RSVP",31989:"Handler recommendation",31990:"Handler information",34550:"Community Definition"}[e]||`Kind ${e}`}function hg(e){return new Date(1e3*e).toLocaleString()}function pg(e){return e?e.length>100?e.slice(0,100)+"...":e:""}const gg=e=>"e"===e[0];function yg(e,t,n){let{isLoggedIn:r=!1}=t,{userRole:o=""}=t,{userPubkey:i=""}=t,{filteredEvents:s=[]}=t,{expandedEvents:a=new Set}=t,{isLoadingEvents:c=!1}=t,{showOnlyMyEvents:l=!1}=t;const u=T();function d(e){u("toggleEventExpansion",e)}function f(e){u("deleteEvent",e)}function h(e,t){u("copyEventToClipboard",{event:e,e:t})}function p(){u("toggleChange")}function g(e,t){u("loadAllEvents",{refresh:e,authors:t})}return e.$$set=e=>{"isLoggedIn"in e&&n(1,r=e.isLoggedIn),"userRole"in e&&n(2,o=e.userRole),"userPubkey"in e&&n(3,i=e.userPubkey),"filteredEvents"in e&&n(4,s=e.filteredEvents),"expandedEvents"in e&&n(5,a=e.expandedEvents),"isLoadingEvents"in e&&n(6,c=e.isLoadingEvents),"showOnlyMyEvents"in e&&n(0,l=e.showOnlyMyEvents)},[l,r,o,i,s,a,c,function(e){u("scroll",e)},d,f,h,p,g,e=>f(e.id),e=>d(e.id),(e,t)=>"Enter"===t.key&&d(e.id),(e,t)=>h(e,t),function(){l=this.checked,n(0,l)},()=>p(),()=>{g(!1,l&&i?[i]:null)},()=>{g(!0,l&&i?[i]:null)}]}class vg extends ee{constructor(e){super(),X(this,e,yg,ug,i,{isLoggedIn:1,userRole:2,userPubkey:3,filteredEvents:4,expandedEvents:5,isLoadingEvents:6,showOnlyMyEvents:0})}}function mg(t){let n,o,i,s,a,c,f,p,y,m,b,E;return{c(){n=h("div"),o=h("div"),i=h("button"),i.textContent="Reformat",s=g(),a=h("button"),a.textContent="Sign",c=g(),f=h("button"),f.textContent="Publish",p=g(),y=h("div"),m=h("textarea"),w(i,"class","compose-btn reformat-btn svelte-mkdcsl"),w(a,"class","compose-btn sign-btn svelte-mkdcsl"),w(f,"class","compose-btn publish-btn svelte-mkdcsl"),w(o,"class","compose-header svelte-mkdcsl"),w(m,"class","compose-textarea svelte-mkdcsl"),w(m,"placeholder","Enter your Nostr event JSON here..."),w(m,"spellcheck","false"),w(y,"class","compose-editor svelte-mkdcsl"),w(n,"class","compose-view svelte-mkdcsl")},m(e,r){u(e,n,r),l(n,o),l(o,i),l(o,s),l(o,a),l(o,c),l(o,f),l(n,p),l(n,y),l(y,m),k(m,t[0]),b||(E=[v(i,"click",t[1]),v(a,"click",t[2]),v(f,"click",t[3]),v(m,"input",t[4])],b=!0)},p(e,[t]){1&t&&k(m,e[0])},i:e,o:e,d(e){e&&d(n),b=!1,r(E)}}}function wg(e,t,n){let{composeEventJson:r=""}=t;const o=T();return e.$$set=e=>{"composeEventJson"in e&&n(0,r=e.composeEventJson)},[r,function(){o("reformatJson")},function(){o("signEvent")},function(){o("publishEvent")},function(){r=this.value,n(0,r)}]}class bg extends ee{constructor(e){super(),X(this,e,wg,mg,i,{composeEventJson:0})}}function Eg(e,t,n){const r=e.slice();return r[23]=t[n],r}function kg(t){let n,r,o,i,s,a;return{c(){n=h("div"),r=h("p"),r.textContent="Please log in to access sprocket management.",o=g(),i=h("button"),i.textContent="Log In",w(r,"class","svelte-fiaj1r"),w(i,"class","login-btn svelte-fiaj1r"),w(n,"class","login-prompt svelte-fiaj1r")},m(e,c){u(e,n,c),l(n,r),l(n,o),l(n,i),s||(a=v(i,"click",t[18]),s=!0)},p:e,d(e){e&&d(n),s=!1,a()}}}function xg(e){let t,n,r,o,i,s,a,c,f,y=(e[2]||"none")+"";return{c(){t=h("div"),n=h("p"),n.textContent="❌ Owner permission required for sprocket management.",r=g(),o=h("p"),o.innerHTML='To enable sprocket functionality, set the ORLY_OWNERS environment variable with your npub when starting the relay.',i=g(),s=h("p"),a=p("Current user role: "),c=h("strong"),f=p(y),w(n,"class","svelte-fiaj1r"),w(o,"class","svelte-fiaj1r"),w(s,"class","svelte-fiaj1r"),w(t,"class","permission-denied svelte-fiaj1r")},m(e,d){u(e,t,d),l(t,n),l(t,r),l(t,o),l(t,i),l(t,s),l(s,a),l(s,c),l(c,f)},p(e,t){4&t&&y!==(y=(e[2]||"none")+"")&&E(f,y)},d(e){e&&d(t)}}}function Sg(e){let t,n,o,i,s,a,c,y,m,b,x,C,A,$,T,I,_,R,O,L,P,B,j,N,U,M,F,D,H,q,z,K,W,V,J,G,Z,Q,Y,X,ee,te,ne,re,oe,ie,se,ae,ce,le,ue,de,fe,he,pe,ge,ye=e[3]?.is_running?"🟢 Running":"🔴 Stopped",ve=e[3]?.script_exists?"✅ Exists":"❌ Not found",me=e[3]?.pid&&Cg(e),we=e[6]&&Ag(e),be=e[8],Ee=[];for(let t=0;t{"isLoggedIn"in e&&n(1,r=e.isLoggedIn),"userRole"in e&&n(2,o=e.userRole),"sprocketStatus"in e&&n(3,i=e.sprocketStatus),"isLoadingSprocket"in e&&n(4,s=e.isLoadingSprocket),"sprocketUploadFile"in e&&n(5,a=e.sprocketUploadFile),"sprocketScript"in e&&n(0,c=e.sprocketScript),"sprocketMessage"in e&&n(6,l=e.sprocketMessage),"sprocketMessageType"in e&&n(7,u=e.sprocketMessageType),"sprocketVersions"in e&&n(8,d=e.sprocketVersions)},[c,r,o,i,s,a,l,u,d,function(){f("restartSprocket")},function(){f("deleteSprocket")},function(e){f("sprocketFileSelect",e)},function(){f("uploadSprocketScript")},function(){f("saveSprocket")},function(){f("loadSprocket")},function(){f("loadVersions")},h,p,function(){f("openLoginModal")},function(){c=this.value,n(0,c)},e=>h(e),e=>p(e.name)]}class Og extends ee{constructor(e){super(),X(this,e,Rg,_g,i,{isLoggedIn:1,userRole:2,sprocketStatus:3,isLoadingSprocket:4,sprocketUploadFile:5,sprocketScript:0,sprocketMessage:6,sprocketMessageType:7,sprocketVersions:8})}}class Lg{constructor(e,t,n){this.relayUrl=e,this.userSigner=t,this.userPubkey=n,this.ws=null,this.challenge=null,this.isAuthenticated=!1,this.authPromise=null}async connect(){return new Promise((e,t)=>{this.ws=new WebSocket(this.relayUrl),this.ws.onopen=()=>{console.log("WebSocket connected to relay:",this.relayUrl),e()},this.ws.onmessage=async e=>{try{const t=JSON.parse(e.data);await this.handleMessage(t)}catch(e){console.error("Error parsing relay message:",e)}},this.ws.onerror=e=>{console.error("WebSocket error:",e),t(new Error("Failed to connect to relay"))},this.ws.onclose=()=>{console.log("WebSocket connection closed"),this.isAuthenticated=!1,this.challenge=null},setTimeout(()=>{this.ws.readyState!==WebSocket.OPEN&&t(new Error("Connection timeout"))},1e4)})}async handleMessage(e){const[t,...n]=e;switch(t){case"AUTH":this.challenge=n[0],console.log("Received AUTH challenge:",this.challenge),await this.authenticate();break;case"OK":const[e,r,o]=n;e&&r?(console.log("Authentication successful for event:",e),this.isAuthenticated=!0,this.authPromise&&(this.authPromise.resolve(),this.authPromise=null)):e&&!r&&(console.error("Authentication failed:",o),this.authPromise&&(this.authPromise.reject(new Error(o||"Authentication failed")),this.authPromise=null));break;case"NOTICE":console.log("Relay notice:",n[0]);break;default:console.log("Unhandled message type:",t,n)}}async authenticate(){if(!this.challenge)throw new Error("No challenge received from relay");if(!this.userSigner)throw new Error("No signer available for authentication");try{const e={kind:22242,created_at:Math.floor(Date.now()/1e3),tags:[["relay",this.relayUrl],["challenge",this.challenge]],content:"",pubkey:this.userPubkey},t=["AUTH",await this.userSigner.signEvent(e)];return this.ws.send(JSON.stringify(t)),console.log("Sent authentication event to relay"),new Promise((e,t)=>{this.authPromise={resolve:e,reject:t},setTimeout(()=>{this.authPromise&&(this.authPromise.reject(new Error("Authentication timeout")),this.authPromise=null)},1e4)})}catch(e){throw console.error("Authentication error:",e),e}}async publishEvent(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("WebSocket not connected");return new Promise((t,n)=>{const r=["EVENT",e];this.ws.send(JSON.stringify(r));const o=this.ws.onmessage,i=setTimeout(()=>{this.ws.onmessage=o,n(new Error("Publish timeout"))},15e3);this.ws.onmessage=async r=>{try{const s=JSON.parse(r.data),[a,c,l,u]=s;if("OK"===a&&c===e.id)if(clearTimeout(i),this.ws.onmessage=o,l)console.log("Event published successfully:",c),t({success:!0,eventId:c,reason:u});else{if(console.error("Event publish failed:",u),u&&u.includes("auth-required")){console.log("Authentication required, attempting to authenticate...");try{await this.authenticate();const t=["EVENT",e];return void this.ws.send(JSON.stringify(t))}catch(e){return void n(new Error(`Authentication failed: ${e.message}`))}}n(new Error(`Publish failed: ${u}`))}else await this.handleMessage(s)}catch(e){clearTimeout(i),this.ws.onmessage=o,n(e)}}})}close(){this.ws&&(this.ws.close(),this.ws=null),this.isAuthenticated=!1,this.challenge=null}getAuthenticated(){return this.isAuthenticated}}async function Pg(e,t,n,r){const o=new Lg(e,n,r);try{await o.connect();return await o.publishEvent(t)}finally{o.close()}}function Bg(e,t,n){const r=e.slice();return r[147]=t[n],r}function jg(e,t,n){const r=e.slice();return r[157]=t[n],r}function Ng(e,t,n){const r=e.slice();return r[150]=t[n],r}function Ug(e,t,n){const r=e.slice();r[150]=t[n];const o=r[44](r[150]);return r[151]=o,r}function Mg(e,t,n){const r=e.slice();return r[154]=t[n],r}function Fg(t){let n;function r(e,t){return e[1]?Zg:Gg}let o=r(t),i=o(t);return{c(){n=h("div"),i.c(),w(n,"class","welcome-message svelte-14c8ed4")},m(e,t){u(e,n,t),i.m(n,null)},p(e,t){o===(o=r(e))&&i?i.p(e,t):(i.d(1),i=o(e),i&&(i.c(),i.m(n,null)))},i:e,o:e,d(e){e&&d(n),i.d()}}}function Dg(t){let n,r=t[6],o=[];for(let e=0;e=0||""!==t[27]&&parseInt(t[27])>=0,L=t[34],P=[];for(let e=0;eEvent Recovery \n

Search and recover old versions of replaceable events

',i=g(),s=h("div"),a=h("div"),c=h("div"),p=h("label"),p.textContent="Select Event Kind:",y=g(),m=h("select"),E=h("option"),E.textContent="Choose a replaceable kind...";for(let e=0;et[97].call(m)),w(c,"class","kind-selector svelte-14c8ed4"),w(A,"for","custom-kind"),w(A,"class","svelte-14c8ed4"),w(T,"id","custom-kind"),w(T,"type","number"),w(T,"placeholder","e.g., 10001"),w(T,"min","0"),w(T,"class","svelte-14c8ed4"),w(C,"class","custom-kind-input svelte-14c8ed4"),w(a,"class","recovery-controls svelte-14c8ed4"),w(s,"class","recovery-controls-card svelte-14c8ed4"),w(n,"class","recovery-tab svelte-14c8ed4")},m(e,r){u(e,n,r),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(c,p),l(c,y),l(c,m),l(m,E);for(let e=0;e=0||""!==e[27]&&parseInt(e[27])>=0),O?B?B.p(e,t):(B=ay(e),B.c(),B.m(n,null)):B&&(B.d(1),B=null)},i:e,o:e,d(e){e&&d(n),f(P,e),B&&B.d(),_=!1,r(R)}}}function qg(e){let t,n,r;function o(t){e[94](t)}let i={isLoggedIn:e[1],userRole:e[4],sprocketStatus:e[19],isLoadingSprocket:e[21],sprocketUploadFile:e[24],sprocketMessage:e[22],sprocketMessageType:e[23],sprocketVersions:e[20]};return void 0!==e[18]&&(i.sprocketScript=e[18]),t=new Og({props:i}),R.push(()=>J(t,"sprocketScript",o)),t.$on("restartSprocket",e[47]),t.$on("deleteSprocket",e[48]),t.$on("sprocketFileSelect",e[52]),t.$on("uploadSprocketScript",e[53]),t.$on("saveSprocket",e[46]),t.$on("loadSprocket",e[45]),t.$on("loadVersions",e[49]),t.$on("loadVersion",e[95]),t.$on("deleteVersion",e[96]),t.$on("openLoginModal",e[56]),{c(){G(t.$$.fragment)},m(e,n){Z(t,e,n),r=!0},p(e,r){const o={};2&r[0]&&(o.isLoggedIn=e[1]),16&r[0]&&(o.userRole=e[4]),524288&r[0]&&(o.sprocketStatus=e[19]),2097152&r[0]&&(o.isLoadingSprocket=e[21]),16777216&r[0]&&(o.sprocketUploadFile=e[24]),4194304&r[0]&&(o.sprocketMessage=e[22]),8388608&r[0]&&(o.sprocketMessageType=e[23]),1048576&r[0]&&(o.sprocketVersions=e[20]),!n&&262144&r[0]&&(n=!0,o.sprocketScript=e[18],N(()=>n=!1)),t.$set(o)},i(e){r||(W(t.$$.fragment,e),r=!0)},o(e){V(t.$$.fragment,e),r=!1},d(e){Q(t,e)}}}function zg(e){let t,n,r,o;const i=[my,vy,yy],s=[];function a(e,t){return"managed"!==e[7]?0:e[1]&&"owner"===e[4]?1:2}return n=a(e),r=s[n]=i[n](e),{c(){t=h("div"),r.c(),w(t,"class","managed-acl-view svelte-14c8ed4")},m(e,r){u(e,t,r),s[n].m(t,null),o=!0},p(e,o){let c=n;n=a(e),n===c?s[n].p(e,o):(z(),V(s[c],1,1,()=>{s[c]=null}),K(),r=s[n],r?r.p(e,o):(r=s[n]=i[n](e),r.c()),W(r,1),r.m(t,null))},i(e){o||(W(r),o=!0)},o(e){V(r),o=!1},d(e){e&&d(t),s[n].d()}}}function Kg(e){let t,n,r;function o(t){e[93](t)}let i={};return void 0!==e[25]&&(i.composeEventJson=e[25]),t=new bg({props:i}),R.push(()=>J(t,"composeEventJson",o)),t.$on("reformatJson",e[74]),t.$on("signEvent",e[75]),t.$on("publishEvent",e[76]),{c(){G(t.$$.fragment)},m(e,n){Z(t,e,n),r=!0},p(e,r){const o={};!n&&33554432&r[0]&&(n=!0,o.composeEventJson=e[25],N(()=>n=!1)),t.$set(o)},i(e){r||(W(t.$$.fragment,e),r=!0)},o(e){V(t.$$.fragment,e),r=!1},d(e){Q(t,e)}}}function Wg(e){let t,n;return t=new vg({props:{isLoggedIn:e[1],userRole:e[4],userPubkey:e[2],filteredEvents:e[32],expandedEvents:e[16],isLoadingEvents:e[17],showOnlyMyEvents:_y}}),t.$on("scroll",e[73]),t.$on("toggleEventExpansion",e[89]),t.$on("deleteEvent",e[90]),t.$on("copyEventToClipboard",e[91]),t.$on("toggleChange",e[37]),t.$on("loadAllEvents",e[92]),{c(){G(t.$$.fragment)},m(e,r){Z(t,e,r),n=!0},p(e,n){const r={};2&n[0]&&(r.isLoggedIn=e[1]),16&n[0]&&(r.userRole=e[4]),4&n[0]&&(r.userPubkey=e[2]),2&n[1]&&(r.filteredEvents=e[32]),65536&n[0]&&(r.expandedEvents=e[16]),131072&n[0]&&(r.isLoadingEvents=e[17]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){V(t.$$.fragment,e),n=!1},d(e){Q(t,e)}}}function Vg(e){let t,n;return t=new Wp({props:{isLoggedIn:e[1],currentEffectiveRole:e[8],selectedFile:e[15]}}),t.$on("fileSelect",e[70]),t.$on("importEvents",e[71]),t.$on("openLoginModal",e[56]),{c(){G(t.$$.fragment)},m(e,r){Z(t,e,r),n=!0},p(e,n){const r={};2&n[0]&&(r.isLoggedIn=e[1]),256&n[0]&&(r.currentEffectiveRole=e[8]),32768&n[0]&&(r.selectedFile=e[15]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){V(t.$$.fragment,e),n=!1},d(e){Q(t,e)}}}function Jg(e){let t,n;return t=new Fp({props:{isLoggedIn:e[1],currentEffectiveRole:e[8]}}),t.$on("exportMyEvents",e[69]),t.$on("exportAllEvents",e[68]),t.$on("openLoginModal",e[56]),{c(){G(t.$$.fragment)},m(e,r){Z(t,e,r),n=!0},p(e,n){const r={};2&n[0]&&(r.isLoggedIn=e[1]),256&n[0]&&(r.currentEffectiveRole=e[8]),t.$set(r)},i(e){n||(W(t.$$.fragment,e),n=!0)},o(e){V(t.$$.fragment,e),n=!1},d(e){Q(t,e)}}}function Gg(t){let n;return{c(){n=h("p"),n.textContent="Log in to access your user dashboard",w(n,"class","svelte-14c8ed4")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Zg(e){let t,n,r,o=(e[3]?.name||e[2].slice(0,8)+"...")+"";return{c(){t=h("p"),n=p("Welcome "),r=p(o),w(t,"class","svelte-14c8ed4")},m(e,o){u(e,t,o),l(t,n),l(t,r)},p(e,t){12&t[0]&&o!==(o=(e[3]?.name||e[2].slice(0,8)+"...")+"")&&E(r,o)},d(e){e&&d(t)}}}function Qg(e){let t,n,o,i,s,a,c,f,y,m,b,k,x,S,C,A,$,T,I,_=e[157].query+"",R=e[33].get(e[157].id)?.isLoading,O=!e[33].get(e[157].id)?.hasMore&&e[33].get(e[157].id)?.events?.length>0;function L(){return e[102](e[157])}function P(e,t){return 64&t[0]&&(x=null),64&t[0]&&(S=null),null==x&&(x=!!(e[33].get(e[157].id)?.events?.length>0)),x?Xg:(null==S&&(S=!e[33].get(e[157].id)?.isLoading),S?Yg:void 0)}let B=P(e,[-1,-1,-1,-1,-1,-1]),j=B&&B(e),N=R&&ry(),U=O&&oy();function M(...t){return e[107](e[157],...t)}return{c(){t=h("div"),n=h("div"),o=h("h2"),i=p('🔍 Search Results: "'),s=p(_),a=p('"'),c=g(),f=h("button"),y=p("🔄 Refresh"),b=g(),k=h("div"),j&&j.c(),C=g(),N&&N.c(),A=g(),U&&U.c(),$=g(),w(o,"class","svelte-14c8ed4"),w(f,"class","refresh-btn svelte-14c8ed4"),f.disabled=m=e[33].get(e[157].id)?.isLoading,w(n,"class","search-results-header svelte-14c8ed4"),w(k,"class","search-results-content svelte-14c8ed4"),w(t,"class","search-results-view svelte-14c8ed4")},m(e,r){u(e,t,r),l(t,n),l(n,o),l(o,i),l(o,s),l(o,a),l(n,c),l(n,f),l(f,y),l(t,b),l(t,k),j&&j.m(k,null),l(k,C),N&&N.m(k,null),l(k,A),U&&U.m(k,null),l(t,$),T||(I=[v(f,"click",L),v(k,"scroll",M)],T=!0)},p(t,n){e=t,64&n[0]&&_!==(_=e[157].query+"")&&E(s,_),64&n[0]&&m!==(m=e[33].get(e[157].id)?.isLoading)&&(f.disabled=m),B===(B=P(e,n))&&j?j.p(e,n):(j&&j.d(1),j=B&&B(e),j&&(j.c(),j.m(k,C))),64&n[0]&&(R=e[33].get(e[157].id)?.isLoading),R?N||(N=ry(),N.c(),N.m(k,A)):N&&(N.d(1),N=null),64&n[0]&&(O=!e[33].get(e[157].id)?.hasMore&&e[33].get(e[157].id)?.events?.length>0),O?U||(U=oy(),U.c(),U.m(k,null)):U&&(U.d(1),U=null)},d(e){e&&d(t),j&&j.d(),N&&N.d(),U&&U.d(),T=!1,r(I)}}}function Yg(e){let t,n,r,o,i,s=e[157].query+"";return{c(){t=h("div"),n=h("p"),r=p('No search results found for "'),o=p(s),i=p('".'),w(n,"class","svelte-14c8ed4"),w(t,"class","no-search-results svelte-14c8ed4")},m(e,s){u(e,t,s),l(t,n),l(n,r),l(n,o),l(n,i)},p(e,t){64&t[0]&&s!==(s=e[157].query+"")&&E(o,s)},d(e){e&&d(t)}}}function Xg(e){let t,n=e[33].get(e[157].id).events,r=[];for(let t=0;t👤',i=g(),s=h("div"),a=h("div"),c=p(U),f=g(),y=h("div"),m=h("span"),b=p(M),k=g(),x=h("span"),C=p(F),A=g(),$=h("div"),T=h("div"),I=p(D),_=g(),R=h("div"),O=p(H),L=g(),z&&z.c(),P=g(),V&&V.c(),B=g(),w(o,"class","search-result-avatar svelte-14c8ed4"),w(a,"class","search-result-author svelte-14c8ed4"),w(m,"class","kind-number svelte-14c8ed4"),w(x,"class","kind-name svelte-14c8ed4"),w(y,"class","search-result-kind svelte-14c8ed4"),w(s,"class","search-result-info svelte-14c8ed4"),w(T,"class","event-timestamp svelte-14c8ed4"),w(R,"class","event-content-single-line svelte-14c8ed4"),w($,"class","search-result-content svelte-14c8ed4"),w(n,"class","search-result-row svelte-14c8ed4"),w(n,"role","button"),w(n,"tabindex","0"),w(t,"class","search-result-item svelte-14c8ed4"),S(t,"expanded",e[16].has(e[150].id))},m(e,r){u(e,t,r),l(t,n),l(n,o),l(n,i),l(n,s),l(s,a),l(a,c),l(s,f),l(s,y),l(y,m),l(m,b),l(y,k),l(y,x),l(x,C),l(n,A),l(n,$),l($,T),l(T,I),l($,_),l($,R),l(R,O),l(n,L),z&&z.m(n,null),l(t,P),V&&V.m(t,null),l(t,B),j||(N=[v(n,"click",K),v(n,"keydown",W)],j=!0)},p(r,o){e=r,64&o[0]&&U!==(U=Ry(e[150].pubkey)+"")&&E(c,U),64&o[0]&&M!==(M=e[150].kind+"")&&E(b,M),64&o[0]&&F!==(F=e[35](e[150].kind)+"")&&E(C,F),64&o[0]&&D!==(D=Ly(e[150].created_at)+"")&&E(I,D),64&o[0]&&H!==(H=Oy(e[150].content)+"")&&E(O,H),5!==e[150].kind&&("admin"===e[4]||"owner"===e[4]||"write"===e[4]&&e[150].pubkey&&e[150].pubkey===e[2])?z?z.p(e,o):(z=ey(e),z.c(),z.m(n,null)):z&&(z.d(1),z=null),65600&o[0]&&(q=e[16].has(e[150].id)),q?V?V.p(e,o):(V=ty(e),V.c(),V.m(t,B)):V&&(V.d(1),V=null),65600&o[0]|4&o[1]&&S(t,"expanded",e[16].has(e[150].id))},d(e){e&&d(t),z&&z.d(),V&&V.d(),j=!1,r(N)}}}function ry(e){let t;return{c(){t=h("div"),t.innerHTML='
\n

Searching...

',w(t,"class","loading-search-results svelte-14c8ed4")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function oy(e){let t;return{c(){t=h("div"),t.innerHTML='

No more search results to load.

',w(t,"class","end-of-search-results svelte-14c8ed4")},m(e,n){u(e,t,n)},d(e){e&&d(t)}}}function iy(e){let t,n=e[157].id===e[5]&&Qg(e);return{c(){n&&n.c(),t=y()},m(e,r){n&&n.m(e,r),u(e,t,r)},p(e,r){e[157].id===e[5]?n?n.p(e,r):(n=Qg(e),n.c(),n.m(t.parentNode,t)):n&&(n.d(1),n=null)},d(e){n&&n.d(e),e&&d(t)}}}function sy(t){let n,r,o=t[154].label+"";return{c(){n=h("option"),r=p(o),n.__value=t[154].value,n.value=n.__value},m(e,t){u(e,n,t),l(n,r)},p:e,d(e){e&&d(n)}}}function ay(e){let t;function n(e,t){return e[29]?uy:0===e[28].length?ly:cy}let r=n(e),o=r(e);return{c(){t=h("div"),o.c(),w(t,"class","recovery-results svelte-14c8ed4")},m(e,n){u(e,t,n),o.m(t,null)},p(e,i){r===(r=n(e))&&o?o.p(e,i):(o.d(1),o=r(e),o&&(o.c(),o.m(t,null)))},d(e){e&&d(t),o.d()}}}function cy(e){let t,n,r,o=e[28],i=[];for(let t=0;tORLY_ACL_MODE=managed in your\n environment variables and restart the relay.',w(r,"class","svelte-14c8ed4"),w(i,"class","svelte-14c8ed4"),w(a,"class","svelte-14c8ed4"),w(m,"class","svelte-14c8ed4"),w(n,"class","acl-mode-warning svelte-14c8ed4")},m(e,t){u(e,n,t),l(n,r),l(n,o),l(n,i),l(n,s),l(n,a),l(a,c),l(a,f),l(f,y),l(n,v),l(n,m)},p(e,t){128&t[0]&&b!==(b=(e[7]||"unknown")+"")&&E(y,b)},i:e,o:e,d(e){e&&d(n)}}}function wy(e){let t,n,o,i,s,a,c,f,p,y;function b(e,t){return e[3]?Ey:e[1]&&e[2]?by:void 0}let E=b(e),k=E&&E(e);return{c(){t=h("div"),n=h("div"),o=h("div"),i=h("h2"),i.textContent="Settings",s=g(),a=h("button"),a.textContent="✕",c=g(),f=h("div"),k&&k.c(),w(i,"class","svelte-14c8ed4"),w(a,"class","close-btn svelte-14c8ed4"),w(o,"class","drawer-header svelte-14c8ed4"),w(f,"class","drawer-content"),w(n,"class","settings-drawer svelte-14c8ed4"),S(n,"dark-theme",e[0]),w(t,"class","drawer-overlay svelte-14c8ed4"),w(t,"role","button"),w(t,"tabindex","0")},m(r,d){u(r,t,d),l(t,n),l(n,o),l(o,i),l(o,s),l(o,a),l(n,c),l(n,f),k&&k.m(f,null),p||(y=[v(a,"click",e[61]),v(n,"click",m(e[83])),v(n,"keydown",m(e[84])),v(t,"click",e[61]),v(t,"keydown",e[109])],p=!0)},p(e,t){E===(E=b(e))&&k?k.p(e,t):(k&&k.d(1),k=E&&E(e),k&&(k.c(),k.m(f,null))),1&t[0]&&S(n,"dark-theme",e[0])},d(e){e&&d(t),k&&k.d(),p=!1,r(y)}}}function by(e){let t,n,r,o,i,s,a,c,f,y,m,b,k,x,S,C=e[2].slice(0,16)+"",A=e[2].slice(-8)+"";return{c(){t=h("div"),n=h("h3"),n.textContent="Profile Loading",r=g(),o=h("p"),o.textContent="Your profile metadata is being loaded...",i=g(),s=h("button"),s.textContent="Retry Loading Profile",a=g(),c=h("div"),f=h("strong"),f.textContent="Public Key:",y=g(),m=p(C),b=p("..."),k=p(A),w(n,"class","svelte-14c8ed4"),w(o,"class","svelte-14c8ed4"),w(s,"class","retry-profile-btn svelte-14c8ed4"),w(c,"class","user-pubkey-display svelte-14c8ed4"),w(t,"class","profile-loading-section svelte-14c8ed4")},m(d,h){u(d,t,h),l(t,n),l(t,r),l(t,o),l(t,i),l(t,s),l(t,a),l(t,c),l(c,f),l(c,y),l(c,m),l(c,b),l(c,k),x||(S=v(s,"click",e[67]),x=!0)},p(e,t){4&t[0]&&C!==(C=e[2].slice(0,16)+"")&&E(m,C),4&t[0]&&A!==(A=e[2].slice(-8)+"")&&E(k,A)},d(e){e&&d(t),x=!1,S()}}}function Ey(e){let t,n,r,o,i,s,a,c,f,m,b,k,x,S,C,A=(e[3].name||"Unknown User")+"",$=e[3].banner&&ky(e);function T(e,t){return e[3].picture?Sy:xy}let I=T(e),_=I(e),R=e[3].nip05&&Cy(e),O=e[3].about&&Ay(e),L=e[4]&&"read"!==e[4]&&$y(e);return{c(){t=h("div"),n=h("div"),$&&$.c(),r=g(),o=h("button"),o.textContent="Log out",i=g(),_.c(),s=g(),a=h("div"),c=h("h3"),f=p(A),m=g(),R&&R.c(),b=g(),O&&O.c(),k=g(),L&&L.c(),x=y(),w(o,"class","logout-btn floating svelte-14c8ed4"),w(c,"class","profile-username svelte-14c8ed4"),w(a,"class","name-row svelte-14c8ed4"),w(n,"class","profile-hero svelte-14c8ed4"),w(t,"class","profile-section svelte-14c8ed4")},m(d,h){u(d,t,h),l(t,n),$&&$.m(n,null),l(n,r),l(n,o),l(n,i),_.m(n,null),l(n,s),l(n,a),l(a,c),l(c,f),l(a,m),R&&R.m(a,null),l(t,b),O&&O.m(t,null),u(d,k,h),L&&L.m(d,h),u(d,x,h),S||(C=v(o,"click",e[58]),S=!0)},p(e,o){e[3].banner?$?$.p(e,o):($=ky(e),$.c(),$.m(n,r)):$&&($.d(1),$=null),I===(I=T(e))&&_?_.p(e,o):(_.d(1),_=I(e),_&&(_.c(),_.m(n,s))),8&o[0]&&A!==(A=(e[3].name||"Unknown User")+"")&&E(f,A),e[3].nip05?R?R.p(e,o):(R=Cy(e),R.c(),R.m(a,null)):R&&(R.d(1),R=null),e[3].about?O?O.p(e,o):(O=Ay(e),O.c(),O.m(t,null)):O&&(O.d(1),O=null),e[4]&&"read"!==e[4]?L?L.p(e,o):(L=$y(e),L.c(),L.m(x.parentNode,x)):L&&(L.d(1),L=null)},d(e){e&&d(t),$&&$.d(),_.d(),R&&R.d(),O&&O.d(),e&&d(k),L&&L.d(e),e&&d(x),S=!1,C()}}}function ky(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[3].banner)||w(t,"src",n),w(t,"alt","Profile banner"),w(t,"class","profile-banner svelte-14c8ed4")},m(e,n){u(e,t,n)},p(e,r){8&r[0]&&!a(t.src,n=e[3].banner)&&w(t,"src",n)},d(e){e&&d(t)}}}function xy(t){let n;return{c(){n=h("div"),n.textContent="👤",w(n,"class","profile-avatar-placeholder overlap svelte-14c8ed4")},m(e,t){u(e,n,t)},p:e,d(e){e&&d(n)}}}function Sy(e){let t,n;return{c(){t=h("img"),a(t.src,n=e[3].picture)||w(t,"src",n),w(t,"alt","User avatar"),w(t,"class","profile-avatar overlap svelte-14c8ed4")},m(e,n){u(e,t,n)},p(e,r){8&r[0]&&!a(t.src,n=e[3].picture)&&w(t,"src",n)},d(e){e&&d(t)}}}function Cy(e){let t,n,r=e[3].nip05+"";return{c(){t=h("span"),n=p(r),w(t,"class","profile-nip05-inline svelte-14c8ed4")},m(e,r){u(e,t,r),l(t,n)},p(e,t){8&t[0]&&r!==(r=e[3].nip05+"")&&E(n,r)},d(e){e&&d(t)}}}function Ay(e){let t,n;return{c(){t=h("div"),n=h("p"),w(n,"class","profile-about svelte-14c8ed4"),w(t,"class","about-card svelte-14c8ed4")},m(r,o){u(r,t,o),l(t,n),n.innerHTML=e[31]},p(e,t){1&t[1]&&(n.innerHTML=e[31])},d(e){e&&d(t)}}}function $y(e){let t,n,r,o,i,s,a=e[78](),c=[];for(let t=0;tJ(t,"searchQuery",k)),t.$on("searchKeydown",e[63]),t.$on("toggleSearchMode",e[62]),t.$on("toggleTheme",e[55]),t.$on("openSettingsDrawer",e[60]),t.$on("openLoginModal",e[56]),i=new Pp({props:{isDarkTheme:e[0],tabs:e[9],selectedTab:e[5]}}),i.$on("selectTab",e[87]),i.$on("closeSearchTab",e[88]);const C=[Jg,Vg,Wg,Kg,zg,qg,Hg,Dg,Fg],A=[];function $(e,t){return 96&t[0]&&(c=null),"export"===e[5]?0:"import"===e[5]?1:"events"===e[5]?2:"compose"===e[5]?3:"managed-acl"===e[5]?4:"sprocket"===e[5]?5:"recovery"===e[5]?6:(null==c&&(c=!!e[6].some(e[85])),c?7:8)}f=$(e,[-1,-1,-1,-1,-1,-1]),p=A[f]=C[f](e);let T=e[12]&&wy(e);function I(t){e[110](t)}let _={isDarkTheme:e[0]};return void 0!==e[10]&&(_.showModal=e[10]),m=new $h({props:_}),R.push(()=>J(m,"showModal",I)),m.$on("login",e[57]),m.$on("close",e[59]),{c(){G(t.$$.fragment),r=g(),o=h("div"),G(i.$$.fragment),s=g(),a=h("main"),p.c(),y=g(),T&&T.c(),v=g(),G(m.$$.fragment),w(a,"class","main-content svelte-14c8ed4"),w(o,"class","app-container svelte-14c8ed4"),S(o,"dark-theme",e[0])},m(e,n){Z(t,e,n),u(e,r,n),u(e,o,n),Z(i,o,null),l(o,s),l(o,a),A[f].m(a,null),u(e,y,n),T&&T.m(e,n),u(e,v,n),Z(m,e,n),E=!0},p(e,r){const s={};1&r[0]&&(s.isDarkTheme=e[0]),8192&r[0]&&(s.isSearchMode=e[13]),2&r[0]&&(s.isLoggedIn=e[1]),16&r[0]&&(s.userRole=e[4]),256&r[0]&&(s.currentEffectiveRole=e[8]),8&r[0]&&(s.userProfile=e[3]),4&r[0]&&(s.userPubkey=e[2]),!n&&16384&r[0]&&(n=!0,s.searchQuery=e[14],N(()=>n=!1)),t.$set(s);const c={};1&r[0]&&(c.isDarkTheme=e[0]),512&r[0]&&(c.tabs=e[9]),32&r[0]&&(c.selectedTab=e[5]),i.$set(c);let l=f;f=$(e,r),f===l?A[f].p(e,r):(z(),V(A[l],1,1,()=>{A[l]=null}),K(),p=A[f],p?p.p(e,r):(p=A[f]=C[f](e),p.c()),W(p,1),p.m(a,null)),(!E||1&r[0])&&S(o,"dark-theme",e[0]),e[12]?T?T.p(e,r):(T=wy(e),T.c(),T.m(v.parentNode,v)):T&&(T.d(1),T=null);const u={};1&r[0]&&(u.isDarkTheme=e[0]),!b&&1024&r[0]&&(b=!0,u.showModal=e[10],N(()=>b=!1)),m.$set(u)},i(e){E||(W(t.$$.fragment,e),W(i.$$.fragment,e),W(p),W(m.$$.fragment,e),E=!0)},o(e){V(t.$$.fragment,e),V(i.$$.fragment,e),V(p),V(m.$$.fragment,e),E=!1},d(e){Q(t,e),e&&d(r),e&&d(o),Q(i),A[f].d(),e&&d(y),T&&T.d(e),e&&d(v),Q(m,e)}}}let _y=!1;function Ry(e){return e?e.slice(0,8)+"..."+e.slice(-8):"unknown"}function Oy(e,t=100){return e?e.length>t?e.slice(0,t)+"...":e:""}function Ly(e){return e?new Date(1e3*e).toLocaleString():""}async function Py(e,t){try{const n=JSON.stringify(e);await navigator.clipboard.writeText(n);const r=t.target.closest(".copy-json-btn");if(r){const e=r.textContent;r.textContent="✅",r.style.backgroundColor="#4CAF50",setTimeout(()=>{r.textContent=e,r.style.backgroundColor=""},2e3)}}catch(n){console.error("Failed to copy to clipboard:",n);try{const n=document.createElement("textarea");n.value=JSON.stringify(e),document.body.appendChild(n),n.select(),document.execCommand("copy"),document.body.removeChild(n);const r=t.target.closest(".copy-json-btn");if(r){const e=r.textContent;r.textContent="✅",r.style.backgroundColor="#4CAF50",setTimeout(()=>{r.textContent=e,r.style.backgroundColor=""},2e3)}}catch(e){console.error("Fallback copy also failed:",e),alert("Failed to copy to clipboard. Please copy manually.")}}}function By(e,t,n){let r,o,i,s,a;"undefined"!=typeof window&&(window.debugIndexedDB=mh);let c=!1,l=!1,u=!1,d="",f="",h=null,p="",g=null,y=!1,v=localStorage.getItem("selectedTab")||"export",m=!1,w="",E=[],k=[],x=null,S=new Set,C=!1,A=!0,$=null,T="",_=new Map,R=[],O=0;const L=3e5;let P=[],B=!0,j=null,N="",U=null,M=[],F=!1,D="",H="info",q=!1,z=null,K="",W="",V=null,J="",G=[],Z=!1,Q=!0,Y=null;const X=[{value:0,label:"User Metadata (0)"},{value:3,label:"Follows (3)"},{value:1e4,label:"Mute list (10000)"},{value:10001,label:"Pin list (10001)"},{value:10002,label:"Relay List Metadata (10002)"},{value:10003,label:"Bookmark list (10003)"},{value:10004,label:"Communities list (10004)"},{value:10005,label:"Public chats list (10005)"},{value:10006,label:"Blocked relays list (10006)"},{value:10007,label:"Search relays list (10007)"},{value:10009,label:"User groups (10009)"},{value:10012,label:"Favorite relays list (10012)"},{value:10013,label:"Private event relay list (10013)"},{value:10015,label:"Interests list (10015)"},{value:10019,label:"Nutzap Mint Recommendation (10019)"},{value:10020,label:"Media follows (10020)"},{value:10030,label:"User emoji list (10030)"},{value:10050,label:"Relay list to receive DMs (10050)"},{value:10051,label:"KeyPackage Relays List (10051)"},{value:10063,label:"User server list (10063)"},{value:10096,label:"File storage server list (10096)"},{value:10166,label:"Relay Monitor Announcement (10166)"},{value:10312,label:"Room Presence (10312)"},{value:10377,label:"Proxy Announcement (10377)"},{value:11111,label:"Transport Method Announcement (11111)"},{value:13194,label:"Wallet Info (13194)"},{value:17375,label:"Cashu Wallet Event (17375)"},{value:3e4,label:"Follow sets (30000)"},{value:30001,label:"Generic lists (30001)"},{value:30002,label:"Relay sets (30002)"},{value:30003,label:"Bookmark sets (30003)"},{value:30004,label:"Curation sets (30004)"},{value:30005,label:"Video sets (30005)"},{value:30007,label:"Kind mute sets (30007)"},{value:30008,label:"Profile Badges (30008)"},{value:30009,label:"Badge Definition (30009)"},{value:30015,label:"Interest sets (30015)"},{value:30017,label:"Create or update a stall (30017)"},{value:30018,label:"Create or update a product (30018)"},{value:30019,label:"Marketplace UI/UX (30019)"},{value:30020,label:"Product sold as an auction (30020)"},{value:30023,label:"Long-form Content (30023)"},{value:30024,label:"Draft Long-form Content (30024)"},{value:30030,label:"Emoji sets (30030)"},{value:30040,label:"Curated Publication Index (30040)"},{value:30041,label:"Curated Publication Content (30041)"},{value:30063,label:"Release artifact sets (30063)"},{value:30078,label:"Application-specific Data (30078)"},{value:30166,label:"Relay Discovery (30166)"},{value:30267,label:"App curation sets (30267)"},{value:30311,label:"Live Event (30311)"},{value:30312,label:"Interactive Room (30312)"},{value:30313,label:"Conference Event (30313)"},{value:30315,label:"User Statuses (30315)"},{value:30388,label:"Slide Set (30388)"},{value:30402,label:"Classified Listing (30402)"},{value:30403,label:"Draft Classified Listing (30403)"},{value:30617,label:"Repository announcements (30617)"},{value:30618,label:"Repository state announcements (30618)"},{value:30818,label:"Wiki article (30818)"},{value:30819,label:"Redirects (30819)"},{value:31234,label:"Draft Event (31234)"},{value:31388,label:"Link Set (31388)"},{value:31890,label:"Feed (31890)"},{value:31922,label:"Date-Based Calendar Event (31922)"},{value:31923,label:"Time-Based Calendar Event (31923)"},{value:31924,label:"Calendar (31924)"},{value:31925,label:"Calendar Event RSVP (31925)"},{value:31989,label:"Handler recommendation (31989)"},{value:31990,label:"Handler information (31990)"},{value:32267,label:"Software Application (32267)"},{value:34550,label:"Community Definition (34550)"},{value:37516,label:"Geocache listing (37516)"},{value:38172,label:"Cashu Mint Announcement (38172)"},{value:38173,label:"Fedimint Announcement (38173)"},{value:38383,label:"Peer-to-peer Order events (38383)"},{value:39089,label:"Starter packs (39089)"},{value:39092,label:"Media starter packs (39092)"},{value:39701,label:"Web bookmarks (39701)"}],ee={0:"User Metadata",1:"Short Text Note",2:"Recommend Relay",3:"Follows",4:"Encrypted Direct Messages",5:"Event Deletion Request",6:"Repost",7:"Reaction",8:"Badge Award",9:"Chat Message",10:"Group Chat Threaded Reply",11:"Thread",12:"Group Thread Reply",13:"Seal",14:"Direct Message",15:"File Message",16:"Generic Repost",17:"Reaction to a website",20:"Picture",40:"Channel Creation",41:"Channel Metadata",42:"Channel Message",43:"Channel Hide Message",44:"Channel Mute User",1021:"Bid",1022:"Bid Confirmation",1040:"OpenTimestamps",1063:"File Metadata",1311:"Live Chat Message",1971:"Problem Tracker",1984:"Reporting",1985:"Label",4550:"Community Post Approval",5e3:"Job Request",5999:"Job Request",6e3:"Job Result",6999:"Job Result",7e3:"Job Feedback",9041:"Zap Goal",9734:"Zap Request",9735:"Zap",9882:"Highlights",1e4:"Mute list",10001:"Pin list",10002:"Relay List Metadata",10003:"Bookmarks list",10004:"Communities list",10005:"Public Chats list",10006:"Blocked Relays list",10007:"Search Relays list",10015:"Interests",10030:"User Emoji list",10050:"DM relays",10096:"File Storage Server List",13194:"Wallet Service Info",21e3:"Lightning pub RPC",22242:"Client Authentication",23194:"Wallet Request",23195:"Wallet Response",23196:"Wallet Notification",23197:"Wallet Notification",24133:"Nostr Connect",27235:"HTTP Auth",3e4:"Follow sets",30001:"Generic lists",30002:"Relay sets",30003:"Bookmark sets",30004:"Curation sets",30008:"Profile Badges",30009:"Badge Definition",30015:"Interest sets",30017:"Stall Definition",30018:"Product Definition",30019:"Marketplace UI/UX",30020:"Product sold as an auction",30023:"Long-form Content",30024:"Draft Long-form Content",30030:"Emoji sets",30078:"Application-specific Data",30311:"Live Event",30315:"User Statuses",30402:"Classified Listing",30403:"Draft Classified Listing",31922:"Date-Based Calendar Event",31923:"Time-Based Calendar Event",31924:"Calendar",31925:"Calendar Event RSVP",31989:"Handler recommendation",31990:"Handler information",34235:"Video Event Horizontal",34236:"Video Event Vertical",34550:"Community Definition"};function te(e){S.has(e)?S.delete(e):S.add(e),n(16,S)}async function ne(e){if(!u)return void alert("Please log in first");const t=k.find(t=>t.id===e);if(!t)return void alert("Event not found");if("admin"===p||"owner"===p||"write"===p&&t.pubkey&&t.pubkey===d){if(confirm("Are you sure you want to delete this event?"))try{if(!g)throw new Error("Signer not available for signing");const r={kind:5,created_at:Math.floor(Date.now()/1e3),tags:[["e",e]],content:""};console.log("Created delete event template:",r),console.log("User pubkey:",d),console.log("Target event:",t),console.log("Target event pubkey:",t.pubkey);const o=await g.signEvent(r);console.log("Signed delete event:",o),console.log("Signed delete event pubkey:",o.pubkey),console.log("Delete event tags:",o.tags);const i=`wss://${window.location.host}`;try{const e=await Pg(i,o,g,d);e.success?console.log("Delete event published successfully to ORLY relay"):console.error("Failed to publish delete event:",e.reason)}catch(e){console.error("Error publishing delete event:",e)}const s=t.pubkey&&t.pubkey===d;if(s){const t=await oh.publish(o);if(console.log("Delete event published:",t),!(t.success&&t.okCount>0))throw new Error("No relays accepted the delete event");{await new Promise(e=>setTimeout(e,2e3));try{const n=await gh(e,{timeout:5e3});n?(console.warn("Event still exists after deletion attempt:",n),alert(`Warning: Delete event was accepted by ${t.okCount} relay(s), but the event still exists on the relay. This may indicate the relay does not properly handle delete events.`)):console.log("Event successfully deleted and verified")}catch(e){console.log("Could not fetch event after deletion (likely deleted):",e.message)}try{const t=await yh(e,{timeout:5e3});if(t.length>0){console.log(`Delete event verification: Found ${t.length} delete event(s) targeting ${e}`);const n=t.find(e=>e.pubkey&&e.pubkey===d);n?console.log("Our delete event found in database:",n.id):console.warn("Our delete event not found in database, but other delete events exist")}else console.warn("No delete events found in database for target event:",e)}catch(e){console.log("Could not verify delete event in database:",e.message)}n(79,k=k.filter(t=>t.id!==e)),P=P.filter(t=>t.id!==e),R=R.filter(t=>t.id!==e);for(const[t,n]of _)n.events&&(n.events=n.events.filter(t=>t.id!==e),_.set(t,n));se(),console.log("Reloading events to show delete event...");const r=_y&&u&&d?[d]:null;await xe(!0,r),alert(`Event deleted successfully (accepted by ${t.okCount} relay(s))`)}}else{const t=`wss://${window.location.host}/`,r=new rh;await r.connectToRelay(t);const i=await r.publish(o);if(console.log("Delete event published to local relay only:",i),!(i.success&&i.okCount>0))throw new Error("Local relay did not accept the delete event");{await new Promise(e=>setTimeout(e,2e3));try{const t=await gh(e,{timeout:5e3});t?(console.warn("Event still exists after deletion attempt:",t),alert(`Warning: Delete event was accepted by ${i.okCount} relay(s), but the event still exists on the relay. This may indicate the relay does not properly handle delete events.`)):console.log("Event successfully deleted and verified")}catch(e){console.log("Could not fetch event after deletion (likely deleted):",e.message)}try{const t=await yh(e,{timeout:5e3});if(t.length>0){console.log(`Delete event verification: Found ${t.length} delete event(s) targeting ${e}`);const n=t.find(e=>e.pubkey&&e.pubkey===d);n?console.log("Our delete event found in database:",n.id):console.warn("Our delete event not found in database, but other delete events exist")}else console.warn("No delete events found in database for target event:",e)}catch(e){console.log("Could not verify delete event in database:",e.message)}n(79,k=k.filter(t=>t.id!==e)),P=P.filter(t=>t.id!==e),R=R.filter(t=>t.id!==e);for(const[t,n]of _)n.events&&(n.events=n.events.filter(t=>t.id!==e),_.set(t,n));se(),console.log("Reloading events to show delete event...");const t=_y&&u&&d?[d]:null;await xe(!0,t),alert("Event deleted successfully (local relay only - admin/owner deleting other user's event)")}}}catch(e){console.error("Failed to delete event:",e),alert("Failed to delete event: "+e.message)}}else alert("You do not have permission to delete this event")}async function re(){const e=J?parseInt(J):V;if(null==e||isNaN(e))console.log("No valid kind to load, kindToUse:",e);else if(u){console.log("Loading recovery events for kind:",e,"user:",d),n(29,Z=!0);try{const t=[{kinds:[e],authors:[d],limit:100}];Y&&(t[0].until=Y),console.log("Recovery filters:",t);const r=await async function(e,t={}){const{timeout:n=3e4,cacheFirst:r=!0,cacheOnly:o=!1}=t;let i=[];if(r||o)try{if(i=await dh(e),console.log(`Found ${i.length} events in cache`),o||i.length>0)return i}catch(e){console.warn("Failed to query cache",e)}if(!o){const t=await ph(e,{timeout:n,useCache:!1});return console.log(`Fetched ${t.length} events from relay`),t}return i}(t,{timeout:3e4,cacheFirst:!0});console.log("Recovery events received:",r.length),console.log("Recovery events kinds:",r.map(e=>e.kind)),n(28,G=Y?[...G,...r]:r),r.length>0?(Y=Math.min(...r.map(e=>e.created_at)),n(30,Q=100===r.length)):n(30,Q=!1)}catch(e){console.error("Failed to load recovery events:",e)}finally{n(29,Z=!1)}}else console.log("Not logged in, cannot load recovery events")}async function oe(e){if(confirm("Are you sure you want to repost this event?"))try{const t=`wss://${window.location.host}/`;console.log("Reposting event to local relay:",t,e);const r={...e};if(r.created_at=Math.floor(Date.now()/1e3),r.id="",r.sig="",e.kind>=3e4&&e.kind<=39999){const t=e.tags.find(e=>"d"===e[0]);t&&(r.tags=r.tags.filter(e=>"d"!==e[0]),r.tags.push(t))}if(g){const e=await g.signEvent(r);console.log("Signed event for repost:",e);const o=await oh.publish(e,[t]);console.log("Repost publish result:",o),o.success&&o.okCount>0?(alert("Event reposted successfully!"),n(30,Q=!1),await re()):alert("Failed to repost event. Check console for details.")}else alert("No signer available. Please log in.")}catch(e){console.error("Error reposting event:",e),alert("Error reposting event: "+e.message)}}async function ie(e){if(confirm("Are you sure you want to repost this event to all your write relays?"))try{const t=await async function(){if(!d)return[];try{const e=await dh([{kinds:[10002],authors:[d],limit:1}]);if(0===e.length)return console.log("No relay list event found for user"),[];const t=e[0];console.log("Found relay list event:",t);const n=[];for(const e of t.tags)if("r"===e[0]&&e.length>=2){const t=e[1],r=e.length>=3?e[2]:null;r&&"write"!==r||n.push(t)}return console.log("Found write relays:",n),n}catch(e){return console.error("Error fetching user write relays:",e),[]}}(),r=`wss://${window.location.host}/`,o=[r,...t.filter(e=>e!==r)];1===o.length&&alert("No write relays found in your relay list. Only posting to local relay."),console.log("Reposting event to all relays:",o,e);const i={...e};if(i.created_at=Math.floor(Date.now()/1e3),i.id="",i.sig="",e.kind>=3e4&&e.kind<=39999){const t=e.tags.find(e=>"d"===e[0]);t&&(i.tags=i.tags.filter(e=>"d"!==e[0]),i.tags.push(t))}if(g){const e=await g.signEvent(i);console.log("Signed event for repost to all:",e);const t=await oh.publish(e,o);console.log("Repost to all publish result:",t),t.success&&t.okCount>0?(alert(`Event reposted successfully to ${o.length} relays!`),n(30,Q=!1),await re()):alert("Failed to repost event. Check console for details.")}else alert("No signer available. Please log in.")}catch(e){console.error("Error reposting event to all:",e),alert("Error reposting event to all: "+e.message)}}if("undefined"!=typeof localStorage){const e=localStorage.getItem("isDarkTheme");null!==e&&(c=JSON.parse(e));const t=localStorage.getItem("nostr_auth_method"),r=localStorage.getItem("nostr_pubkey");t&&r&&(u=!0,d=r,f=t,"extension"===t&&window.nostr&&(g=window.nostr),be(),Ee()),function(){if("undefined"==typeof localStorage)return;try{const t=localStorage.getItem("app_state");if(t){const r=JSON.parse(t);r.selectedTab&&he.some(e=>e.id===r.selectedTab)&&n(5,v=r.selectedTab),r.expandedEvents&&n(16,S=new Set(r.expandedEvents)),r.globalEventsCache&&(R=r.globalEventsCache),r.globalCacheTimestamp&&(O=r.globalCacheTimestamp),void 0!==r.hasMoreEvents&&(A=r.hasMoreEvents),r.oldestEventTimestamp&&($=r.oldestEventTimestamp),void 0!==r.hasMoreMyEvents&&(B=r.hasMoreMyEvents),r.oldestMyEventTimestamp&&(j=r.oldestMyEventTimestamp),R.length>0&&((e=O)&&Date.now()-et.created_at-e.created_at),O=Date.now(),se()}async function ce(){if(u&&"owner"===p&&q)try{n(21,F=!0);const e=await fetch("/api/sprocket/status",{method:"GET",headers:{Authorization:`Nostr ${await Ae("GET","/api/sprocket/status")}`,"Content-Type":"application/json"}});e.ok?n(19,U=await e.json()):fe("Failed to load sprocket status","error")}catch(e){fe(`Error loading sprocket status: ${e.message}`,"error")}finally{n(21,F=!1)}}async function le(){if(u&&"owner"===p)try{n(21,F=!0);const e=await fetch("/api/sprocket/versions",{method:"GET",headers:{Authorization:`Nostr ${await Ae("GET","/api/sprocket/versions")}`,"Content-Type":"application/json"}});e.ok?n(20,M=await e.json()):fe("Failed to load versions","error")}catch(e){fe(`Error loading versions: ${e.message}`,"error")}finally{n(21,F=!1)}}async function ue(e){u&&"owner"===p&&(n(18,N=e.content),fe(`Loaded version: ${e.name}`,"success"))}async function de(e){if(u&&"owner"===p&&confirm(`Are you sure you want to delete version ${e}?`))try{n(21,F=!0);const t=await fetch("/api/sprocket/delete-version",{method:"POST",headers:{Authorization:`Nostr ${await Ae("POST","/api/sprocket/delete-version")}`,"Content-Type":"application/json"},body:JSON.stringify({filename:e})});if(t.ok)fe(`Version ${e} deleted successfully`,"success"),await le();else{fe(`Failed to delete version: ${await t.text()}`,"error")}}catch(e){fe(`Error deleting version: ${e.message}`,"error")}finally{n(21,F=!1)}}function fe(e,t="info"){n(22,D=e),n(23,H=t),setTimeout(()=>{n(22,D="")},5e3)}const he=[{id:"export",icon:"📤",label:"Export"},{id:"import",icon:"💾",label:"Import",requiresAdmin:!0},{id:"events",icon:"📡",label:"Events"},{id:"compose",icon:"✏️",label:"Compose",requiresWrite:!0},{id:"recovery",icon:"🔄",label:"Recovery"},{id:"managed-acl",icon:"🛡️",label:"Managed ACL",requiresOwner:!0},{id:"sprocket",icon:"⚙️",label:"Sprocket",requiresOwner:!0}];function pe(e){n(5,v=e),"sprocket"===e&&u&&"owner"===p&&q&&(ce(),le()),se()}function ge(){n(12,y=!1)}function ye(e){n(6,E=E.filter(t=>t.id!==e)),_.delete(e),v===e&&n(5,v="export")}async function ve(e,t,n=!0){const r=_.get(e);if(r&&!r.isLoading){r.isLoading=!0,_.set(e,r);try{const o={limit:n?100:200,until:n?Math.floor(Date.now()/1e3):r.oldestTimestamp};console.log("Loading search results for query:",t,"with options:",o);const i=await async function(e,t={}){const{limit:n=100,since:r=null,until:o=null,kinds:i=null}=t,s=[{search:e}];return r&&(s[0].since=r),o&&(s[0].until=o),i&&(s[0].kinds=i),n&&(s[0].limit=n),await ph(s,{timeout:3e4})}(t,o);if(console.log("Received search results:",i.length,"events"),r.events=n?i.sort((e,t)=>t.created_at-e.created_at):[...r.events,...i].sort((e,t)=>t.created_at-e.created_at),i.length>0){const e=Math.min(...i.map(e=>e.created_at));(!r.oldestTimestamp||et.id===e);t&&await ve(e,t.query,!1)}(t)}}async function we(){if(u&&d&&!h)try{console.log("Auto-fetching profile for:",d),await vh(),n(3,h=await hh(d)),console.log("Profile auto-loaded:",h)}catch(e){console.error("Failed to auto-load profile:",e)}}async function be(){if(u&&d)try{const e=await fetch(`/api/permissions/${d}`);if(e.ok){const t=await e.json();n(4,p=t.permission||""),console.log("User role loaded:",p),console.log("Is owner?","owner"===p)}else console.error("Failed to fetch user role:",e.status),n(4,p="")}catch(e){console.error("Error fetching user role:",e),n(4,p="")}else n(4,p="")}async function Ee(){try{const e=await fetch("/api/acl-mode");if(e.ok){const t=await e.json();n(7,K=t.acl_mode||""),console.log("ACL mode loaded:",K)}else console.error("Failed to fetch ACL mode:",e.status),n(7,K="")}catch(e){console.error("Error fetching ACL mode:",e),n(7,K="")}}async function ke(e=[]){if(u)if(0!==e.length||"admin"===a||"owner"===a)try{const t=await Ce("/api/export","POST"),n=await fetch("/api/export",{method:"POST",headers:{Authorization:t,"Content-Type":"application/json"},body:JSON.stringify({pubkeys:e})});if(!n.ok)throw new Error(`Export failed: ${n.status} ${n.statusText}`);const r=await n.blob(),o=window.URL.createObjectURL(r),i=document.createElement("a");i.href=o;const s=n.headers.get("Content-Disposition");let a="events.jsonl";if(s){const e=s.match(/filename="([^"]+)"/);e&&(a=e[1])}i.download=a,document.body.appendChild(i),i.click(),document.body.removeChild(i),window.URL.revokeObjectURL(o)}catch(e){console.error("Export failed:",e),alert("Export failed: "+e.message)}else alert("Admin or owner permission required to export all events");else alert("Please log in first")}async function xe(e=!1,t=null){if(!u||"write"!==p&&"admin"!==p&&"owner"!==p)alert("Write, admin, or owner permission required");else if(!C){n(17,C=!0),e&&($=null);try{console.log("Loading events with authors filter:",t,"including delete events");const r=await async function(e={}){const{limit:t=100,since:n=null,until:r=null,authors:o=null,kinds:i=null,...s}=e,a=[{...s}];return n&&(a[0].since=n),r&&(a[0].until=r),o&&(a[0].authors=o),i&&(a[0].kinds=i),t&&(a[0].limit=t),await ph(a,{timeout:3e4})}({limit:e?100:200,until:e?Math.floor(Date.now()/1e3):$,authors:t});if(console.log("Received events:",r.length,"events"),t&&r.length>0){const e=r.filter(e=>e.pubkey&&e.pubkey!==d);e.length>0&&console.warn("Server returned non-user events:",e.length,"out of",r.length)}if(e?(n(79,k=r.sort((e,t)=>t.created_at-e.created_at)),ae(r)):(n(79,k=[...k,...r].sort((e,t)=>t.created_at-e.created_at)),ae(k)),r.length>0){const e=Math.min(...r.map(e=>e.created_at));(!$||e<$)&&($=e)}A=r.length===(e?1e3:200),e&&A&&setTimeout(()=>{if("events"===v){const e=document.querySelectorAll(".events-view-content")[0];e&&e.scrollHeight<=e.clientHeight&&Se()}},100)}catch(e){console.error("Failed to load events:",e),alert("Failed to load events: "+e.message)}finally{n(17,C=!1)}}}async function Se(){await xe(!1)}async function Ce(e,t){if(!u||!d)throw new Error("Not logged in");const n={kind:27235,created_at:Math.floor(Date.now()/1e3),tags:[["u",window.location.origin+e],["method",t.toUpperCase()]],content:"",pubkey:d};let r;if(g&&"extension"===f)try{r=await g.signEvent(n)}catch(e){throw new Error("Failed to sign with extension: "+e.message)}else{if("nsec"!==f)throw new Error("No valid signer available");n.id="mock-id-"+Date.now(),n.sig="mock-signature-"+Date.now(),r=n}const o=JSON.stringify(r);return`Nostr ${btoa(o)}`}async function Ae(e,t){if(!u||!d)throw new Error("Not logged in");const n={kind:27235,created_at:Math.floor(Date.now()/1e3),tags:[["u",window.location.origin+t],["method",e.toUpperCase()]],content:"",pubkey:d};let r;if(g&&"extension"===f)try{r=await g.signEvent(n)}catch(e){throw new Error("Failed to sign with extension: "+e.message)}else{if("nsec"!==f)throw new Error("No valid signer available");n.id="mock-id-"+Date.now(),n.sig="mock-signature-"+Date.now(),r=n}const o=JSON.stringify(r);return btoa(o)}function $e(e){n(80,T=e),localStorage.setItem("viewAsRole",e),console.log("View as role changed to:",e,"Current effective role:",a)}T=localStorage.getItem("viewAsRole")||"";return e.$$.update=()=>{var t;if(6&e.$$.dirty[0]|131072&e.$$.dirty[2]&&n(32,r=k.sort((e,t)=>t.created_at-e.created_at)),8&e.$$.dirty[0]&&n(31,o=h?.about?(t=h.about,String(t).replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'")).replace(/\n{2,}/g,"
"):""),16&e.$$.dirty[0]|262144&e.$$.dirty[2]&&n(8,a=T&&""!==T?T:p),402&e.$$.dirty[0]|786432&e.$$.dirty[2]&&n(82,i=he.filter(e=>{const t=a;return!(e.requiresAdmin&&(!u||"admin"!==t&&"owner"!==t))&&(!(e.requiresOwner&&(!u||"owner"!==t))&&(!(e.requiresWrite&&(!u||"read"===t))&&(!("sprocket"===e.id&&!q)&&(("managed-acl"!==e.id||"managed"===K)&&(console.log(`Tab ${e.id} filter check:`,{isLoggedIn:u,userRole:p,viewAsRole:T,currentRole:t,requiresAdmin:e.requiresAdmin,requiresOwner:e.requiresOwner,requiresWrite:e.requiresWrite,visible:!0}),!0)))))})),64&e.$$.dirty[0]|1048576&e.$$.dirty[2]&&n(9,s=[...i,...E]),658&e.$$.dirty[0]|1048576&e.$$.dirty[2]&&console.log("Tabs debug:",{isLoggedIn:u,userRole:p,aclMode:K,filteredBaseTabs:i.map(e=>e.id),allTabs:s.map(e=>e.id)}),1&e.$$.dirty[0]&&"undefined"!=typeof document&&(c?document.body.classList.add("dark-theme"):document.body.classList.remove("dark-theme")),14&e.$$.dirty[0]&&u&&d&&!h&&we(),54&e.$$.dirty[0]|131072&e.$$.dirty[2]&&"events"===v&&u&&("read"===p||"write"===p||"admin"===p||"owner"===p)&&0===k.length){xe(!0,null)}32&e.$$.dirty[0]&&localStorage.setItem("selectedTab",v)},[c,u,d,h,p,v,E,K,a,s,l,g,y,m,w,x,S,C,N,U,M,F,D,H,z,W,V,J,G,Z,Q,o,r,_,X,function(e){return ee[e]||`Kind ${e}`},te,async function(){console.log("Toggle changed, showOnlyMyEvents:",_y),await xe(!0,null)},ne,re,oe,ie,function(){console.log("selectRecoveryKind called, recoverySelectedKind:",V),null!=V?(n(27,J=""),n(28,G=[]),Y=null,n(30,Q=!0),re()):console.log("No kind selected, skipping load")},function(){console.log("handleCustomKindInput called, recoveryCustomKind:",J);const e=parseInt(J);""!==J&&!isNaN(e)&&e>=0&&(n(26,V=null),n(28,G=[]),Y=null,n(30,Q=!0),re())},function(e){const t=G.filter(t=>t.kind===e.kind&&t.pubkey===e.pubkey),n=Math.max(...t.map(e=>e.created_at));return e.created_at===n},async function(){if(u&&"owner"===p)try{n(21,F=!0);const e=await fetch("/api/sprocket/status",{method:"GET",headers:{Authorization:`Nostr ${await Ae("GET","/api/sprocket/status")}`,"Content-Type":"application/json"}});if(e.ok){const t=await e.json();n(18,N=t.script_content||""),n(19,U=t),fe("Script loaded successfully","success")}else fe("Failed to load script","error")}catch(e){fe(`Error loading script: ${e.message}`,"error")}finally{n(21,F=!1)}},async function(){if(u&&"owner"===p)try{n(21,F=!0);const e=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await Ae("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:N});if(e.ok)fe("Script saved and updated successfully","success"),await ce(),await le();else{fe(`Failed to save script: ${await e.text()}`,"error")}}catch(e){fe(`Error saving script: ${e.message}`,"error")}finally{n(21,F=!1)}},async function(){if(u&&"owner"===p)try{n(21,F=!0);const e=await fetch("/api/sprocket/restart",{method:"POST",headers:{Authorization:`Nostr ${await Ae("POST","/api/sprocket/restart")}`,"Content-Type":"application/json"}});if(e.ok)fe("Sprocket restarted successfully","success"),await ce();else{fe(`Failed to restart sprocket: ${await e.text()}`,"error")}}catch(e){fe(`Error restarting sprocket: ${e.message}`,"error")}finally{n(21,F=!1)}},async function(){if(u&&"owner"===p&&confirm("Are you sure you want to delete the sprocket script? This will stop the current process."))try{n(21,F=!0);const e=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await Ae("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:""});if(e.ok)n(18,N=""),fe("Sprocket script deleted successfully","success"),await ce(),await le();else{fe(`Failed to delete script: ${await e.text()}`,"error")}}catch(e){fe(`Error deleting script: ${e.message}`,"error")}finally{n(21,F=!1)}},le,ue,de,function(e){n(24,z=e.target.files[0])},async function(){if(u&&"owner"===p&&z)try{n(21,F=!0);const e=await z.text(),t=await fetch("/api/sprocket/update",{method:"POST",headers:{Authorization:`Nostr ${await Ae("POST","/api/sprocket/update")}`,"Content-Type":"text/plain"},body:e});if(t.ok)n(18,N=e),fe("Script uploaded and updated successfully","success"),await ce(),await le();else{fe(`Failed to upload script: ${await t.text()}`,"error")}}catch(e){fe(`Error uploading script: ${e.message}`,"error")}finally{n(21,F=!1),n(24,z=null);const e=document.getElementById("sprocket-upload-file");e&&(e.value="")}},pe,function(){n(0,c=!c),"undefined"!=typeof localStorage&&localStorage.setItem("isDarkTheme",JSON.stringify(c))},function(){u||n(10,l=!0)},async function(e){const{method:t,pubkey:r,privateKey:o,signer:i}=e.detail;n(1,u=!0),n(2,d=r),f=t,n(11,g=i),n(10,l=!1);try{if(await vh(),"extension"===t&&i)oh.setSigner(i);else if("nsec"===t&&o){const e=new qd(o);oh.setSigner(e)}n(3,h=await hh(r)),console.log("Profile loaded:",h)}catch(e){console.error("Failed to load profile:",e)}await be(),await Ee()},function(){n(1,u=!1),n(2,d=""),f="",n(3,h=null),n(4,p=""),n(11,g=null),n(12,y=!1),P=[],n(79,k=[]),R=[],O=0,se(),"undefined"!=typeof localStorage&&(localStorage.removeItem("nostr_auth_method"),localStorage.removeItem("nostr_pubkey"),localStorage.removeItem("nostr_privkey"))},function(){n(10,l=!1)},function(){n(12,y=!0)},ge,function(){n(13,m=!m),m||n(14,w="")},function(e){"Enter"===e.key&&w.trim()?(!function(e){const t=`search-${Date.now()}`,r={id:t,icon:"🔍",label:e,isSearchTab:!0,query:e};n(6,E=[...E,r]),n(5,v=t),_.set(t,{events:[],isLoading:!1,hasMore:!0,oldestTimestamp:null}),ve(t,e)}(w.trim()),n(14,w=""),n(13,m=!1)):"Escape"===e.key&&(n(13,m=!1),n(14,w=""))},ye,ve,me,we,async function(){await ke([])},async function(){await ke([d])},function(e){n(15,x=e.target.files[0])},async function(){if(!u||"admin"!==p&&"owner"!==p)alert("Admin or owner permission required");else if(x)try{const e=await Ce("/api/import","POST"),t=new FormData;t.append("file",x);const r=await fetch("/api/import",{method:"POST",headers:{Authorization:e},body:t});if(!r.ok)throw new Error(`Import failed: ${r.status} ${r.statusText}`);await r.json();alert("Import started successfully"),n(15,x=null),document.getElementById("import-file").value=""}catch(e){console.error("Import failed:",e),alert("Import failed: "+e.message)}else alert("Please select a file")},xe,function(e){const{scrollTop:t,scrollHeight:n,clientHeight:r}=e.target;n-t-r<100&&Se()},function(){try{if(!W.trim())return void alert("Please enter some JSON to reformat");const e=JSON.parse(W);n(25,W=JSON.stringify(e,null,2))}catch(e){alert("Invalid JSON: "+e.message)}},async function(){try{if(!W.trim())return void alert("Please enter an event to sign");if(!u||!d)return void alert("Please log in to sign events");if(!g)return void alert("No signer available. Please log in with a valid authentication method.");const e=JSON.parse(W);e.pubkey=d,e.created_at=Math.floor(Date.now()/1e3),delete e.id,delete e.sig;const t=await g.signEvent(e);n(25,W=JSON.stringify(t,null,2)),alert("Event signed successfully!")}catch(e){console.error("Error signing event:",e),alert("Error signing event: "+e.message)}},async function(){try{if(!W.trim())return void alert("Please enter an event to publish");if(!u)return void alert("Please log in to publish events");if(!g)return void alert("No signer available. Please log in with a valid authentication method.");const e=JSON.parse(W);if(!e.id||!e.sig)return void alert('Event must be signed before publishing. Please click "Sign" first.');const t=`wss://${window.location.host}`,n=await Pg(t,e,g,d);n.success?alert("Event published successfully to ORLY relay!"):alert(`Event publishing failed: ${n.reason||"Unknown error"}`)}catch(e){console.error("Error publishing event:",e),alert("Error publishing event: "+e.message)}},$e,function(){const e=["owner","admin","write","read"],t=e.indexOf(p);return-1===t?["read"]:e.slice(t)},k,T,q,i,function(t){I.call(this,e,t)},function(t){I.call(this,e,t)},e=>e.id===v,function(e){w=e,n(14,w)},e=>pe(e.detail),e=>ye(e.detail),e=>te(e.detail),e=>ne(e.detail),e=>Py(e.detail.event,e.detail.e),e=>xe(e.detail.refresh,e.detail.authors),function(e){W=e,n(25,W)},function(e){N=e,n(18,N)},e=>ue(e.detail),e=>de(e.detail),function(){V=function(e){const t=e.querySelector(":checked");return t&&t.__value}(this),n(26,V),n(34,X)},function(){J=b(this.value),n(27,J)},e=>ie(e),e=>oe(e),(e,t)=>Py(e,t),e=>ve(e.id,e.query,!0),e=>ne(e.id),e=>te(e.id),(e,t)=>"Enter"===t.key&&te(e.id),(e,t)=>Py(e,t),(e,t)=>me(t,e.id),e=>$e(e===p?"":e),e=>"Escape"===e.key&&ge(),function(e){l=e,n(10,l)}]}return new class extends ee{constructor(e){super(),X(this,e,By,Iy,i,{},null,[-1,-1,-1,-1,-1,-1])}}({target:document.body,props:{name:"world"}})}(); //# sourceMappingURL=bundle.js.map diff --git a/app/web/dist/bundle.js.map b/app/web/dist/bundle.js.map index eadc844..460d7c9 100644 --- a/app/web/dist/bundle.js.map +++ b/app/web/dist/bundle.js.map @@ -1 +1 @@ -{"version":3,"file":"bundle.js","sources":["../node_modules/svelte/internal/index.mjs","../node_modules/@noble/curves/node_modules/@noble/hashes/esm/_assert.js","../node_modules/@noble/curves/node_modules/@noble/hashes/esm/crypto.js","../node_modules/@noble/curves/node_modules/@noble/hashes/esm/utils.js","../node_modules/@noble/curves/node_modules/@noble/hashes/esm/_sha2.js","../node_modules/@noble/curves/node_modules/@noble/hashes/esm/sha256.js","../node_modules/@noble/curves/esm/abstract/utils.js","../node_modules/@noble/curves/esm/abstract/modular.js","../node_modules/@noble/curves/esm/abstract/curve.js","../node_modules/@noble/curves/esm/abstract/weierstrass.js","../node_modules/@noble/curves/node_modules/@noble/hashes/esm/hmac.js","../node_modules/@noble/curves/esm/_shortw_utils.js","../node_modules/@noble/curves/esm/secp256k1.js","../node_modules/nostr-tools/node_modules/@noble/hashes/esm/crypto.js","../node_modules/nostr-tools/node_modules/@noble/hashes/esm/utils.js","../node_modules/nostr-tools/node_modules/@noble/hashes/esm/_assert.js","../node_modules/nostr-tools/node_modules/@noble/hashes/esm/_sha2.js","../node_modules/nostr-tools/node_modules/@noble/hashes/esm/sha256.js","../node_modules/nostr-tools/lib/esm/pool.js","../node_modules/nostr-tools/node_modules/@scure/base/lib/esm/index.js","../node_modules/@noble/ciphers/esm/_assert.js","../node_modules/@noble/ciphers/esm/utils.js","../node_modules/@noble/ciphers/esm/aes.js","../node_modules/@noble/ciphers/esm/_arx.js","../node_modules/@noble/ciphers/esm/chacha.js","../node_modules/nostr-tools/node_modules/@noble/hashes/esm/hmac.js","../node_modules/nostr-tools/node_modules/@noble/hashes/esm/hkdf.js","../node_modules/nostr-tools/lib/esm/index.js","../node_modules/nostr-tools/lib/esm/kinds.js","../node_modules/tslib/tslib.es6.mjs","../node_modules/rxjs/dist/esm5/internal/util/isFunction.js","../node_modules/rxjs/dist/esm5/internal/util/createErrorClass.js","../node_modules/rxjs/dist/esm5/internal/util/UnsubscriptionError.js","../node_modules/rxjs/dist/esm5/internal/util/arrRemove.js","../node_modules/rxjs/dist/esm5/internal/Subscription.js","../node_modules/rxjs/dist/esm5/internal/config.js","../node_modules/rxjs/dist/esm5/internal/scheduler/timeoutProvider.js","../node_modules/rxjs/dist/esm5/internal/util/reportUnhandledError.js","../node_modules/rxjs/dist/esm5/internal/util/noop.js","../node_modules/rxjs/dist/esm5/internal/util/errorContext.js","../node_modules/rxjs/dist/esm5/internal/Subscriber.js","../node_modules/rxjs/dist/esm5/internal/symbol/observable.js","../node_modules/rxjs/dist/esm5/internal/util/identity.js","../node_modules/rxjs/dist/esm5/internal/Observable.js","../node_modules/rxjs/dist/esm5/internal/util/pipe.js","../node_modules/rxjs/dist/esm5/internal/util/lift.js","../node_modules/rxjs/dist/esm5/internal/operators/OperatorSubscriber.js","../node_modules/rxjs/dist/esm5/internal/util/ObjectUnsubscribedError.js","../node_modules/rxjs/dist/esm5/internal/Subject.js","../node_modules/rxjs/dist/esm5/internal/scheduler/dateTimestampProvider.js","../node_modules/rxjs/dist/esm5/internal/ReplaySubject.js","../node_modules/rxjs/dist/esm5/internal/scheduler/Action.js","../node_modules/rxjs/dist/esm5/internal/scheduler/intervalProvider.js","../node_modules/rxjs/dist/esm5/internal/scheduler/AsyncAction.js","../node_modules/rxjs/dist/esm5/internal/Scheduler.js","../node_modules/rxjs/dist/esm5/internal/scheduler/AsyncScheduler.js","../node_modules/rxjs/dist/esm5/internal/scheduler/async.js","../node_modules/rxjs/dist/esm5/internal/observable/empty.js","../node_modules/rxjs/dist/esm5/internal/util/isScheduler.js","../node_modules/rxjs/dist/esm5/internal/util/args.js","../node_modules/rxjs/dist/esm5/internal/util/isArrayLike.js","../node_modules/rxjs/dist/esm5/internal/util/isPromise.js","../node_modules/rxjs/dist/esm5/internal/util/isInteropObservable.js","../node_modules/rxjs/dist/esm5/internal/util/isAsyncIterable.js","../node_modules/rxjs/dist/esm5/internal/util/throwUnobservableError.js","../node_modules/rxjs/dist/esm5/internal/symbol/iterator.js","../node_modules/rxjs/dist/esm5/internal/util/isIterable.js","../node_modules/rxjs/dist/esm5/internal/util/isReadableStreamLike.js","../node_modules/rxjs/dist/esm5/internal/observable/innerFrom.js","../node_modules/rxjs/dist/esm5/internal/util/executeSchedule.js","../node_modules/rxjs/dist/esm5/internal/operators/observeOn.js","../node_modules/rxjs/dist/esm5/internal/operators/subscribeOn.js","../node_modules/rxjs/dist/esm5/internal/scheduled/scheduleAsyncIterable.js","../node_modules/rxjs/dist/esm5/internal/scheduled/scheduled.js","../node_modules/rxjs/dist/esm5/internal/scheduled/scheduleObservable.js","../node_modules/rxjs/dist/esm5/internal/scheduled/scheduleArray.js","../node_modules/rxjs/dist/esm5/internal/scheduled/schedulePromise.js","../node_modules/rxjs/dist/esm5/internal/scheduled/scheduleIterable.js","../node_modules/rxjs/dist/esm5/internal/scheduled/scheduleReadableStreamLike.js","../node_modules/rxjs/dist/esm5/internal/observable/from.js","../node_modules/rxjs/dist/esm5/internal/observable/of.js","../node_modules/rxjs/dist/esm5/internal/operators/map.js","../node_modules/rxjs/dist/esm5/internal/util/mapOneOrManyArgs.js","../node_modules/rxjs/dist/esm5/internal/util/argsArgArrayOrObject.js","../node_modules/rxjs/dist/esm5/internal/observable/combineLatest.js","../node_modules/rxjs/dist/esm5/internal/util/createObject.js","../node_modules/rxjs/dist/esm5/internal/operators/mergeMap.js","../node_modules/rxjs/dist/esm5/internal/operators/mergeInternals.js","../node_modules/rxjs/dist/esm5/internal/operators/mergeAll.js","../node_modules/rxjs/dist/esm5/internal/observable/concat.js","../node_modules/rxjs/dist/esm5/internal/operators/concatAll.js","../node_modules/rxjs/dist/esm5/internal/observable/defer.js","../node_modules/rxjs/dist/esm5/internal/observable/timer.js","../node_modules/rxjs/dist/esm5/internal/util/isDate.js","../node_modules/rxjs/dist/esm5/internal/observable/merge.js","../node_modules/rxjs/dist/esm5/internal/operators/filter.js","../node_modules/rxjs/dist/esm5/internal/operators/take.js","../node_modules/rxjs/dist/esm5/internal/operators/distinctUntilChanged.js","../node_modules/rxjs/dist/esm5/internal/operators/endWith.js","../node_modules/rxjs/dist/esm5/internal/operators/finalize.js","../node_modules/rxjs/dist/esm5/internal/operators/merge.js","../node_modules/rxjs/dist/esm5/internal/operators/mergeWith.js","../node_modules/rxjs/dist/esm5/internal/operators/scan.js","../node_modules/rxjs/dist/esm5/internal/operators/scanInternals.js","../node_modules/rxjs/dist/esm5/internal/operators/share.js","../node_modules/rxjs/dist/esm5/internal/operators/switchMap.js","../node_modules/rxjs/dist/esm5/internal/operators/tap.js","../node_modules/applesauce-core/dist/helpers/tags.js","../node_modules/applesauce-core/dist/helpers/cache.js","../node_modules/nostr-tools/lib/esm/utils.js","../node_modules/applesauce-core/dist/helpers/event.js","../node_modules/applesauce-core/dist/helpers/time.js","../node_modules/applesauce-core/dist/helpers/expiration.js","../node_modules/applesauce-core/dist/helpers/url.js","../node_modules/applesauce-core/dist/helpers/relays.js","../node_modules/applesauce-core/dist/helpers/string.js","../node_modules/applesauce-core/node_modules/@noble/hashes/esm/utils.js","../node_modules/applesauce-core/dist/helpers/pointers.js","../node_modules/applesauce-core/dist/helpers/groups.js","../node_modules/applesauce-core/dist/helpers/encrypted-content.js","../node_modules/applesauce-core/dist/helpers/hidden-content.js","../node_modules/applesauce-core/dist/helpers/hidden-tags.js","../node_modules/applesauce-core/dist/helpers/event-tags.js","../node_modules/applesauce-core/dist/helpers/lru.js","../node_modules/ms/index.js","../node_modules/debug/src/common.js","../node_modules/debug/src/browser.js","../node_modules/applesauce-core/dist/logger.js","../node_modules/applesauce-core/dist/event-store/event-memory.js","../node_modules/hash-sum/hash-sum.js","../node_modules/applesauce-core/dist/helpers/filter.js","../node_modules/applesauce-core/dist/models/blossom.js","../node_modules/applesauce-core/dist/helpers/blossom.js","../node_modules/applesauce-core/dist/helpers/profile.js","../node_modules/applesauce-core/dist/helpers/json.js","../node_modules/light-bolt11-decoder/node_modules/@scure/base/lib/index.js","../node_modules/light-bolt11-decoder/bolt11.js","../node_modules/applesauce-core/dist/helpers/comment.js","../node_modules/applesauce-core/dist/helpers/contacts.js","../node_modules/applesauce-core/dist/helpers/encrypted-content-cache.js","../node_modules/applesauce-core/dist/helpers/event-cache.js","../node_modules/applesauce-core/dist/helpers/lnurl.js","../node_modules/applesauce-core/dist/helpers/mailboxes.js","../node_modules/applesauce-core/dist/helpers/mutes.js","../node_modules/applesauce-core/dist/helpers/reports.js","../node_modules/applesauce-core/dist/helpers/threading.js","../node_modules/applesauce-core/dist/observable/claim-events.js","../node_modules/applesauce-core/dist/observable/claim-latest.js","../node_modules/applesauce-core/dist/observable/defined.js","../node_modules/applesauce-core/dist/observable/with-immediate-value.js","../node_modules/applesauce-core/dist/models/common.js","../node_modules/rxjs/dist/esm5/internal/operators/ignoreElements.js","../node_modules/rxjs/dist/esm5/internal/operators/takeUntil.js","../node_modules/rxjs/dist/esm5/internal/operators/repeat.js","../node_modules/applesauce-core/dist/observable/watch-event-updates.js","../node_modules/applesauce-core/dist/models/contacts.js","../node_modules/applesauce-core/dist/models/comments.js","../node_modules/applesauce-core/dist/models/mailboxes.js","../node_modules/applesauce-core/dist/models/mutes.js","../node_modules/applesauce-core/dist/models/profile.js","../node_modules/applesauce-core/dist/models/reactions.js","../node_modules/applesauce-core/dist/models/thread.js","../node_modules/applesauce-core/dist/event-store/model-mixin.js","../node_modules/applesauce-core/dist/event-store/event-store.js","../node_modules/applesauce-core/dist/helpers/delete.js","../node_modules/applesauce-core/dist/promise/deferred.js","../node_modules/applesauce-signers/dist/signers/amber-clipboard-signer.js","../node_modules/applesauce-signers/dist/helpers/nostr-connect.js","../node_modules/applesauce-signers/dist/signers/private-key-signer.js","../node_modules/applesauce-signers/node_modules/@noble/hashes/esm/crypto.js","../node_modules/applesauce-signers/node_modules/@noble/hashes/esm/utils.js","../node_modules/applesauce-signers/node_modules/@noble/secp256k1/lib/esm/index.js","../node_modules/applesauce-signers/node_modules/@scure/base/lib/esm/index.js","../node_modules/applesauce-signers/dist/signers/serial-port-signer.js","../src/constants.js","../src/nostr.js","../src/LoginModal.svelte","../src/ManagedACL.svelte","../src/Header.svelte","../src/Sidebar.svelte","../src/ExportView.svelte","../src/ImportView.svelte","../src/EventsView.svelte","../src/ComposeView.svelte","../src/SprocketView.svelte","../src/websocket-auth.js","../src/App.svelte","../src/main.js"],"sourcesContent":["function noop() { }\nconst identity = x => x;\nfunction assign(tar, src) {\n // @ts-ignore\n for (const k in src)\n tar[k] = src[k];\n return tar;\n}\n// Adapted from https://github.com/then/is-promise/blob/master/index.js\n// Distributed under MIT License https://github.com/then/is-promise/blob/master/LICENSE\nfunction is_promise(value) {\n return !!value && (typeof value === 'object' || typeof value === 'function') && typeof value.then === 'function';\n}\nfunction add_location(element, file, line, column, char) {\n element.__svelte_meta = {\n loc: { file, line, column, char }\n };\n}\nfunction run(fn) {\n return fn();\n}\nfunction blank_object() {\n return Object.create(null);\n}\nfunction run_all(fns) {\n fns.forEach(run);\n}\nfunction is_function(thing) {\n return typeof thing === 'function';\n}\nfunction safe_not_equal(a, b) {\n return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');\n}\nlet src_url_equal_anchor;\nfunction src_url_equal(element_src, url) {\n if (!src_url_equal_anchor) {\n src_url_equal_anchor = document.createElement('a');\n }\n src_url_equal_anchor.href = url;\n return element_src === src_url_equal_anchor.href;\n}\nfunction not_equal(a, b) {\n return a != a ? b == b : a !== b;\n}\nfunction is_empty(obj) {\n return Object.keys(obj).length === 0;\n}\nfunction validate_store(store, name) {\n if (store != null && typeof store.subscribe !== 'function') {\n throw new Error(`'${name}' is not a store with a 'subscribe' method`);\n }\n}\nfunction subscribe(store, ...callbacks) {\n if (store == null) {\n return noop;\n }\n const unsub = store.subscribe(...callbacks);\n return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;\n}\nfunction get_store_value(store) {\n let value;\n subscribe(store, _ => value = _)();\n return value;\n}\nfunction component_subscribe(component, store, callback) {\n component.$$.on_destroy.push(subscribe(store, callback));\n}\nfunction create_slot(definition, ctx, $$scope, fn) {\n if (definition) {\n const slot_ctx = get_slot_context(definition, ctx, $$scope, fn);\n return definition[0](slot_ctx);\n }\n}\nfunction get_slot_context(definition, ctx, $$scope, fn) {\n return definition[1] && fn\n ? assign($$scope.ctx.slice(), definition[1](fn(ctx)))\n : $$scope.ctx;\n}\nfunction get_slot_changes(definition, $$scope, dirty, fn) {\n if (definition[2] && fn) {\n const lets = definition[2](fn(dirty));\n if ($$scope.dirty === undefined) {\n return lets;\n }\n if (typeof lets === 'object') {\n const merged = [];\n const len = Math.max($$scope.dirty.length, lets.length);\n for (let i = 0; i < len; i += 1) {\n merged[i] = $$scope.dirty[i] | lets[i];\n }\n return merged;\n }\n return $$scope.dirty | lets;\n }\n return $$scope.dirty;\n}\nfunction update_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn) {\n if (slot_changes) {\n const slot_context = get_slot_context(slot_definition, ctx, $$scope, get_slot_context_fn);\n slot.p(slot_context, slot_changes);\n }\n}\nfunction update_slot(slot, slot_definition, ctx, $$scope, dirty, get_slot_changes_fn, get_slot_context_fn) {\n const slot_changes = get_slot_changes(slot_definition, $$scope, dirty, get_slot_changes_fn);\n update_slot_base(slot, slot_definition, ctx, $$scope, slot_changes, get_slot_context_fn);\n}\nfunction get_all_dirty_from_scope($$scope) {\n if ($$scope.ctx.length > 32) {\n const dirty = [];\n const length = $$scope.ctx.length / 32;\n for (let i = 0; i < length; i++) {\n dirty[i] = -1;\n }\n return dirty;\n }\n return -1;\n}\nfunction exclude_internal_props(props) {\n const result = {};\n for (const k in props)\n if (k[0] !== '$')\n result[k] = props[k];\n return result;\n}\nfunction compute_rest_props(props, keys) {\n const rest = {};\n keys = new Set(keys);\n for (const k in props)\n if (!keys.has(k) && k[0] !== '$')\n rest[k] = props[k];\n return rest;\n}\nfunction compute_slots(slots) {\n const result = {};\n for (const key in slots) {\n result[key] = true;\n }\n return result;\n}\nfunction once(fn) {\n let ran = false;\n return function (...args) {\n if (ran)\n return;\n ran = true;\n fn.call(this, ...args);\n };\n}\nfunction null_to_empty(value) {\n return value == null ? '' : value;\n}\nfunction set_store_value(store, ret, value) {\n store.set(value);\n return ret;\n}\nconst has_prop = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);\nfunction action_destroyer(action_result) {\n return action_result && is_function(action_result.destroy) ? action_result.destroy : noop;\n}\nfunction split_css_unit(value) {\n const split = typeof value === 'string' && value.match(/^\\s*(-?[\\d.]+)([^\\s]*)\\s*$/);\n return split ? [parseFloat(split[1]), split[2] || 'px'] : [value, 'px'];\n}\nconst contenteditable_truthy_values = ['', true, 1, 'true', 'contenteditable'];\n\nconst is_client = typeof window !== 'undefined';\nlet now = is_client\n ? () => window.performance.now()\n : () => Date.now();\nlet raf = is_client ? cb => requestAnimationFrame(cb) : noop;\n// used internally for testing\nfunction set_now(fn) {\n now = fn;\n}\nfunction set_raf(fn) {\n raf = fn;\n}\n\nconst tasks = new Set();\nfunction run_tasks(now) {\n tasks.forEach(task => {\n if (!task.c(now)) {\n tasks.delete(task);\n task.f();\n }\n });\n if (tasks.size !== 0)\n raf(run_tasks);\n}\n/**\n * For testing purposes only!\n */\nfunction clear_loops() {\n tasks.clear();\n}\n/**\n * Creates a new task that runs on each raf frame\n * until it returns a falsy value or is aborted\n */\nfunction loop(callback) {\n let task;\n if (tasks.size === 0)\n raf(run_tasks);\n return {\n promise: new Promise(fulfill => {\n tasks.add(task = { c: callback, f: fulfill });\n }),\n abort() {\n tasks.delete(task);\n }\n };\n}\n\nconst globals = (typeof window !== 'undefined'\n ? window\n : typeof globalThis !== 'undefined'\n ? globalThis\n : global);\n\n/**\n * Resize observer singleton.\n * One listener per element only!\n * https://groups.google.com/a/chromium.org/g/blink-dev/c/z6ienONUb5A/m/F5-VcUZtBAAJ\n */\nclass ResizeObserverSingleton {\n constructor(options) {\n this.options = options;\n this._listeners = 'WeakMap' in globals ? new WeakMap() : undefined;\n }\n observe(element, listener) {\n this._listeners.set(element, listener);\n this._getObserver().observe(element, this.options);\n return () => {\n this._listeners.delete(element);\n this._observer.unobserve(element); // this line can probably be removed\n };\n }\n _getObserver() {\n var _a;\n return (_a = this._observer) !== null && _a !== void 0 ? _a : (this._observer = new ResizeObserver((entries) => {\n var _a;\n for (const entry of entries) {\n ResizeObserverSingleton.entries.set(entry.target, entry);\n (_a = this._listeners.get(entry.target)) === null || _a === void 0 ? void 0 : _a(entry);\n }\n }));\n }\n}\n// Needs to be written like this to pass the tree-shake-test\nResizeObserverSingleton.entries = 'WeakMap' in globals ? new WeakMap() : undefined;\n\n// Track which nodes are claimed during hydration. Unclaimed nodes can then be removed from the DOM\n// at the end of hydration without touching the remaining nodes.\nlet is_hydrating = false;\nfunction start_hydrating() {\n is_hydrating = true;\n}\nfunction end_hydrating() {\n is_hydrating = false;\n}\nfunction upper_bound(low, high, key, value) {\n // Return first index of value larger than input value in the range [low, high)\n while (low < high) {\n const mid = low + ((high - low) >> 1);\n if (key(mid) <= value) {\n low = mid + 1;\n }\n else {\n high = mid;\n }\n }\n return low;\n}\nfunction init_hydrate(target) {\n if (target.hydrate_init)\n return;\n target.hydrate_init = true;\n // We know that all children have claim_order values since the unclaimed have been detached if target is not \n let children = target.childNodes;\n // If target is , there may be children without claim_order\n if (target.nodeName === 'HEAD') {\n const myChildren = [];\n for (let i = 0; i < children.length; i++) {\n const node = children[i];\n if (node.claim_order !== undefined) {\n myChildren.push(node);\n }\n }\n children = myChildren;\n }\n /*\n * Reorder claimed children optimally.\n * We can reorder claimed children optimally by finding the longest subsequence of\n * nodes that are already claimed in order and only moving the rest. The longest\n * subsequence of nodes that are claimed in order can be found by\n * computing the longest increasing subsequence of .claim_order values.\n *\n * This algorithm is optimal in generating the least amount of reorder operations\n * possible.\n *\n * Proof:\n * We know that, given a set of reordering operations, the nodes that do not move\n * always form an increasing subsequence, since they do not move among each other\n * meaning that they must be already ordered among each other. Thus, the maximal\n * set of nodes that do not move form a longest increasing subsequence.\n */\n // Compute longest increasing subsequence\n // m: subsequence length j => index k of smallest value that ends an increasing subsequence of length j\n const m = new Int32Array(children.length + 1);\n // Predecessor indices + 1\n const p = new Int32Array(children.length);\n m[0] = -1;\n let longest = 0;\n for (let i = 0; i < children.length; i++) {\n const current = children[i].claim_order;\n // Find the largest subsequence length such that it ends in a value less than our current value\n // upper_bound returns first greater value, so we subtract one\n // with fast path for when we are on the current longest subsequence\n const seqLen = ((longest > 0 && children[m[longest]].claim_order <= current) ? longest + 1 : upper_bound(1, longest, idx => children[m[idx]].claim_order, current)) - 1;\n p[i] = m[seqLen] + 1;\n const newLen = seqLen + 1;\n // We can guarantee that current is the smallest value. Otherwise, we would have generated a longer sequence.\n m[newLen] = i;\n longest = Math.max(newLen, longest);\n }\n // The longest increasing subsequence of nodes (initially reversed)\n const lis = [];\n // The rest of the nodes, nodes that will be moved\n const toMove = [];\n let last = children.length - 1;\n for (let cur = m[longest] + 1; cur != 0; cur = p[cur - 1]) {\n lis.push(children[cur - 1]);\n for (; last >= cur; last--) {\n toMove.push(children[last]);\n }\n last--;\n }\n for (; last >= 0; last--) {\n toMove.push(children[last]);\n }\n lis.reverse();\n // We sort the nodes being moved to guarantee that their insertion order matches the claim order\n toMove.sort((a, b) => a.claim_order - b.claim_order);\n // Finally, we move the nodes\n for (let i = 0, j = 0; i < toMove.length; i++) {\n while (j < lis.length && toMove[i].claim_order >= lis[j].claim_order) {\n j++;\n }\n const anchor = j < lis.length ? lis[j] : null;\n target.insertBefore(toMove[i], anchor);\n }\n}\nfunction append(target, node) {\n target.appendChild(node);\n}\nfunction append_styles(target, style_sheet_id, styles) {\n const append_styles_to = get_root_for_style(target);\n if (!append_styles_to.getElementById(style_sheet_id)) {\n const style = element('style');\n style.id = style_sheet_id;\n style.textContent = styles;\n append_stylesheet(append_styles_to, style);\n }\n}\nfunction get_root_for_style(node) {\n if (!node)\n return document;\n const root = node.getRootNode ? node.getRootNode() : node.ownerDocument;\n if (root && root.host) {\n return root;\n }\n return node.ownerDocument;\n}\nfunction append_empty_stylesheet(node) {\n const style_element = element('style');\n append_stylesheet(get_root_for_style(node), style_element);\n return style_element.sheet;\n}\nfunction append_stylesheet(node, style) {\n append(node.head || node, style);\n return style.sheet;\n}\nfunction append_hydration(target, node) {\n if (is_hydrating) {\n init_hydrate(target);\n if ((target.actual_end_child === undefined) || ((target.actual_end_child !== null) && (target.actual_end_child.parentNode !== target))) {\n target.actual_end_child = target.firstChild;\n }\n // Skip nodes of undefined ordering\n while ((target.actual_end_child !== null) && (target.actual_end_child.claim_order === undefined)) {\n target.actual_end_child = target.actual_end_child.nextSibling;\n }\n if (node !== target.actual_end_child) {\n // We only insert if the ordering of this node should be modified or the parent node is not target\n if (node.claim_order !== undefined || node.parentNode !== target) {\n target.insertBefore(node, target.actual_end_child);\n }\n }\n else {\n target.actual_end_child = node.nextSibling;\n }\n }\n else if (node.parentNode !== target || node.nextSibling !== null) {\n target.appendChild(node);\n }\n}\nfunction insert(target, node, anchor) {\n target.insertBefore(node, anchor || null);\n}\nfunction insert_hydration(target, node, anchor) {\n if (is_hydrating && !anchor) {\n append_hydration(target, node);\n }\n else if (node.parentNode !== target || node.nextSibling != anchor) {\n target.insertBefore(node, anchor || null);\n }\n}\nfunction detach(node) {\n if (node.parentNode) {\n node.parentNode.removeChild(node);\n }\n}\nfunction destroy_each(iterations, detaching) {\n for (let i = 0; i < iterations.length; i += 1) {\n if (iterations[i])\n iterations[i].d(detaching);\n }\n}\nfunction element(name) {\n return document.createElement(name);\n}\nfunction element_is(name, is) {\n return document.createElement(name, { is });\n}\nfunction object_without_properties(obj, exclude) {\n const target = {};\n for (const k in obj) {\n if (has_prop(obj, k)\n // @ts-ignore\n && exclude.indexOf(k) === -1) {\n // @ts-ignore\n target[k] = obj[k];\n }\n }\n return target;\n}\nfunction svg_element(name) {\n return document.createElementNS('http://www.w3.org/2000/svg', name);\n}\nfunction text(data) {\n return document.createTextNode(data);\n}\nfunction space() {\n return text(' ');\n}\nfunction empty() {\n return text('');\n}\nfunction comment(content) {\n return document.createComment(content);\n}\nfunction listen(node, event, handler, options) {\n node.addEventListener(event, handler, options);\n return () => node.removeEventListener(event, handler, options);\n}\nfunction prevent_default(fn) {\n return function (event) {\n event.preventDefault();\n // @ts-ignore\n return fn.call(this, event);\n };\n}\nfunction stop_propagation(fn) {\n return function (event) {\n event.stopPropagation();\n // @ts-ignore\n return fn.call(this, event);\n };\n}\nfunction stop_immediate_propagation(fn) {\n return function (event) {\n event.stopImmediatePropagation();\n // @ts-ignore\n return fn.call(this, event);\n };\n}\nfunction self(fn) {\n return function (event) {\n // @ts-ignore\n if (event.target === this)\n fn.call(this, event);\n };\n}\nfunction trusted(fn) {\n return function (event) {\n // @ts-ignore\n if (event.isTrusted)\n fn.call(this, event);\n };\n}\nfunction attr(node, attribute, value) {\n if (value == null)\n node.removeAttribute(attribute);\n else if (node.getAttribute(attribute) !== value)\n node.setAttribute(attribute, value);\n}\n/**\n * List of attributes that should always be set through the attr method,\n * because updating them through the property setter doesn't work reliably.\n * In the example of `width`/`height`, the problem is that the setter only\n * accepts numeric values, but the attribute can also be set to a string like `50%`.\n * If this list becomes too big, rethink this approach.\n */\nconst always_set_through_set_attribute = ['width', 'height'];\nfunction set_attributes(node, attributes) {\n // @ts-ignore\n const descriptors = Object.getOwnPropertyDescriptors(node.__proto__);\n for (const key in attributes) {\n if (attributes[key] == null) {\n node.removeAttribute(key);\n }\n else if (key === 'style') {\n node.style.cssText = attributes[key];\n }\n else if (key === '__value') {\n node.value = node[key] = attributes[key];\n }\n else if (descriptors[key] && descriptors[key].set && always_set_through_set_attribute.indexOf(key) === -1) {\n node[key] = attributes[key];\n }\n else {\n attr(node, key, attributes[key]);\n }\n }\n}\nfunction set_svg_attributes(node, attributes) {\n for (const key in attributes) {\n attr(node, key, attributes[key]);\n }\n}\nfunction set_custom_element_data_map(node, data_map) {\n Object.keys(data_map).forEach((key) => {\n set_custom_element_data(node, key, data_map[key]);\n });\n}\nfunction set_custom_element_data(node, prop, value) {\n if (prop in node) {\n node[prop] = typeof node[prop] === 'boolean' && value === '' ? true : value;\n }\n else {\n attr(node, prop, value);\n }\n}\nfunction set_dynamic_element_data(tag) {\n return (/-/.test(tag)) ? set_custom_element_data_map : set_attributes;\n}\nfunction xlink_attr(node, attribute, value) {\n node.setAttributeNS('http://www.w3.org/1999/xlink', attribute, value);\n}\nfunction get_binding_group_value(group, __value, checked) {\n const value = new Set();\n for (let i = 0; i < group.length; i += 1) {\n if (group[i].checked)\n value.add(group[i].__value);\n }\n if (!checked) {\n value.delete(__value);\n }\n return Array.from(value);\n}\nfunction init_binding_group(group) {\n let _inputs;\n return {\n /* push */ p(...inputs) {\n _inputs = inputs;\n _inputs.forEach(input => group.push(input));\n },\n /* remove */ r() {\n _inputs.forEach(input => group.splice(group.indexOf(input), 1));\n }\n };\n}\nfunction init_binding_group_dynamic(group, indexes) {\n let _group = get_binding_group(group);\n let _inputs;\n function get_binding_group(group) {\n for (let i = 0; i < indexes.length; i++) {\n group = group[indexes[i]] = group[indexes[i]] || [];\n }\n return group;\n }\n function push() {\n _inputs.forEach(input => _group.push(input));\n }\n function remove() {\n _inputs.forEach(input => _group.splice(_group.indexOf(input), 1));\n }\n return {\n /* update */ u(new_indexes) {\n indexes = new_indexes;\n const new_group = get_binding_group(group);\n if (new_group !== _group) {\n remove();\n _group = new_group;\n push();\n }\n },\n /* push */ p(...inputs) {\n _inputs = inputs;\n push();\n },\n /* remove */ r: remove\n };\n}\nfunction to_number(value) {\n return value === '' ? null : +value;\n}\nfunction time_ranges_to_array(ranges) {\n const array = [];\n for (let i = 0; i < ranges.length; i += 1) {\n array.push({ start: ranges.start(i), end: ranges.end(i) });\n }\n return array;\n}\nfunction children(element) {\n return Array.from(element.childNodes);\n}\nfunction init_claim_info(nodes) {\n if (nodes.claim_info === undefined) {\n nodes.claim_info = { last_index: 0, total_claimed: 0 };\n }\n}\nfunction claim_node(nodes, predicate, processNode, createNode, dontUpdateLastIndex = false) {\n // Try to find nodes in an order such that we lengthen the longest increasing subsequence\n init_claim_info(nodes);\n const resultNode = (() => {\n // We first try to find an element after the previous one\n for (let i = nodes.claim_info.last_index; i < nodes.length; i++) {\n const node = nodes[i];\n if (predicate(node)) {\n const replacement = processNode(node);\n if (replacement === undefined) {\n nodes.splice(i, 1);\n }\n else {\n nodes[i] = replacement;\n }\n if (!dontUpdateLastIndex) {\n nodes.claim_info.last_index = i;\n }\n return node;\n }\n }\n // Otherwise, we try to find one before\n // We iterate in reverse so that we don't go too far back\n for (let i = nodes.claim_info.last_index - 1; i >= 0; i--) {\n const node = nodes[i];\n if (predicate(node)) {\n const replacement = processNode(node);\n if (replacement === undefined) {\n nodes.splice(i, 1);\n }\n else {\n nodes[i] = replacement;\n }\n if (!dontUpdateLastIndex) {\n nodes.claim_info.last_index = i;\n }\n else if (replacement === undefined) {\n // Since we spliced before the last_index, we decrease it\n nodes.claim_info.last_index--;\n }\n return node;\n }\n }\n // If we can't find any matching node, we create a new one\n return createNode();\n })();\n resultNode.claim_order = nodes.claim_info.total_claimed;\n nodes.claim_info.total_claimed += 1;\n return resultNode;\n}\nfunction claim_element_base(nodes, name, attributes, create_element) {\n return claim_node(nodes, (node) => node.nodeName === name, (node) => {\n const remove = [];\n for (let j = 0; j < node.attributes.length; j++) {\n const attribute = node.attributes[j];\n if (!attributes[attribute.name]) {\n remove.push(attribute.name);\n }\n }\n remove.forEach(v => node.removeAttribute(v));\n return undefined;\n }, () => create_element(name));\n}\nfunction claim_element(nodes, name, attributes) {\n return claim_element_base(nodes, name, attributes, element);\n}\nfunction claim_svg_element(nodes, name, attributes) {\n return claim_element_base(nodes, name, attributes, svg_element);\n}\nfunction claim_text(nodes, data) {\n return claim_node(nodes, (node) => node.nodeType === 3, (node) => {\n const dataStr = '' + data;\n if (node.data.startsWith(dataStr)) {\n if (node.data.length !== dataStr.length) {\n return node.splitText(dataStr.length);\n }\n }\n else {\n node.data = dataStr;\n }\n }, () => text(data), true // Text nodes should not update last index since it is likely not worth it to eliminate an increasing subsequence of actual elements\n );\n}\nfunction claim_space(nodes) {\n return claim_text(nodes, ' ');\n}\nfunction claim_comment(nodes, data) {\n return claim_node(nodes, (node) => node.nodeType === 8, (node) => {\n node.data = '' + data;\n return undefined;\n }, () => comment(data), true);\n}\nfunction find_comment(nodes, text, start) {\n for (let i = start; i < nodes.length; i += 1) {\n const node = nodes[i];\n if (node.nodeType === 8 /* comment node */ && node.textContent.trim() === text) {\n return i;\n }\n }\n return nodes.length;\n}\nfunction claim_html_tag(nodes, is_svg) {\n // find html opening tag\n const start_index = find_comment(nodes, 'HTML_TAG_START', 0);\n const end_index = find_comment(nodes, 'HTML_TAG_END', start_index);\n if (start_index === end_index) {\n return new HtmlTagHydration(undefined, is_svg);\n }\n init_claim_info(nodes);\n const html_tag_nodes = nodes.splice(start_index, end_index - start_index + 1);\n detach(html_tag_nodes[0]);\n detach(html_tag_nodes[html_tag_nodes.length - 1]);\n const claimed_nodes = html_tag_nodes.slice(1, html_tag_nodes.length - 1);\n for (const n of claimed_nodes) {\n n.claim_order = nodes.claim_info.total_claimed;\n nodes.claim_info.total_claimed += 1;\n }\n return new HtmlTagHydration(claimed_nodes, is_svg);\n}\nfunction set_data(text, data) {\n data = '' + data;\n if (text.data === data)\n return;\n text.data = data;\n}\nfunction set_data_contenteditable(text, data) {\n data = '' + data;\n if (text.wholeText === data)\n return;\n text.data = data;\n}\nfunction set_data_maybe_contenteditable(text, data, attr_value) {\n if (~contenteditable_truthy_values.indexOf(attr_value)) {\n set_data_contenteditable(text, data);\n }\n else {\n set_data(text, data);\n }\n}\nfunction set_input_value(input, value) {\n input.value = value == null ? '' : value;\n}\nfunction set_input_type(input, type) {\n try {\n input.type = type;\n }\n catch (e) {\n // do nothing\n }\n}\nfunction set_style(node, key, value, important) {\n if (value == null) {\n node.style.removeProperty(key);\n }\n else {\n node.style.setProperty(key, value, important ? 'important' : '');\n }\n}\nfunction select_option(select, value, mounting) {\n for (let i = 0; i < select.options.length; i += 1) {\n const option = select.options[i];\n if (option.__value === value) {\n option.selected = true;\n return;\n }\n }\n if (!mounting || value !== undefined) {\n select.selectedIndex = -1; // no option should be selected\n }\n}\nfunction select_options(select, value) {\n for (let i = 0; i < select.options.length; i += 1) {\n const option = select.options[i];\n option.selected = ~value.indexOf(option.__value);\n }\n}\nfunction select_value(select) {\n const selected_option = select.querySelector(':checked');\n return selected_option && selected_option.__value;\n}\nfunction select_multiple_value(select) {\n return [].map.call(select.querySelectorAll(':checked'), option => option.__value);\n}\n// unfortunately this can't be a constant as that wouldn't be tree-shakeable\n// so we cache the result instead\nlet crossorigin;\nfunction is_crossorigin() {\n if (crossorigin === undefined) {\n crossorigin = false;\n try {\n if (typeof window !== 'undefined' && window.parent) {\n void window.parent.document;\n }\n }\n catch (error) {\n crossorigin = true;\n }\n }\n return crossorigin;\n}\nfunction add_iframe_resize_listener(node, fn) {\n const computed_style = getComputedStyle(node);\n if (computed_style.position === 'static') {\n node.style.position = 'relative';\n }\n const iframe = element('iframe');\n iframe.setAttribute('style', 'display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; ' +\n 'overflow: hidden; border: 0; opacity: 0; pointer-events: none; z-index: -1;');\n iframe.setAttribute('aria-hidden', 'true');\n iframe.tabIndex = -1;\n const crossorigin = is_crossorigin();\n let unsubscribe;\n if (crossorigin) {\n iframe.src = \"data:text/html,\";\n unsubscribe = listen(window, 'message', (event) => {\n if (event.source === iframe.contentWindow)\n fn();\n });\n }\n else {\n iframe.src = 'about:blank';\n iframe.onload = () => {\n unsubscribe = listen(iframe.contentWindow, 'resize', fn);\n // make sure an initial resize event is fired _after_ the iframe is loaded (which is asynchronous)\n // see https://github.com/sveltejs/svelte/issues/4233\n fn();\n };\n }\n append(node, iframe);\n return () => {\n if (crossorigin) {\n unsubscribe();\n }\n else if (unsubscribe && iframe.contentWindow) {\n unsubscribe();\n }\n detach(iframe);\n };\n}\nconst resize_observer_content_box = /* @__PURE__ */ new ResizeObserverSingleton({ box: 'content-box' });\nconst resize_observer_border_box = /* @__PURE__ */ new ResizeObserverSingleton({ box: 'border-box' });\nconst resize_observer_device_pixel_content_box = /* @__PURE__ */ new ResizeObserverSingleton({ box: 'device-pixel-content-box' });\nfunction toggle_class(element, name, toggle) {\n element.classList[toggle ? 'add' : 'remove'](name);\n}\nfunction custom_event(type, detail, { bubbles = false, cancelable = false } = {}) {\n const e = document.createEvent('CustomEvent');\n e.initCustomEvent(type, bubbles, cancelable, detail);\n return e;\n}\nfunction query_selector_all(selector, parent = document.body) {\n return Array.from(parent.querySelectorAll(selector));\n}\nfunction head_selector(nodeId, head) {\n const result = [];\n let started = 0;\n for (const node of head.childNodes) {\n if (node.nodeType === 8 /* comment node */) {\n const comment = node.textContent.trim();\n if (comment === `HEAD_${nodeId}_END`) {\n started -= 1;\n result.push(node);\n }\n else if (comment === `HEAD_${nodeId}_START`) {\n started += 1;\n result.push(node);\n }\n }\n else if (started > 0) {\n result.push(node);\n }\n }\n return result;\n}\nclass HtmlTag {\n constructor(is_svg = false) {\n this.is_svg = false;\n this.is_svg = is_svg;\n this.e = this.n = null;\n }\n c(html) {\n this.h(html);\n }\n m(html, target, anchor = null) {\n if (!this.e) {\n if (this.is_svg)\n this.e = svg_element(target.nodeName);\n /** #7364 target for