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
37 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
var oe=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Ce=Object.getOwnPropertyNames;var Te=Object.prototype.hasOwnProperty;var Fe=(w,t)=>{for(var e in t)oe(w,e,{get:t[e],enumerable:!0})},xe=(w,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ce(t))!Te.call(w,i)&&i!==e&&oe(w,i,{get:()=>t[i],enumerable:!(n=ve(t,i))||n.enumerable});return w};var Se=w=>xe(oe({},"__esModule",{value:!0}),w);var Me={};Fe(Me,{default:()=>re});module.exports=Se(Me);var be=require("obsidian");var A=require("obsidian");var Z=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 ae=require("obsidian"),B=class{static getFilePathWithNewExtension(t,e){return(0,ae.normalizePath)(t.parent.path+"/"+t.basename+"."+e)}static getFilePathExcludingExtension(t){return(0,ae.normalizePath)(t.parent.path+"/"+t.basename)}};var u=class{static setActive(t){u.isActive=t,u.isActive||this.clear()}static setAutoExpire(t){u.baseMinutesToExpire=t!=null?t:0,u.updateExpiryTime()}static setLevel(t){u.level!=t&&(u.allLevels.contains(t)&&(u.level=t),u.level=u.LevelFilename,this.clear())}static updateExpiryTime(){u.baseMinutesToExpire==0||u.baseMinutesToExpire==null?u.expiryTime=null:u.expiryTime=Date.now()+u.baseMinutesToExpire*1e3*60}static putByFile(t,e){if(!u.isActive)return;let n=u.getFileCacheKey(e);this.cache.put(n,t),u.updateExpiryTime()}static getByFile(t){if(!u.isActive)return u.blankPasswordAndHint;this.clearIfExpired(),u.updateExpiryTime();let e=u.getFileCacheKey(t);return this.cache.get(e,u.blankPasswordAndHint)}static putByPath(t,e){if(!u.isActive)return;let n=u.getPathCacheKey(e);this.cache.put(n,t),u.updateExpiryTime()}static getByPath(t){if(!u.isActive)return u.blankPasswordAndHint;this.clearIfExpired(),u.updateExpiryTime();let e=u.getPathCacheKey(t);return this.cache.get(e,u.blankPasswordAndHint)}static getPathCacheKey(t){let e=t.split("/").slice(0,-1).join("/");switch(u.level){case u.LevelParentPath:return e;default:return t}}static getFileCacheKey(t){switch(u.level){case u.LevelParentPath:return t.parent.path;default:return B.getFilePathExcludingExtension(t)}}static clearIfExpired(){u.expiryTime!=null&&(Date.now()<u.expiryTime||this.clear())}static clearForFile(t){let e=u.getFileCacheKey(t);this.cache.removeKey(e)}static clearForPath(t){let e=u.getPathCacheKey(t);this.cache.removeKey(e)}static clear(){this.cache.clear()}},g=u;g.isActive=!0,g.blankPasswordAndHint={password:"",hint:""},g.cache=new Z,g.baseMinutesToExpire=0,g.expiryTime=null,g.LevelFilename="filename",g.LevelParentPath="parentPath",g.allLevels=[u.LevelFilename,u.LevelParentPath],g.level=u.LevelFilename;var W=class extends A.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 A.Setting(e).setHeading().setName("Common Settings"),new A.Setting(e).setName("Confirm password?").setDesc("Confirm password when encrypting. (Recommended)").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="Until Obsidian is closed"),i.setName(`Remember Password (${o})`)};new A.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(r=>{r.setValue(this.settings.rememberPassword).onChange(async o=>{this.settings.rememberPassword=o,await this.plugin.saveSettings(),g.setActive(this.sett
`).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 D=require("obsidian");var y=require("obsidian");var K=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}},fe=class{static async encode(t,e,n){let s=await C.BuildDefault().encryptToBase64(n,t);return new ie(fe.DEFAULT_VERSION,e,s)}static async decrypt(t,e){return t.encodedData==""?"":await C.BuildFromFileDataOrThrow(t).decryptFromBase64(t.encodedData,e)}},S=fe;S.DEFAULT_VERSION="2.0";var I=class{static encode(t){return JSON.stringify(t,null,2)}static decode(t){return t===""?new ie(S.DEFAULT_VERSION,"",""):JSON.parse(t)}};var k="encrypted";var q="meld-encrypted-file-content-view",se=class extends y.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="",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.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"}),K.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 y.Setting(n).setDesc("Please provide a password and hint to start editing this note.");let i=async(l,c,p)=>{let m=this.validatePassword(l),V=this.validateConfirm(l,c);h.setDesc(m),f.setDesc(V),m.length===0&&V.length===0&&(this.encryptionPassword=l,this.hint=p,K.showInlineTitle||(this.currentEditorSourceText=`# ${this.file.basename}
2 years ago
`),await this.encodeAndSave(),g.putByFile({password:l,hint:p},this.file),this.currentEditNoteMode="Source",this.refreshView(2))},s=g.getByFile(this.file),r=s.password,o="",a=s.hint,h=E.buildPasswordSetting({container:n,name:"Password:",autoFocus:!0,initialValue:r,onChangeCallback:l=>{r=l,h.setDesc(this.validatePassword(r)),f.setDesc(this.validateConfirm(r,o))},onEnterCallback:l=>{var c;r=l,r.length>0&&((c=f.controlEl.querySelector("input"))==null||c.focus())}}),f=E.buildPasswordSetting({container:n,name:"Confirm:",autoFocus:!1,onChangeCallback:l=>{o=l,h.setDesc(this.validatePassword(r)),f.setDesc(this.validateConfirm(r,o))},onEnterCallback:l=>{var p;o=l,r===o&&((p=d.controlEl.querySelector("input"))==null||p.focus())}}),d=new y.Setting(n).setName("Hint:").addText(l=>{l.setValue(a),l.onChange(c=>{a=c})});d.controlEl.on("keydown","*",l=>{l.key==="Enter"&&(l.preventDefault(),i(r,o,a))}),new y.Setting(n).addButton(l=>{l.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 y.Setting(n).setDesc("Please provide a password to unlock this note.");let i=E.buildPasswordSetting({container:n,name:"Password:",autoFocus:!0,placeholder:this.formatHint(this.hint),onChangeCallback:r=>{this.encryptionPassword=r,i.setDesc(this.validatePassword(this.encryptionPassword))},onEnterCallback:async()=>await this.handleDecryptButtonClick()});new y.Setting(n).addButton(r=>{r.setCta().setIcon("checkmark").setTooltip("Unlock & Edit").onClick(o=>this.handleDecryptButtonClick())});let s=g.getByFile(this.file);this.encryptionPassword=s.password,s.password.length>0&&this.decryptWithPassword(s.password).then(r=>{r!=null&&(this.currentEditorSourceText=r,this.refreshView(2),new y.Notice("Decrypted using remembered password",2e3))})}async encodeAndSave(){try{let e=await S.encode(this.encryptionPassword,this.hint,this.currentEditorSourceText);this.data=I.encode(e),this.requestSave()}catch(e){console.error(e),new y.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="plaintext-only",n.innerText=this.currentEditorSourceText,n.focus(),n.on("input","*",async(i,s)=>{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"});y.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(d,l,c)=>{let p=this.validatePassword(d),m=this.validateConfirm(d,l);a.setDesc(p),h.setDesc(m),p.length===0&&m.length===0&&(this.encryptionPassword=d,this.hint=c,this.encodeAndSave(),this.refreshView(2),g.putByFile({password:d,hint:c},this.file),new y.Notice("Password and Hint were changed"))},a=E.buildPasswordSetting({container:n,name:"New Password:",autoFocus:!0,onChangeCallback:d=>{i=d,a.setDesc(this.validatePassword(i)),h.setDesc(this.validateConfirm(i,s))},onEnterCallback:d=>{var l;i=d,i.length>0&&((l=h.controlEl.querySelector("input"))==null||l.focus())}}),h=E.buildPasswordSetting({container:n,name:"Confirm:",onChangeCallback:d=>{s=d,a.setDesc(this.validatePassword(i)),h.setDesc(this.validateConfirm(i,s))},onEnterCallback:d=>{var c;s=d,i===s&&((c=f.controlEl.querySelector("input"))==null||c.focus())}}),f=new y.Setting(n).setName("New Hint:").addText(d=>{d.onChange(l=>{r=l})});f.controlEl.on("keydown","*",d=>{d.key==="Enter"&&(d.preventDefault(),o(i,s,r))}),new y.Setting(n).addButton(d=>{d.removeCta().setIcon("cross").setTooltip("Cancel").o