You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
147 KiB

2 years ago
/*
- THIS IS A GENERATED/BUNDLED FILE BY ESBUILD -
Please visit the repository linked to view the source code:
https://github.com/noatpad/obsidian-banners
*/
var Zn=Object.create;var Ie=Object.defineProperty;var ei=Object.getOwnPropertyDescriptor;var ui=Object.getOwnPropertyNames;var ti=Object.getPrototypeOf,ri=Object.prototype.hasOwnProperty;var Pu=t=>Ie(t,"__esModule",{value:!0});var o=(t,u)=>()=>(u||t((u={exports:{}}).exports,u),u.exports),ai=(t,u)=>{Pu(t);for(var r in u)Ie(t,r,{get:u[r],enumerable:!0})},ni=(t,u,r)=>{if(u&&typeof u=="object"||typeof u=="function")for(let a of ui(u))!ri.call(t,a)&&a!=="default"&&Ie(t,a,{get:()=>u[a],enumerable:!(r=ei(u,a))||r.enumerable});return t},S=t=>ni(Pu(Ie(t!=null?Zn(ti(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var Pe=o((ge,ru)=>{"use strict";Object.defineProperty(ge,"__esModule",{value:!0});ge.default=ii;function Me(t){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Me=function(r){return typeof r}:Me=function(r){return r&&typeof Symbol=="function"&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},Me(t)}function ii(t){var u=typeof t=="string"||t instanceof String;if(!u){var r=Me(t);throw t===null?r="null":r==="object"&&(r=t.constructor.name),new TypeError("Expected a string but received a ".concat(r))}}ru.exports=ge.default;ru.exports.default=ge.default});var nu=o((pe,au)=>{"use strict";Object.defineProperty(pe,"__esModule",{value:!0});pe.default=di;function di(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},u=arguments.length>1?arguments[1]:void 0;for(var r in u)typeof t[r]=="undefined"&&(t[r]=u[r]);return t}au.exports=pe.default;au.exports.default=pe.default});var Lu=o((_e,iu)=>{"use strict";Object.defineProperty(_e,"__esModule",{value:!0});_e.default=li;var oi=qu(Pe()),si=qu(nu());function qu(t){return t&&t.__esModule?t:{default:t}}var Di={require_tld:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_numeric_tld:!1};function li(t,u){(0,oi.default)(t),u=(0,si.default)(u,Di),u.allow_trailing_dot&&t[t.length-1]==="."&&(t=t.substring(0,t.length-1));var r=t.split("."),a=r[r.length-1];return u.require_tld&&(r.length<2||!/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(a)||/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20\u00A9\uFFFD]/.test(a))||!u.allow_numeric_tld&&/^\d+$/.test(a)?!1:r.every(function(n){return!(n.length>63||!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(n)||/[\uff01-\uff5e]/.test(n)||/^-|-$/.test(n)||!u.allow_underscores&&/_/.test(n))})}iu.exports=_e.default;iu.exports.default=_e.default});var ju=o((he,ou)=>{"use strict";Object.defineProperty(he,"__esModule",{value:!0});he.default=du;var ci=fi(Pe());function fi(t){return t&&t.__esModule?t:{default:t}}var Ou="(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])",Y="(".concat(Ou,"[.]){3}").concat(Ou),mi=new RegExp("^".concat(Y,"$")),I="(?:[0-9a-fA-F]{1,4})",gi=new RegExp("^("+"(?:".concat(I,":){7}(?:").concat(I,"|:)|")+"(?:".concat(I,":){6}(?:").concat(Y,"|:").concat(I,"|:)|")+"(?:".concat(I,":){5}(?::").concat(Y,"|(:").concat(I,"){1,2}|:)|")+"(?:".concat(I,":){4}(?:(:").concat(I,"){0,1}:").concat(Y,"|(:").concat(I,"){1,3}|:)|")+"(?:".concat(I,":){3}(?:(:").concat(I,"){0,2}:").concat(Y,"|(:").concat(I,"){1,4}|:)|")+"(?:".concat(I,":){2}(?:(:").concat(I,"){0,3}:").concat(Y,"|(:").concat(I,"){1,5}|:)|")+"(?:".concat(I,":){1}(?:(:").concat(I,"){0,4}:").concat(Y,"|(:").concat(I,"){1,6}|:)|")+"(?::((?::".concat(I,"){0,5}:").concat(Y,"|(?::").concat(I,"){1,7}|:))")+")(%[0-9a-zA-Z-.:]{1,})?$");function du(t){var u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";if((0,ci.default)(t),u=String(u),!u)return du(t,4)||du(t,6);if(u==="4"){if(!mi.test(t))return!1;var r=t.split(".").sort(function(a,n){return a-n});return r[3]<=255}return u==="6"?!!gi.test(t):!1}ou.exports=he.default;ou.exports.default=he.default});var Nu=o((be,su)=>{"use strict";Object.defineProperty(be,"__esModule",{value:!0});be.default=Ei;var pi=qe(Pe()),_i=qe(Lu()),Ru=qe(ju()),hi=qe(nu());function qe(t){return t&&t.__esModule?t:{default:t}}var bi={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_port:!1,require_valid_protocol:!0,allow_underscores:!
`),Oe,B,P,w),z=MI;var ER=new E(ae(`
`),B,P,w,K(/&/g,"&amp;"),K(/</g,"&lt;"),K(/>/g,"&gt;"),K(/"/g,"&quot;"),K(/'/g,"&#x27;"),K(/`/g,"&#x60;"));var AR=new E(H(/(?:\n(?:\s*))+/g," "),w);var LR=new E(H(/(?:\n\s*)/g,""),w);var $R=new E(B({separator:","}),H(/(?:\s+)/g," "),w);var QR=new E(B({separator:",",conjunction:"or"}),H(/(?:\s+)/g," "),w);var iH=new E(B({separator:",",conjunction:"and"}),H(/(?:\s+)/g," "),w);var mH=new E(B,P,w);var EH=new E(B,H(/(?:\s+)/g," "),w);var AH=new E(P,w);var zI=new E(P("all"),w),je=zI;var X=S(require("obsidian"));var q=S(require("obsidian")),Uu={height:null,style:"solid",showInInternalEmbed:!0,internalEmbedHeight:null,showInPreviewEmbed:!0,previewEmbedHeight:null,frontmatterField:null,bannerDragModifier:"none",iconHorizontalAlignment:"left",iconHorizontalTransform:null,iconVerticalAlignment:"center",iconVerticalTransform:null,useTwemoji:!0,showPreviewInLocalModal:!0,localSuggestionsLimit:null,bannersFolder:null,allowMobileDrag:!1},L={height:250,internalEmbedHeight:200,previewEmbedHeight:120,frontmatterField:"banner",iconHorizontalTransform:"0px",iconVerticalTransform:"0px",localSuggestionsLimit:10,bannersFolder:"/"},$I={solid:"Solid",gradient:"Gradient"},GI={none:"None",shift:"\u21E7 Shift",ctrl:"\u2303 Ctrl",alt:"\u2387 Alt",meta:"\u2318 Meta"},KI={left:"Left",center:"Center",right:"Right",custom:"Custom"},UI={above:"Above",center:"Center",below:"Below",custom:"Custom"},Re=class extends q.PluginSettingTab{constructor(u){super(u.app,u);this.plugin=u,this.containerEl.addClass("banner-settings")}async saveSettings(u,r={}){this.plugin.settings={...this.plugin.settings,...u},await this.plugin.saveData(this.plugin.settings),this.plugin.loadStyles();let{refreshViews:a,reloadSettings:n}=r;n&&this.display(),a&&this.plugin.refreshViews()}display(){let{containerEl:u}=this,{height:r,style:a,showInInternalEmbed:n,internalEmbedHeight:i,showInPreviewEmbed:s,previewEmbedHeight:l,frontmatterField:D,bannerDragModifier:c,iconHorizontalAlignment:b,iconHorizontalTransform:h,iconVerticalAlignment:m,iconVerticalTransform:g,useTwemoji:y,showPreviewInLocalModal:F,localSuggestionsLimit:v,bannersFolder:M,allowMobileDrag:C}=this.plugin.settings;u.empty(),this.createHeader("Banners","A nice, lil' thing to add some flair to your notes"),new q.Setting(u).setName("Banner height").setDesc("Set how big the banner should be in pixels").addText(d=>{d.inputEl.type="number",d.setValue(`${r}`),d.setPlaceholder(`${L.height}`),d.onChange(async p=>this.saveSettings({height:p?parseInt(p):null}))}),new q.Setting(u).setName("Banner style").setDesc("Set a style for all of your banners").addDropdown(d=>d.addOptions($I).setValue(a).onChange(async p=>this.saveSettings({style:p},{refreshViews:!0}))),new q.Setting(u).setName("Show banner in internal embed").setDesc(createFragment(d=>{d.appendText("Choose whether to display the banner in the internal embed. This is the embed that appears when you write "),d.createEl("code",{text:"![[file]]"}),d.appendText(" in a file")})).addToggle(d=>d.setValue(n).onChange(async p=>this.saveSettings({showInInternalEmbed:p},{reloadSettings:!0,refreshViews:!0}))),this.plugin.settings.showInInternalEmbed&&new q.Setting(u).setName("Internal embed banner height").setDesc("Set the banner size inside the internal embed").addText(d=>{d.inputEl.type="number",d.setValue(`${i}`),d.setPlaceholder(`${L.internalEmbedHeight}`),d.onChange(async p=>this.saveSettings({internalEmbedHeight:p?parseInt(p):null}))}),new q.Setting(u).setName("Show banner in preview embed").setDesc(createFragment(d=>{d.appendText("Choose whether to display the banner in the page preview embed. This is the embed that appears from the "),d.createEl("span",{text:"Page Preview ",attr:{style:"color: --var(text-normal)"}}),d.appendText("core plugin")})).addToggle(d=>d.setValue(s).onChange(async p=>this.saveSettings({showInPreviewEmbed:p},{reloadSettings:!0}))),this.plugin.settings.showInPreviewEmbed&&new q.Setting(u).setName("Preview embed banner height").setDesc("Set the banner size inside the page preview embed").addText(d=>{d.inputEl.type="number",d.setValue(`${l}`),d.setPlaceholder(`${L
<p class="suggestion-text">${n}</p>
<div class="suggestion-image-wrapper">
<img src="${this.vault.getResourcePath(u.item)}" />
</div>
`}}async onChooseItem(u){let r=this.metadataCache.fileToLinktext(u,this.targetFile.path);await this.metaManager.upsertBannerData(this.targetFile,{src:`"![[${r}]]"`})}getImagesInFolder(u){let r=[];return u.children.forEach(a=>{a instanceof X.TFolder&&r.push(...this.getImagesInFolder(u));let n=a;Wu.includes(n.extension)&&r.push(n)}),r}};var lu=S(require("obsidian"));var WI=["src","x","y","icon","lock"],Ne=class{constructor(u){this.plugin=u,this.metadata=u.app.metadataCache,this.vault=u.app.vault}getBannerData(u){if(!u)return null;let r=this.plugin.getSettingValue("frontmatterField"),{[r]:a,[`${r}_x`]:n,[`${r}_y`]:i,[`${r}_icon`]:s,[`${r}_lock`]:l}=u;return{src:a,x:this.parseBannerPos(n),y:this.parseBannerPos(i),icon:s,lock:typeof l=="boolean"?l:l==="true"}}getBannerDataFromFile(u){if(!u)return null;let{frontmatter:r}=this.metadata.getFileCache(u);return this.getBannerData(r)}async upsertBannerData(u,r){let a=u instanceof lu.TFile?u:this.getFileByPath(u);if(!a)return;let{src:n,x:i,y:s,icon:l,lock:D}=r,c=this.plugin.getSettingValue("frontmatterField"),b={...n!==void 0&&{[c]:n},...i!==void 0&&{[`${c}_x`]:i},...s!==void 0&&{[`${c}_y`]:s},...l!==void 0&&{[`${c}_icon`]:l},...D!==void 0&&{[`${c}_lock`]:D}},h=Object.keys(b),g=(await this.vault.read(a)).split(`
`),y=g.indexOf("---"),F=y!==-1&&g.slice(0,y).every(C=>!C),v=!1;if(F){let C;for(C=y+1;C<g.length&&h.length&&!g[C].startsWith("---");C++){let[x,d]=g[C].split(": "),p=h.indexOf(x);if(p===-1)continue;let _=b[x];d!==_&&(g[C]=`${x}: ${_}`,v=!0),h.splice(p,1)}h.length&&(g.splice(C,0,...this.formatYamlFields(h,b)),C+=h.length,v=!0),g.indexOf("---",C)===-1&&(g.splice(C,0,"---"),v=!0)}else g.unshift(je`
---
${this.formatYamlFields(h,b).join(`
`)}
---
`),v=!0;if(!v)return;let M=g.join(`
`);await this.vault.modify(a,M)}async removeBannerData(u,r=WI){let a=Array.isArray(r)?r:[r],n=a.indexOf("src");n>-1&&a.splice(n,1,"");let i=this.plugin.getSettingValue("frontmatterField"),s=a.map(F=>`${i}${F?`_${F}`:""}`),{frontmatter:{position:l,...D}}=this.metadata.getFileCache(u),c=Object.keys(D??{});if(!D||!s.some(F=>c.includes(F)))return;let h=(await this.vault.read(u)).split(`
`),{line:m}=l.start,{line:g}=l.end;if(c.every(F=>s.includes(F)))h.splice(m,g-m+1);else for(let F=m+1;F<g&&s.length;F++){let[v]=h[F].split(": "),M=s.indexOf(v);M!==-1&&(h.splice(F,1),s.splice(M,1),F--,g--)}let y=h.join(`
`);await this.vault.modify(u,y)}getFileByPath(u){let r=this.vault.getAbstractFileByPath(u);return r instanceof lu.TFile?r:null}parseBannerPos(u){if(u!==void 0)return typeof u=="number"?u:parseFloat(u)}formatYamlFields(u,r){return u.map(a=>[a,`${r[a]}`]).sort((a,n)=>a[0].localeCompare(n[0])).map(([a,n])=>`${a}: ${n}`)}};var vt=S(require("obsidian"));var wt=S(require("obsidian")),Ce=S(Et());var yt=t=>{let{clientX:u,clientY:r}=t instanceof MouseEvent?t:t.targetTouches[0];return{x:u,y:r}},MM=(t,u,r)=>{if(!r&&t instanceof MouseEvent)return;let{x:a,y:n}=yt(t),{clientHeight:i,clientWidth:s,naturalHeight:l,naturalWidth:D}=t.target;u.x=a,u.y=n,u.isDragging=!0,u.vertical=l/D>=i/s},PM=(t,u)=>{if(!u.isDragging)return;let r=t.target,{x:a,y:n}=yt(t),i={x:(u.x-a)/r.clientWidth*100,y:(u.y-n)/r.clientHeight*100};u.x=a,u.y=n;let[s,l]=r.style.objectPosition.split(" ").map(D=>parseFloat(D));if(u.vertical){let D=(0,Ce.default)(l+i.y,0,100);r.style.objectPosition=`${s}% ${D}%`}else{let D=(0,Ce.default)(s+i.x,0,100);r.style.objectPosition=`${D}% ${l}%`}},qM=async(t,u,r,a)=>{if(!r.isDragging)return;r.isDragging=!1;let[n,i]=t.style.objectPosition.split(" ").map(s=>Math.round(parseFloat(s)*1e3)/1e5);await a.metaManager.upsertBannerData(u,r.vertical?{y:i}:{x:n})},LM=(t,u,r)=>{if(/^\!\[\[.+\]\]$/.test(u)){let i=u.slice(3,-2),s=t.metadataCache.getFirstLinkpathDest(i,r);return s?t.vault.getResourcePath(s):i}let a=u.startsWith("/")?u.slice(1):u,n=t.vault.getAbstractFileByPath(a);return n instanceof wt.TFile?t.vault.getResourcePath(n):u},OM=(t,u,r,a,n,i=!1)=>{let{src:s,x:l=.5,y:D=.5,lock:c}=u,b={x:null,y:null,isDragging:!1,vertical:!0},h=!i&&!c,m=document.createElement("div");m.className="banner-message",m.innerHTML=z`
<div class="spinner">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
`;let g=document.createElement("img"),y=(0,Ce.default)(l,0,1),F=(0,Ce.default)(D,0,1);g.className="banner-image full-width",g.style.objectPosition=`${y*100}% ${F*100}%`,g.draggable=!1,g.onload=()=>a.addClass("loaded"),g.onerror=()=>{m.innerHTML=`<p>Error loading banner image! Is the <code>${t.getSettingValue("frontmatterField")}</code> field valid?</p>`,a.addClass("error")};let v=[];if(h){g.classList.toggle("draggable",t.settings.bannerDragModifier==="none"||t.holdingDragModKey);let C=d=>MM(d,b,t.holdingDragModKey),j=d=>PM(d,b),x=()=>qM(g,r,b,t);v.push({target:g,ev:"mousedown",func:C},{target:g,ev:"mousemove",func:j},{target:n.parentElement,ev:"mouseup",func:x}),t.settings.allowMobileDrag&&v.push({target:g,ev:"touchstart",func:C},{target:g,ev:"touchmove",func:j},{target:n.parentElement,ev:"touchend",func:x})}v.forEach(({target:C,ev:j,func:x})=>C.addEventListener(j,x));let M=()=>v.forEach(({target:C,ev:j,func:x})=>C.removeEventListener(j,x));return g.src=LM(t,s,r),[[m,g],M]},$e=OM;var Ge=class extends vt.MarkdownRenderChild{constructor(u,r,a,n,i){super(document.createElement("div"));this.plugin=u,this.wrapper=r,this.ctx=a,this.bannerData=n,this.isEmbed=i,this.removeListeners=()=>{}}onload(){let{style:u}=this.plugin.settings,{containerEl:r,sourcePath:a}=this.ctx;this.wrapper.addClass("obsidian-banner-wrapper"),this.containerEl.addClass("obsidian-banner","cm5-banner",u);let[n,i]=$e(this.plugin,this.bannerData,a,this.containerEl,r,this.isEmbed);this.containerEl.append(...n),this.removeListeners=i,this.wrapper.prepend(this.containerEl)}onunload(){this.removeListeners()}};var Bt=S(require("obsidian"));var Tt=S(Du());var jM=(0,Tt.default)(),RM=t=>{let{iconHorizontalAlignment:u,iconVerticalAlignment:r}=t.settings,{iconHorizontalTransform:a,iconVerticalTransform:n}=L,i=u==="custom"?t.getSettingValue("iconHorizontalTransform"):a,s=r==="custom"?t.getSettingValue("iconVerticalTransform"):n;return i!==a||s!==n?`translate(${i}, ${s})`:null},HM=(t,u,r)=>{let a=document.createElement("span");a.addClass("icon-box"),a.style.transform=RM(t);let n=u.match(jM)?.join("")??u[0];return t.settings.useTwemoji?a.innerHTML=Le.parse(n):a.textContent=n,a.onclick=async()=>new re(t,r).open(),a},Ke=HM;var Ue=class extends Bt.MarkdownRenderChild{constructor(u,r,a,n){super(document.createElement("div"));this.plugin=u,this.wrapper=r,this.icon=a,this.file=n}onload(){let{iconHorizontalAlignment:u,iconVerticalAlignment:r}=this.plugin.settings;this.wrapper.addClass("has-banner-icon"),this.containerEl.addClass("obsidian-banner-icon","cm5-banner-icon",`h-${u}`,`v-${r}`);let a=Ke(this.plugin,this.icon,this.file);this.containerEl.append(a),this.wrapper.prepend(this.containerEl)}};var NM=t=>(u,r)=>{if(!u.querySelector("pre.frontmatter"))return;let{showInInternalEmbed:a,showInPreviewEmbed:n}=t.settings,{containerEl:i,frontmatter:s,sourcePath:l}=r,D=t.metaManager.getBannerData(s),c=t.metadataCache.getFirstLinkpathDest(l,"/"),b=i?.parentElement?.parentElement?.parentElement?.parentElement,h=b?.hasClass("internal-embed")??!1,m=b?.hasClass("popover")??!1;D?.icon&&r.addChild(new Ue(t,u,D.icon,c)),D?.src&&(!h||a)&&(!m||n)&&r.addChild(new Ge(t,u,r,D,h||m))},xt=NM;var Un=S(require("obsidian")),G=S(require("@codemirror/view")),Wn=S(require("@codemirror/language"));var At=S(require("@codemirror/view"));var We=class extends At.WidgetType{constructor(u,r,a,n,i){super();this.plugin=u,this.bannerData=r,this.filepath=a,this.contentEl=n,this.settingsFacet=i,this.removeListeners=()=>{}}eq(u){let{bannerData:{src:r,x:a,y:n,lock:i},filepath:s,settingsFacet:l}=u;return this.bannerData.src===r&&this.bannerData.x===a&&this.bannerData.y===n&&this.bannerData.lock===i&&this.filepath===s&&this.settingsFacet===l}toDOM(){let{plugin:u,bannerData:r,filepath:a,contentEl:n}=this,i=document.createElement("div");i.addClass("obsidian-banner","cm6-banner",u.settings.style);let[s,l]=$e(u,r,a,i,n);return i.append(...s),this.removeListeners=l,i}destroy(){this.removeListeners()}};var kt=S(require("@codemirror/view")),Ye=class extends kt.WidgetType{toDOM(){let u=document.createElement("div");return u.add
/*! Copyright Twitter Inc. and other contributors. Licensed under MIT */