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.
7 lines
23 KiB
7 lines
23 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 X=Object.defineProperty;var it=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var at=(h,e)=>{for(var t in e)X(h,t,{get:e[t],enumerable:!0})},ct=(h,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of rt(e))!ot.call(h,s)&&s!==t&&X(h,s,{get:()=>e[s],enumerable:!(n=it(e,s))||n.enumerable});return h};var lt=h=>ct(X({},"__esModule",{value:!0}),h);var ft={};at(ft,{default:()=>G});module.exports=lt(ft);var st=require("obsidian");var S=require("obsidian");var O=class{constructor(){this.values=new Map}put(e,t){this.values.set(e,t)}get(e,t){var n;return(n=this.values.get(e))!=null?n:t}getFirst(e,t){for(let n=0;n<e.length;n++){let s=e[n];if(this.containsKey(s))return this.get(s,t)}return t}containsKey(e){return this.values.has(e)}getKeys(){return Array.from(this.values.keys())}clear(){this.values.clear()}};var g=class{static setActive(e){g.isActive=e,g.isActive||this.clear()}static setAutoExpire(e){g.baseMinutesToExpire=e!=null?e:0,g.updateExpiryTime()}static updateExpiryTime(){g.baseMinutesToExpire==0||g.baseMinutesToExpire==null?g.expiryTime=null:g.expiryTime=Date.now()+g.baseMinutesToExpire*1e3*60}static put(e,t){!g.isActive||(this.cache.put(t.path,e),this.cache.put(t.parent.path,e),this.cache.put(t.basename,e),g.updateExpiryTime())}static getExact(e){return g.isActive?(this.clearIfExpired(),g.updateExpiryTime(),this.cache.get(e.path,g.blankPasswordAndHint)):g.blankPasswordAndHint}static getBestGuess(e){return g.isActive?(this.clearIfExpired(),g.updateExpiryTime(),this.cache.getFirst([e.path,e.parent.path,e.basename],g.blankPasswordAndHint)):g.blankPasswordAndHint}static clearIfExpired(){g.expiryTime!=null&&(Date.now()<g.expiryTime||this.clear())}static clear(){this.cache.clear()}},f=g;f.isActive=!0,f.blankPasswordAndHint={password:"",hint:""},f.cache=new O,f.baseMinutesToExpire=0,f.expiryTime=null;var N=class extends S.PluginSettingTab{constructor(t,n,s,i){super(t,n);this.plugin=n,this.settings=s,this.features=i}display(){let{containerEl:t}=this;t.empty(),t.createEl("h1",{text:"Settings for Meld Encrypt"}),new S.Setting(t).setHeading().setName("Common Settings"),new S.Setting(t).setName("Confirm password?").setDesc("Confirm password when encrypting.").addToggle(i=>{i.setValue(this.settings.confirmPassword).onChange(async r=>{this.settings.confirmPassword=r,await this.plugin.saveSettings()})});let n=()=>{if(!this.settings.rememberPassword){s.settingEl.hide();return}s.settingEl.show();let i=this.settings.rememberPasswordTimeout,r=`${i} minutes`;i==0&&(r="Never forget"),s.setName(`Remember Password Timeout (${r})`)};new S.Setting(t).setName("Remember password?").setDesc("Remember the last used passwords when encrypting or decrypting.").addToggle(i=>{i.setValue(this.settings.rememberPassword).onChange(async r=>{this.settings.rememberPassword=r,await this.plugin.saveSettings(),f.setActive(this.settings.rememberPassword),n()})});let s=new S.Setting(t).setDesc("The number of minutes to remember passwords.").addSlider(i=>{i.setLimits(0,120,5).setValue(this.settings.rememberPasswordTimeout).onChange(async r=>{this.settings.rememberPasswordTimeout=r,await this.plugin.saveSettings(),f.setAutoExpire(this.settings.rememberPasswordTimeout),n()})});n(),this.features.forEach(i=>{i.buildSettingsUi(t,async()=>await this.plugin.saveSettings())})}};var v=require("obsidian");var q=new TextEncoder,pt=new TextDecoder,dt=1e3,ut=q.encode("XHWnDAT6ehMVY2zD"),C=class{async deriveKey(e){let t=q.encode(e),n=await crypto.subtle.importKey("raw",t,{name:"PBKDF2"},!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",hash:{name:"SHA-256"},iterations:dt,salt:ut},n,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}async encryptToBytes(e,t){let n=await this.deriveKey(t),s=q.encode(e),i=crypto.getRandomValues(new Uint8Array(16)),r=new Uint8Array(await crypto.subtle.encrypt({name:"AES-GCM",iv:i},n,s)),o=new Uint8Array(i.byteLength+r.byteLength);return o.set(i,0),o.set(r,i.byteLength),o}convertToString(e){let t="";for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return t}async encryptToBase64(e,t){let n=await this.encryptToBytes(e,t);return btoa(this.convertToString(n))}stringToArray(e){let t=[];for(let n=0;n<e.length;n++)t.push(e.charCodeAt(n));return new Uint8Array(t)}async decryptFromBytes(e,t){try{let n=e.slice(0,16),s=e.slice(16),i=await this.deriveKey(t),r=await crypto.subtle.decrypt({name:"AES-GCM",iv:n},i,s);return pt.decode(r)}catch(n){return null}}async decryptFromBase64(e,t){try{let n=this.stringToArray(atob(e));return await this.decryptFromBytes(n,t)}catch(n){return null}}};var z={name:"AES-GCM",iv:new Uint8Array([196,190,240,190,188,78,41,132,15,220,84,211]),tagLength:128},U=class{async buildKey(e){let n=new TextEncoder().encode(e),s=await crypto.subtle.digest({name:"SHA-256"},n);return await crypto.subtle.importKey("raw",s,z,!1,["encrypt","decrypt"])}async encryptToBase64(e,t){let n=await this.buildKey(t),i=new TextEncoder().encode(e),r=new Uint8Array(await crypto.subtle.encrypt(z,n,i));return btoa(String.fromCharCode(...r))}stringToArray(e){let t=[];for(let n=0;n<e.length;n++)t.push(e.charCodeAt(n));return new Uint8Array(t)}async decryptFromBase64(e,t){try{let n=this.stringToArray(atob(e)),s=await this.buildKey(t),i=await crypto.subtle.decrypt(z,s,n);return new TextDecoder().decode(i)}catch(n){return null}}};var I=require("obsidian"),D=class extends I.Modal{constructor(t,n,s=""){super(t);this.decryptInPlace=!1;this.titleEl.setText(n),this.text=s}onOpen(){var r;let{contentEl:t}=this,n;(r=new I.Setting(t).addTextArea(o=>{n=o,o.setValue(this.text),o.inputEl.setSelectionRange(0,0),o.inputEl.readOnly=!0,o.inputEl.rows=10,o.inputEl.style.width="100%",o.inputEl.style.minHeight="3em",o.inputEl.style.resize="vertical"}).settingEl.querySelector(".setting-item-info"))==null||r.remove(),new I.Setting(t).addButton(o=>{o.setButtonText("Copy").onClick(c=>{navigator.clipboard.writeText(n.getValue()),new I.Notice("Copied!")})}).addButton(o=>{o.setWarning().setButtonText("Decrypt in-place").onClick(c=>{this.decryptInPlace=!0,this.close()})})}};var w=require("obsidian");var k=require("obsidian"),m=class{static isSettingsModalOpen(){return document.querySelector(".mod-settings")!==null}static buildPasswordSetting({container:e,name:t,desc:n="",autoFocus:s=!1,placeholder:i="",initialValue:r="",onChangeCallback:o,onEnterCallback:c}){let d=new k.Setting(e).setName(t).setDesc(n).addButton(l=>{l.setIcon("reading-glasses").onClick(a=>{let p=d.components.find((u,P,E)=>u instanceof k.TextComponent);p instanceof k.TextComponent&&(p.inputEl.type=p.inputEl.type=="password"?"text":"password")})}).addText(l=>{l.setPlaceholder(i),l.setValue(r),l.inputEl.type="password",o!=null&&l.onChange(o),c!=null&&(l.inputEl.onkeydown=a=>{a.key==="Enter"&&(a.preventDefault(),c(l.getValue()))}),s&&setTimeout(()=>l.inputEl.focus(),0)});return d}};var A=class extends w.Modal{constructor(t,n,s,i=null,r=null){super(t);this.defaultPassword=null;this.defaultHint=null;this.resultConfirmed=!1;this.resultPassword=null;this.resultHint=null;this.defaultPassword=i,this.confirmPassword=s,this.isEncrypting=n,this.defaultHint=r}onOpen(){var d,l;let{contentEl:t}=this;t.empty(),this.invalidate();let n=(d=this.defaultPassword)!=null?d:"",s="",i=(l=this.defaultHint)!=null?l:"";new w.Setting(t).setHeading().setName(this.isEncrypting?"Encrypting":"Decrypting"),m.buildPasswordSetting({container:t,name:"Password:",placeholder:this.isEncrypting?"":`Hint: ${this.defaultHint}`,initialValue:n,autoFocus:!0,onChangeCallback:a=>{n=a,this.invalidate()},onEnterCallback:a=>{if(n=a,this.invalidate(),n.length>0)if(r.settingEl.isShown()){let p=r.components.find(u=>u instanceof w.TextComponent);p instanceof w.TextComponent&&p.inputEl.focus()}else if(o.settingEl.isShown()){let p=o.components.find(u=>u instanceof w.TextComponent);p instanceof w.TextComponent&&p.inputEl.focus()}else c()&&this.close()}});let r=m.buildPasswordSetting({container:t,name:"Confirm Password:",onChangeCallback:a=>{s=a,this.invalidate()},onEnterCallback:a=>{if(s=a,this.invalidate(),s.length>0&&c()&&o.settingEl.isShown()){let p=o.components.find(u=>u instanceof w.TextComponent);p instanceof w.TextComponent&&p.inputEl.focus()}}});this.confirmPassword||r.settingEl.hide();let o=new w.Setting(t).setName("Optional Password Hint").addText(a=>{a.inputEl.placeholder="Password Hint",a.setValue(i),a.onChange(p=>i=p),a.inputEl.on("keypress","*",(p,u)=>{p.key=="Enter"&&u instanceof HTMLInputElement&&u.value.length>0&&(p.preventDefault(),c()&&this.close())})});this.isEncrypting||o.settingEl.hide(),new w.Setting(t).addButton(a=>{a.setButtonText("Confirm").onClick(p=>{c()&&this.close()})});let c=()=>(this.invalidate(),r.setDesc(""),this.confirmPassword&&n!=s?(r.setDesc("Passwords don't match"),!1):(this.resultConfirmed=!0,this.resultPassword=n,this.resultHint=i,!0))}invalidate(){this.resultConfirmed=!1,this.resultPassword=null,this.resultHint=null}};var _="%%\u{1F510}\u03B1 ",ht="\u{1F510}\u03B1 ",nt="%%\u{1F510} ",M=[_,ht,nt],$=" \u{1F510}%%",gt=" \u{1F510}",F=[$,gt],T="\u{1F4A1}",H=class{async onload(e,t){this.plugin=e,this.pluginSettings=t,this.featureSettings=t.featureInplaceEncrypt,e.addCommand({id:"meld-encrypt",name:"Encrypt/Decrypt",icon:"lock",editorCheckCallback:(n,s,i)=>this.processEncryptDecryptCommand(n,s,!1)}),e.addCommand({id:"meld-encrypt-in-place",name:"Encrypt/Decrypt In-place",icon:"lock",editorCheckCallback:(n,s,i)=>this.processEncryptDecryptCommand(n,s,!0)})}onunload(){}buildSettingsUi(e,t){new v.Setting(e).setHeading().setName("In-place Encryption Settings"),new v.Setting(e).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 s=>{this.featureSettings.expandToWholeLines=s,await t()})})}processEncryptDecryptCommand(e,t,n){if(e&&m.isSettingsModalOpen())return!0;let s=t.getCursor("from"),i=t.getCursor("to");if(this.featureSettings.expandToWholeLines){s={line:s.line,ch:0};let c=i.line,d=t.getLine(c);i={line:c,ch:d.length}}else if(!t.somethingSelected()){let o=this.getClosestPrefixCursorPos(t);if(o==null)return!1;s=o;let c=this.getClosestSuffixCursorPos(t);if(c==null)return!1;i=c}let r=t.getRange(s,i);return this.processSelection(e,t,r,s,i,n)}getClosestPrefixCursorPos(e){let t=M.reduce((s,i,r)=>r==0||i.length>s.length?i:s),n=e.posToOffset(e.getCursor("from"))+t.length;for(let s=n;s>=0;s--){let i=e.offsetToPos(s);for(let r of M){let o=s-r.length,c=e.offsetToPos(o);if(e.getRange(c,i)==r)return e.offsetToPos(o)}}return null}getClosestSuffixCursorPos(e){let t=M.reduce((r,o,c)=>c==0||o.length>r.length?o:r),n=e.posToOffset(e.getCursor("from"))-t.length+1,s=e.lastLine(),i=e.posToOffset({line:s,ch:e.getLine(s).length});for(let r=n;r<=i;r++){let o=e.offsetToPos(r);for(let c of F){let d=r+c.length,l=e.offsetToPos(d);if(e.getRange(o,l)==c)return l}}return null}processSelection(e,t,n,s,i,r,o=!0){var P;let c=new j(n);if(c.isEmpty)return e||new v.Notice("Nothing to Encrypt."),!1;if(!c.canDecrypt&&!c.canEncrypt)return e||new v.Notice("Unable to Encrypt or Decrypt that."),!1;if(c.canEncrypt&&!o)return!1;let d=this.plugin.app.workspace.getActiveFile();if(d==null)return!1;if(e)return!0;let l="",a=(P=c.decryptable)==null?void 0:P.hint;if(this.pluginSettings.rememberPassword){let E=f.getBestGuess(d);l=E.password,a=a!=null?a:E.hint}let p=c.canEncrypt&&this.pluginSettings.confirmPassword,u=new A(this.plugin.app,c.canEncrypt,p,l,a);return u.onClose=async()=>{var Z,tt,et;if(!u.resultConfirmed)return;let E=(Z=u.resultPassword)!=null?Z:"",Y=(tt=u.resultHint)!=null?tt:"";if(c.canEncrypt){let x=new J;x.text=n,x.hint=Y,this.encryptSelection(t,x,E,s,i),f.put({password:E,hint:Y},d)}else{let x;((et=c.decryptable)==null?void 0:et.version)==1?x=await this.decryptSelection_a(t,c.decryptable,E,s,i,r):x=await this.decryptSelectionObsolete(t,c,E,s,i,r),x&&f.put({password:E,hint:Y},d)}},u.open(),!0}async encryptSelection(e,t,n,s,i){let r=new C,o=this.encodeEncryption(await r.encryptToBase64(t.text,n),t.hint);e.setSelection(s,i),e.replaceSelection(o)}async decryptSelection_a(e,t,n,s,i,r){let c=await new C().decryptFromBase64(t.base64CipherText,n);if(c===null)return new v.Notice("\u274C Decryption failed!"),!1;if(r)e.setSelection(s,i),e.replaceSelection(c);else{let d=new D(this.plugin.app,"\u{1F513}",c);d.onClose=()=>{e.focus(),d.decryptInPlace&&(e.setSelection(s,i),e.replaceSelection(c))},d.open()}return!0}async decryptSelectionObsolete(e,t,n,s,i,r){let o=t.decryptable.base64CipherText,d=await new U().decryptFromBase64(o,n);if(d===null)return new v.Notice("\u274C Decryption failed!"),!1;if(r)e.setSelection(s,i),e.replaceSelection(d);else{let l=new D(this.plugin.app,"\u{1F513}",d);l.onClose=()=>{e.focus(),l.decryptInPlace&&(e.setSelection(s,i),e.replaceSelection(d))},l.open()}return!0}encodeEncryption(e,t){return!M.some(n=>e.contains(n))&&!F.some(n=>e.contains(n))?t.length>0?_.concat(T,t,T,e,$):_.concat(e,$):e}},j=class{constructor(e){this.process(e)}process(e){var t,n;if(this.processedText=e,this.isEmpty=e.length===0,this.prefix=(t=M.find(s=>e.startsWith(s)))!=null?t:"",this.suffix=(n=F.find(s=>e.endsWith(s)))!=null?n:"",this.hasEncryptedPrefix=this.prefix.length>0,this.hasEncryptedSuffix=this.suffix.length>0,this.hasObsoleteEncryptedPrefix=this.prefix===nt,this.containsEncryptedMarkers=[...M,...F].some(s=>e.contains(s)),this.canDecrypt=this.hasEncryptedPrefix&&this.hasEncryptedSuffix,this.canEncrypt=!this.hasEncryptedPrefix&&!this.containsEncryptedMarkers,this.canDecrypt){let s=this.parseDecryptableContent(e);s!=null?this.decryptable=s:this.canDecrypt=!1}}parseDecryptableContent(e){let t=new Q;if(!this.hasEncryptedPrefix||!this.hasEncryptedSuffix)return null;t.version=this.hasObsoleteEncryptedPrefix?0:1;let n=e.substring(this.prefix.length,e.length-this.suffix.length);if([...M,...F].some(s=>n.contains(s)))return null;if(n.substring(0,T.length)==T){let s=n.indexOf(T,T.length);if(s<0)return null;t.hint=n.substring(T.length,s),t.base64CipherText=n.substring(s+T.length)}else t.base64CipherText=n;return t}},J=class{},Q=class{};var b=require("obsidian");var y=require("obsidian");var L="meld-encrypted-file-content-view",R=class extends y.TextFileView{constructor(t){super(t);this.currentView=0;this.encryptionPassword="";this.hint="";this.currentEditorText="";this.elActionIconLockNote=this.addAction("lock","Lock",()=>this.actionLockFile()),this.elActionChangePassword=this.addAction("key","Change Password",()=>this.actionChangePassword()),this.contentEl.style.display="flex",this.contentEl.style.flexDirection="column",this.contentEl.style.alignItems="center"}actionLockFile(){this.encryptionPassword="",this.refreshView(1)}actionChangePassword(){this.refreshView(3)}onPaneMenu(t,n){n=="tab-header"&&this.currentView==2&&(t.addItem(s=>{s.setSection("action").setIcon("lock").setTitle("Lock").onClick(()=>this.actionLockFile())}),t.addItem(s=>{s.setSection("action").setIcon("key").setTitle("Change Password").onClick(()=>this.actionChangePassword())})),super.onPaneMenu(t,n)}createTitle(t){return this.contentEl.createDiv({text:`\u{1F510} ${t} \u{1F510}`,attr:{style:"margin-bottom:2em;"}})}validatePassword(t){return t.length==0?"Password is too short":""}validateConfirm(t,n){return t===n?"":"Password doesn't match"}createNewNoteView(){let t=this.createInputContainer();new y.Setting(t).setDesc("Please provide a password and hint to start editing this note.");let n=async(a,p,u)=>{let P=this.validatePassword(a),E=this.validateConfirm(a,p);c.setDesc(P),d.setDesc(E),P.length===0&&E.length===0&&(this.encryptionPassword=a,this.hint=u,this.currentEditorText=this.file.basename,await this.encodeAndSave(),f.put({password:a,hint:u},this.file),this.refreshView(2))},s=f.getBestGuess(this.file),i=s.password,r="",o=s.hint,c=m.buildPasswordSetting({container:t,name:"Password:",autoFocus:!0,initialValue:i,onChangeCallback:a=>{i=a,c.setDesc(this.validatePassword(i)),d.setDesc(this.validateConfirm(i,r))},onEnterCallback:a=>{var p;i=a,i.length>0&&((p=d.controlEl.querySelector("input"))==null||p.focus())}}),d=m.buildPasswordSetting({container:t,name:"Confirm:",autoFocus:!1,onChangeCallback:a=>{r=a,c.setDesc(this.validatePassword(i)),d.setDesc(this.validateConfirm(i,r))},onEnterCallback:a=>{var u;r=a,i===r&&((u=l.controlEl.querySelector("input"))==null||u.focus())}}),l=new y.Setting(t).setName("Hint:").addText(a=>{a.setValue(o),a.onChange(p=>{o=p})});return l.controlEl.on("keydown","*",a=>{a.key==="Enter"&&(a.preventDefault(),n(i,r,o))}),new y.Setting(t).addButton(a=>{a.setCta().setIcon("go-to-file").setTooltip("Edit").onClick(p=>n(i,r,o))}),t}createDecryptNoteView(){let t=this.createInputContainer();new y.Setting(t).setDesc("Please provide a password to unlock this note.");let n=f.getBestGuess(this.file);return this.encryptionPassword=n.password,m.buildPasswordSetting({container:t,name:"Password:",initialValue:this.encryptionPassword,autoFocus:!0,placeholder:this.formatHint(this.hint),onChangeCallback:s=>{this.encryptionPassword=s},onEnterCallback:async()=>await this.handleDecryptButtonClick()}),new y.Setting(t).addButton(s=>{s.setCta().setIcon("checkmark").setTooltip("Unlock & Edit").onClick(i=>this.handleDecryptButtonClick())}),t}async encodeAndSave(){try{let t=await K.encode(this.encryptionPassword,this.hint,this.currentEditorText);this.data=V.encode(t),this.requestSave()}catch(t){console.error(t),new y.Notice(t,1e4)}}createEditorView(){let t=this.contentEl.createDiv();return t.contentEditable="true",t.style.flexGrow="1",t.style.alignSelf="stretch",t.innerText=this.currentEditorText,t.focus(),t.on("input","*",async(n,s)=>{this.currentEditorText=t.innerText,await this.encodeAndSave()}),t}createInputContainer(){return this.contentEl.createDiv({attr:{style:"width:100%; max-width:400px;"}})}createChangePasswordView(){let t=this.createInputContainer(),n="",s="",i="",r=async(l,a,p)=>{let u=this.validatePassword(l),P=this.validateConfirm(l,a);o.setDesc(u),c.setDesc(P),u.length===0&&P.length===0&&(this.encryptionPassword=l,this.hint=p,this.encodeAndSave(),this.refreshView(2),new y.Notice("Password and Hint were changed"))},o=m.buildPasswordSetting({container:t,name:"New Password:",autoFocus:!0,onChangeCallback:l=>{n=l,o.setDesc(this.validatePassword(n)),c.setDesc(this.validateConfirm(n,s))},onEnterCallback:l=>{var a;n=l,n.length>0&&((a=c.controlEl.querySelector("input"))==null||a.focus())}}),c=m.buildPasswordSetting({container:t,name:"Confirm:",onChangeCallback:l=>{s=l,o.setDesc(this.validatePassword(n)),c.setDesc(this.validateConfirm(n,s))},onEnterCallback:l=>{var p;s=l,n===s&&((p=d.controlEl.querySelector("input"))==null||p.focus())}}),d=new y.Setting(t).setName("New Hint:").addText(l=>{l.onChange(a=>{i=a})});return d.controlEl.on("keydown","*",l=>{l.key==="Enter"&&(l.preventDefault(),r(n,s,i))}),new y.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(a=>{r(n,s,i)})}),t}formatHint(t){return t.length>0?`Hint: ${t}`:""}refreshView(t){switch(this.elActionIconLockNote.hide(),this.elActionChangePassword.hide(),this.contentEl.empty(),this.currentView=t,this.currentView){case 4:this.createTitle("This note will be encrypted"),this.createNewNoteView();break;case 1:this.createTitle("This note is encrypted"),this.createDecryptNoteView();break;case 2:this.elActionIconLockNote.show(),this.elActionChangePassword.show(),this.createTitle("This note is encrypted"),this.createEditorView();break;case 3:this.createTitle("Change encrypted note password"),this.createChangePasswordView();break}}async handleDecryptButtonClick(){let t=V.decode(this.data),n=await K.decrypt(t,this.encryptionPassword);n===null?new y.Notice("Decryption failed"):(f.put({password:this.encryptionPassword,hint:this.hint},this.file),this.currentEditorText=n,this.refreshView(2))}canAcceptExtension(t){return t=="encrypted"}getViewType(){return L}setViewData(t,n){if(n){let s;t===""?s=4:s=1,this.encryptionPassword="";let i=V.decode(this.data);this.hint=i.hint,this.refreshView(s)}else this.leaf.detach(),new y.Notice("Multiple views of the same encrypted note isn't supported")}getViewData(){return this.data}clear(){}},W=class{constructor(e,t){this.version="1.0";this.hint=e,this.encodedData=t}},K=class{static async encode(e,t,n){let i=await new C().encryptToBase64(n,e);return new W(t,i)}static async decrypt(e,t){return e.encodedData==""?"":await new C().decryptFromBase64(e.encodedData,t)}},V=class{static encode(e){return JSON.stringify(e,null,2)}static decode(e){return e===""?new W("",""):JSON.parse(e)}};var B=class{async onload(e,t){this.plugin=e,this.settings=t.featureWholeNoteEncrypt,this.updateUiForSettings(),this.plugin.registerView(L,n=>new R(n)),this.plugin.registerExtensions(["encrypted"],L),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(L)}processCreateNewEncryptedNoteCommand(){try{let e=(0,b.moment)().format("[Untitled] YYYYMMDD hhmmss[.encrypted]"),t,n=this.plugin.app.workspace.getActiveFile();n!=null?t=this.plugin.app.fileManager.getNewFileParent(n.path):t=this.plugin.app.fileManager.getNewFileParent("");let s=(0,b.normalizePath)(t.path+"/"+e);return this.plugin.app.vault.create(s,"").then(async i=>{await this.plugin.app.workspace.getLeaf(!1).openFile(i)}).catch(i=>{new b.Notice(i,1e4)}),!0}catch(e){return console.error(e),new b.Notice(e,1e4),!1}}buildSettingsUi(e,t){new b.Setting(e).setHeading().setName("Whole Note Encryption Settings"),new b.Setting(e).setName("Add ribbon icon to create note").setDesc("Adds a ribbon icon to the left bar to create an encrypted note.").addToggle(n=>{n.setValue(this.settings.addRibbonIconToCreateNote).onChange(async s=>{this.settings.addRibbonIconToCreateNote=s,await t(),this.updateUiForSettings()})})}updateUiForSettings(){this.settings.addRibbonIconToCreateNote?this.ribbonIconCreateNewNote==null&&(this.ribbonIconCreateNewNote=this.plugin.addRibbonIcon("lock","Create new encrypted note",e=>{this.processCreateNewEncryptedNoteCommand()})):this.ribbonIconCreateNewNote!=null&&(this.ribbonIconCreateNewNote.remove(),this.ribbonIconCreateNewNote=null)}};var G=class extends st.Plugin{constructor(){super(...arguments);this.enabledFeatures=[]}async onload(){await this.loadSettings(),this.enabledFeatures.push(new B,new H),this.addSettingTab(new N(this.app,this,this.settings,this.enabledFeatures)),this.enabledFeatures.forEach(async t=>{await t.onload(this,this.settings)})}onunload(){this.enabledFeatures.forEach(async t=>{t.onunload()})}async loadSettings(){let t={confirmPassword:!0,rememberPassword:!0,rememberPasswordTimeout:30,featureWholeNoteEncrypt:{addRibbonIconToCreateNote:!0},featureInplaceEncrypt:{expandToWholeLines:!1}};this.settings=Object.assign(t,await this.loadData()),f.setActive(this.settings.rememberPassword),f.setAutoExpire(this.settings.rememberPasswordTimeout==0?null:this.settings.rememberPasswordTimeout)}async saveSettings(){await this.saveData(this.settings)}};
|