varz=Object.defineProperty;varle=Object.getOwnPropertyDescriptor;varde=Object.getOwnPropertyNames;varpe=Object.prototype.hasOwnProperty;varue=(w,t)=>{for(vareint)z(w,e,{get:t[e],enumerable:!0})},he=(w,t,e,n)=>{if(t&&typeoft=="object"||typeoft=="function")for(letiofde(t))!pe.call(w,i)&&i!==e&&z(w,i,{get:()=>t[i],enumerable:!(n=le(t,i))||n.enumerable});returnw};varge=w=>he(z({},"__esModule",{value:!0}),w);varEe={};ue(Ee,{default:()=>q});module.exports=ge(Ee);varce=require("obsidian");varT=require("obsidian");varW=class{constructor(){this.values=newMap}put(t,e){this.values.set(t,e)}get(t,e){varn;return(n=this.values.get(t))!=null?n:e}getFirst(t,e){for(letn=0;n<t.length;n++){leti=t[n];if(this.containsKey(i))returnthis.get(i,e)}returne}containsKey(t){returnthis.values.has(t)}getKeys(){returnArray.from(this.values.keys())}removeKey(t){returnthis.values.delete(t)}clear(){this.values.clear()}};varf=class{staticsetActive(t){f.isActive=t,f.isActive||this.clear()}staticsetAutoExpire(t){f.baseMinutesToExpire=t!=null?t:0,f.updateExpiryTime()}staticsetLevel(t){f.level!=t&&(f.level=t,this.clear())}staticupdateExpiryTime(){f.baseMinutesToExpire==0||f.baseMinutesToExpire==null?f.expiryTime=null:f.expiryTime=Date.now()+f.baseMinutesToExpire*1e3*60}staticputByPath(t,e){if(!f.isActive)return;letn=f.getPathCacheKey(e);this.cache.put(n,t),f.updateExpiryTime()}staticgetByPath(t){if(!f.isActive)returnf.blankPasswordAndHint;this.clearIfExpired(),f.updateExpiryTime();lete=f.getPathCacheKey(t);returnthis.cache.get(e,f.blankPasswordAndHint)}staticgetPathCacheKey(t){lete=t.split("/").slice(0,-1).join("/");switch(f.level){casef.LevelParentPath:returne;default:returnt}}staticclearIfExpired(){f.expiryTime!=null&&(Date.now()<f.expiryTime||this.clear())}staticclearForPath(t){lete=f.getPathCacheKey(t);this.cache.removeKey(e)}staticclear(){this.cache.clear()}},h=f;h.isActive=!0,h.blankPasswordAndHint={password:"",hint:""},h.cache=newW,h.baseMinutesToExpire=0,h.expiryTime=null,h.LevelFullPath="fullPath",h.LevelParentPath="parentPath",h.level=f.LevelFullPath;varL=classextendsT.PluginSettingTab{constructor(e,n,i,s){super(e,n);this.plugin=n,this.settings=i,this.features=s}display(){let{containerEl:e}=this;e.empty(),e.createEl("h1",{text:"Settings for Meld Encrypt"}),newT.Setting(e).setHeading().setName("Common Settings"),newT.Setting(e).setName("Confirm password?").setDesc("Confirm password when encrypting.").addToggle(r=>{r.setValue(this.settings.confirmPassword).onChange(asynco=>{this.settings.confirmPassword=o,awaitthis.plugin.saveSettings()})});letn=()=>{if(!this.settings.rememberPassword){i.settingEl.hide(),s.settingEl.hide();return}i.settingEl.show(),s.settingEl.show();letr=this.settings.rememberPasswordTimeout,o=`For ${r} minutes`;r==0&&(o="Always"),i.setName(`Remember Password (${o})`)};newT.Setting(e).setName("Remember password?").setDesc("Remember the last used passwords when encrypting or decrypting.").addToggle(r=>{r.setValue(this.settings.rememberPassword).onChange(asynco=>{this.settings.rememberPassword=o,awaitthis.plugin.saveSettings(),h.setActive(this.settings.rememberPassword),n()})});leti=newT.Setting(e).setDesc("The number of minutes to remember passwords.").addSlider(r=>{r.setLimits(0,120,5).setValue(this.settings.rememberPasswordTimeout).onChange(asynco=>{this.settings.rememberPasswordTimeout=o,awaitthis.plugin.saveSettings(),h.setAutoExpire(this.settings.rememberPasswordTimeout),n()})}),s=newT.Setting(e).setDesc("Remember passwords by using").addDropdown(r=>{r.addOption(h.LevelFullPath,"Full Path").addOption(h.LevelParentPath,"Parent Path").setValue(this.settings.rememberPasswordLevel).onChange(asynco=>{this.settings.rememberPasswordLevel=o,awaitthis.plugin.saveSettings(),h.setLevel(this.settings.rememberPasswordLevel),n()})});n(),this.features.forEach(r=>{r.buildSettingsUi(e,async()=>awaitthis.plugin.saveSettings())})}};varv=require("obsidian");varj=newTextEncoder,fe=newTextDecoder,we=1e3,ye=j.encode("XHWnDAT6ehMVY2zD"),C=class{asyncderiveKey(t){lete=j.encode(t),
`).slice(e,n+1).join(`
`)}static findFirstMarker(t,e,n=0){let i=null,s=null;return t.forEach(r=>{let o=e.indexOf(r,n);o!=-1&&(i==null||o<i)&&(i=o,s=r)}),s==null||i==null?null:{marker:s,position:i}}};var b=require("obsidian");var m=require("obsidian");var V=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 O="meld-encrypted-file-content-view",Y=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.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="",h.clearForPath(this.file.path),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.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,n)}addHeader(e,n){var i;e.createDiv({text:`\u{1F510}${n}\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,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,c,g)=>{let y=this.validatePassword(d),N=this.validateConfirm(d,c);p.setDesc(y),u.setDesc(N),y.length===0&&N.length===0&&(this.encryptionPassword=d,this.hint=g,V.showInlineTitle||(this.currentEditorSourceText=`#${this.file.basename}
`),await this.encodeAndSave(),h.putByPath({password:d,hint:g},this.file.path),this.currentEditNoteMode="Source",this.refreshView(2))},s=h.getByPath(this.file.path),r=s.password,o="",a=s.hint,p=P.buildPasswordSetting({container:n,name:"Password:",autoFocus:!0,initialValue:r,onChangeCallback:d=>{r=d,p.setDesc(this.validatePassword(r)),u.setDesc(this.validateConfirm(r,o))},onEnterCallback:d=>{var c;r=d,r.length>0&&((c=u.controlEl.querySelector("input"))==null||c.focus())}}),u=P.buildPasswordSetting({container:n,name:"Confirm:",autoFocus:!1,onChangeCallback:d=>{o=d,p.setDesc(this.validatePassword(r)),u.setDesc(this.validateConfirm(r,o))},onEnterCallback:d=>{var g;o=d,r===o&&((g=l.controlEl.querySelector("input"))==null||g.focus())}}),l=new m.Setting(n).setName("Hint:").addText(d=>{d.setValue(a),d.onChange(c=>{a=c})});l.controlEl.on("keydown","*",d=>{d.key==="Enter"&&(d.preventDefault(),i(r,o,a))}),new m.Setting(n).addButton(d=>{d.setCta().setIcon("go-to-file").setTooltip("Edit").onClick(c=>i(r,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."),P.buildPasswordSetting({container:n,name:"Password:",autoFocus:!0,placeholder:this.formatHint(this.hint),onChangeCallback:s=>{this.encryptionPassword=s},onEnterCallback:async()=>await this.handleDecryptButtonClick()}),new m.Setting(n).addButton(s=>{s.setCta().setIcon("checkmark").setTooltip("Unlock & Edit").onClick(r=>this.handleDecryptButtonClick())});let i=h.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 X.encode(this.encryptionPassword,this.hint,this.currentEditorSourceText);this.data=R.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"});n.spellcheck=!0,n.autocapitalize="on",n.translate=!1,n.contentEditable="true",n.innerText=this.currentEditorSourceText,n.focus(),n.on("input","*",async(i,s)=>{console.debug({container:n}),this.currentEditorSourceText=n.innerText,await this.encodeAndSave()})}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)})}addUserInputContainer(e){return e.createDiv({cls:"input-container"})}addChangePasswordView(e){this.addHeader(e,"Change encrypted note password");let n=this.addUserInputContainer(e),i="",s="",r="",o=async(l,d,c)=>{let g=this.validatePassword(l),y=this.validateConfirm(l,d);a.setDesc(g),p.setDesc(y),g.length===0&&y.length===0&&(this.encryptionPassword=l,this.hint=c,this.encodeAndSave(),this.refreshView(2),h.putByPath({password:l,hint:c},this.file.path),new m.Notice("Password and Hint were changed"))},a=P.buildPasswordSetting({container:n,name:"New Password:",autoFocus:!0,onChangeCallback:l=>{i=l,a.setDesc(this.validatePassword(i)),p.setDesc(this.validateConfirm(i,s))},onEnterCallback:l=>{var d;i=l,i.length>0&&((d=p.controlEl.querySelector("input"))==null||d.focus())}}),p=P.buildPasswordSetting({container:n,name:"Confirm:",onChangeCallback:l=>{s=l,a.setDesc(this.validatePassword(i)),p.setDesc(this.validateConfirm(i,s))},onEnterCallback:l=>{var c;s=l,i===s&&((c=u.controlEl.querySelector("input"))==null||c.focus())}}),u=new m.Setting(n).setName("New Hint:").addText(l=>{l.onChange(d=>{r=d})});u.controlEl.on("keydown","*",l=>{l.key==="Enter"&&(l.preventDefault(),o(i,s,r))}),new m.Setting(n).addButton(l=>{l.removeCta().setIcon("cross").setTooltip("Cancel").onClick(()=>{this.refreshView(2)})}).addButton(