vare;(function(){vare;e=classextendsthis.OS.application.BaseApplication{constructor(e){super("Preview",e)}main(){returnthis.currfile=void0,this.args&&this.args.length>0&&(this.currfile=this.args[0].path.asFileHandle()),this.view=this.find("view"),this.status=this.find("status"),this.zoom=this.find("zoom"),this.btnext=this.find("btnext"),this.btprev=this.find("btprev"),this.btreset=this.find("btreset"),this.txtpage=this.find("txtpage"),this.zoom.onvaluechange=e=>this.setViewScale(e.data),this.btreset.onbtclick=e=>(this.zoom.value=100,this.setViewScale(100)),this.btnext.onbtclick=e=>{vart;if(t=parseInt($(this.txtpage).val()),!isNaN(t))return$(this.txtpage).val(t+1),this.gotoPage()},this.btprev.onbtclick=e=>{vart;if(t=parseInt($(this.txtpage).val()),!isNaN(t))return$(this.txtpage).val(t-1),this.gotoPage()},$(this.txtpage).keyup(e=>{if(13===e.which&&this.pdf)returnthis.gotoPage()}),PDFJS.workerSrc=(this.path()+"/pdf.worker.js").asFileHandle().getlink(),this.pdf=void0,this.img=void0,this.bindKey("ALT-O",()=>this.actionFile(this.name+"-Open")),this.bindKey("CTRL-X",()=>this.actionFile(this.name+"-Close")),this.zoom.max=200,this.zoom.value=100,this.open(this.currfile)}open(e){if(e)returnthis.currfile!==e&&(this.currfile=e),e.onready().then(()=>(e.info.size=(e.info.size/1024).toFixed(2),this.renderFile())).catch(t=>this.error(__("File not found {0}",e.path),t))}gotoPage(){vare;if(this.pdf&&(e=parseInt($(this.txtpage).val()),!isNaN(e)&&!(e<=0||e>this.pdf.numPages)))return$(this.view).empty(),this.renderPDFPages(e,this.zoom.value/100,!1).catch(t=>this.error(__("Unable to render page {0}",e),t))}renderFile(){vare;if(e=this.currfile.info.mime)returnthis.pdf=void0,this.img=void0,$(this.view).empty(),this.zoom.value=100,e.match(/^[^\/]+\/.*pdf.*/g)?this.renderPDF():e.match(/image\/.*svg.*/g)?this.renderSVG():e.match(/image\/.*/g)?this.renderImage():this.notify(__("Mime type {0} is not supported",file.info.mime))}setStatus(e){return$(this.status).html(e)}setViewScale(e){vart,r,n,i,a,s;if(this.currfile){if(a=e/100,(i=this.currfile.info.mime).match(/^[^\/]+\/.*pdf.*/g)){if(!this.pdf)return;return$(this.view).empty(),this.load(this.renderPDFPages(1,a)).catch(e=>this.error(__("Unable to set view scale"),e))}if(i.match(/image\/.*svg.*/g))return$($(this.view).children()[0]).css("width",Math.round(e)+"%").css("height",Math.round(e)+"%");if(i.match(/image\/.*/g)){if(!this.img)return;returnr=(t=$(this.view).children()[0]).getContext("2d"),s=this.img.width*a,n=this.img.height*a,t.height=n,t.width=s,r.clearRect(0,0,t.width,t.height),r.scale(a,a),r.drawImage(this.img,0,0)}}}renderPDFPages(e,t,r){returnnewPromise((n,i)=>{vara;returna=`${this.currfile.info.name} (${this.currfile.info.size} Kb)`,e>this.pdf.numPages?n():this.pdf.getPage(e).then(s=>{varo,l,c,u,h;returnh=s.getViewport(t),c=$("<div/>").attr("id","page-"+(s.pageIndex+1)).attr("scale",t).addClass("pdf-page"),$(this.view).append(c),o=$("<canvas>")[0],c.append(o),l=o.getContext("2d"),o.height=h.height,o.width=h.width,u={canvasContext:l,viewport:h},s.render(u),s._canvas=o,this.setStatus(`${a} - page ${e}/${this.pdf.numPages} loaded`),r?this.renderPDFPages(e+1,t,r).then((function(){returnn()})).catch((function(e){returni(__e(e))})):n()}).catch((function(e){returni(__e(e))}))})}renderPDF(){returnthis.load(newPromise((e,t)=>this.currfile.read("binary").then(r=>($(this.view).removeClass(),PDFJS.getDocument({data:r}).then(r=>(this.pdf=r,this.renderPDFPages(1,1,!1).then(()=>($(this.txtpage).val("1"),e())).catch((function(e){returnt(__e(e))})))).catch((function(e){returnt(__e(e))})))).catch((function(e){returnt(__e(e))})))).catch(e=>this.error(__("Unable to view file: {0}",this.currfile.path),e))}renderSVG(){return$(this.view).attr("class","image"),this.currfile.read().then(e=>(this.view.innerHTML=e,$($(this.view).children()[0]).css("width","100%").css("height","100%"))).catch(e=>this.error(__("Unable to read file: {0}",this.currfile.path),e))}renderImage(){return$(this.view).attr("class","image"),this.currfile.read("binary").then(e=>{vart,r,n;returnn=new