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

20 lines
9.1 KiB
JavaScript

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var U=Object.create;var w=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var v=n=>w(n,"__esModule",{value:!0});var _=(n,t)=>{v(n);for(var e in t)w(n,e,{get:t[e],enumerable:!0})},K=(n,t,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of V(t))!j.call(n,l)&&l!=="default"&&w(n,l,{get:()=>t[l],enumerable:!(e=W(t,l))||e.enumerable});return n},N=n=>K(v(w(n!=null?U(q(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var m=(n,t,e)=>new Promise((l,r)=>{var s=a=>{try{o(e.next(a))}catch(h){r(h)}},i=a=>{try{o(e.throw(a))}catch(h){r(h)}},o=a=>a.done?l(a.value):Promise.resolve(a.value).then(s,i);o((e=e.apply(n,t)).next())});_(exports,{ColumnInsertModal:()=>x,default:()=>M});var u=N(require("obsidian"));var I=N(require("obsidian")),J=n=>n=="yes"||n=="true",Q=(n,t)=>{if(t=="string")return n;if(t=="boolean")return J(n);if(t=="number")return parseFloat(n)};function T(n,t,e,l){let r=new I.Setting(n).setName(t[1].name).setDesc(t[1].desc);typeof t[1].value=="boolean"?r.addToggle(s=>s.setValue(e).onChange(i=>{l(i,t[0])})):r.addText(s=>s.setPlaceholder(String(t[1].value)).setValue(String(e)).onChange(i=>{l(Q(i,typeof t[1].value),t[0])}))}function L(n,t,e){let{containerEl:l}=n;l.empty(),l.createEl("h2",{text:"Settings for "+e});let r=Object.entries(t);for(let s of r)T(l,s,n.plugin.settings[s[0]].value,(i,o)=>{n.plugin.settings[o].value=i,n.plugin.saveSettings()})}function D(n,t){return m(this,null,function*(){return new Promise((e,l)=>{n.settings=t,n.loadData().then(r=>{r&&Object.entries(r).forEach(i=>{n.settings[i[0]].value=i[1]})}).then(e).catch(l)})})}function P(n,t){return m(this,null,function*(){let e={};Object.entries(n.settings).forEach(l=>{e[l[0]]=l[1].value,l[1].onChange(l[1].value)}),yield n.saveData(e)})}var X="Obsidian Columns",E="col",O=E+"-md",Y="!!!",A="===";var k="--obsidian-columns-min-width",G="--obsidian-columns-def-span",Z="`",b={wrapSize:{value:100,name:"Minimum width of column",desc:"Columns will have this minimum width before wrapping to a new row. 0 disables column wrapping. Useful for smaller devices",onChange:n=>{document.querySelector(":root").style.setProperty(k,n.toString()+"px")}},defaultSpan:{value:1,name:"The default span of an item",desc:"The default width of a column. If the minimum width is specified, the width of the column will be multiplied by this setting.",onChange:n=>{document.querySelector(":root").style.setProperty(G,n.toString())}}},B=(n,t=["`"],e=A)=>{let l=n.split(`
`),r=!1;e:for(let s of l)for(let i of t){if(s.contains(i))break e;if(s==e){let o=n.split(e+`
`);if(o.length>1)return{settings:o[0],source:o.slice(1).join(e+`
`)};break e}}return{settings:"",source:n}},H=n=>{let t={};return n.split(`
`).map(e=>e.split(";")).reduce((e,l)=>(e.push(...l),e)).map(e=>e.split("=").map(l=>l.trim()).slice(0,2)).forEach(e=>{t[e[0]]=e[1]}),t},$=n=>{let t=0,e=n.split("");for(let l of e)if(l==Z)t++;else break;return t},ee=n=>{let t=n.split(`
`),e=[],l=0,r=0,s=[];for(let i of t){let o=$(i);if(r=o<3?0:o,l==0&&r==0&&i.startsWith(A)){e.push(s.join(`
`)),s=[];continue}else l==0?l=r:l==r&&(l=0);s.push(i)}return e.push(s.join(`
`)),e},R=n=>parseFloat(n.split("").filter(t=>"0123456789.".contains(t)).join("")),M=class extends u.Plugin{constructor(){super(...arguments);this.generateCssString=t=>{let e={};return e.flexGrow=t.toString(),e.flexBasis=(this.settings.wrapSize.value*t).toString()+"px",e.width=(this.settings.wrapSize.value*t).toString()+"px",e};this.applyStyle=(t,e)=>{Object.assign(t.style,e)};this.processChild=t=>{t.firstChild!=null&&"tagName"in t.firstChild&&t.firstChild.tagName=="BR"&&t.removeChild(t.firstChild);let e=t;for(;e!=null;)"style"in e&&(e.style.marginTop="0px"),e=e.firstChild;let l=t;for(;l!=null;)"style"in l&&(l.style.marginBottom="0px"),l=l.lastChild}}onload(){return m(this,null,function*(){yield this.loadSettings(),this.addSettingTab(new F(this.app,this)),this.registerMarkdownCodeBlockProcessor(O,(e,l,r)=>{let s=B(e),i=H(s.settings);e=s.source;let o=r.sourcePath,a=l.createDiv(),h=new u.MarkdownRenderChild(a);if(r.addChild(h),u.MarkdownRenderer.renderMarkdown(e,a,o,h),i.flexGrow!=null){let d=parseFloat(i.flexGrow),f=this.generateCssString(d);delete f.width,this.applyStyle(a,f)}if(i.height!=null){let d={};d.height=i.height.toString(),d.overflow="scroll",this.applyStyle(a,d)}if(i.textAlign!=null){let d={};d.textAlign=i.textAlign,this.applyStyle(a,d)}this.applyPotentialBorderStyling(i,a)}),this.registerMarkdownCodeBlockProcessor(E,(e,l,r)=>m(this,null,function*(){let s=B(e),i=H(s.settings),o=ee(s.source);console.log(o);for(let a of o){let h=r.sourcePath,d=createDiv(),f=new u.MarkdownRenderChild(d);r.addChild(f);let y=u.MarkdownRenderer.renderMarkdown(a,d,h,f),S=l.createEl("div",{cls:"columnParent"});if(Array.from(d.children).forEach(g=>{let c=S.createEl("div",{cls:"columnChild"}),C=new u.MarkdownRenderChild(c);r.addChild(C),this.applyStyle(c,this.generateCssString(this.settings.defaultSpan.value)),c.appendChild(g),g.classList.contains("block-language-"+O)&&g.childNodes[0].style.flexGrow!=""&&(c.style.flexGrow=g.childNodes[0].style.flexGrow,c.style.flexBasis=g.childNodes[0].style.flexBasis,c.style.width=g.childNodes[0].style.flexBasis),this.processChild(g)}),i.height!=null){let g=i.height;if(g=="shortest"){yield y;let c=Math.min(...Array.from(S.children).map(p=>p.childNodes[0]).map(p=>R(getComputedStyle(p).height)+R(getComputedStyle(p).lineHeight))),C={};C.height=c+"px",C.overflow="scroll",Array.from(S.children).map(p=>p.childNodes[0]).forEach(p=>{this.applyStyle(p,C)})}else{let c={};c.height=g,c.overflow="scroll",this.applyStyle(S,c)}}if(i.textAlign!=null){let g={};g.textAlign=i.textAlign,this.applyStyle(S,g)}this.applyPotentialBorderStyling(i,S)}})),this.addCommand({id:"insert-column-wrapper",name:"Insert column wrapper",editorCallback:(e,l)=>{new x(this.app,r=>{let s=r.numberOfColumns.value,i="````col\n";for(let o=0;o<s;o++)i+="```col-md\nflexGrow=1\n===\n# Column "+o+"\n```\n";i+="````\n",e.replaceSelection(i)}).open()}}),this.addCommand({id:"insert-quick-column-wrapper",name:"Insert quick column wrapper",editorCallback:(e,l)=>{let r=e.getSelection(),s=e.getCursor(),i="````col\n```col-md\nflexGrow=1\n===\n"+r+"\n```\n````\n";if(e.replaceSelection(i),r==="")e.setCursor({line:s.line+4,ch:0});else{let o=r.split(`
`).length;e.setCursor({line:s.line+4+o-1,ch:r.length-r.lastIndexOf(`
`)-1})}}}),this.addCommand({id:"insert-column",name:"Insert column",editorCallback:(e,l)=>{let r=e.getSelection(),s=e.getCursor(),i;if(r==="")i="```col-md\nflexGrow=1\n===\n# New Column\n\n```",e.replaceSelection(i),e.setCursor({line:s.line+4,ch:0});else{i="```col-md\nflexGrow=1\n===\n"+r+"\n```",e.replaceSelection(i);let o=r.split(`
`).length;e.setCursor({line:s.line+o+2,ch:r.length-r.lastIndexOf(`
`)-1})}}});let t=(e,l)=>{for(let r of Array.from(e.children))if(r!=null&&!(r.nodeName!="UL"&&r.nodeName!="OL"))for(let s of Array.from(r.children)){if(s==null)continue;if(!s.textContent.trim().startsWith(Y+E)){t(s,l);continue}r.removeChild(s);let i=e.createEl("div",{cls:"columnParent"}),o=new u.MarkdownRenderChild(i);l.addChild(o);let a=s.querySelector("ul, ol");if(a!=null)for(let h of Array.from(a.children)){let d=i.createEl("div",{cls:"columnChild"}),f=new u.MarkdownRenderChild(d);l.addChild(f);let y=parseFloat(h.textContent.split(`
`)[0].split(" ")[0]);isNaN(y)&&(y=this.settings.defaultSpan.value),this.applyStyle(d,this.generateCssString(y));let S=!1;t(h,l);for(let g of Array.from(h.childNodes))S&&d.appendChild(g),g.nodeName=="#text"&&(S=!0);this.processChild(d)}}};this.registerMarkdownPostProcessor((e,l)=>{t(e,l)})})}applyPotentialBorderStyling(t,e){var r,s;if(t.borderColor!=null||t.borderStyle!=null||t.borderWidth!=null||t.borderRadius!=null||t.borderPadding!=null){let i={};i.borderColor=(r=t.borderColor)!=null?r:"white",i.borderStyle=(s=t.borderStyle)!=null?s:"solid",i.borderWidth=this.parseBorderSizeInput(t.borderWidth,"1px"),i.borderRadius=this.parseBorderSizeInput(t.borderRadius),i.padding=this.parseBorderSizeInput(t.borderPadding),this.applyStyle(e,i)}}parseBorderSizeInput(t,e="0"){return t==null?e:+t?t+"px":t}onunload(){}loadSettings(){return m(this,null,function*(){yield D(this,b);let t=document.querySelector(":root");console.log(this.settings.wrapSize.value.toString()),t.style.setProperty(k,this.settings.wrapSize.value.toString()+"px"),t.style.setProperty(G,this.settings.defaultSpan.value.toString())})}saveSettings(){return m(this,null,function*(){yield P(this,b)})}},z={numberOfColumns:{value:2,name:"Number of Columns",desc:"Number of Columns to be made"}},x=class extends u.Modal{constructor(t,e){super(t);this.onSubmit=e}onOpen(){let{contentEl:t}=this;t.createEl("h1",{text:"Create a Column Wrapper"});let e=z,l=Object.entries(z);for(let r of l)T(t,r,"",(s,i)=>{e[i].value=s});new u.Setting(t).addButton(r=>r.setButtonText("Submit").setCta().onClick(()=>{this.close(),this.onSubmit(e)}))}onClose(){let{contentEl:t}=this;t.empty()}},F=class extends u.PluginSettingTab{constructor(t,e){super(t,e);this.plugin=e}display(){L(this,b,X)}};
/* nosourcemap */