/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var Q=Object.defineProperty;var he=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var fe=Object.prototype.hasOwnProperty;var ye=(f,n)=>{for(var e in n)Q(f,e,{get:n[e],enumerable:!0})},we=(f,n,e,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of ge(n))!fe.call(f,i)&&i!==e&&Q(f,i,{get:()=>n[i],enumerable:!(t=he(n,i))||t.enumerable});return f};var me=f=>we(Q({},"__esModule",{value:!0}),f);var xe={};ye(xe,{default:()=>J});module.exports=me(xe);var ue=require("obsidian");var T=require("obsidian");var _=class{constructor(){this.values=new Map}put(n,e){this.values.set(n,e)}get(n,e){var t;return(t=this.values.get(n))!=null?t:e}getFirst(n,e){for(let t=0;t{r.setValue(this.settings.confirmPassword).onChange(async o=>{this.settings.confirmPassword=o,await this.plugin.saveSettings()})});let t=()=>{if(!this.settings.rememberPassword){i.settingEl.hide(),s.settingEl.hide();return}i.settingEl.show(),s.settingEl.show();let r=this.settings.rememberPasswordTimeout,o=`For ${r} minutes`;r==0&&(o="Always"),i.setName(`Remember Password (${o})`)};new T.Setting(e).setName("Remember password?").setDesc("Remember the last used passwords when encrypting or decrypting.").addToggle(r=>{r.setValue(this.settings.rememberPassword).onChange(async o=>{this.settings.rememberPassword=o,await this.plugin.saveSettings(),u.setActive(this.settings.rememberPassword),t()})});let i=new T.Setting(e).setDesc("The number of minutes to remember passwords.").addSlider(r=>{r.setLimits(0,120,5).setValue(this.settings.rememberPasswordTimeout).onChange(async o=>{this.settings.rememberPasswordTimeout=o,await this.plugin.saveSettings(),u.setAutoExpire(this.settings.rememberPasswordTimeout),t()})}),s=new T.Setting(e).setDesc("Remember passwords by using").addDropdown(r=>{r.addOption(u.LevelFullPath,"Full Path").addOption(u.LevelParentPath,"Parent Path").setValue(this.settings.rememberPasswordLevel).onChange(async o=>{this.settings.rememberPasswordLevel=o,await this.plugin.saveSettings(),u.setLevel(this.settings.rememberPasswordLevel),t()})});t(),this.features.forEach(r=>{r.buildSettingsUi(e,async()=>await this.plugin.saveSettings())})}};var P=require("obsidian");var k=require("obsidian"),I=class extends k.Modal{constructor(e,t,i=""){super(e);this.decryptInPlace=!1;this.canDecryptInPlace=!0;this.titleEl.setText(t),this.text=i}onOpen(){var r;let{contentEl:e}=this;e.empty(),e.classList.add("meld-encrypt-decrypt-modal");let t;(r=new k.Setting(e).addTextArea(o=>{t=o,o.setValue(this.text),o.inputEl.setSelectionRange(0,0),o.inputEl.readOnly=!0,o.inputEl.rows=10}).settingEl.querySelector(".setting-item-info"))==null||r.remove();let s=new k.Setting(e);s.addButton(o=>{o.setButtonText("Copy").onClick(a=>{navigator.clipboard.writeText(t.getValue()),new k.Notice("Copied!")})}),this.canDecryptInPlace&&s.addButton(o=>{o.setWarning().setButtonText("Decrypt in-place").onClick(a=>{this.decryptInPlace=!0,this.close()})})}};var E=require("obsidian");var H=require("obsidian"),b=class{static isSettingsModalOpen(){return document.querySelector(".mod-settings")!==null}static buildPasswordSetting({container:n,name:e,desc:t="",autoFocus:i=!1,placeholder:s="",initialValue:r="",onChangeCallback:o,onEnterCallback:a}){let p=new H.Setting(n).setName(e).setDesc(t).addButton(h=>{h.setIcon("reading-glasses").onClick(l=>{let c=p.components.find((d,g,w)=>d instanceof H.TextComponent);c instanceof H.TextComponent&&(c.inputEl.type=c.inputEl.type=="password"?"text":"password")})}).addText(h=>{h.setPlaceholder(s),h.setValue(r),h.inputEl.type="password",o!=null&&h.onChange(o),a!=null&&(h.inputEl.onkeydown=l=>{l.key==="Enter"&&(l.preventDefault(),a(h.getValue()))}),i&&setTimeout(()=>h.inputEl.focus(),0)});return p}};var A=class extends E.Modal{constructor(e,t,i,s,r=null,o=null){super(e);this.defaultPassword=null;this.defaultHint=null;this.resultConfirmed=!1;this.resultPassword=null;this.resultHint=null;this.resultShowInReadingView=null;this.defaultPassword=r,this.confirmPassword=i,this.showInReadingView=s,this.isEncrypting=t,this.defaultHint=o}onOpen(){var l,c;let{contentEl:e}=this;e.empty(),this.invalidate();let t=(l=this.defaultPassword)!=null?l:"",i="",s=(c=this.defaultHint)!=null?c:"",r=this.showInReadingView;new E.Setting(e).setHeading().setName(this.isEncrypting?"Encrypting":"Decrypting"),b.buildPasswordSetting({container:e,name:"Password:",placeholder:this.isEncrypting?"":`Hint: ${this.defaultHint}`,initialValue:t,autoFocus:!0,onChangeCallback:d=>{t=d,this.invalidate()},onEnterCallback:d=>{if(t=d,this.invalidate(),t.length>0)if(o.settingEl.isShown()){let g=o.components.find(w=>w instanceof E.TextComponent);g instanceof E.TextComponent&&g.inputEl.focus()}else if(a.settingEl.isShown()){let g=a.components.find(w=>w instanceof E.TextComponent);g instanceof E.TextComponent&&g.inputEl.focus()}else h()&&this.close()}});let o=b.buildPasswordSetting({container:e,name:"Confirm Password:",onChangeCallback:d=>{i=d,this.invalidate()},onEnterCallback:d=>{if(i=d,this.invalidate(),i.length>0&&h()&&a.settingEl.isShown()){let g=a.components.find(w=>w instanceof E.TextComponent);g instanceof E.TextComponent&&g.inputEl.focus()}}});this.confirmPassword||o.settingEl.hide();let a=new E.Setting(e).setName("Optional Password Hint").addText(d=>{d.inputEl.placeholder="Password Hint",d.setValue(s),d.onChange(g=>s=g),d.inputEl.on("keypress","*",(g,w)=>{g.key=="Enter"&&w instanceof HTMLInputElement&&w.value.length>0&&(g.preventDefault(),h()&&this.close())})});this.isEncrypting||a.settingEl.hide();let p=new E.Setting(e).setName("Show encrypted marker in Reading view").addToggle(d=>{d.setValue(r).onChange(g=>{r=g})});this.isEncrypting||p.settingEl.hide(),new E.Setting(e).addButton(d=>{d.setButtonText("Confirm").onClick(g=>{h()&&this.close()})});let h=()=>(this.invalidate(),o.setDesc(""),this.confirmPassword&&t!=i?(o.setDesc("Passwords don't match"),!1):(this.resultConfirmed=!0,this.resultPassword=t,this.resultHint=s,this.resultShowInReadingView=r,!0))}invalidate(){this.resultConfirmed=!1,this.resultPassword=null,this.resultHint=null}};var Z=new TextEncoder,Ee=new TextDecoder,be=1e3,Pe=Z.encode("XHWnDAT6ehMVY2zD"),R=class{async deriveKey(n){let e=Z.encode(n),t=await crypto.subtle.importKey("raw",e,{name:"PBKDF2"},!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",hash:{name:"SHA-256"},iterations:be,salt:Pe},t,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async encryptToBytes(n,e){let t=await this.deriveKey(e),i=Z.encode(n),s=crypto.getRandomValues(new Uint8Array(16)),r=new Uint8Array(await crypto.subtle.encrypt({name:"AES-GCM",iv:s},t,i)),o=new Uint8Array(s.byteLength+r.byteLength);return o.set(s,0),o.set(r,s.byteLength),o}convertToString(n){let e="";for(let t=0;tthis.processEncryptedCodeBlockProcessor(t,i)),n.addCommand({id:"meld-encrypt",name:"Encrypt/Decrypt",icon:"lock",editorCheckCallback:(t,i,s)=>this.processEncryptDecryptCommand(t,i,!1)}),n.addCommand({id:"meld-encrypt-in-place",name:"Encrypt/Decrypt In-place",icon:"lock",editorCheckCallback:(t,i,s)=>this.processEncryptDecryptCommand(t,i,!0)})}onunload(){}async processEncryptedCodeBlockProcessor(n,e){let t=e.getSectionInfo(n);if(t==null)return;let i=S.extractTextLines(t.text,t.lineStart,t.lineEnd),s=S.findFirstMarker(D,i);if(s==null||!(s.marker==ie||s.marker==Y))return;let r=S.findFirstMarker(N,i,s.position+s.marker.length);if(r==null)return;let o=S.removeMarkers(i,s,r),a=new $(o);if(!a.canDecrypt)return;let p=S.extractTextBeforeMarker(i,s),h=S.extractTextAfterMarker(i,r),l=p+'\u{1F510}'+h;n.empty(),await P.MarkdownRenderer.renderMarkdown(l,n,e.sourcePath,this.plugin);let c=n.querySelector(".meld-encrypt-inline-reading-marker");c==null||c.onClickEvent(async()=>await this.handleReadingIndicatorClick(e.sourcePath,a.decryptable))}async handleReadingIndicatorClick(n,e){if(e==null){new P.Notice("\u274C Decryption failed!");return}if(await this.showDecryptedTextIfPasswordKnown(n,e))return;let t=await this.fetchPasswordFromUser(e.hint);t!=null&&(await this.showDecryptedResultForPassword(e,t)?u.putByPath({password:t,hint:e.hint},n):new P.Notice("\u274C Decryption failed!"))}async showDecryptedResultForPassword(n,e){let i=await C.BuildFromDecryptable(n).decryptFromBase64(n.base64CipherText,e);return i===null?!1:new Promise(s=>{let r=new I(this.plugin.app,"\u{1F513}",i);r.canDecryptInPlace=!1,r.onClose=()=>{s(!0)},r.open()})}async fetchPasswordFromUser(n){return new Promise(e=>{let t=new A(this.plugin.app,!1,!1,this.featureSettings.showMarkerWhenReadingDefault,"",n);t.onClose=()=>{e(t.resultPassword)},t.open()})}async showDecryptedTextIfPasswordKnown(n,e){let t=u.getByPath(n);return t.password==null?!1:await this.showDecryptedResultForPassword(e,t.password)}buildSettingsUi(n,e){new P.Setting(n).setHeading().setName("In-place Encryption Settings"),new P.Setting(n).setName("Expand selection to whole line?").setDesc("Partial selections will get expanded to the whole line.").addToggle(t=>{t.setValue(this.featureSettings.expandToWholeLines).onChange(async i=>{this.featureSettings.expandToWholeLines=i,await e()})}),new P.Setting(n).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(t=>{t.setValue(this.featureSettings.showMarkerWhenReadingDefault).onChange(async i=>{this.featureSettings.showMarkerWhenReadingDefault=i,await e()})})}processEncryptDecryptCommand(n,e,t){if(n&&b.isSettingsModalOpen())return!0;let i=e.getCursor("from"),s=e.getCursor("to");if(this.featureSettings.expandToWholeLines){i={line:i.line,ch:0};let a=s.line,p=e.getLine(a);s={line:a,ch:p.length}}else if(!e.somethingSelected()){let o=this.getClosestPrefixCursorPos(e);if(o==null)return!1;i=o;let a=this.getClosestSuffixCursorPos(e);if(a==null)return!1;s=a}let r=e.getRange(i,s);return this.processSelection(n,e,r,i,s,t)}getClosestPrefixCursorPos(n){let e=D.reduce((i,s,r)=>r==0||s.length>i.length?s:i),t=n.posToOffset(n.getCursor("from"))+e.length;for(let i=t;i>=0;i--){let s=n.offsetToPos(i);for(let r of D){let o=i-r.length,a=n.offsetToPos(o);if(n.getRange(a,s)==r)return n.offsetToPos(o)}}return null}getClosestSuffixCursorPos(n){let e=D.reduce((r,o,a)=>a==0||o.length>r.length?o:r),t=n.posToOffset(n.getCursor("from"))-e.length+1,i=n.lastLine(),s=n.posToOffset({line:i,ch:n.getLine(i).length});for(let r=t;r<=s;r++){let o=n.offsetToPos(r);for(let a of N){let p=r+a.length,h=n.offsetToPos(p);if(n.getRange(o,h)==a)return h}}return null}processSelection(n,e,t,i,s,r,o=!0){var g;let a=new $(t);if(a.isEmpty)return n||new P.Notice("Nothing to Encrypt."),!1;if(!a.canDecrypt&&!a.canEncrypt)return n||new P.Notice("Unable to Encrypt or Decrypt that."),!1;if(a.canEncrypt&&!o)return!1;let p=this.plugin.app.workspace.getActiveFile();if(p==null)return!1;if(n)return!0;let h="",l=(g=a.decryptable)==null?void 0:g.hint;if(this.pluginSettings.rememberPassword){let w=u.getByPath(p.path);h=w.password,l=l!=null?l:w.hint}let c=a.canEncrypt&&this.pluginSettings.confirmPassword,d=new A(this.plugin.app,a.canEncrypt,c,this.featureSettings.showMarkerWhenReadingDefault,h,l);return d.onClose=async()=>{var re,oe,ae;if(!d.resultConfirmed)return;let w=(re=d.resultPassword)!=null?re:"",M=(oe=d.resultHint)!=null?oe:"";if(a.canEncrypt){let z=new te;z.text=t,z.hint=M,this.encryptSelection(e,z,w,i,s,(ae=d.resultShowInReadingView)!=null?ae:this.featureSettings.showMarkerWhenReadingDefault),u.putByPath({password:w,hint:M},p.path)}else a.decryptable&&await this.decryptSelection(e,a.decryptable,w,i,s,r)&&u.putByPath({password:w,hint:M},p.path)},d.open(),!0}async encryptSelection(n,e,t,i,s,r){let o=C.BuildDefault(),a=this.encodeEncryption(await o.encryptToBase64(e.text,t),e.hint,r);n.setSelection(i,s),n.replaceSelection(a)}async decryptSelection(n,e,t,i,s,r){let a=await C.BuildFromDecryptable(e).decryptFromBase64(e.base64CipherText,t);if(a===null)return new P.Notice("\u274C Decryption failed!"),!1;if(r)n.setSelection(i,s),n.replaceSelection(a);else{let p=new I(this.plugin.app,"\u{1F513}",a);p.onClose=()=>{n.focus(),p.decryptInPlace&&(n.setSelection(i,s),n.replaceSelection(a))},p.open()}return!0}encodeEncryption(n,e,t){if(!D.some(i=>n.contains(i))&&!N.some(i=>n.contains(i))){let i=t?Ce:ve,s=t?pe:de;return e.length>0?i.concat(x,e,x,n,s):i.concat(n,s)}return n}},$=class{constructor(n){this.process(n)}process(n){var e,t;if(this.processedText=n,this.isEmpty=n.length===0,this.prefix=(e=D.find(i=>n.startsWith(i)))!=null?e:"",this.suffix=(t=N.find(i=>n.endsWith(i)))!=null?t:"",this.hasEncryptedPrefix=this.prefix.length>0,this.hasEncryptedSuffix=this.suffix.length>0,this.hasObsoleteEncryptedPrefix=this.prefix===le,this.containsEncryptedMarkers=[...D,...N].some(i=>n.contains(i)),this.canDecrypt=this.hasEncryptedPrefix&&this.hasEncryptedSuffix,this.canEncrypt=!this.hasEncryptedPrefix&&!this.containsEncryptedMarkers,this.canDecrypt){let i=this.parseDecryptableContent(n);i!=null?this.decryptable=i:this.canDecrypt=!1}}parseDecryptableContent(n){let e=new X;if(!this.hasEncryptedPrefix||!this.hasEncryptedSuffix)return null;this.hasObsoleteEncryptedPrefix?e.version=0:this.prefix==ne||this.prefix==Y?e.version=2:(this.prefix==ce||this.prefix==ie)&&(e.version=1);let t=n.substring(this.prefix.length,n.length-this.suffix.length);if([...D,...N].some(i=>t.contains(i)))return null;if(t.substring(0,x.length)==x){let i=t.indexOf(x,x.length);if(i<0)return null;e.hint=t.substring(x.length,i),e.base64CipherText=t.substring(i+x.length)}else e.base64CipherText=t;return e}},te=class{},S=class{static extractTextBeforeMarker(n,e){return n.substring(0,e.position)}static extractTextAfterMarker(n,e){return n.substring(e.position+e.marker.length)}static removeMarkers(n,e,t){return n.substring(e.position,t.position+t.marker.length)}static extractTextLines(n,e,t){return n.split(` `).slice(e,t+1).join(` `)}static findFirstMarker(n,e,t=0){let i=null,s=null;return n.forEach(r=>{let o=e.indexOf(r,t);o!=-1&&(i==null||othis.actionToggleEditMode()),this.elActionReadingView=this.addAction(this.iconReadingView,"Reading",()=>this.actionToggleEditMode()),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")}actionToggleEditMode(){this.currentView==2&&(this.currentEditNoteMode=="Reading"?this.currentEditNoteMode="Source":this.currentEditNoteMode=="Source"&&(this.currentEditNoteMode="Reading"),this.refreshView(2))}actionLockFile(){this.encryptionPassword="",u.clearForPath(this.file.path),this.refreshView(1)}actionChangePassword(){this.refreshView(3)}onPaneMenu(e,t){t=="tab-header"&&this.currentView==2&&(e.addItem(i=>{i.setSection("action").setIcon(this.iconToggleEditView).setTitle("Toggle Editing/Reading").onClick(()=>this.actionToggleEditMode())}),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,t)}addHeader(e,t){var i;e.createDiv({text:`\u{1F510} ${t} \u{1F510}`,cls:"encrypted-note-message"}),V.showInlineTitle&&e.createDiv({text:(i=this.file)==null?void 0:i.basename,cls:"inline-title"})}validatePassword(e){return e.length==0?"Password is too short":""}validateConfirm(e,t){return e===t?"":"Password doesn't match"}addNewNoteView(e){this.addHeader(e,"This note will be encrypted");let t=this.addUserInputContainer(e);new m.Setting(t).setDesc("Please provide a password and hint to start editing this note.");let i=async(c,d,g)=>{let w=this.validatePassword(c),M=this.validateConfirm(c,d);p.setDesc(w),h.setDesc(M),w.length===0&&M.length===0&&(this.encryptionPassword=c,this.hint=g,V.showInlineTitle||(this.currentEditorSourceText=`# ${this.file.basename} `),await this.encodeAndSave(),u.putByPath({password:c,hint:g},this.file.path),this.currentEditNoteMode="Source",this.refreshView(2))},s=u.getByPath(this.file.path),r=s.password,o="",a=s.hint,p=b.buildPasswordSetting({container:t,name:"Password:",autoFocus:!0,initialValue:r,onChangeCallback:c=>{r=c,p.setDesc(this.validatePassword(r)),h.setDesc(this.validateConfirm(r,o))},onEnterCallback:c=>{var d;r=c,r.length>0&&((d=h.controlEl.querySelector("input"))==null||d.focus())}}),h=b.buildPasswordSetting({container:t,name:"Confirm:",autoFocus:!1,onChangeCallback:c=>{o=c,p.setDesc(this.validatePassword(r)),h.setDesc(this.validateConfirm(r,o))},onEnterCallback:c=>{var g;o=c,r===o&&((g=l.controlEl.querySelector("input"))==null||g.focus())}}),l=new m.Setting(t).setName("Hint:").addText(c=>{c.setValue(a),c.onChange(d=>{a=d})});l.controlEl.on("keydown","*",c=>{c.key==="Enter"&&(c.preventDefault(),i(r,o,a))}),new m.Setting(t).addButton(c=>{c.setCta().setIcon("go-to-file").setTooltip("Edit").onClick(d=>i(r,o,a))})}addDecryptNoteView(e){this.addHeader(e,"This note is encrypted");let t=this.addUserInputContainer(e);new m.Setting(t).setDesc("Please provide a password to unlock this note."),b.buildPasswordSetting({container:t,name:"Password:",autoFocus:!0,placeholder:this.formatHint(this.hint),onChangeCallback:s=>{this.encryptionPassword=s},onEnterCallback:async()=>await this.handleDecryptButtonClick()}),new m.Setting(t).addButton(s=>{s.setCta().setIcon("checkmark").setTooltip("Unlock & Edit").onClick(r=>this.handleDecryptButtonClick())});let i=u.getByPath(this.file.path);this.encryptionPassword=i.password,this.decryptWithPassword(i.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 L.encode(this.encryptionPassword,this.hint,this.currentEditorSourceText);this.data=O.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 t=e.createDiv({cls:"editor-source-view"});t.spellcheck=!0,t.autocapitalize="on",t.translate=!1,t.contentEditable="true",t.innerText=this.currentEditorSourceText,t.focus(),t.on("input","*",async(i,s)=>{this.currentEditorSourceText=t.innerText,await this.encodeAndSave()})}addEditorReadingView(e){this.elActionEditView.show(),this.elActionIconLockNote.show(),this.elActionChangePassword.show(),this.addHeader(e,"Reading an encrypted note");let t=e.createDiv({cls:"editor-reading-view"});m.MarkdownRenderer.renderMarkdown(this.currentEditorSourceText,t,this.file.path,this).catch(i=>{console.error(i)})}addUserInputContainer(e){return e.createDiv({cls:"input-container"})}addChangePasswordView(e){this.addHeader(e,"Change encrypted note password");let t=this.addUserInputContainer(e),i="",s="",r="",o=async(l,c,d)=>{let g=this.validatePassword(l),w=this.validateConfirm(l,c);a.setDesc(g),p.setDesc(w),g.length===0&&w.length===0&&(this.encryptionPassword=l,this.hint=d,this.encodeAndSave(),this.refreshView(2),u.putByPath({password:l,hint:d},this.file.path),new m.Notice("Password and Hint were changed"))},a=b.buildPasswordSetting({container:t,name:"New Password:",autoFocus:!0,onChangeCallback:l=>{i=l,a.setDesc(this.validatePassword(i)),p.setDesc(this.validateConfirm(i,s))},onEnterCallback:l=>{var c;i=l,i.length>0&&((c=p.controlEl.querySelector("input"))==null||c.focus())}}),p=b.buildPasswordSetting({container:t,name:"Confirm:",onChangeCallback:l=>{s=l,a.setDesc(this.validatePassword(i)),p.setDesc(this.validateConfirm(i,s))},onEnterCallback:l=>{var d;s=l,i===s&&((d=h.controlEl.querySelector("input"))==null||d.focus())}}),h=new m.Setting(t).setName("New Hint:").addText(l=>{l.onChange(c=>{r=c})});h.controlEl.on("keydown","*",l=>{l.key==="Enter"&&(l.preventDefault(),o(i,s,r))}),new m.Setting(t).addButton(l=>{l.removeCta().setIcon("cross").setTooltip("Cancel").onClick(()=>{this.refreshView(2)})}).addButton(l=>{l.setCta().setIcon("checkmark").setTooltip("Change Password").setWarning().onClick(c=>{o(i,s,r)})})}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(),V.readableLineLength?this.contentEl.classList.add("is-readable-line-width"):this.contentEl.classList.remove("is-readable-line-width");let t=this.contentEl.createDiv({cls:"content-container"});switch(this.currentView){case 4:this.addNewNoteView(t);break;case 1:this.addDecryptNoteView(t);break;case 2:this.currentEditNoteMode=="Source"?this.addEditorSourceView(t):this.addEditorReadingView(t);break;case 3:this.addChangePasswordView(t);break}}async decryptWithPassword(e){if(e.length==0)return null;let t=O.decode(this.data);return await L.decrypt(t,e)}async handleDecryptButtonClick(){let e=await this.decryptWithPassword(this.encryptionPassword);e===null?new m.Notice("Decryption failed"):(u.putByPath({password:this.encryptionPassword,hint:this.hint},this.file.path),this.currentEditorSourceText=e,this.refreshView(2))}canAcceptExtension(e){return e=="encrypted"}getViewType(){return K}setViewData(e,t){if(t){let i;e===""?i=4:i=1,this.encryptionPassword="";let s=O.decode(this.data);this.hint=s.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(){}},j=class{constructor(n,e,t){this.version="1.0";this.version=n,this.hint=e,this.encodedData=t}},se=class{static async encode(n,e,t){let s=await C.BuildDefault().encryptToBase64(t,n);return new j(se.DEFAULT_VERSION,e,s)}static async decrypt(n,e){return n.encodedData==""?"":await C.BuildFromFileData(n).decryptFromBase64(n.encodedData,e)}},L=se;L.DEFAULT_VERSION="2.0";var O=class{static encode(n){return JSON.stringify(n,null,2)}static decode(n){return n===""?new j(L.DEFAULT_VERSION,"",""):JSON.parse(n)}};var W=class{async onload(n,e){this.plugin=n,this.settings=e.featureWholeNoteEncrypt,this.updateUiForSettings(),this.plugin.registerView(K,t=>new q(t,this.settings)),this.plugin.registerExtensions(["encrypted"],K),this.plugin.addCommand({id:"meld-encrypt-create-new-note",name:"Create new encrypted note",icon:"lock",callback:()=>this.processCreateNewEncryptedNoteCommand()})}onunload(){this.plugin.app.workspace.detachLeavesOfType(K)}processCreateNewEncryptedNoteCommand(){try{let n=(0,v.moment)().format("[Untitled] YYYYMMDD hhmmss[.encrypted]"),e,t=this.plugin.app.workspace.getActiveFile();t!=null?e=this.plugin.app.fileManager.getNewFileParent(t.path):e=this.plugin.app.fileManager.getNewFileParent("");let i=(0,v.normalizePath)(e.path+"/"+n);return this.plugin.app.vault.create(i,"").then(async s=>{await this.plugin.app.workspace.getLeaf(!1).openFile(s)}).catch(s=>{new v.Notice(s,1e4)}),!0}catch(n){return console.error(n),new v.Notice(n,1e4),!1}}buildSettingsUi(n,e){new v.Setting(n).setHeading().setName("Whole Note Encryption Settings"),new v.Setting(n).setName("Add ribbon icon to create note").setDesc("Adds a ribbon icon to the left bar to create an encrypted note.").addToggle(t=>{t.setValue(this.settings.addRibbonIconToCreateNote).onChange(async i=>{this.settings.addRibbonIconToCreateNote=i,await e(),this.updateUiForSettings()})}),new v.Setting(n).setName("Default view for new tabs").setDesc("The default view that a new encrypted note tab gets opened in").addDropdown(t=>{var i;t.addOption(`${"Source"}`,"Source view").addOption(`${"Reading"}`,"Reading view").setValue(`${(i=this.settings.defaultView)!=null?i:"Source"}`).onChange(async s=>{this.settings.defaultView=s,await e()})})}updateUiForSettings(){this.settings.addRibbonIconToCreateNote?this.ribbonIconCreateNewNote==null&&(this.ribbonIconCreateNewNote=this.plugin.addRibbonIcon("lock","Create new encrypted note",n=>{this.processCreateNewEncryptedNoteCommand()})):this.ribbonIconCreateNewNote!=null&&(this.ribbonIconCreateNewNote.remove(),this.ribbonIconCreateNewNote=null)}};var J=class extends ue.Plugin{constructor(){super(...arguments);this.enabledFeatures=[]}async onload(){await this.loadSettings(),this.enabledFeatures.push(new W,new U),this.addSettingTab(new B(this.app,this,this.settings,this.enabledFeatures)),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:u.LevelFullPath,featureWholeNoteEncrypt:{addRibbonIconToCreateNote:!0,defaultView:"Source".toString()},featureInplaceEncrypt:{expandToWholeLines:!1,showMarkerWhenReadingDefault:!0}};this.settings=Object.assign(e,await this.loadData()),u.setActive(this.settings.rememberPassword),u.setAutoExpire(this.settings.rememberPasswordTimeout==0?null:this.settings.rememberPasswordTimeout),u.setLevel(this.settings.rememberPasswordLevel)}async saveSettings(){await this.saveData(this.settings)}};