import{r as t,d as i,h as o,e}from"./p-d00c3523.js";import{p as s}from"./p-42da9819.js";import"./p-b66a001a.js";s.GlobalWorkerOptions.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${s.version}/pdf.worker.min.js`;let n=class{constructor(o){t(this,o),this.pageRendered=i(this,"pageRendered",7),this.pdfZoom=1,this.isDocumentLoading=!1}async componentWillLoad(){this.isDocumentLoading=!0,this.pdfDocument=null,this.pdfDocumentLoader&&this.pdfDocumentLoader.cancel(),this.pdfDocumentLoader=s.getDocument(this.src),this.pdfDocument=await this.pdfDocumentLoader.promise,this.isDocumentLoading=!1}componentDidLoad(){const t=this.pdfContext.offsetWidth,i=this.pdfContext.offsetHeight;this.pdfContext.setAttribute("style",`width: ${t}px`),this.pdfContext.style.width=`${t} px`,this.pdfContext.setAttribute("style",`height: ${i}px`),this.pdfContext.style.height=`${i} px`}async updateSrc(t,i){t!==i&&(this.isDocumentLoading=!0,this.pdfDocument=null,console.log("reload?"),this.pdfDocument=await s.getDocument(t).promise,this.isDocumentLoading=!1)}handleZoom(t){this.pdfZoom=t}handleMouseEnter(){var t;null===(t=this.btns)||void 0===t||t.classList.add("active"),clearTimeout(this.zoomButtonsHideTimeout)}handleMouseLeave(){this.zoomButtonsHideTimeout=setTimeout((()=>{var t;return null===(t=this.btns)||void 0===t?void 0:t.classList.remove("active")}),1e3)}handleMouseMove(){this.handleMouseEnter(),this.handleMouseLeave()}async renderPage(t,i,o=0){const e=await this.pdfDocument.getPage(t);let s=e.getViewport({scale:1,rotation:o});s=e.getViewport({scale:this.pdfZoom*((this.pdfContext.offsetWidth-50)/s.width),rotation:o}),i.width=s.width,i.height=s.height,i.parentElement.setAttribute("style",`width:${i.width}px;height:${i.height}px`),i.parentElement.style.width=`${i.width}px`,i.parentElement.style.height=`${i.height}px`;const n={viewport:s,canvasContext:i.getContext("2d")};await e.render(n).promise,this.pageRendered.emit(t)}renderPageCard(t){return o("ion-card",null,o("canvas",{key:t,ref:i=>this.renderPage(t,i)}))}renderDocument(){return this.pdfDocument&&!this.isDocumentLoading?[...Array(this.pdfDocument.numPages).keys()].map((t=>this.renderPageCard(t+1))):o("center",null,o("ion-spinner",{name:"dots"}))}renderButtons(){return this.pdfDocument?o("ion-buttons",{ref:t=>this.btns=t,class:"pdf-zoom-buttons active",onMouseEnter:()=>this.handleMouseEnter(),onMouseLeave:()=>this.handleMouseLeave()},o("ion-button",{onClick:()=>this.handleZoom(this.pdfZoom-.1)},o("ion-icon",{slot:"icon-only",name:"remove-outline"})),o("ion-button",{onClick:()=>this.handleZoom(1)},o("ion-icon",{slot:"icon-only",name:"refresh"})),o("ion-button",{onClick:()=>this.handleZoom(this.pdfZoom+.1)},o("ion-icon",{slot:"icon-only",name:"add"}))):null}render(){return o("div",{style:{height:this.height,display:"block",textAlign:"-webkit-center"},ref:t=>this.pdfContext=t,class:"pdf-context"},o("div",{class:"pdf-container",onMouseMove:()=>this.handleMouseMove()},this.renderDocument()),this.renderButtons())}get component(){return e(this)}static get watchers(){return{src:["updateSrc"]}}};n.style="akord-pdf-viewer canvas{margin:0 auto;display:block;border-radius:4px}akord-pdf-viewer ion-card{transform:translate(-50%);left:50%}akord-pdf-viewer .pdf-canvas{margin:0;margin-bottom:6px;width:calc(100vw - 32px)}akord-pdf-viewer .pdf-viewer-container{width:100%}akord-pdf-viewer .pdf-controlls-container{display:flex;position:fixed;bottom:24px;left:45%;background:#2e2e2e;padding:10px 16px 7px;border-radius:4px;font-style:normal;color:#fff;font-style:normal !important}akord-pdf-viewer .pdf-context{transform:translateZ(0);width:100%;height:100%}akord-pdf-viewer .pdf-container{position:relative;overflow:scroll;width:100%;height:100%;background-color:#ddd}akord-pdf-viewer .pdf-zoom-buttons.active{opacity:1}akord-pdf-viewer .pdf-zoom-buttons{position:sticky;display:inline-block;bottom:5px;left:50%;background-color:rgba(60, 60, 60, 0.4);border-radius:10px;transform:translate(-50%, 0);transition:opacity ease-out 0.5s}";export{n as akord_pdf_viewer}