diff --git a/app/components/AuthEntry.js b/app/components/AuthEntry.js index 3f67d7a..ac3ed56 100644 --- a/app/components/AuthEntry.js +++ b/app/components/AuthEntry.js @@ -4,6 +4,7 @@ import { totp } from '@Lib/otp'; import CountdownPie from '@Components/CountdownPie'; import AuthMenu from '@Components/AuthMenu'; import DragIndicator from '@Components/DragIndicator'; +import { getVarColorForContrast, hexColorToRGB } from '@Lib/utils'; export default class AuthEntry extends React.Component { constructor(props) { @@ -75,7 +76,14 @@ export default class AuthEntry extends React.Component { const entryStyle = {}; if (color) { + // The background color for the entry. entryStyle.backgroundColor = color; + + const rgbColor = hexColorToRGB(color); + const varColor = getVarColorForContrast(rgbColor); + + // The foreground color for the entry. + entryStyle.color = `var(${varColor})`; } delete divProps.onCopyValue; @@ -121,7 +129,13 @@ export default class AuthEntry extends React.Component {
)?\[FileSafe[^\]]*\](<\/p>)?/g,c=e=>e.replace(s,(e=>d(e))),u=e=>"[FileSafe:".concat(e.uuid,":").concat(e.content.fileName,"]"),d=e=>{const t=(e=(e=(e=e.replace("
","")).replace("
","")).replace("[","").replace("]","")).split(":"),n=t[1],r=t[2],o=t[3];let a="";if(o){const e=o.split("x");a="width=".concat(e[0]," height=").concat(e[1])}return"")};function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var p;!function(e){e.PlainText="plaintext",e.Html="html",e.Markdown="markdown",e.Json="json"}(p||(p={}));class h{constructor(e,t){this.delegate=e,this.options=t,f(this,"fileIdsPendingAssociation",[]),f(this,"componentRelay",void 0),f(this,"fileLoader",void 0),f(this,"textExpander",void 0),f(this,"fileSafeLoading",void 0),f(this,"fileSafeClass",void 0),f(this,"fileSafeInstance",void 0),f(this,"note",void 0),f(this,"ignoreNextTextChange",void 0),f(this,"needsFileSafeElementLoad",void 0),f(this,"previousText",void 0),this.connectToBridge(),this.options.supportsFileSafe&&(this.fileSafeLoading=this.importFileSafe())}connectToBridge(){const{coallesedSaving:e,coallesedSavingDelay:n,mode:r,supportsFileSafe:o}=this.options;this.componentRelay=new(t())({targetWindow:window,options:{coallesedSaving:e,coallesedSavingDelay:n},onReady:()=>{const{platform:e}=this.componentRelay;e&&document.documentElement.classList.add(e)}}),this.componentRelay.streamContextItem((e=>{let t=!0;this.note&&this.note.uuid==e.uuid&&(t=!1);const n=this.note;if(o){const t=this.fileSafeClass.getSFItemClass();this.note=new t(e),this.fileSafeInstance.setCurrentNote(this.note)}else this.note=e;if(e.isMetadataUpdate)return;let a=e.content.text;if(r===p.Html&&t&&(/<[a-z][\s\S]*>/i.test(a)||(this.ignoreNextTextChange=!0)),this.previousText=a,o&&(this.needsFileSafeElementLoad=!0,a=c(a)),this.delegate.setEditorRawText(a),this.delegate.onNoteLockToggle){var i,l;const e=null!==(i=this.componentRelay.getItemAppDataValue(n,"locked"))&&void 0!==i&&i,t=null!==(l=this.componentRelay.getItemAppDataValue(this.note,"locked"))&&void 0!==l&&l;e!==t&&this.delegate.onNoteLockToggle(t)}t&&this.delegate.clearUndoHistory()}))}async importFileSafe(){return Promise.resolve().then(a.t.bind(a,695,23)).then((e=>(this.fileSafeClass=e.default,this.configureFileSafe(),this.fileSafeInstance)))}configureFileSafe(){this.fileSafeInstance=new this.fileSafeClass({componentManager:this.componentRelay}),this.fileSafeInstance.addDataChangeObserver((()=>{const e=this.fileSafeInstance.getAllFileDescriptors();if(this.note&&this.fileIdsPendingAssociation.length>0){let t=!1;for(const n of this.fileIdsPendingAssociation.slice()){const r=e.find((e=>e.uuid==n));if(!r)continue;t=!0,this.fileIdsPendingAssociation.splice(this.fileIdsPendingAssociation.indexOf(n),1);const o=u(r);this.delegate.insertRawText(o)}t&&this.textExpander.searchPatterns()}e.length>0&&this.fileLoader.loadFileSafeElements()})),this.fileSafeInstance.addNewFileDescriptorHandler((e=>{this.fileIdsPendingAssociation.push(e.uuid)})),this.fileLoader=new o({fileSafeInstance:this.fileSafeInstance,getElementsBySelector:this.delegate.getElementsBySelector,insertElement:this.delegate.insertElement,preprocessElement:this.delegate.preprocessElement}),this.textExpander=new l({afterExpand:()=>this.fileLoader.loadFileSafeElements(),getCurrentLineText:this.delegate.getCurrentLineText,getPreviousLineText:this.delegate.getPreviousLineText,replaceText:this.delegate.replaceText,patterns:[{regex:s,callback:e=>c(e)}]})}async getFileSafe(){return!this.fileSafeInstance&&this.fileSafeLoading?this.fileSafeLoading:this.importFileSafe()}onEditorKeyUp(e){let{isSpace:t,isEnter:n}=e;this.textExpander.onKeyUp({isSpace:t,isEnter:n})}onEditorPaste(){this.textExpander.onKeyUp({isPaste:!0})}onEditorValueChanged(e){const{mode:t,supportsFileSafe:n}=this.options;if(this.needsFileSafeElementLoad&&(this.needsFileSafeElementLoad=!1,this.fileLoader.loadFileSafeElements()),this.ignoreNextTextChange)return void(this.ignoreNextTextChange=!1);if(n&&(e=(e=>{const t=(new DOMParser).parseFromString(e,"text/html"),n=t.querySelectorAll("*[fscollapsable]");for(const e of n){const t=e.getAttribute("fsid"),n=e.getAttribute("fsname"),r=e.getAttribute("width"),o=e.getAttribute("height"),a=["FileSafe",t,n];if(r&&o){const e="".concat(r,"x").concat(o);a.push(e)}const i="[".concat(a.join(":"),"]
");e.insertAdjacentHTML("afterend",i),e.remove()}return t.querySelectorAll("*[ghost]").forEach((e=>e.remove())),t.body.innerHTML})(e),this.previousText==e))return;if(this.previousText=e,!this.note)return;const r=this.note;this.componentRelay.saveItemWithPresave(r,(()=>{if(r.content.text=e,this.delegate.generateCustomPreview){const t=this.delegate.generateCustomPreview(e);t.html?r.content.preview_html=t.html:t.plain&&(r.content.preview_plain=t.plain)}else{if(t===p.Html){let t=e.replace(s,(e=>""));t=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:90;return e.length<=t?e:e.substring(0,t)+"..."}((e=>{const t=document.implementation.createHTMLDocument().body;return t.innerHTML=e,t.textContent||t.innerText||""})(t)),r.content.preview_plain=t.length>0?t:" "}else r.content.preview_plain=e;r.content.preview_html=null}}))}canUploadFiles(){const e=this.fileSafeInstance.getAllCredentials(),t=this.fileSafeInstance.getAllIntegrations();return e.length>0&&t.length>0}async uploadJSFileObject(e){const t=this.fileLoader.insertStatusAtCursor("Processing file...");return this.fileSafeInstance.encryptAndUploadJavaScriptFileObject(e).then((()=>{this.fileLoader.removeCursorStatus(t)}))}}})(),i.default})())},7757:(e,t,n)=>{e.exports=n(5666)},597:(e,t,n)=>{"use strict";var r,o=Object.assign||function(e){for(var t=1;t".concat(this.text,"
"):"";return'\n)?\[FileSafe[^\]]*\](<\/p>)?/g,c=e=>e.replace(s,(e=>d(e))),u=e=>"[FileSafe:".concat(e.uuid,":").concat(e.content.fileName,"]"),d=e=>{const t=(e=(e=(e=e.replace("
","")).replace("
","")).replace("[","").replace("]","")).split(":"),n=t[1],r=t[2],o=t[3];let a="";if(o){const e=o.split("x");a="width=".concat(e[0]," height=").concat(e[1])}return"")};function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var p;!function(e){e.PlainText="plaintext",e.Html="html",e.Markdown="markdown",e.Json="json"}(p||(p={}));class h{constructor(e,t){this.delegate=e,this.options=t,f(this,"fileIdsPendingAssociation",[]),f(this,"componentRelay",void 0),f(this,"fileLoader",void 0),f(this,"textExpander",void 0),f(this,"fileSafeLoading",void 0),f(this,"fileSafeClass",void 0),f(this,"fileSafeInstance",void 0),f(this,"note",void 0),f(this,"ignoreNextTextChange",void 0),f(this,"needsFileSafeElementLoad",void 0),f(this,"previousText",void 0),this.connectToBridge(),this.options.supportsFileSafe&&(this.fileSafeLoading=this.importFileSafe())}connectToBridge(){const{coallesedSaving:e,coallesedSavingDelay:n,mode:r,supportsFileSafe:o}=this.options;this.componentRelay=new(t())({targetWindow:window,options:{coallesedSaving:e,coallesedSavingDelay:n},onReady:()=>{const{platform:e}=this.componentRelay;e&&document.documentElement.classList.add(e)}}),this.componentRelay.streamContextItem((e=>{let t=!0;this.note&&this.note.uuid==e.uuid&&(t=!1);const n=this.note;if(o){const t=this.fileSafeClass.getSFItemClass();this.note=new t(e),this.fileSafeInstance.setCurrentNote(this.note)}else this.note=e;if(e.isMetadataUpdate)return;let a=e.content.text;if(r===p.Html&&t&&(/<[a-z][\s\S]*>/i.test(a)||(this.ignoreNextTextChange=!0)),this.previousText=a,o&&(this.needsFileSafeElementLoad=!0,a=c(a)),this.delegate.setEditorRawText(a),this.delegate.onNoteLockToggle){var i,l;const e=null!==(i=this.componentRelay.getItemAppDataValue(n,"locked"))&&void 0!==i&&i,t=null!==(l=this.componentRelay.getItemAppDataValue(this.note,"locked"))&&void 0!==l&&l;e!==t&&this.delegate.onNoteLockToggle(t)}t&&this.delegate.clearUndoHistory()}))}async importFileSafe(){return Promise.resolve().then(a.t.bind(a,695,23)).then((e=>(this.fileSafeClass=e.default,this.configureFileSafe(),this.fileSafeInstance)))}configureFileSafe(){this.fileSafeInstance=new this.fileSafeClass({componentManager:this.componentRelay}),this.fileSafeInstance.addDataChangeObserver((()=>{const e=this.fileSafeInstance.getAllFileDescriptors();if(this.note&&this.fileIdsPendingAssociation.length>0){let t=!1;for(const n of this.fileIdsPendingAssociation.slice()){const r=e.find((e=>e.uuid==n));if(!r)continue;t=!0,this.fileIdsPendingAssociation.splice(this.fileIdsPendingAssociation.indexOf(n),1);const o=u(r);this.delegate.insertRawText(o)}t&&this.textExpander.searchPatterns()}e.length>0&&this.fileLoader.loadFileSafeElements()})),this.fileSafeInstance.addNewFileDescriptorHandler((e=>{this.fileIdsPendingAssociation.push(e.uuid)})),this.fileLoader=new o({fileSafeInstance:this.fileSafeInstance,getElementsBySelector:this.delegate.getElementsBySelector,insertElement:this.delegate.insertElement,preprocessElement:this.delegate.preprocessElement}),this.textExpander=new l({afterExpand:()=>this.fileLoader.loadFileSafeElements(),getCurrentLineText:this.delegate.getCurrentLineText,getPreviousLineText:this.delegate.getPreviousLineText,replaceText:this.delegate.replaceText,patterns:[{regex:s,callback:e=>c(e)}]})}async getFileSafe(){return!this.fileSafeInstance&&this.fileSafeLoading?this.fileSafeLoading:this.importFileSafe()}onEditorKeyUp(e){let{isSpace:t,isEnter:n}=e;this.textExpander.onKeyUp({isSpace:t,isEnter:n})}onEditorPaste(){this.textExpander.onKeyUp({isPaste:!0})}onEditorValueChanged(e){const{mode:t,supportsFileSafe:n}=this.options;if(this.needsFileSafeElementLoad&&(this.needsFileSafeElementLoad=!1,this.fileLoader.loadFileSafeElements()),this.ignoreNextTextChange)return void(this.ignoreNextTextChange=!1);if(n&&(e=(e=>{const t=(new DOMParser).parseFromString(e,"text/html"),n=t.querySelectorAll("*[fscollapsable]");for(const e of n){const t=e.getAttribute("fsid"),n=e.getAttribute("fsname"),r=e.getAttribute("width"),o=e.getAttribute("height"),a=["FileSafe",t,n];if(r&&o){const e="".concat(r,"x").concat(o);a.push(e)}const i="[".concat(a.join(":"),"]
");e.insertAdjacentHTML("afterend",i),e.remove()}return t.querySelectorAll("*[ghost]").forEach((e=>e.remove())),t.body.innerHTML})(e),this.previousText==e))return;if(this.previousText=e,!this.note)return;const r=this.note;this.componentRelay.saveItemWithPresave(r,(()=>{if(r.content.text=e,this.delegate.generateCustomPreview){const t=this.delegate.generateCustomPreview(e);t.html?r.content.preview_html=t.html:t.plain&&(r.content.preview_plain=t.plain)}else{if(t===p.Html){let t=e.replace(s,(e=>""));t=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:90;return e.length<=t?e:e.substring(0,t)+"..."}((e=>{const t=document.implementation.createHTMLDocument().body;return t.innerHTML=e,t.textContent||t.innerText||""})(t)),r.content.preview_plain=t.length>0?t:" "}else r.content.preview_plain=e;r.content.preview_html=null}}))}canUploadFiles(){const e=this.fileSafeInstance.getAllCredentials(),t=this.fileSafeInstance.getAllIntegrations();return e.length>0&&t.length>0}async uploadJSFileObject(e){const t=this.fileLoader.insertStatusAtCursor("Processing file...");return this.fileSafeInstance.encryptAndUploadJavaScriptFileObject(e).then((()=>{this.fileLoader.removeCursorStatus(t)}))}}})(),i.default})())},7757:(e,t,n)=>{e.exports=n(5666)},597:(e,t,n)=>{"use strict";var r,o=Object.assign||function(e){for(var t=1;t".concat(this.text,"
"):"";return'\n