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