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.

12 lines
29 KiB

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
3 years ago
2 years ago
var z=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var ue=(w,t)=>{for(var e in t)z(w,e,{get:t[e],enumerable:!0})},he=(w,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of de(t))!pe.call(w,i)&&i!==e&&z(w,i,{get:()=>t[i],enumerable:!(n=le(t,i))||n.enumerable});return w};var ge=w=>he(z({},"__esModule",{value:!0}),w);var Ee={};ue(Ee,{default:()=>q});module.exports=ge(Ee);var ce=require("obsidian");var T=require("obsidian");var W=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 f=class{static setActive(t){f.isActive=t,f.isActive||this.clear()}static setAutoExpire(t){f.baseMinutesToExpire=t!=null?t:0,f.updateExpiryTime()}static setLevel(t){f.level!=t&&(f.level=t,this.clear())}static updateExpiryTime(){f.baseMinutesToExpire==0||f.baseMinutesToExpire==null?f.expiryTime=null:f.expiryTime=Date.now()+f.baseMinutesToExpire*1e3*60}static putByPath(t,e){if(!f.isActive)return;let n=f.getPathCacheKey(e);this.cache.put(n,t),f.updateExpiryTime()}static getByPath(t){if(!f.isActive)return f.blankPasswordAndHint;this.clearIfExpired(),f.updateExpiryTime();let e=f.getPathCacheKey(t);return this.cache.get(e,f.blankPasswordAndHint)}static getPathCacheKey(t){let e=t.split("/").slice(0,-1).join("/");switch(f.level){case f.LevelParentPath:return e;default:return t}}static clearIfExpired(){f.expiryTime!=null&&(Date.now()<f.expiryTime||this.clear())}static clearForPath(t){let e=f.getPathCacheKey(t);this.cache.removeKey(e)}static clear(){this.cache.clear()}},h=f;h.isActive=!0,h.blankPasswordAndHint={password:"",hint:""},h.cache=new W,h.baseMinutesToExpire=0,h.expiryTime=null,h.LevelFullPath="fullPath",h.LevelParentPath="parentPath",h.level=f.LevelFullPath;var L=class extends T.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"}),new T.Setting(e).setHeading().setName("Common Settings"),new T.Setting(e).setName("Confirm password?").setDesc("Confirm password when encrypting.").addToggle(r=>{r.setValue(this.settings.confirmPassword).onChange(async o=>{this.settings.confirmPassword=o,await this.plugin.saveSettings()})});let n=()=>{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(),h.setActive(this.settings.rememberPassword),n()})});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(),h.setAutoExpire(this.settings.rememberPasswordTimeout),n()})}),s=new T.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(async o=>{this.settings.rememberPasswordLevel=o,await this.plugin.saveSettings(),h.setLevel(this.settings.rememberPasswordLevel),n()})});n(),this.features.forEach(r=>{r.buildSettingsUi(e,async()=>await this.plugin.saveSettings())})}};var v=require("obsidian");var j=new TextEncoder,fe=new TextDecoder,we=1e3,ye=j.encode("XHWnDAT6ehMVY2zD"),C=class{async deriveKey(t){let e=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(