`:" ";return n.replaceRange(`${l}^${a}`,o),a}static shouldInsertAfter(n){let e=r.getBlockType(n);return e?["blockquote","code","table","heading","comment","footnoteDefinition"].includes(e):!1}static getBlockId(n){let e=n.workspace.getActiveViewOfType(je.MarkdownView);if(e){let t=e.editor,i=e.file,o=this.getBlock(n,t,i);if(o)return this.getIdOfBlock(t,o)}}};var be={openFileOnWrite:!0,openDailyInNewPane:!1,openFileOnWriteInNewPane:!1,openFileWithoutWriteInNewPane:!1,idField:"id",useUID:!1,addFilepathWhenUsingUID:!1,includeVaultName:!0,vaultParam:"name",linkFormats:[{name:"Markdown",format:"[{{name}}]({{uri}})"}]};var Me=require("obsidian");function Ie(r){let n=r.internalPlugins.plugins["daily-notes"];return!!(n&&n.enabled)}function Ze(...r){let n=[];for(let t=0,i=r.length;t<i;t++)r[t]&&(n=n.concat(r[t].split("/")));let e=[];for(let t=0,i=n.length;t<i;t++){let o=n[t];!o||o==="."||e.push(o)}return n[0]===""&&e.unshift(""),e.join("/")}async function Ae(r,n){let e=n.internalPlugins.getEnabledPluginById("daily-notes");if(!e)throw new Error("Daily notes plugin is not enabled");let{format:t,folder:i}=e.options,o=r.format(t);return o.endsWith(".md")||(o+=".md"),(0,Me.normalizePath)(Ze(i,o))}var se=require("obsidian"),Je=r=>{var e,t;let n=(t=(e=r.internalPlugins)==null?void 0:e.plugins)==null?void 0:t.sync;return n==null?void 0:n.instance},Ce=async r=>{var i;let n=Je(r);if(!n){console.warn("sync instance not found, not waiting");return}if(((i=n==null?void 0:n.plugin)==null?void 0:i.enabled)!==!0){console.warn("sync plugin is disabled, not waiting");return}if(!("syncing"in n)||!("ready"in n)){console.warn("sync instance does not have expected properties, not waiting");return}let e=null,t=0;for(;n.ready===!1;){if(t++,t>40){console.warn("sync instance not ready after 10 seconds, not waiting"),e==null||e.hide();return}t>6&&!e&&(e=new se.Notice("Adv. URI: Waiting for sync to complete...",0)),await new Promise(o=>window.setTimeout(o,250))}for(;n.syncing===!0&&n.syncStatus!=="Indexing...";){if(t++,t>240){console.warn("sync instance still syncing after 60 seconds, not waiting"),e==null||e.hide();return}t>6&&!e&&(e=new se.Notice("Adv. URI: Waiting for sync to complete...",0)),await new Promise(o=>window.setTimeout(o,250))}e==null||e.hide()};var x=require("obsidian");var S=require("obsidian"),B=class extends S.Modal{constructor(e,t,i){super(e.app);this.plugin=e;this.withFormat=t;this.file=i;this.modes=[{value:void 0,label:"Default",description:"Write normally, or only open the file when data is empty."},{value:"overwrite",label:"Overwrite",description:"Replace the existing file contents with the data."},{value:"append",label:"Append",description:"Add the data after the existing file contents."},{value:"prepend",label:"Prepend",description:"Add the data before the existing file contents."}];this.data=""}onOpen(){var i;this.setTitle("Configure URI");let e=this.contentEl.createDiv({cls:"advanced-uri-data-section"});new S.Setting(e).setName("Data").setDesc("Enter the text to write. Leave this empty to only open the file.").setHeading();let t=new S.TextAreaComponent(e);t.setPlaceholder("Text to write").onChange(o=>{this.data=o,this.updateCopyButton()}),t.inputEl.rows=4,t.inputEl.addClass("advanced-uri-data-input"),t.inputEl.focus(),new S.Setting(this.contentEl).setName("Mode").setDesc("Select how to write the data to the file.").setHeading();for(let o=0;o<this.modes.length;o++){let a=this.modes[o],l=new S.Setting(this.contentEl).setName(a.label).setDesc(a.description),s=l.controlEl.createEl("input",{type:"radio",attr:{name:"advanced-uri-write-mode",value:(i=a.value)!=null?i:"default","aria-label":a.label}});s.checked=o===0,s.addEventListener("change",()=>{s.checked&&(this.mode=a.value,this.updateCopyButton())}),l.settingEl.addEventListener("click",c=>{c.target!==s&&(s.focus(),s.click())}),l.settingEl.addClass("advanced-uri-mode-option")}new S.Setting(this.contentEl).addButton(o=>o.setButtonText("Cancel").onClick(()=>this.close())).addButton(o=>{this.copyButton=o.setButtonText(this.withFormat?"Copy formatted URI":"Copy URI").setCta().onClick(()=>
${d.message}`):new x.Notice("Failed to update frontmatter, check console for more details")}})}if(o&&!n.data){let s=Oe({obj:o,key:e}),c=typeof s=="string"||typeof s=="number"||typeof s=="boolean"?String(s):JSON.stringify(s!=null?s:"");await W(c)}let a=await this.plugin.open({parameters:n,file:t,setting:this.plugin.settings.openFileWithoutWriteInNewPane});if(a&&n.mode&&a.view instanceof x.MarkdownView){let s=a.view.metadataEditor;if(!s)return;let c;switch(n.mode){case"append":c="end";break;case"prepend":c="start";break;case"overwrite":c="both";break}s.focusValue(e,c)}}async handleWorkspace(n){let e=this.app.internalPlugins.getEnabledPluginById("workspaces");if(!e)new x.Notice("Workspaces plugin is not enabled"),this.plugin.failure(n);else{if(n.saveworkspace=="true"){let t=e.activeWorkspace;e.saveWorkspace(t),new x.Notice(`Saved current workspace to ${t}`)}n.clipboard&&n.clipboard!="false"?await this.tools.copyURI({workspace:e.activeWorkspace}):n.workspace!=null&&e.loadWorkspace(n.workspace),this.plugin.success(n)}}async handleCommand(n){if(n.filepath)if(n.mode){if(n.mode=="new"){let t=this.app.metadataCache.getFirstLinkpathDest(n.filepath,"/");t instanceof x.TFile&&(n.filepath=he(this.app,t))}await this.plugin.open({file:n.filepath,mode:"source",parameters:n});let e=this.app.workspace.getActiveViewOfType(x.MarkdownView);if(e){let t=e.editor;n.mode==="append"?this.insertCommandLine(e,n,"append"):n.mode==="prepend"?this.insertCommandLine(e,n,"prepend"):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(i=>window.setTimeout(i,750));let t=document.querySelector(".mod-cta:not([style*='display:none'])");t.click instanceof Function&&t.click()}this.plugin.success(n),await new Promise(e=>window.setTimeout(e,4e3))}insertCommandLine(n,e,t){let i=n.editor,o=i.lineCount(),a=i.lastLine(),l,s=!1;if(e.heading){let c=D(this.app,n.file,e.heading);if(!c)return;let d=t==="append"?c.lastLine:c.firstLine;d>=o?l={line:a,ch:i.getLine(a).length}:(l={line:d,ch:0},s=!0)}else if(e.block){let c=z(this.app,n.file,e.block);if(!c)return;l=t==="append"?{line:c.lastLine,ch:i.getLine(c.lastLine).length}:{line:c.firstLine,ch:0},s=t==="prepend"}else t==="append"?l={line:a,ch:i.getLine(a).length}:(l={line:0,ch:0},s=!0);i.replaceRange(`
`,l),i.setCursor(s?l:{line:l.line+1,ch:0}),i.scrollIntoView({from:i.getCursor(),to:i.getCursor()},!0)}async handleDoesFileExist(n){let e=await this.app.vault.adapter.exists(n.filepath);await W((e?1:0).toString()),this.plugin.success(n)}async handleReveal(n){let e=this.app.vault.getAbstractFileByPath(n.filepath);if(!e){new x.Notice("Cannot find file or folder"),this.plugin.failure(n);return}let t=this.app.workspace.getLeavesOfType("file-explorer")[0],i=t==null?void 0:t.view;if(!i||typeof i.revealInFolder!="function"){new x.Notice("File Explorer is not available"),this.plugin.failure(n);return}i.revealInFolder(e),this.plugin.success(n)}handleRemovedEval(n){new x.Notice("The eval URI parameter was removed due to security concerns and newer Obsidian plugin checks."),this.plugin.failure(n)}async handleSearchAndReplace(n){let e;if(n.filepath){let t=this.app.vault.getAbstractFileByPath(n.filepath);t instanceof x.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,o]=n.searchregex.match(/(\/?)(.+)\1([a-z]*)/i),a=new RegExp(i,o);t=t.replace(a,n.replace),this.plugin.success(n)}catch(i){new x.Notice(`Can'tparse${n.searchregex}asRegEx`),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 x.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(x.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 o,a=(i=n.filepath)!=null?i:t.path;n.mode==="overwrite"?(o=await this.plugin.writeAndOpenFile(a,n.data,n),this.plugin.success(n)):n.mode==="prepend"?(t instanceof x.TFile?o=await this.plugin.prepend(t,n):o=await this.plugin.prepend(a,n),this.plugin.success(n)):n.mode==="append"?(t instanceof x.TFile?o=await this.plugin.append(t,n):o=await this.plugin.append(a,n),this.plugin.success(n)):n.mode==="new"?t instanceof x.TFile?(o=await this.plugin.writeAndOpenFile(he(this.app,t),n.data,n),await this.plugin.hookSuccess(n,o)):(o=await this.plugin.writeAndOpenFile(a,n.data,n),await this.plugin.hookSuccess(n,o)):!e&&t instanceof x.TFile?(new x.Notice("File already exists"),await this.plugin.openExistingFileAndSetCursor(t.path,n),this.plugin.failure(n)):(o=await this.plugin.writeAndOpenFile(a,n.data,n),this.plugin.success(n)),n.uid&&await this.tools.writeUIDToFile(o,n.uid)}else new x.Notice("Cannot find file"),this.plugin.failure(n)}async handleOpen(n){if(n.heading!=null){let e="";n.mode||(e="#"+n.heading),await this.plugin.open({file:n.filepath+e,setting:this.plugin.settings.openFileWithoutWriteInNewPane,parameters:n})}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(x.MarkdownView);if(!e)return;let i=this.app.metadataCache.getFileCache(e.file).blocks[n.block.toLowerCase()];e.editor.focus(),i&&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||n.heading)&&await this.plugin.setCursor(n),n.uid){let e=this.app.workspace.getActiveViewOfType(x.MarkdownView);await 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)}async handleCopyFileURI(n,e,t){let i=this.app.workspace.getActiveViewOfType(x.FileView);if(!(!i&&!t)){if(t=t!=null?t:i.file,i instanceof x.MarkdownView){let o=i.editor.getCursor(),a=this.app.metadataCach
`);returnawaitthis.app.vault.modify(n,s),e}asyncgetUIDFromFile(n){vari;lete=(i=this.app.metadataCache.getFileCache(n))!=null?i:awaitnewPromise(o=>{leta=this.app.metadataCache.on("changed",l=>{if(l.path==n.path){lets=this.app.metadataCache.getFileCache(n);this.app.metadataCache.offref(a),o(s)}})}),[t]=r.getFrontmatterUIDs(e.frontmatter,this.plugin.settings.idField);if(t!=null)returnString(t)}asyncgenerateURI(n){vara;lete="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&&iinstanceofk.TFile&&i.extension=="md"&&(this.settings.addFilepathWhenUsingUID||(n.filepath=void0),n.uid=(a=awaitthis.getUIDFromFile(i))!=null?a:awaitthis.writeUIDToFile(i,fe()));leto=Object.keys(n).filter(l=>n[l]!=null).sort((l,s)=>{letc=["filepath","filename","uid","daily"],d=["data","eval"];returnc.includes(l)?-1:c.includes(s)||d.includes(l)?1:d.includes(s)?-1:0});for(letlofo)n[l]!=null&&(t+=t?"&":"?",t+=`${l}=${encodeURIComponent(n[l])}`);returnt.endsWith("%20")&&(t+="&"),e+t}asynccopyURI(n,e=!1,t=void0){varo,a,l;leti=awaitthis.generateURI(n);if(e){lets=this.settings.linkFormats;if(s.length==0){newk.Notice("No link formats defined in the settings");return}letc;if(s.length==1)c=s[0];else{letp=s.map(h=>h.name),u=awaitnewne(this.plugin,{options:p,onlySelection:!0,placeholder:"Select link format"}).openAndGetResult();if(!u){newk.Notice("No link format selected");return}c=s.find(h=>h.name==u)}letd=c.format.replace(/\{\{uri\}\}/g,i).replace(/\{\{path\}\}/g,t==null?void0:t.path).replace(/\{\{folder\}\}/g,(o=t==null?void0:t.parent)==null?void0:o.path).replace(/\{\{name\}\}/g,t==null?void0:t.basename).replace(/\{\{vaultName\}\}/g,this.app.vault.getName()).replace(/\{\{vaultId\}\}/g,this.app.appId);if(t&&d.match(/\{\{uid\}\}/g)){letp=(a=awaitthis.getUIDFromFile(t))!=null?a:t.basename;d=d.replace(/\{\{uid\}\}/g,p)}if(t&&d.match(/\{\{alias\}\}/g)){letp=(0,k.parseFrontMatterAliases)((l=this.app.metadataCache.getFileCache(t))==null?void0:l.frontmatter),u=p?p[0]:t==null?void0:t.basename;d=d.replace(/\{\{alias\}\}/g,u)}awaitW(d),newk.Notice(`Advanced URI in format "${c.name}" copied to your clipboard`);return}awaitW(i),newk.Notice("Advanced URI copied to your clipboard")}getFileFromUID(n){vari;lete=this.app.vault.getMarkdownFiles(),t=this.settings.idField;for(letoofe)if(r.getFrontmatterUIDs((i=this.app.metadataCache.getFileCache(o))==null?void0:i.frontmatter,t).some(l=>l===n||typeofl=="number"&&Number(n)===l))returno}getFileFromBlockID(n){vart,i;lete=this.app.vault.getMarkdownFiles();n=n.toLowerCase();for(letoofe)if(((i=(t=this.app.metadataCache.getFileCache(o))==null?void0:t.blocks)==null?void0:i[n])!=null)returno}};varoe=require("obsidian"),ie=classextendsoe.FuzzySuggestModal{constructor(e){super(e.app);this.plugin=e,this.setPlaceholder("Choose a workspace")}getItems(){lete=this.app.internalPlugins.getEnabledPluginById("workspaces");if(!e)newoe.Notice("Workspaces plugin is not enabled");elsereturnObject.keys(e.workspaces)}getItemText(e){returne}onChooseItem(e,t){this.plugin.tools.copyURI({workspace:e})}};varae=classextendsw.Plugin{constructor(){super(...arguments);this.handlers=newZ(this);this.tools=newJ(this)}getActiveView(){vare;return(e=this.app.workspace.activeLeaf)==null?void0:e.view}decodeParameterValues(e){for(lettine){leti=e[t];typeofi=="string"&&(e[t]=decodeURIComponent(i))}returne}asynconload(){awaitthis.loadSettings(),this.addSettingTab(newte(this.app,this)),this.addCommand({id:"copy-uri-current-file",name:"Copy URI for file with options",callback:()=>this.handlers.handleCopyFileURI(!1,!1)}),this.addCommand({id:"copy-uri-current-file-simple",name:"Copy URI for current file",callback:()=>this.handlers.handleCopyFileURI(!0,!1)}),this.addCommand({id:"copy-uri-current-file-with-format",name:"Copy formatted URI for file with options ",callback:()