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.

36 lines
132 KiB

3 years ago
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source visit the plugins github repository (https://github.com/Vinzent03/obsidian-advanced-uri)
3 years ago
*/
2 months ago
var gt=Object.create;var ae=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var xt=Object.getOwnPropertyNames;var vt=Object.getPrototypeOf,wt=Object.prototype.hasOwnProperty;var De=(o,n)=>()=>(n||o((n={exports:{}}).exports,n),n.exports),jt=(o,n)=>{for(var e in n)ae(o,e,{get:n[e],enumerable:!0})},Ve=(o,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of xt(n))!wt.call(o,i)&&i!==e&&ae(o,i,{get:()=>n[i],enumerable:!(t=mt(n,i))||t.enumerable});return o};var xe=(o,n,e)=>(e=o!=null?gt(vt(o)):{},Ve(n||!o||!o.__esModule?ae(e,"default",{value:o,enumerable:!0}):e,o)),bt=o=>Ve(ae({},"__esModule",{value:!0}),o);var Le=De((Y,ve)=>{(function(n,e){typeof Y=="object"&&typeof ve=="object"?ve.exports=e():typeof define=="function"&&define.amd?define([],e):typeof Y=="object"?Y.feather=e():n.feather=e()})(typeof self!="undefined"?self:Y,function(){return function(o){var n={};function e(t){if(n[t])return n[t].exports;var i=n[t]={i:t,l:!1,exports:{}};return o[t].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=o,e.c=n,e.d=function(t,i,a){e.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:a})},e.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},e.p="",e(e.s=0)}({"./dist/icons.json":function(o){o.exports={activity:'<polyline points="22 12 18 12 15 21 9 3 6 12 2 12"></polyline>',airplay:'<path d="M5 17H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-1"></path><polygon points="12 15 17 21 7 21 12 15"></polygon>',"alert-circle":'<circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line>',"alert-octagon":'<polygon points="7.86 2 16.14 2 22 7.86 22 16.14 16.14 22 7.86 22 2 16.14 2 7.86 7.86 2"></polygon><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line>',"alert-triangle":'<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12.01" y2="17"></line>',"align-center":'<line x1="18" y1="10" x2="6" y2="10"></line><line x1="21" y1="6" x2="3" y2="6"></line><line x1="21" y1="14" x2="3" y2="14"></line><line x1="18" y1="18" x2="6" y2="18"></line>',"align-justify":'<line x1="21" y1="10" x2="3" y2="10"></line><line x1="21" y1="6" x2="3" y2="6"></line><line x1="21" y1="14" x2="3" y2="14"></line><line x1="21" y1="18" x2="3" y2="18"></line>',"align-left":'<line x1="17" y1="10" x2="3" y2="10"></line><line x1="21" y1="6" x2="3" y2="6"></line><line x1="21" y1="14" x2="3" y2="14"></line><line x1="17" y1="18" x2="3" y2="18"></line>',"align-right":'<line x1="21" y1="10" x2="7" y2="10"></line><line x1="21" y1="6" x2="3" y2="6"></line><line x1="21" y1="14" x2="3" y2="14"></line><line x1="21" y1="18" x2="7" y2="18"></line>',anchor:'<circle cx="12" cy="5" r="3"></circle><line x1="12" y1="22" x2="12" y2="8"></line><path d="M5 12H2a10 10 0 0 0 20 0h-3"></path>',aperture:'<circle cx="12" cy="12" r="10"></circle><line x1="14.31" y1="8" x2="20.05" y2="17.94"></line><line x1="9.69" y1="8" x2="21.17" y2="8"></line><line x1="7.38" y1="12" x2="13.12" y2="2.06"></line><line x1="9.69" y1="16" x2="3.95" y2="6.06"></line><line x1="14.31" y1="16" x2="2.83" y2="16"></line><line x1="16.62" y1="12" x2="10.88" y2="21.94"></line>',archive:'<polyline points="21 8 21 21 3 21 3 8"></polyline><rect x="1" y="3" width="22" height="5"></rect><line x1="10" y1="12" x2="14" y2="12"></line>',"arrow-down-circle":'<circle cx="12" cy="12" r="10"></circle><polyline points="8 12 12 16 16 12"></polyline><line x1="12" y1="8" x2="12" y2="16"></line>',"arrow-down-left":'<line x1="17" y1="7" x2="7" y2="17"></line><polyline points="17 17 7 17 7 7"></polyline>',"arrow-down-right":'<line x1="7" y1="7" x2="17" y2="17"></line><polyline points="17 7 17 17 7 17"></polyline>',"arrow-down":'<line x1="12" y1="5" x2="12" y2="
`:" ";return n.replaceRange(`${r}^${l}`,a),l}static shouldInsertAfter(n){if(n.type)return["blockquote","code","table","heading","comment","footnoteDefinition"].includes(n.type)}static getBlockId(n){let e=n.workspace.getActiveViewOfType(qe.MarkdownView);if(e){let t=e.editor,i=e.file,a=this.getBlock(n,t,i);if(a)return this.getIdOfBlock(t,a)}}};var _e={openFileOnWrite:!0,openDailyInNewPane:!1,openFileOnWriteInNewPane:!1,openFileWithoutWriteInNewPane:!1,idField:"id",useUID:!1,addFilepathWhenUsingUID:!1,allowEval:!1,includeVaultName:!0,vaultParam:"name"};var et=require("obsidian"),tt=xe(Ie());function nt(...o){let n=[];for(let t=0,i=o.length;t<i;t++)n=n.concat(o[t].split("/"));let e=[];for(let t=0,i=n.length;t<i;t++){let a=n[t];!a||a==="."||e.push(a)}return n[0]===""&&e.unshift(""),e.join("/")}async function Yt(o,n){n.endsWith(".md")||(n+=".md");let e=(0,et.normalizePath)(nt(o,n));return await Kt(e),e}async function Kt(o){let n=o.replace(/\\/g,"/").split("/");if(n.pop(),n.length){let e=nt(...n);window.app.vault.getAbstractFileByPath(e)||await window.app.vault.createFolder(e)}}async function it(o){let{format:n,folder:e}=(0,tt.getDailyNoteSettings)(),t=o.format(n);return await Yt(e,t)}var w=require("obsidian");var ot=require("obsidian"),B=class extends ot.SuggestModal{constructor(e,t){super(e.app);this.file=t;this.modes=[null,"overwrite","append","prepend"];this.plugin=e,this.setPlaceholder("Type your data to be written to the file or leave it empty to just open it")}getSuggestions(e){e==""&&(e=null);let t=[];for(let i of this.modes)if(!(i==="overwrite"&&!e)){let a;e?i?a=`Write "${e}" in ${i} mode`:a=`Write "${e}"`:i?a=`Open in ${i} mode`:a="Open",t.push({data:e,display:a,mode:i,func:()=>{this.file?this.plugin.tools.copyURI({filepath:this.file,data:e,mode:i}):this.plugin.tools.copyURI({daily:"true",data:e,mode:i})}})}return t}renderSuggestion(e,t){t.innerText=e.display}onChooseSuggestion(e,t){e.func()}};var at=require("obsidian"),V=class extends at.FuzzySuggestModal{constructor(e,t,i=!0){super(e.app);this.placeHolder=t;this.allowNoFile=i;this.plugin=e,this.setPlaceholder(this.placeHolder)}getItems(){let e=[];this.allowNoFile&&e.push({display:"<Don't specify a file>",source:void 0});let t=this.app.workspace.getActiveFile();return t&&e.push({display:"<Current file>",source:t.path}),[...e,...this.app.vault.getFiles().map(i=>({display:i.path,source:i.path}))]}getItemText(e){return e.display}onChooseItem(e,t){}};var lt=require("obsidian");function Se(o){return o.viewmode?{state:{mode:o.viewmode,source:o.viewmode=="source"}}:void 0}function ee(o){return navigator.clipboard.writeText(o)}function re(o,n){var a;let e=(a=n.parent)==null?void 0:a.path,t=e==="/"?"":e,i=n.name;for(let l=1;l<100;l++){let r=K(i),c=t+(t==""?"":"/")+r+` ${l}.md`;if(!(o.vault.getAbstractFileByPath(c)!==null))return c}}function rt(o,n){let e=new URL(o.vault.getResourcePath(n));return e.host="localhosthostlocal",e.protocol="file",e.search="",e.pathname=decodeURIComponent(e.pathname),e.toString().replace("/localhosthostlocal/","/")}function Oe(o,n,e){var l,r;let t=o.metadataCache.getFileCache(n),i=t.sections,a=(l=t.headings)==null?void 0:l.find(c=>c.heading===e);if(a){let c=i.findIndex(u=>u.type==="heading"&&u.position.start.line===a.position.start.line),s=i.slice(c+1),d=s==null?void 0:s.findIndex(u=>u.type==="heading");return{lastLine:((r=s[(d!==-1?d:s.length)-1])!=null?r:i[c]).position.end.line+1,firstLine:i[c].position.end.line+1}}else new lt.Notice("Can't find heading")}var te=class{constructor(n){this.plugin=n;this.app=this.plugin.app}get tools(){return this.plugin.tools}handlePluginManagement(n){if(n["enable-plugin"]){let e=n["enable-plugin"];this.app.plugins.getPlugin(e)?(this.app.plugins.enablePluginAndSave(e),new w.Notice(`Enabled ${e}`)):this.app.internalPlugins.plugins[e]&&(this.app.internalPlugins.plugins[e].enable(!0),new w.Notice(`Enabled ${e}`))}else if(n["disable-plugin"]){let e=n["disable-plugin"];this.app.plugins.getPlugin(e)?(this.app.plugins.disablePluginAndSave(e),new w.Notice(`Disabled ${e}`)):this.app.internalPlugins.plugins[e]&&(this.app.in
`);let a=t.lineCount();t.setCursor({ch:0,line:a})}else n.mode==="prepend"?(t.setValue(`
`+i),t.setCursor({ch:0,line:0})):n.mode==="overwrite"&&t.setValue("")}}else n.line!=null||n.column!=null||n.offset!=null?(await this.plugin.open({file:n.filepath,mode:"source",parameters:n}),await this.plugin.setCursorInLine(n)):await this.plugin.open({file:n.filepath,setting:this.plugin.settings.openFileWithoutWriteInNewPane,parameters:n});else(n.openmode||n.viewmode)&&await this.plugin.open({parameters:n});if(n.commandid)this.app.commands.executeCommandById(n.commandid);else if(n.commandname){let e=this.app.commands.commands;for(let t in e)if(e[t].name===n.commandname){e[t].callback?await e[t].callback():e[t].checkCallback(!1);break}}if(n.confirm&&n.confirm!="false"){await new Promise(t=>setTimeout(t,750));let e=document.querySelector(".mod-cta:not([style*='display: none'])");e.click instanceof Function&&e.click()}this.plugin.success(n)}async handleEval(n){if(n.filepath)if(n.mode){if(n.mode=="new"){let t=this.app.metadataCache.getFirstLinkpathDest(n.filepath,"/");t instanceof w.TFile&&(n.filepath=re(this.app,t))}await this.plugin.open({file:n.filepath,mode:"source",parameters:n});let e=this.app.workspace.getActiveViewOfType(w.MarkdownView);if(e){let t=e.editor,i=t.getValue();if(n.mode==="append"){t.setValue(i+`
`);let a=t.lineCount();t.setCursor({ch:0,line:a})}else n.mode==="prepend"?(t.setValue(`
`+i),t.setCursor({ch:0,line:0})):n.mode==="overwrite"&&t.setValue("")}}else n.line!=null||n.column!=null||n.offset!=null?(await this.plugin.open({file:n.filepath,mode:"source",parameters:n}),await this.plugin.setCursorInLine(n)):await this.plugin.open({file:n.filepath,setting:this.plugin.settings.openFileWithoutWriteInNewPane,parameters:n});this.plugin.settings.allowEval?((0,eval)(n.eval),this.plugin.success(n)):(new w.Notice("Eval is not allowed. Please enable it in the settings."),this.plugin.failure(n))}async handleDoesFileExist(n){let e=await this.app.vault.adapter.exists(n.filepath);ee((e?1:0).toString()),this.plugin.success(n)}async handleSearchAndReplace(n){let e;if(n.filepath){let t=this.app.vault.getAbstractFileByPath(n.filepath);t instanceof w.TFile&&(e=t)}else e=this.app.workspace.getActiveFile();if(e){let t=await this.app.vault.read(e);if(n.searchregex)try{let[,,i,a]=n.searchregex.match(/(\/?)(.+)\1([a-z]*)/i),l=new RegExp(i,a);t=t.replace(l,n.replace),this.plugin.success(n)}catch(i){new w.Notice(`Can't parse ${n.searchregex} as RegEx`),this.plugin.failure(n)}else t=t.replaceAll(n.search,n.replace),this.plugin.success(n);await this.plugin.writeAndOpenFile(e.path,t,n)}else new w.Notice("Cannot find file"),this.plugin.failure(n)}async handleSearch(n){n.filepath&&await this.plugin.open({file:n.filepath,parameters:n});let e=this.app.workspace.getActiveViewOfType(w.FileView);e.currentMode.showSearch();let t=e.currentMode.search;t.searchInputEl.value=n.search,t.searchInputEl.dispatchEvent(new Event("input"))}async handleWrite(n,e=!1){var i;let t;if(n.filepath?t=this.app.vault.getAbstractFileByPath(n.filepath):t=this.app.workspace.getActiveFile(),n.filepath||t){let a,l=(i=n.filepath)!=null?i:t.path;n.mode==="overwrite"?(a=await this.plugin.writeAndOpenFile(l,n.data,n),this.plugin.success(n)):n.mode==="prepend"?(t instanceof w.TFile?a=await this.plugin.prepend(t,n):a=await this.plugin.prepend(l,n),this.plugin.success(n)):n.mode==="append"?(t instanceof w.TFile?a=await this.plugin.append(t,n):a=await this.plugin.append(l,n),this.plugin.success(n)):n.mode==="new"?t instanceof w.TFile?(a=await this.plugin.writeAndOpenFile(re(this.app,t),n.data,n),this.plugin.hookSuccess(n,a)):(a=await this.plugin.writeAndOpenFile(l,n.data,n),this.plugin.hookSuccess(n,a)):!e&&t instanceof w.TFile?(new w.Notice("File already exists"),this.plugin.openExistingFileAndSetCursor(t.path,n),this.plugin.failure(n)):(a=await this.plugin.writeAndOpenFile(l,n.data,n),this.plugin.success(n)),n.uid&&this.tools.writeUIDToFile(a,n.uid)}else new w.Notice("Cannot find file"),this.plugin.failure(n)}async handleOpen(n){if(n.heading!=null){await this.plugin.open({file:n.filepath+"#"+n.heading,setting:this.plugin.settings.openFileWithoutWriteInNewPane,parameters:n});let e=this.app.workspace.getActiveViewOfType(w.MarkdownView);if(!e)return;let i=this.app.metadataCache.getFileCache(e.file).headings.find(a=>a.heading===n.heading);e.editor.focus(),e.editor.setCursor({line:i.position.start.line+1,ch:0})}else if(n.block!=null){await this.plugin.open({file:n.filepath+"#^"+n.block,setting:this.plugin.settings.openFileWithoutWriteInNewPane,parameters:n});let e=this.app.workspace.getActiveViewOfType(w.MarkdownView);if(!e)return;let i=this.app.metadataCache.getFileCache(e.file).blocks[n.block];e.editor.focus(),e.editor.setCursor({line:i.position.start.line,ch:0})}else await this.plugin.open({file:n.filepath,setting:this.plugin.settings.openFileWithoutWriteInNewPane,parameters:n}),(n.line!=null||n.column!=null||n.offset!=null)&&await this.plugin.setCursorInLine(n);if(n.mode!=null&&await this.plugin.setCursor(n),n.uid){let e=this.app.workspace.getActiveViewOfType(w.MarkdownView);this.tools.writeUIDToFile(e.file,n.uid)}this.plugin.success(n)}async handleOpenBlock(n){let e=this.tools.getFileFromBlockID(n.block);e&&await this.plugin.chooseHandler({...n,filepath:e.path},!1)}handleCopyFileURI(n,e){let t=this.app.workspace.getActiveViewOfType(w.FileView);if(!(!t&&!e)){if(t instanceof w.MarkdownView){let i=t.editor.getCursor(),a=this.app.metadataCache.getFileCache(t.file);if(a.
`),r=`${this.plugin.settings.idField}:`;if(a)l.unshift("---"),l.unshift(`${r} ${e}`),l.unshift("---");else{let d=l.findIndex(p=>p.startsWith(r));d!=-1?l[d]=`${r} ${e}`:l.splice(1,0,`${r} ${e}`)}let c=l.join(`
`);return await this.app.vault.modify(n,c),e}async getUIDFromFile(n){var i;let e=(i=this.app.metadataCache.getFileCache(n))!=null?i:await new Promise(a=>{let l=this.app.metadataCache.on("changed",r=>{if(r.path==n.path){let c=this.app.metadataCache.getFileCache(n);this.app.metadataCache.offref(l),a(c)}})}),t=(0,L.parseFrontMatterEntry)(e.frontmatter,this.plugin.settings.idField);return t!=null?t instanceof Array?t[0]:t:await this.writeUIDToFile(n,ke())}async generateURI(n){let e="obsidian://adv-uri",t="",i=this.app.vault.getAbstractFileByPath(n.filepath);this.settings.includeVaultName&&(t+="?vault=",this.settings.vaultParam=="id"&&this.app.appId?t+=encodeURIComponent(this.app.appId):t+=encodeURIComponent(this.app.vault.getName())),this.settings.useUID&&i instanceof L.TFile&&i.extension=="md"&&(this.settings.addFilepathWhenUsingUID||(n.filepath=void 0),n.uid=await this.getUIDFromFile(i));let a=Object.keys(n).filter(l=>n[l]).sort((l,r)=>{let c=["filepath","filename","uid","daily"],s=["data","eval"];return c.includes(l)?-1:c.includes(r)||s.includes(l)?1:s.includes(r)?-1:0});for(let l of a)n[l]!=null&&(t+=t?"&":"?",t+=`${l}=${encodeURIComponent(n[l])}`);return t.endsWith("%20")&&(t+="&"),e+t}async copyURI(n){let e=await this.generateURI(n);await ee(e),new L.Notice("Advanced URI copied to your clipboard")}getFileFromUID(n){var i;let e=this.app.vault.getMarkdownFiles(),t=this.settings.idField;for(let a of e){let l=(0,L.parseFrontMatterEntry)((i=this.app.metadataCache.getFileCache(a))==null?void 0:i.frontmatter,t);if(l instanceof Array){if(l.contains(n))return a}else if(l==n)return a}}getFileFromBlockID(n){var t,i;let e=this.app.vault.getMarkdownFiles();for(let a of e)if(((i=(t=this.app.metadataCache.getFileCache(a))==null?void 0:t.blocks)==null?void 0:i[n])!=null)return a}};var fe=require("obsidian"),ye=class extends fe.FuzzySuggestModal{constructor(e){super(e.app);this.plugin=e,this.setPlaceholder("Choose a workspace")}getItems(){let e=this.app.internalPlugins.getEnabledPluginById("workspaces");if(!e)new fe.Notice("Workspaces plugin is not enabled");else return Object.keys(e.workspaces)}getItemText(e){return e}onChooseItem(e,t){this.plugin.tools.copyURI({workspace:e})}};var ge=class extends j.Plugin{constructor(){super(...arguments);this.handlers=new te(this);this.tools=new ne(this)}async onload(){await this.loadSettings(),this.addSettingTab(new pe(this.app,this)),this.addCommand({id:"copy-uri-current-file",name:"Copy URI for file with options",callback:()=>this.handlers.handleCopyFileURI(!1)}),this.addCommand({id:"copy-uri-current-file-simple",name:"Copy URI for current file",callback:()=>this.handlers.handleCopyFileURI(!0)}),this.addCommand({id:"copy-uri-daily",name:"Copy URI for daily note",callback:()=>new B(this).open()}),this.addCommand({id:"copy-uri-search-and-replace",name:"Copy URI for search and replace",callback:()=>{let e=new V(this,"Used file for search and replace");e.open(),e.onChooseItem=t=>{let i=new de(this);i.open(),i.onChooseSuggestion=a=>{new ce(this,a,t==null?void 0:t.source).open()}}}}),this.addCommand({id:"copy-uri-command",name:"Copy URI for command",callback:()=>{let e=new V(this,"Select a file to be opened before executing the command");e.open(),e.onChooseItem=t=>{new se(this,t==null?void 0:t.source).open()}}}),this.addCommand({id:"copy-uri-block",name:"Copy URI for current block",checkCallback:e=>{let t=this.app.workspace.getActiveViewOfType(j.MarkdownView);if(e)return t!=null;let i=le.getBlockId(this.app);i&&this.tools.copyURI({filepath:t.file.path,block:i})}}),this.addCommand({id:"copy-uri-workspace",name:"Copy URI for workspace",callback:()=>{new ye(this).open()}}),this.addCommand({id:"copy-uri-canvas-node",name:"Copy URI for selected canvas nodes",checkCallback:e=>{let t=this.app.workspace.activeLeaf.view;if(e)return t.getViewType()==="canvas"&&t.canvas.selection.size>0;if(t.getViewType()!=="canvas")return!1;let i=t,a=[];i.canvas.selection.forEach(l=>{a.push(l.id)}),this.tools.copyURI({canvasnodes:a.join(","),filepath:t.file.path})}}),this.addCommand({id:"copy-uri-canvas-viewport",name:"Copy UR
`);s.splice(r,0,...t.data.split(`
`)),a=s.join(`
`)}}else if(e instanceof j.TFile){i=e.path;let r=await this.app.vault.read(e);if(t.line){let c=Math.max(Number(t.line),0),s=r.split(`
`);s.splice(c,0,t.data),a=s.join(`
`)}else a=r+`
`+t.data}else i=e,a=t.data;return this.writeAndOpenFile(i,a,t)}async prepend(e,t){var l;let i,a;if(t.heading){if(e instanceof j.TFile){i=e.path;let r=(l=Oe(this.app,e,t.heading))==null?void 0:l.firstLine;if(r===void 0)return;let s=(await this.app.vault.read(e)).split(`
`);s.splice(r,0,...t.data.split(`
`)),a=s.join(`
`)}}else if(e instanceof j.TFile){i=e.path;let r=await this.app.vault.read(e),c=this.app.metadataCache.getFileCache(e),s=0;t.line?s+=Math.max(Number(t.line)-1,0):c.frontmatterPosition&&(s+=c.frontmatterPosition.end.line+1);let d=r.split(`
`);d.splice(s,0,t.data),a=d.join(`
`)}else i=e,a=t.data;return this.writeAndOpenFile(i,a,t)}async writeAndOpenFile(e,t,i){let a=this.app.vault.getAbstractFileByPath(e);if(a instanceof j.TFile)await this.app.vault.modify(a,t);else{let l=e.split("/"),r=l.slice(0,l.length-1).join("/");l.length>1&&!(this.app.vault.getAbstractFileByPath(r)instanceof j.TFolder)&&await this.app.vault.createFolder(r),/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/.test(t)?await this.app.vault.createBinary(e,(0,j.base64ToArrayBuffer)(t)):await this.app.vault.create(e,t)}return this.openExistingFileAndSetCursor(e,i),this.app.vault.getAbstractFileByPath(e)}async openExistingFileAndSetCursor(e,t){t.openmode!="silent"&&this.settings.openFileOnWrite&&(await this.open({file:e,setting:this.settings.openFileOnWriteInNewPane,parameters:t}),(t.line!=null||t.column!=null||t.offset!=null)&&await this.setCursorInLine(t))}async open({file:e,setting:t,parameters:i,supportPopover:a,mode:l}){var c;let r;if(i.openmode=="popover"&&(a==null||a)){let s=this.app.plugins.plugins["obsidian-hover-editor"];s||(new j.Notice("Cannot find Hover Editor plugin. Please file an issue."),this.failure(i)),await new Promise(d=>{r=s.spawnPopover(void 0,()=>{this.app.workspace.setActiveLeaf(r,{focus:!0}),d()})})}else{let s=t;if(i.newpane!==void 0&&(s=i.newpane=="true"),i.openmode!==void 0&&(i.openmode=="true"||i.openmode=="false"?s=i.openmode=="true":i.openmode=="popover"?s=!1:j.Platform.isMobile&&i.openmode=="window"||(s=i.openmode)),s=="silent")return;if(j.Platform.isMobileApp&&s=="window"&&(s=!0),e!=null){let d=!1;isBoolean(s)&&this.app.workspace.iterateAllLeaves(p=>{var h;if(((h=p.view.file)==null?void 0:h.path)===i.filepath){if(d&&p.width==0)return;d=!0,this.app.workspace.setActiveLeaf(p,{focus:!0}),r=p}})}r||(r=this.app.workspace.getLeaf(s),this.app.workspace.setActiveLeaf(r,{focus:!0}))}if(e instanceof j.TFile?await r.openFile(e):e!=null&&await this.app.workspace.openLinkText(e,"/",!1,l!=null?{state:{mode:l}}:Se(i)),r.view instanceof j.MarkdownView){let s=r.getViewState();l!=null?s.state.mode=l:s.state={...s.state,...(c=Se(i))==null?void 0:c.state},await r.setViewState(s)}return r}async setCursor(e){let t=this.app.workspace.getActiveViewOfType(j.MarkdownView);if(!t)return;let i=e.mode,a=t.editor,l=t.leaf.getViewState();if(l.state.mode="source",i==="append"){let r=a.lastLine(),c=a.getLine(r).length;await t.leaf.setViewState(l,{focus:!0}),a.setCursor({ch:c,line:r})}else i==="prepend"&&(await t.leaf.setViewState(l,{focus:!0}),a.setCursor({ch:0,line:0}));await new Promise(r=>setTimeout(r,10)),e.viewmode=="preview"&&(l.state.mode="preview",await t.leaf.setViewState(l))}async setCursorInLine(e){let t=this.app.workspace.getActiveViewOfType(j.MarkdownView);if(!t)return;let i=t.leaf.getViewState(),a=e.line!=null?Number(e.line):void 0,l=e.column?Number(e.column):void 0;i.state.mode="source",await t.leaf.setViewState(i);let r,c;if(e.offset!=null){let s=t.editor.offsetToPos(Number(e.offset));r=s.line,c=s.ch}else{r=a!=null?Math.min(a-1,t.editor.lineCount()-1):t.editor.getCursor().line;let s=t.editor.getLine(r).length-1;c=Math.min(l-1,s)}t.editor.focus(),t.editor.setCursor({line:r,ch:c}),t.editor.scrollIntoView({from:{line:r,ch:c},to:{line:r,ch:c}},!0),await new Promise(s=>setTimeout(s,10)),e.viewmode=="preview"&&(i.state.mode="preview",await t.leaf.setViewState(i))}async loadSettings(){this.settings=Object.assign(_e,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}};
//! All of these methods are taken from https://www.npmjs.com/package/obsidian-daily-notes-interface.
/*! Bundled license information:
feather-icons/dist/feather.js:
(*!
Copyright (c) 2016 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*)
*/