45 lines
81 KiB
JavaScript
45 lines
81 KiB
JavaScript
"use strict";var tn=Object.create;var pe=Object.defineProperty;var nn=Object.getOwnPropertyDescriptor;var sn=Object.getOwnPropertyNames;var on=Object.getPrototypeOf,rn=Object.prototype.hasOwnProperty;var x=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),an=(s,e)=>{for(var t in e)pe(s,t,{get:e[t],enumerable:!0})},Ze=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of sn(e))!rn.call(s,i)&&i!==t&&pe(s,i,{get:()=>e[i],enumerable:!(n=nn(e,i))||n.enumerable});return s};var ln=(s,e,t)=>(t=s!=null?tn(on(s)):{},Ze(e||!s||!s.__esModule?pe(t,"default",{value:s,enumerable:!0}):t,s)),un=s=>Ze(pe({},"__esModule",{value:!0}),s);var $e=x((ps,et)=>{"use strict";var cn=typeof process=="object"&&process.env&&process.env.NODE_DEBUG&&/\bsemver\b/i.test(process.env.NODE_DEBUG)?(...s)=>console.error("SEMVER",...s):()=>{};et.exports=cn});var xe=x((ms,tt)=>{"use strict";var gn="2.0.0",dn=Number.MAX_SAFE_INTEGER||9007199254740991,pn=16,mn=250,hn=["major","premajor","minor","preminor","patch","prepatch","prerelease"];tt.exports={MAX_LENGTH:256,MAX_SAFE_COMPONENT_LENGTH:pn,MAX_SAFE_BUILD_LENGTH:mn,MAX_SAFE_INTEGER:dn,RELEASE_TYPES:hn,SEMVER_SPEC_VERSION:gn,FLAG_INCLUDE_PRERELEASE:1,FLAG_LOOSE:2}});var Be=x((F,nt)=>{"use strict";var{MAX_SAFE_COMPONENT_LENGTH:Oe,MAX_SAFE_BUILD_LENGTH:fn,MAX_LENGTH:bn}=xe(),wn=$e();F=nt.exports={};var Tn=F.re=[],En=F.safeRe=[],h=F.src=[],yn=F.safeSrc=[],f=F.t={},vn=0,Fe="[a-zA-Z0-9-]",Pn=[["\\s",1],["\\d",bn],[Fe,fn]],Rn=s=>{for(let[e,t]of Pn)s=s.split(`${e}*`).join(`${e}{0,${t}}`).split(`${e}+`).join(`${e}{1,${t}}`);return s},y=(s,e,t)=>{let n=Rn(e),i=vn++;wn(s,i,e),f[s]=i,h[i]=e,yn[i]=n,Tn[i]=new RegExp(e,t?"g":void 0),En[i]=new RegExp(n,t?"g":void 0)};y("NUMERICIDENTIFIER","0|[1-9]\\d*");y("NUMERICIDENTIFIERLOOSE","\\d+");y("NONNUMERICIDENTIFIER",`\\d*[a-zA-Z-]${Fe}*`);y("MAINVERSION",`(${h[f.NUMERICIDENTIFIER]})\\.(${h[f.NUMERICIDENTIFIER]})\\.(${h[f.NUMERICIDENTIFIER]})`);y("MAINVERSIONLOOSE",`(${h[f.NUMERICIDENTIFIERLOOSE]})\\.(${h[f.NUMERICIDENTIFIERLOOSE]})\\.(${h[f.NUMERICIDENTIFIERLOOSE]})`);y("PRERELEASEIDENTIFIER",`(?:${h[f.NONNUMERICIDENTIFIER]}|${h[f.NUMERICIDENTIFIER]})`);y("PRERELEASEIDENTIFIERLOOSE",`(?:${h[f.NONNUMERICIDENTIFIER]}|${h[f.NUMERICIDENTIFIERLOOSE]})`);y("PRERELEASE",`(?:-(${h[f.PRERELEASEIDENTIFIER]}(?:\\.${h[f.PRERELEASEIDENTIFIER]})*))`);y("PRERELEASELOOSE",`(?:-?(${h[f.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${h[f.PRERELEASEIDENTIFIERLOOSE]})*))`);y("BUILDIDENTIFIER",`${Fe}+`);y("BUILD",`(?:\\+(${h[f.BUILDIDENTIFIER]}(?:\\.${h[f.BUILDIDENTIFIER]})*))`);y("FULLPLAIN",`v?${h[f.MAINVERSION]}${h[f.PRERELEASE]}?${h[f.BUILD]}?`);y("FULL",`^${h[f.FULLPLAIN]}$`);y("LOOSEPLAIN",`[v=\\s]*${h[f.MAINVERSIONLOOSE]}${h[f.PRERELEASELOOSE]}?${h[f.BUILD]}?`);y("LOOSE",`^${h[f.LOOSEPLAIN]}$`);y("GTLT","((?:<|>)?=?)");y("XRANGEIDENTIFIERLOOSE",`${h[f.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);y("XRANGEIDENTIFIER",`${h[f.NUMERICIDENTIFIER]}|x|X|\\*`);y("XRANGEPLAIN",`[v=\\s]*(${h[f.XRANGEIDENTIFIER]})(?:\\.(${h[f.XRANGEIDENTIFIER]})(?:\\.(${h[f.XRANGEIDENTIFIER]})(?:${h[f.PRERELEASE]})?${h[f.BUILD]}?)?)?`);y("XRANGEPLAINLOOSE",`[v=\\s]*(${h[f.XRANGEIDENTIFIERLOOSE]})(?:\\.(${h[f.XRANGEIDENTIFIERLOOSE]})(?:\\.(${h[f.XRANGEIDENTIFIERLOOSE]})(?:${h[f.PRERELEASELOOSE]})?${h[f.BUILD]}?)?)?`);y("XRANGE",`^${h[f.GTLT]}\\s*${h[f.XRANGEPLAIN]}$`);y("XRANGELOOSE",`^${h[f.GTLT]}\\s*${h[f.XRANGEPLAINLOOSE]}$`);y("COERCEPLAIN",`(^|[^\\d])(\\d{1,${Oe}})(?:\\.(\\d{1,${Oe}}))?(?:\\.(\\d{1,${Oe}}))?`);y("COERCE",`${h[f.COERCEPLAIN]}(?:$|[^\\d])`);y("COERCEFULL",h[f.COERCEPLAIN]+`(?:${h[f.PRERELEASE]})?(?:${h[f.BUILD]})?(?:$|[^\\d])`);y("COERCERTL",h[f.COERCE],!0);y("COERCERTLFULL",h[f.COERCEFULL],!0);y("LONETILDE","(?:~>?)");y("TILDETRIM",`(\\s*)${h[f.LONETILDE]}\\s+`,!0);F.tildeTrimReplace="$1~";y("TILDE",`^${h[f.LONETILDE]}${h[f.XRANGEPLAIN]}$`);y("TILDELOOSE",`^${h[f.LONETILDE]}${h[f.XRANGEPLAINLOOSE]}$`);y("LONECARET","(?:\\^)");y("CARETTRIM",`(\\s*)${h[f.LONECARET]}\\s+`,!0);F.caretTrimReplace="$1^";y("CARET",`^${h[f.LONECARET]}${h[f.XRANGEPLAIN]}$`);y("CARETLOOSE",`^${h[f.LONECARET]}${h[f.XRANGEPLAINLOOSE]}$`);y("COMPARATORLOOSE",`^${h[f.GTLT]}\\s*(${h[f.LOOSEPLAIN]})$|^$`);y("COMPARATOR",`^${h[f.GTLT]}\\s*(${h[f.FULLPLAIN]})$|^$`);y("COMPARATORTRIM",`(\\s*)${h[f.GTLT]}\\s*(${h[f.LOOSEPLAIN]}|${h[f.XRANGEPLAIN]})`,!0);F.comparatorTrimReplace="$1$2$3";y("HYPHENRANGE",`^\\s*(${h[f.XRANGEPLAIN]})\\s+-\\s+(${h[f.XRANGEPLAIN]})\\s*$`);y("HYPHENRANGELOOSE",`^\\s*(${h[f.XRANGEPLAINLOOSE]})\\s+-\\s+(${h[f.XRANGEPLAINLOOSE]})\\s*$`);y("STAR","(<|>)?=?\\s*\\*");y("GTE0","^\\s*>=\\s*0\\.0\\.0\\s*$");y("GTE0PRE","^\\s*>=\\s*0\\.0\\.0-0\\s*$")});var it=x((hs,st)=>{"use strict";var In=Object.freeze({loose:!0}),Nn=Object.freeze({}),An=s=>s?typeof s!="object"?In:s:Nn;st.exports=An});var lt=x((fs,at)=>{"use strict";var ot=/^[0-9]+$/,rt=(s,e)=>{if(typeof s=="number"&&typeof e=="number")return s===e?0:s<e?-1:1;let t=ot.test(s),n=ot.test(e);return t&&n&&(s=+s,e=+e),s===e?0:t&&!n?-1:n&&!t?1:s<e?-1:1},Cn=(s,e)=>rt(e,s);at.exports={compareIdentifiers:rt,rcompareIdentifiers:Cn}});var we=x((bs,ct)=>{"use strict";var me=$e(),{MAX_LENGTH:ut,MAX_SAFE_INTEGER:he}=xe(),{safeRe:fe,t:be}=Be(),Ln=it(),{compareIdentifiers:Me}=lt(),Ve=class s{constructor(e,t){if(t=Ln(t),e instanceof s){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>ut)throw new TypeError(`version is longer than ${ut} characters`);me("SemVer",e,t),this.options=t,this.loose=!!t.loose,this.includePrerelease=!!t.includePrerelease;let n=e.trim().match(t.loose?fe[be.LOOSE]:fe[be.FULL]);if(!n)throw new TypeError(`Invalid Version: ${e}`);if(this.raw=e,this.major=+n[1],this.minor=+n[2],this.patch=+n[3],this.major>he||this.major<0)throw new TypeError("Invalid major version");if(this.minor>he||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>he||this.patch<0)throw new TypeError("Invalid patch version");n[4]?this.prerelease=n[4].split(".").map(i=>{if(/^[0-9]+$/.test(i)){let o=+i;if(o>=0&&o<he)return o}return i}):this.prerelease=[],this.build=n[5]?n[5].split("."):[],this.format()}format(){return this.version=`${this.major}.${this.minor}.${this.patch}`,this.prerelease.length&&(this.version+=`-${this.prerelease.join(".")}`),this.version}toString(){return this.version}compare(e){if(me("SemVer.compare",this.version,this.options,e),!(e instanceof s)){if(typeof e=="string"&&e===this.version)return 0;e=new s(e,this.options)}return e.version===this.version?0:this.compareMain(e)||this.comparePre(e)}compareMain(e){return e instanceof s||(e=new s(e,this.options)),this.major<e.major?-1:this.major>e.major?1:this.minor<e.minor?-1:this.minor>e.minor?1:this.patch<e.patch?-1:this.patch>e.patch?1:0}comparePre(e){if(e instanceof s||(e=new s(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 n=this.prerelease[t],i=e.prerelease[t];if(me("prerelease compare",t,n,i),n===void 0&&i===void 0)return 0;if(i===void 0)return 1;if(n===void 0)return-1;if(n===i)continue;return Me(n,i)}while(++t)}compareBuild(e){e instanceof s||(e=new s(e,this.options));let t=0;do{let n=this.build[t],i=e.build[t];if(me("build compare",t,n,i),n===void 0&&i===void 0)return 0;if(i===void 0)return 1;if(n===void 0)return-1;if(n===i)continue;return Me(n,i)}while(++t)}inc(e,t,n){if(e.startsWith("pre")){if(!t&&n===!1)throw new Error("invalid increment argument: identifier is empty");if(t){let i=`-${t}`.match(this.options.loose?fe[be.PRERELEASELOOSE]:fe[be.PRERELEASE]);if(!i||i[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,n);break;case"preminor":this.prerelease.length=0,this.patch=0,this.minor++,this.inc("pre",t,n);break;case"prepatch":this.prerelease.length=0,this.inc("patch",t,n),this.inc("pre",t,n);break;case"prerelease":this.prerelease.length===0&&this.inc("patch",t,n),this.inc("pre",t,n);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 i=Number(n)?1:0;if(this.prerelease.length===0)this.prerelease=[i];else{let o=this.prerelease.length;for(;--o>=0;)typeof this.prerelease[o]=="number"&&(this.prerelease[o]++,o=-2);if(o===-1){if(t===this.prerelease.join(".")&&n===!1)throw new Error("invalid increment argument: identifier already exists");this.prerelease.push(i)}}if(t){let o=[t,i];n===!1&&(o=[t]),Me(this.prerelease[0],t)===0?isNaN(this.prerelease[1])&&(this.prerelease=o):this.prerelease=o}break}default:throw new Error(`invalid increment argument: ${e}`)}return this.raw=this.format(),this.build.length&&(this.raw+=`+${this.build.join(".")}`),this}};ct.exports=Ve});var Ue=x((ws,dt)=>{"use strict";var gt=we(),kn=(s,e,t)=>new gt(s,t).compare(new gt(e,t));dt.exports=kn});var ht=x((Ts,mt)=>{"use strict";var pt=we(),Sn=(s,e,t=!1)=>{if(s instanceof pt)return s;try{return new pt(s,e)}catch(n){if(!t)return null;throw n}};mt.exports=Sn});var _e=x((Es,ft)=>{"use strict";var Dn=we(),$n=ht(),{safeRe:Te,t:Ee}=Be(),xn=(s,e)=>{if(s instanceof Dn)return s;if(typeof s=="number"&&(s=String(s)),typeof s!="string")return null;e=e||{};let t=null;if(!e.rtl)t=s.match(e.includePrerelease?Te[Ee.COERCEFULL]:Te[Ee.COERCE]);else{let u=e.includePrerelease?Te[Ee.COERCERTLFULL]:Te[Ee.COERCERTL],g;for(;(g=u.exec(s))&&(!t||t.index+t[0].length!==s.length);)(!t||g.index+g[0].length!==t.index+t[0].length)&&(t=g),u.lastIndex=g.index+g[1].length+g[2].length;u.lastIndex=-1}if(t===null)return null;let n=t[2],i=t[3]||"0",o=t[4]||"0",a=e.includePrerelease&&t[5]?`-${t[5]}`:"",c=e.includePrerelease&&t[6]?`+${t[6]}`:"";return $n(`${n}.${i}.${o}${a}${c}`,e)};ft.exports=xn});var Kt=x(v=>{"use strict";Object.defineProperty(v,"__esModule",{value:!0});var I=require("obsidian"),qe="YYYY-MM-DD",Ye="gggg-[W]ww",Mt="YYYY-MM",Vt="YYYY-[Q]Q",Ut="YYYY";function oe(s){var t,n;let e=window.app.plugins.getPlugin("periodic-notes");return e&&((n=(t=e.settings)==null?void 0:t[s])==null?void 0:n.enabled)}function re(){var s,e,t,n;try{let{internalPlugins:i,plugins:o}=window.app;if(oe("daily")){let{format:g,folder:m,template:l}=((e=(s=o.getPlugin("periodic-notes"))==null?void 0:s.settings)==null?void 0:e.daily)||{};return{format:g||qe,folder:(m==null?void 0:m.trim())||"",template:(l==null?void 0:l.trim())||""}}let{folder:a,format:c,template:u}=((n=(t=i.getPluginById("daily-notes"))==null?void 0:t.instance)==null?void 0:n.options)||{};return{format:c||qe,folder:(a==null?void 0:a.trim())||"",template:(u==null?void 0:u.trim())||""}}catch(i){console.info("No custom daily note settings found!",i)}}function ae(){var s,e,t,n,i,o,a;try{let c=window.app.plugins,u=(s=c.getPlugin("calendar"))==null?void 0:s.options,g=(t=(e=c.getPlugin("periodic-notes"))==null?void 0:e.settings)==null?void 0:t.weekly;if(oe("weekly"))return{format:g.format||Ye,folder:((n=g.folder)==null?void 0:n.trim())||"",template:((i=g.template)==null?void 0:i.trim())||""};let m=u||{};return{format:m.weeklyNoteFormat||Ye,folder:((o=m.weeklyNoteFolder)==null?void 0:o.trim())||"",template:((a=m.weeklyNoteTemplate)==null?void 0:a.trim())||""}}catch(c){console.info("No custom weekly note settings found!",c)}}function le(){var e,t,n,i;let s=window.app.plugins;try{let o=oe("monthly")&&((t=(e=s.getPlugin("periodic-notes"))==null?void 0:e.settings)==null?void 0:t.monthly)||{};return{format:o.format||Mt,folder:((n=o.folder)==null?void 0:n.trim())||"",template:((i=o.template)==null?void 0:i.trim())||""}}catch(o){console.info("No custom monthly note settings found!",o)}}function ue(){var e,t,n,i;let s=window.app.plugins;try{let o=oe("quarterly")&&((t=(e=s.getPlugin("periodic-notes"))==null?void 0:e.settings)==null?void 0:t.quarterly)||{};return{format:o.format||Vt,folder:((n=o.folder)==null?void 0:n.trim())||"",template:((i=o.template)==null?void 0:i.trim())||""}}catch(o){console.info("No custom quarterly note settings found!",o)}}function ce(){var e,t,n,i;let s=window.app.plugins;try{let o=oe("yearly")&&((t=(e=s.getPlugin("periodic-notes"))==null?void 0:e.settings)==null?void 0:t.yearly)||{};return{format:o.format||Ut,folder:((n=o.folder)==null?void 0:n.trim())||"",template:((i=o.template)==null?void 0:i.trim())||""}}catch(o){console.info("No custom yearly note settings found!",o)}}function _t(...s){let e=[];for(let n=0,i=s.length;n<i;n++)e=e.concat(s[n].split("/"));let t=[];for(let n=0,i=e.length;n<i;n++){let o=e[n];!o||o==="."||t.push(o)}return e[0]===""&&t.unshift(""),t.join("/")}function Hn(s){let e=s.substring(s.lastIndexOf("/")+1);return e.lastIndexOf(".")!=-1&&(e=e.substring(0,e.lastIndexOf("."))),e}async function Gn(s){let e=s.replace(/\\/g,"/").split("/");if(e.pop(),e.length){let t=_t(...e);window.app.vault.getAbstractFileByPath(t)||await window.app.vault.createFolder(t)}}async function ge(s,e){e.endsWith(".md")||(e+=".md");let t=I.normalizePath(_t(s,e));return await Gn(t),t}async function Y(s){let{metadataCache:e,vault:t}=window.app,n=I.normalizePath(s);if(n==="/")return Promise.resolve(["",null]);try{let i=e.getFirstLinkpathDest(n,""),o=await t.cachedRead(i),a=window.app.foldManager.load(i);return[o,a]}catch(i){return console.error(`Failed to read the daily note template '${n}'`,i),new I.Notice("Failed to read the daily note template"),["",null]}}function $(s,e="day"){let t=s.clone().startOf(e).format();return`${e}-${t}`}function Ht(s){return s.replace(/\[[^\]]*\]/g,"")}function jn(s,e){if(e==="week"){let t=Ht(s);return/w{1,2}/i.test(t)&&(/M{1,4}/.test(t)||/D{1,4}/.test(t))}return!1}function X(s,e){return Gt(s.basename,e)}function zn(s,e){return Gt(Hn(s),e)}function Gt(s,e){let n={day:re,week:ae,month:le,quarter:ue,year:ce}[e]().format.split("/").pop(),i=window.moment(s,n,!0);if(!i.isValid())return null;if(jn(n,e)&&e==="week"){let o=Ht(n);if(/w{1,2}/i.test(o))return window.moment(s,n.replace(/M{1,4}/g,"").replace(/D{1,4}/g,""),!1)}return i}var Xe=class extends Error{};async function jt(s){let e=window.app,{vault:t}=e,n=window.moment,{template:i,format:o,folder:a}=re(),[c,u]=await Y(i),g=s.format(o),m=await ge(a,g);try{let l=await t.create(m,c.replace(/{{\s*date\s*}}/gi,g).replace(/{{\s*time\s*}}/gi,n().format("HH:mm")).replace(/{{\s*title\s*}}/gi,g).replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi,(r,d,b,w,p,T)=>{let C=n(),N=s.clone().set({hour:C.get("hour"),minute:C.get("minute"),second:C.get("second")});return b&&N.add(parseInt(w,10),p),T?N.format(T.substring(1).trim()):N.format(o)}).replace(/{{\s*yesterday\s*}}/gi,s.clone().subtract(1,"day").format(o)).replace(/{{\s*tomorrow\s*}}/gi,s.clone().add(1,"d").format(o)));return e.foldManager.save(l,u),l}catch(l){console.error(`Failed to create file: '${m}'`,l),new I.Notice("Unable to create new file.")}}function qn(s,e){var t;return(t=e[$(s,"day")])!=null?t:null}function Yn(){let{vault:s}=window.app,{folder:e}=re(),t=s.getAbstractFileByPath(I.normalizePath(e));if(!t)throw new Xe("Failed to find daily notes folder");let n={};return I.Vault.recurseChildren(t,i=>{if(i instanceof I.TFile){let o=X(i,"day");if(o){let a=$(o,"day");n[a]=i}}}),n}var We=class extends Error{};function Xn(){let{moment:s}=window,e=s.localeData()._week.dow,t=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"];for(;e;)t.push(t.shift()),e--;return t}function Wn(s){return Xn().indexOf(s.toLowerCase())}async function zt(s){let{vault:e}=window.app,{template:t,format:n,folder:i}=ae(),[o,a]=await Y(t),c=s.format(n),u=await ge(i,c);try{let g=await e.create(u,o.replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi,(m,l,r,d,b,w)=>{let p=window.moment(),T=s.clone().set({hour:p.get("hour"),minute:p.get("minute"),second:p.get("second")});return r&&T.add(parseInt(d,10),b),w?T.format(w.substring(1).trim()):T.format(n)}).replace(/{{\s*title\s*}}/gi,c).replace(/{{\s*time\s*}}/gi,window.moment().format("HH:mm")).replace(/{{\s*(sunday|monday|tuesday|wednesday|thursday|friday|saturday)\s*:(.*?)}}/gi,(m,l,r)=>{let d=Wn(l);return s.weekday(d).format(r.trim())}));return window.app.foldManager.save(g,a),g}catch(g){console.error(`Failed to create file: '${u}'`,g),new I.Notice("Unable to create new file.")}}function Jn(s,e){var t;return(t=e[$(s,"week")])!=null?t:null}function Kn(){let s={};if(!Yt())return s;let{vault:e}=window.app,{folder:t}=ae(),n=e.getAbstractFileByPath(I.normalizePath(t));if(!n)throw new We("Failed to find weekly notes folder");return I.Vault.recurseChildren(n,i=>{if(i instanceof I.TFile){let o=X(i,"week");if(o){let a=$(o,"week");s[a]=i}}}),s}var Je=class extends Error{};async function qt(s){let{vault:e}=window.app,{template:t,format:n,folder:i}=le(),[o,a]=await Y(t),c=s.format(n),u=await ge(i,c);try{let g=await e.create(u,o.replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi,(m,l,r,d,b,w)=>{let p=window.moment(),T=s.clone().set({hour:p.get("hour"),minute:p.get("minute"),second:p.get("second")});return r&&T.add(parseInt(d,10),b),w?T.format(w.substring(1).trim()):T.format(n)}).replace(/{{\s*date\s*}}/gi,c).replace(/{{\s*time\s*}}/gi,window.moment().format("HH:mm")).replace(/{{\s*title\s*}}/gi,c));return window.app.foldManager.save(g,a),g}catch(g){console.error(`Failed to create file: '${u}'`,g),new I.Notice("Unable to create new file.")}}function Qn(s,e){var t;return(t=e[$(s,"month")])!=null?t:null}function Zn(){let s={};if(!Xt())return s;let{vault:e}=window.app,{folder:t}=le(),n=e.getAbstractFileByPath(I.normalizePath(t));if(!n)throw new Je("Failed to find monthly notes folder");return I.Vault.recurseChildren(n,i=>{if(i instanceof I.TFile){let o=X(i,"month");if(o){let a=$(o,"month");s[a]=i}}}),s}var Ke=class extends Error{};async function es(s){let{vault:e}=window.app,{template:t,format:n,folder:i}=ue(),[o,a]=await Y(t),c=s.format(n),u=await ge(i,c);try{let g=await e.create(u,o.replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi,(m,l,r,d,b,w)=>{let p=window.moment(),T=s.clone().set({hour:p.get("hour"),minute:p.get("minute"),second:p.get("second")});return r&&T.add(parseInt(d,10),b),w?T.format(w.substring(1).trim()):T.format(n)}).replace(/{{\s*date\s*}}/gi,c).replace(/{{\s*time\s*}}/gi,window.moment().format("HH:mm")).replace(/{{\s*title\s*}}/gi,c));return window.app.foldManager.save(g,a),g}catch(g){console.error(`Failed to create file: '${u}'`,g),new I.Notice("Unable to create new file.")}}function ts(s,e){var t;return(t=e[$(s,"quarter")])!=null?t:null}function ns(){let s={};if(!Wt())return s;let{vault:e}=window.app,{folder:t}=ue(),n=e.getAbstractFileByPath(I.normalizePath(t));if(!n)throw new Ke("Failed to find quarterly notes folder");return I.Vault.recurseChildren(n,i=>{if(i instanceof I.TFile){let o=X(i,"quarter");if(o){let a=$(o,"quarter");s[a]=i}}}),s}var Qe=class extends Error{};async function ss(s){let{vault:e}=window.app,{template:t,format:n,folder:i}=ce(),[o,a]=await Y(t),c=s.format(n),u=await ge(i,c);try{let g=await e.create(u,o.replace(/{{\s*(date|time)\s*(([+-]\d+)([yqmwdhs]))?\s*(:.+?)?}}/gi,(m,l,r,d,b,w)=>{let p=window.moment(),T=s.clone().set({hour:p.get("hour"),minute:p.get("minute"),second:p.get("second")});return r&&T.add(parseInt(d,10),b),w?T.format(w.substring(1).trim()):T.format(n)}).replace(/{{\s*date\s*}}/gi,c).replace(/{{\s*time\s*}}/gi,window.moment().format("HH:mm")).replace(/{{\s*title\s*}}/gi,c));return window.app.foldManager.save(g,a),g}catch(g){console.error(`Failed to create file: '${u}'`,g),new I.Notice("Unable to create new file.")}}function is(s,e){var t;return(t=e[$(s,"year")])!=null?t:null}function os(){let s={};if(!Jt())return s;let{vault:e}=window.app,{folder:t}=ce(),n=e.getAbstractFileByPath(I.normalizePath(t));if(!n)throw new Qe("Failed to find yearly notes folder");return I.Vault.recurseChildren(n,i=>{if(i instanceof I.TFile){let o=X(i,"year");if(o){let a=$(o,"year");s[a]=i}}}),s}function rs(){var n,i;let{app:s}=window,e=s.internalPlugins.plugins["daily-notes"];if(e&&e.enabled)return!0;let t=s.plugins.getPlugin("periodic-notes");return t&&((i=(n=t.settings)==null?void 0:n.daily)==null?void 0:i.enabled)}function Yt(){var t,n;let{app:s}=window;if(s.plugins.getPlugin("calendar"))return!0;let e=s.plugins.getPlugin("periodic-notes");return e&&((n=(t=e.settings)==null?void 0:t.weekly)==null?void 0:n.enabled)}function Xt(){var t,n;let{app:s}=window,e=s.plugins.getPlugin("periodic-notes");return e&&((n=(t=e.settings)==null?void 0:t.monthly)==null?void 0:n.enabled)}function Wt(){var t,n;let{app:s}=window,e=s.plugins.getPlugin("periodic-notes");return e&&((n=(t=e.settings)==null?void 0:t.quarterly)==null?void 0:n.enabled)}function Jt(){var t,n;let{app:s}=window,e=s.plugins.getPlugin("periodic-notes");return e&&((n=(t=e.settings)==null?void 0:t.yearly)==null?void 0:n.enabled)}function as(s){let e={day:re,week:ae,month:le,quarter:ue,year:ce}[s];return e()}function ls(s,e){return{day:jt,month:qt,week:zt}[s](e)}v.DEFAULT_DAILY_NOTE_FORMAT=qe;v.DEFAULT_MONTHLY_NOTE_FORMAT=Mt;v.DEFAULT_QUARTERLY_NOTE_FORMAT=Vt;v.DEFAULT_WEEKLY_NOTE_FORMAT=Ye;v.DEFAULT_YEARLY_NOTE_FORMAT=Ut;v.appHasDailyNotesPluginLoaded=rs;v.appHasMonthlyNotesPluginLoaded=Xt;v.appHasQuarterlyNotesPluginLoaded=Wt;v.appHasWeeklyNotesPluginLoaded=Yt;v.appHasYearlyNotesPluginLoaded=Jt;v.createDailyNote=jt;v.createMonthlyNote=qt;v.createPeriodicNote=ls;v.createQuarterlyNote=es;v.createWeeklyNote=zt;v.createYearlyNote=ss;v.getAllDailyNotes=Yn;v.getAllMonthlyNotes=Zn;v.getAllQuarterlyNotes=ns;v.getAllWeeklyNotes=Kn;v.getAllYearlyNotes=os;v.getDailyNote=qn;v.getDailyNoteSettings=re;v.getDateFromFile=X;v.getDateFromPath=zn;v.getDateUID=$;v.getMonthlyNote=Qn;v.getMonthlyNoteSettings=le;v.getPeriodicNoteSettings=as;v.getQuarterlyNote=ts;v.getQuarterlyNoteSettings=ue;v.getTemplateInfo=Y;v.getWeeklyNote=Jn;v.getWeeklyNoteSettings=ae;v.getYearlyNote=is;v.getYearlyNoteSettings=ce});var us={};an(us,{default:()=>ke});module.exports=un(us);var en=require("obsidian");var k=require("obsidian");var J=require("obsidian"),Se=class extends J.Modal{constructor(t,n){super(t.app);this.resolve=n;this.isConfirmed=!1;let i={app:t.app,cancelButtonText:"Cancel",cssClass:"",message:t.message,okButtonText:"OK",title:""};this.options={...i,...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 J.ButtonComponent(this.contentEl);t.setClass("ok-button"),t.setButtonText(this.options.okButtonText),t.setCta(),t.onClick(()=>{this.isConfirmed=!0,this.close()});let n=new J.ButtonComponent(this.contentEl);n.setButtonText(this.options.cancelButtonText),n.onClick(this.close.bind(this))}};async function De(s){return await new Promise(e=>{new Se(s,e).open()})}var D=class extends Error{constructor(t,n,i,o){let a=Math.ceil((i-Math.floor(Date.now()/1e3))/60);super(`GitHub API rate limit exceeded. Reset in ${a} minutes.`);this.limit=t;this.remaining=n;this.reset=i;this.requestUrl=o}getMinutesToReset(){return Math.ceil((this.reset-Math.floor(Date.now()/1e3))/60)}},O=class extends Error{constructor(e){var n,i;super(`GitHub API error ${e}: ${e.message}`),this.message=e.message;let t=e;this.status=(n=t.status)!=null?n:400,this.headers=(i=t.headers)!=null?i:{},this.name="GitHubResponseError"}};var V=require("obsidian");var On=Ue(),bt=_e();var ye=s=>{let e=s.replace(/https?:\/\/github\.com\//i,"");return e.endsWith("/")&&(e=e.slice(0,-1)),e.toLowerCase().endsWith(".git")&&(e=e.slice(0,-4)),e},wt=["ghp_","github_pat_"],Fn=/^(gh[ps]_[a-zA-Z0-9]{36}|github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59})$/,Tt=async(s,e)=>{var o,a,c,u,g,m,l,r,d,b,w;let t=["repo","public_repo","metadata=read"],n=wt.some(p=>s.toLowerCase().startsWith(p.toLowerCase())),i=Fn.test(s);if(!n||!i)return{validToken:!1,currentScopes:[],acceptedScopes:[],acceptedPermissions:[],expirationDate:null,rateLimit:{limit:0,remaining:0,reset:0,resource:"",used:0},error:{type:n?"invalid_format":"invalid_prefix",message:"Invalid token format",details:{validPrefixes:wt}}};try{let p=Date.now()%1e3,T=e||`user${p}/repo${p%100}`;if(await ve({url:`https://api.github.com/repos/${T}`,headers:{Authorization:`Token ${s}`,Accept:"application/vnd.github.v3+json"}}),e)return{validToken:!0,currentScopes:[],acceptedScopes:[],acceptedPermissions:[],expirationDate:null,rateLimit:{limit:0,remaining:0,reset:0,resource:"",used:0},error:{type:"none",message:"No error",details:{}}};throw new Error("Expected request to fail")}catch(p){if(!(p instanceof O))throw p;let T=p.headers;if(!T)throw new Error("No headers in GitHub response");let C=T["github-authentication-token-expiration"],N=C?new Date(C):null,R=N&&!Number.isNaN(N.getTime())?N.toISOString():null,P={validToken:!1,currentScopes:(a=(o=T["x-oauth-scopes"])==null?void 0:o.split(", "))!=null?a:[],acceptedScopes:(u=(c=T["x-accepted-oauth-scopes"])==null?void 0:c.split(", "))!=null?u:[],acceptedPermissions:(m=(g=T["x-accepted-github-permissions"])==null?void 0:g.split(", "))!=null?m:[],expirationDate:R,rateLimit:{limit:Number.parseInt((l=T["x-ratelimit-limit"])!=null?l:"0",10),remaining:Number.parseInt((r=T["x-ratelimit-remaining"])!=null?r:"0",10),reset:Number.parseInt((d=T["x-ratelimit-reset"])!=null?d:"0",10),resource:(b=T["x-ratelimit-resource"])!=null?b:"",used:Number.parseInt((w=T["x-ratelimit-used"])!=null?w:"0",10)},error:{type:"none",message:"No error",details:{}}};return P.expirationDate&&new Date(P.expirationDate)<new Date?(P.error={type:"expired",message:"Token has expired",details:{expirationDate:P.expirationDate}},P):P.currentScopes.some(M=>t.includes(M))||P.acceptedPermissions.some(M=>t.includes(M))?(P.validToken=p.status===404,P):(P.error={type:"insufficient_scope",message:"Token lacks required scopes. Check documentation for requirements.",details:{currentScopes:[...P.acceptedScopes,...P.acceptedPermissions]}},P)}},He=async(s,e=!0,t="")=>{let n=`https://api.github.com/repos/${s}`;try{return(await ve({url:n,headers:t?{Authorization:`Token ${t}`}:{}})).json.private}catch(i){if(i instanceof D)throw i;return e&&console.log("error in isPrivateRepo",n,i),!1}},Et=async(s,e=!0,t="")=>{let n=`https://api.github.com/repos/${s}/releases`;try{return(await ve({url:`${n}?per_page=100`,headers:t?{Authorization:`Token ${t}`}:{}})).json.map(a=>({version:a.tag_name,prerelease:a.prerelease}))}catch(i){if(i instanceof D||i instanceof O)throw i;return e&&console.log("Error in fetchReleaseVersions",n,i),null}},K=async(s,e,t=!0,n=!1,i="")=>{try{let o=s.assets.find(g=>g.name===e);if(!o)return null;let a={Accept:"application/octet-stream"};n&&i&&(a.Authorization=`Token ${i}`);let c=n?o.url:o.browser_download_url,u=await(0,V.requestUrl)({url:c,headers:a});return u.status!==200?null:u.text}catch(o){if(o instanceof D)throw o;return t&&console.log("error in grabReleaseFileFromRepository",s,o),null}},yt=async(s=!0)=>{let e="https://raw.githubusercontent.com/obsidianmd/obsidian-releases/HEAD/community-plugins.json";try{let t=await(0,V.requestUrl)({url:e});return t.status===404?null:t.json}catch(t){return s&&console.log("error in grabCommmunityPluginList",t),null}},vt=async(s=!0)=>{let e="https://raw.githubusercontent.com/obsidianmd/obsidian-releases/HEAD/community-css-themes.json";try{let t=await(0,V.requestUrl)({url:e});return t.status===404?null:t.json}catch(t){return s&&console.log("error in grabCommmunityThemesList",t),null}},G=async(s,e=!1,t=!1)=>{let n=`https://raw.githubusercontent.com/${s}/HEAD/theme${e?"-beta":""}.css`;try{let i=await(0,V.requestUrl)({url:n});return i.status===404?null:i.text}catch(i){return t&&console.log("error in grabCommmunityThemeCssFile",i),null}},Pt=async(s,e=!0)=>{let t=`https://raw.githubusercontent.com/${s}/HEAD/manifest.json`;try{let n=await(0,V.requestUrl)({url:t});return n.status===404?null:n.text}catch(n){return e&&console.log("error in grabCommmunityThemeManifestFile",n),null}},Bn=s=>{let e=0;for(let t=0;t<s.length;t++)e+=s.charCodeAt(t);return e},Q=s=>Bn(s).toString(),Z=async(s,e,t)=>{let n=await G(s,e,t);return n?Q(n):"0"},Mn=async(s,e,t=!0)=>{let n=`https://api.github.com/repos/${s}/commits?path=${e}&page=1&per_page=1`;try{let i=await(0,V.requestUrl)({url:n});return i.status===404?null:i.json}catch(i){return t&&console.log("error in grabLastCommitInfoForAFile",i),null}},Rt=async(s,e)=>{var n;let t=await Mn(s,e);return t&&t.length>0&&((n=t[0].commit.committer)!=null&&n.date)?t[0].commit.committer.date:""},Ge=async(s,e,t=!1,n=!1,i=!1,o)=>{var a;try{let c=e&&e!=="latest"?`https://api.github.com/repos/${s}/releases/tags/${e}`:`https://api.github.com/repos/${s}/releases`,u={Accept:"application/vnd.github.v3+json"};(i&&o||o)&&(u.Authorization=`Token ${o}`);let g=await ve({url:c,headers:u});if(g.status===404)return null;let m=e&&e!=="latest"?[g.json]:g.json;return n&&console.log(`grabReleaseFromRepository for ${s}:`,m),(a=m.sort((l,r)=>{try{let d=bt(l.tag_name,{includePrerelease:!0,loose:!0}),b=bt(r.tag_name,{includePrerelease:!0,loose:!0});return On(b,d)}catch(d){let b=new Date(l.published_at).getTime(),w=new Date(r.published_at).getTime();return b<w?1:b>w?-1:0}}).filter(l=>t||!l.prerelease)[0])!=null?a:null}catch(c){throw n&&console.log(`Error in grabReleaseFromRepository for ${s}:`,c),c}},ve=async(s,e)=>{let t=0,n=0,i=0;s.headers={...s.headers,"User-Agent":"Obsidian/BRAT-Plugin"};try{return await(0,V.requestUrl)(s)}catch(o){let a=new O(o),c=a.headers;if(c&&(t=Number.parseInt(c["x-ratelimit-limit"],10),n=Number.parseInt(c["x-ratelimit-remaining"],10),i=Number.parseInt(c["x-ratelimit-reset"],10)),a.status===403&&n===0){let u=new D(t,n,i,s.url);throw e&&console.error(`BRAT
|
|
GitHub API rate limit exceeded:`,`
|
|
Request: ${u.requestUrl}`,`
|
|
Rate limits - Remaining: ${u.remaining}`,`
|
|
Reset in: ${u.getMinutesToReset()} minutes`),u}throw e&&console.log("GitHub request failed:",o),a}};var je={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 It(s,e,t="latest",n=!1,i=""){let o=!1;s.settings.pluginList.contains(e)||(s.settings.pluginList.unshift(e),o=!0);let a=s.settings.pluginSubListFrozenVersion.find(c=>c.repo===e);a?(Object.assign(a,{repo:e,version:t,token:void 0,tokenName:i||a.tokenName,isIncompatible:n||void 0}),o=!0):(s.settings.pluginSubListFrozenVersion.unshift({repo:e,version:t,token:void 0,tokenName:i||void 0,isIncompatible:n||void 0}),o=!0),o&&s.saveSettings()}function Pe(s,e){return s.settings.pluginList.contains(e)}function Nt(s,e,t){let n={repo:e,lastUpdate:Q(t)};s.settings.themesList.unshift(n),s.saveSettings()}function At(s,e){return!!s.settings.themesList.find(n=>n.repo===e)}function ze(s,e,t){let n=s.settings.pluginSubListFrozenVersion.find(i=>i.repo===e);n&&(n.tokenName=t||void 0,s.saveSettings())}function Ct(s,e,t){for(let n of s.settings.themesList)n.repo===e&&(n.lastUpdate=t,s.saveSettings())}var L=require("obsidian");var j=class{constructor(e){this.statusEl=e}async validateToken(e,t){var n,i,o,a,c,u,g,m,l;if(!e)return(n=this.statusEl)==null||n.setText("No token provided"),(i=this.statusEl)==null||i.addClass("invalid"),(o=this.statusEl)==null||o.removeClass("valid"),!1;try{let r=await Tt(e,t);return(a=this.statusEl)==null||a.removeClass("invalid","valid"),(c=this.statusEl)==null||c.empty(),r.validToken?((u=this.statusEl)==null||u.addClass("valid"),this.showValidTokenInfo(r),!0):((g=this.statusEl)==null||g.addClass("invalid"),this.showErrorMessage(r.error),!1)}catch(r){return console.error("Token validation error:",r),(m=this.statusEl)==null||m.setText("Failed to validate token"),(l=this.statusEl)==null||l.addClass("invalid"),!1}}showValidTokenInfo(e){var n,i;let t=(n=this.statusEl)==null?void 0:n.createDiv({cls:"brat-token-details"});if(t&&(t.createDiv({text:"\u2713 Valid token",cls:"brat-token-status valid"}),(i=e.currentScopes)!=null&&i.length&&t.createDiv({text:`Scopes: ${e.currentScopes.join(", ")}`,cls:"brat-token-scopes"}),e.rateLimit&&t.createDiv({text:`Rate Limit: ${e.rateLimit.remaining}/${e.rateLimit.limit}`,cls:"brat-token-rate"}),e.expirationDate)){let o=new Date(e.expirationDate),a=Math.ceil((o.getTime()-Date.now())/(1e3*60*60*24));a<7&&t.createDiv({text:`\u26A0\uFE0F Token expires in ${a} days`,cls:"brat-token-warning"})}}showErrorMessage(e){var n,i,o;let t=(n=this.statusEl)==null?void 0:n.createDiv({cls:"brat-token-error"});if(t&&(t.createDiv({text:e.message}),e.details))switch(e.type){case"invalid_prefix":t.createDiv({text:`Valid prefixes: ${(i=e.details.validPrefixes)==null?void 0:i.join(", ")}`});break;case"insufficient_scope":t.createDiv({text:`Required scopes: ${(o=e.details.requiredScopes)==null?void 0:o.join(", ")}`});break}}};function ee(s,e){let t=new DocumentFragment,n=document.createElement("a");if(n.textContent=s,n.href=`https://github.com/${s}`,n.target="_blank",t.appendChild(n),e){let i=document.createTextNode(e);t.appendChild(i)}return t}function Lt({prependText:s,url:e,text:t,appendText:n}){let i=new DocumentFragment,o=document.createElement("a");if(o.textContent=t,o.href=e,s){let a=document.createTextNode(s);i.appendChild(a)}if(i.appendChild(o),n){let a=document.createTextNode(n);i.appendChild(a)}return i}var Re=require("obsidian");function E(s,e,t=10,n){if(!s.settings.notificationsEnabled)return;let i=n?Re.Platform.isDesktop?"(click=dismiss, right-click=Info)":"(click=dismiss)":"",o=new Re.Notice(`BRAT
|
|
${e}
|
|
${i}`,t*1e3);n&&(o.noticeEl.oncontextmenu=()=>{n()})}var z=(s,e=!0)=>{let t=s.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 n=t.createDiv("coffee");n.addClass("ex-twitter-span"),n.style.paddingLeft="10px";let i=n.createDiv();i.innerText="Learn more about my work at:",n.appendChild(i);let o=n.createEl("a",{href:"https://tfthacker.com"});return o.innerText="https://tfthacker.com",t};var kt=require("obsidian"),Ie=class extends kt.SuggestModal{constructor(e,t,n,i,o){super(e),this.versions=n,this.selected=i,this.onChoose=o,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(n=>n.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 U=class extends L.Modal{constructor(t,n,i=!1,o=!1,a="",c="",u=""){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=n,this.address=a,this.version=c,this.secretName=u,this.openSettingsTabAfterwards=i,this.updateVersion=o,this.enableAfterInstall=t.settings.enableAfterInstall}async submitForm(){var o,a,c,u,g,m,l,r;if(this.address==="")return;let t=ye(this.address);if(this.plugin.settings.pluginSubListFrozenVersion.find(d=>d.repo===t)){await this.betaPlugins.addPlugin(t,!1,!1,!1,this.version,!0,this.enableAfterInstall,this.secretName)&&this.close(),(o=this.cancelButton)==null||o.setDisabled(!1),(a=this.addPluginButton)==null||a.setDisabled(!1),(c=this.addPluginButton)==null||c.setButtonText("Add Plugin"),(u=this.versionSetting)==null||u.setDisabled(!1);return}if(!this.version&&Pe(this.plugin,t)){E(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(),(g=this.cancelButton)==null||g.setDisabled(!1),(m=this.addPluginButton)==null||m.setDisabled(!1),(l=this.addPluginButton)==null||l.setButtonText("Add Plugin"),(r=this.versionSetting)==null||r.setDisabled(!1)}updateVersionDropdown(t,n,i=""){let o;t.clear(),n.length>0&&!i&&this.plugin.settings.selectLatestPluginVersionByDefault?(o="latest",this.version="latest"):o=i,n.length<20||L.Platform.isMobile?t.addDropdown(c=>{c.addOption("","Select a version"),c.addOption("latest","Latest version");for(let u of n)c.addOption(u.version,`${u.version} ${u.prerelease?"(Prerelease)":""}`);c.onChange(u=>{var g;this.version=u,(g=this.addPluginButton)==null||g.setDisabled(this.version==="")}),c.setValue(o),c.selectEl.addClass("brat-version-selector"),c.selectEl.style.width="100%"}):t.addButton(c=>{c.setButtonText(o==="latest"?"Latest version":o||"Select a version...").setClass("brat-version-selector").setClass("button").onClick(()=>{let g=[{version:"latest",prerelease:!1},...n];new Ie(this.app,this.address,g,o,l=>{var r;this.version=l,c.setButtonText(l==="latest"?"Latest version":l||"Select a version..."),(r=this.addPluginButton)==null||r.setDisabled(this.version==="")}).open()})})}onOpen(){let t=this.contentEl.createEl("h4");this.address?(t.appendText("Change plugin version: "),t.appendChild(ee(this.address))):t.setText("Github repository for beta plugin:"),this.contentEl.createEl("form",{},n=>{var g;n.addClass("brat-modal"),(!this.address||!this.updateVersion)&&new L.Setting(n).setClass("repository-setting").then(l=>{l.addText(r=>{this.repositoryAddressEl=r,r.setPlaceholder("Repository (example: https://github.com/GitHubUserName/repository-name)"),r.setValue(this.address),r.onChange(d=>{var b,w;this.address=ye(d.trim()),this.version!==""&&(!this.address||!this.isGitHubRepositoryMatch(this.address))&&this.versionSetting&&(this.updateVersionDropdown(this.versionSetting,[]),this.versionSetting.settingEl.classList.add("disabled-setting"),this.versionSetting.setDisabled(!0),r.inputEl.classList.remove("valid-repository"),r.inputEl.classList.remove("invalid-repository")),this.version||(this.isGitHubRepositoryMatch(this.address)?(b=this.addPluginButton)==null||b.setDisabled(!1):(w=this.addPluginButton)==null||w.setDisabled(!0))}),r.inputEl.addEventListener("keydown",async d=>{var b,w,p;d.key==="Enter"&&(this.address&&(this.updateVersion&&this.version!==""||!this.updateVersion)&&(d.preventDefault(),(b=this.addPluginButton)==null||b.setDisabled(!0),(w=this.cancelButton)==null||w.setDisabled(!0),(p=this.versionSetting)==null||p.setDisabled(!0),this.submitForm()),await this.updateRepositoryVersionInfo(this.version,i))}),r.inputEl.addEventListener("blur",async()=>{await this.updateRepositoryVersionInfo(this.version,i)}),l.setDesc("Repository"),r.inputEl.style.width="100%"})});let i=n.createDiv("validation-status");this.address||i.setText("Enter a GitHub repository address to validate it."),this.versionSetting=new L.Setting(n).setClass("version-setting").setClass("disabled-setting"),this.updateVersionDropdown(this.versionSetting,[],this.version),this.versionSetting.setDisabled(!0);let o=n.createDiv("token-setting");if(new L.Setting(o).setName("GitHub Token").setDesc("Select a secret as token for this repository (optional)").addComponent(m=>new L.SecretComponent(this.plugin.app,m).setValue(this.secretName).onChange(async l=>{var d,b,w,p,T;if(this.secretName=(l==null?void 0:l.trim())||"",!this.secretName){this.address&&Pe(this.plugin,this.address)&&(ze(this.plugin,this.address,""),E(this.plugin,`Token setting cleared for ${this.address}`,3)),this.updateRepositoryVersionInfo(this.version,i);return}let r=this.secretName?this.plugin.app.secretStorage.getSecret(this.secretName):null;r&&(this.validToken=await((d=this.validator)==null?void 0:d.validateToken(r,this.address)),this.validToken?((p=this.validateButton)==null||p.setButtonText("Valid"),(T=this.validateButton)==null||T.setDisabled(!0),this.address&&(await this.updateRepositoryVersionInfo(this.version,i),Pe(this.plugin,this.address)&&(ze(this.plugin,this.address,this.secretName),E(this.plugin,`Token setting updated for ${this.address}`,3)))):((b=this.validateButton)==null||b.setButtonText("Invalid"),(w=this.validateButton)==null||w.setDisabled(!1)))})),this.validator=new j,this.secretName){let m=this.plugin.app.secretStorage.getSecret(this.secretName);m&&((g=this.validator)==null||g.validateToken(m,this.address).then(l=>{var r,d;this.validToken=l,this.validToken&&((r=this.validateButton)==null||r.setButtonText("Valid"),(d=this.validateButton)==null||d.setDisabled(!0))}))}n.createDiv("modal-button-container",m=>{var l;m.createEl("label",{cls:"mod-checkbox"},r=>{let d=r.createEl("input",{attr:{tabindex:-1},type:"checkbox"});d.checked=this.enableAfterInstall,d.addEventListener("click",()=>{this.enableAfterInstall=d.checked}),r.appendText("Enable after installing the plugin")}),this.cancelButton=new L.ButtonComponent(m).setButtonText("Never mind").setClass("mod-cancel").onClick(()=>{this.close()}),this.addPluginButton=new L.ButtonComponent(m).setButtonText(this.updateVersion&&this.address?"Change version":"Add plugin").setCta().onClick(()=>{var r,d,b,w;this.address!==""&&(this.updateVersion&&this.version!==""||!this.updateVersion)&&((r=this.addPluginButton)==null||r.setDisabled(!0),(d=this.addPluginButton)==null||d.setButtonText("Installing \u2026"),(b=this.cancelButton)==null||b.setDisabled(!0),(w=this.versionSetting)==null||w.setDisabled(!0),this.submitForm())}),(this.updateVersion||this.address==="")&&((l=this.addPluginButton)==null||l.setDisabled(!0))});let a=n.createDiv();a.style.borderTop="1px solid #ccc",a.style.marginTop="30px";let c=a.createSpan();c.createEl("a",{href:"https://bit.ly/o42-twitter",text:"TFTHacker"}),c.appendText(" and "),c.createEl("a",{href:"https://github.com/johannrichard",text:"johannrichard"}),c.style.fontStyle="italic",a.appendChild(c),z(a,!1);let u=n.querySelectorAll("button");for(let m of Array.from(u))m.setAttribute("type","button");n.addEventListener("submit",m=>{var l;m.preventDefault(),this.address!==""&&(this.updateVersion&&this.version!==""||!this.updateVersion)&&((l=this.addPluginButton)==null||l.setDisabled(!0),this.submitForm())})}),this.address&&window.setTimeout(async()=>{await this.updateRepositoryVersionInfo(this.version)},100)}async updateRepositoryVersionInfo(t="",n){var a,c,u,g,m,l;let i=this.repositoryAddressEl;if(this.plugin.settings.debuggingMode&&console.log(`[BRAT] Updating version dropdown for ${this.address} with selected version ${t}`),!this.address){n==null||n.setText("Repository address is required."),n==null||n.addClass("validation-status-error");return}n==null||n.setText("Validating repository address..."),n==null||n.removeClass("validation-status-error"),this.versionSetting&&this.updateVersion&&this.updateVersionDropdown(this.versionSetting,[]);let o=ye(this.address);try{let r="";if(this.secretName){let b=this.plugin.app.secretStorage.getSecret(this.secretName);b&&(r=b)}else if(this.plugin.settings.globalTokenName){let b=this.plugin.app.secretStorage.getSecret(this.plugin.settings.globalTokenName);b&&(r=b)}let d=await Et(o,this.plugin.settings.debuggingMode,r);d&&d.length>0?(i==null||i.inputEl.classList.remove("invalid-repository"),i==null||i.inputEl.classList.add("valid-repository"),n==null||n.setText(""),this.versionSetting&&(this.versionSetting.settingEl.classList.remove("disabled-setting"),this.versionSetting.setDisabled(!1),this.updateVersionDropdown(this.versionSetting,d,t))):(i==null||i.inputEl.classList.remove("valid-repository"),i==null||i.inputEl.classList.add("invalid-repository"),n==null||n.setText("Error: No releases found in this repository."),n==null||n.addClass("validation-status-error"),(a=this.versionSetting)==null||a.settingEl.classList.add("disabled-setting"),(c=this.versionSetting)==null||c.setDisabled(!0),(u=this.addPluginButton)==null||u.setDisabled(!0))}catch(r){if(r instanceof D&&(i==null||i.inputEl.classList.remove("valid-repository"),i==null||i.inputEl.classList.add("validation-error"),n==null||n.setText(`GitHub API rate limit exceeded. Try again in ${r.getMinutesToReset()} minutes.`),this.versionSetting&&(this.versionSetting.settingEl.classList.add("disabled-setting"),this.versionSetting.setDisabled(!0),(g=this.addPluginButton)==null||g.setDisabled(!0)),E(this.plugin,`${r.message} Consider adding a personal access token in BRAT settings for higher limits. See documentation for details.`,20,()=>{window.open("https://github.com/TfTHacker/obsidian42-brat/blob/main/BRAT-DEVELOPER-GUIDE.md#github-api-rate-limits")})),r instanceof O){let d=r;switch(d.status){case 404:n==null||n.setText("Repository not found. Check the address or provide a valid token for access to a private repository.");break;case 403:n==null||n.setText("Access denied. Check your personal access token.");break;default:n==null||n.setText(`Error: ${d.message}`);break}n==null||n.addClass("validation-status-error"),(m=this.versionSetting)==null||m.setDisabled(!0),(l=this.addPluginButton)==null||l.setDisabled(!0),E(this.plugin,`${d.message} `,20)}}}onClose(){this.openSettingsTabAfterwards&&(this.plugin.app.setting.open(),this.plugin.app.setting.openTabById(this.plugin.APP_ID))}isGitHubRepositoryMatch(t){let n=t.trim().replace(/\.git$/,"").toLowerCase();return/^(?:https?:\/\/github\.com\/)?([a-zA-Z0-9._-]+)\/([a-zA-Z0-9._-]+)$/i.test(n)}};var St=require("obsidian");async function Ne(){try{let s=await(0,St.requestUrl)(`https://obsidian.md/?${Math.random()}`);return s.status>=200&&s.status<300}catch(s){return!1}}var Dt=Ue(),Ae=_e(),te=class{constructor(e){this.plugin=e}displayAddNewPluginModal(e=!1,t=!1,n="",i="",o=""){new U(this.plugin,this,e,t,n,i,o).open()}async validateRepository(e,t=!1,n=!1,i="",o=""){let c=o;try{let u=await He(e,this.plugin.settings.debuggingMode,c),g=await Ge(e,i,t,this.plugin.settings.debuggingMode,u,c);if(!g)return n&&(E(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,t,n)),null;let m=await K(g,"manifest.json",this.plugin.settings.debuggingMode,u,c);if(!m)return n&&(E(this.plugin,`${e}
|
|
This does not seem to be an obsidian plugin, as there is no manifest.json file.`,15),console.error("BRAT: validateRepository",e,t,n)),null;let l=JSON.parse(m);if(!("id"in l))return n&&E(this.plugin,`${e}
|
|
The plugin id attribute for the release is missing from the manifest file`,15),null;if(!("version"in l))return n&&E(this.plugin,`${e}
|
|
The version attribute for the release is missing from the manifest file`,15),null;try{let r=Ae(g.tag_name,{includePrerelease:!0,loose:!0}),d=Ae(l.version,{includePrerelease:!0,loose:!0});Dt(r,d)!==0&&(n&&E(this.plugin,`${e}
|
|
Version mismatch detected:
|
|
Release tag version: ${g.tag_name}
|
|
Manifest version: ${l.version}
|
|
|
|
The release tag version will be used to ensure consistency.`,15),l.version=r.version)}catch(r){}return l}catch(u){if(u instanceof D){let g=`GitHub API rate limit exceeded. Reset in ${u.getMinutesToReset()} minutes.`;throw n&&E(this.plugin,g,15),console.error(`BRAT: validateRepository ${u}`),E(this.plugin,`${u.message} Consider adding a personal access token in BRAT settings for higher limits. See documentation for details.`,20,()=>{window.open("https://github.com/TfTHacker/obsidian42-brat/blob/main/BRAT-DEVELOPER-GUIDE.md#github-api-rate-limits")}),u}if(u instanceof O)throw n&&(u.status===401?E(this.plugin,`${e}
|
|
GitHub API Authentication error. Please verify that your personal access token is valid and set correctly.`,15):E(this.plugin,`${e}
|
|
GitHub API error ${u.status}: ${u.message}`,15)),console.error(`BRAT: validateRepository ${u}`),u;return n&&E(this.plugin,`${e}
|
|
Unspecified error encountered: ${u}, verify debug for more information.`,15),null}}async getAllReleaseFiles(e,t,n="",i=""){let o=i,a=await He(e,this.plugin.settings.debuggingMode,o),c=await Ge(e,n,t,this.plugin.settings.debuggingMode,a,o);if(!c)return Promise.reject("No release found");let u=t||n!=="";return console.log({reallyGetManifestOrNot:u,version:c.tag_name}),{mainJs:await K(c,"main.js",this.plugin.settings.debuggingMode,a,o),manifest:u?await K(c,"manifest.json",this.plugin.settings.debuggingMode,a,o):"",styles:await K(c,"styles.css",this.plugin.settings.debuggingMode,a,o)}}async writeReleaseFilesToPluginFolder(e,t){var o,a;let n=`${(0,k.normalizePath)(`${this.plugin.app.vault.configDir}/plugins/${e}`)}/`,{adapter:i}=this.plugin.app.vault;await i.exists(n)||await i.mkdir(n),await i.write(`${n}main.js`,(o=t.mainJs)!=null?o:""),await i.write(`${n}manifest.json`,(a=t.manifest)!=null?a:""),t.styles&&await i.write(`${n}styles.css`,t.styles)}async addPlugin(e,t=!1,n=!1,i=!1,o="",a=!1,c=this.plugin.settings.enableAfterInstall,u=""){try{this.plugin.settings.debuggingMode&&console.log("BRAT: addPlugin",e,t,n,i,o,a,c,u?"with secret":"public");let g="";u&&u.trim()!==""?(g=await this.plugin.app.secretStorage.getSecret(u)||"",g||E(this.plugin,`Secret not found for token name: ${u}. Please add it to SecretStorage or clear the token name for this plugin.`,10)):this.plugin.settings.globalTokenName&&(g=await this.plugin.app.secretStorage.getSecret(this.plugin.settings.globalTokenName)||"");let m=10,l=await this.validateRepository(e,!0,!0,o,g),r=!!l;if(r||(l=await this.validateRepository(e,!1,!0,o,g)),l===null){let w=`${e}
|
|
A manifest.json file does not exist in the latest release of the repository. This plugin cannot be installed.`;return await this.plugin.log(w,!0),E(this.plugin,w,m),!1}if(!Object.hasOwn(l,"version")){let w=`${e}
|
|
The manifest.json file in the latest release or pre-release of the repository does not have a version number in the file. This plugin cannot be installed.`;return await this.plugin.log(w,!0),E(this.plugin,w,m),!1}let d=!1;if(Object.hasOwn(l,"minAppVersion")&&!(0,k.requireApiVersion)(l.minAppVersion)){if(o===""||o==="latest"||!this.plugin.settings.allowIncompatiblePlugins){let p=`Plugin: ${e}
|
|
|
|
The manifest.json for this plugin indicates that the Obsidian version of the app needs to be ${l.minAppVersion}, but this installation of Obsidian is ${k.apiVersion}.
|
|
|
|
You will need to update your Obsidian to use this plugin or contact the plugin developer for more information.`;return await this.plugin.log(p,!0),E(this.plugin,p,30),!1}if(!await De({app:this.plugin.app,message:createFragment(p=>{p.appendText("Plugin: "),p.createEl("code",{text:e}),p.createEl("br"),p.appendText("The "),p.createEl("code",{text:"manifest.json"}),p.appendText(" for this plugin indicates that the Obsidian version of the app needs to be "),p.createEl("code",{text:l.minAppVersion}),p.appendText(", but this installation of Obsidian is "),p.createEl("code",{text:k.apiVersion}),p.appendText("."),p.createEl("br"),p.appendText("Using this plugin is not recommended and may not work as expected. Use at your own risk."),p.createEl("br"),p.appendText("Do you want to install it anyways?")})}))return!1;d=!0}let b=async()=>{var T,C;let w=await this.getAllReleaseFiles(e,r,o,g);console.log("rFiles",w),(r||w.manifest==="")&&(w.manifest=JSON.stringify(l));let p=JSON.parse((T=w.manifest)!=null?T:"");if(d&&(p.brat={isIncompatible:!0,minAppVersionOriginal:p.minAppVersion},p.minAppVersion=k.apiVersion),k.Platform.isMobile&&p.isDesktopOnly)if(this.plugin.settings.allowIncompatiblePlugins){if(!await De({app:this.plugin.app,message:createFragment(R=>{R.appendText("Plugin: "),R.createEl("code",{text:e}),R.createEl("br"),R.appendText("The "),R.createEl("code",{text:"manifest.json"}),R.appendText(" for this plugin indicates that the plugin has "),R.createEl("code",{text:"isDesktopOnly: true"}),R.appendText(", but you are using a mobile device."),R.createEl("br"),R.appendText("Using this plugin is not recommended and may not work as expected. Use at your own risk."),R.createEl("br"),R.appendText("Do you want to forcefully run it on mobile anyways?")})}))return null;p.isDesktopOnly=!1,(C=p.brat)!=null||(p.brat={}),p.brat.isDesktopOnlyOriginal=!0,p.brat.isIncompatible=!0,d=!0}else{let N=`Plugin: ${e}
|
|
|
|
The manifest.json for this plugin indicates that the plugin has isDesktopOnly: true, but you are using a mobile device.
|
|
|
|
The plugin will not be installed.`;return await this.plugin.log(N,!0),E(this.plugin,N,30),null}if(d&&(w.manifest=JSON.stringify(p)),this.plugin.settings.debuggingMode&&console.log("BRAT: rFiles.manifest",r,w),w.mainJs===null){let N=`${e}
|
|
The release is not complete and cannot be downloaded. main.js is missing from the Release`;return await this.plugin.log(N,!0),E(this.plugin,N,m),null}return w};if(!t||a){let w=await b();if(w===null)return!1;if(await this.writeReleaseFilesToPluginFolder(l.id,w),It(this.plugin,e,o,d,u),c){let{plugins:p}=this.plugin.app,T=(0,k.normalizePath)(`${p.getPluginFolder()}/${l.id}`);await p.loadManifest(T),await p.enablePluginAndSave(l.id)}if(await this.plugin.app.plugins.loadManifests(),a)await this.reloadPlugin(l.id),await this.plugin.log(`${e} reinstalled`,!0),E(this.plugin,`${e}
|
|
Plugin has been reinstalled and reloaded with version ${l.version}`,m);else{let p=o===""?"":` (version: ${o})`,T=`${e}${p}
|
|
The plugin has been registered with BRAT.`;c||(T+=" You may still need to enable it the Community Plugin List."),await this.plugin.log(T,!0),E(this.plugin,T,m)}}else{let w=`${this.plugin.app.vault.configDir}/plugins/${l.id}/`,p="";try{p=await this.plugin.app.vault.adapter.read(`${w}manifest.json`)}catch(R){if(R.errno===-4058||R.errno===-2)return await this.addPlugin(e,!1,r,!1,o,!1,c,u),!0;console.log("BRAT - Local Manifest Load",l.id,JSON.stringify(R,null,2))}if(o!==""&&o!=="latest")return E(this.plugin,`The version of ${e} is frozen, not updating.`,3),!1;let T=await JSON.parse(p),C=Ae(T.version,{includePrerelease:!0,loose:!0}),N=Ae(l.version,{includePrerelease:!0,loose:!0});if(Dt(C,N)===-1){let R=await b();if(R===null)return!1;if(n){let W=`There is an update available for ${l.id} from version ${T.version} to ${l.version}. `;return await this.plugin.log(`${W}[Release Info](https://github.com/${e}/releases/tag/${l.version})`,!0),E(this.plugin,W,30,()=>{l&&window.open(`https://github.com/${e}/releases/tag/${l.version}`)}),!1}await this.writeReleaseFilesToPluginFolder(l.id,R),await this.plugin.app.plugins.loadManifests(),await this.reloadPlugin(l.id);let P=`${l.id}
|
|
Plugin has been updated from version ${T.version} to ${l.version}. `;return await this.plugin.log(`${P}[Release Info](https://github.com/${e}/releases/tag/${l.version})`,!0),E(this.plugin,P,30,()=>{l&&window.open(`https://github.com/${e}/releases/tag/${l.version}`)}),!0}return i&&E(this.plugin,`No update available for ${e}`,3),!0}}catch(g){console.error(`BRAT: Error adding plugin ${e}:`,{error:g,updatePluginFiles:t,seeIfUpdatedOnly:n,specifyVersion:o,forceReinstall:a});let m=g instanceof Error?g.message:"Unknown error occurred";return await this.plugin.log(`Error ${t?"updating":"adding"} plugin ${e}: ${m}`,!0),!1}return!0}async reloadPlugin(e){let{plugins:t}=this.plugin.app;try{await t.disablePlugin(e),await t.enablePlugin(e)}catch(n){this.plugin.settings.debuggingMode&&console.log("reload plugin",n)}}async updatePlugin(e,t=!1,n=!1,i=!1,o=""){let a=await this.addPlugin(e,!0,t,n,"",i,!1,o);return!a&&!t&&E(this.plugin,`${e}
|
|
Update of plugin failed.`),a}async checkForPluginUpdatesAndInstallUpdates(e=!1,t=!1){if(!await Ne()){console.log("BRAT: No internet detected.");return}let n,i="Checking for plugin updates STARTED";await this.plugin.log(i,!0),e&&this.plugin.settings.notificationsEnabled&&(n=new k.Notice(`BRAT
|
|
${i}`,3e4));let o=new Map(this.plugin.settings.pluginSubListFrozenVersion.map(u=>[u.repo,u.version])),a=new Map(this.plugin.settings.pluginSubListFrozenVersion.map(u=>[u.repo,u.tokenName||""]));for(let u of this.plugin.settings.pluginList){let g=o.get(u);g&&g!=="latest"||await this.updatePlugin(u,t,!1,!1,a.get(u)||"")}let c="Checking for plugin updates COMPLETED";await this.plugin.log(c,!0),e&&(n&&n.hide(),E(this.plugin,c,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(n=>n!==e),this.plugin.settings.pluginSubListFrozenVersion=this.plugin.settings.pluginSubListFrozenVersion.filter(n=>n.repo!==e),this.plugin.saveSettings()}getEnabledDisabledPlugins(e){let t=this.plugin.app.plugins,n=Object.values(t.manifests),i=Object.values(t.plugins).map(o=>o.manifest);return e?n.filter(o=>i.find(a=>o.id===a.id)):n.filter(o=>!i.find(a=>o.id===a.id))}checkIncompatiblePlugins(){let e=this.plugin.settings.pluginSubListFrozenVersion.filter(t=>t.isIncompatible).map(t=>t.repo);e.length>0&&E(this.plugin,`The following incompatible plugins were forcefully installed by BRAT and may not work as expected:
|
|
${e.join(`
|
|
`)}`,30)}};var _=require("obsidian");var ne=async(s,e,t)=>{let n=await G(e,!0,s.settings.debuggingMode);if(n||(n=await G(e,!1,s.settings.debuggingMode)),!n)return E(s,"There is no theme.css or theme-beta.css file in the root path of this repository, so there is no theme to install."),!1;let i=await Pt(e,s.settings.debuggingMode);if(!i)return E(s,"There is no manifest.json file in the root path of this repository, so theme cannot be installed."),!1;let o=await JSON.parse(i),a=(0,_.normalizePath)(Vn(s)+o.name),{adapter:c}=s.app.vault;await c.exists(a)||await c.mkdir(a),await c.write((0,_.normalizePath)(`${a}/theme.css`),n),await c.write((0,_.normalizePath)(`${a}/manifest.json`),i),Ct(s,e,Q(n));let u="";return t?(Nt(s,e,n),u=`${o.name} theme installed from ${e}. `,setTimeout(()=>{s.app.customCss.setTheme(o.name)},500)):u=`${o.name} theme updated from ${e}.`,s.log(`${u}[Theme Info](https://github.com/${e})`,!1),E(s,u,20,()=>{window.open(`https://github.com/${e}`)}),!0},q=async(s,e)=>{if(!await Ne()){console.log("BRAT: No internet detected.");return}let t,n="Checking for beta theme updates STARTED";await s.log(n,!0),e&&s.settings.notificationsEnabled&&(t=new _.Notice(`BRAT
|
|
${n}`,3e4));for(let o of s.settings.themesList){let a=await Z(o.repo,!0,s.settings.debuggingMode);a==="0"&&(a=await Z(o.repo,!1,s.settings.debuggingMode)),console.log("BRAT: lastUpdateOnline",a),a!==o.lastUpdate&&await ne(s,o.repo,!1)}let i="Checking for beta theme updates COMPLETED";(async()=>await s.log(i,!0))(),e&&(s.settings.notificationsEnabled&&t&&t.hide(),E(s,i))},Ce=(s,e)=>{s.settings.themesList=s.settings.themesList.filter(n=>n.repo!==e),s.saveSettings();let t=`Removed ${e} from BRAT themes list and will no longer be updated. However, the theme files still exist in the vault. To remove them, go into Settings > Appearance and remove the theme.`;s.log(t,!0),E(s,t)},Vn=s=>`${(0,_.normalizePath)(`${s.app.vault.configDir}/themes`)}/`;var $t="brat-migrations";async function Un(s,e){try{let t=await s.vault.adapter.read(`${s.vault.configDir}/plugins/obsidian42-brat/${$t}.json`);return JSON.parse(t).appliedMigrations.includes(e)}catch(t){return!1}}async function _n(s,e){try{let t=`${s.vault.configDir}/plugins/obsidian42-brat/${$t}.json`,n={appliedMigrations:[]};try{let i=await s.vault.adapter.read(t);n=JSON.parse(i)}catch(i){}n.appliedMigrations.includes(e)||(n.appliedMigrations.push(e),await s.vault.adapter.write(t,JSON.stringify(n,null,2)))}catch(t){console.error(`BRAT: Failed to mark migration ${e} complete:`,t)}}async function xt(s,e,t){let n="tokens-to-secretstorage-v1";if(!await Un(s,n))try{let i=0,o=u=>{let m=`brat-gh-${u.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")}`;return m.length>64?m.substring(0,64).replace(/-$/,""):m},a=u=>{let g=s.secretStorage.listSecrets();for(let m of g)if(s.secretStorage.getSecret(m)===u)return m;return null},c=(u,g)=>{let m=a(u);return m?(console.log(`BRAT: Reusing existing secret "${m}"`),m):(s.secretStorage.setSecret(g,u),console.log(`BRAT: Created new secret "${g}"`),g)};if(e.personalAccessToken&&e.personalAccessToken.trim()!==""){let u=e.personalAccessToken.trim(),m=c(u,"brat-gh-global");e.globalTokenName=m,e.personalAccessToken="",i++}if(e.pluginSubListFrozenVersion){for(let u of e.pluginSubListFrozenVersion)if(u.token&&u.token.trim()!==""){let g=u.token.trim(),m=o(u.repo),l=c(g,m);u.tokenName=l,u.token=void 0,i++}}i>0&&(await t(),console.log(`BRAT: Migrated ${i} token(s) to SecretStorage`)),await _n(s,n)}catch(i){console.error("BRAT: Failed to migrate tokens to SecretStorage:",i)}}var H=require("obsidian");var B=class extends H.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(At(this.plugin,e)){E(this.plugin,"This theme is already in the list for beta testing",10);return}await ne(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 H.Setting(e).addText(i=>{i.setPlaceholder("Repository (example: https://github.com/GitHubUserName/repository-name"),i.setValue(this.address),i.onChange(o=>{this.address=o.trim()}),i.inputEl.addEventListener("keydown",o=>{o.key==="Enter"&&this.address!==" "&&(o.preventDefault(),this.submitForm())}),i.inputEl.style.width="100%",window.setTimeout(()=>{let o=document.querySelector(".setting-item-info");o&&o.remove(),i.inputEl.focus()},10)}),e.createDiv("modal-button-container",i=>{new H.ButtonComponent(i).setButtonText("Never mind").onClick(()=>{this.close()}),new H.ButtonComponent(i).setButtonText("Add theme").setCta().onClick(o=>{o.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 n=t.createSpan();n.createEl("a",{href:"https://bit.ly/o42-twitter",text:"TFTHacker"}),n.appendText(" and "),n.createEl("a",{href:"https://github.com/johannrichard",text:"johannrichard"}),n.style.fontStyle="italic",t.appendChild(n),z(t,!1),window.setTimeout(()=>{let i=e.querySelectorAll(".brat-modal .setting-item-info");for(let o of Array.from(i))o.remove()},50)})}onClose(){this.openSettingsTabAfterwards&&(this.plugin.app.setting.openTab(),this.plugin.app.setting.openTabById(this.plugin.APP_ID))}};var Ot=require("obsidian");function Ft(){(0,Ot.addIcon)("BratIcon",'<path fill="currentColor" stroke="currentColor" d="M 41.667969 41.667969 C 41.667969 39.367188 39.800781 37.5 37.5 37.5 C 35.199219 37.5 33.332031 39.367188 33.332031 41.667969 C 33.332031 43.96875 35.199219 45.832031 37.5 45.832031 C 39.800781 45.832031 41.667969 43.96875 41.667969 41.667969 Z M 60.417969 58.582031 C 59.460938 58.023438 58.320312 57.867188 57.25 58.148438 C 56.179688 58.429688 55.265625 59.125 54.707031 60.082031 C 53.746094 61.777344 51.949219 62.820312 50 62.820312 C 48.050781 62.820312 46.253906 61.777344 45.292969 60.082031 C 44.734375 59.125 43.820312 58.429688 42.75 58.148438 C 41.679688 57.867188 40.539062 58.023438 39.582031 58.582031 C 37.597656 59.726562 36.910156 62.257812 38.042969 64.25 C 40.5 68.53125 45.0625 71.171875 50 71.171875 C 54.9375 71.171875 59.5 68.53125 61.957031 64.25 C 63.089844 62.257812 62.402344 59.726562 60.417969 58.582031 Z M 62.5 37.5 C 60.199219 37.5 58.332031 39.367188 58.332031 41.667969 C 58.332031 43.96875 60.199219 45.832031 62.5 45.832031 C 64.800781 45.832031 66.667969 43.96875 66.667969 41.667969 C 66.667969 39.367188 64.800781 37.5 62.5 37.5 Z M 50 8.332031 C 26.988281 8.332031 8.332031 26.988281 8.332031 50 C 8.332031 73.011719 26.988281 91.667969 50 91.667969 C 73.011719 91.667969 91.667969 73.011719 91.667969 50 C 91.667969 26.988281 73.011719 8.332031 50 8.332031 Z M 50 83.332031 C 33.988281 83.402344 20.191406 72.078125 17.136719 56.363281 C 14.078125 40.644531 22.628906 24.976562 37.5 19.042969 C 37.457031 19.636719 37.457031 20.238281 37.5 20.832031 C 37.5 27.738281 43.097656 33.332031 50 33.332031 C 52.300781 33.332031 54.167969 31.46875 54.167969 29.167969 C 54.167969 26.867188 52.300781 25 50 25 C 47.699219 25 45.832031 23.132812 45.832031 20.832031 C 45.832031 18.53125 47.699219 16.667969 50 16.667969 C 68.410156 16.667969 83.332031 31.589844 83.332031 50 C 83.332031 68.410156 68.410156 83.332031 50 83.332031 Z M 50 83.332031 " />')}var Bt=require("obsidian"),S=class extends Bt.FuzzySuggestModal{constructor(t){super(t.app);this.data=[];this.scope.register(["Shift"],"Enter",n=>{this.enterTrigger(n)}),this.scope.register(["Ctrl"],"Enter",n=>{this.enterTrigger(n)})}setSuggesterData(t){this.data=t}display(t){this.callbackFunction=t,this.open()}getItems(){return this.data}getItemText(t){return t.display}onChooseItem(){}renderSuggestion(t,n){n.createEl("div",{text:t.item.display})}enterTrigger(t){var o;let n=(o=document.querySelector(".suggestion-item.is-selected div"))==null?void 0:o.textContent,i=this.data.find(a=>a.display===n);i&&(this.invokeCallback(i,t),this.close())}onChooseSuggestion(t,n){this.invokeCallback(t.item,n)}invokeCallback(t,n){typeof this.callbackFunction=="function"&&this.callbackFunction(t,n)}};var se=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(i=>[i.repo,{version:i.version,token:i.token}])),t=Object.values(this.plugin.settings.pluginList).filter(i=>{let o=e.get(i);return!(o!=null&&o.version)||o.version==="latest"}).map(i=>({display:i,info:i})),n=new S(this.plugin);n.setSuggesterData(t),n.display(i=>{let o=`Checking for updates for ${i.info}`,a=e.get(i.info);this.plugin.log(o,!0),E(this.plugin,`
|
|
${o}`,3),this.plugin.betaPlugins.updatePlugin(i.info,!1,!0,!1,a==null?void 0:a.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(i=>i.repo)),t=Object.values(this.plugin.settings.pluginList).filter(i=>!e.has(i)).map(i=>({display:i,info:i})),n=new S(this.plugin);n.setSuggesterData(t),n.display(i=>{let o=`Reinstalling ${i.info}`;E(this.plugin,`
|
|
${o}`,3),this.plugin.log(o,!0),this.plugin.betaPlugins.updatePlugin(i.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(n=>({display:n.id,info:n.id})),t=new S(this.plugin);t.setSuggesterData(e),t.display(n=>{E(this.plugin,`${n.info}
|
|
Plugin reloading .....`,5),this.plugin.betaPlugins.reloadPlugin(n.info)})}},{id:"disablePlugin",icon:"BratIcon",name:"Plugins: Disable a plugin - toggle it off",showInRibbon:!0,callback:()=>{let e=this.plugin.betaPlugins.getEnabledDisabledPlugins(!0).map(n=>({display:`${n.name} (${n.id})`,info:n.id})),t=new S(this.plugin);t.setSuggesterData(e),t.display(n=>{this.plugin.log(`${n.display} plugin disabled`,!1),this.plugin.settings.debuggingMode&&console.log(n.info),this.plugin.app.plugins.disablePluginAndSave(n.info)})}},{id:"enablePlugin",icon:"BratIcon",name:"Plugins: Enable a plugin - toggle it on",showInRibbon:!0,callback:()=>{let e=this.plugin.betaPlugins.getEnabledDisabledPlugins(!1).map(n=>({display:`${n.name} (${n.id})`,info:n.id})),t=new S(this.plugin);t.setSuggesterData(e),t.display(n=>{this.plugin.log(`${n.display} plugin enabled`,!1),this.plugin.app.plugins.enablePluginAndSave(n.info)})}},{id:"openGitHubZRepository",icon:"BratIcon",name:"Plugins: Open the GitHub repository for a plugin",showInRibbon:!0,callback:async()=>{let e=await yt(this.plugin.settings.debuggingMode);if(e){let t=Object.values(e).map(o=>({display:`Plugin: ${o.name} (${o.repo})`,info:o.repo})),n=Object.values(this.plugin.settings.pluginList).map(o=>({display:`BRAT: ${o}`,info:o}));for(let o of t)n.push(o);let i=new S(this.plugin);i.setSuggesterData(n),i.display(o=>{o.info&&window.open(`https://github.com/${o.info}`)})}}},{id:"openGitHubRepoTheme",icon:"BratIcon",name:"Themes: Open the GitHub repository for a theme (appearance)",showInRibbon:!0,callback:async()=>{let e=await vt(this.plugin.settings.debuggingMode);if(e){let t=Object.values(e).map(i=>({display:`Theme: ${i.name} (${i.repo})`,info:i.repo})),n=new S(this.plugin);n.setSuggesterData(t),n.display(i=>{i.info&&window.open(`https://github.com/${i.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(o=>({display:`Plugin: ${o.name}`,info:o.id})),n=new S(this.plugin),i=Object.values(e.settingTabs).map(o=>({display:`Core: ${o.name}`,info:o.id}));for(let o of t)i.push(o);n.setSuggesterData(i),n.display(o=>{e.open(),e.openTabById(o.info)})}},{id:"GrabBetaTheme",icon:"BratIcon",name:"Themes: Grab a beta theme for testing from a Github repository",showInRibbon:!0,callback:()=>{new B(this.plugin).open()}},{id:"updateBetaThemes",icon:"BratIcon",name:"Themes: Update beta themes",showInRibbon:!0,callback:async()=>{await q(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 a of this.bratCommands)a.showInRibbon&&e.push({display:a.name,info:a.callback});let t=new S(this.plugin),n=this.plugin.app.setting,i=Object.values(n.settingTabs).map(a=>({display:`Core: ${a.name}`,info:()=>{n.open(),n.openTabById(a.id)}})),o=Object.values(n.pluginTabs).map(a=>({display:`Plugin: ${a.name}`,info:()=>{n.open(),n.openTabById(a.id)}}));e.push({display:"---- Core Plugin Settings ----",info:()=>{this.ribbonDisplayCommands()}});for(let a of i)e.push(a);e.push({display:"---- Plugin Settings ----",info:()=>{this.ribbonDisplayCommands()}});for(let a of o)e.push(a);t.setSuggesterData(e),t.display(a=>{typeof a.info=="function"&&a.info()})}};var A=require("obsidian");var Le=class extends A.PluginSettingTab{constructor(t,n){super(t,n);this.accessTokenSetting=null;this.accessTokenButton=null;this.tokenInfo=null;this.validator=null;this.plugin=n}display(){let{containerEl:t}=this;t.empty(),t.addClass("brat-settings"),new A.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 r=>{this.plugin.settings.enableAfterInstall=r,await this.plugin.saveSettings()})}),new A.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 r=>{this.plugin.settings.updateAtStartup=r,await this.plugin.saveSettings()})}),new A.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 r=>{this.plugin.settings.updateThemesAtStartup=r,await this.plugin.saveSettings()})}),new A.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 r=>{this.plugin.settings.selectLatestPluginVersionByDefault=r,await this.plugin.saveSettings()})}),new A.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 r=>{this.plugin.settings.allowIncompatiblePlugins=r,await this.plugin.saveSettings()})}),z(t,!0),t.createEl("hr");let n=new Map(this.plugin.settings.pluginSubListFrozenVersion.map(l=>[l.repo,l])),i=new Map,o=new A.SettingGroup(t).setHeading("Beta plugin list");o.addSearch(l=>{l.setPlaceholder("Filter plugins"),l.onChange(r=>{let d=r.toLowerCase().trim();i.forEach(({container:b,pluginName:w})=>{d===""||w.includes(d)?b.removeAttribute("hidden"):b.setAttribute("hidden","true")})})}),o.addSetting(l=>{let r=document.createDocumentFragment();r.createEl("div",{text:'The following is a list of beta plugins added via the command "Add a beta plugin for testing". You can chose to add the latest version or a frozen version. A frozen version is a specific release of a plugin based on its release tag.'}),r.createEl("p"),r.createEl("div",{text:"Click the 'Edit' button next to a plugin to change the installed version and the x button next to a plugin to remove it from the list."}),r.createEl("p"),r.createEl("span").createEl("b",{text:"Note: "}),r.createSpan({text:"Removing from the list does not delete the plugin, this should be done from the Community Plugins tab in Settings."}),l.setDesc(r),l.addButton(d=>{d.setButtonText("Add beta plugin").setCta().onClick(()=>{this.plugin.betaPlugins.displayAddNewPluginModal(!0)})})});for(let l of this.plugin.settings.pluginList){let r=n.get(l);o.addSetting(d=>{let b=(r==null?void 0:r.tokenName)||"",w=b?this.plugin.app.secretStorage.getSecret(b):"",p=!!(b&&!w),T=document.createDocumentFragment(),C=r!=null&&r.version?` Tracked version: ${r.version} ${r.version==="latest"?"":"(frozen)"}`:"",N=r!=null&&r.isIncompatible?" (incompatible)":"";T.createDiv({text:`${C}${N}`}),p&&T.createDiv({text:` Secret not defined or empty: ${b}`,cls:"mod-warning",title:"Token name configured but secret is missing. Add the secret or update the plugin configuration."}),d.setName(ee(l)).setDesc(T);let R=d.settingEl;R.addClass("brat-plugin-item"),i.set(l,{container:R,pluginName:l.toLowerCase()}),(!(r!=null&&r.version)||r.version==="latest")&&d.addButton(P=>{p?P.setIcon("sync").setTooltip(`Secret missing: ${b}. Please add the secret or update the plugin configuration.`).setWarning().setDisabled(!0):P.setIcon("sync").setTooltip("Check and update plugin").onClick(async()=>{await this.plugin.betaPlugins.updatePlugin(l,!1,!0,!1,(r==null?void 0:r.tokenName)||"")})}),d.addButton(P=>{P.setIcon("edit").setTooltip("Change version and update settings"),p&&P.setWarning(),P.onClick(()=>{this.plugin.betaPlugins.displayAddNewPluginModal(!0,!0,l,r==null?void 0:r.version,(r==null?void 0:r.tokenName)||""),this.plugin.app.setting.updatePluginSection()})}).addButton(P=>{P.setIcon("cross").setTooltip("Remove this beta plugin").setWarning().onClick(()=>{if(P.buttonEl.textContent==="")P.setButtonText("Click once more to confirm removal");else{let{buttonEl:W}=P,{parentElement:M}=W;M!=null&&M.parentElement&&(M.parentElement.remove(),this.plugin.betaPlugins.deletePlugin(l))}})})})}let a=new Map,c=new A.SettingGroup(t).setHeading("Beta themes list");c.addSetting(l=>l.addButton(r=>{r.setButtonText("Add beta theme").setCta().onClick(()=>{this.plugin.app.setting.close(),new B(this.plugin).open()})})),c.addSearch(l=>{l.setPlaceholder("Filter themes"),l.onChange(r=>{let d=r.toLowerCase().trim();a.forEach(({container:b,themeName:w})=>{d===""||w.includes(d)?b.removeAttribute("hidden"):b.setAttribute("hidden","true")})})});for(let l of this.plugin.settings.themesList)c.addSetting(r=>{r.setName(ee(l.repo));let d=r.settingEl;d.addClass("brat-theme-item"),a.set(l.repo,{container:d,themeName:l.repo.toLowerCase()}),r.addButton(b=>{b.setIcon("cross").setTooltip("Delete this beta theme").onClick(()=>{if(b.buttonEl.textContent==="")b.setButtonText("Click once more to confirm removal");else{let{buttonEl:w}=b,{parentElement:p}=w;p!=null&&p.parentElement&&(p.parentElement.remove(),Ce(this.plugin,l.repo))}})})});new A.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(r=>{r.setValue(this.plugin.settings.notificationsEnabled),r.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(r=>{r.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(r=>{r.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(r=>{r.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(r=>{r.setValue(this.plugin.settings.debuggingMode).onChange(async d=>{this.plugin.settings.debuggingMode=d,await this.plugin.saveSettings()})}));let g=new A.SettingGroup(t).setHeading("GitHub Personal Access Token"),m="";g.addSetting(l=>{l.setName("Personal access token").setDesc(Lt({prependText:"Set a personal access token to increase rate limits for public repositories on GitHub. You can create one in ",url:"https://github.com/settings/tokens/new?scopes=public_repo",text:"your GitHub account settings",appendText:" and then add it here. Please consult the documentation for more details."})),this.accessTokenSetting=new A.SecretComponent(this.plugin.app,l.controlEl),this.accessTokenSetting.setValue(this.plugin.settings.globalTokenName||"").onChange(async r=>{var b,w,p;let d=(r==null?void 0:r.trim())||"";this.plugin.settings.globalTokenName=d,await this.plugin.saveSettings(),d?(m=this.plugin.app.secretStorage.getSecret(d)||"",(b=this.accessTokenButton)==null||b.setDisabled(!1)):(m="",(w=this.accessTokenButton)==null||w.setDisabled(!0),await((p=this.validator)==null?void 0:p.validateToken("")))}),this.plugin.settings.globalTokenName&&(m=this.plugin.app.secretStorage.getSecret(this.plugin.settings.globalTokenName)||""),l.addExtraButton(r=>{r.setIcon("cross").setTooltip("Clear personal access token").onClick(async()=>{var d,b;this.plugin.settings.globalTokenName="",await this.plugin.saveSettings(),(d=this.accessTokenSetting)==null||d.setValue(""),m="",await((b=this.validator)==null?void 0:b.validateToken(""))})}).addButton(r=>{this.accessTokenButton=r,r.setButtonText("Validate").setCta().onClick(async()=>{var d;m&&await((d=this.validator)==null?void 0:d.validateToken(m))})}).then(()=>{var r;this.tokenInfo=this.createTokenInfoElement(t),this.validator=new j(this.tokenInfo),(r=this.validator)==null||r.validateToken(m).then(d=>{var b;(b=this.accessTokenButton)==null||b.setDisabled(d||!this.plugin.settings.globalTokenName)})})})}createTokenInfoElement(t){let n=t.createDiv({cls:"brat-token-info"});return n.createDiv({cls:"brat-token-status"}),n.createDiv({cls:"brat-token-details"}),n}};var ie=class{constructor(e){this.console=(e,...t)=>{console.log(`BRAT: ${e}`,...t)};this.themes={themeseCheckAndUpates:async e=>{await q(this.plugin,e)},themeInstallTheme:async e=>{let t=e.replace("https://github.com/","");await ne(this.plugin,t,!0)},themesDelete:e=>{let t=e.replace("https://github.com/","");Ce(this.plugin,t)},grabCommmunityThemeCssFile:async(e,t=!1)=>await G(e,t,this.plugin.settings.debuggingMode),grabChecksumOfThemeCssFile:async(e,t=!1)=>await Z(e,t,this.plugin.settings.debuggingMode),grabLastCommitDateForFile:async(e,t)=>await Rt(e,t)};this.plugin=e}};var de=require("obsidian"),Qt=ln(Kt());async function Zt(s,e,t=!1){if(s.settings.debuggingMode&&console.log(`BRAT: ${e}`),s.settings.loggingEnabled){if(!s.settings.loggingVerboseEnabled&&t)return;let n=`${s.settings.loggingPath}.md`,i=`[[${(0,de.moment)().format((0,Qt.getDailyNoteSettings)().format).toString()}]] ${(0,de.moment)().format("HH:mm")}`,o=window.require("os"),a=de.Platform.isDesktop?o.hostname():"MOBILE",c=`${i} ${a} ${e.replace(`
|
|
`," ")}
|
|
`,u=s.app.vault.getAbstractFileByPath(n);u?await s.app.vault.append(u,c):u=await s.app.vault.create(n,c)}}var ke=class extends en.Plugin{constructor(){super(...arguments);this.APP_NAME="BRAT";this.APP_ID="obsidian42-brat";this.settings=je;this.betaPlugins=new te(this);this.commands=new se(this);this.bratApi=new ie(this);this.obsidianProtocolHandler=t=>{if(!t.plugin&&!t.theme){E(this,"Could not locate the repository from the URL.",10);return}for(let n of["plugin","theme"])if(t[n]){let i;switch(n){case"plugin":i=new U(this,this.betaPlugins,!0,!1,t[n],t.version?t.version:void 0),i.open();break;case"theme":i=new B(this),i.address=t[n],i.open();break}return}}}onload(){console.log(`loading ${this.APP_NAME}`),Ft(),this.addRibbonIcon("BratIcon","BRAT",()=>{this.commands.ribbonDisplayCommands()}),this.loadSettings().then(async()=>{await xt(this.app,this.settings,()=>this.saveSettings()),this.app.workspace.onLayoutReady(()=>{this.addSettingTab(new Le(this.app,this)),this.registerObsidianProtocolHandler("brat",this.obsidianProtocolHandler),this.betaPlugins.checkIncompatiblePlugins(),this.settings.updateAtStartup&&setTimeout(()=>{this.betaPlugins.checkForPluginUpdatesAndInstallUpdates(!1)},6e4),this.settings.updateThemesAtStartup&&setTimeout(()=>{q(this,!1)},12e4),setTimeout(()=>{window.bratAPI=this.bratApi},500)})}).catch(t=>{console.error("Failed to load settings:",t)})}async log(t,n=!1){await Zt(this,t,n)}onunload(){console.log(`unloading ${this.APP_NAME}`)}async loadSettings(){this.settings=Object.assign({},je,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}};
|
|
|
|
/* nosourcemap */ |