antosdk-apps/VizApp/build/debug/main.js

1 line
1.4 MiB
JavaScript
Raw Normal View History

2020-11-29 23:26:01 +01:00
var A;(function(){var A;(A=class A extends this.OS.application.BaseApplication{constructor(A){super("VizApp",A)}main(){return this.currfile=this.args&&this.args.length>0?this.args[0].path.asFileHandle():"Untitled".asFileHandle(),this.currfile.dirty=!1,this.datarea=this.find("datarea"),this.preview=this.find("preview"),this.btctn=this.find("btn-container"),this.previewSVG=void 0,$(this.preview).append(this.btctn),ace.config.set("basePath","scripts/ace"),this.editor=ace.edit(this.datarea),this.editor.setOptions({enableBasicAutocompletion:!0,enableLiveAutocompletion:!0,fontSize:"11pt"}),this.editor.getSession().setUseWrapMode(!0),this.editor.session.setMode("ace/mode/dot"),this.editor.setTheme("ace/theme/monokai"),this.editor.on("input",()=>this.editormux?(this.editormux=!1,!1):this.currfile.dirty?void 0:this.currfile.dirty=!0),this.currfile.basename||(this.editormux=!0,this.editor.setValue(A.dummydot),this.renderSVG(!1)),this.editor.container.addEventListener("keydown",A=>{if(13===A.keyCode)return this.renderSVG(!0)},!0),this.bindKey("CTRL-R",()=>this.renderSVG(!1)),this.bindKey("ALT-G",()=>this.export("SVG")),this.bindKey("ALT-P",()=>this.export("PNG")),this.bindKey("ALT-N",()=>this.actionFile(this.name+"-New")),this.bindKey("ALT-O",()=>this.actionFile(this.name+"-Open")),this.bindKey("CTRL-S",()=>this.actionFile(this.name+"-Save")),this.bindKey("ALT-W",()=>this.actionFile(this.name+"-Saveas")),this.on("hboxchange",()=>(this.editor.resize(),this.calibrate())),this.on("focus",()=>this.editor.focus()),this.find("btn-zoomin").onbtclick=A=>{if(this.pan)return this.pan.zoomIn()},this.find("btn-zoomout").onbtclick=A=>{if(this.pan)return this.pan.zoomOut()},this.find("btn-reset").onbtclick=A=>{if(this.pan)return this.pan.resetZoom()},this.open(this.currfile)}menu(){return[{text:"__(File)",nodes:[{text:"__(New)",dataid:this.name+"-New",shortcut:"A-N"},{text:"__(Open)",dataid:this.name+"-Open",shortcut:"A-O"},{text:"__(Save)",dataid:this.name+"-Save",shortcut:"C-S"},{text:"__(Save as)",dataid:this.name+"-Saveas",shortcut:"A-W"},{text:"__(Render)",dataid:this.name+"-Render",shortcut:"C-R"},{text:"__(Export as)",nodes:[{text:"SVG",shortcut:"A-G"},{text:"PNG",shortcut:"A-P"}],onchildselect:A=>this.export(A.data.item.data.text)}],onchildselect:A=>this.actionFile(A.data.item.data.dataid)}]}open(A){if("Untitled"!==A.path)return A.dirty=!1,A.read().then(e=>(this.currfile=A,this.editormux=!0,this.currfile.dirty=!1,this.editor.setValue(e),this.scheme.apptitle=""+this.currfile.basename,this.renderSVG(!1))).catch(A=>this.error(A.toString(),A))}save(A){return A.write("text/plain").then(e=>(A.dirty=!1,A.text=A.basename,this.scheme.apptitle=""+this.currfile.basename)).catch(A=>this.error(A.toString(),A))}actionFile(A){var e;switch(e=()=>this.openDialog("FileDialog",{title:__("Save as"),file:this.currfile}).then(A=>(this.currfile.setPath(`${A.file.path}/${A.name}`),this.save(this.currfile))).catch(A=>this.error(A.toString(),A)),A){case this.name+"-Open":return this.openDialog("FileDialog",{title:__("Open file")}).then((A,e)=>this.open(A.file.path.asFileHandle())).catch(A=>this.error(A.toString(),A));case this.name+"-Save":return this.currfile.cache=this.editor.getValue(),this.currfile.basename?this.save(this.currfile):e();case this.name+"-Saveas":return this.currfile.cache=this.editor.getValue(),e();case this.name+"-Render":return this.renderSVG(!1);case this.name+"-New":return this.currfile="Untitled".asFileHandle(),this.currfile.cache="",this.currfile.dirty=!1,this.editormux=!0,this.editor.setValue("")}}export(A){return this.openDialog("FileDialog",{title:__("Export as"),file:this.currfile}).then(e=>{var i,r,n;switch(i=`${e.file.path}/${e.name}`.asFileHandle(),n=new Viz,r=this.editor.getValue(),A){case"SVG":return n.renderSVGElement(r).then(e=>{var r;return r=new XMLSerializer,i.cache=r.serializeToString(e),i.write("text/plain").then(A=>this.notify(__("File exported to SVG"))).catch(e=>this.error(__("Cannot export to {0}: {1}",A,e.toString()),e))}).catch(A=>this.error(A.toString(),A));case"PNG":return n.renderImageElement(r).then(e=>{var r;re