UNPKG

@zklogic/draw.io

Version:

Draw.IO - Graph Editor integration in Angular-cli

1 lines 30.6 kB
window.PLUGINS_BASE_PATH=".",window.TEMPLATE_PATH="templates",window.DRAW_MATH_URL="math",window.DRAWIO_BASE_URL=".",FeedbackDialog.feedbackUrl="https://log.draw.io/email",mxStencilRegistry.allowEval=!1,function(){App.mode=App.MODE_DEVICE,EmbedDialog.showPreviewOption=!1,EditDiagramDialog.showNewWindowOption=!1,PrintDialog.previewEnabled=!1,PrintDialog.electronPrint=function(e,t,i,n,s,r,l,o,a,c){var u="",p="",d=e.getCurrentFile();d&&(d.updateFileData(),u=d.getData(),p=d.title),new f("export",{print:!0,format:"pdf",xml:u,from:i-1,to:n-1,allPages:t,pageWidth:c.width,pageHeight:c.height,pageScale:a,fit:s,sheetsAcross:r,sheetsDown:l,scale:o,fileTitle:p}).send((function(){}),(function(){}))};var e=window.open;window.open=function(t){if(null==t||!t.startsWith("http"))return e(t);{const{shell:e}=require("electron");e.openExternal(t)}};var t=App.main;App.main=function(){App.filesWorker=new Worker("electronFilesWorker.js"),App.filesWorkerReqId=1,App.filesWorkerReqInfo={},App.filesWorkerReq=function(e,t,i){e.reqId=App.filesWorkerReqId++,App.filesWorkerReqInfo[e.reqId]={callback:t,error:i},App.filesWorker.postMessage(e)},App.filesWorker.onmessage=function(e){var t=e.data,i=App.filesWorkerReqInfo[t.reqId];t.error?i.error(t.msg,t.e):i.callback(t.data),delete App.filesWorkerReqInfo[t.reqId]};var e=null!=mxSettings.settings?mxSettings.getPlugins():null;if(App.initPluginCallback(),null!=e&&e.length>0)for(var i=0;i<e.length;i++)try{if(e[i].startsWith("/plugins/"))e[i]="."+e[i];else if(e[i].startsWith("plugins/"))e[i]="./"+e[i];else if(!e[i].startsWith("file://")){var n=require("fs"),r=require("path"),l=r.join(s(),"/plugins",e[i]);if(!n.existsSync(l))continue;e[i]="file://"+l}mxscript(e[i])}catch(e){}urlParams.plugins="0",t.apply(this,arguments)};var i=Menus.prototype.init;function n(){try{return require("@electron/remote").app.getPath("documents")}catch(e){}return"."}function s(){try{var e=require("fs"),t=require("@electron/remote").app.getPath("appData")+"/draw.io";return e.existsSync(t)||e.mkdirSync(t),t}catch(e){}return"."}Menus.prototype.init=function(){i.apply(this,arguments);var e=this.editorUi;e.actions.put("useOffline",new Action(mxResources.get("useOffline")+"...",(function(){e.openLink("https://www.draw.io/")}))),this.put("openRecent",new Menu((function(t,i){var n=e.getRecent();if(null!=n){for(var s=0;s<n.length;s++)!function(n){t.addItem(n.title,null,(function(){function t(){e.loadArgs({args:[n.id]})}var i=e.getCurrentFile();null!=i&&i.isModified()?e.confirm(mxResources.get("allChangesLost"),null,t,mxResources.get("cancel"),mxResources.get("discardChanges")):t()}),i)}(n[s]);t.addSeparator(i)}t.addItem(mxResources.get("reset"),null,(function(){e.resetRecent()}),i)}))),this.put("file",new Menu(mxUtils.bind(this,(function(t,i){this.addMenuItems(t,["new","open"],i),this.addSubmenu("openRecent",t,i),this.addMenuItems(t,["-","synchronize","-","save","saveAs","-","import"],i),this.addSubmenu("exportAs",t,i),t.addSeparator(i),this.addSubmenu("embed",t,i),t.addSeparator(i),this.addMenuItems(t,["newLibrary","openLibrary"],i);var n=e.getCurrentFile();if(null!=n&&null!=e.fileNode){var s=null!=n.getTitle()?n.getTitle():e.defaultFilename;/(\.html)$/i.test(s)||/(\.svg)$/i.test(s)||this.addMenuItems(t,["-","properties"])}this.addMenuItems(t,["-","pageSetup","print","-","close"],i)}))))};var r=Graph.prototype.createLinkForHint;Graph.prototype.createLinkForHint=function(e,t){var i=r.call(this,e,t);return null==e||this.isCustomLink(e)||mxEvent.addListener(i,"click",mxUtils.bind(this,(function(e){this.openLink(i.getAttribute("href"),i.getAttribute("target")),mxEvent.consume(e)}))),i},Graph.prototype.openLink=function(e,t){require("electron").shell.openExternal(e)};var l=EditorUi.prototype.init;EditorUi.prototype.init=function(){l.apply(this,arguments);var e=this,t=this.editor.graph;global.__emt_isModified=t=>!!e.getCurrentFile()&&e.getCurrentFile().isModified(),global.__emt_removeDraft=function(){var t=e.getCurrentFile();null!=t&&t.removeDraft()},this.actions.addAction("newLibrary...",mxUtils.bind(this,(function(){e.showLibraryDialog(null,null,null,null,App.MODE_DEVICE)}))),this.actions.addAction("openLibrary...",mxUtils.bind(this,(function(){e.pickLibrary(App.MODE_DEVICE)}))),this.actions.addAction("import...",mxUtils.bind(this,(function(){if(null!=e.getCurrentFile()){var i=require("@electron/remote").dialog;const c=require("path");var s=localStorage.getItem(".lastImpDir"),r=i.showOpenDialogSync({defaultPath:s||n(),properties:["openFile"]});if(void 0!==r&&null!=r[0]){var l=r[0];localStorage.setItem(".lastImpDir",c.dirname(l));var o=/\.png$/i.test(l)||/\.gif$/i.test(l)||/\.jpe?g$/i.test(l),a=o||/\.pdf$/i.test(l)||/\.vsdx$/i.test(l)||/\.vssx$/i.test(l)?"base64":"utf-8";e.spinner.spin(document.body,mxResources.get("loading"))&&require("fs").readFile(l,a,mxUtils.bind(this,(function(i,n){if(i)e.spinner.stop(),e.handleError(i);else try{if(e.isLucidChartData(n))e.convertLucidChart(n,(function(i){e.spinner.stop(),t.setSelectionCells(e.importXml(i))}),(function(t){e.spinner.stop(),e.handleError(t)}));else if(/(\.vsdx)($|\?)/i.test(l))e.importVisio(e.base64ToBlob(n,"application/octet-stream"),(function(i){e.spinner.stop(),t.setSelectionCells(e.importXml(i))}));else if(!e.isOffline()&&(new XMLHttpRequest).upload&&e.isRemoteFileFormat(n,l))e.parseFile(new Blob([n],{type:"application/octet-stream"}),mxUtils.bind(this,(function(i){4==i.readyState&&(e.spinner.stop(),i.status>=200&&i.status<=299&&t.setSelectionCells(e.importXml(i.responseText)))})),l);else{if(/\.pdf$/i.test(l))null!=(s=Editor.extractGraphModelFromPdf(n))&&(n=s);else if(/\.png$/i.test(l)){var s;null!=(s=e.extractGraphModelFromPng(n))&&(o=!1,n=s)}else if(/\.svg$/i.test(l)){var r=mxUtils.parseXml(n).getElementsByTagName("svg");if(r.length>0){var a=r[0].getAttribute("content");null!=a&&"<"!=a.charAt(0)&&"%"!=a.charAt(0)&&(a=unescape(window.atob?atob(a):Base64.decode(a,!0))),null!=a&&"%"==a.charAt(0)&&(a=decodeURIComponent(a)),null==a||"<mxfile "!==a.substring(0,8)&&"<mxGraphModel "!==a.substring(0,14)?o=!0:(o=!1,n=a)}}if(o){var c=new Image;c.onload=function(){e.resizeImage(c,c.src,(function(i,n,s){e.spinner.stop();var r=t.getInsertPoint();t.setSelectionCell(t.insertVertex(null,null,"",r.x,r.y,n,s,"shape=image;aspect=fixed;image="+e.convertDataUri(i)+";"))}),!0)},c.onerror=function(t){e.spinner.stop(),e.handleError()};var u=l.substring(l.lastIndexOf(".")+1);c.src="svg"==u?Editor.createSvgDataUri(n):"data:image/"+u+";base64,"+n}else e.spinner.stop(),null!=n&&t.setSelectionCells(e.importXml(n))}}catch(i){e.spinner.stop(),e.handleError(i)}})))}}})));var i=this.actions.get("new").funct;function r(){var e=new Graph;return e.setExtendParents(!1),e.setExtendParentsOnAdd(!1),e.setConstrainChildren(!1),e.setHtmlLabels(!0),e.getModel().maintainEdgeParent=!1,e}function o(){var e=mxClipboard.getCells();if(e&&e.length>0)try{var t=r();t.importCells(e,0,0,t.getDefaultParent());var i=require("@electron/remote").clipboard,n=(new mxCodec).encode(t.getModel()),s=mxUtils.getXml(n);i.writeText(encodeURIComponent(s))}catch(e){}}function a(){try{var e=require("@electron/remote").clipboard.readText();if(e){e=decodeURIComponent(e);var t=mxUtils.parseXml(e),i=r(),n=new mxCodec(t),s=i.getModel();n.decode(t.documentElement,s),mxClipboard.setCells(s.root.children[0].children)}}catch(e){}}this.actions.addAction("new...",mxUtils.bind(this,(function(){null==this.getCurrentFile()?i():require("electron").ipcRenderer.sendSync("winman",{action:"newfile",opt:{width:1600}})})),null,null,Editor.ctrlKey+"+N"),this.actions.get("open").shortcut=Editor.ctrlKey+"+O",e.keyHandler.bindAction(78,!0,"new"),e.keyHandler.bindAction(79,!0,"open");var c=this.actions.get("cut").funct;e.actions.addAction("cut",(function(){c(),o()}),null,"sprite-cut",Editor.ctrlKey+"+X");var u=this.actions.get("copy").funct;e.actions.addAction("copy",(function(){u(),o()}),null,"sprite-copy",Editor.ctrlKey+"+C");var p=this.actions.get("paste").funct;e.actions.addAction("paste",(function(){a(),p()}),!1,"sprite-paste",Editor.ctrlKey+"+V");var d=this.actions.get("pasteHere").funct;e.actions.addAction("pasteHere",(function(){a(),d()})),e.updatePasteActionStates=function(){var e=this.editor.graph,t=this.actions.get("paste"),i=this.actions.get("pasteHere");t.setEnabled(this.editor.graph.cellEditor.isContentEditing()||e.isEnabled()&&!e.isCellLocked(e.getDefaultParent())),i.setEnabled(t.isEnabled())},e.actions.addAction("plugins...",(function(){e.showDialog(new PluginsDialog(e,(function(t){var i=document.createElement("div"),r=document.createElement("span");r.style.marginTop="6px",mxUtils.write(r,mxResources.get("builtinPlugins")+": "),i.appendChild(r);var l=document.createElement("select");l.style.width="150px";for(var o=0;o<App.publicPlugin.length;o++){var a=document.createElement("option");mxUtils.write(a,App.publicPlugin[o]),a.value=App.publicPlugin[o],l.appendChild(a)}i.appendChild(l),mxUtils.br(i),mxUtils.br(i),r=document.createElement("span"),mxUtils.write(r,mxResources.get("extPlugins")+": "),i.appendChild(r);var c=mxUtils.button(mxResources.get("selectFile")+"...",(function(){var i=require("@electron/remote").dialog;const r=require("path");var l=localStorage.getItem(".lastPluginDir"),o=i.showOpenDialogSync({defaultPath:l||n(),filters:[{name:"draw.io Plugins",extensions:["js"]},{name:"All Files",extensions:["*"]}],properties:["openFile"]});if(void 0!==o&&null!=o[0]){localStorage.setItem(".lastPluginDir",r.dirname(o[0]));var a=require("fs"),c=r.join(s(),"/plugins");a.existsSync(c)||a.mkdirSync(c);var u=r.basename(o[0]),p=r.join(c,u);a.existsSync(p)?alert(mxResources.get("fileExists")):a.copyFile(o[0],p,(i=>{i?alert("Adding plugin failed."):(t(u),e.hideDialog())}))}}));c.className="geBtn",i.appendChild(c);var u=new CustomDialog(e,i,mxUtils.bind(this,(function(){t(App.pluginRegistry[l.value])})));e.showDialog(u.container,300,120,!0,!0)}),(function(e){var t=require("fs"),i=require("path").join(s(),"/plugins",e);t.existsSync(i)&&t.unlinkSync(i)})).container,360,170,!0,!1)}))};var o=App.prototype.load;App.prototype.load=function(){o.apply(this,arguments);const{ipcRenderer:e}=require("electron");e.on("args-obj",((e,t)=>{this.loadArgs(t)}));var t=this;e.on("export-vsdx",((i,n)=>{var s=new LocalFile(t,n.xml,"");t.fileLoaded(s);try{t.saveData=function(t,i,n,s,r){e.send("export-vsdx-finished",n)},new VsdxExport(t).exportCurrentDiagrams()||e.send("export-vsdx-finished",null)}catch(t){e.send("export-vsdx-finished",null)}})),e.send("app-load-finished",null)},App.prototype.loadArgs=function(e){var t=e.args;if(void 0!==t&&null!=t[0]&&0!=t[0].indexOf("-")&&this.spinner.spin(document.body,mxResources.get("loading"))){var i=t[0];this.hideDialog();var n=mxUtils.bind(this,(function(e,t,i,n,s){if(this.spinner.stop(),null!=t){var r=new LocalFile(this,t,n||"");r.fileObject=e,r.stat=i,r.setModified(!!s),this.fileLoaded(r)}})),s=mxUtils.bind(this,(function(e){if(this.spinner.stop(),"ENOENT"===e.code){var t=i.replace(/^.*[\\\/]/,""),n=this.emptyDiagramXml,s=new LocalFile(this,n,t,null);s.fileObject=new Object,s.fileObject.path=i,s.fileObject.name=t,s.fileObject.type="utf-8",this.fileCreated(s,null,null,null),this.saveFile()}else this.handleError(e)}));this.readGraphFile(n,s,i)}else if(null!=e.create){var r=this.emptyDiagramXml,l=new LocalFile(this,r,"Untitled document",null);this.fileCreated(l,null,null,null)}else this.checkDrafts()};var a=EditorUi.prototype.fileLoaded;EditorUi.prototype.fileLoaded=function(e){var t=require("fs"),i=this.getCurrentFile();if(null!=i&&null!=i.fileObject&&t.unwatchFile(i.fileObject.path),null!=e){if(null==e.fileObject){var n=e.getTitle(),s=u[n];null!=s&&(e.fileObject={name:s.name,path:s.path,type:s.type||"utf-8"},delete u[n])}if(null!=e.fileObject){var r=e.fileObject.path;r.length>100&&(r="..."+r.substr(r.length-97)),this.addRecent({id:e.fileObject.path,title:r}),t.watchFile(e.fileObject.path,mxUtils.bind(this,(function(t,i){if(t.mtimeMs!=i.mtimeMs){if(e.unwatchedSaves||null!=e.state&&e.stat.mtimeMs==t.mtimeMs)return void(e.unwatchedSaves=!1);e.inConflictState=!0,this.showError(mxResources.get("externalChanges"),mxResources.get("fileChangedSyncDialog"),mxResources.get("synchronize"),mxUtils.bind(this,(function(){this.spinner.spin(document.body,mxResources.get("updatingDocument"))&&e.synchronizeFile(mxUtils.bind(this,(function(){this.spinner.stop()})),mxUtils.bind(this,(function(t){e.handleFileError(t,!0)})))})),null,null,null,mxResources.get("cancel"),mxUtils.bind(this,(function(){this.hideDialog(),e.handleFileError(null,!1)})),340,150)}})))}}a.apply(this,arguments)},App.prototype.pickFile=function(){var e=mxUtils.bind(this,(function(){this.chooseFileEntry(mxUtils.bind(this,(function(e,t,i,n,s){var r=new LocalFile(this,t,"");r.fileObject=e,r.stat=i,r.setModified(!!s),this.fileLoaded(r)})))})),t=this.getCurrentFile();null!=t&&t.isModified()?this.confirm(mxResources.get("allChangesLost"),null,e,mxResources.get("cancel"),mxResources.get("discardChanges")):e()},App.prototype.pickLibrary=function(e){this.chooseFileEntry(mxUtils.bind(this,(function(e,t,i){try{var n=new DesktopLibrary(this,t,e);this.loadLibrary(n)}catch(e){this.handleError(e,mxResources.get("errorLoadingFile"))}})))},App.prototype.chooseFileEntry=function(e){var t=require("@electron/remote").dialog;const i=require("path");var s=localStorage.getItem(".lastOpenDir"),r=t.showOpenDialogSync({defaultPath:s||n(),filters:[{name:"draw.io Diagrams",extensions:["drawio","xml","png","svg","html"]},{name:"VSDX Documents",extensions:["vsdx"]},{name:"All Files",extensions:["*"]}],properties:["openFile"]});void 0!==r&&null!=r[0]?(localStorage.setItem(".lastOpenDir",i.dirname(r[0])),this.readGraphFile(e,mxUtils.bind(this,(function(e){this.handleError(e)})),r[0])):this.spinner.stop()};var c=EditorUi.prototype.openFiles,u={};EditorUi.prototype.openFiles=function(e,t){u={};for(var i=0;i<e.length;i++)u[e[i].name]=e[i];c.apply(this,arguments)},App.prototype.readGraphFile=function(e,t,i){var n=require("fs"),s=i.lastIndexOf(".png"),r=s>-1&&s==i.length-4,l=/\.vsdx$/i.test(i)||/\.vssx$/i.test(i),o=l?null:r||/\.pdf$/i.test(i)?"base64":"utf-8",a=new Object,c=null;a.path=i,a.name=i.replace(/^.*[\\\/]/,""),a.type=o;var u=mxUtils.bind(this,(function(){this.filterDrafts(a.path,"dummy",mxUtils.bind(this,(function(t){if(t.length>0){var i=new DraftDialog(this,mxResources.get("unsavedChanges"),t.length>1?null:t[0].data,mxUtils.bind(this,(function(i){i=i||0,this.hideDialog(),e(a,t[i].data,c,null,!0),this.removeDatabaseItem(t[i].key)})),mxUtils.bind(this,(function(e){e=e||0,this.confirm(mxResources.get("areYouSure"),null,mxUtils.bind(this,(function(){this.removeDatabaseItem(t[e].key),this.hideDialog()})),mxResources.get("no"),mxResources.get("yes"))})),null,null,null,t.length>1?t:null);this.showDialog(i.container,640,480,!0,!1),i.init()}})))})),p=mxUtils.bind(this,(function(s,o){if(s)t(s),u();else{if(l){var p=a.name;return void this.importVisio(o,mxUtils.bind(this,(function(t){if(p.lastIndexOf(".")>=0?p=p.substring(0,p.lastIndexOf("."))+".drawio":p+=".drawio","<mxlibrary"==t.substring(0,10)){null==this.getCurrentFile()&&"1"!=urlParams.embed&&this.openLocalFile(this.emptyDiagramXml,this.defaultFilename);try{this.loadLibrary(new LocalLibrary(this,t,p))}catch(e){this.handleError(e,mxResources.get("errorLoadingFile"))}e()}else e(null,t,null,p,!1);u()})),null,p)}if(/\.pdf$/i.test(i)){var d=Editor.extractGraphModelFromPdf("data:application/pdf;base64,"+o);if(null!=d)return p=a.name,e(null,d,null,p.substring(0,p.lastIndexOf("."))+".drawio",!1),void u()}else r&&(o=this.extractGraphModelFromPng("data:image/png;base64,"+o));n.stat(i,mxUtils.bind(this,(function(s,r){s?t(s):(e(a,o,c=r,null,!1),n.access(i,n.constants.W_OK,mxUtils.bind(this,(function(e){if(e){var t=this.getCurrentFile();null!=t&&null!=t.fileObject&&t.fileObject.path==i&&(t.setEditable(!1),this.editor.setStatus('<div class="geStatusAlert">'+mxResources.get("readOnly")+"</div>"))}})))),u()})))}}));n.readFile(i,o,p)};var p=LocalFile;LocalFile=function(e,t,i,n){p.call(this,e,t,i,!1)},mxUtils.extend(LocalFile,p),LocalFile.prototype.getLatestVersion=function(e,t){null==this.fileObject?null!=t&&t({message:mxResources.get("fileNotFound")}):this.ui.readGraphFile(mxUtils.bind(this,(function(t,i,n,s,r){var l=new LocalFile(this,i,"");l.stat=n,l.setModified(!!r),e(l)})),t,this.fileObject.path)},LocalFile.prototype.copyFile=function(e,t){this.saveAs(this.ui.getCopyFilename(this),e,t)},LocalFile.prototype.getDescriptor=function(){return this.stat},LocalFile.prototype.setDescriptor=function(e){this.stat=e},LocalFile.prototype.reloadFile=function(e){if(null==this.fileObject)this.ui.handleError({message:mxResources.get("fileNotFound")});else{this.ui.spinner.stop();var t=mxUtils.bind(this,(function(){this.setModified(!1);var t=this.ui.currentPage,i=this.ui.editor.graph.getViewState(),n=this.ui.editor.graph.getSelectionCells();this.ui.spinner.spin(document.body,mxResources.get("loading"))&&this.ui.readGraphFile(mxUtils.bind(this,(function(s,r,l,o,a){this.ui.spinner.stop();var c=new LocalFile(this.ui,r,"");c.fileObject=s,c.stat=l,c.setModified(!!a),this.ui.fileLoaded(c),this.ui.restoreViewState(t,i,n),null!=this.backupPatch&&this.patch([this.backupPatch]),null!=e&&e()})),mxUtils.bind(this,(function(e){this.handleFileError(e)})),this.fileObject.path)}));this.isModified()&&null==this.backupPatch?this.ui.confirm(mxResources.get("allChangesLost"),mxUtils.bind(this,(function(){this.handleFileSuccess("manual"==DrawioFile.SYNC)})),t,mxResources.get("cancel"),mxResources.get("discardChanges")):t()}},LocalFile.prototype.isAutosave=function(){return null!=this.fileObject&&DrawioFile.prototype.isAutosave.apply(this,arguments)},LocalFile.prototype.isAutosaveOptional=function(){return null!=this.fileObject},LocalFile.prototype.getTitle=function(){return null!=this.fileObject?this.fileObject.name:this.title},LocalFile.prototype.isRenamable=function(){return!1},LocalFile.prototype.open=DrawioFile.prototype.open,LocalFile.prototype.save=function(e,t,i,n,s){DrawioFile.prototype.save.apply(this,[e,mxUtils.bind(this,(function(){this.saveFile(e,t,i,n,s)})),i,n,s])},LocalFile.prototype.isConflict=function(e){return null!=e&&null!=this.stat&&e.mtimeMs!=this.stat.mtimeMs},LocalFile.prototype.isEditable=function(){return null!=this.editable?this.editable:this.ui.editor.editable},LocalFile.prototype.setEditable=function(e){this.editable=e},LocalFile.prototype.getFilename=function(){var e=this.title;return!(e.length>0)||/(\.xml)$/i.test(e)||/(\.html)$/i.test(e)||/(\.svg)$/i.test(e)||/(\.png)$/i.test(e)||/(\.drawio)$/i.test(e)||(e+=".drawio"),e},LocalLibrary.prototype.getFilename=LocalFile.prototype.getFilename,LocalFile.prototype.saveFile=function(e,t,i,s,r){if("function"==typeof t){if(!this.savingFile){var l=mxUtils.bind(this,(function(){var e=mxUtils.bind(this,(function(e,n){var s=this.data;this.setShadowModified(!1),this.savingFile=!0;var l=mxUtils.bind(this,(function(e){this.savingFile=!1,null!=i&&i(e)}));null==this.fileObject.bkpPath&&(this.fileObject.bkpPath=function(e){const t=require("path");return t.join(t.dirname(e),"~$"+t.basename(e)+".bkp")}(this.fileObject.path)),this.unwatchedSaves=!0,App.filesWorkerReq({action:"saveFile",fileObject:this.fileObject,defEnc:n,data:e,origStat:this.stat,overwrite:r},mxUtils.bind(this,(function(e){this.setModified(this.getShadowModified()),this.savingFile=!1;var n=this.stat;this.stat=e.stat,this.fileSaved(s,n,mxUtils.bind(this,(function(){this.contentChanged(),null!=t&&t()})),i)})),mxUtils.bind(this,(function(e,t){"empty data"==e?(this.ui.handleError({message:mxResources.get("errorSavingFile")}),l()):"conflict"==e?(this.inConflictState=!0,l()):l(t||e)})))}));if(/(\.png)$/i.test(this.fileObject.name)){var n=this.ui.getPngFileProperties(this.ui.fileNode);this.ui.getEmbeddedPng((function(t){e(atob(t),"binary")}),i,null,n.scale,n.border)}else e(this.getData())}));if(null==this.fileObject){var o=require("@electron/remote").dialog;const e=require("path");var a=localStorage.getItem(".lastSaveDir"),c=this.getFilename(),u=null;if(null!=c){var p=c.lastIndexOf(".");p>0&&(u=c.substring(p+1),c=c.substring(0,p))}var d=o.showSaveDialogSync({defaultPath:(a||n())+"/"+c,filters:this.ui.createFileSystemFilters(u)});null!=d?(localStorage.setItem(".lastSaveDir",e.dirname(d)),this.fileObject=new Object,this.fileObject.path=d,this.fileObject.name=d.replace(/^.*[\\\/]/,""),this.fileObject.type="utf-8",l()):this.ui.spinner.stop()}else l()}}else"function"==typeof s&&s({message:"This is a bug, please report!"})},LocalFile.prototype.saveAs=function(e,t,i){var s=require("@electron/remote").dialog;const r=require("path");var l=localStorage.getItem(".lastSaveDir"),o=this.getFilename(),a=null;if(""==o&&null!=this.fileObject&&null!=this.fileObject.name){var c=(o=this.fileObject.name).lastIndexOf(".");c>0&&(a=o.substring(c+1),o=o.substring(0,c))}var u=s.showSaveDialogSync({defaultPath:(l||n())+"/"+o,filters:this.ui.createFileSystemFilters(a)});null!=u&&(localStorage.setItem(".lastSaveDir",r.dirname(u)),this.fileObject=new Object,this.fileObject.path=u,this.fileObject.name=u.replace(/^.*[\\\/]/,""),this.fileObject.type="utf-8",this.save(!1,t,i,null,!0))},App.prototype.createFileSystemFilters=function(e){for(var t=[],i=0;i<this.editor.diagramFileTypes.length;i++){var n={name:mxResources.get(this.editor.diagramFileTypes[i].description)+" (."+this.editor.diagramFileTypes[i].extension+")",extensions:[this.editor.diagramFileTypes[i].extension]};this.editor.diagramFileTypes[i].extension==e?t.splice(0,0,n):t.push(n)}return t},App.prototype.saveFile=function(e){var t=this.getCurrentFile();null!=t&&(e||null==t.getTitle()?t.saveAs(null,mxUtils.bind(this,(function(){EditorUi.enableDrafts&&t.removeDraft(),t.handleFileSuccess(!0)})),mxUtils.bind(this,(function(e){t.handleFileError(e,!0)}))):t.save(!0,mxUtils.bind(this,(function(){EditorUi.enableDrafts&&t.removeDraft(),t.handleFileSuccess(!0)})),mxUtils.bind(this,(function(e){t.handleFileError(e,!0)}))))},App.prototype.saveLibrary=function(e,t,i,n,s,r,l){n=null!=n?n:this.mode,s=null!=s&&s,r=null!=r&&r;var o=this.createLibraryDataFromImages(t),a=mxUtils.bind(this,(function(e){this.spinner.stop(),null!=l&&l(),null!=e&&this.handleError(e,mxResources.get("errorSavingFile"))}));if(null==i&&(i=new LocalLibrary(this,o,e)),s||this.spinner.spin(document.body,mxResources.get("saving"))){i.setData(o);var c=mxUtils.bind(this,(function(){i.save(!0,mxUtils.bind(this,(function(e){this.spinner.stop(),this.hideDialog(!0),r||this.libraryLoaded(i,t),null!=l&&l()})),a)}));if(e!=i.getTitle()){var u=i.getHash();i.rename(e,mxUtils.bind(this,(function(e){i.constructor!=LocalLibrary&&u!=i.getHash()&&(mxSettings.removeCustomLibrary(u),mxSettings.addCustomLibrary(i.getHash())),this.removeLibrarySidebar(u),c()})),a)}else c()}},App.prototype.checkForUpdates=function(){require("electron").ipcRenderer.send("checkForUpdates")},App.prototype.toggleSpellCheck=function(){require("electron").ipcRenderer.send("toggleSpellCheck")};var d=App.prototype.updateHeader;App.prototype.updateHeader=function(){if(d.apply(this,arguments),"1"!=urlParams.winCtrls)return;document.querySelectorAll(".geMenuItem").forEach((e=>e.style.webkitAppRegion="no-drag"));var e=document.querySelector(".geMenubarContainer");"1"==urlParams.sketch&&(e=this.titlebar),e.style.webkitAppRegion="drag",this.windowControls=document.createElement("div"),this.windowControls.id="geWindow-controls",this.windowControls.innerHTML='<div class="button" id="min-button"> <svg width="10" height="1" viewBox="0 0 11 1"> <path d="m11 0v1h-11v-1z" stroke-width=".26208"/> </svg></div><div class="button" id="max-button"> <svg width="10" height="10" viewBox="0 0 10 10"> <path d="m10-1.6667e-6v10h-10v-10zm-1.001 1.001h-7.998v7.998h7.998z" stroke-width=".25" /> </svg></div><div class="button" id="restore-button"> <svg width="10" height="10" viewBox="0 0 11 11"> <path d="m11 8.7978h-2.2021v2.2022h-8.7979v-8.7978h2.2021v-2.2022h8.7979zm-3.2979-5.5h-6.6012v6.6011h6.6012zm2.1968-2.1968h-6.6012v1.1011h5.5v5.5h1.1011z" stroke-width=".275" /> </svg></div><div class="button" id="close-button"> <svg width="10" height="10" viewBox="0 0 12 12"> <path d="m6.8496 6 5.1504 5.1504-0.84961 0.84961-5.1504-5.1504-5.1504 5.1504-0.84961-0.84961 5.1504-5.1504-5.1504-5.1504 0.84961-0.84961 5.1504 5.1504 5.1504-5.1504 0.84961 0.84961z" stroke-width=".3" /> </svg></div>',"atlas"==uiTheme?this.windowControls.style.top="9px":"1"==urlParams.sketch&&(this.windowControls.style.top="-1px"),e.appendChild(this.windowControls);var t=mxUtils.bind(this,(function(){"atlas"==uiTheme||Editor.isDarkMode()?(this.windowControls.style.fill="white",document.querySelectorAll("#geWindow-controls .button").forEach((e=>e.className="button dark"))):(this.windowControls.style.fill="#999",document.querySelectorAll("#geWindow-controls .button").forEach((e=>e.className="button white")))}));t(),this.addListener("darkModeChanged",t),null!=this.appIcon&&(this.appIcon.style.webkitAppRegion="no-drag"),null!=this.menubar&&(this.menubar.container.style.webkitAppRegion="no-drag","atlas"==uiTheme&&(this.menubar.container.style.width="fit-content"),null!=this.menubar.langIcon&&(this.menubar.langIcon.parentNode.removeChild(this.menubar.langIcon),e.appendChild(this.menubar.langIcon)));const i=require("@electron/remote"),n=i.getCurrentWindow();function s(){n.isMaximized()?document.body.classList.add("geMaximized"):document.body.classList.remove("geMaximized")}window.onbeforeunload=e=>{n.removeAllListeners()},document.getElementById("min-button").addEventListener("click",(e=>{n.minimize()})),document.getElementById("max-button").addEventListener("click",(e=>{n.maximize()})),document.getElementById("restore-button").addEventListener("click",(e=>{n.unmaximize()})),document.getElementById("close-button").addEventListener("click",(e=>{n.close()})),s(),n.on("maximize",s),n.on("unmaximize",s),n.on("resize",s)};var h=App.prototype.updateDocumentTitle;App.prototype.updateDocumentTitle=function(){h.apply(this,arguments),null!=this.titlebar&&null!=this.titlebar.firstChild&&(this.titlebar.firstChild.innerHTML=mxUtils.htmlEntities(document.title))},EditorUi.prototype.writeImageToClipboard=function(e,t,i,n){try{const n=require("@electron/remote");n.clipboard.write({image:n.nativeImage.createFromDataURL(e),html:'<img src="'+e+'" width="'+t+'" height="'+i+'">'})}catch(e){n(e)}};var m=EditorUi.prototype.updateActionStates;function f(e,t){this.reqType=e,this.reqObj=t}EditorUi.prototype.updateActionStates=function(){m.apply(this,arguments);var e=this.getCurrentFile(),t=null!=e&&null!=e.fileObject;this.actions.get("synchronize").setEnabled(t)},EditorUi.prototype.saveLocalFile=function(e,t,i,n,s,r){this.saveData(t,s,e,i,n)},EditorUi.prototype.saveRequest=function(e,t,i,n,s,r){var l=i(null,"1");null!=l&&this.spinner.spin(document.body,mxResources.get("saving"))&&l.send(mxUtils.bind(this,(function(){this.spinner.stop(),l.getStatus()>=200&&l.getStatus()<=299?this.saveData(e,t,l.getText(),r,!0):this.handleError({message:mxResources.get("errorSavingFile")})})),mxUtils.bind(this,(function(e){this.spinner.stop(),this.handleError(e)})))},mxUtils.extend(f,mxXmlRequest),f.prototype.send=function(e,t){const i=require("electron").ipcRenderer;i.send(this.reqType,this.reqObj),i.once(this.reqType+"-success",((t,n)=>{this.response=n,e(),i.send(this.reqType+"-finalize")})),i.once(this.reqType+"-error",((e,n)=>{this.hasError=!0,t(n),i.send(this.reqType+"-finalize")}))},f.prototype.getStatus=function(){return this.hasError?500:200},f.prototype.getText=function(){return this.response},EditorUi.prototype.createDownloadRequest=function(e,t,i,n,s,r,l,o,a,c){var u=this.editor.graph,p=(u.getGraphBounds(),this.getFileData(!0,null,null,null,i,0!=r&&"xmlpng"!=t)),d=null,h=null,m=c?"1":"0";if("pdf"==t&&0==r&&(h="1"),"xmlpng"==t&&(m="1",t="png",null!=this.pages&&null!=this.currentPage))for(var g=0;g<this.pages.length;g++)if(this.pages[g]==this.currentPage){d=g;break}var b=u.background;"png"==t&&s?b=mxConstants.NONE:s||null!=b&&b!=mxConstants.NONE||(b="#ffffff");var v={globalVars:u.getExportVariables()};return a&&(v.grid={size:u.gridSize,steps:u.view.gridSteps,color:u.view.gridColor}),new f("export",{format:t,xml:p,from:d,bg:null!=b?b:mxConstants.NONE,filename:null!=e?e:null,allPages:h,base64:n,embedXml:m,extras:encodeURIComponent(JSON.stringify(v)),scale:l,border:o})};var g=ExportDialog.exportFile;ExportDialog.exportFile=function(e,t,i,n,s,r,l){var o=e.editor.graph;if("xml"==i||"svg"==i)return g.apply(this,arguments);var a=e.getFileData(!0,null,null,null,null,!0),c=o.getGraphBounds(),u=Math.floor(c.width*s/o.view.scale),p=Math.floor(c.height*s/o.view.scale);if(e.hideDialog(),"png"!=i&&"jpg"!=i&&"jpeg"!=i||!e.isExportToCanvas()){var d={globalVars:o.getExportVariables()};e.saveRequest(t,i,(function(e,t){return new f("export",{format:i,xml:a,bg:null!=n?n:mxConstants.NONE,filename:null!=e?e:null,w:u,h:p,border:r,base64:t||"0",extras:JSON.stringify(d),dpi:l>0?l:null})}))}else"png"==i?e.exportImage(s,null==n||"none"==n,!0,!1,!1,r,!0,!1,null,null,l):e.exportImage(s,!1,!0,!1,!1,r,!0,!1,"jpeg")},EditorUi.prototype.saveData=function(e,t,i,s,r){var l=require("@electron/remote").dialog,o=null!=this.spinner&&null!=this.spinner.pause?this.spinner.pause():function(){};const a=require("path");var c=localStorage.getItem(".lastExpDir");window.setTimeout(mxUtils.bind(this,(function(){var s={defaultPath:(c||n())+"/"+e},u=null;switch(t){case"xmlpng":case"png":u=[{name:"PNG Images",extensions:["png"]}];break;case"jpg":case"jpeg":u=[{name:"JPEG Images",extensions:["jpg","jpeg"]}];break;case"svg":u=[{name:"SVG Images",extensions:["svg"]}];break;case"pdf":u=[{name:"PDF Documents",extensions:["pdf"]}];break;case"vsdx":u=[{name:"VSDX Documents",extensions:["vsdx"]}];break;case"html":u=[{name:"HTML Documents",extensions:["html"]}];break;case"xml":u=[{name:"XML Documents",extensions:["xml"]}]}s.filters=u;var p=l.showSaveDialogSync(s);if(null!=p)if(localStorage.setItem(".lastExpDir",a.dirname(p)),null==i||0==i.length)this.handleError({message:mxResources.get("errorSavingFile")});else{var d=require("fs");o();var h=new Object;h.path=p,h.name=p.replace(/^.*[\\\/]/,""),h.type=r?"base64":"utf-8",d.writeFile(h.path,i,h.type,mxUtils.bind(this,(function(e){this.spinner.stop(),e&&this.handleError({message:mxResources.get("errorSavingFile")})})))}})),50)},EditorUi.prototype.addBeforeUnloadListener=function(){},EditorUi.prototype.loadDesktopLib=function(e,t,i){this.readGraphFile(mxUtils.bind(this,(function(e,i,n){var s=new DesktopLibrary(this,i,e);this.loadLibrary(s),t(s)})),i,e)}}();