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

1 line
243 KiB
JavaScript
Raw Normal View History

2020-05-22 17:58:13 +02:00
var e;(function(){var e;e=class extends this.OS.GUI.BaseApplication{constructor(e){super("Preview",e)}main(){return this.currfile=void 0,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.set("onchange",e=>this.setViewScale(e.data)),this.btreset.set("onbtclick",e=>(this.zoom.set("value",100),this.setViewScale(100))),this.btnext.set("onbtclick",e=>{var t;if(t=parseInt($(this.txtpage).val()),!isNaN(t))return $(this.txtpage).val(t+1),this.gotoPage()}),this.btprev.set("onbtclick",e=>{var t;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)return this.gotoPage()}),PDFJS.workerSrc=(this.path()+"/pdf.worker.js").asFileHandle().getlink(),this.pdf=void 0,this.img=void 0,this.bindKey("ALT-O",()=>this.actionFile(this.name+"-Open")),this.bindKey("CTRL-X",()=>this.actionFile(this.name+"-Close")),this.zoom.set("max",200),this.zoom.set("value",100),this.open(this.currfile)}open(e){if(e)return this.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(){var e;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.get("value")/100,!1).catch(t=>this.error(__("Unable to render page {0}",e),t))}renderFile(){var e;if(e=this.currfile.info.mime)return this.pdf=void 0,this.img=void 0,$(this.view).empty(),this.zoom.set("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){var t,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;return r=(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){return new Promise((n,i)=>{var a;return a=`${this.currfile.info.name} (${this.currfile.info.size} Kb)`,e>this.pdf.numPages?n():this.pdf.getPage(e).then(s=>{var o,l,c,u,h;return h=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(){return n()})).catch((function(e){return i(__e(e))})):n()}).catch((function(e){return i(__e(e))}))})}renderPDF(){return this.load(new Promise((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){return t(__e(e))})))).catch((function(e){return t(__e(e))})))).catch((function(e){return t(__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.currfi