"use strict";var u=class extends Error{constructor(t,r=`Unsupported type: ${t}`){super(r)}};var T=e=>({ch:e.col,line:e.line});function b(){return app.workspace}function w(){return app.metadataCache}function E(e){return app.vault.adapter.exists(e)}var c=()=>app.workspace.getActiveFile();function _e(){return app.metadataCache.getFileCache(c())}function S(){return app.vault.getMarkdownFiles()}function U(){return app.vault.fileMap}function g(e){let t=app.vault.getAbstractFileByPath(e);return t||null}function B(e){let t=g(e);return t?app.metadataCache.getFileCache(t):null}var D=e=>B(e)?.frontmatter??null,p=()=>_e()?.frontmatter??null,$=e=>B(e)?.sections?.filter(t=>t.type==="code")??[],i=()=>app.workspace.activeEditor?.editor,l=()=>app.workspace.activeEditor.metadataEditor;function f(){let e=i();return e.getLine(e.getCursor().line)}function I(){return app.metadataCache.getBacklinksForFile(c()).data}function d(){return i().getSelection()}async function h(e,t){let r=g(e);if(!r)return null;let n=await app.vault.cachedRead(r);return t?n.slice(t.start.offset,t.end.offset):n}function R(e){let t=i();return e?t.getRange(T(e.start),T(e.end)):t.getValue()}function x(e){i().replaceSelection(e)}function W(){let e=i(),t=e.getCursor();t.line===e.lastLine()?e.setLine(t.line,""):e.replaceRange("",{line:t.line,ch:0},{line:t.line+1,ch:0})}function _(e,t){let r=i(),{line:n,ch:o}=r.getCursor();r.setLine(n,e);let s=t?.cursor==="last"?e.length:Math.min(o,e.length-1);r.setCursor({line:n,ch:s})}function N(e){let t=i();t.replaceRange(` ${e}`,{line:t.lastLine()+1,ch:0})}function j(e,t){new Notice(e,t??null)}function a(e){return moment(e)}function F(){return app.plugins.plugins["templater-obsidian"].templater.current_functions_object}function O(){return app.plugins.plugins["periodic-notes"]}async function V(){return app.internalPlugins.plugins.publish.instance.apiCustomUrl().then(e=>e.url)}function Y(e,t=""){return app.vault.create(e,t)}function H(e,t){let r=t?.newLeaf??!1;return app.workspace.openLinkText("",e,r)}function q(){let t=!(app.vault.getConfig("readableLineLength")??!1);return app.vault.setConfig("readableLineLength",t),t}function v(e,t="asc"){return(r,n)=>t==="asc"?e(r)>e(n)?1:e(n)>e(r)?-1:0:e(r)[ \t\s]*([-*] (\[.] |)|))(?.*)$/g)).at(0);return{prefix:t?.groups?.prefix??"",content:t?.groups?.content??""}}function J(e){return e.split(" ").filter(t=>t.startsWith("#")).map(t=>t.slice(1))}function K(e){return e.replaceAll(/\*\*([^*]*?)\*\*/g,"$1").replaceAll(/__([^*]*?)__/g,"$1").replaceAll(/\*([^*]*?)\*/g,"$1").replaceAll(/_([^*]*?)_/g,"$1").replaceAll(/~~([^~]*?)~~/g,"$1").replaceAll(/==([^~]*?)==/g,"$1")}function Q(e){return e.replaceAll(/\[\[[^\|\]]*?\|([^\]]*?)\]\]/g,"$1").replaceAll(/\[\[([^\]]*?)\]\]/g,"$1").replaceAll(/\[([^\]]*?)\]\(.*?\)/g,"$1").replaceAll(/\[([^\]]*?)\]/g,"$1")}function X(e,t){let r=[],n=moment(e).startOf("day"),o=moment(t).startOf("day");if(n.isAfter(o))throw new Error("beginDate is after endDate");for(;r.push(n.clone()),!(n.add(1,"days").diff(o)>0););return r}function Z(e){return e!=null}function ee(){return{workspace:b(),metadataCache:w(),editor:i(),properties:p(),metadataEditor:l()}}function y(e,t){l().insertProperties({[e]:t})}function te(e){l().insertProperties(e)}function re(){return p()}function ne(e){return D(e)}function oe(e,t){A(e),y(e,t)}function A(e){l().insertProperties({[e]:null})}function ie(){return p()?.tags??[]}function ae(){return p()?.aliases??[]}function se(e){l().focusValue(e)}function ce(e){let t=i();t.replaceRange(e,t.getCursor())}function le(e){N(e)}function P(){return f()}function pe(){return W()}function ue(){return J(P())}function M(){return d().split(` `)}function C(e){i()?.replaceSelection(e)}async function ge(){return k(c().path)}async function k(e){let t=$(e),r=[];for(let n of t){let o=await h(e,n.position),s=o.match(/[`~]{3,}(?[^ \n]*)/)?.groups?.language||null;r.push({language:s,content:o.split(` `).slice(1).slice(0,-1).join(` `),position:n.position})}return r}function de(e,t){let r=f(),{prefix:n,content:o}=G(r),s=t?.attached??"prefix",m;switch(s){case"prefix":m=`${n}${e}${o}`;break;case"suffix":m=`${n}${o}${e}`;break;default:throw new u(s)}_(m,{cursor:t?.cursor})}function me(e){let t=e?.order??"asc",r=e?.predicate??(s=>s),n=M();if(!n)return;let o=z(n,r,t);C(o.join(` `))}function fe(){let e=K(d());x(e)}function he(){let e=Q(d());x(e)}function xe(e,t=5e3){j(e,t==="never"?void 0:t)}function Fe(){return Object.keys(I()??{})}function ve(e){let t=c().stat.ctime;switch(e){case"unixtime":return t;case"moment":return a(t);default:return a(t).format(e)}}function ye(e){let t=c().stat.mtime;switch(e){case"unixtime":return t;case"moment":return a(t);default:return a(t).format(e)}}function Ae(e){let t=a();switch(e){case"unixtime":return t.unix();case"moment":return t;default:return t.format(e)}}function Pe(e){return a(e)}function Me(e){return F().system.prompt(e)}function Ce(e,t){return F().system.suggester(e,t)}function ke(e,t){let r=O()?.settings.daily;if(!r)throw new Error("Periodic Notes plugin is not installed.");return X(a(e),a(t)).map(n=>g(`${r.folder}/${n.format(r.format||"YYYY-MM-DD")}.md`)).filter(Z)}async function Le(e,t){let r=await h(e,t);if(r==null)throw new Error(`${e} is not existed.`);return r}function Te(e){let t=R(e);if(t==null)throw new Error("Couldn't get content from the active file.");return t}function be(){return c().path}function we(e){return E(e)}async function Ee(e,t){return Y(e,t)}function L(){return U()}function Se(){return Object.values(L())}function Ue(){return S()}async function Be(e,t){return H(e,t)}async function De(e){await navigator.clipboard.writeText(e)}async function $e(e){return`https://${await V()}/${encodeURI(e.replace(".md",""))}`}function Ie(e){return new Error(e)}function Re(e,t="asc"){return v(e,t)}function We(){return q()}module.exports=()=>({addProperties:te,addProperty:y,appendLine:le,attachTextToListItem:de,copyToClipboard:De,createFile:Ee,createMomentDate:Pe,createObsidianPublishUrl:$e,deleteActiveLine:pe,exit:Ie,fileExists:we,focusPropertyValue:se,getActiveFileContent:Te,getActiveFilePath:be,getActiveLine:P,getActiveLineTags:ue,getAllFiles:Se,getAllFilesByPath:L,getAllMarkdownFiles:Ue,getBacklinkPaths:Fe,getCodeBlocks:ge,getCodeBlocksFrom:k,getCreationDate:ve,getDailyNotes:ke,getFileContent:Le,getProperties:re,getPropertiesFrom:ne,getSelectionLines:M,getUpdateDate:ye,insert:ce,notify:xe,now:Ae,openFile:Be,readAliasesFromProperty:ae,readTagsFromProperty:ie,removeProperty:A,setTextToSelection:C,showInputDialog:Me,showSelectionDialog:Ce,sorter:Re,sortSelectionLines:me,stripDecorationFromSelection:fe,stripLinksFromSelection:he,toggleReadableLength:We,updateProperty:oe,use:ee});