Files
my-vault/.obsidian/plugins/obsidian-advanced-uri/main.js
T

31 lines
129 KiB
JavaScript
Raw Normal View History

2026-01-05 13:03:55 +08:00
/*
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)
*/
var He=Object.create;var Q=Object.defineProperty;var Ne=Object.getOwnPropertyDescriptor;var Be=Object.getOwnPropertyNames;var We=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty;var Ke=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),Ge=(r,n)=>{for(var e in n)Q(r,e,{get:n[e],enumerable:!0})},xe=(r,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of Be(n))!$e.call(r,i)&&i!==e&&Q(r,i,{get:()=>n[i],enumerable:!(t=Ne(n,i))||t.enumerable});return r};var Ye=(r,n,e)=>(e=r!=null?He(We(r)):{},xe(n||!r||!r.__esModule?Q(e,"default",{value:r,enumerable:!0}):e,r)),Ze=r=>xe(Q({},"__esModule",{value:!0}),r);var ve=Ke((W,le)=>{(function(n,e){typeof W=="object"&&typeof le=="object"?le.exports=e():typeof define=="function"&&define.amd?define([],e):typeof W=="object"?W.feather=e():n.feather=e()})(typeof self!="undefined"?self:W,function(){return function(r){var n={};function e(t){if(n[t])return n[t].exports;var i=n[t]={i:t,l:!1,exports:{}};return r[t].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=r,e.c=n,e.d=function(t,i,o){e.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:o})},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(r){r.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="19"><
2026-01-05 13:03:55 +08:00
`:" ";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'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 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("Failed to update frontmatter, check console for more details")}})}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("Workspaces plugin is not enabled"),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(`
`,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 N((e?1:0).toString()),this.plugin.success(n)}handleRemovedEval(n){new v.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 v.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 v.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 v.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(v.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 v.TFile?o=await this.plugin.prepend(t,n):o=await this.plugin.prepend(a,n),this.plugin.success(n)):n.mode==="append"?(t instanceof v.TFile?o=await this.plugin.append(t,n):o=await this.plugin.append(a,n),this.plugin.success(n)):n.mode==="new"?t instanceof v.TFile?(o=await this.plugin.writeAndOpenFile(pe(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 v.TFile?(new v.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 v.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(v.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(v.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(v.FileView);if(!(!i&&!t)){if(t=t!=null?t:i.file,i instanceof v.MarkdownView){let o=i.editor.getCursor(),a=this.app.metadataCache.getFileCache(i.file);if(a.headings){for(let l of a.headings)if(l.position.start.line<=o.line&&l.position.end.line>=o.line){await this.tools.copyURI({filepath:i.file.path,heading:l.heading},e,t);return}}if(a.blocks)for(let l of Object.keys(a.blocks)){let s=a.blocks[l];if(s.position.start.line<=o.line&&s.position.end.line>=o.line){await this.tools.copyURI({filepath:i.file.path,block:s.id},e,t);return}}}
`),l=`${this.plugin.settings.idField}:`;if(o)a.unshift("---"),a.unshift(`${l} ${e}`),a.unshift("---");else{let d=a.findIndex(p=>p.startsWith(l));d!=-1?a[d]=`${l} ${e}`:a.splice(1,0,`${l} ${e}`)}let s=a.join(`
`);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
`),d;if(t.heading){let p=L(this.app,e,t.heading);if(d=p==null?void 0:p.lastLine,d===void 0)return;p.firstLine==p.lastLine&&t.separator&&(t.separator=`
`+t.separator)}else if(t.block){let p=U(this.app,e,t.block);if(p===void 0)return;d=p.lastLine+1}else t.line?d=Number(t.line):d=c.length;d=Math.max(1,d),c[d-1]=((a=c[d-1])!=null?a:"")+((l=t.separator)!=null?l:`
2026-01-05 13:03:55 +08:00
`)+t.data,o=c.join(`
`)}else i=e,o=t.data;return this.writeAndOpenFile(i,o,t)}async prepend(e,t){var a,l,s;let i,o;if(e instanceof w.TFile){i=e.path;let c=await this.app.vault.read(e),d=this.app.metadataCache.getFileCache(e),p=c.split(`
`),u;if(t.heading){if(u=(a=L(this.app,e,t.heading))==null?void 0:a.firstLine,u===void 0)return;u+=1}else if(t.block){let h=U(this.app,e,t.block);if(h===void 0)return;u=h.firstLine+1}else t.line?u=Number(t.line):d.frontmatterPosition?u=d.frontmatterPosition.end.line+2:u=1;u=Math.max(1,u),p[u-1]=`${t.data}${(l=t.separator)!=null?l:`
`}${(s=p[u-1])!=null?s:""}`,o=p.join(`
`)}else i=e,o=t.data;return this.writeAndOpenFile(i,o,t)}async writeAndOpenFile(e,t,i){let o=this.app.vault.getAbstractFileByPath(e);if(o instanceof w.TFile)await this.app.vault.modify(o,t);else{let a=e.split("/"),l=a.slice(0,a.length-1).join("/");a.length>1&&!(this.app.vault.getAbstractFileByPath(l)instanceof w.TFolder)&&await this.app.vault.createFolder(l),/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/.test(t)?await this.app.vault.createBinary(e,(0,w.base64ToArrayBuffer)(t)):await this.app.vault.create(e,t)}return await this.openExistingFileAndSetCursor(e,i),this.app.vault.getFileByPath(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):t.mode!=null&&await this.setCursor(t))}async open({file:e,setting:t,parameters:i,supportPopover:o,mode:a}){var s;let l;if(i.openmode=="popover"&&(o==null||o)){let c=this.app.plugins.plugins["obsidian-hover-editor"];c||(new w.Notice("Cannot find hover editor plugin. Please file an issue."),this.failure(i)),await new Promise(d=>{l=c.spawnPopover(void 0,()=>{this.app.workspace.setActiveLeaf(l,{focus:!0}),d()})})}else{let c=t,d=isBoolean(c);if(i.newpane!==void 0&&(c=i.newpane=="true",d=!0),i.openmode!==void 0&&(i.openmode=="true"||i.openmode=="false"?(c=i.openmode=="true",d=!0):i.openmode=="popover"?(c=!1,d=!1):i.openmode=="split-or-focus"?(c="split",d=!0):w.Platform.isMobile&&(i.openmode=="window"||i.openmode=="window-or-focus")?(c=!1,d=i.openmode=="window-or-focus"):i.openmode=="window-or-focus"?(c="window",d=!0):(c=i.openmode,d=!1)),c=="silent")return;if(w.Platform.isMobileApp&&c=="window"&&(c=!0),e!=null){let p=!1;if(d){let u=e instanceof w.TFile?e.path:i.filepath;this.app.workspace.iterateAllLeaves(h=>{if(h.getViewState().state.file===u){if(p&&h.width==0)return;p=!0,this.app.workspace.setActiveLeaf(h,{focus:!0}),l=h}})}}l||(l=this.app.workspace.getLeaf(c),this.app.workspace.setActiveLeaf(l,{focus:!0}))}if(e instanceof w.TFile?await l.openFile(e):e!=null&&await this.app.workspace.openLinkText(e,"/",!1,a!=null?{state:{mode:a}}:de(i)),l.view instanceof w.MarkdownView){let c=l.getViewState();a!=null?c.state.mode=a:c.state={...c.state,...(s=de(i))==null?void 0:s.state},await l.setViewState(c)}return l}async setCursor(e){let t=this.app.workspace.getActiveViewOfType(w.MarkdownView);if(!t)return;let i=e.mode,o=t.editor,a=t.leaf.getViewState();if(a.state.mode="source",i==="append"){let l;if(e.heading){let d=L(this.app,t.file,e.heading);l=d==null?void 0:d.lastLine}else if(e.block){let d=U(this.app,t.file,e.block);l=d==null?void 0:d.lastLine}else l=o.lastLine();if(l===void 0)return;let s=e.heading&&l<o.lineCount()?Math.max(0,l-1):Math.min(l,o.lastLine()),c={line:s,ch:o.getLine(s).length};await t.leaf.setViewState(a,{focus:!0}),o.setCursor(c),t.editor.scrollIntoView({from:c,to:c},!0)}else if(i==="prepend"||!i&&e.heading){await t.leaf.setViewState(a,{focus:!0});let l;if(e.heading){let s=L(this.app,t.file,e.heading);l=s==null?void 0:s.firstLine}else if(e.block){let s=U(this.app,t.file,e.block);l=s==null?void 0:s.firstLine}else l=0;if(l===void 0)return;o.setCursor({line:l,ch:0}),t.editor.scrollIntoView({from:{line:l,ch:0},to:{line:l,ch:0}},!0)}await new Promise(l=>window.setTimeout(l,10)),e.viewmode=="preview"&&(a.state.mode="preview",await t.leaf.setViewState(a))}async setCursorInLine(e){let t=this.app.workspace.getActiveViewOfType(w.MarkdownView);if(!t)return;let i=t.leaf.getViewState(),o=e.line!=null?Number(e.line):void 0,a=e.column?Number(e.column):void 0;i.state.mode="source",await t.leaf.setViewState(i);let l,s;if(e.offset!=null){let c=t.editor.offsetToPos(Number(e.offset));l=c.line,s=c.ch}else{l=o!=null?Math.min(o-1,t.editor.lineCount()-1):t.editor.getCursor().line;let c=t.editor.getLine(l).length-1;s=Math.min(a-1,c)}t.editor.focus(),t.editor.setCursor({line:l,ch:s}),t.editor.scrollIntoView({from:{line:l,ch:s},to:{line:l,ch:s}},!0),await new Promise(c=>window.setTimeout
2026-01-05 13:03:55 +08:00
//! 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
*)
*/
/* nosourcemap */