vault backup: 2024-02-17 23:27:17

This commit is contained in:
2024-02-17 23:27:17 +08:00
parent b579c616cf
commit 20846242bb
36 changed files with 64670 additions and 49980 deletions

View File

@@ -3,343 +3,16 @@ THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = (target, module2, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
}
return target;
};
var __toModule = (module2) => {
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// main.ts
__export(exports, {
ColumnInsertModal: () => ColumnInsertModal,
default: () => ObsidianColumns
});
var import_obsidian2 = __toModule(require("obsidian"));
// obsidian-settings/settings.ts
var import_obsidian = __toModule(require("obsidian"));
var parseBoolean = (value) => {
return value == "yes" || value == "true";
};
var parseObject = (value, typ) => {
if (typ == "string") {
return value;
}
if (typ == "boolean") {
return parseBoolean(value);
}
if (typ == "number") {
return parseFloat(value);
}
};
function createSetting(containerEl, keyval, currentValue, onChange) {
let setting = new import_obsidian.Setting(containerEl).setName(keyval[1].name).setDesc(keyval[1].desc);
if (typeof keyval[1].value == "boolean") {
setting.addToggle((toggle) => toggle.setValue(currentValue).onChange((bool) => {
onChange(bool, keyval[0]);
}));
} else {
setting.addText((text) => text.setPlaceholder(String(keyval[1].value)).setValue(String(currentValue)).onChange((value) => {
onChange(parseObject(value, typeof keyval[1].value), keyval[0]);
}));
}
}
function display(obj, DEFAULT_SETTINGS2, name) {
const { containerEl } = obj;
containerEl.empty();
containerEl.createEl("h2", { text: "Settings for " + name });
let keyvals = Object.entries(DEFAULT_SETTINGS2);
for (let keyval of keyvals) {
createSetting(containerEl, keyval, obj.plugin.settings[keyval[0]].value, (value, key) => {
obj.plugin.settings[key].value = value;
obj.plugin.saveSettings();
});
}
}
function loadSettings(obj, DEFAULT_SETTINGS2) {
obj.settings = DEFAULT_SETTINGS2;
obj.loadData().then((data) => {
if (data) {
let items = Object.entries(data);
items.forEach((item) => {
obj.settings[item[0]].value = item[1];
});
}
});
}
function saveSettings(obj, DEFAULT_SETTINGS2) {
return __async(this, null, function* () {
let saveData = {};
Object.entries(obj.settings).forEach((i) => {
saveData[i[0]] = i[1].value;
});
yield obj.saveData(saveData);
});
}
// main.ts
var NAME = "Obsidian Columns";
var COLUMNNAME = "col";
var COLUMNMD = COLUMNNAME + "-md";
var TOKEN = "!!!";
var SETTINGSDELIM = "\n===\n";
var DEFAULT_SETTINGS = {
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" },
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." }
};
var parseSettings = (settings) => {
let o = {};
settings.split("\n").map((i) => {
return i.split(";");
}).reduce((a, b) => {
a.push(...b);
return a;
}).map((i) => {
return i.split("=").map((j) => {
return j.trim();
}).slice(0, 2);
}).forEach((i) => {
o[i[0]] = i[1];
});
return o;
};
var ObsidianColumns = class extends import_obsidian2.Plugin {
constructor() {
super(...arguments);
this.generateCssString = (span) => {
let o = {};
o.flexGrow = span.toString();
o.flexBasis = (this.settings.wrapSize.value * span).toString() + "px";
o.width = (this.settings.wrapSize.value * span).toString() + "px";
return o;
};
this.applyStyle = (el, styles) => {
Object.assign(el.style, styles);
};
this.processChild = (c) => {
if (c.firstChild != null && "tagName" in c.firstChild && c.firstChild.tagName == "BR") {
c.removeChild(c.firstChild);
}
let firstChild = c;
while (firstChild != null) {
if ("style" in firstChild) {
firstChild.style.marginTop = "0px";
}
firstChild = firstChild.firstChild;
}
let lastChild = c;
while (lastChild != null) {
if ("style" in lastChild) {
lastChild.style.marginBottom = "0px";
}
lastChild = lastChild.lastChild;
}
};
}
onload() {
return __async(this, null, function* () {
yield this.loadSettings();
this.addSettingTab(new ObsidianColumnsSettings(this.app, this));
this.registerMarkdownCodeBlockProcessor(COLUMNMD, (source, el, ctx) => {
let split = source.split(SETTINGSDELIM);
let settings = {};
if (split.length > 1) {
source = split.slice(1).join(SETTINGSDELIM);
settings = parseSettings(split[0]);
}
const sourcePath = ctx.sourcePath;
let child = el.createDiv();
let renderChild = new import_obsidian2.MarkdownRenderChild(child);
ctx.addChild(renderChild);
import_obsidian2.MarkdownRenderer.renderMarkdown(source, child, sourcePath, renderChild);
if ("flexGrow" in settings) {
let flexGrow = parseFloat(settings.flexGrow);
let CSS = this.generateCssString(flexGrow);
delete CSS.width;
this.applyStyle(child, CSS);
}
});
this.registerMarkdownCodeBlockProcessor(COLUMNNAME, (source, el, ctx) => {
const sourcePath = ctx.sourcePath;
let child = createDiv();
let renderChild = new import_obsidian2.MarkdownRenderChild(child);
ctx.addChild(renderChild);
import_obsidian2.MarkdownRenderer.renderMarkdown(source, child, sourcePath, renderChild);
let parent = el.createEl("div", { cls: "columnParent" });
Array.from(child.children).forEach((c) => {
let cc = parent.createEl("div", { cls: "columnChild" });
let renderCc = new import_obsidian2.MarkdownRenderChild(cc);
ctx.addChild(renderCc);
this.applyStyle(cc, this.generateCssString(this.settings.defaultSpan.value));
cc.appendChild(c);
if (c.classList.contains("block-language-" + COLUMNMD) && c.childNodes[0].style.flexGrow != "") {
cc.style.flexGrow = c.childNodes[0].style.flexGrow;
cc.style.flexBasis = c.childNodes[0].style.flexBasis;
cc.style.width = c.childNodes[0].style.flexBasis;
}
this.processChild(c);
});
});
this.addCommand({
id: "insert-column-wrapper",
name: "Insert column wrapper",
editorCallback: (editor, view) => {
new ColumnInsertModal(this.app, (result) => {
let num = result.numberOfColumns.value;
let outString = "````col\n";
for (let i = 0; i < num; i++) {
outString += "```col-md\nflexGrow=1\n===\n# Column " + i + "\n```\n";
}
outString += "````\n";
editor.replaceSelection(outString);
}).open();
}
});
this.addCommand({
id: "insert-column",
name: "Insert column",
editorCallback: (editor, view) => {
editor.replaceSelection("```col-md\nflexGrow=1\n===\n# New Column\n```");
}
});
let processList = (element, context) => {
for (let child of Array.from(element.children)) {
if (child == null) {
continue;
}
if (child.nodeName != "UL" && child.nodeName != "OL") {
continue;
}
for (let listItem of Array.from(child.children)) {
if (listItem == null) {
continue;
}
if (!listItem.textContent.trim().startsWith(TOKEN + COLUMNNAME)) {
processList(listItem, context);
continue;
}
child.removeChild(listItem);
let colParent = element.createEl("div", { cls: "columnParent" });
let renderColP = new import_obsidian2.MarkdownRenderChild(colParent);
context.addChild(renderColP);
let itemList = listItem.querySelector("ul, ol");
if (itemList == null) {
continue;
}
for (let itemListItem of Array.from(itemList.children)) {
let childDiv = colParent.createEl("div", { cls: "columnChild" });
let renderColC = new import_obsidian2.MarkdownRenderChild(childDiv);
context.addChild(renderColC);
let span = parseFloat(itemListItem.textContent.split("\n")[0].split(" ")[0]);
if (isNaN(span)) {
span = this.settings.defaultSpan.value;
}
this.applyStyle(childDiv, this.generateCssString(span));
let afterText = false;
processList(itemListItem, context);
for (let itemListItemChild of Array.from(itemListItem.childNodes)) {
if (afterText) {
childDiv.appendChild(itemListItemChild);
}
if (itemListItemChild.nodeName == "#text") {
afterText = true;
}
}
this.processChild(childDiv);
}
}
}
};
this.registerMarkdownPostProcessor((element, context) => {
processList(element, context);
});
});
}
onunload() {
}
loadSettings() {
return __async(this, null, function* () {
loadSettings(this, DEFAULT_SETTINGS);
});
}
saveSettings() {
return __async(this, null, function* () {
yield saveSettings(this, DEFAULT_SETTINGS);
});
}
};
var DEFAULT_MODAL_SETTINGS = {
numberOfColumns: { value: 2, name: "Number of Columns", desc: "Number of Columns to be made" }
};
var ColumnInsertModal = class extends import_obsidian2.Modal {
constructor(app, onSubmit) {
super(app);
this.onSubmit = onSubmit;
}
onOpen() {
const { contentEl } = this;
contentEl.createEl("h1", { text: "Create a Column Wrapper" });
let modalSettings = DEFAULT_MODAL_SETTINGS;
let keyvals = Object.entries(DEFAULT_MODAL_SETTINGS);
for (let keyval of keyvals) {
createSetting(contentEl, keyval, "", (value, key) => {
modalSettings[key].value = value;
});
}
new import_obsidian2.Setting(contentEl).addButton((btn) => btn.setButtonText("Submit").setCta().onClick(() => {
this.close();
this.onSubmit(modalSettings);
}));
}
onClose() {
let { contentEl } = this;
contentEl.empty();
}
};
var ObsidianColumnsSettings = class extends import_obsidian2.PluginSettingTab {
constructor(app, plugin) {
super(app, plugin);
this.plugin = plugin;
}
display() {
display(this, DEFAULT_SETTINGS, NAME);
}
};
var V=Object.create;var w=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty;var b=n=>w(n,"__esModule",{value:!0});var _=(n,t)=>{b(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 z(t))!W.call(n,l)&&l!=="default"&&w(n,l,{get:()=>t[l],enumerable:!(e=q(t,l))||e.enumerable});return n},N=n=>K(b(w(n!=null?V(j(n)):{},"default",n&&n.__esModule&&"default"in n?{get:()=>n.default,enumerable:!0}:{value:n,enumerable:!0})),n);var p=(n,t,e)=>new Promise((l,i)=>{var r=a=>{try{o(e.next(a))}catch(u){i(u)}},s=a=>{try{o(e.throw(a))}catch(u){i(u)}},o=a=>a.done?l(a.value):Promise.resolve(a.value).then(r,s);o((e=e.apply(n,t)).next())});_(exports,{ColumnInsertModal:()=>v,default:()=>x});var g=N(require("obsidian"));var L=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 E(n,t,e,l){let i=new L.Setting(n).setName(t[1].name).setDesc(t[1].desc);typeof t[1].value=="boolean"?i.addToggle(r=>r.setValue(e).onChange(s=>{l(s,t[0])})):i.addText(r=>r.setPlaceholder(String(t[1].value)).setValue(String(e)).onChange(s=>{l(Q(s,typeof t[1].value),t[0])}))}function I(n,t,e){let{containerEl:l}=n;l.empty(),l.createEl("h2",{text:"Settings for "+e});let i=Object.entries(t);for(let r of i)E(l,r,n.plugin.settings[r[0]].value,(s,o)=>{n.plugin.settings[o].value=s,n.plugin.saveSettings()})}function A(n,t){return p(this,null,function*(){return new Promise((e,l)=>{n.settings=t,n.loadData().then(i=>{i&&Object.entries(i).forEach(s=>{n.settings[s[0]].value=s[1]})}).then(e).catch(l)})})}function D(n,t){return p(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",T="col",P=T+"-md",Y="!!!",O="===";var k="--obsidian-columns-min-width",G="--obsidian-columns-def-span",Z="`",M={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())}}},H=(n,t=["`"],e=O)=>{let l=n.split(`
`),i=!1;e:for(let r of l)for(let s of t){if(r.contains(s))break e;if(r==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}},B=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,i=0,r=[];for(let s of t){let o=$(s);if(i=o<3?0:o,l==0&&i==0&&s.startsWith(O)){e.push(r.join(`
`)),r=[];continue}else l==0?l=i:l==i&&(l=0);r.push(s)}return e.push(r.join(`
`)),e},F=n=>parseFloat(n.split("").filter(t=>"0123456789.".contains(t)).join("")),x=class extends g.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 p(this,null,function*(){yield this.loadSettings(),this.addSettingTab(new R(this.app,this)),this.registerMarkdownCodeBlockProcessor(P,(e,l,i)=>{let r=H(e),s=B(r.settings);e=r.source;let o=i.sourcePath,a=l.createDiv(),u=new g.MarkdownRenderChild(a);if(i.addChild(u),g.MarkdownRenderer.renderMarkdown(e,a,o,u),s.flexGrow!=null){let d=parseFloat(s.flexGrow),f=this.generateCssString(d);delete f.width,this.applyStyle(a,f)}if(s.height!=null){let d={};d.height=s.height.toString(),d.overflow="scroll",this.applyStyle(a,d)}if(s.textAlign!=null){let d={};d.textAlign=s.textAlign,this.applyStyle(a,d)}}),this.registerMarkdownCodeBlockProcessor(T,(e,l,i)=>p(this,null,function*(){let r=H(e),s=B(r.settings),o=ee(r.source);console.log(o);for(let a of o){let u=i.sourcePath,d=createDiv(),f=new g.MarkdownRenderChild(d);i.addChild(f);let C=g.MarkdownRenderer.renderMarkdown(a,d,u,f),m=l.createEl("div",{cls:"columnParent"});if(Array.from(d.children).forEach(c=>{let h=m.createEl("div",{cls:"columnChild"}),y=new g.MarkdownRenderChild(h);i.addChild(y),this.applyStyle(h,this.generateCssString(this.settings.defaultSpan.value)),h.appendChild(c),c.classList.contains("block-language-"+P)&&c.childNodes[0].style.flexGrow!=""&&(h.style.flexGrow=c.childNodes[0].style.flexGrow,h.style.flexBasis=c.childNodes[0].style.flexBasis,h.style.width=c.childNodes[0].style.flexBasis),this.processChild(c)}),s.height!=null){let c=s.height;if(c=="shortest"){yield C;let h=Math.min(...Array.from(m.children).map(S=>S.childNodes[0]).map(S=>F(getComputedStyle(S).height)+F(getComputedStyle(S).lineHeight))),y={};y.height=h+"px",y.overflow="scroll",Array.from(m.children).map(S=>S.childNodes[0]).forEach(S=>{this.applyStyle(S,y)})}else{let h={};h.height=c,h.overflow="scroll",this.applyStyle(m,h)}}if(s.textAlign!=null){let c={};c.textAlign=s.textAlign,this.applyStyle(m,c)}}})),this.addCommand({id:"insert-column-wrapper",name:"Insert column wrapper",editorCallback:(e,l)=>{new v(this.app,i=>{let r=i.numberOfColumns.value,s="````col\n";for(let o=0;o<r;o++)s+="```col-md\nflexGrow=1\n===\n# Column "+o+"\n```\n";s+="````\n",e.replaceSelection(s)}).open()}}),this.addCommand({id:"insert-quick-column-wrapper",name:"Insert quick column wrapper",editorCallback:(e,l)=>{let i=e.getSelection(),r=e.getCursor(),s="````col\n```col-md\nflexGrow=1\n===\n"+i+"\n```\n````\n";if(e.replaceSelection(s),i==="")e.setCursor({line:r.line+4,ch:0});else{let o=i.split(`
`).length;e.setCursor({line:r.line+4+o-1,ch:i.length-i.lastIndexOf(`
`)-1})}}}),this.addCommand({id:"insert-column",name:"Insert column",editorCallback:(e,l)=>{let i=e.getSelection(),r=e.getCursor(),s;if(i==="")s="```col-md\nflexGrow=1\n===\n# New Column\n\n```",e.replaceSelection(s),e.setCursor({line:r.line+4,ch:0});else{s="```col-md\nflexGrow=1\n===\n"+i+"\n```",e.replaceSelection(s);let o=i.split(`
`).length;e.setCursor({line:r.line+o+2,ch:i.length-i.lastIndexOf(`
`)-1})}}});let t=(e,l)=>{for(let i of Array.from(e.children))if(i!=null&&!(i.nodeName!="UL"&&i.nodeName!="OL"))for(let r of Array.from(i.children)){if(r==null)continue;if(!r.textContent.trim().startsWith(Y+T)){t(r,l);continue}i.removeChild(r);let s=e.createEl("div",{cls:"columnParent"}),o=new g.MarkdownRenderChild(s);l.addChild(o);let a=r.querySelector("ul, ol");if(a!=null)for(let u of Array.from(a.children)){let d=s.createEl("div",{cls:"columnChild"}),f=new g.MarkdownRenderChild(d);l.addChild(f);let C=parseFloat(u.textContent.split(`
`)[0].split(" ")[0]);isNaN(C)&&(C=this.settings.defaultSpan.value),this.applyStyle(d,this.generateCssString(C));let m=!1;t(u,l);for(let c of Array.from(u.childNodes))m&&d.appendChild(c),c.nodeName=="#text"&&(m=!0);this.processChild(d)}}};this.registerMarkdownPostProcessor((e,l)=>{t(e,l)})})}onunload(){}loadSettings(){return p(this,null,function*(){yield A(this,M);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 p(this,null,function*(){yield D(this,M)})}},U={numberOfColumns:{value:2,name:"Number of Columns",desc:"Number of Columns to be made"}},v=class extends g.Modal{constructor(t,e){super(t);this.onSubmit=e}onOpen(){let{contentEl:t}=this;t.createEl("h1",{text:"Create a Column Wrapper"});let e=U,l=Object.entries(U);for(let i of l)E(t,i,"",(r,s)=>{e[s].value=r});new g.Setting(t).addButton(i=>i.setButtonText("Submit").setCta().onClick(()=>{this.close(),this.onSubmit(e)}))}onClose(){let{contentEl:t}=this;t.empty()}},R=class extends g.PluginSettingTab{constructor(t,e){super(t,e);this.plugin=e}display(){I(this,M,X)}};