let url="https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf",pdfDoc=null,pageNum=1,pageRendering=!1,pageNumPending=null,scale=1.5,zoomRange=.25,canvas=document.getElementById("the-canvas"),ctx=canvas.getContext("2d"),pageCountEl=document.getElementById("page_count"),pageNumInput=document.getElementById("page_num");function renderPage(n){pageRendering=!0,pdfDoc.getPage(n).then(e=>{var n=e.getViewport({scale:scale}),n=(canvas.width=n.width,canvas.height=n.height,{canvasContext:ctx,viewport:n});e.render(n).promise.then(()=>{pageRendering=!1,null!==pageNumPending&&(renderPage(pageNumPending),pageNumPending=null)})}).catch(e=>{console.error(`Error rendering page ${n}:`,e)}),pageNumInput.value=n}function queueRenderPage(e){pageRendering?pageNumPending=e:renderPage(e)}function onPrevPage(){1<pageNum&&queueRenderPage(--pageNum)}let prevButton=document.getElementById("prev");function onNextPage(){pageNum<pdfDoc.numPages&&queueRenderPage(++pageNum)}prevButton&&prevButton.addEventListener("click",onPrevPage);let nextButton=document.getElementById("next");function onZoomIn(){scale+=zoomRange,queueRenderPage(pageNum)}nextButton&&nextButton.addEventListener("click",onNextPage);let zoomInButton=document.getElementById("zoomin");function onZoomOut(){scale>zoomRange&&(scale-=zoomRange,queueRenderPage(pageNum))}zoomInButton&&zoomInButton.addEventListener("click",onZoomIn);let zoomOutButton=document.getElementById("zoomout");function onZoomFit(){scale=1,queueRenderPage(pageNum)}zoomOutButton&&zoomOutButton.addEventListener("click",onZoomOut);let zoomFitButton=document.getElementById("zoomfit");function onPageInputChange(e){var n=Number(e.target.value);1<=n&&n<=pdfDoc.numPages?queueRenderPage(pageNum=n):e.target.value=pageNum}function initPDFViewer(e){"undefined"==typeof pdfjsLib||"function"!=typeof pdfjsLib.getDocument?console.error("PDF.js is not available or not loaded."):e&&"string"==typeof e?pdfjsLib.getDocument(e).promise.then(e=>{pdfDoc=e,pageCountEl.textContent="/ "+pdfDoc.numPages,renderPage(pageNum)}).catch(e=>{console.error("Failed to load PDF:",e),alert("Error loading PDF document.")}):console.error("Invalid PDF URL:",e)}zoomFitButton&&zoomFitButton.addEventListener("click",onZoomFit),pageNumInput.addEventListener("change",onPageInputChange),initPDFViewer(url);