tech-tips/.obsidian/plugins/link-favicon/main.js

11 lines
139 KiB
JavaScript
Raw Permalink Normal View History

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
https://github.com/joethei/obisidian-link-favicon
*/
var Ir=Object.create;var Ye=Object.defineProperty;var br=Object.getOwnPropertyDescriptor;var Ur=Object.getOwnPropertyNames;var Pr=Object.getPrototypeOf,Tr=Object.prototype.hasOwnProperty;var lo=o=>Ye(o,"__esModule",{value:!0});var Te=(o,e)=>()=>(o&&(e=o(o=0)),e);var mo=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports),uo=(o,e)=>{lo(o);for(var t in e)Ye(o,t,{get:e[t],enumerable:!0})},yr=(o,e,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Ur(e))!Tr.call(o,r)&&r!=="default"&&Ye(o,r,{get:()=>e[r],enumerable:!(t=br(e,r))||t.enumerable});return o},N=o=>yr(lo(Ye(o!=null?Ir(Pr(o)):{},"default",o&&o.__esModule&&"default"in o?{get:()=>o.default,enumerable:!0}:{value:o,enumerable:!0})),o);var v=(o,e,t)=>new Promise((r,n)=>{var s=c=>{try{a(t.next(c))}catch(l){n(l)}},i=c=>{try{a(t.throw(c))}catch(l){n(l)}},a=c=>c.done?r(c.value):Promise.resolve(c.value).then(s,i);a((t=t.apply(o,e)).next())});var bt,L,ke=Te(()=>{bt=N(require("obsidian")),L={google:{name:"Google",url:o=>Promise.resolve("https://www.google.com/s2/favicons?domain="+o)},duckduckgo:{name:"DuckDuckGo",url:o=>Promise.resolve("https://icons.duckduckgo.com/ip3/"+o+".ico")},iconhorse:{name:"Icon Horse",url:o=>Promise.resolve("https://icon.horse/icon/"+o)},splitbee:{name:"Splitbee",url:o=>Promise.resolve("https://favicon.splitbee.io/?url="+o)},besticon:{name:"The Favicon Finder",url:(o,e)=>v(void 0,null,function*(){try{let t=e.provider==="besticon"?e.providerDomain:e.fallbackProviderDomain,r=yield(0,bt.requestUrl)({url:t+"/allicons.json?url="+o});return r.json.icons.length===0?Promise.reject("besticon: no icons for domain "+o):Promise.resolve(r.json.icons[0].url)}catch(t){return console.error(t),Promise.reject("besticon: failed to retrieve icon for "+o)}})},favicongrabber:{name:"Favicon Grabber",url:o=>v(void 0,null,function*(){try{let e=yield(0,bt.requestUrl)({url:"https://favicongrabber.com/api/grab/"+o});return e.json.length===0?Promise.resolve(""):Promise.resolve(e.json.icons[0].src)}catch(e){return console.error(e),Promise.reject("favicongrabber: failed to retrieve icon for domain "+o)}})}}});var Fo=mo((op,cn)=>{cn.exports=[{"URI Scheme":"aaa",Template:"",Description:"Diameter Protocol",Status:"Permanent","Well-Known URI Support":"-",Reference:"[RFC6733]",Notes:"",schema:"aaa"},{"URI Scheme":"aaas",Template:"",Description:"Diameter Protocol with Secure Transport",Status:"Permanent","Well-Known URI Support":"-",Reference:"[RFC6733]",Notes:"",schema:"aaas"},{"URI Scheme":"about",Template:"",Description:"about",Status:"Permanent","Well-Known URI Support":"-",Reference:"[RFC6694]",Notes:"",schema:"about"},{"URI Scheme":"acap",Template:"",Description:"application configuration access protocol",Status:"Permanent","Well-Known URI Support":"-",Reference:"[RFC2244]",Notes:"",schema:"acap"},{"URI Scheme":"acct",Template:"",Description:"acct",Status:"Permanent","Well-Known URI Support":"-",Reference:"[RFC7565]",Notes:"",schema:"acct"},{"URI Scheme":"acd",Template:"prov/acd",Description:"acd",Status:"Provisional","Well-Known URI Support":"-",Reference:"[Michael_Hedenus]",Notes:"",schema:"acd"},{"URI Scheme":"acr",Template:"prov/acr",Description:"acr",Status:"Provisional","Well-Known URI Support":"-",Reference:"[OMA-OMNA]",Notes:"",schema:"acr"},{"URI Scheme":"adiumxtra",Template:"prov/adiumxtra",Description:"adiumxtra",Status:"Provisional","Well-Known URI Support":"-",Reference:"[Dave_Thaler]",Notes:"",schema:"adiumxtra"},{"URI Scheme":"adt",Template:"prov/adt",Description:"adt",Status:"Provisional","Well-Known URI Support":"-",Reference:"[SAP_SE]",Notes:"",schema:"adt"},{"URI Scheme":"afp",Template:"prov/afp",Description:"afp",Status:"Provisional","Well-Known URI Support":"-",Reference:"[Dave_Thaler]",Notes:"",schema:"afp"},{"URI Scheme":"afs",Template:"",Description:"Andrew File System global file names",Status:"Provisional","Well-Known URI Support":"-",Reference:"[RFC1738]",Notes:"",schema:"afs"},{"URI Scheme":"aim",Template:"prov/aim",Description:"aim",Status:"Provisional","Well-Known URI Support":"-",Reference:"[Dave_Thaler]",Notes:"",schema:"aim"},{"URI S
Details: https://developer.mozilla.org/en/docs/Web/HTML/CORS_enabled_image`));return Ve(n,t.silent),!t.silent&&console.error(c),this.prepareResult(r,n)}},o.prototype.getColorFromArray4=function(e,t){t=t||{};var r=4,n=e.length,s=er(t);if(n<r)return s;var i=n-n%r,a=(t.step||1)*r,c;switch(t.algorithm||"sqrt"){case"simple":c=Vn;break;case"sqrt":c=zn;break;case"dominant":c=Bn;break;default:throw re("".concat(t.algorithm," is unknown algorithm"))}return c(e,i,{defaultColor:s,ignoredColor:An(t.ignoredColor),step:a,dominantDivider:t.dominantDivider})},o.prototype.prepareResult=function(e,t){var r=e.slice(0,3),n=[e[0],e[1],e[2],e[3]/255],s=En(e);return{value:[e[0],e[1],e[2],e[3]],rgb:"rgb("+r.join(",")+")",rgba:"rgba("+n.join(",")+")",hex:Qo(r),hexa:Qo(e),isDark:s,isLight:!s,error:t}},o.prototype.destroy=function(){this.canvas&&(this.canvas.width=1,this.canvas.height=1,this.canvas=null),this.ctx=null},o.prototype.bindImageEvents=function(e,t){var r=this;return new Promise(function(n,s){var i=function(){l();var p=r.getColor(e,t);p.error?s(p.error):n(p)},a=function(){l(),s(re('Error loading image "'.concat(e.src,'"')))},c=function(){l(),s(re('Image "'.concat(e.src,'" loading aborted')))},l=function(){e.removeEventListener("load",i),e.removeEventListener("error",a),e.removeEventListener("abort",c)};e.addEventListener("load",i),e.addEventListener("error",a),e.addEventListener("abort",c)})},o}();var Jt=class{constructor(e){this.fac=new sr;this.plugin=e}destruct(){this.fac.destroy()}constructURL(e){try{return new URL(e)}catch(t){return e.startsWith("http")?void 0:this.constructURL("http://"+e)}}addFavicon(e,t,r,n){return v(this,null,function*(){if((!t||t==="")&&(!r||r==="")){console.log("no icon for "+n.href);return}if(!t||t===""){yield this.useDownloadedIcon(r,e,n);return}if(typeof t=="string"){if(!t.startsWith("http")){this.addIcon(e,t);return}let s=yield this.getImageEl(t,n);this.addIcon(e,s);return}this.addIcon(e,t)})}getImageEl(e,t){return v(this,null,function*(){if(typeof t=="string"){let r=this.constructURL(t);return r?this.getImageElFromUrl(e,r):Promise.reject("could not get Object for "+e+" "+t)}else return this.getImageElFromUrl(e,t)})}getImageElFromUrl(e,t){return v(this,null,function*(){let r=activeDocument.createElement("img");return r.addClass("link-favicon"),r.dataset.host=t.hostname,r.src=yield this.getEncodedIcon(e,t.hostname),yield this.setColorAttributes(r),r.style.height="0.8em",r.style.display="inline-block",r})}useDownloadedIcon(e,t,r){return v(this,null,function*(){if(!(!e||e==="")&&typeof e=="string"){let n=activeDocument.createElement("img");n.addClass("link-favicon"),n.src=yield this.getEncodedIcon(e,r.hostname),yield this.setColorAttributes(n),this.addIcon(t,n)}})}addIcon(e,t){!t||t==="undefined"||(this.plugin.settings.iconPosition==="front"&&e.prepend(t),this.plugin.settings.iconPosition==="back"&&e.append(t))}getEncodedIcon(e,t){return v(this,null,function*(){if(e==="")return"";let r=e.split("."),n=r[r.length-1];n||(n="png");let s="lf-"+t+"."+n,i=Xt.default.get(s);if(i)return i;let a=yield this.downloadIcon(e);return Xt.default.set(s,a,{ttl:30*24*60*60}),a})}downloadIcon(e){return v(this,null,function*(){let t=yield(0,dt.requestUrl)({url:e});return t.status!==200?Promise.reject("server returned status code"+t.status+" for "+e):"data:image/png;base64,"+(0,dt.arrayBufferToBase64)(t.arrayBuffer)})}setColorAttributes(e){return v(this,null,function*(){let t=activeDocument.getElementsByClassName("theme-dark")[0],r=activeDocument.getElementsByClassName("theme-light")[0],n;if(t!==void 0)try{n=activeWindow.getComputedStyle(t).getPropertyValue("--background-primary")}catch(s){n="000000"}else try{n=activeWindow.getComputedStyle(r).getPropertyValue("--background-primary")}catch(s){n="FFFFFF"}try{let s=yield this.fac.getColorAsync(e);e.dataset.averageColorHex=s.hex,e.dataset.isDark=String(s.isDark),e.dataset.isLight=String(s.isLight);let i=d(n);e.dataset.colorInversion=String(this.plugin.settings.colorInversion),e.dataset.readable=d.readability(s.hex,i).toString(),e.dataset.isReadableAA=String(d.isReadable(s.hex,i)),e.
`).filter(a=>a.length>0).some(a=>r.hostname.match(new RegExp(a))))return Promise.reject();let i=yield this.getCustomDomainIcon(r.hostname);if(i)return typeof i!="string"&&(i.addClass("link-favicon"),i.dataset.target=r.href,i.dataset.host=r.hostname),i;try{return yield t.url(r.hostname,this.settings)}catch(a){return console.error(a),Promise.reject()}return""})}isUsingLivePreviewEnabledEditor(){return!app.vault.getConfig("legacyEditor")}onload(){return v(this,null,function*(){console.log("enabling plugin: link favicons"),yield this.loadSettings(),this.iconAdder=new Jt(this);let e=this.app.vault.configDir+"/favicons/";if((yield this.app.vault.adapter.exists(e))&&(yield this.app.vault.adapter.rmdir(e,!0)),this.registerEvent(this.app.workspace.on("css-change",()=>{this.app.workspace.updateOptions()})),this.addSettingTab(new Ht(this.app,this)),this.isUsingLivePreviewEnabledEditor()){let r=(Qt(),fr).asyncDecoBuilderExt,n=require("@codemirror/state").Prec;this.registerEditorExtension(n.lowest(r(this))),this.registerEditorExtension(n.lowest(Vo(this)))}let t=new Bt(this);this.registerMarkdownPostProcessor(t.processor),this.app.workspace.updateOptions()})}onunload(){this.iconAdder.destruct(),console.log("disabling plugin: link favicons")}loadSettings(){return v(this,null,function*(){this.settings=Object.assign({},jo,yield this.loadData())})}saveSettings(){return v(this,null,function*(){yield this.saveData(this.settings),this.app.workspace.updateOptions()})}};
/*! Fast Average Color | © 2023 Denis Seleznev | MIT License | https://github.com/fast-average-color/fast-average-color */