`:" ";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(we.MarkdownView);if(e){let t=e.editor,i=e.file,o=this.getBlock(n,t,i);if(o)return this.getIdOfBlock(t,o)}}};var je={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 be=require("obsidian");function Me(r){let n=r.internalPlugins.plugins["daily-notes"];return!!(n&&n.enabled)}function Qe(...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,be.normalizePath)(Qe(i,o))}var re=require("obsidian"),Xe=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},Ie=async r=>{var i;let n=Xe(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 re.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 re.Notice("Adv. URI: Waiting for sync to complete...",0)),await new Promise(o=>window.setTimeout(o,250))}e==null||e.hide()};var v=require("obsidian");var Fe=require("obsidian"),H=class extends Fe.SuggestModal{constructor(e,t,i){super(e.app);this.withFormat=t;this.file=i;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 o;e?i?o=`Write "${e}" in ${i} mode`:o=`Write "${e}"`:i?o=`Open in ${i} mode`:o="Open",t.push({data:e,display:o,mode:i,func:()=>{this.file?this.plugin.tools.copyURI({filepath:this.file,data:e,mode:i},this.withFormat,this.app.vault.getFileByPath(this.file)):this.plugin.tools.copyURI({daily:"true",data:e,mode:i},this.withFormat,void 0)}})}return t}renderSuggestion(e,t){t.innerText=e.display}onChooseSuggestion(e,t){e.func()}};var Ce=require("obsidian"),V=class extends Ce.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'tspecifyafile>",source:void 0});let t=this.app.workspace.getActiveFile();return t&&e.push({display:"<Currentfile>",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 ce=require("obsidian");function de(r){return r.viewmode?{state:{mode:r.viewmode,source:r.viewmode=="source"}}:void 0}function N(r){return navigator.clipboard.writeText(r)}function pe(r,n){var o;let e=(o=n.parent)==null?void 0:o.path,t=e==="/"?"":e,i=n.name;for(let a=1;a<100;a++){let l=$(i),s=t+(t==""?"":"/")+l+` ${a}.md`;if(!(r.vault.getAbstractFileByPath(s)!==null))return s}}function Pe(r,n){let e=new URL(r.vault.getResourcePath(n));return e.host="localhosthostlocal",e.protocol=
${d.message}`):new v.Notice("Failedtoupdatefrontmatter,checkconsoleformoredetails")}})}if(o&&!n.data){let s=Te({obj:o,key:e}),c=typeof s=="string"||typeof s=="number"||typeof s=="boolean"?String(s):JSON.stringify(s!=null?s:"");await N(c)}let a=await this.plugin.open({parameters:n,file:t,setting:this.plugin.settings.openFileWithoutWriteInNewPane});if(a&&n.mode&&a.view instanceof v.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 v.Notice("Workspacespluginisnotenabled"),this.plugin.failure(n);else{if(n.saveworkspace=="true"){let t=e.activeWorkspace;e.saveWorkspace(t),new v.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 v.TFile&&(n.filepath=pe(this.app,t))}await this.plugin.open({file:n.filepath,mode:"source",parameters:n});let e=this.app.workspace.getActiveViewOfType(v.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=L(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=U(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(`
`);return await this.app.vault.modify(n,s),e}async getUIDFromFile(n){var i;let e=(i=this.app.metadataCache.getFileCache(n))!=null?i:await new Promise(o=>{let a=this.app.metadataCache.on("changed",l=>{if(l.path==n.path){let s=this.app.metadataCache.getFileCache(n);this.app.metadataCache.offref(a),o(s)}})}),t=r.getFrontmatterString(e.frontmatter,this.plugin.settings.idField);if(t!=null)return t}async generateURI(n){var a;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 C.TFile&&i.extension=="md"&&(this.settings.addFilepathWhenUsingUID||(n.filepath=void 0),n.uid=(a=await this.getUIDFromFile(i))!=null?a:await this.writeUIDToFile(i,ue()));let o=Object.keys(n).filter(l=>n[l]).sort((l,s)=>{let c=["filepath","filename","uid","daily"],d=["data","eval"];return c.includes(l)?-1:c.includes(s)||d.includes(l)?1:d.includes(s)?-1:0});for(let l of o)n[l]!=null&&(t+=t?"&":"?",t+=`${l}=${encodeURIComponent(n[l])}`);return t.endsWith("%20")&&(t+="&"),e+t}async copyURI(n,e=!1,t=void 0){var o,a,l;let i=await this.generateURI(n);if(e){let s=this.settings.linkFormats;if(s.length==0){new C.Notice("No link formats defined in the settings");return}let c;if(s.length==1)c=s[0];else{let p=s.map(h=>h.name),u=await new te(this.plugin,{options:p,onlySelection:!0,placeholder:"Select link format"}).openAndGetResult();if(!u){new C.Notice("No link format selected");return}c=s.find(h=>h.name==u)}let d=c.format.replace(/\{\{uri\}\}/g,i).replace(/\{\{path\}\}/g,t==null?void 0:t.path).replace(/\{\{folder\}\}/g,(o=t==null?void 0:t.parent)==null?void 0:o.path).replace(/\{\{name\}\}/g,t==null?void 0:t.basename).replace(/\{\{vaultName\}\}/g,this.app.vault.getName()).replace(/\{\{vaultId\}\}/g,this.app.appId);if(t&&d.match(/\{\{uid\}\}/g)){let p=(a=await this.getUIDFromFile(t))!=null?a:t.basename;d=d.replace(/\{\{uid\}\}/g,p)}if(t&&d.match(/\{\{alias\}\}/g)){let p=(0,C.parseFrontMatterAliases)((l=this.app.metadataCache.getFileCache(t))==null?void 0:l.frontmatter),u=p?p[0]:t==null?void 0:t.basename;d=d.replace(/\{\{alias\}\}/g,u)}await N(d),new C.Notice(`Advanced URI in format "${c.name}" copied to your clipboard`);return}await N(i),new C.Notice("Advanced URI copied to your clipboard")}getFileFromUID(n){var i,o;let e=this.app.vault.getMarkdownFiles(),t=this.settings.idField;for(let a of e){let l=r.getFrontmatterStringArray((i=this.app.metadataCache.getFileCache(a))==null?void 0:i.frontmatter,t);if(l!=null&&l.includes(n)||r.getFrontmatterString((o=this.app.metadataCache.getFileCache(a))==null?void 0:o.frontmatter,t)==n)return a}}getFileFromBlockID(n){var t,i;let e=this.app.vault.getMarkdownFiles();n=n.toLowerCase();for(let o of e)if(((i=(t=this.app.metadataCache.getFileCache(o))==null?void 0:t.blocks)==null?void 0:i[n])!=null)return o}};var ie=require("obsidian"),ne=class extends ie.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 ie.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 oe=class extends w.Plugin{constructor(){super(...arguments);this.handlers=new G(this);this.tools=new Y(this)}getActiveView(){var e;return(e=this.app.workspace.activeLeaf)==null?void 0:e.view}decodeParameterValues(e){for(let t in e){let i=e[t];typeof i=="string"&&(e[t]=decodeURIComponent(i))}return e}async onload(){await this.loadSettings(),this.addSettingTab(new ee(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-fi