(function(){varA;(A=classextendsthis.OS.application.BaseApplication{constructor(A){super("Clipper",A)}main(){varA;if(this.scene=this.find("scene"),this.wrapper=this.find("wrapper"),this.cropwin=this.find("cropwin"),this.dirty=!1,this.currfile="Untitled".asFileHandle(),$(this.cropwin).css("position","absolute").hide(),this.find("btnCptScreen").onbtclick=()=>this.capture(document.body,!0),this.find("btnCptWindow").onbtclick=()=>{varA,e,t,r,n,B,s;for(eins=[],n=OS.PM.processes)for(A=0,t=(B=n[e]).length;A<t;A++)r=B[A],0===OS.application[r.name].type&&s.push({text:r.scheme.apptitle,el:r.scheme,icon:r.meta().icon,iconclass:r.meta().iconclass});returnthis.openDialog("SelectionDialog",{title:"Select a window",data:s}).then(A=>{if(A)returnthis.capture(A.el)})},A=this.find("btnCrop"),this.cropselect=A=>{vare,t,r;returnt=$(this.cropwin).offset(),r=A.clientX-t.left,e=A.clientY-t.top,$(this.cropwin).css("width",r+"px").css("height",e+"px")},this.cropup=e=>($(window).off("mousemove",this.cropselect),$(window).off("mouseup",this.cropup),this.ask({text:__("Crop the selected zone ?")}).then(e=>{vart,r,n,B,s,o,i,a;if(A.enable=!0,A.selected=!1,t=$(this.cropwin).offset(),s=$(this.scene).offset(),i=t.left-s.left,a=t.top-s.top,o=$(this.cropwin).width(),B=$(this.cropwin).height(),$(this.cropwin).hide(),$(this.cropwin).css("width","0px").css("height","0px"),e)returnn=(r=this.scene.getContext("2d")).getImageData(i,a,o,B),this.scene.width=o,this.scene.height=B,r.putImageData(n,0,0),this.dirty=!0})),this.cropdown=e=>{vart;returnA.enable=!1,t=$(this.scheme).offset(),$(this.cropwin).css("left",e.clientX-t.left+"px").css("top",e.clientY-t.top+"px").show(),$(window).off("mousedown",this.cropdown),$(window).mousemove(this.cropselect),$(window).mouseup(this.cropup)},A.onbtclick=()=>A.selected?$(window).mousedown(this.cropdown):$(window).off("mousedown",this.cropdown),this.bindKey("CTRL-S",()=>this.actionFile(this.name+"-Save")),this.bindKey("ALT-W",()=>this.actionFile(this.name+"-Saveas")),this.notify(__("User ALT-S global shortcut to capture the entire VDE")),this._gui.bindKey("ALT-S",()=>{if(html2canvas)returnhtml2canvas(document.body).then(A=>this._gui.launch("Clipper",[A]))}),this.args&&1===this.args.length)returnthis.copycanvas(this.args[0])}copycanvas(A){returnthis.scene.height=A.height,this.scene.width=A.width,this.scene.getContext("2d").drawImage(A,0,0),this.dirty=!0}capture(A,e){returne&&this.hide(),this.load(newPromise((t,r)=>html2canvas(A).then(A=>(this.copycanvas(A),e&&this.show(),t())).catch((function(A){returnr(__e(A))})))).then(()=>this.notify(__("Screen captured"))).catch(A=>this.error(A.toString(),A))}menu(){return[{text:"__(File)",nodes:[{text:"__(Save)",dataid:this.name+"-Save",shortcut:"C-S"},{text:"__(Save as)",dataid:this.name+"-Saveas",shortcut:"A-W"}],onchildselect:A=>this.actionFile(A.data.item.data.dataid)}]}save(){returnthis.currfile.cache=this.scene.toDataURL("image/png"),this.currfile.write("base64").then(A=>(this.notify(__("File saved")),this.dirty=!1)).catch(A=>this.error(__("Cannot save to file: {0}",A.toString()),A))}actionFile(A){vare;switch(e=()=>this.openDialog("FileDialog",{title:__("Save as"),file:this.currfile}).then(A=>{vare;returne=A.file.path.asFileHandle(),"file"===A.file.type&&(e=e.parent()),this.currfile.setPath(`${e.path}/${A.name}`),this.save(this.currfile)}),A){casethis.name+"-Save":returnthis.currfile.basename?this.save():e();casethis.name+"-Saveas":returne()}}cleanup(A){if(this.dirty)returnA.preventDefault(),this.ask({title:__("Quit"),text:__("Quit without saving ?")}).then(A=>{if(A)returnthis.dirty=!1,this.quit()})}}).singleton=!0,this.OS.register("Clipper",A)}).call(this),