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.

10 lines
40 KiB

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var ae=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var xe=Object.prototype.hasOwnProperty;var Fe=(y,t)=>{for(var e in t)ae(y,e,{get:t[e],enumerable:!0})},Se=(y,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ce(t))!xe.call(y,i)&&i!==e&&ae(y,i,{get:()=>t[i],enumerable:!(n=Te(t,i))||n.enumerable});return y};var Ie=y=>Se(ae({},"__esModule",{value:!0}),y);var Le={};Fe(Le,{default:()=>re});module.exports=Ie(Le);var oe=require("obsidian");var k=require("obsidian");var J=class{constructor(){this.values=new Map}put(t,e){this.values.set(t,e)}get(t,e){var n;return(n=this.values.get(t))!=null?n:e}getFirst(t,e){for(let n=0;n<t.length;n++){let i=t[n];if(this.containsKey(i))return this.get(i,e)}return e}containsKey(t){return this.values.has(t)}getKeys(){return Array.from(this.values.keys())}removeKey(t){return this.values.delete(t)}clear(){this.values.clear()}};var le=require("obsidian"),R=class{static getFilePathWithNewExtension(t,e){return(0,le.normalizePath)(t.parent.path+"/"+t.basename+"."+e)}static getFilePathExcludingExtension(t){return(0,le.normalizePath)(t.parent.path+"/"+t.basename)}};var p=class{static setActive(t){p.isActive=t,p.isActive||this.clear()}static setAutoExpire(t){p.baseMinutesToExpire=t!=null?t:0,p.updateExpiryTime()}static setLevel(t){p.level!=t&&(p.allLevels.contains(t)&&(p.level=t),p.level=p.LevelFilename,this.clear())}static updateExpiryTime(){p.baseMinutesToExpire==0||p.baseMinutesToExpire==null?p.expiryTime=null:p.expiryTime=Date.now()+p.baseMinutesToExpire*1e3*60}static putByFile(t,e){if(!p.isActive)return;let n=p.getFileCacheKey(e);this.cache.put(n,t),p.updateExpiryTime()}static getByFile(t){if(!p.isActive)return p.blankPasswordAndHint;this.clearIfExpired(),p.updateExpiryTime();let e=p.getFileCacheKey(t);return this.cache.get(e,p.blankPasswordAndHint)}static putByPath(t,e){if(!p.isActive)return;let n=p.getPathCacheKey(e);this.cache.put(n,t),p.updateExpiryTime()}static getByPath(t){if(!p.isActive)return p.blankPasswordAndHint;this.clearIfExpired(),p.updateExpiryTime();let e=p.getPathCacheKey(t);return this.cache.get(e,p.blankPasswordAndHint)}static getPathCacheKey(t){let e=t.split("/").slice(0,-1).join("/");switch(p.level){case p.LevelVault:return"$vault";case p.LevelParentPath:return e;default:return t}}static getFileCacheKey(t){switch(p.level){case p.LevelVault:return"$vault";case p.LevelParentPath:return t.parent.path;default:return R.getFilePathExcludingExtension(t)}}static clearIfExpired(){p.expiryTime!=null&&(Date.now()<p.expiryTime||this.clear())}static clearForFile(t){let e=p.getFileCacheKey(t);this.cache.removeKey(e)}static clearForPath(t){let e=p.getPathCacheKey(t);this.cache.removeKey(e)}static clear(){let t=this.cache.getKeys().length;return this.cache.clear(),t}},g=p;g.isActive=!0,g.blankPasswordAndHint={password:"",hint:""},g.cache=new J,g.baseMinutesToExpire=0,g.expiryTime=null,g.LevelFilename="filename",g.LevelParentPath="parentPath",g.LevelVault="vault",g.allLevels=[p.LevelFilename,p.LevelParentPath,p.LevelVault],g.level=p.LevelVault;var _=class extends k.PluginSettingTab{constructor(e,n,i,r){super(e,n);this.plugin=n,this.settings=i,this.features=r}display(){let{containerEl:e}=this;e.empty(),new k.Setting(e).setName("Confirm password?").setDesc("Confirm password when encrypting. (Recommended)").addToggle(s=>{s.setValue(this.settings.confirmPassword).onChange(async o=>{this.settings.confirmPassword=o,await this.plugin.saveSettings()})});let n=()=>{if(!this.settings.rememberPassword){i.settingEl.hide(),r.settingEl.hide();return}i.settingEl.show(),r.settingEl.show();let s=this.settings.rememberPasswordTimeout,o=`For ${s} minutes`;s==0&&(o="Until Obsidian is closed"),i.setName(`Remember Password (${o})`)};new k.Setting(e).setName("Remember password?").setDesc("Remember the last used passwords when encrypting or decrypting. Passwords are remembered until they timeout or Obsidian is closed").addToggle(s=>{s.setValue(this.settings.rememberPassword).onChange(async o=>{this.settings.rememberPassword=o,await this.plugin.saveSettings(),g.setActive(this.settings.rememberPassword),n()})});let i=new k.Setting(e).setDesc("The number of minutes to remember passwords.").addSlider(s=>{s.setLimits(0,120,5).setValue(this.settings.rememberPasswordTimeout).onChange(async o=>{this.settings.rememberPasswordTimeout=o,await this.plugin.saveSettings(),g.setAutoExpire(this.settings.rememberPasswordTimeout),n()})}),r=new k.Setting(e).setName("Remember passwords by:").setDesc(this.buildRememberPasswordDescription()).addDropdown(s=>{s.addOption(g.LevelVault,"Vault").addOption(g.LevelParentPath,"Folder").addOption(g.LevelFilename,"File").setValue(this.settings.rememberPasswordLevel).onChange(async o=>{this.settings.rememberPasswordLevel=o,await this.plugin.saveSettings(),g.setLevel(this.settings.rememberPasswordLevel),n()})});n(),this.features.forEach(s=>{s.buildSettingsUi(e,async()=>await this.plugin.saveSettings())})}buildRememberPasswordDescription(){let e=new DocumentFragment,n=e.createEl("table").createTBody(),i=n.createEl("tr");return i.createEl("th",{text:"Vault:",attr:{align:"left"}}),i.createEl("td",{text:"typically, you'll use the same password every time."}),i=n.createEl("tr"),i.createEl("th",{text:"Folder:",attr:{align:"left"}}),i.createEl("td",{text:"typically, you'll use the same password for each note within a folder."}),i=n.createEl("tr"),i.createEl("th",{text:"File:",attr:{align:"left"}}),i.createEl("td",{text:"typically, each note will have a unique password."}),e}};var x=require("obsidian");var M=require("obsidian"),H=class extends M.Modal{constructor(e,n,i=""){super(e);this.decryptInPlace=!1;this.canDecryptInPlace=!0;this.titleEl.setText(n),this.text=i}onOpen(){var s;let{contentEl:e}=this;e.empty(),e.classList.add("meld-encrypt-decrypt-modal");let n;(s=new M.Setting(e).addTextArea(o=>{n=o,o.setValue(this.text),o.inputEl.setSelectionRange(0,0),o.inputEl.readOnly=!0,o.inputEl.rows=10}).settingEl.querySelector(".setting-item-info"))==null||s.remove();let r=new M.Setting(e);r.addButton(o=>{o.setButtonText("Copy").onClick(a=>{navigator.clipboard.writeText(n.getValue()),new M.Notice("Copied!")})}),this.canDecryptInPlace&&r.addButton(o=>{o.setWarning().setButtonText("Decrypt in-place").onClick(a=>{this.decryptInPlace=!0,this.close()})})}};var v=require("obsidian");var K=require("obsidian"),P=class{static isSettingsModalOpen(){return document.querySelector(".mod-settings")!==null}static buildPasswordSetting({container:t,name:e,desc:n="",autoFocus:i=!1,placeholder:r="",initialValue:s="",onChangeCallback:o,onEnterCallback:a}){let l=new K.Setting(t).setName(e).setDesc(n).addButton(w=>{w.setIcon("reading-glasses").onClick(f=>{let d=l.components.find((h,c,u)=>h instanceof K.TextComponent);d instanceof K.TextComponent&&(d.inputEl.type=d.inputEl.type=="password"?"text":"password")})}).addText(w=>{w.setPlaceholder(r),w.setValue(s),w.inputEl.type="password",o!=null&&w.onChange(o),a!=null&&(w.inputEl.onkeydown=f=>{f.key==="Enter"&&(f.preventDefault(),a(w.getValue()))}),i&&setTimeout(()=>w.inputEl.focus(),0)});return l}};var L=class extends v.Modal{constructor(e,n,i,r,s=null,o=null,a=!1){super(e);this.defaultPassword=null;this.resultConfirmed=!1;this.resultPassword=null;this.resultShowInReadingView=null;this.resultTextToEncrypt=null;this.defaultPassword=s,this.confirmPassword=i,this.showInReadingView=r,this.isEncrypting=n,this.defaultHint=o!=null?o:"",this.showTextToEncrypt=a}onOpen(){var h;let{contentEl:e}=this;e.empty(),e.classList.add("meld-encrypt-password-modal"),this.invalidate();let n=(h=this.defaultPassword)!=null?h:"",i="",r=this.defaultHint,s=this.showInReadingView,o="";new v.Setting(e).setHeading().setName(this.isEncrypting?"Encrypting":"Decrypting"),P.buildPasswordSetting({container:e,name:"Password:",placeholder:this.isEncrypting||r.length==0?"":`Hint: ${r}`,initialValue:n,autoFocus:!0,onChangeCallback:c=>{n=c,this.invalidate()},onEnterCallback:c=>{if(n=c,this.invalidate(),n.length>0)if(a.settingEl.isShown()){let u=a.components.find(E=>E instanceof v.TextComponent);u instanceof v.TextComponent&&u.inputEl.focus()}else if(l.settingEl.isShown()){let u=l.components.find(E=>E instanceof v.TextComponent);u instanceof v.TextComponent&&u.inputEl.focus()}else d()&&this.close()}});let a=P.buildPasswordSetting({container:e,name:"Confirm Password:",onChangeCallback:c=>{i=c,this.invalidate()},onEnterCallback:c=>{if(i=c,this.invalidate(),i.length>0&&d()&&l.settingEl.isShown()){let u=l.components.find(E=>E instanceof v.TextComponent);u instanceof v.TextComponent&&u.inputEl.focus()}}});this.confirmPassword||a.settingEl.hide();let l=new v.Setting(e).setName("Optional Password Hint").addText(c=>{c.inputEl.placeholder="Password Hint",c.setValue(r),c.onChange(u=>r=u),c.inputEl.on("keypress","*",(u,E)=>{u.key=="Enter"&&E instanceof HTMLInputElement&&E.value.length>0&&(u.preventDefault(),d()&&this.close())})});this.isEncrypting||l.settingEl.hide();let w=new v.Setting(e).setName("Show encrypted marker in Reading view").addToggle(c=>{c.setValue(s).onChange(u=>{s=u})});this.isEncrypting||w.settingEl.hide();let f=new v.Setting(e).setName("Text to encrypt").addTextArea(c=>{c.setValue("").onChange(u=>o=u),c.inputEl.rows=5,c.inputEl.style.width="100%"});this.showTextToEncrypt||f.settingEl.hide(),new v.Setting(e).addButton(c=>{c.setButtonText("Confirm").onClick(u=>{d()&&this.close()})});let d=()=>(this.invalidate(),a.setDesc(""),this.confirmPassword&&n!=i?(a.setDesc("Passwords don't match"),!1):(this.resultConfirmed=!0,this.resultPassword=n,this.resultHint=r,this.resultShowInReadingView=s,this.resultTextToEncrypt=o,!0))}invalidate(){this.resultConfirmed=!1,this.resultPassword=null,this.resultHint="",this.resultTextToEncrypt=""}};var ce=new TextEncoder,De=new TextDecoder,Ae=1e3,Ne=ce.encode("XHWnDAT6ehMVY2zD"),W=class{async deriveKey(t){let e=ce.encode(t),n=await crypto.subtle.importKey("raw",e,{name:"PBKDF2"},!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",hash:{name:"SHA-256"},iterations:Ae,salt:Ne},n,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async encryptToBytes(t,e){let n=await this.deriveKey(e),i=ce.encode(t),r=crypto.getRandomValues(new Uint8Array(16)),s=new Uint8Array(await crypto.subtle.encrypt({name:"AES-GCM",iv:r},n,i)),o=new Uint8Array(r.byteLength+s.byteLength);return o.set(r,0),o.set(s,r.byteLength),o}convertToString(t){let e="";for(let n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return e}async encryptToBase64(t,e){let n=await this.encryptToBytes(t,e);return btoa(this.convertToString(n))}stringToArray(t){let e=[];for(let n=0;n<t.length;n++)e.push(t.charCodeAt(n));return new Uint8Array(e)}async decryptFromBytes(t,e){try{let n=t.slice(0,16),i=t.slice(16),r=await this.deriveKey(e),s=await crypto.subtle.decrypt({name:"AES-GCM",iv:n},r,i);return De.decode(s)}catch(n){return null}}async decryptFromBase64(t,e){try{let n=this.stringToArray(atob(t));return await this.decryptFromBytes(n,e)}catch(n){return null}}};var B=class{constructor(t,e,n){this.vectorSize=t,this.saltSize=e,this.iterations=n}async deriveKey(t,e){let i=new TextEncoder().encode(t),r=await crypto.subtle.importKey("raw",i,"PBKDF2",!1,["deriveKey"]);return await crypto.subtle.deriveKey({name:"PBKDF2",hash:"SHA-512",salt:e,iterations:this.iterations},r,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async encryptToBytes(t,e){let n=crypto.getRandomValues(new Uint8Array(this.saltSize)),i=await this.deriveKey(e,n),s=new TextEncoder().encode(t),o=crypto.getRandomValues(new Uint8Array(this.vectorSize)),a=new Uint8Array(await crypto.subtle.encrypt({name:"AES-GCM",iv:o},i,s)),l=new Uint8Array(o.byteLength+n.byteLength+a.byteLength);return l.set(o,0),l.set(n,o.byteLength),l.set(a,o.byteLength+n.byteLength),l}convertToString(t){let e="";for(let n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return e}async encryptToBase64(t,e){let n=await this.encryptToBytes(t,e);return btoa(this.convertToString(n))}stringToArray(t){let e=[];for(let n=0;n<t.length;n++)e.push(t.charCodeAt(n));return new Uint8Array(e)}async decryptFromBytes(t,e){try{let n,i;n=0,i=n+this.vectorSize;let r=t.slice(n,i);n=i,i=n+this.saltSize;let s=t.slice(n,i);n=i,i=void 0;let o=t.slice(n),a=await this.deriveKey(e,s),l=await crypto.subtle.decrypt({name:"AES-GCM",iv:r},a,o);return new TextDecoder().decode(l)}catch(n){return null}}async decryptFromBase64(t,e){try{let n=this.stringToArray(atob(t));return await this.decryptFromBytes(n,e)}catch(n){return null}}};var de={name:"AES-GCM",iv:new Uint8Array([196,190,240,190,188,78,41,132,15,220,84,211]),tagLength:128},Q=class{async buildKey(t){let n=new TextEncoder().encode(t),i=await crypto.subtle.digest({name:"SHA-256"},n);return await crypto.subtle.importKey("raw",i,de,!1,["encrypt","decrypt"])}async encryptToBase64(t,e){let n=await this.buildKey(e),r=new TextEncoder().encode(t),s=new Uint8Array(await crypto.subtle.encrypt(de,n,r));return btoa(String.fromCharCode(...s))}stringToArray(t){let e=[];for(let n=0;n<t.length;n++)e.push(t.charCodeAt(n));return new Uint8Array(e)}async decryptFromBase64(t,e){try{let n=this.stringToArray(atob(t)),i=await this.buildKey(e),r=await crypto.subtle.decrypt(de,i,n);return new TextDecoder().decode(r)}catch(n){return null}}};var C=class{static BuildDefault(){return new B(16,16,21e4)}static BuildFromFileDataOrThrow(t){let e=C.BuildFromFileDataOrNull(t);if(e!=null)return e;throw new Error(`Unable to determine ICryptoHelper for File ver ${t.version}`)}static BuildFromFileDataOrNull(t){return t.version=="1.0"?new W:t.version=="2.0"?new B(16,16,21e4):null}static BuildFromDecryptableOrThrow(t){let e=C.BuildFromDecryptableOrNull(t);if(e!=null)return e;throw new Error(`Unable to determine ICryptoHelper for Decryptable ver ${t.version}`)}static BuildFromDecryptableOrNull(t){return t.version==0?new Q:t.version==1?new W:t.version==2?new B(16,16,21e4):null}};var Z=class{};var ee="%%\u{1F510}\u03B2 ",te="\u{1F510}\u03B2 ",pe="%%\u{1F510}\u03B1 ",ue="\u{1F510}\u03B1 ",he="%%\u{1F510} ",Pe=ee,ve=te,A=[ee,te,pe,ue,he],ge=" \u{1F510}%%",fe=" \u{1F510}",V=[ge,fe],S="\u{1F4A1}";var X=class{constructor(t){this.process(t)}process(t){var e,n;if(this.processedText=t,this.isEmpty=t.length===0,this.prefix=(e=A.find(i=>t.startsWith(i)))!=null?e:"",this.suffix=(n=V.find(i=>t.endsWith(i)))!=null?n:"",this.hasEncryptedPrefix=this.prefix.length>0,this.hasEncryptedSuffix=this.suffix.length>0,this.hasObsoleteEncryptedPrefix=this.prefix===he,this.containsEncryptedMarkers=[...A,...V].some(i=>t.includes(i)),this.canDecrypt=this.hasEncryptedPrefix&&this.hasEncryptedSuffix,this.canEncrypt=!this.hasEncryptedPrefix&&!this.containsEncryptedMarkers,this.canDecrypt){let i=this.parseDecryptableContent(t);i!=null?this.decryptable=i:this.canDecrypt=!1}}parseDecryptableContent(t){let e=new Z;if(!this.hasEncryptedPrefix||!this.hasEncryptedSuffix)return null;this.hasObsoleteEncryptedPrefix?e.version=0:this.prefix==ee||this.prefix==te?e.version=2:(this.prefix==pe||this.prefix==ue)&&(e.version=1);let n=t.substring(this.prefix.length,t.length-this.suffix.length);if([...A,...V].some(i=>n.includes(i)))return null;if(n.substring(0,S.length)==S){let i=n.indexOf(S,S.length);if(i<0)return null;e.hint=n.substring(S.length,i),e.base64CipherText=n.substring(i+S.length)}else e.base64CipherText=n;return e}};var Y=class{async onload(t,e){this.plugin=t,this.pluginSettings=e,this.featureSettings=e.featureInplaceEncrypt,this.plugin.registerMarkdownPostProcessor((n,i)=>this.processEncryptedCodeBlockProcessor(n,i)),t.addCommand({id:"meld-encrypt",name:"Encrypt/Decrypt",icon:"lock",editorCheckCallback:(n,i,r)=>this.processEncryptDecryptCommand(n,i,!1)}),this.plugin.addRibbonIcon("file-lock","Encrypt/Decrypt",n=>{let i=this.plugin.app.workspace.getActiveViewOfType(x.MarkdownView);if(i==null){console.debug("no active view found");return}return this.processEncryptDecryptCommand(!1,i.editor,!1)}),t.addCommand({id:"meld-encrypt-in-place",name:"Encrypt/Decrypt In-place",icon:"lock",editorCheckCallback:(n,i,r)=>this.processEncryptDecryptCommand(n,i,!0)})}onunload(){}replaceMarkersRecursive(t,e=0){if(t instanceof HTMLElement){for(let i of Array.from(t.childNodes)){var n=this.replaceMarkersRecursive(i,e+1);i.replaceWith(...n)}return[t]}if(t instanceof Text){let i=t.textContent;if(i==null)return[t];if(!i.contains("\u{1F510}"))return[t];let r=/🔐(.*?)🔐/g,s=i.split(r),o=[];for(let a=0;a<s.length;a++){let l=s[a];if(a%2!=0){let w=createSpan({cls:"meld-encrypt-inline-reading-marker",text:"\u{1F510}",attr:{"data-meld-encrypt-encrypted":`\u{1F510}${l}\u{1F510}`}});o.push(w)}else o.push(new Text(l))}return o}return[t]}async processEncryptedCodeBlockProcessor(t,e){let n=this.replaceMarkersRecursive(t);t.replaceWith(...n);let i=t.querySelectorAll(".meld-encrypt-inline-reading-marker");this.bindReadingIndicatorEventHandlers(e.sourcePath,i)}bindReadingIndicatorEventHandlers(t,e){e.forEach(n=>{let i=n;i!=null&&i.onClickEvent(async r=>{let s=r.target;if(s==null)return;let o=s.dataset.meldEncryptEncrypted;if(o==null)return;let a=new X(o);await this.handleReadingIndicatorClick(t,a.decryptable)})})}async handleReadingIndicatorClick(t,e){if(e==null){new x.Notice("\u274C Decryption failed!");return}if(await this.showDecryptedTextIfPasswordKnown(t,e))return;let n=await this.fetchPasswordFromUser(e.hint);n!=null&&(await this.showDecryptedResultForPassword(e,n)?g.putByPath({password:n,hint:e.hint},t):new x.Notice("\u274C Decryption failed!"))}async showDecryptedResultForPassword(t,e){let i=await C.BuildFromDecryptableOrThrow(t).decryptFromBase64(t.base64CipherText,e);return i===null?!1:new Promise(r=>{let s=new H(this.plugin.app,"\u{1F513}",i);s.canDecryptInPlace=!1,s.onClose=()=>{r(!0)},s.open()})}async fetchPasswordFromUser(t){return new Promise(e=>{let n=new L(this.plugin.app,!1,!1,this.featureSettings.showMarkerWhenReadingDefault,"",t);n.onClose=()=>{e(n.resultPassword)},n.open()})}async showDecryptedTextIfPasswordKnown(t,e){let n=g.getByPath(t);return n.password==null?!1:await this.showDecryptedResultForPassword(e,n.password)}buildSettingsUi(t,e){new x.Setting(t).setHeading().setName("In-place encryption"),new x.Setting(t).setName("Expand selection to whole line?").setDesc("Partial selections will get expanded to the whole line.").addToggle(n=>{n.setValue(this.featureSettings.expandToWholeLines).onChange(async i=>{this.featureSettings.expandToWholeLines=i,await e()})}),new x.Setting(t).setName("By default, show encrypted marker when reading").setDesc("When encrypting inline text, should the default be to have a visible marker in Reading view?").addToggle(n=>{n.setValue(this.featureSettings.showMarkerWhenReadingDefault).onChange(async i=>{this.featureSettings.showMarkerWhenReadingDefault=i,await e()})})}processEncryptDecryptCommand(t,e,n){if(t&&P.isSettingsModalOpen())return!0;let i=e.getCursor("from"),r=e.getCursor("to");if(this.featureSettings.expandToWholeLines){i={line:i.line,ch:0};let a=r.line,l=e.getLine(a);r={line:a,ch:l.length}}else if(!e.somethingSelected()){let o=this.getClosestPrefixCursorPos(e),a=this.getClosestSuffixCursorPos(e);if(o==null||a==null||i.line<o.line||r.line>a.line)return this.promptForTextToEncrypt(t,e,i);i=o,r=a}let s=e.getRange(i,r);return this.processSelection(t,e,s,i,r,n)}promptForTextToEncrypt(t,e,n){let i=this.plugin.app.workspace.getActiveFile();if(i==null)return!1;if(t)return!0;let r="",s="";if(this.pluginSettings.rememberPassword){let l=g.getByPath(i.path);r=l.password,s=l.hint}let o=this.pluginSettings.confirmPassword,a=new L(this.plugin.app,!0,o,this.featureSettings.showMarkerWhenReadingDefault,r,s,!0);return a.onClose=async()=>{var h,c,u,E;if(!a.resultConfirmed)return;let l=(h=a.resultPassword)!=null?h:"",w=(c=a.resultHint)!=null?c:"",f=(u=a.resultTextToEncrypt)!=null?u:"",d=new ne;d.text=f,d.hint=w,this.encryptSelection(e,d,l,n,n,(E=a.resultShowInReadingView)!=null?E:this.featureSettings.showMarkerWhenReadingDefault),g.putByPath({password:l,hint:w},i.path)},a.open(),!1}getClosestPrefixCursorPos(t){let e=A.reduce((i,r,s)=>s==0||r.length>i.length?r:i),n=t.posToOffset(t.getCursor("from"))+e.length;for(let i=n;i>=0;i--){let r=t.offsetToPos(i);for(let s of A){let o=i-s.length,a=t.offsetToPos(o);if(t.getRange(a,r)==s)return t.offsetToPos(o)}}return null}getClosestSuffixCursorPos(t){let e=A.reduce((s,o,a)=>a==0||o.length>s.length?o:s),n=t.posToOffset(t.getCursor("from"))-e.length+1,i=t.lastLine(),r=t.posToOffset({line:i,ch:t.getLine(i).length});for(let s=n;s<=r;s++){let o=t.offsetToPos(s);for(let a of V){let l=s+a.length,w=t.offsetToPos(l);if(t.getRange(o,w)==a)return w}}return null}processSelection(t,e,n,i,r,s,o=!0){var c;let a=new X(n);if(a.isEmpty)return t||new x.Notice("Nothing to Encrypt."),!1;if(!a.canDecrypt&&!a.canEncrypt)return t||new x.Notice("Unable to Encrypt or Decrypt that."),!1;if(a.canEncrypt&&!o)return!1;let l=this.plugin.app.workspace.getActiveFile();if(l==null)return!1;if(t)return!0;let w="",f=(c=a.decryptable)==null?void 0:c.hint;if(this.pluginSettings.rememberPassword){let u=g.getByPath(l.path);w=u.password,f=f!=null?f:u.hint}let d=a.canEncrypt&&this.pluginSettings.confirmPassword,h=new L(this.plugin.app,a.canEncrypt,d,this.featureSettings.showMarkerWhenReadingDefault,w,f);return h.onClose=async()=>{var ye,me,Ee;if(!h.resultConfirmed)return;let u=(ye=h.resultPassword)!=null?ye:"",E=(me=h.resultHint)!=null?me:"";if(a.canEncrypt){let j=new ne;j.text=n,j.hint=E,this.encryptSelection(e,j,u,i,r,(Ee=h.resultShowInReadingView)!=null?Ee:this.featureSettings.showMarkerWhenReadingDefault),g.putByPath({password:u,hint:E},l.path)}else a.decryptable&&await this.decryptSelection(e,a.decryptable,u,i,r,s)&&g.putByPath({password:u,hint:E},l.path)},h.open(),!0}async encryptSelection(t,e,n,i,r,s){let o=C.BuildDefault(),a=this.encodeEncryption(await o.encryptToBase64(e.text,n),e.hint,s);t.setSelection(i,r),t.replaceSelection(a)}async decryptSelection(t,e,n,i,r,s){let a=await C.BuildFromDecryptableOrThrow(e).decryptFromBase64(e.base64CipherText,n);if(a===null)return new x.Notice("\u274C Decryption failed!"),!1;if(s)t.setSelection(i,r),t.replaceSelection(a);else{let l=new H(this.plugin.app,"\u{1F513}",a);l.onClose=()=>{t.focus(),l.decryptInPlace&&(t.setSelection(i,r),t.replaceSelection(a))},l.open()}return!0}encodeEncryption(t,e,n){if(!A.some(i=>t.includes(i))&&!V.some(i=>t.includes(i))){let i=n?ve:Pe,r=n?fe:ge;return e.length>0?i.concat(S,e,S,t,r):i.concat(t,r)}return t}},ne=class{};var F=require("obsidian");var m=require("obsidian");var O=class{static get showInlineTitle(){var t;return(t=app.vault.getConfig("showInlineTitle"))!=null?t:!0}static get readableLineLength(){var t;return(t=app.vault.getConfig("readableLineLength"))!=null?t:!0}};var ie=class{constructor(t,e,n){this.version="1.0";this.version=t,this.hint=e,this.encodedData=n}},we=class{static async encode(t,e,n){let r=await C.BuildDefault().encryptToBase64(n,t);return new ie(we.DEFAULT_VERSION,e,r)}static async decrypt(t,e){return t.encodedData==""?"":await C.BuildFromFileDataOrThrow(t).decryptFromBase64(t.encodedData,e)}},I=we;I.DEFAULT_VERSION="2.0";var D=class{static encode(t){return JSON.stringify(t,null,2)}static decode(t){return t===""?new ie(I.DEFAULT_VERSION,"",""):JSON.parse(t)}};var ke="encrypted",be="mdenc",se=be,N=[be,ke];var $="meld-encrypted-file-content-view",z=class extends m.TextFileView{constructor(e,n){var i;super(e);this.iconReadingView="book-open";this.iconSourceView="code";this.iconToggleEditView="edit";this.iconLockFile="lock";this.iconChangePassword="key";this.currentView=0;this.encryptionPassword="";this.hint="";this.currentEditorSourceText="";this.settings=n,this.defaultEditNoteView=(i=n.defaultView)!=null?i:"Source",this.currentEditNoteMode=this.defaultEditNoteView,this.elActionEditView=this.addAction(this.iconSourceView,"Source",()=>this.toggleReadingView()),this.elActionReadingView=this.addAction(this.iconReadingView,"Reading",()=>this.toggleReadingView()),this.elActionIconLockNote=this.addAction(this.iconLockFile,"Lock",()=>this.actionLockFile()),this.elActionChangePassword=this.addAction(this.iconChangePassword,"Change Password",()=>this.actionChangePassword()),this.elActionEditView.hide(),this.elActionReadingView.hide(),this.elActionIconLockNote.hide(),this.elActionChangePassword.hide(),this.containerEl.classList.add("meld-encrypt-encrypted-note-view"),this.contentEl.classList.add("meld-encrypt-encrypted-note-view-content")}toggleReadingView(){this.currentView==2&&(this.currentEditNoteMode=="Reading"?this.currentEditNoteMode="Source":this.currentEditNoteMode=="Source"&&(this.currentEditNoteMode="Reading"),this.refreshView(2))}actionLockFile(){this.encryptionPassword="",g.clearForFile(this.file),this.refreshView(1)}actionChangePassword(){this.refreshView(3)}onPaneMenu(e,n){n=="tab-header"&&this.currentView==2&&(e.addItem(i=>{i.setSection("action").setIcon(this.iconToggleEditView).setTitle("Toggle Editing/Reading").onClick(()=>this.toggleReadingView())}),e.addItem(i=>{i.setSection("action").setIcon(this.iconLockFile).setTitle("Lock").onClick(()=>this.actionLockFile())}),e.addItem(i=>{i.setSection("action").setIcon(this.iconChangePassword).setTitle("Change Password").onClick(()=>this.actionChangePassword())})),super.onPaneMenu(e,n)}addHeader(e,n){var i;e.createDiv({text:`\u{1F510} ${n} \u{1F510}`,cls:"encrypted-note-message"}),O.showInlineTitle&&e.createDiv({text:(i=this.file)==null?void 0:i.basename,cls:"inline-title"})}validatePassword(e){return""}validateConfirm(e,n){return e===n?"":"Password doesn't match"}addNewNoteView(e){this.addHeader(e,"This note will be encrypted");let n=this.addUserInputContainer(e);new m.Setting(n).setDesc("Please provide a password and hint to start editing this note.");let i=async(d,h,c)=>{let u=this.validatePassword(d),E=this.validateConfirm(d,h);l.setDesc(u),w.setDesc(E),u.length===0&&E.length===0&&(this.encryptionPassword=d,this.hint=c,O.showInlineTitle||(this.currentEditorSourceText=`# ${this.file.basename}
`),await this.encodeAndSave(),g.putByFile({password:d,hint:c},this.file),this.currentEditNoteMode="Source",this.refreshView(2))},r=g.getByFile(this.file),s=r.password,o="",a=r.hint,l=P.buildPasswordSetting({container:n,name:"Password:",autoFocus:!0,initialValue:s,onChangeCallback:d=>{s=d,l.setDesc(this.validatePassword(s)),w.setDesc(this.validateConfirm(s,o))},onEnterCallback:d=>{var h;s=d,s.length>0&&((h=w.controlEl.querySelector("input"))==null||h.focus())}}),w=P.buildPasswordSetting({container:n,name:"Confirm:",autoFocus:!1,onChangeCallback:d=>{o=d,l.setDesc(this.validatePassword(s)),w.setDesc(this.validateConfirm(s,o))},onEnterCallback:d=>{var c;o=d,s===o&&((c=f.controlEl.querySelector("input"))==null||c.focus())}}),f=new m.Setting(n).setName("Hint:").addText(d=>{d.setValue(a),d.onChange(h=>{a=h})});f.controlEl.on("keydown","*",d=>{d.key==="Enter"&&(d.preventDefault(),i(s,o,a))}),new m.Setting(n).addButton(d=>{d.setCta().setIcon("go-to-file").setTooltip("Edit").onClick(h=>i(s,o,a))})}addDecryptNoteView(e){this.addHeader(e,"This note is encrypted");let n=this.addUserInputContainer(e);new m.Setting(n).setDesc("Please provide a password to unlock this note.");let i=P.buildPasswordSetting({container:n,name:"Password:",autoFocus:!0,placeholder:this.formatHint(this.hint),onChangeCallback:s=>{this.encryptionPassword=s,i.setDesc(this.validatePassword(this.encryptionPassword))},onEnterCallback:async()=>await this.handleDecryptButtonClick()});new m.Setting(n).addButton(s=>{s.setCta().setIcon("checkmark").setTooltip("Unlock & Edit").onClick(o=>this.handleDecryptButtonClick())});let r=g.getByFile(this.file);this.encryptionPassword=r.password,r.password.length>0&&this.decryptWithPassword(r.password).then(s=>{s!=null&&(this.currentEditorSourceText=s,this.refreshView(2),new m.Notice("Decrypted using remembered password",2e3))})}async encodeAndSave(){try{let e=await I.encode(this.encryptionPassword,this.hint,this.currentEditorSourceText);this.data=D.encode(e),this.requestSave()}catch(e){console.error(e),new m.Notice(e,1e4)}}addEditorSourceView(e){this.elActionReadingView.show(),this.elActionIconLockNote.show(),this.elActionChangePassword.show(),this.addHeader(e,"Editing an encrypted note");let n=e.createDiv({cls:"editor-source-view"},i=>{i.spellcheck=!0,i.autocapitalize="on",i.translate=!1,i.contentEditable="plaintext-only",i.style.tabSize="4",i.innerText=this.currentEditorSourceText});n.focus(),n.on("keydown","*",(i,r)=>{i.key=="Tab"&&this.handleTabInEditor(i,n)}),n.on("input","*",async(i,r)=>{this.updateAndSaveEditorSourceText(n)})}async updateAndSaveEditorSourceText(e){this.currentEditorSourceText=e.innerText,await this.encodeAndSave()}handleTabInEditor(e,n){let i=window.getSelection();if(i==null||i.rangeCount<1)return;e.preventDefault();let r=!e.shiftKey;for(let s=0;s<i.rangeCount;s++){let o=i.getRangeAt(s),a=this.getRangeNodes(o);for(let l=0;l<a.length;l++){let w=a[l];w instanceof Text&&(r?w.insertData(0," "):w.data.startsWith(" ")&&w.replaceData(0,1,""))}}this.updateAndSaveEditorSourceText(n)}getRangeNodes(e){let n=Array();if(e.startContainer==e.endContainer)return[e.startContainer];let i=e.startContainer;for(i==e.commonAncestorContainer&&(i=e.commonAncestorContainer.firstChild);i!=null;)e.intersectsNode(i)&&n.push(i),i=i.nextSibling;return n}addEditorReadingView(e){this.elActionEditView.show(),this.elActionIconLockNote.show(),this.elActionChangePassword.show(),this.addHeader(e,"Reading an encrypted note");let n=e.createDiv({cls:"editor-reading-view"});m.MarkdownRenderer.renderMarkdown(this.currentEditorSourceText,n,this.file.path,this).catch(i=>{console.error(i)}),n.on("click","a.internal-link",async(i,r)=>{if(r instanceof HTMLAnchorElement){let s=(0,m.normalizePath)(decodeURI(r.pathname));this.app.workspace.openLinkText(s,this.file.path,i.ctrlKey)}})}addUserInputContainer(e){return e.createDiv({cls:"input-container"})}addChangePasswordView(e){this.addHeader(e,"Change encrypted note password");let n=this.addUserInputContainer(e),i="",r="",s="",o=async(f,d,h)=>{let c=this.validatePassword(f),u=this.validateConfirm(f,d);a.setDesc(c),l.setDesc(u),c.length===0&&u.length===0&&(this.encryptionPassword=f,this.hint=h,this.encodeAndSave(),this.refreshView(2),g.putByFile({password:f,hint:h},this.file),new m.Notice("Password and Hint were changed"))},a=P.buildPasswordSetting({container:n,name:"New Password:",autoFocus:!0,onChangeCallback:f=>{i=f,a.setDesc(this.validatePassword(i)),l.setDesc(this.validateConfirm(i,r))},onEnterCallback:f=>{var d;i=f,i.length>0&&((d=l.controlEl.querySelector("input"))==null||d.focus())}}),l=P.buildPasswordSetting({container:n,name:"Confirm:",onChangeCallback:f=>{r=f,a.setDesc(this.validatePassword(i)),l.setDesc(this.validateConfirm(i,r))},onEnterCallback:f=>{var h;r=f,i===r&&((h=w.controlEl.querySelector("input"))==null||h.focus())}}),w=new m.Setting(n).setName("New Hint:").addText(f=>{f.onChange(d=>{s=d})});w.controlEl.on("keydown","*",f=>{f.key==="Enter"&&(f.preventDefault(),o(i,r,s))}),new m.Setting(n).addButton(f=>{f.removeCta().setIcon("cross").setTooltip("Cancel").onClick(()=>{this.refreshView(2)})}).addButton(f=>{f.setCta().setIcon("checkmark").setTooltip("Change Password").setWarning().onClick(d=>{o(i,r,s)})})}formatHint(e){return e.length>0?`Hint: ${e}`:""}refreshView(e){this.currentView=e,this.elActionEditView.hide(),this.elActionReadingView.hide(),this.elActionIconLockNote.hide(),this.elActionChangePassword.hide(),this.contentEl.empty(),O.readableLineLength?this.contentEl.classList.add("is-readable-line-width"):this.contentEl.classList.remove("is-readable-line-width");let n=this.contentEl.createDiv({cls:"content-container"});switch(this.currentView){case 4:this.addNewNoteView(n);break;case 1:this.addDecryptNoteView(n);break;case 2:this.currentEditNoteMode=="Source"?this.addEditorSourceView(n):this.addEditorReadingView(n);break;case 3:this.addChangePasswordView(n);break}}async decryptWithPassword(e){let n=D.decode(this.data);return await I.decrypt(n,e)}async handleDecryptButtonClick(){let e=await this.decryptWithPassword(this.encryptionPassword);e===null?new m.Notice("Decryption failed"):(g.putByFile({password:this.encryptionPassword,hint:this.hint},this.file),this.currentEditorSourceText=e,this.refreshView(2))}canAcceptExtension(e){return N.contains(e)}getViewType(){return $}setViewData(e,n){if(n){let i;e===""?i=4:i=1,this.encryptionPassword="";let r=D.decode(this.data);this.hint=r.hint,this.refreshView(i)}else this.leaf.detach(),new m.Notice("Multiple views of the same encrypted note isn't supported")}getViewData(){return this.data}clear(){}};var G=class{async onload(t,e){this.plugin=t,this.settings=e.featureWholeNoteEncrypt,this.plugin.addRibbonIcon("file-lock-2","New encrypted note",n=>{this.processCreateNewEncryptedNoteCommand(this.getDefaultFileFolder())}),this.plugin.registerView($,n=>new z(n,this.settings)),this.plugin.registerExtensions(N,$),this.plugin.addCommand({id:"meld-encrypt-create-new-note",name:"Create new encrypted note",icon:"file-lock-2",callback:()=>this.processCreateNewEncryptedNoteCommand(this.getDefaultFileFolder())}),this.plugin.addCommand({id:"meld-encrypt-toggle-reading-view",name:"Toggle Reading View",icon:"edit",callback:()=>this.processToggleReadingViewCommand()}),this.plugin.registerEvent(this.plugin.app.workspace.on("file-menu",(n,i)=>{i instanceof F.TFolder&&n.addItem(r=>{r.setTitle("New encrypted note").setIcon("file-lock-2").onClick(()=>this.processCreateNewEncryptedNoteCommand(i))})}))}onunload(){this.plugin.app.workspace.detachLeavesOfType($)}processToggleReadingViewCommand(){let t=this.plugin.app.workspace.getActiveViewOfType(z);t==null||t.toggleReadingView()}getDefaultFileFolder(){let t=this.plugin.app.workspace.getActiveFile();return t!=null?this.plugin.app.fileManager.getNewFileParent(t.path):this.plugin.app.fileManager.getNewFileParent("")}processCreateNewEncryptedNoteCommand(t){try{let e=(0,F.moment)().format(`[Untitled] YYYYMMDD hhmmss[.${se}]`),n=(0,F.normalizePath)(t.path+"/"+e);this.plugin.app.vault.create(n,"").then(async i=>{await this.plugin.app.workspace.getLeaf(!0).openFile(i)}).catch(i=>{new F.Notice(i,1e4)})}catch(e){console.error(e),new F.Notice(e,1e4)}}buildSettingsUi(t,e){new F.Setting(t).setHeading().setName("Whole note encryption"),new F.Setting(t).setName("Default view for new tabs").setDesc("The default view that a new encrypted note tab gets opened in").addDropdown(n=>{var i;n.addOption(`${"Source"}`,"Source view").addOption(`${"Reading"}`,"Reading view").setValue(`${(i=this.settings.defaultView)!=null?i:"Source"}`).onChange(async r=>{this.settings.defaultView=r,await e()})})}};var T=require("obsidian");var b=require("obsidian");var U=class extends b.Modal{constructor(e,n,i,r,s){super(e);this.resultConfirmed=!1;this.title=n,this.defaultPassword=s,this.confirmPassword=r,this.isEncrypting=i}onOpen(){var l,w,f,d;let{contentEl:e}=this;e.empty(),this.invalidate();let n=(w=(l=this.defaultPassword)==null?void 0:l.password)!=null?w:"",i="",r=(d=(f=this.defaultPassword)==null?void 0:f.hint)!=null?d:"";new b.Setting(e).setHeading().setName(this.title),P.buildPasswordSetting({container:e,name:"Password:",placeholder:this.isEncrypting?"":`Hint: ${r}`,initialValue:n,autoFocus:n=="",onChangeCallback:h=>{n=h,this.invalidate()},onEnterCallback:h=>{if(n=h,this.invalidate(),n.length>0)if(s.settingEl.isShown()){let c=s.components.find(u=>u instanceof b.TextComponent);c instanceof b.TextComponent&&c.inputEl.focus()}else if(o.settingEl.isShown()){let c=o.components.find(u=>u instanceof b.TextComponent);c instanceof b.TextComponent&&c.inputEl.focus()}else a()&&this.close()}});let s=P.buildPasswordSetting({container:e,name:"Confirm Password:",autoFocus:n!="",onChangeCallback:h=>{i=h,this.invalidate()},onEnterCallback:h=>{if(i=h,this.invalidate(),i.length>0&&a()&&o.settingEl.isShown()){let c=o.components.find(u=>u instanceof b.TextComponent);c instanceof b.TextComponent&&c.inputEl.focus()}}});this.confirmPassword||s.settingEl.hide();let o=new b.Setting(e).setName("Optional Password Hint").addText(h=>{h.inputEl.placeholder="Password Hint",h.setValue(r),h.onChange(c=>r=c),h.inputEl.on("keypress","*",(c,u)=>{c.key=="Enter"&&u instanceof HTMLInputElement&&u.value.length>0&&(c.preventDefault(),a()&&this.close())})});this.isEncrypting||o.settingEl.hide(),new b.Setting(e).addButton(h=>{h.setButtonText("Confirm").onClick(c=>{a()&&this.close()})});let a=()=>(this.invalidate(),s.setDesc(""),this.confirmPassword&&n!=i?(s.setDesc("Passwords don't match"),!1):(this.resultConfirmed=!0,this.resultPassword={password:n,hint:r},!0))}openAsync(){return new Promise((e,n)=>{this.onClose=()=>{this.resultConfirmed==!0?e(this.resultPassword):n()},this.open()})}invalidate(){this.resultConfirmed=!1,this.resultPassword={password:"",hint:""}}};var q=class{async onload(t,e){this.plugin=t,this.plugin.addCommand({id:"meld-encrypt-convert-to-or-from-encrypted-note",name:"Convert to or from an Encrypted note",icon:"file-lock",checkCallback:n=>this.processCommandConvertActiveNote(n)}),this.plugin.addRibbonIcon("file-lock","Convert to or from an Encrypted note",n=>this.processCommandConvertActiveNote(!1)),this.plugin.registerEvent(this.plugin.app.workspace.on("file-menu",(n,i)=>{i instanceof T.TFile&&(i.extension=="md"&&n.addItem(r=>{r.setTitle("Encrypt note").setIcon("file-lock").onClick(()=>this.processCommandEncryptNote(i))}),N.contains(i.extension)&&n.addItem(r=>{r.setTitle("Decrypt note").setIcon("file").onClick(()=>this.processCommandDecryptNote(i))}))}))}onunload(){}buildSettingsUi(t,e){}checkCanEncryptFile(t){return t==null?!1:t.extension=="md"}checkCanDecryptFile(t){return t==null?!1:N.contains(t.extension)}processCommandEncryptNote(t){this.getPasswordAndEncryptFile(t).catch(e=>{e&&new T.Notice(e,1e4)})}processCommandDecryptNote(t){this.getPasswordAndDecryptFile(t).catch(e=>{e&&new T.Notice(e,1e4)})}processCommandConvertActiveNote(t){let e=this.plugin.app.workspace.getActiveFile();if(t)return this.checkCanEncryptFile(e)||this.checkCanDecryptFile(e);(e==null?void 0:e.extension)=="md"&&this.getPasswordAndEncryptFile(e).catch(n=>{n&&new T.Notice(n,1e4)}),e&&N.contains(e.extension)&&this.getPasswordAndDecryptFile(e).catch(n=>{n&&new T.Notice(n,1e4)})}async getPasswordAndEncryptFile(t){if(!this.checkCanEncryptFile(t))throw new Error("Unable to encrypt file");let e=g.getByFile(t),n=new U(this.plugin.app,"Encrypt Note",!0,!0,e);try{let i=await n.openAsync(),r=await this.encryptFile(t,i);await this.closeUpdateRememberPasswordThenReopen(t,se,r,i),new T.Notice("\u{1F510} Note was encrypted \u{1F510}")}catch(i){i&&new T.Notice(i,1e4)}}async getPasswordAndDecryptFile(t){if(!this.checkCanDecryptFile(t))throw new Error("Unable to decrypt file");let e=g.getByFile(t);if(e.password!=""){let s=await this.decryptFile(t,e.password);if(s!=null){await this.closeUpdateRememberPasswordThenReopen(t,"md",s,e);return}}let n=await this.plugin.app.vault.read(t),i=D.decode(n),r=new U(this.plugin.app,"Decrypt Note",!1,!1,{password:"",hint:i.hint});try{if(e=await r.openAsync(),!r.resultConfirmed)return;let s=await this.decryptFile(t,e.password);if(s==null)throw new Error("Decryption failed");await this.closeUpdateRememberPasswordThenReopen(t,"md",s,e),new T.Notice("\u{1F513} Note was decrypted \u{1F513}")}catch(s){s&&new T.Notice(s,1e4)}}async closeUpdateRememberPasswordThenReopen(t,e,n,i){let r=!1;this.plugin.app.workspace.iterateAllLeaves(s=>{s.view instanceof T.TextFileView&&s.view.file==t&&(s.detach(),r=!0)});try{let s=R.getFilePathWithNewExtension(t,e);await this.plugin.app.fileManager.renameFile(t,s),await this.plugin.app.vault.modify(t,n),g.putByFile(i,t)}finally{r&&await this.plugin.app.workspace.getLeaf().openFile(t)}}async encryptFile(t,e){let n=await this.plugin.app.vault.read(t),i=await I.encode(e.password,e.hint,n);return D.encode(i)}async decryptFile(t,e){let n=await this.plugin.app.vault.read(t),i=D.decode(n);return await I.decrypt(i,e)}};var re=class extends oe.Plugin{constructor(){super(...arguments);this.enabledFeatures=[]}async onload(){await this.loadSettings(),this.enabledFeatures.push(new G,new q,new Y),this.addSettingTab(new _(this.app,this,this.settings,this.enabledFeatures)),this.addCommand({id:"meld-encrypt-clear-password-cache",name:"Clear Session Password Cache",icon:"file-lock",callback:()=>{let e=g.clear();new oe.Notice(`Items cleared: ${e}`)}}),this.enabledFeatures.forEach(async e=>{await e.onload(this,this.settings)})}onunload(){this.enabledFeatures.forEach(async e=>{e.onunload()})}async loadSettings(){let e={confirmPassword:!0,rememberPassword:!0,rememberPasswordTimeout:30,rememberPasswordLevel:g.LevelVault,featureWholeNoteEncrypt:{defaultView:"Source".toString()},featureInplaceEncrypt:{expandToWholeLines:!1,showMarkerWhenReadingDefault:!0}};this.settings=Object.assign(e,await this.loadData()),g.setActive(this.settings.rememberPassword),g.setAutoExpire(this.settings.rememberPasswordTimeout==0?null:this.settings.rememberPasswordTimeout),g.setLevel(this.settings.rememberPasswordLevel)}async saveSettings(){await this.saveData(this.settings)}};