"use strict";var Ni=Object.create;var we=Object.defineProperty;var xi=Object.getOwnPropertyDescriptor;var Di=Object.getOwnPropertyNames;var Oi=Object.getPrototypeOf,Bi=Object.prototype.hasOwnProperty;var b=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),Fi=(i,e)=>{for(var t in e)we(i,t,{get:e[t],enumerable:!0})},vt=(i,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Di(e))!Bi.call(i,n)&&n!==t&&we(i,n,{get:()=>e[n],enumerable:!(s=xi(e,n))||s.enumerable});return i};var Tt=(i,e,t)=>(t=i!=null?Ni(Oi(i)):{},vt(e||!i||!i.__esModule?we(t,"default",{value:i,enumerable:!0}):t,i)),qi=i=>vt(we({},"__esModule",{value:!0}),i);var Z=b((ra,Pt)=>{"use strict";var Mi="2.0.0",Vi=Number.MAX_SAFE_INTEGER||9007199254740991,Ui=16,_i=250,Gi=["major","premajor","minor","preminor","patch","prepatch","prerelease"];Pt.exports={MAX_LENGTH:256,MAX_SAFE_COMPONENT_LENGTH:Ui,MAX_SAFE_BUILD_LENGTH:_i,MAX_SAFE_INTEGER:Vi,RELEASE_TYPES:Gi,SEMVER_SPEC_VERSION:Mi,FLAG_INCLUDE_PRERELEASE:1,FLAG_LOOSE:2}});var re=b((oa,yt)=>{"use strict";var ji=typeof process=="object"&&process.env&&process.env.NODE_DEBUG&&/\bsemver\b/i.test(process.env.NODE_DEBUG)?(...i)=>console.error("SEMVER",...i):()=>{};yt.exports=ji});var J=b((V,Et)=>{"use strict";var{MAX_SAFE_COMPONENT_LENGTH:ze,MAX_SAFE_BUILD_LENGTH:Hi,MAX_LENGTH:zi}=Z(),Yi=re();V=Et.exports={};var Xi=V.re=[],Wi=V.safeRe=[],h=V.src=[],Zi=V.safeSrc=[],f=V.t={},Ji=0,Ye="[a-zA-Z0-9-]",Ki=[["\\s",1],["\\d",zi],[Ye,Hi]],Qi=i=>{for(let[e,t]of Ki)i=i.split(`${e}*`).join(`${e}{0,${t}}`).split(`${e}+`).join(`${e}{1,${t}}`);return i},v=(i,e,t)=>{let s=Qi(e),n=Ji++;Yi(i,n,e),f[i]=n,h[n]=e,Zi[n]=s,Xi[n]=new RegExp(e,t?"g":void 0),Wi[n]=new RegExp(s,t?"g":void 0)};v("NUMERICIDENTIFIER","0|[1-9]\\d*");v("NUMERICIDENTIFIERLOOSE","\\d+");v("NONNUMERICIDENTIFIER",`\\d*[a-zA-Z-]${Ye}*`);v("MAINVERSION",`(${h[f.NUMERICIDENTIFIER]})\\.(${h[f.NUMERICIDENTIFIER]})\\.(${h[f.NUMERICIDENTIFIER]})`);v("MAINVERSIONLOOSE",`(${h[f.NUMERICIDENTIFIERLOOSE]})\\.(${h[f.NUMERICIDENTIFIERLOOSE]})\\.(${h[f.NUMERICIDENTIFIERLOOSE]})`);v("PRERELEASEIDENTIFIER",`(?:${h[f.NONNUMERICIDENTIFIER]}|${h[f.NUMERICIDENTIFIER]})`);v("PRERELEASEIDENTIFIERLOOSE",`(?:${h[f.NONNUMERICIDENTIFIER]}|${h[f.NUMERICIDENTIFIERLOOSE]})`);v("PRERELEASE",`(?:-(${h[f.PRERELEASEIDENTIFIER]}(?:\\.${h[f.PRERELEASEIDENTIFIER]})*))`);v("PRERELEASELOOSE",`(?:-?(${h[f.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${h[f.PRERELEASEIDENTIFIERLOOSE]})*))`);v("BUILDIDENTIFIER",`${Ye}+`);v("BUILD",`(?:\\+(${h[f.BUILDIDENTIFIER]}(?:\\.${h[f.BUILDIDENTIFIER]})*))`);v("FULLPLAIN",`v?${h[f.MAINVERSION]}${h[f.PRERELEASE]}?${h[f.BUILD]}?`);v("FULL",`^${h[f.FULLPLAIN]}$`);v("LOOSEPLAIN",`[v=\\s]*${h[f.MAINVERSIONLOOSE]}${h[f.PRERELEASELOOSE]}?${h[f.BUILD]}?`);v("LOOSE",`^${h[f.LOOSEPLAIN]}$`);v("GTLT","((?:<|>)?=?)");v("XRANGEIDENTIFIERLOOSE",`${h[f.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);v("XRANGEIDENTIFIER",`${h[f.NUMERICIDENTIFIER]}|x|X|\\*`);v("XRANGEPLAIN",`[v=\\s]*(${h[f.XRANGEIDENTIFIER]})(?:\\.(${h[f.XRANGEIDENTIFIER]})(?:\\.(${h[f.XRANGEIDENTIFIER]})(?:${h[f.PRERELEASE]})?${h[f.BUILD]}?)?)?`);v("XRANGEPLAINLOOSE",`[v=\\s]*(${h[f.XRANGEIDENTIFIERLOOSE]})(?:\\.(${h[f.XRANGEIDENTIFIERLOOSE]})(?:\\.(${h[f.XRANGEIDENTIFIERLOOSE]})(?:${h[f.PRERELEASELOOSE]})?${h[f.BUILD]}?)?)?`);v("XRANGE",`^${h[f.GTLT]}\\s*${h[f.XRANGEPLAIN]}$`);v("XRANGELOOSE",`^${h[f.GTLT]}\\s*${h[f.XRANGEPLAINLOOSE]}$`);v("COERCEPLAIN",`(^|[^\\d])(\\d{1,${ze}})(?:\\.(\\d{1,${ze}}))?(?:\\.(\\d{1,${ze}}))?`);v("COERCE",`${h[f.COERCEPLAIN]}(?:$|[^\\d])`);v("COERCEFULL",h[f.COERCEPLAIN]+`(?:${h[f.PRERELEASE]})?(?:${h[f.BUILD]})?(?:$|[^\\d])`);v("COERCERTL",h[f.COERCE],!0);v("COERCERTLFULL",h[f.COERCEFULL],!0);v("LONETILDE","(?:~>?)");v("TILDETRIM",`(\\s*)${h[f.LONETILDE]}\\s+`,!0);V.tildeTrimReplace="$1~";v("TILDE",`^${h[f.LONETILDE]}${h[f.XRANGEPLAIN]}$`);v("TILDELOOSE",`^${h[f.LONETILDE]}${h[f.XRANGEPLAINLOOSE]}$`);v("LONECARET","(?:\\^)");v("CARETTRIM",`(\\s*)${h[f.LONECARET]}\\s+`,!0);V.caretTrimReplace="$1^";v("CARET",`^${h[f.LONECARET]}${h[f.XRANGEPLAIN]}$`);v("CARETLOOSE",`^${h[f.LONECARET]}${h[f.XRANGEPLAINLOOSE]}$`);v("COMPARATORLOOSE",`^${h[f.GTLT]}\\s*(${h[f.LOOSEPLAIN]})$|^$`);v("COMPARATOR",`^${h[f.GTLT]}\\s*(${h[f.FULLPLAIN]})$|^$`);v("COMPARATORTRIM",`(\\s*)${h[f.GTLT]}\\s*(${h[f.LOOSEPLAIN]}|${h[f.XRANGEPLAIN]})`,!0);V.comparatorTrimReplace="$1$2$3";v("HYPHENRANGE",`^\\s*(${h[f.XRANGEPLAIN]})\\s+-\\s+(${h[f.XRANGEPLAIN]})\\s*$`);v("HYPHENRANGELOOSE",`^\\s*(${h[f.XRANGEPLAINLOOSE]})\\s+-\\s+(${h[f.XRANGEPLAINLOOSE]})\\s*$`);v("STAR","(<|>)?=?\\s*\\*");v("GTE0","^\\s*>=\\s*0\\.0\\.0\\s*$");v("GTE0PRE","^\\s*>=\\s*0\\.0\\.0-0\\s*$")});var ve=b((aa,Rt)=>{"use strict";var en=Object.freeze({loose:!0}),tn=Object.freeze({}),sn=i=>i?typeof i!="object"?en:i:tn;Rt.exports=sn});var Xe=b((la,At)=>{"use strict";var $t=/^[0-9]+$/,It=(i,e)=>{if(typeof i=="number"&&typeof e=="number")return i===e?0:iIt(e,i);At.exports={compareIdentifiers:It,rcompareIdentifiers:nn}});var A=b((ua,St)=>{"use strict";var Te=re(),{MAX_LENGTH:Ct,MAX_SAFE_INTEGER:Pe}=Z(),{safeRe:ye,t:Ee}=J(),rn=ve(),{compareIdentifiers:We}=Xe(),Ze=class i{constructor(e,t){if(t=rn(t),e instanceof i){if(e.loose===!!t.loose&&e.includePrerelease===!!t.includePrerelease)return e;e=e.version}else if(typeof e!="string")throw new TypeError(`Invalid version. Must be a string. Got type "${typeof e}".`);if(e.length>Ct)throw new TypeError(`version is longer than ${Ct} characters`);Te("SemVer",e,t),this.options=t,this.loose=!!t.loose,this.includePrerelease=!!t.includePrerelease;let s=e.trim().match(t.loose?ye[Ee.LOOSE]:ye[Ee.FULL]);if(!s)throw new TypeError(`Invalid Version: ${e}`);if(this.raw=e,this.major=+s[1],this.minor=+s[2],this.patch=+s[3],this.major>Pe||this.major<0)throw new TypeError("Invalid major version");if(this.minor>Pe||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>Pe||this.patch<0)throw new TypeError("Invalid patch version");s[4]?this.prerelease=s[4].split(".").map(n=>{if(/^[0-9]+$/.test(n)){let r=+n;if(r>=0&&re.major?1:this.minore.minor?1:this.patche.patch?1:0}comparePre(e){if(e instanceof i||(e=new i(e,this.options)),this.prerelease.length&&!e.prerelease.length)return-1;if(!this.prerelease.length&&e.prerelease.length)return 1;if(!this.prerelease.length&&!e.prerelease.length)return 0;let t=0;do{let s=this.prerelease[t],n=e.prerelease[t];if(Te("prerelease compare",t,s,n),s===void 0&&n===void 0)return 0;if(n===void 0)return 1;if(s===void 0)return-1;if(s===n)continue;return We(s,n)}while(++t)}compareBuild(e){e instanceof i||(e=new i(e,this.options));let t=0;do{let s=this.build[t],n=e.build[t];if(Te("build compare",t,s,n),s===void 0&&n===void 0)return 0;if(n===void 0)return 1;if(s===void 0)return-1;if(s===n)continue;return We(s,n)}while(++t)}inc(e,t,s){if(e.startsWith("pre")){if(!t&&s===!1)throw new Error("invalid increment argument: identifier is empty");if(t){let n=`-${t}`.match(this.options.loose?ye[Ee.PRERELEASELOOSE]:ye[Ee.PRERELEASE]);if(!n||n[1]!==t)throw new Error(`invalid identifier: ${t}`)}}switch(e){case"premajor":this.prerelease.length=0,this.patch=0,this.minor=0,this.major++,this.inc("pre",t,s);break;case"preminor":this.prerelease.length=0,this.patch=0,this.minor++,this.inc("pre",t,s);break;case"prepatch":this.prerelease.length=0,this.inc("patch",t,s),this.inc("pre",t,s);break;case"prerelease":this.prerelease.length===0&&this.inc("patch",t,s),this.inc("pre",t,s);break;case"release":if(this.prerelease.length===0)throw new Error(`version ${this.raw} is not a prerelease`);this.prerelease.length=0;break;case"major":(this.minor!==0||this.patch!==0||this.prerelease.length===0)&&this.major++,this.minor=0,this.patch=0,this.prerelease=[];break;case"minor":(this.patch!==0||this.prerelease.length===0)&&this.minor++,this.patch=0,this.prerelease=[];break;case"patch":this.prerelease.length===0&&this.patch++,this.prerelease=[];break;case"pre":{let n=Number(s)?1:0;if(this.prerelease.length===0)this.prerelease=[n];else{let r=this.prerelease.length;for(;--r>=0;)typeof this.prerelease[r]=="number"&&(this.prerelease[r]++,r=-2);if(r===-1){if(t===this.prerelease.join(".")&&s===!1)throw new Error("invalid increment argument: identifier already exists");this.prerelease.push(n)}}if(t){let r=[t,n];s===!1&&(r=[t]),We(this.prerelease[0],t)===0?isNaN(this.prerelease[1])&&(this.prerelease=r):this.prerelease=r}break}default:throw new Error(`invalid increment argument: ${e}`)}return this.raw=this.format(),this.build.length&&(this.raw+=`+${this.build.join(".")}`),this}};St.exports=Ze});var _=b((ca,kt)=>{"use strict";var Lt=A(),on=(i,e,t=!1)=>{if(i instanceof Lt)return i;try{return new Lt(i,e)}catch(s){if(!t)return null;throw s}};kt.exports=on});var xt=b((ga,Nt)=>{"use strict";var an=_(),ln=(i,e)=>{let t=an(i,e);return t?t.version:null};Nt.exports=ln});var Ot=b((pa,Dt)=>{"use strict";var un=_(),cn=(i,e)=>{let t=un(i.trim().replace(/^[=v]+/,""),e);return t?t.version:null};Dt.exports=cn});var qt=b((da,Ft)=>{"use strict";var Bt=A(),gn=(i,e,t,s,n)=>{typeof t=="string"&&(n=s,s=t,t=void 0);try{return new Bt(i instanceof Bt?i.version:i,t).inc(e,s,n).version}catch(r){return null}};Ft.exports=gn});var Ut=b((ma,Vt)=>{"use strict";var Mt=_(),pn=(i,e)=>{let t=Mt(i,null,!0),s=Mt(e,null,!0),n=t.compare(s);if(n===0)return null;let r=n>0,o=r?t:s,u=r?s:t,l=!!o.prerelease.length;if(!!u.prerelease.length&&!l){if(!u.patch&&!u.minor)return"major";if(u.compareMain(o)===0)return u.minor&&!u.patch?"minor":"patch"}let d=l?"pre":"";return t.major!==s.major?d+"major":t.minor!==s.minor?d+"minor":t.patch!==s.patch?d+"patch":"prerelease"};Vt.exports=pn});var Gt=b((ha,_t)=>{"use strict";var dn=A(),mn=(i,e)=>new dn(i,e).major;_t.exports=mn});var Ht=b((fa,jt)=>{"use strict";var hn=A(),fn=(i,e)=>new hn(i,e).minor;jt.exports=fn});var Yt=b((ba,zt)=>{"use strict";var bn=A(),wn=(i,e)=>new bn(i,e).patch;zt.exports=wn});var Wt=b((wa,Xt)=>{"use strict";var vn=_(),Tn=(i,e)=>{let t=vn(i,e);return t&&t.prerelease.length?t.prerelease:null};Xt.exports=Tn});var O=b((va,Jt)=>{"use strict";var Zt=A(),Pn=(i,e,t)=>new Zt(i,t).compare(new Zt(e,t));Jt.exports=Pn});var Qt=b((Ta,Kt)=>{"use strict";var yn=O(),En=(i,e,t)=>yn(e,i,t);Kt.exports=En});var ts=b((Pa,es)=>{"use strict";var Rn=O(),$n=(i,e)=>Rn(i,e,!0);es.exports=$n});var Re=b((ya,is)=>{"use strict";var ss=A(),In=(i,e,t)=>{let s=new ss(i,t),n=new ss(e,t);return s.compare(n)||s.compareBuild(n)};is.exports=In});var rs=b((Ea,ns)=>{"use strict";var An=Re(),Cn=(i,e)=>i.sort((t,s)=>An(t,s,e));ns.exports=Cn});var as=b((Ra,os)=>{"use strict";var Sn=Re(),Ln=(i,e)=>i.sort((t,s)=>Sn(s,t,e));os.exports=Ln});var oe=b(($a,ls)=>{"use strict";var kn=O(),Nn=(i,e,t)=>kn(i,e,t)>0;ls.exports=Nn});var $e=b((Ia,us)=>{"use strict";var xn=O(),Dn=(i,e,t)=>xn(i,e,t)<0;us.exports=Dn});var Je=b((Aa,cs)=>{"use strict";var On=O(),Bn=(i,e,t)=>On(i,e,t)===0;cs.exports=Bn});var Ke=b((Ca,gs)=>{"use strict";var Fn=O(),qn=(i,e,t)=>Fn(i,e,t)!==0;gs.exports=qn});var Ie=b((Sa,ps)=>{"use strict";var Mn=O(),Vn=(i,e,t)=>Mn(i,e,t)>=0;ps.exports=Vn});var Ae=b((La,ds)=>{"use strict";var Un=O(),_n=(i,e,t)=>Un(i,e,t)<=0;ds.exports=_n});var Qe=b((ka,ms)=>{"use strict";var Gn=Je(),jn=Ke(),Hn=oe(),zn=Ie(),Yn=$e(),Xn=Ae(),Wn=(i,e,t,s)=>{switch(e){case"===":return typeof i=="object"&&(i=i.version),typeof t=="object"&&(t=t.version),i===t;case"!==":return typeof i=="object"&&(i=i.version),typeof t=="object"&&(t=t.version),i!==t;case"":case"=":case"==":return Gn(i,t,s);case"!=":return jn(i,t,s);case">":return Hn(i,t,s);case">=":return zn(i,t,s);case"<":return Yn(i,t,s);case"<=":return Xn(i,t,s);default:throw new TypeError(`Invalid operator: ${e}`)}};ms.exports=Wn});var et=b((Na,hs)=>{"use strict";var Zn=A(),Jn=_(),{safeRe:Ce,t:Se}=J(),Kn=(i,e)=>{if(i instanceof Zn)return i;if(typeof i=="number"&&(i=String(i)),typeof i!="string")return null;e=e||{};let t=null;if(!e.rtl)t=i.match(e.includePrerelease?Ce[Se.COERCEFULL]:Ce[Se.COERCE]);else{let l=e.includePrerelease?Ce[Se.COERCERTLFULL]:Ce[Se.COERCERTL],g;for(;(g=l.exec(i))&&(!t||t.index+t[0].length!==i.length);)(!t||g.index+g[0].length!==t.index+t[0].length)&&(t=g),l.lastIndex=g.index+g[1].length+g[2].length;l.lastIndex=-1}if(t===null)return null;let s=t[2],n=t[3]||"0",r=t[4]||"0",o=e.includePrerelease&&t[5]?`-${t[5]}`:"",u=e.includePrerelease&&t[6]?`+${t[6]}`:"";return Jn(`${s}.${n}.${r}${o}${u}`,e)};hs.exports=Kn});var bs=b((xa,fs)=>{"use strict";var Qn=_(),er=Z(),tr=A(),sr=(i,e,t)=>{if(!er.RELEASE_TYPES.includes(e))return null;let s=ir(i,t);return s&&nr(s,e)},ir=(i,e)=>{let t=i instanceof tr?i.version:i;return Qn(t,e)},nr=(i,e)=>{if(rr(e))return i.version;switch(i.prerelease=[],e){case"major":i.minor=0,i.patch=0;break;case"minor":i.patch=0;break}return i.format()},rr=i=>i.startsWith("pre");fs.exports=sr});var vs=b((Da,ws)=>{"use strict";var tt=class{constructor(){this.max=1e3,this.map=new Map}get(e){let t=this.map.get(e);if(t!==void 0)return this.map.delete(e),this.map.set(e,t),t}delete(e){return this.map.delete(e)}set(e,t){if(!this.delete(e)&&t!==void 0){if(this.map.size>=this.max){let n=this.map.keys().next().value;this.delete(n)}this.map.set(e,t)}return this}};ws.exports=tt});var q=b((Oa,Es)=>{"use strict";var or=/\s+/g,st=class i{constructor(e,t){if(t=lr(t),e instanceof i)return e.loose===!!t.loose&&e.includePrerelease===!!t.includePrerelease?e:new i(e.raw,t);if(e instanceof it)return this.raw=e.value,this.set=[[e]],this.formatted=void 0,this;if(this.options=t,this.loose=!!t.loose,this.includePrerelease=!!t.includePrerelease,this.raw=e.trim().replace(or," "),this.set=this.raw.split("||").map(s=>this.parseRange(s.trim())).filter(s=>s.length),!this.set.length)throw new TypeError(`Invalid SemVer Range: ${this.raw}`);if(this.set.length>1){let s=this.set[0];if(this.set=this.set.filter(n=>!Ps(n[0])),this.set.length===0)this.set=[s];else if(this.set.length>1){for(let n of this.set)if(n.length===1&&br(n[0])){this.set=[n];break}}}this.formatted=void 0}get range(){if(this.formatted===void 0){this.formatted="";for(let e=0;e0&&(this.formatted+="||");let t=this.set[e];for(let s=0;s0&&(this.formatted+=" "),this.formatted+=t[s].toString().trim()}}return this.formatted}format(){return this.range}toString(){return this.range}parseRange(e){e=e.replace(fr,"");let s=((this.options.includePrerelease&&mr)|(this.options.loose&&hr))+":"+e,n=Ts.get(s);if(n)return n;let r=this.options.loose,o=r?S[C.HYPHENRANGELOOSE]:S[C.HYPHENRANGE];e=e.replace(o,Ar(this.options.includePrerelease)),y("hyphen replace",e),e=e.replace(S[C.COMPARATORTRIM],gr),y("comparator trim",e),e=e.replace(S[C.TILDETRIM],pr),y("tilde trim",e),e=e.replace(S[C.CARETTRIM],dr),y("caret trim",e);let u=e.split(" ").map(a=>wr(a,this.options)).join(" ").split(/\s+/).map(a=>Ir(a,this.options));r&&(u=u.filter(a=>(y("loose invalid filter",a,this.options),!!a.match(S[C.COMPARATORLOOSE])))),y("range list",u);let l=new Map,g=u.map(a=>new it(a,this.options));for(let a of g){if(Ps(a))return[a];l.set(a.value,a)}l.size>1&&l.has("")&&l.delete("");let d=[...l.values()];return Ts.set(s,d),d}intersects(e,t){if(!(e instanceof i))throw new TypeError("a Range is required");return this.set.some(s=>ys(s,t)&&e.set.some(n=>ys(n,t)&&s.every(r=>n.every(o=>r.intersects(o,t)))))}test(e){if(!e)return!1;if(typeof e=="string")try{e=new ur(e,this.options)}catch(t){return!1}for(let t=0;ti.value==="<0.0.0-0",br=i=>i.value==="",ys=(i,e)=>{let t=!0,s=i.slice(),n=s.pop();for(;t&&s.length;)t=s.every(r=>n.intersects(r,e)),n=s.pop();return t},wr=(i,e)=>(i=i.replace(S[C.BUILD],""),y("comp",i,e),i=Pr(i,e),y("caret",i),i=vr(i,e),y("tildes",i),i=Er(i,e),y("xrange",i),i=$r(i,e),y("stars",i),i),L=i=>!i||i.toLowerCase()==="x"||i==="*",vr=(i,e)=>i.trim().split(/\s+/).map(t=>Tr(t,e)).join(" "),Tr=(i,e)=>{let t=e.loose?S[C.TILDELOOSE]:S[C.TILDE];return i.replace(t,(s,n,r,o,u)=>{y("tilde",i,s,n,r,o,u);let l;return L(n)?l="":L(r)?l=`>=${n}.0.0 <${+n+1}.0.0-0`:L(o)?l=`>=${n}.${r}.0 <${n}.${+r+1}.0-0`:u?(y("replaceTilde pr",u),l=`>=${n}.${r}.${o}-${u} <${n}.${+r+1}.0-0`):l=`>=${n}.${r}.${o} <${n}.${+r+1}.0-0`,y("tilde return",l),l})},Pr=(i,e)=>i.trim().split(/\s+/).map(t=>yr(t,e)).join(" "),yr=(i,e)=>{y("caret",i,e);let t=e.loose?S[C.CARETLOOSE]:S[C.CARET],s=e.includePrerelease?"-0":"";return i.replace(t,(n,r,o,u,l)=>{y("caret",i,n,r,o,u,l);let g;return L(r)?g="":L(o)?g=`>=${r}.0.0${s} <${+r+1}.0.0-0`:L(u)?r==="0"?g=`>=${r}.${o}.0${s} <${r}.${+o+1}.0-0`:g=`>=${r}.${o}.0${s} <${+r+1}.0.0-0`:l?(y("replaceCaret pr",l),r==="0"?o==="0"?g=`>=${r}.${o}.${u}-${l} <${r}.${o}.${+u+1}-0`:g=`>=${r}.${o}.${u}-${l} <${r}.${+o+1}.0-0`:g=`>=${r}.${o}.${u}-${l} <${+r+1}.0.0-0`):(y("no pr"),r==="0"?o==="0"?g=`>=${r}.${o}.${u}${s} <${r}.${o}.${+u+1}-0`:g=`>=${r}.${o}.${u}${s} <${r}.${+o+1}.0-0`:g=`>=${r}.${o}.${u} <${+r+1}.0.0-0`),y("caret return",g),g})},Er=(i,e)=>(y("replaceXRanges",i,e),i.split(/\s+/).map(t=>Rr(t,e)).join(" ")),Rr=(i,e)=>{i=i.trim();let t=e.loose?S[C.XRANGELOOSE]:S[C.XRANGE];return i.replace(t,(s,n,r,o,u,l)=>{y("xRange",i,s,n,r,o,u,l);let g=L(r),d=g||L(o),a=d||L(u),c=a;return n==="="&&c&&(n=""),l=e.includePrerelease?"-0":"",g?n===">"||n==="<"?s="<0.0.0-0":s="*":n&&c?(d&&(o=0),u=0,n===">"?(n=">=",d?(r=+r+1,o=0,u=0):(o=+o+1,u=0)):n==="<="&&(n="<",d?r=+r+1:o=+o+1),n==="<"&&(l="-0"),s=`${n+r}.${o}.${u}${l}`):d?s=`>=${r}.0.0${l} <${+r+1}.0.0-0`:a&&(s=`>=${r}.${o}.0${l} <${r}.${+o+1}.0-0`),y("xRange return",s),s})},$r=(i,e)=>(y("replaceStars",i,e),i.trim().replace(S[C.STAR],"")),Ir=(i,e)=>(y("replaceGTE0",i,e),i.trim().replace(S[e.includePrerelease?C.GTE0PRE:C.GTE0],"")),Ar=i=>(e,t,s,n,r,o,u,l,g,d,a,c)=>(L(s)?t="":L(n)?t=`>=${s}.0.0${i?"-0":""}`:L(r)?t=`>=${s}.${n}.0${i?"-0":""}`:o?t=`>=${t}`:t=`>=${t}${i?"-0":""}`,L(g)?l="":L(d)?l=`<${+g+1}.0.0-0`:L(a)?l=`<${g}.${+d+1}.0-0`:c?l=`<=${g}.${d}.${a}-${c}`:i?l=`<${g}.${d}.${+a+1}-0`:l=`<=${l}`,`${t} ${l}`.trim()),Cr=(i,e,t)=>{for(let s=0;s0){let n=i[s].semver;if(n.major===e.major&&n.minor===e.minor&&n.patch===e.patch)return!0}return!1}return!0}});var ae=b((Ba,Ss)=>{"use strict";var le=Symbol("SemVer ANY"),ot=class i{static get ANY(){return le}constructor(e,t){if(t=Rs(t),e instanceof i){if(e.loose===!!t.loose)return e;e=e.value}e=e.trim().split(/\s+/).join(" "),rt("comparator",e,t),this.options=t,this.loose=!!t.loose,this.parse(e),this.semver===le?this.value="":this.value=this.operator+this.semver.version,rt("comp",this)}parse(e){let t=this.options.loose?$s[Is.COMPARATORLOOSE]:$s[Is.COMPARATOR],s=e.match(t);if(!s)throw new TypeError(`Invalid comparator: ${e}`);this.operator=s[1]!==void 0?s[1]:"",this.operator==="="&&(this.operator=""),s[2]?this.semver=new As(s[2],this.options.loose):this.semver=le}toString(){return this.value}test(e){if(rt("Comparator.test",e,this.options.loose),this.semver===le||e===le)return!0;if(typeof e=="string")try{e=new As(e,this.options)}catch(t){return!1}return nt(e,this.operator,this.semver,this.options)}intersects(e,t){if(!(e instanceof i))throw new TypeError("a Comparator is required");return this.operator===""?this.value===""?!0:new Cs(e.value,t).test(this.value):e.operator===""?e.value===""?!0:new Cs(this.value,t).test(e.semver):(t=Rs(t),t.includePrerelease&&(this.value==="<0.0.0-0"||e.value==="<0.0.0-0")||!t.includePrerelease&&(this.value.startsWith("<0.0.0")||e.value.startsWith("<0.0.0"))?!1:!!(this.operator.startsWith(">")&&e.operator.startsWith(">")||this.operator.startsWith("<")&&e.operator.startsWith("<")||this.semver.version===e.semver.version&&this.operator.includes("=")&&e.operator.includes("=")||nt(this.semver,"<",e.semver,t)&&this.operator.startsWith(">")&&e.operator.startsWith("<")||nt(this.semver,">",e.semver,t)&&this.operator.startsWith("<")&&e.operator.startsWith(">")))}};Ss.exports=ot;var Rs=ve(),{safeRe:$s,t:Is}=J(),nt=Qe(),rt=re(),As=A(),Cs=q()});var ue=b((Fa,Ls)=>{"use strict";var Sr=q(),Lr=(i,e,t)=>{try{e=new Sr(e,t)}catch(s){return!1}return e.test(i)};Ls.exports=Lr});var Ns=b((qa,ks)=>{"use strict";var kr=q(),Nr=(i,e)=>new kr(i,e).set.map(t=>t.map(s=>s.value).join(" ").trim().split(" "));ks.exports=Nr});var Ds=b((Ma,xs)=>{"use strict";var xr=A(),Dr=q(),Or=(i,e,t)=>{let s=null,n=null,r=null;try{r=new Dr(e,t)}catch(o){return null}return i.forEach(o=>{r.test(o)&&(!s||n.compare(o)===-1)&&(s=o,n=new xr(s,t))}),s};xs.exports=Or});var Bs=b((Va,Os)=>{"use strict";var Br=A(),Fr=q(),qr=(i,e,t)=>{let s=null,n=null,r=null;try{r=new Fr(e,t)}catch(o){return null}return i.forEach(o=>{r.test(o)&&(!s||n.compare(o)===1)&&(s=o,n=new Br(s,t))}),s};Os.exports=qr});var Ms=b((Ua,qs)=>{"use strict";var at=A(),Mr=q(),Fs=oe(),Vr=(i,e)=>{i=new Mr(i,e);let t=new at("0.0.0");if(i.test(t)||(t=new at("0.0.0-0"),i.test(t)))return t;t=null;for(let s=0;s{let u=new at(o.semver.version);switch(o.operator){case">":u.prerelease.length===0?u.patch++:u.prerelease.push(0),u.raw=u.format();case"":case">=":(!r||Fs(u,r))&&(r=u);break;case"<":case"<=":break;default:throw new Error(`Unexpected operation: ${o.operator}`)}}),r&&(!t||Fs(t,r))&&(t=r)}return t&&i.test(t)?t:null};qs.exports=Vr});var Us=b((_a,Vs)=>{"use strict";var Ur=q(),_r=(i,e)=>{try{return new Ur(i,e).range||"*"}catch(t){return null}};Vs.exports=_r});var Le=b((Ga,Hs)=>{"use strict";var Gr=A(),js=ae(),{ANY:jr}=js,Hr=q(),zr=ue(),_s=oe(),Gs=$e(),Yr=Ae(),Xr=Ie(),Wr=(i,e,t,s)=>{i=new Gr(i,s),e=new Hr(e,s);let n,r,o,u,l;switch(t){case">":n=_s,r=Yr,o=Gs,u=">",l=">=";break;case"<":n=Gs,r=Xr,o=_s,u="<",l="<=";break;default:throw new TypeError('Must provide a hilo val of "<" or ">"')}if(zr(i,e,s))return!1;for(let g=0;g{p.semver===jr&&(p=new js(">=0.0.0")),a=a||p,c=c||p,n(p.semver,a.semver,s)?a=p:o(p.semver,c.semver,s)&&(c=p)}),a.operator===u||a.operator===l||(!c.operator||c.operator===u)&&r(i,c.semver))return!1;if(c.operator===l&&o(i,c.semver))return!1}return!0};Hs.exports=Wr});var Ys=b((ja,zs)=>{"use strict";var Zr=Le(),Jr=(i,e,t)=>Zr(i,e,">",t);zs.exports=Jr});var Ws=b((Ha,Xs)=>{"use strict";var Kr=Le(),Qr=(i,e,t)=>Kr(i,e,"<",t);Xs.exports=Qr});var Ks=b((za,Js)=>{"use strict";var Zs=q(),eo=(i,e,t)=>(i=new Zs(i,t),e=new Zs(e,t),i.intersects(e,t));Js.exports=eo});var ei=b((Ya,Qs)=>{"use strict";var to=ue(),so=O();Qs.exports=(i,e,t)=>{let s=[],n=null,r=null,o=i.sort((d,a)=>so(d,a,t));for(let d of o)to(d,e,t)?(r=d,n||(n=d)):(r&&s.push([n,r]),r=null,n=null);n&&s.push([n,null]);let u=[];for(let[d,a]of s)d===a?u.push(d):!a&&d===o[0]?u.push("*"):a?d===o[0]?u.push(`<=${a}`):u.push(`${d} - ${a}`):u.push(`>=${d}`);let l=u.join(" || "),g=typeof e.raw=="string"?e.raw:String(e);return l.length{"use strict";var ti=q(),ct=ae(),{ANY:lt}=ct,ut=ue(),gt=O(),io=(i,e,t={})=>{if(i===e)return!0;i=new ti(i,t),e=new ti(e,t);let s=!1;e:for(let n of i.set){for(let r of e.set){let o=ro(n,r,t);if(s=s||o!==null,o)continue e}if(s)return!1}return!0},no=[new ct(">=0.0.0-0")],si=[new ct(">=0.0.0")],ro=(i,e,t)=>{if(i===e)return!0;if(i.length===1&&i[0].semver===lt){if(e.length===1&&e[0].semver===lt)return!0;t.includePrerelease?i=no:i=si}if(e.length===1&&e[0].semver===lt){if(t.includePrerelease)return!0;e=si}let s=new Set,n,r;for(let p of i)p.operator===">"||p.operator===">="?n=ii(n,p,t):p.operator==="<"||p.operator==="<="?r=ni(r,p,t):s.add(p.semver);if(s.size>1)return null;let o;if(n&&r){if(o=gt(n.semver,r.semver,t),o>0)return null;if(o===0&&(n.operator!==">="||r.operator!=="<="))return null}for(let p of s){if(n&&!ut(p,String(n),t)||r&&!ut(p,String(r),t))return null;for(let m of e)if(!ut(p,String(m),t))return!1;return!0}let u,l,g,d,a=r&&!t.includePrerelease&&r.semver.prerelease.length?r.semver:!1,c=n&&!t.includePrerelease&&n.semver.prerelease.length?n.semver:!1;a&&a.prerelease.length===1&&r.operator==="<"&&a.prerelease[0]===0&&(a=!1);for(let p of e){if(d=d||p.operator===">"||p.operator===">=",g=g||p.operator==="<"||p.operator==="<=",n){if(c&&p.semver.prerelease&&p.semver.prerelease.length&&p.semver.major===c.major&&p.semver.minor===c.minor&&p.semver.patch===c.patch&&(c=!1),p.operator===">"||p.operator===">="){if(u=ii(n,p,t),u===p&&u!==n)return!1}else if(n.operator===">="&&!p.test(n.semver))return!1}if(r){if(a&&p.semver.prerelease&&p.semver.prerelease.length&&p.semver.major===a.major&&p.semver.minor===a.minor&&p.semver.patch===a.patch&&(a=!1),p.operator==="<"||p.operator==="<="){if(l=ni(r,p,t),l===p&&l!==r)return!1}else if(r.operator==="<="&&!p.test(r.semver))return!1}if(!p.operator&&(r||n)&&o!==0)return!1}return!(n&&g&&!r&&o!==0||r&&d&&!n&&o!==0||c||a)},ii=(i,e,t)=>{if(!i)return e;let s=gt(i.semver,e.semver,t);return s>0?i:s<0||e.operator===">"&&i.operator===">="?e:i},ni=(i,e,t)=>{if(!i)return e;let s=gt(i.semver,e.semver,t);return s<0?i:s>0||e.operator==="<"&&i.operator==="<="?e:i};ri.exports=io});var dt=b((Wa,ui)=>{"use strict";var pt=J(),ai=Z(),oo=A(),li=Xe(),ao=_(),lo=xt(),uo=Ot(),co=qt(),go=Ut(),po=Gt(),mo=Ht(),ho=Yt(),fo=Wt(),bo=O(),wo=Qt(),vo=ts(),To=Re(),Po=rs(),yo=as(),Eo=oe(),Ro=$e(),$o=Je(),Io=Ke(),Ao=Ie(),Co=Ae(),So=Qe(),Lo=et(),ko=bs(),No=ae(),xo=q(),Do=ue(),Oo=Ns(),Bo=Ds(),Fo=Bs(),qo=Ms(),Mo=Us(),Vo=Le(),Uo=Ys(),_o=Ws(),Go=Ks(),jo=ei(),Ho=oi();ui.exports={parse:ao,valid:lo,clean:uo,inc:co,diff:go,major:po,minor:mo,patch:ho,prerelease:fo,compare:bo,rcompare:wo,compareLoose:vo,compareBuild:To,sort:Po,rsort:yo,gt:Eo,lt:Ro,eq:$o,neq:Io,gte:Ao,lte:Co,cmp:So,coerce:Lo,truncate:ko,Comparator:No,Range:xo,satisfies:Do,toComparators:Oo,maxSatisfying:Bo,minSatisfying:Fo,minVersion:qo,validRange:Mo,outside:Vo,gtr:Uo,ltr:_o,intersects:Go,simplifyRange:jo,subset:Ho,SemVer:oo,re:pt.re,src:pt.src,tokens:pt.t,SEMVER_SPEC_VERSION:ai.SEMVER_SPEC_VERSION,RELEASE_TYPES:ai.RELEASE_TYPES,compareIdentifiers:li.compareIdentifiers,rcompareIdentifiers:li.rcompareIdentifiers}});var ta={};Fi(ta,{default:()=>Ge});module.exports=qi(ta);var ki=require("obsidian");var F=require("obsidian");var ne=require("obsidian"),je=class extends ne.Modal{constructor(t,s){super(t.app);this.resolve=s;this.isConfirmed=!1;let n={app:t.app,cancelButtonText:"Cancel",cssClass:"",message:t.message,okButtonText:"OK",title:""};this.options={...n,...t},this.containerEl.addClass("confirm-modal")}onClose(){super.onClose(),this.resolve(this.isConfirmed)}onOpen(){super.onOpen(),this.titleEl.setText(this.options.title),this.contentEl.createEl("p",{text:this.options.message});let t=new ne.ButtonComponent(this.contentEl);t.setClass("ok-button"),t.setButtonText(this.options.okButtonText),t.setCta(),t.onClick(()=>{this.isConfirmed=!0,this.close()});let s=new ne.ButtonComponent(this.contentEl);s.setButtonText(this.options.cancelButtonText),s.onClick(this.close.bind(this))}};async function He(i){return await new Promise(e=>{new je(i,e).open()})}var x=class extends Error{constructor(e,t,s,n,r){let o=Math.ceil((s-Math.floor(Date.now()/1e3))/60);super(`${r} API rate limit exceeded. Reset in ${o} minutes.`),this.limit=e,this.remaining=t,this.reset=s,this.requestUrl=n}getMinutesToReset(){return Math.ceil((this.reset-Math.floor(Date.now()/1e3))/60)}},I=class extends Error{constructor(e,t,s={}){super(e),this.status=t,this.statusMessage=e,this.headers=s,this.name="ProviderResponseError"}};var ke=require("obsidian"),ce=Tt(dt());function ci(i){return Object.keys(i).reduce((e,t)=>(e[t.toLowerCase()]=i[t],e),{})}var Ne=class{parseUrl(e){var o,u;let t=e.replace(/https?:\/\//i,"");t.toLowerCase().startsWith("github.com/")&&(t=t.slice(11)),t.toLowerCase().endsWith(".git")&&(t=t.slice(0,-4)),t.endsWith("/")&&(t=t.slice(0,-1));let s=t.split("/"),n=(o=s[0])!=null?o:"",r=(u=s[1])!=null?u:"";return{host:"api.github.com",owner:n,repo:r,apiBaseUrl:"https://api.github.com",rawBaseUrl:"https://raw.githubusercontent.com",isGitHub:!0}}formatRepoUrl(e){return`${e.owner}/${e.repo}`}async getRepoInfo(e,t){var s;try{return{exists:!0,isPrivate:(s=(await this.apiRequest({url:`${e.apiBaseUrl}/repos/${e.owner}/${e.repo}`,headers:t?{Authorization:`Token ${t}`}:{}})).json.private)!=null?s:!1}}catch(n){if(n instanceof I&&n.status===404)return{exists:!1,isPrivate:!1};throw n}}async listReleases(e,t){try{return(await this.apiRequest({url:`${e.apiBaseUrl}/repos/${e.owner}/${e.repo}/releases?per_page=100`,headers:t?{Authorization:`Token ${t}`}:{}})).json.map(r=>({version:r.tag_name,prerelease:r.prerelease}))}catch(s){if(s instanceof x||s instanceof I)throw s;return null}}async getRelease(e,t,s=!1,n){var r;try{let o=t&&t!=="latest"?`${e.apiBaseUrl}/repos/${e.owner}/${e.repo}/releases/tags/${t}`:`${e.apiBaseUrl}/repos/${e.owner}/${e.repo}/releases`,u={Accept:"application/vnd.github.v3+json"};n&&(u.Authorization=`Token ${n}`);let l=await this.apiRequest({url:o,headers:u});return l.status===404?null:(r=(t&&t!=="latest"?[this.normalizeRelease(l.json)]:l.json.map(a=>this.normalizeRelease(a))).sort((a,c)=>{try{let p=(0,ce.coerce)(a.tag_name,{includePrerelease:!0,loose:!0}),m=(0,ce.coerce)(c.tag_name,{includePrerelease:!0,loose:!0});return p&&m?(0,ce.compare)(m.version,p.version):0}catch(p){return new Date(c.published_at).getTime()-new Date(a.published_at).getTime()}}).filter(a=>s||!a.prerelease)[0])!=null?r:null}catch(o){if(o instanceof x)throw o;if(o instanceof I){if(o.status===404)return null;throw o}return null}}async getAsset(e,t,s,n){let r=e.assets.find(l=>l.name===t);if(!r)return null;let o={Accept:"application/octet-stream"};s&&n&&(o.Authorization=`Token ${n}`);let u=s?r.url:r.browser_download_url;try{let l=await(0,ke.requestUrl)({url:u,headers:o});return l.status===200?l.text:null}catch(l){return null}}async getRawFile(e,t,s="HEAD",n){let r=`${e.rawBaseUrl}/${e.owner}/${e.repo}/${s}/${t}`;try{let o={};n&&(o.Authorization=`Token ${n}`);let u=await(0,ke.requestUrl)({url:r,headers:o});return u.status===404?null:u.text}catch(o){return null}}async validateToken(e,t){var r,o,u,l;if(!e)return{valid:!1,message:"No token provided"};let s=["ghp_","github_pat_","ghs_"];if(!s.some(g=>e.toLowerCase().startsWith(g)))return{valid:!1,message:`Invalid token format. Valid prefixes: ${s.join(", ")}`,details:{validPrefixes:s.join(", ")}};try{let g=`_brat_validate_${Date.now()%1e4}/_probe_`;return await this.apiRequest({url:`https://api.github.com/repos/${g}`,headers:{Authorization:`Token ${e}`,Accept:"application/vnd.github.v3+json"}}),{valid:!0,message:"Token is valid"}}catch(g){if(g instanceof I){let d=ci(g.headers),a=(o=(r=d["x-oauth-scopes"])==null?void 0:r.split(", "))!=null?o:[],c=d["github-authentication-token-expiration"];if(g.status===404){let p={valid:!0,message:"Token is valid"};return a.length>0&&(p.details={scopes:a.join(", ")}),c&&(p.details={...p.details,expires:c}),p}if(g.status===403){if(parseInt((u=d["x-ratelimit-remaining"])!=null?u:"0",10)===0){let m=parseInt((l=d["x-ratelimit-reset"])!=null?l:"0",10),P=Math.ceil((m-Math.floor(Date.now()/1e3))/60);return{valid:!1,message:`GitHub API rate limit exceeded. Reset in ${P} minutes.`,details:{resetInMinutes:String(P)}}}return{valid:!1,message:"Token lacks required permissions (repo scope needed)",details:{requiredScopes:"repo, public_repo"}}}return{valid:!1,message:`GitHub API error: ${g.status} ${g.statusMessage}`}}return{valid:!1,message:`Token validation failed: ${g}`}}}normalizeRelease(e){var t,s,n;return{url:e.url,tag_name:e.tag_name,name:(t=e.name)!=null?t:e.tag_name,published_at:e.published_at,prerelease:(s=e.prerelease)!=null?s:!1,assets:((n=e.assets)!=null?n:[]).map(r=>({name:r.name,url:r.url,browser_download_url:r.browser_download_url}))}}async apiRequest(e){var t,s,n,r,o,u;e.headers={...e.headers,"User-Agent":"Obsidian/BRAT-Gitea-Plugin"};try{return await(0,ke.requestUrl)(e)}catch(l){let g=l,d=(t=g.status)!=null?t:400,a=ci((s=g.headers)!=null?s:{});if(d===403){let c=parseInt((n=a["x-ratelimit-remaining"])!=null?n:"0",10);if(c===0){let p=parseInt((r=a["x-ratelimit-limit"])!=null?r:"0",10),m=parseInt((o=a["x-ratelimit-reset"])!=null?o:"0",10);throw new x(p,c,m,e.url,"GitHub")}}throw new I((u=g.message)!=null?u:"GitHub API error",d,a)}}};var xe=require("obsidian"),ge=Tt(dt());var De=class{constructor(){this.defaultBranch="HEAD"}parseUrl(e){let t=e.trim();/^https?:\/\//i.test(t)||(t=`https://${t}`);let s=new URL(t),n=s.hostname,o=s.pathname.replace(/^\/+/,"").replace(/\/+$/,"").split("/"),u="",l="",g=0;o.length>=2&&(u=o[o.length-2],l=o[o.length-1]),l.toLowerCase().endsWith(".git")&&(l=l.slice(0,-4));let d=s.protocol;return{host:n,owner:u,repo:l,apiBaseUrl:`${d}//${n}/api/v1`,rawBaseUrl:`${d}//${n}`,isGitHub:!1}}formatRepoUrl(e){return`${e.host}/${e.owner}/${e.repo}`}async getRepoInfo(e,t){var s;try{return{exists:!0,isPrivate:(s=(await this.apiRequest({url:`${e.apiBaseUrl}/repos/${e.owner}/${e.repo}`,headers:t?{Authorization:`token ${t}`}:{}})).json.private)!=null?s:!1}}catch(n){if(n instanceof I&&n.status===404)return{exists:!1,isPrivate:!1};throw n}}async listReleases(e,t){try{return(await this.apiRequest({url:`${e.apiBaseUrl}/repos/${e.owner}/${e.repo}/releases?limit=100`,headers:t?{Authorization:`token ${t}`}:{}})).json.map(r=>{var o;return{version:r.tag_name,prerelease:(o=r.prerelease)!=null?o:!1}})}catch(s){if(s instanceof x||s instanceof I)throw s;return null}}async getRelease(e,t,s=!1,n){var r;try{let o=t&&t!=="latest"?`${e.apiBaseUrl}/repos/${e.owner}/${e.repo}/releases/tags/${t}`:`${e.apiBaseUrl}/repos/${e.owner}/${e.repo}/releases`,u={};n&&(u.Authorization=`token ${n}`);let l=await this.apiRequest({url:o,headers:u});return l.status===404?null:(r=(t&&t!=="latest"?[this.normalizeRelease(l.json)]:l.json.map(a=>this.normalizeRelease(a))).sort((a,c)=>{try{let p=(0,ge.coerce)(a.tag_name,{includePrerelease:!0,loose:!0}),m=(0,ge.coerce)(c.tag_name,{includePrerelease:!0,loose:!0});return p&&m?(0,ge.compare)(m.version,p.version):0}catch(p){return new Date(c.published_at).getTime()-new Date(a.published_at).getTime()}}).filter(a=>s||!a.prerelease)[0])!=null?r:null}catch(o){if(o instanceof x)throw o;if(o instanceof I){if(o.status===404)return null;throw o}return null}}async getAsset(e,t,s,n){let r=e.assets.find(l=>l.name===t);if(!r)return null;let o={Accept:"application/octet-stream"};n&&(o.Authorization=`token ${n}`);let u=s?r.url:r.browser_download_url;try{let l=await(0,xe.requestUrl)({url:u,headers:o});return l.status===200?l.text:null}catch(l){return null}}async getRawFile(e,t,s,n){let r=s!=null?s:this.defaultBranch,o=`${e.rawBaseUrl}/${e.owner}/${e.repo}/raw/${r}/${t}`;try{let u={};n&&(u.Authorization=`token ${n}`);let l=await(0,xe.requestUrl)({url:o,headers:u});return l.status===404?null:l.text}catch(u){return null}}async validateToken(e,t){var s;if(!e)return{valid:!1,message:"No token provided"};try{return t&&t.owner&&t.repo?(await this.apiRequest({url:`${t.apiBaseUrl}/repos/${t.owner}/${t.repo}`,headers:{Authorization:`token ${e}`}}),{valid:!0,message:"Token is valid"}):(await this.apiRequest({url:`${(s=t==null?void 0:t.apiBaseUrl)!=null?s:"https://localhost/api/v1"}/user`,headers:{Authorization:`token ${e}`}})).status===200?{valid:!0,message:"Token is valid"}:{valid:!1,message:"Token validation failed"}}catch(n){return n instanceof I?n.status===401||n.status===403?{valid:!1,message:`Token rejected: ${n.statusMessage}`}:n.status===404?{valid:!0,message:"Token is valid (no specific repo access checked)"}:{valid:!1,message:`API error: ${n.status} ${n.statusMessage}`}:{valid:!1,message:`Token validation failed: ${n}`}}}normalizeRelease(e){var t,s,n,r;return{url:e.url,tag_name:e.tag_name,name:(t=e.name)!=null?t:e.tag_name,published_at:(s=e.published_at)!=null?s:e.created_at,prerelease:(n=e.prerelease)!=null?n:!1,assets:((r=e.assets)!=null?r:[]).map(o=>({name:o.name,url:o.url,browser_download_url:o.browser_download_url}))}}async apiRequest(e){var t,s,n,r,o;e.headers={...e.headers,"User-Agent":"Obsidian/BRAT-Gitea-Plugin"};try{return await(0,xe.requestUrl)(e)}catch(u){let l=u,g=(t=l.status)!=null?t:400,d=(s=l.message)!=null?s:"API error",a={};if(l.headers)for(let[p,m]of Object.entries(l.headers))a[p.toLowerCase()]=String(m);let c=parseInt((n=a["x-ratelimit-remaining"])!=null?n:"",10);if(g===403&&!isNaN(c)&&c===0){let p=parseInt((r=a["x-ratelimit-limit"])!=null?r:"0",10),m=parseInt((o=a["x-ratelimit-reset"])!=null?o:"0",10);throw new x(p,c,m,e.url,"Gitea")}throw new I(d,g,a)}}};var mt=null,ht=null;function gi(){return mt||(mt=new Ne),mt}function zo(){return ht||(ht=new De),ht}function K(i){let e=i.trim();return/^[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+$/.test(e)||/github\.com/i.test(e)?gi():zo()}function z(i){let e=K(i),t=e.parseUrl(i);return{provider:e,parsed:t}}function Yo(i){let e=0;for(let t=0;tYo(i).toString(),ft={pluginList:[],pluginSubListFrozenVersion:[],themesList:[],updateAtStartup:!0,updateThemesAtStartup:!0,enableAfterInstall:!0,loggingEnabled:!1,loggingPath:"BRAT-log",loggingVerboseEnabled:!1,debuggingMode:!1,notificationsEnabled:!0,globalTokenName:"",personalAccessToken:"",selectLatestPluginVersionByDefault:!1,allowIncompatiblePlugins:!1};function pi(i,e,t="latest",s=!1,n="",r=""){let o=!1;i.settings.pluginList.contains(e)||(i.settings.pluginList.unshift(e),o=!0);let u=i.settings.pluginSubListFrozenVersion.find(l=>l.repo===e);u?(Object.assign(u,{repo:e,version:t,token:void 0,tokenName:n||u.tokenName,isIncompatible:s||void 0,giteaUrl:r||u.giteaUrl}),o=!0):(i.settings.pluginSubListFrozenVersion.unshift({repo:e,version:t,token:void 0,tokenName:n||void 0,isIncompatible:s||void 0,giteaUrl:r||void 0}),o=!0),o&&i.saveSettings()}function Oe(i,e){return i.settings.pluginList.contains(e)}function di(i,e,t){let s={repo:e,lastUpdate:Xo(t)};i.settings.themesList.unshift(s),i.saveSettings()}function mi(i,e){return!!i.settings.themesList.find(s=>s.repo===e)}function bt(i,e,t){let s=i.settings.pluginSubListFrozenVersion.find(n=>n.repo===e);s&&(s.tokenName=t||void 0,i.saveSettings())}function hi(i,e,t){for(let s of i.settings.themesList)s.repo===e&&(s.lastUpdate=t,i.saveSettings())}var B=require("obsidian");var Q=class{constructor(e){this.statusEl=e}async validateToken(e,t){if(!e)return this.updateStatus("No token provided",!1),!1;try{let s=t?K(t):K("github.com/test/test"),n=t?s.parseUrl(t):void 0,r=await s.validateToken(e,n);return r.valid?(this.showValidInfo(r),!0):(this.showError(r),!1)}catch(s){return console.error("Token validation error:",s),this.updateStatus("Failed to validate token",!1),!1}}updateStatus(e,t){this.statusEl&&(this.statusEl.empty(),this.statusEl.removeClass("valid","invalid"),this.statusEl.addClass(t?"valid":"invalid"),this.statusEl.setText(e))}showValidInfo(e){var s,n;if(!this.statusEl)return;this.statusEl.empty(),this.statusEl.removeClass("invalid"),this.statusEl.addClass("valid");let t=this.statusEl.createDiv({cls:"brat-token-details"});if(t.createDiv({text:"\u2713 Valid token",cls:"brat-token-status valid"}),(s=e.details)!=null&&s.scopes&&t.createDiv({text:`Scopes: ${e.details.scopes}`,cls:"brat-token-scopes"}),(n=e.details)!=null&&n.expires){let r=new Date(e.details.expires),o=Math.ceil((r.getTime()-Date.now())/(1e3*60*60*24));o<7&&t.createDiv({text:`\u26A0\uFE0F Token expires in ${o} days`,cls:"brat-token-warning"})}}showError(e){var s,n;if(!this.statusEl)return;this.statusEl.empty(),this.statusEl.removeClass("valid"),this.statusEl.addClass("invalid");let t=this.statusEl.createDiv({cls:"brat-token-error"});t.createDiv({text:`\u2717 ${e.message}`}),(s=e.details)!=null&&s.validPrefixes&&t.createDiv({text:`Valid prefixes: ${e.details.validPrefixes}`}),(n=e.details)!=null&&n.requiredScopes&&t.createDiv({text:`Required scopes: ${e.details.requiredScopes}`})}};function Wo(i,e){let t=new DocumentFragment,s=document.createElement("a");return/^[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+$/.test(i)?(s.textContent=i,s.href=`https://github.com/${i}`):(s.textContent=i,s.href=i.startsWith("http")?i:`https://${i}`),s.target="_blank",t.appendChild(s),e&&t.appendChild(document.createTextNode(e)),t}function fi({prependText:i,url:e,text:t,appendText:s}){let n=new DocumentFragment,r=document.createElement("a");return r.textContent=t,r.href=e,i&&n.appendChild(document.createTextNode(i)),n.appendChild(r),s&&n.appendChild(document.createTextNode(s)),n}var pe=Wo;var Be=require("obsidian");function w(i,e,t=10,s){if(!i.settings.notificationsEnabled)return;let n=s?Be.Platform.isDesktop?"(click=dismiss, right-click=Info)":"(click=dismiss)":"",r=new Be.Notice(`BRAT ${e} ${n}`,t*1e3);s&&(r.noticeEl.oncontextmenu=()=>{s()})}var ee=(i,e=!0)=>{let t=i.createEl("div");t.style.float="right",e?(t.style.padding="15px",t.style.paddingLeft="15px",t.style.paddingRight="15px",t.style.marginLeft="15px"):(t.style.padding="10px",t.style.paddingLeft="15px",t.style.paddingRight="15px");let s=t.createDiv("coffee");s.addClass("ex-twitter-span"),s.style.paddingLeft="10px";let n=s.createDiv();n.innerText="Learn more about my work at:",s.appendChild(n);let r=s.createEl("a",{href:"https://tfthacker.com"});return r.innerText="https://tfthacker.com",t};var bi=require("obsidian"),Fe=class extends bi.SuggestModal{constructor(e,t,s,n,r){super(e),this.versions=s,this.selected=n,this.onChoose=r,this.setTitle("Select a version"),this.setPlaceholder(`Type to search for a version for ${t}`),this.setInstructions([{command:"\u2191\u2193",purpose:"Navigate versions"},{command:"\u21B5",purpose:"Select version"},{command:"esc",purpose:"Dismiss modal"}])}getSuggestions(e){let t=e.toLowerCase();return this.versions.filter(s=>s.version.toLowerCase().contains(t))}renderSuggestion(e,t){t.createEl("div",{text:`${e.version} ${e.prerelease?"(Prerelease)":""}`})}onChooseSuggestion(e){this.onChoose(e.version)}onNoSuggestion(){this.onChoose(this.selected?this.selected:""),this.close()}};var Y=class extends B.Modal{constructor(t,s,n=!1,r=!1,o="",u="",l=""){super(t.app);this.versionSetting=null;this.repositoryAddressEl=null;this.tokenInputEl=null;this.validateButton=null;this.validator=null;this.addPluginButton=null;this.cancelButton=null;this.plugin=t,this.betaPlugins=s,this.address=o,this.version=u,this.secretName=l,this.openSettingsTabAfterwards=n,this.updateVersion=r,this.enableAfterInstall=t.settings.enableAfterInstall,this.giteaInstanceUrl=""}async submitForm(){if(this.address==="")return;let t=this.scrubAddress(this.address);if(this.plugin.settings.pluginSubListFrozenVersion.find(r=>r.repo===t)){await this.betaPlugins.addPlugin(t,!1,!1,!1,this.version,!0,this.enableAfterInstall,this.secretName)&&this.close(),this.resetButtons();return}if(!this.version&&Oe(this.plugin,t)){w(this.plugin,"This plugin is already in the list for beta testing",10);return}await this.betaPlugins.addPlugin(t,!1,!1,!1,this.version,!1,this.enableAfterInstall,this.secretName)&&this.close(),this.resetButtons()}resetButtons(){var t,s,n,r;(t=this.cancelButton)==null||t.setDisabled(!1),(s=this.addPluginButton)==null||s.setDisabled(!1),(n=this.addPluginButton)==null||n.setButtonText("Add Plugin"),(r=this.versionSetting)==null||r.setDisabled(!1)}updateVersionDropdown(t,s,n=""){let r;t.clear(),s.length>0&&!n&&this.plugin.settings.selectLatestPluginVersionByDefault?(r="latest",this.version="latest"):r=n,s.length<20||B.Platform.isMobile?t.addDropdown(u=>{u.addOption("","Select a version"),u.addOption("latest","Latest version");for(let l of s)u.addOption(l.version,`${l.version} ${l.prerelease?"(Prerelease)":""}`);u.onChange(l=>{var g;this.version=l,(g=this.addPluginButton)==null||g.setDisabled(this.version==="")}),u.setValue(r),u.selectEl.addClass("brat-version-selector"),u.selectEl.style.width="100%"}):t.addButton(u=>{u.setButtonText(r==="latest"?"Latest version":r||"Select a version...").setClass("brat-version-selector").setClass("button").onClick(()=>{let g=[{version:"latest",prerelease:!1},...s];new Fe(this.app,this.address,g,r,a=>{var c;this.version=a,u.setButtonText(a==="latest"?"Latest version":a||"Select a version..."),(c=this.addPluginButton)==null||c.setDisabled(this.version==="")}).open()})})}scrubAddress(t){let s=t.trim();return/^[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+$/.test(s)?s:/github\.com/i.test(s)?s.replace(/https?:\/\/github\.com\//i,"").replace(/\.git$/i,"").replace(/\/$/,""):s.replace(/\.git$/i,"").replace(/\/$/,"")}isValidRepository(t){let s=t.trim().replace(/\.git$/i,""),n=/^(?:https?:\/\/github\.com\/)?([a-zA-Z0-9._-]+)\/([a-zA-Z0-9._-]+)$/i,r=/^https?:\/\/[a-zA-Z0-9.-]+\/[a-zA-Z0-9._-]+\/[a-zA-Z0-9._-]+$/i;return n.test(s)||r.test(s)}onOpen(){let t=this.contentEl.createEl("h4");this.address?(t.appendText("Change plugin version: "),t.appendChild(pe(this.address))):t.setText("Repository for beta plugin:"),this.contentEl.createEl("form",{},s=>{s.addClass("brat-modal"),(!this.address||!this.updateVersion)&&new B.Setting(s).setClass("repository-setting").then(d=>{d.addText(a=>{this.repositoryAddressEl=a,a.setPlaceholder(`Repository URL or path GitHub: GitHubUserName/repo (or full URL) Gitea: https://git.example.com/user/repo`),a.setValue(this.address),a.onChange(c=>{var p,m;this.address=this.scrubAddress(c.trim()),this.version!==""&&(!this.address||!this.isValidRepository(this.address))&&this.versionSetting&&(this.updateVersionDropdown(this.versionSetting,[]),this.versionSetting.settingEl.classList.add("disabled-setting"),this.versionSetting.setDisabled(!0),a.inputEl.classList.remove("valid-repository"),a.inputEl.classList.remove("invalid-repository")),this.version||(this.isValidRepository(this.address)?(p=this.addPluginButton)==null||p.setDisabled(!1):(m=this.addPluginButton)==null||m.setDisabled(!0))}),a.inputEl.addEventListener("keydown",async c=>{c.key==="Enter"&&(this.address&&(this.updateVersion&&this.version!==""||!this.updateVersion)&&(c.preventDefault(),this.disableForm(),this.submitForm()),await this.updateRepositoryVersionInfo(this.version,n))}),a.inputEl.addEventListener("blur",async()=>{await this.updateRepositoryVersionInfo(this.version,n)}),d.setDesc("Repository"),a.inputEl.style.width="100%"})});let n=s.createDiv("validation-status");this.address||n.setText(`Enter a repository address to validate it. Supports GitHub and Gitea.`),this.versionSetting=new B.Setting(s).setClass("version-setting").setClass("disabled-setting"),this.updateVersionDropdown(this.versionSetting,[],this.version),this.versionSetting.setDisabled(!0);let r=s.createDiv("token-setting");if(new B.Setting(r).setName("Access Token").setDesc("Select a secret as token for this repository (optional)").addComponent(g=>new B.SecretComponent(this.plugin.app,g).setValue(this.secretName).onChange(async d=>{var c,p,m,P,R;if(this.secretName=(d==null?void 0:d.trim())||"",!this.secretName){this.address&&Oe(this.plugin,this.address)&&(bt(this.plugin,this.address,""),w(this.plugin,`Token setting cleared for ${this.address}`,3)),this.updateRepositoryVersionInfo(this.version,n);return}let a=this.secretName?this.plugin.app.secretStorage.getSecret(this.secretName):null;a&&(this.validToken=await((c=this.validator)==null?void 0:c.validateToken(a,this.address)),this.validToken?((P=this.validateButton)==null||P.setButtonText("Valid"),(R=this.validateButton)==null||R.setDisabled(!0),this.address&&(await this.updateRepositoryVersionInfo(this.version,n),Oe(this.plugin,this.address)&&(bt(this.plugin,this.address,this.secretName),w(this.plugin,`Token setting updated for ${this.address}`,3)))):((p=this.validateButton)==null||p.setButtonText("Invalid"),(m=this.validateButton)==null||m.setDisabled(!1)))})),this.validator=new Q,this.secretName){let g=this.plugin.app.secretStorage.getSecret(this.secretName);g&&this.validator.validateToken(g,this.address).then(d=>{var a,c;this.validToken=d,this.validToken&&((a=this.validateButton)==null||a.setButtonText("Valid"),(c=this.validateButton)==null||c.setDisabled(!0))})}s.createDiv("modal-button-container",g=>{var d;g.createEl("label",{cls:"mod-checkbox"},a=>{let c=a.createEl("input",{attr:{tabindex:-1},type:"checkbox"});c.checked=this.enableAfterInstall,c.addEventListener("click",()=>{this.enableAfterInstall=c.checked}),a.appendText("Enable after installing the plugin")}),this.cancelButton=new B.ButtonComponent(g).setButtonText("Never mind").setClass("mod-cancel").onClick(()=>this.close()),this.addPluginButton=new B.ButtonComponent(g).setButtonText(this.updateVersion&&this.address?"Change version":"Add plugin").setCta().onClick(()=>{this.address!==""&&(this.updateVersion&&this.version!==""||!this.updateVersion)&&(this.disableForm(),this.submitForm())}),(this.updateVersion||this.address==="")&&((d=this.addPluginButton)==null||d.setDisabled(!0))});let o=s.createDiv();o.style.borderTop="1px solid var(--background-modifier-border)",o.style.marginTop="30px",o.style.paddingTop="8px";let u=o.createSpan();u.createEl("a",{href:"https://bit.ly/o42-twitter",text:"TFTHacker"}),u.appendText(" and "),u.createEl("a",{href:"https://github.com/johannrichard",text:"johannrichard"}),u.appendText(" \u2014 Gitea fork"),u.style.fontStyle="italic",o.appendChild(u),ee(o,!1);let l=s.querySelectorAll("button");for(let g of Array.from(l))g.setAttribute("type","button");s.addEventListener("submit",g=>{g.preventDefault(),g.stopPropagation()})}),this.address&&window.setTimeout(async()=>{await this.updateRepositoryVersionInfo(this.version)},100)}disableForm(){var t,s,n,r;(t=this.addPluginButton)==null||t.setDisabled(!0),(s=this.addPluginButton)==null||s.setButtonText("Installing \u2026"),(n=this.cancelButton)==null||n.setDisabled(!0),(r=this.versionSetting)==null||r.setDisabled(!0)}async updateRepositoryVersionInfo(t="",s){var o,u,l;let n=this.repositoryAddressEl;if(!this.address){s==null||s.setText("Repository address is required."),s==null||s.addClass("validation-status-error");return}if(!this.isValidRepository(this.address)){s==null||s.setText("Invalid address. Expected: user/repo (GitHub) or https://host/user/repo (Gitea)."),s==null||s.addClass("validation-status-error");return}s==null||s.setText("Validating repository..."),s==null||s.removeClass("validation-status-error"),this.versionSetting&&this.updateVersion&&this.updateVersionDropdown(this.versionSetting,[]);let r=this.scrubAddress(this.address);try{let g="";if(this.secretName){let p=this.plugin.app.secretStorage.getSecret(this.secretName);p&&(g=p)}else if(this.plugin.settings.globalTokenName){let p=this.plugin.app.secretStorage.getSecret(this.plugin.settings.globalTokenName);p&&(g=p)}let{provider:d,parsed:a}=z(r),c=await d.listReleases(a,g);c&&c.length>0?(n==null||n.inputEl.classList.remove("invalid-repository"),n==null||n.inputEl.classList.add("valid-repository"),s==null||s.setText(""),this.versionSetting&&(this.versionSetting.settingEl.classList.remove("disabled-setting"),this.versionSetting.setDisabled(!1),this.updateVersionDropdown(this.versionSetting,c,t))):(n==null||n.inputEl.classList.remove("valid-repository"),n==null||n.inputEl.classList.add("invalid-repository"),s==null||s.setText("No releases found in this repository."),s==null||s.addClass("validation-status-error"),(o=this.versionSetting)==null||o.settingEl.classList.add("disabled-setting"),(u=this.versionSetting)==null||u.setDisabled(!0),(l=this.addPluginButton)==null||l.setDisabled(!0))}catch(g){if(g instanceof x)n==null||n.inputEl.classList.remove("valid-repository"),n==null||n.inputEl.classList.add("validation-error"),s==null||s.setText(`API rate limit exceeded. Try again in ${g.getMinutesToReset()} minutes.`),this.disableVersionAndButton(),w(this.plugin,`${g.message} Consider adding an access token in settings.`,20);else if(g instanceof I){switch(g.status){case 404:s==null||s.setText("Repository not found. Check the address or provide a valid token for private repos.");break;case 403:s==null||s.setText("Access denied. Check your access token.");break;default:s==null||s.setText(`Error: ${g.message}`)}s==null||s.addClass("validation-status-error"),this.disableVersionAndButton(),w(this.plugin,g.message,20)}else s==null||s.setText(`Unexpected error: ${g}. Enable debug mode for details.`),s==null||s.addClass("validation-status-error"),this.disableVersionAndButton()}}disableVersionAndButton(){var t,s;(t=this.versionSetting)==null||t.setDisabled(!0),(s=this.addPluginButton)==null||s.setDisabled(!0)}onClose(){this.openSettingsTabAfterwards&&(this.plugin.app.setting.open(),this.plugin.app.setting.openTabById(this.plugin.APP_ID))}};var wi=require("obsidian");async function qe(){try{let i=await(0,wi.requestUrl)(`https://obsidian.md/?${Math.random()}`);return i.status>=200&&i.status<300}catch(i){return!1}}var vi=O(),Me=et(),de=class{constructor(e){this.plugin=e}resolveProvider(e){return z(e)}getGiteaUrlForRepo(e){var s;let t=this.plugin.settings.pluginSubListFrozenVersion.find(n=>n.repo===e);return(s=t==null?void 0:t.giteaUrl)!=null?s:""}async getTokenForRepo(e,t){return t?await this.plugin.app.secretStorage.getSecret(t)||"":this.plugin.settings.globalTokenName&&await this.plugin.app.secretStorage.getSecret(this.plugin.settings.globalTokenName)||""}displayAddNewPluginModal(e=!1,t=!1,s="",n="",r=""){new Y(this.plugin,this,e,t,s,n,r).open()}async validateRepository(e,t=!1,s=!1,n="",r="",o=""){let{provider:l,parsed:g}=this.resolveProvider(e),d=r;try{let a=await l.getRepoInfo(g,d),c=await l.getRelease(g,n||void 0,t,d);if(!c)return s&&(w(this.plugin,`${e} This does not seem to be an obsidian plugin with valid releases, as there are no releases available.`,15),console.error("BRAT: validateRepository",e)),null;let p=await l.getAsset(c,"manifest.json",a.isPrivate,d);if(!p)return s&&w(this.plugin,`${e} This does not seem to be an obsidian plugin, as there is no manifest.json file in the release.`,15),null;let m=JSON.parse(p);if(!("id"in m))return s&&w(this.plugin,`${e} The plugin id attribute is missing from the manifest file`,15),null;if(!("version"in m))return s&&w(this.plugin,`${e} The version attribute is missing from the manifest file`,15),null;try{let P=Me(c.tag_name,{includePrerelease:!0,loose:!0}),R=Me(m.version,{includePrerelease:!0,loose:!0});P&&R&&vi(P,R)!==0&&(s&&w(this.plugin,`${e} Version mismatch: release tag '${c.tag_name}' vs manifest '${m.version}'. Using release version.`,15),m.version=P.version)}catch(P){}return m}catch(a){if(a instanceof x){let c=`${g.host} API rate limit exceeded. Reset in ${a.getMinutesToReset()} minutes.`;throw s&&w(this.plugin,c,15),console.error(`BRAT: validateRepository ${a}`),w(this.plugin,`${a.message} Consider adding a personal access token in BRAT settings for higher limits.`,20),a}if(a instanceof I)throw s&&(a.status===401?w(this.plugin,`${e} Authentication error. Verify that your access token is valid.`,15):w(this.plugin,`${e} API error ${a.status}: ${a.message}`,15)),console.error(`BRAT: validateRepository ${a}`),a;return s&&w(this.plugin,`${e} Unspecified error: ${a}. Enable debug for more info.`,15),null}}async getAllReleaseFiles(e,t,s="",n="",r=""){let{provider:o,parsed:u}=this.resolveProvider(e),g=(await o.getRepoInfo(u,n)).isPrivate,d=await o.getRelease(u,s||void 0,t,n);if(!d)return Promise.reject("No release found");let a=t||s!=="";return console.log({reallyGetManifestOrNot:a,version:d.tag_name}),{mainJs:await o.getAsset(d,"main.js",g,n),manifest:a?await o.getAsset(d,"manifest.json",g,n):"",styles:await o.getAsset(d,"styles.css",g,n)}}async writeReleaseFilesToPluginFolder(e,t){var r,o;let s=`${(0,F.normalizePath)(`${this.plugin.app.vault.configDir}/plugins/${e}`)}/`,{adapter:n}=this.plugin.app.vault;await n.exists(s)||await n.mkdir(s),await n.write(`${s}main.js`,(r=t.mainJs)!=null?r:""),await n.write(`${s}manifest.json`,(o=t.manifest)!=null?o:""),t.styles&&await n.write(`${s}styles.css`,t.styles)}async addPlugin(e,t=!1,s=!1,n=!1,r="",o=!1,u=this.plugin.settings.enableAfterInstall,l=""){try{this.plugin.settings.debuggingMode&&console.log("BRAT: addPlugin",e,t,s,n,r,o,u,l?"with secret":"public");let{provider:g,parsed:d}=this.resolveProvider(e),a="";l&&l.trim()!==""?(a=await this.plugin.app.secretStorage.getSecret(l)||"",a||w(this.plugin,`Secret not found for token name: ${l}. Please add it to SecretStorage or clear the token name for this plugin.`,10)):this.plugin.settings.globalTokenName&&(a=await this.plugin.app.secretStorage.getSecret(this.plugin.settings.globalTokenName)||"");let c=this.getGiteaUrlForRepo(e),p=10,m=await this.validateRepository(e,!0,!0,r,a,c),P=!!m;if(P||(m=await this.validateRepository(e,!1,!0,r,a,c)),m===null){let $=`${e} A manifest.json file does not exist in the latest release. This plugin cannot be installed.`;return await this.plugin.log($,!0),w(this.plugin,$,p),!1}if(!Object.hasOwn(m,"version")){let $=`${e} The manifest.json does not have a version number. Cannot install.`;return await this.plugin.log($,!0),w(this.plugin,$,p),!1}let R=!1;if(Object.hasOwn(m,"minAppVersion")&&!(0,F.requireApiVersion)(m.minAppVersion)){if(r===""||r==="latest"||!this.plugin.settings.allowIncompatiblePlugins){let T=`Plugin: ${e} Requires Obsidian ${m.minAppVersion}, but you have ${F.apiVersion}. Update Obsidian or contact the developer.`;return await this.plugin.log(T,!0),w(this.plugin,T,30),!1}if(!await He({app:this.plugin.app,message:createFragment(T=>{T.appendText("Plugin: "),T.createEl("code",{text:e}),T.createEl("br"),T.appendText("The manifest requires Obsidian "),T.createEl("code",{text:m.minAppVersion}),T.appendText(", but you have "),T.createEl("code",{text:F.apiVersion}),T.appendText(". Install at your own risk?")})}))return!1;R=!0}let ie=async()=>{var N,G;let $=await this.getAllReleaseFiles(e,P,r,a,c);(P||$.manifest==="")&&($.manifest=JSON.stringify(m));let T=JSON.parse((N=$.manifest)!=null?N:"");if(R&&(T.brat={isIncompatible:!0,minAppVersionOriginal:T.minAppVersion},T.minAppVersion=F.apiVersion),F.Platform.isMobile&&T.isDesktopOnly)if(this.plugin.settings.allowIncompatiblePlugins){if(!await He({app:this.plugin.app,message:createFragment(E=>{E.appendText("Plugin: "),E.createEl("code",{text:e}),E.createEl("br"),E.appendText("This plugin is desktop-only, but you are on mobile."),E.createEl("br"),E.appendText("Install at your own risk?")})}))return null;T.isDesktopOnly=!1,(G=T.brat)!=null||(T.brat={}),T.brat.isDesktopOnlyOriginal=!0,T.brat.isIncompatible=!0,R=!0}else{let D=`Plugin: ${e} Cannot install desktop-only plugin on mobile.`;return await this.plugin.log(D,!0),w(this.plugin,D,30),null}if(R&&($.manifest=JSON.stringify(T)),$.mainJs===null){let D=`${e} main.js is missing from the release.`;return await this.plugin.log(D,!0),w(this.plugin,D,p),null}return $};if(!t||o){let $=await ie();if($===null)return!1;if(await this.writeReleaseFilesToPluginFolder(m.id,$),pi(this.plugin,e,r,R,l,d.isGitHub?"":d.rawBaseUrl),u){let{plugins:T}=this.plugin.app,N=(0,F.normalizePath)(`${T.getPluginFolder()}/${m.id}`);await T.loadManifest(N),await T.enablePluginAndSave(m.id)}if(await this.plugin.app.plugins.loadManifests(),o)await this.reloadPlugin(m.id),await this.plugin.log(`${e} reinstalled`,!0),w(this.plugin,`${e} Plugin reinstalled (version ${m.version})`,p);else{let T=r===""?"":` (version: ${r})`,N=`${e}${T} Plugin registered with BRAT.`;u||(N+=" You may need to enable it in Community Plugins."),await this.plugin.log(N,!0),w(this.plugin,N,p)}}else{let $=`${this.plugin.app.vault.configDir}/plugins/${m.id}/`,T="";try{T=await this.plugin.app.vault.adapter.read(`${$}manifest.json`)}catch(E){let j=E;if(j.errno===-4058||j.errno===-2)return await this.addPlugin(e,!1,P,!1,r,!1,u,l),!0;console.log("BRAT - Local Manifest Load",m.id,E)}if(r!==""&&r!=="latest")return w(this.plugin,`${e} version is frozen, not updating.`,3),!1;let N=JSON.parse(T),G=Me(N.version,{includePrerelease:!0,loose:!0}),D=Me(m.version,{includePrerelease:!0,loose:!0});if(G&&D&&vi(G,D)===-1){let E=await ie();if(E===null)return!1;if(s){let H=`Update available for ${m.id}: ${N.version} \u2192 ${m.version}. `;return await this.plugin.log(H,!0),w(this.plugin,H,30),!1}await this.writeReleaseFilesToPluginFolder(m.id,E),await this.plugin.app.plugins.loadManifests(),await this.reloadPlugin(m.id);let j=`${m.id} Updated: ${N.version} \u2192 ${m.version}. `;return await this.plugin.log(j,!0),w(this.plugin,j,30),!0}return n&&w(this.plugin,`No update for ${e}`,3),!0}}catch(g){console.error(`BRAT: Error adding plugin ${e}:`,g);let d=g instanceof Error?g.message:"Unknown error";return await this.plugin.log(`Error ${t?"updating":"adding"} plugin ${e}: ${d}`,!0),!1}return!0}async reloadPlugin(e){let{plugins:t}=this.plugin.app;try{await t.disablePlugin(e),await t.enablePlugin(e)}catch(s){this.plugin.settings.debuggingMode&&console.log("reload plugin",s)}}async updatePlugin(e,t=!1,s=!1,n=!1,r=""){let o=await this.addPlugin(e,!0,t,s,"",n,!1,r);return!o&&!t&&w(this.plugin,`${e} Update failed.`),o}async checkForPluginUpdatesAndInstallUpdates(e=!1,t=!1){if(!await qe()){console.log("BRAT: No internet detected.");return}let s,n="Checking for plugin updates STARTED";await this.plugin.log(n,!0),e&&this.plugin.settings.notificationsEnabled&&(s=new F.Notice(`BRAT ${n}`,3e4));let r=new Map(this.plugin.settings.pluginSubListFrozenVersion.map(l=>[l.repo,l.version])),o=new Map(this.plugin.settings.pluginSubListFrozenVersion.map(l=>[l.repo,l.tokenName||""]));for(let l of this.plugin.settings.pluginList){let g=r.get(l);g&&g!=="latest"||await this.updatePlugin(l,t,!1,!1,o.get(l)||"")}let u="Checking for plugin updates COMPLETED";await this.plugin.log(u,!0),e&&(s&&s.hide(),w(this.plugin,u,10))}deletePlugin(e){let t=`Removed ${e} from BRAT plugin list`;this.plugin.log(t,!0),this.plugin.settings.pluginList=this.plugin.settings.pluginList.filter(s=>s!==e),this.plugin.settings.pluginSubListFrozenVersion=this.plugin.settings.pluginSubListFrozenVersion.filter(s=>s.repo!==e),this.plugin.saveSettings()}getEnabledDisabledPlugins(e){let t=this.plugin.app.plugins,s=Object.values(t.manifests),n=Object.values(t.plugins).map(r=>r.manifest);return e?s.filter(r=>n.find(o=>r.id===o.id)):s.filter(r=>!n.find(o=>r.id===o.id))}checkIncompatiblePlugins(){let e=this.plugin.settings.pluginSubListFrozenVersion.filter(t=>t.isIncompatible).map(t=>t.repo);e.length>0&&w(this.plugin,`The following incompatible plugins were forcefully installed and may not work as expected: ${e.join(` `)}`,30)}};var X=require("obsidian");function Zo(i){let e=0;for(let t=0;tZo(i).toString(),me=async(i,e,t)=>{let{provider:s,parsed:n}=z(e),r=await s.getRawFile(n,"theme-beta.css","HEAD");if(r||(r=await s.getRawFile(n,"theme.css","HEAD")),!r)return w(i,"No theme.css or theme-beta.css found in the repository root. Cannot install theme."),!1;let o=await s.getRawFile(n,"manifest.json","HEAD");if(!o)return w(i,"No manifest.json found in the repository root. Theme cannot be installed."),!1;let u=await JSON.parse(o),l=(0,X.normalizePath)(Jo(i)+u.name),{adapter:g}=i.app.vault;await g.exists(l)||await g.mkdir(l),await g.write((0,X.normalizePath)(`${l}/theme.css`),r),await g.write((0,X.normalizePath)(`${l}/manifest.json`),o),hi(i,e,Pi(r));let d="";return t?(di(i,e,r),d=`${u.name} theme installed from ${e}. `,setTimeout(()=>{i.app.customCss.setTheme(u.name)},500)):d=`${u.name} theme updated from ${e}.`,i.log(d,!1),w(i,d,20,()=>{window.open(`${n.rawBaseUrl}/${n.owner}/${n.repo}`)}),!0},te=async(i,e)=>{if(!await qe()){console.log("BRAT: No internet detected.");return}let t,s="Checking for beta theme updates STARTED";await i.log(s,!0),e&&i.settings.notificationsEnabled&&(t=new X.Notice(`BRAT ${s}`,3e4));for(let r of i.settings.themesList){let{provider:o,parsed:u}=z(r.repo),l=await Ti(o,u,!0);l==="0"&&(l=await Ti(o,u,!1)),l!==r.lastUpdate&&await me(i,r.repo,!1)}let n="Checking for beta theme updates COMPLETED";await i.log(n,!0),e&&(i.settings.notificationsEnabled&&t&&t.hide(),w(i,n))},Ve=(i,e)=>{i.settings.themesList=i.settings.themesList.filter(s=>s.repo!==e),i.saveSettings();let t=`Removed ${e} from BRAT themes list. Theme files still exist \u2014 remove via Settings > Appearance.`;i.log(t,!0),w(i,t)},Jo=i=>`${(0,X.normalizePath)(`${i.app.vault.configDir}/themes`)}/`;async function Ti(i,e,t){let s=t?"theme-beta.css":"theme.css",n=await i.getRawFile(e,s,"HEAD");return n?Pi(n):"0"}var yi="brat-migrations";async function Ko(i,e){try{let t=await i.vault.adapter.read(`${i.vault.configDir}/plugins/obsidian42-brat/${yi}.json`);return JSON.parse(t).appliedMigrations.includes(e)}catch(t){return!1}}async function Qo(i,e){try{let t=`${i.vault.configDir}/plugins/obsidian42-brat/${yi}.json`,s={appliedMigrations:[]};try{let n=await i.vault.adapter.read(t);s=JSON.parse(n)}catch(n){}s.appliedMigrations.includes(e)||(s.appliedMigrations.push(e),await i.vault.adapter.write(t,JSON.stringify(s,null,2)))}catch(t){console.error(`BRAT: Failed to mark migration ${e} complete:`,t)}}async function Ei(i,e,t){let s="tokens-to-secretstorage-v1";if(!await Ko(i,s))try{let n=0,r=l=>{let d=`brat-gh-${l.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}`;return d.length>64?d.substring(0,64).replace(/-$/,""):d},o=l=>{let g=i.secretStorage.listSecrets();for(let d of g)if(i.secretStorage.getSecret(d)===l)return d;return null},u=(l,g)=>{let d=o(l);return d?(console.log(`BRAT: Reusing existing secret "${d}"`),d):(i.secretStorage.setSecret(g,l),console.log(`BRAT: Created new secret "${g}"`),g)};if(e.personalAccessToken&&e.personalAccessToken.trim()!==""){let l=e.personalAccessToken.trim(),d=u(l,"brat-gh-global");e.globalTokenName=d,e.personalAccessToken="",n++}if(e.pluginSubListFrozenVersion){for(let l of e.pluginSubListFrozenVersion)if(l.token&&l.token.trim()!==""){let g=l.token.trim(),d=r(l.repo),a=u(g,d);l.tokenName=a,l.token=void 0,n++}}n>0&&(await t(),console.log(`BRAT: Migrated ${n} token(s) to SecretStorage`)),await Qo(i,s)}catch(n){console.error("BRAT: Failed to migrate tokens to SecretStorage:",n)}}var W=require("obsidian");var U=class extends W.Modal{constructor(e,t=!1){super(e.app),this.plugin=e,this.address="",this.openSettingsTabAfterwards=t}async submitForm(){if(this.address==="")return;let e=this.address.replace("https://github.com/","");if(mi(this.plugin,e)){w(this.plugin,"This theme is already in the list for beta testing",10);return}await me(this.plugin,e,!0)&&this.close()}onOpen(){this.contentEl.createEl("h4",{text:"Github repository for beta theme:"}),this.contentEl.createEl("form",{},e=>{e.addClass("brat-modal"),new W.Setting(e).addText(n=>{n.setPlaceholder("Repository (example: https://github.com/user/repo or https://git.example.com/user/repo)"),n.setValue(this.address),n.onChange(r=>{this.address=r.trim()}),n.inputEl.addEventListener("keydown",r=>{r.key==="Enter"&&this.address!==" "&&(r.preventDefault(),this.submitForm())}),n.inputEl.style.width="100%",window.setTimeout(()=>{let r=document.querySelector(".setting-item-info");r&&r.remove(),n.inputEl.focus()},10)}),e.createDiv("modal-button-container",n=>{new W.ButtonComponent(n).setButtonText("Never mind").onClick(()=>{this.close()}),new W.ButtonComponent(n).setButtonText("Add theme").setCta().onClick(r=>{r.preventDefault(),console.log("Add theme button clicked"),this.address!==""&&this.submitForm()})});let t=e.createDiv();t.style.borderTop="1px solid #ccc",t.style.marginTop="30px";let s=t.createSpan();s.createEl("a",{href:"https://bit.ly/o42-twitter",text:"TFTHacker"}),s.appendText(" and "),s.createEl("a",{href:"https://github.com/johannrichard",text:"johannrichard"}),s.style.fontStyle="italic",t.appendChild(s),ee(t,!1),window.setTimeout(()=>{let n=e.querySelectorAll(".brat-modal .setting-item-info");for(let r of Array.from(n))r.remove()},50)})}onClose(){this.openSettingsTabAfterwards&&(this.plugin.app.setting.openTab(),this.plugin.app.setting.openTabById(this.plugin.APP_ID))}};var Ri=require("obsidian");function $i(){(0,Ri.addIcon)("BratIcon",'')}var wt=require("obsidian"),Ii=async(i=!0)=>{let e="https://raw.githubusercontent.com/obsidianmd/obsidian-releases/HEAD/community-plugins.json";try{let t=await(0,wt.requestUrl)({url:e});return t.status===404?null:t.json}catch(t){return i&&console.log("error in grabCommmunityPluginList",t),null}},Ai=async(i=!0)=>{let e="https://raw.githubusercontent.com/obsidianmd/obsidian-releases/HEAD/community-css-themes.json";try{let t=await(0,wt.requestUrl)({url:e});return t.status===404?null:t.json}catch(t){return i&&console.log("error in grabCommmunityThemesList",t),null}};var Ci=require("obsidian"),M=class extends Ci.FuzzySuggestModal{constructor(t){super(t.app);this.data=[];this.scope.register(["Shift"],"Enter",s=>{this.enterTrigger(s)}),this.scope.register(["Ctrl"],"Enter",s=>{this.enterTrigger(s)})}setSuggesterData(t){this.data=t}display(t){this.callbackFunction=t,this.open()}getItems(){return this.data}getItemText(t){return t.display}onChooseItem(){}renderSuggestion(t,s){s.createEl("div",{text:t.item.display})}enterTrigger(t){var r;let s=(r=document.querySelector(".suggestion-item.is-selected div"))==null?void 0:r.textContent,n=this.data.find(o=>o.display===s);n&&(this.invokeCallback(n,t),this.close())}onChooseSuggestion(t,s){this.invokeCallback(t.item,s)}invokeCallback(t,s){typeof this.callbackFunction=="function"&&this.callbackFunction(t,s)}};var he=class{constructor(e){this.bratCommands=[{id:"AddBetaPlugin",icon:"BratIcon",name:"Plugins: Add a beta plugin for testing (with or without version)",showInRibbon:!0,callback:()=>{this.plugin.betaPlugins.displayAddNewPluginModal(!1,!0)}},{id:"checkForUpdatesAndUpdate",icon:"BratIcon",name:"Plugins: Check for updates to all beta plugins and UPDATE",showInRibbon:!0,callback:async()=>{await this.plugin.betaPlugins.checkForPluginUpdatesAndInstallUpdates(!0,!1)}},{id:"checkForUpdatesAndDontUpdate",icon:"BratIcon",name:"Plugins: Only check for updates to beta plugins, but don't Update",showInRibbon:!0,callback:async()=>{await this.plugin.betaPlugins.checkForPluginUpdatesAndInstallUpdates(!0,!0)}},{id:"updateOnePlugin",icon:"BratIcon",name:"Plugins: Choose a single plugin version to update",showInRibbon:!0,callback:()=>{let e=new Map(this.plugin.settings.pluginSubListFrozenVersion.map(n=>[n.repo,{version:n.version,token:n.token}])),t=Object.values(this.plugin.settings.pluginList).filter(n=>{let r=e.get(n);return!(r!=null&&r.version)||r.version==="latest"}).map(n=>({display:n,info:n})),s=new M(this.plugin);s.setSuggesterData(t),s.display(n=>{let r=`Checking for updates for ${n.info}`,o=e.get(n.info);this.plugin.log(r,!0),w(this.plugin,` ${r}`,3),this.plugin.betaPlugins.updatePlugin(n.info,!1,!0,!1,o==null?void 0:o.token)})}},{id:"reinstallOnePlugin",icon:"BratIcon",name:"Plugins: Choose a single plugin to reinstall",showInRibbon:!0,callback:()=>{let e=new Set(this.plugin.settings.pluginSubListFrozenVersion.map(n=>n.repo)),t=Object.values(this.plugin.settings.pluginList).filter(n=>!e.has(n)).map(n=>({display:n,info:n})),s=new M(this.plugin);s.setSuggesterData(t),s.display(n=>{let r=`Reinstalling ${n.info}`;w(this.plugin,` ${r}`,3),this.plugin.log(r,!0),this.plugin.betaPlugins.updatePlugin(n.info,!1,!1,!0)})}},{id:"restartPlugin",icon:"BratIcon",name:"Plugins: Restart a plugin that is already installed",showInRibbon:!0,callback:()=>{let e=Object.values(this.plugin.app.plugins.manifests).map(s=>({display:s.id,info:s.id})),t=new M(this.plugin);t.setSuggesterData(e),t.display(s=>{w(this.plugin,`${s.info} Plugin reloading .....`,5),this.plugin.betaPlugins.reloadPlugin(s.info)})}},{id:"disablePlugin",icon:"BratIcon",name:"Plugins: Disable a plugin - toggle it off",showInRibbon:!0,callback:()=>{let e=this.plugin.betaPlugins.getEnabledDisabledPlugins(!0).map(s=>({display:`${s.name} (${s.id})`,info:s.id})),t=new M(this.plugin);t.setSuggesterData(e),t.display(s=>{this.plugin.log(`${s.display} plugin disabled`,!1),this.plugin.settings.debuggingMode&&console.log(s.info),this.plugin.app.plugins.disablePluginAndSave(s.info)})}},{id:"enablePlugin",icon:"BratIcon",name:"Plugins: Enable a plugin - toggle it on",showInRibbon:!0,callback:()=>{let e=this.plugin.betaPlugins.getEnabledDisabledPlugins(!1).map(s=>({display:`${s.name} (${s.id})`,info:s.id})),t=new M(this.plugin);t.setSuggesterData(e),t.display(s=>{this.plugin.log(`${s.display} plugin enabled`,!1),this.plugin.app.plugins.enablePluginAndSave(s.info)})}},{id:"openGitHubZRepository",icon:"BratIcon",name:"Plugins: Open the GitHub repository for a plugin",showInRibbon:!0,callback:async()=>{let e=await Ii(this.plugin.settings.debuggingMode);if(e){let t=Object.values(e).map(r=>({display:`Plugin: ${r.name} (${r.repo})`,info:r.repo})),s=Object.values(this.plugin.settings.pluginList).map(r=>({display:`BRAT: ${r}`,info:r}));for(let r of t)s.push(r);let n=new M(this.plugin);n.setSuggesterData(s),n.display(r=>{r.info&&window.open(`https://github.com/${r.info}`)})}}},{id:"openGitHubRepoTheme",icon:"BratIcon",name:"Themes: Open the GitHub repository for a theme (appearance)",showInRibbon:!0,callback:async()=>{let e=await Ai(this.plugin.settings.debuggingMode);if(e){let t=Object.values(e).map(n=>({display:`Theme: ${n.name} (${n.repo})`,info:n.repo})),s=new M(this.plugin);s.setSuggesterData(t),s.display(n=>{n.info&&window.open(`https://github.com/${n.info}`)})}}},{id:"opentPluginSettings",icon:"BratIcon",name:"Plugins: Open Plugin Settings Tab",showInRibbon:!0,callback:()=>{let e=this.plugin.app.setting,t=Object.values(e.pluginTabs).map(r=>({display:`Plugin: ${r.name}`,info:r.id})),s=new M(this.plugin),n=Object.values(e.settingTabs).map(r=>({display:`Core: ${r.name}`,info:r.id}));for(let r of t)n.push(r);s.setSuggesterData(n),s.display(r=>{e.open(),e.openTabById(r.info)})}},{id:"GrabBetaTheme",icon:"BratIcon",name:"Themes: Grab a beta theme for testing from a Github repository",showInRibbon:!0,callback:()=>{new U(this.plugin).open()}},{id:"updateBetaThemes",icon:"BratIcon",name:"Themes: Update beta themes",showInRibbon:!0,callback:async()=>{await te(this.plugin,!0)}},{id:"allCommands",icon:"BratIcon",name:"All Commands list",showInRibbon:!1,callback:()=>{this.ribbonDisplayCommands()}}];this.plugin=e;for(let t of this.bratCommands)this.plugin.addCommand({id:t.id,name:t.name,icon:t.icon,callback:()=>{t.callback()}})}ribbonDisplayCommands(){let e=[];for(let o of this.bratCommands)o.showInRibbon&&e.push({display:o.name,info:o.callback});let t=new M(this.plugin),s=this.plugin.app.setting,n=Object.values(s.settingTabs).map(o=>({display:`Core: ${o.name}`,info:()=>{s.open(),s.openTabById(o.id)}})),r=Object.values(s.pluginTabs).map(o=>({display:`Plugin: ${o.name}`,info:()=>{s.open(),s.openTabById(o.id)}}));e.push({display:"---- Core Plugin Settings ----",info:()=>{this.ribbonDisplayCommands()}});for(let o of n)e.push(o);e.push({display:"---- Plugin Settings ----",info:()=>{this.ribbonDisplayCommands()}});for(let o of r)e.push(o);t.setSuggesterData(e),t.display(o=>{typeof o.info=="function"&&o.info()})}};var k=require("obsidian");var Ue=class extends k.PluginSettingTab{constructor(t,s){super(t,s);this.accessTokenSetting=null;this.accessTokenButton=null;this.tokenInfo=null;this.validator=null;this.plugin=s}display(){let{containerEl:t}=this;t.empty(),t.addClass("brat-settings"),new k.Setting(t).setName("Auto-enable plugins after installation").setDesc('If enabled beta plugins will be automatically enabled after installtion by default. Note: you can toggle this on and off for each plugin in the "Add Plugin" form.').addToggle(a=>{a.setValue(this.plugin.settings.enableAfterInstall).onChange(async c=>{this.plugin.settings.enableAfterInstall=c,await this.plugin.saveSettings()})}),new k.Setting(t).setName("Auto-update plugins at startup").setDesc("If enabled all beta plugins will be checked for updates each time Obsidian starts. Note: this does not update frozen version plugins.").addToggle(a=>{a.setValue(this.plugin.settings.updateAtStartup).onChange(async c=>{this.plugin.settings.updateAtStartup=c,await this.plugin.saveSettings()})}),new k.Setting(t).setName("Auto-update themes at startup").setDesc("If enabled all beta themes will be checked for updates each time Obsidian starts.").addToggle(a=>{a.setValue(this.plugin.settings.updateThemesAtStartup).onChange(async c=>{this.plugin.settings.updateThemesAtStartup=c,await this.plugin.saveSettings()})}),new k.Setting(t).setName("Select latest plugin version by default").setDesc("If enabled the latest version will be selected by default when adding a new plugin.").addToggle(a=>{a.setValue(this.plugin.settings.selectLatestPluginVersionByDefault).onChange(async c=>{this.plugin.settings.selectLatestPluginVersionByDefault=c,await this.plugin.saveSettings()})}),new k.Setting(t).setName("Allow incompatible plugins").setDesc("If enabled, plugins with higher app versions will be allowed to be installed. Also it allows desktop-only plugins to be installed on mobile devices.").addToggle(a=>{a.setValue(this.plugin.settings.allowIncompatiblePlugins).onChange(async c=>{this.plugin.settings.allowIncompatiblePlugins=c,await this.plugin.saveSettings()})}),ee(t,!0),t.createEl("hr");let s=new Map(this.plugin.settings.pluginSubListFrozenVersion.map(a=>[a.repo,a])),n=new Map,r=new k.SettingGroup(t).setHeading("Beta plugin list");r.addSearch(a=>{a.setPlaceholder("Filter plugins"),a.onChange(c=>{let p=c.toLowerCase().trim();n.forEach(({container:m,pluginName:P})=>{p===""||P.includes(p)?m.removeAttribute("hidden"):m.setAttribute("hidden","true")})})}),r.addSetting(a=>{let c=document.createDocumentFragment();c.createEl("div",{text:'Plugins added via "Add a beta plugin for testing". Supports both GitHub and Gitea repositories.'}),c.createEl("p"),c.createEl("div",{text:"Click the 'Edit' button next to a plugin to change installed version. Click x to remove from list."}),c.createEl("p"),c.createEl("span").createEl("b",{text:"Note: "}),c.createSpan({text:"Removing from the list does not delete the plugin \u2014 remove from Community Plugins tab instead."}),a.setDesc(c),a.addButton(p=>{p.setButtonText("Add beta plugin").setCta().onClick(()=>{this.plugin.betaPlugins.displayAddNewPluginModal(!0)})})});for(let a of this.plugin.settings.pluginList){let c=s.get(a);r.addSetting(p=>{let m=(c==null?void 0:c.tokenName)||"",P=m?this.plugin.app.secretStorage.getSecret(m):"",R=!!(m&&!P),ie=!!(c!=null&&c.giteaUrl),$=document.createDocumentFragment(),T=c!=null&&c.version?` Tracked version: ${c.version} ${c.version==="latest"?"":"(frozen)"}`:"",N=c!=null&&c.isIncompatible?" (incompatible)":"",G=ie?" (Gitea)":"";$.createDiv({text:`${T}${N}${G}`}),R&&$.createDiv({text:` Secret not defined or empty: ${m}`,cls:"mod-warning",title:"Token name configured but secret is missing. Add the secret or update the plugin configuration."}),p.setName(pe(a)).setDesc($);let D=p.settingEl;D.addClass("brat-plugin-item"),ie&&D.addClass("brat-plugin-gitea"),n.set(a,{container:D,pluginName:a.toLowerCase()}),(!(c!=null&&c.version)||c.version==="latest")&&p.addButton(E=>{R?E.setIcon("sync").setTooltip(`Secret missing: ${m}. Please add the secret or update the plugin configuration.`).setWarning().setDisabled(!0):E.setIcon("sync").setTooltip("Check and update plugin").onClick(async()=>{await this.plugin.betaPlugins.updatePlugin(a,!1,!0,!1,(c==null?void 0:c.tokenName)||"")})}),p.addButton(E=>{E.setIcon("edit").setTooltip("Change version and update settings"),R&&E.setWarning(),E.onClick(()=>{this.plugin.betaPlugins.displayAddNewPluginModal(!0,!0,a,c==null?void 0:c.version,(c==null?void 0:c.tokenName)||""),this.plugin.app.setting.updatePluginSection()})}).addButton(E=>{E.setIcon("cross").setTooltip("Remove this beta plugin").setWarning().onClick(()=>{if(E.buttonEl.textContent==="")E.setButtonText("Click once more to confirm removal");else{let{buttonEl:j}=E,{parentElement:H}=j;H!=null&&H.parentElement&&(H.parentElement.remove(),this.plugin.betaPlugins.deletePlugin(a))}})})})}let o=new Map,u=new k.SettingGroup(t).setHeading("Beta themes list");u.addSetting(a=>a.addButton(c=>{c.setButtonText("Add beta theme").setCta().onClick(()=>{this.plugin.app.setting.close(),new U(this.plugin).open()})})),u.addSearch(a=>{a.setPlaceholder("Filter themes"),a.onChange(c=>{let p=c.toLowerCase().trim();o.forEach(({container:m,themeName:P})=>{p===""||P.includes(p)?m.removeAttribute("hidden"):m.setAttribute("hidden","true")})})});for(let a of this.plugin.settings.themesList)u.addSetting(c=>{c.setName(pe(a.repo));let p=c.settingEl;p.addClass("brat-theme-item"),o.set(a.repo,{container:p,themeName:a.repo.toLowerCase()}),c.addButton(m=>{m.setIcon("cross").setTooltip("Delete this beta theme").onClick(()=>{if(m.buttonEl.textContent==="")m.setButtonText("Click once more to confirm removal");else{let{buttonEl:P}=m,{parentElement:R}=P;R!=null&&R.parentElement&&(R.parentElement.remove(),Ve(this.plugin,a.repo))}})})});new k.SettingGroup(t).setHeading("Monitoring").addSetting(a=>a.setName("Enable notifications").setDesc("BRAT will provide popup notifications for its various activities. Turn this off means no notifications from BRAT.").addToggle(c=>{c.setValue(this.plugin.settings.notificationsEnabled),c.onChange(async p=>{this.plugin.settings.notificationsEnabled=p,await this.plugin.saveSettings()})})).addSetting(a=>a.setName("Enable logging").setDesc("Plugin updates will be logged to a file in the log file.").addToggle(c=>{c.setValue(this.plugin.settings.loggingEnabled).onChange(async p=>{this.plugin.settings.loggingEnabled=p,await this.plugin.saveSettings()})})).addSetting(a=>a.setName("BRAT log file location").setDesc("Logs will be saved to this file. Don't add .md to the file name.").addSearch(c=>{c.setPlaceholder("Example: BRAT-log").setValue(this.plugin.settings.loggingPath).onChange(async p=>{this.plugin.settings.loggingPath=p,await this.plugin.saveSettings()})})).addSetting(a=>a.setName("Enable verbose logging").setDesc("Get a lot more information in the log.").addToggle(c=>{c.setValue(this.plugin.settings.loggingVerboseEnabled).onChange(async p=>{this.plugin.settings.loggingVerboseEnabled=p,await this.plugin.saveSettings()})})).addSetting(a=>a.setName("Debugging mode").setDesc("Atomic Bomb level console logging. Can be used for troubleshooting and development.").addToggle(c=>{c.setValue(this.plugin.settings.debuggingMode).onChange(async p=>{this.plugin.settings.debuggingMode=p,await this.plugin.saveSettings()})}));let g=new k.SettingGroup(t).setHeading("Access Token"),d="";g.addSetting(a=>{a.setName("Personal access token").setDesc(fi({prependText:"Increase rate limits for GitHub, or access private repos. Create one in ",url:"https://github.com/settings/tokens/new?scopes=public_repo",text:"your GitHub settings",appendText:". For Gitea, create a token in your Gitea instance settings."})),this.accessTokenSetting=new k.SecretComponent(this.plugin.app,a.controlEl),this.accessTokenSetting.setValue(this.plugin.settings.globalTokenName||"").onChange(async c=>{var m,P,R;let p=(c==null?void 0:c.trim())||"";this.plugin.settings.globalTokenName=p,await this.plugin.saveSettings(),p?(d=this.plugin.app.secretStorage.getSecret(p)||"",(m=this.accessTokenButton)==null||m.setDisabled(!1)):(d="",(P=this.accessTokenButton)==null||P.setDisabled(!0),await((R=this.validator)==null?void 0:R.validateToken("")))}),this.plugin.settings.globalTokenName&&(d=this.plugin.app.secretStorage.getSecret(this.plugin.settings.globalTokenName)||""),a.addExtraButton(c=>{c.setIcon("cross").setTooltip("Clear personal access token").onClick(async()=>{var p,m;this.plugin.settings.globalTokenName="",await this.plugin.saveSettings(),(p=this.accessTokenSetting)==null||p.setValue(""),d="",await((m=this.validator)==null?void 0:m.validateToken(""))})}).addButton(c=>{this.accessTokenButton=c,c.setButtonText("Validate").setCta().onClick(async()=>{var p;d&&await((p=this.validator)==null?void 0:p.validateToken(d))})}).then(()=>{var c;this.tokenInfo=this.createTokenInfoElement(t),this.validator=new Q(this.tokenInfo),(c=this.validator)==null||c.validateToken(d).then(p=>{var m;(m=this.accessTokenButton)==null||m.setDisabled(p||!this.plugin.settings.globalTokenName)})})})}createTokenInfoElement(t){let s=t.createDiv({cls:"brat-token-info"});return s.createDiv({cls:"brat-token-status"}),s.createDiv({cls:"brat-token-details"}),s}};var fe=class{constructor(e){this.console=(e,...t)=>{console.log(`BRAT: ${e}`,...t)};this.themes={themeseCheckAndUpates:async e=>{await te(this.plugin,e)},themeInstallTheme:async e=>{await me(this.plugin,e,!0)},themesDelete:e=>{Ve(this.plugin,e)},getThemeChecksum:async(e,t=!1)=>{try{let s=K(e),n=s.parseUrl(e),r=t?"theme-beta.css":"theme.css",o=await s.getRawFile(n,r,"HEAD");if(!o)return"0";let u=0;for(let l=0;l{if(!t.plugin&&!t.theme){w(this,"Could not locate the repository from the URL.",10);return}for(let s of["plugin","theme"])if(t[s]){let n;switch(s){case"plugin":n=new Y(this,this.betaPlugins,!0,!1,t[s],t.version?t.version:void 0),n.open();break;case"theme":n=new U(this),n.address=t[s],n.open();break}return}}}onload(){console.log(`loading ${this.APP_NAME}`),$i(),this.addRibbonIcon("BratIcon","BRAT",()=>{this.commands.ribbonDisplayCommands()}),this.loadSettings().then(async()=>{await Ei(this.app,this.settings,()=>this.saveSettings()),this.app.workspace.onLayoutReady(()=>{this.addSettingTab(new Ue(this.app,this)),this.registerObsidianProtocolHandler("brat",this.obsidianProtocolHandler),this.betaPlugins.checkIncompatiblePlugins(),this.settings.updateAtStartup&&setTimeout(()=>{this.betaPlugins.checkForPluginUpdatesAndInstallUpdates(!1)},6e4),this.settings.updateThemesAtStartup&&setTimeout(()=>{te(this,!1)},12e4),setTimeout(()=>{window.bratAPI=this.bratApi},500)})}).catch(t=>{console.error("Failed to load settings:",t)})}async log(t,s=!1){await Li(this,t,s)}onunload(){console.log(`unloading ${this.APP_NAME}`)}async loadSettings(){this.settings=Object.assign({},ft,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}};