diff --git a/dist/pdfjs-viewer.compress.js b/dist/pdfjs-viewer.compress.js new file mode 100644 index 0000000..5dab4db --- /dev/null +++ b/dist/pdfjs-viewer.compress.js @@ -0,0 +1,2 @@ +/* Copyright 2021 Carlos A. (https://github.com/dealfonso); License: http://www.apache.org/licenses/LICENSE-2.0 */ +!function(exports,$){if(void 0===$)console.error("jQuery-like library not available");else{let defaults={visibleThreshold:.5,extraPagesToLoad:3,pageClass:"pdfpage",contentClass:"content-wrapper",onDocumentReady:()=>{},onNewPage:(t,e)=>{},onPageRender:(t,e)=>{},zoomValues:[.25,.5,.75,1,1.25,1.5,2,4,8],onZoomChange:t=>{},onActivePageChanged:(t,e)=>{},zoomFillArea:.95,emptyContent:()=>$('
'),renderingScale:1.5};class Zoomer{constructor(t,e={}){this.current=1,this.viewer=t,this.settings=Object.assign({},{zoomValues:[.25,.5,.75,1,1.25,1.5,2,4,8],fillArea:.9},e),this.settings.zoomValues=this.settings.zoomValues.sort()}get(e=null){if(null===e)return this.current;if(parseFloat(e)!=e){var i=this.viewer.getActivePage();let t=[];switch(e){case"in":e=this.current,0<(t=this.settings.zoomValues.filter(t=>et.2*e.clientHeight*this._zoom.current||Math.abs(e.scrollLeft-s.left)>.2*e.clientWidth*this._zoom.current)&&(s={top:e.scrollTop,left:e.scrollLeft},this._visiblePages()),i=!1)}.bind(this),this.$container.off("scroll"),this.$container.on("scroll",this.__scrollHandler)}_createSkeleton(t,e){var i={$div:null,width:0,height:0,loaded:!1},s=(void 0!==t.getViewport?(s=t.getViewport({rotation:this._rotation,scale:1}),i.width=s.width,i.height=s.height,i.loaded=!0):(i.width=t.width,i.height=t.height),console.assert(0`).attr("data-page",e).data("width",i.width).data("height",i.height).data("zoom",this._zoom.current).addClass(this.settings.pageClass).width(i.width*this._zoom.current).height(i.height*this._zoom.current),$(`
`).width(i.width).height(i.height));return i.$div.append(s),this._cleanPage(i.$div),i}_placeSkeleton(t,e){let i=e-1,s=null;for(;0this.pdf.numPages)return!1;let e=t="string"==typeof t?parseInt(t):t;if("number"==typeof t){if(void 0===this.pages[t])return!1;e=this.pages[t].$div}return this._areaOfPageVisible(e)>e.outerWidth()*e.outerHeight()*this.settings.visibleThreshold}_visiblePages(i=!1){let s=0,a=null;if(0===this.pages.length)this._visibles=[],this._setActivePage(0);else{var n=this.pages.filter(function(t){var e=this._areaOfPageVisible(t.$div);return e>s&&(s=e,a=t.$div.data("page")),0t.$div);this._setActivePage(a);let e=n.map(t=>parseInt($(t).data("page")));if(0");var s=o.get(0),h=s.getContext("2d");return s.height=n.height*a,s.width=n.width*a,s.getContext("2d"),t.render({canvasContext:h,viewport:n,transform:1!==a?[a,0,0,a,0,0]:null}).promise.then(function(){return this._setPageContent(i.$div,o),this._documentReady&&("function"==typeof this.settings.onPageRender&&this.settings.onPageRender.call(this,i.$div.get(0),e),this.$container.get(0).dispatchEvent(new CustomEvent("pagerender",{detail:{pageNumber:e,page:i.$div.get(0)}}))),i}.bind(this))}getActivePage(){return null===this._activePage||null===this.pdf||this._activePage<1||this._activePage>this.pdf.numPages?null:this.pages[this._activePage].$div}getPages(){return this.pages}getPageCount(){return null===this.pdf?0:this.pdf.numPages}next(){this._activePaget.replace(/[A-Z]/g,t=>"-"+t.toLowerCase());let $target=$(target),result={};if(0<$target.length)for(var originalAttributeName in $target=$($target[0]),attributeDefaults){let attributeName=camelcaseToSnakecase(originalAttributeName),attributeValue=$target.attr(attributeName);if(null!=attributeValue){switch(typeof attributeDefaults[originalAttributeName]){case"float":try{attributeValue=parseFloat(attributeValue)}catch(_){}break;case"number":try{attributeValue=parseInt(attributeValue)}catch(_){}break;case"function":let functionString=attributeValue;attributeValue=function(){eval(functionString)}.bind(target[0])}result[originalAttributeName]=attributeValue}}return result}function init(e){let i=recoverAttributes(e,Object.assign({pdfDocument:"",initialZoom:""},defaults));if(null!=i.pdfDocument){let t=new PDFjsViewer($(e),i);t.loadDocument(i.pdfDocument).then(function(){null!=i.initialZoom&&t.setZoom(i.initialZoom)}),e.get(0).pdfViewer=t}}$(function(){$(".pdfjs-viewer").each(function(){init($(this))})}),exports.PDFjsViewer=PDFjsViewer}}(window,window._$??window.jQuery??void 0); \ No newline at end of file diff --git a/dist/pdfjs-viewer.compress.js.map b/dist/pdfjs-viewer.compress.js.map new file mode 100644 index 0000000..f998fe7 --- /dev/null +++ b/dist/pdfjs-viewer.compress.js.map @@ -0,0 +1 @@ +{"version":3,"file":"pdfjs-viewer.compress.js.map","sources":["pdfjs-viewer.js"],"sourcesContent":["/**\n Copyright 2021 Carlos A. (https://github.com/dealfonso)\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\n(function (exports, $) {\n\t\"use strict\";\n\tif ($ === undefined) {\n\t\tconsole.error(\"jQuery-like library not available\");\n\t\treturn;\n\t}\n\tlet defaults = {\n\t\tvisibleThreshold: .5,\n\t\textraPagesToLoad: 3,\n\t\tpageClass: \"pdfpage\",\n\t\tcontentClass: \"content-wrapper\",\n\t\tonDocumentReady: () => {},\n\t\tonNewPage: (page, i) => {},\n\t\tonPageRender: (page, i) => {},\n\t\tzoomValues: [.25, .5, .75, 1, 1.25, 1.5, 2, 4, 8],\n\t\tonZoomChange: zoomlevel => {},\n\t\tonActivePageChanged: (page, i) => {},\n\t\tzoomFillArea: .95,\n\t\temptyContent: () => $('
'),\n\t\trenderingScale: 1.5\n\t};\n\tclass Zoomer {\n\t\tconstructor(viewer, options = {}) {\n\t\t\tlet defaults = {\n\t\t\t\tzoomValues: [.25, .5, .75, 1, 1.25, 1.5, 2, 4, 8],\n\t\t\t\tfillArea: .9\n\t\t\t};\n\t\t\tthis.current = 1;\n\t\t\tthis.viewer = viewer;\n\t\t\tthis.settings = Object.assign({}, defaults, options);\n\t\t\tthis.settings.zoomValues = this.settings.zoomValues.sort();\n\t\t}\n\t\tget(zoom = null) {\n\t\t\tif (zoom === null) {\n\t\t\t\treturn this.current;\n\t\t\t}\n\t\t\tif (parseFloat(zoom) == zoom) {\n\t\t\t\treturn zoom;\n\t\t\t}\n\t\t\tlet $activepage = this.viewer.getActivePage();\n\t\t\tlet zoomValues = [];\n\t\t\tswitch (zoom) {\n\t\t\tcase \"in\":\n\t\t\t\tzoom = this.current;\n\t\t\t\tzoomValues = this.settings.zoomValues.filter(x => x > zoom);\n\t\t\t\tif (zoomValues.length > 0) {\n\t\t\t\t\tzoom = Math.min(...zoomValues);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"out\":\n\t\t\t\tzoom = this.current;\n\t\t\t\tzoomValues = this.settings.zoomValues.filter(x => x < zoom);\n\t\t\t\tif (zoomValues.length > 0) {\n\t\t\t\t\tzoom = Math.max(...zoomValues);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"fit\":\n\t\t\t\tzoom = Math.min(this.get(\"width\"), this.get(\"height\"));\n\t\t\t\tbreak;\n\t\t\tcase \"width\":\n\t\t\t\tzoom = this.settings.fillArea * this.viewer.$container.width() / $activepage.data(\"width\");\n\t\t\t\tbreak;\n\t\t\tcase \"height\":\n\t\t\t\tzoom = this.settings.fillArea * this.viewer.$container.height() / $activepage.data(\"height\");\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tzoom = this.current;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\treturn zoom;\n\t\t}\n\t\tzoomPages(zoom) {\n\t\t\tzoom = this.get(zoom);\n\t\t\tthis.viewer.getPages().forEach(function (page) {\n\t\t\t\tlet $page = page.$div;\n\t\t\t\tlet c_width = $page.data(\"width\");\n\t\t\t\tlet c_height = $page.data(\"height\");\n\t\t\t\t$page.width(c_width * zoom).height(c_height * zoom);\n\t\t\t\t$page.data(\"zoom\", zoom);\n\t\t\t\t$page.find(`.${this.viewer.settings.contentClass}`).width(c_width * zoom).height(c_height * zoom);\n\t\t\t}.bind(this));\n\t\t\tthis.current = zoom;\n\t\t}\n\t}\n\tclass PDFjsViewer {\n\t\tversion = \"2.0.0\";\n\t\tconstructor($container, options = {}) {\n\t\t\tthis.settings = Object.assign({}, defaults, options);\n\t\t\tthis._zoom = new Zoomer(this, {\n\t\t\t\tzoomValues: this.settings.zoomValues,\n\t\t\t\tfillArea: this.settings.zoomFillArea\n\t\t\t});\n\t\t\t$container = $($container);\n\t\t\tthis.$container = $container;\n\t\t\t$container.get(0)._pdfjsViewer = this;\n\t\t\tthis._setScrollListener();\n\t\t\tthis.pages = [];\n\t\t\tthis.pdf = null;\n\t\t\tthis._documentReady = false;\n\t\t}\n\t\tsetZoom(zoom) {\n\t\t\tlet container = this.$container.get(0);\n\t\t\tlet prevzoom = this._zoom.current;\n\t\t\tlet prevScroll = {\n\t\t\t\ttop: container.scrollTop,\n\t\t\t\tleft: container.scrollLeft\n\t\t\t};\n\t\t\tthis._zoom.zoomPages(zoom);\n\t\t\tcontainer.scrollLeft = prevScroll.left * this._zoom.current / prevzoom;\n\t\t\tcontainer.scrollTop = prevScroll.top * this._zoom.current / prevzoom;\n\t\t\tthis._visiblePages(true);\n\t\t\tif (this._documentReady) {\n\t\t\t\tif (typeof this.settings.onZoomChange === \"function\") this.settings.onZoomChange.call(this, this._zoom.current);\n\t\t\t\tthis.$container.get(0).dispatchEvent(new CustomEvent(\"zoomchange\", {\n\t\t\t\t\tdetail: {\n\t\t\t\t\t\tzoom: this._zoom.current\n\t\t\t\t\t}\n\t\t\t\t}));\n\t\t\t}\n\t\t\treturn this._zoom.current;\n\t\t}\n\t\tgetZoom() {\n\t\t\treturn this._zoom.current;\n\t\t}\n\t\t_cleanPage($page) {\n\t\t\tlet $emptyContent = this.settings.emptyContent();\n\t\t\t$page.find(`.${this.settings.contentClass}`).html(\"\").append($emptyContent);\n\t\t}\n\t\t_setPageContent($page, $content) {\n\t\t\t$page.find(`.${this.settings.contentClass}`).html(\"\").append($content);\n\t\t}\n\t\trefreshAll() {\n\t\t\tthis._visiblePages(true);\n\t\t}\n\t\t_setScrollListener() {\n\t\t\tlet scrollLock = false;\n\t\t\tlet scrollPos = {\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0\n\t\t\t};\n\t\t\tthis.__scrollHandler = function (e) {\n\t\t\t\tif (scrollLock === true) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tscrollLock = true;\n\t\t\t\tlet container = this.$container.get(0);\n\t\t\t\tif (Math.abs(container.scrollTop - scrollPos.top) > container.clientHeight * .2 * this._zoom.current || Math.abs(container.scrollLeft - scrollPos.left) > container.clientWidth * .2 * this._zoom.current) {\n\t\t\t\t\tscrollPos = {\n\t\t\t\t\t\ttop: container.scrollTop,\n\t\t\t\t\t\tleft: container.scrollLeft\n\t\t\t\t\t};\n\t\t\t\t\tthis._visiblePages();\n\t\t\t\t}\n\t\t\t\tscrollLock = false;\n\t\t\t}.bind(this);\n\t\t\tthis.$container.off(\"scroll\");\n\t\t\tthis.$container.on(\"scroll\", this.__scrollHandler);\n\t\t}\n\t\t_createSkeleton(page, i) {\n\t\t\tlet pageinfo = {\n\t\t\t\t$div: null,\n\t\t\t\twidth: 0,\n\t\t\t\theight: 0,\n\t\t\t\tloaded: false\n\t\t\t};\n\t\t\tif (page.getViewport !== undefined) {\n\t\t\t\tlet viewport = page.getViewport({\n\t\t\t\t\trotation: this._rotation,\n\t\t\t\t\tscale: 1\n\t\t\t\t});\n\t\t\t\tpageinfo.width = viewport.width;\n\t\t\t\tpageinfo.height = viewport.height;\n\t\t\t\tpageinfo.loaded = true;\n\t\t\t} else {\n\t\t\t\tpageinfo.width = page.width;\n\t\t\t\tpageinfo.height = page.height;\n\t\t\t}\n\t\t\tconsole.assert(pageinfo.width > 0 && pageinfo.height > 0, \"Page width and height must be greater than 0\");\n\t\t\tpageinfo.$div = $(`
`).attr(\"data-page\", i).data(\"width\", pageinfo.width).data(\"height\", pageinfo.height).data(\"zoom\", this._zoom.current).addClass(this.settings.pageClass).width(pageinfo.width * this._zoom.current).height(pageinfo.height * this._zoom.current);\n\t\t\tlet $content = $(`
`).width(pageinfo.width).height(pageinfo.height);\n\t\t\tpageinfo.$div.append($content);\n\t\t\tthis._cleanPage(pageinfo.$div);\n\t\t\treturn pageinfo;\n\t\t}\n\t\t_placeSkeleton(pageinfo, i) {\n\t\t\tlet prevpage = i - 1;\n\t\t\tlet $prevpage = null;\n\t\t\twhile (prevpage > 0 && ($prevpage = this.$container.find(`.${this.settings.pageClass}[data-page=\"${prevpage}\"]`)).length === 0) {\n\t\t\t\tprevpage--;\n\t\t\t}\n\t\t\tif (prevpage === 0) {\n\t\t\t\tthis.$container.append(pageinfo.$div);\n\t\t\t} else {\n\t\t\t\t$prevpage.after(pageinfo.$div);\n\t\t\t}\n\t\t}\n\t\t_createSkeletons(pageinfo) {\n\t\t\tfor (let i = 1; i <= this.pageCount; i++) {\n\t\t\t\tif (this.pages[i] === undefined) {\n\t\t\t\t\tpageinfo = this._createSkeleton(pageinfo, i);\n\t\t\t\t\tthis.pages[i] = pageinfo;\n\t\t\t\t\tthis._placeSkeleton(pageinfo, i);\n\t\t\t\t\tif (typeof this.settings.onNewPage === \"function\") {\n\t\t\t\t\t\tthis.settings.onNewPage.call(this, pageinfo.$div.get(0), i);\n\t\t\t\t\t}\n\t\t\t\t\tthis.$container.get(0).dispatchEvent(new CustomEvent(\"newpage\", {\n\t\t\t\t\t\tdetail: {\n\t\t\t\t\t\t\tpageNumber: i,\n\t\t\t\t\t\t\tpage: pageinfo.$div.get(0)\n\t\t\t\t\t\t}\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t_setActivePage(i) {\n\t\t\tif (this._activePage !== i) {\n\t\t\t\tthis._activePage = i;\n\t\t\t\tlet activePage = this.getActivePage();\n\t\t\t\tif (this._documentReady) {\n\t\t\t\t\tactivePage = activePage == null ? null : activePage.get(0);\n\t\t\t\t\tif (typeof this.settings.onActivePageChanged === \"function\") {\n\t\t\t\t\t\tthis.settings.onActivePageChanged.call(this, activePage, i);\n\t\t\t\t\t}\n\t\t\t\t\tthis.$container.get(0).dispatchEvent(new CustomEvent(\"activepagechanged\", {\n\t\t\t\t\t\tdetail: {\n\t\t\t\t\t\t\tactivePageNumber: i,\n\t\t\t\t\t\t\tactivePage: activePage\n\t\t\t\t\t\t}\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t_areaOfPageVisible($page) {\n\t\t\tif ($page === undefined) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tlet c_offset = this.$container.offset();\n\t\t\tlet c_width = this.$container.width();\n\t\t\tlet c_height = this.$container.height();\n\t\t\tlet position = $page.offset();\n\t\t\tposition.top -= c_offset.top;\n\t\t\tposition.left -= c_offset.left;\n\t\t\tposition.bottom = position.top + $page.outerHeight();\n\t\t\tposition.right = position.left + $page.outerWidth();\n\t\t\tlet page_y0 = Math.min(Math.max(position.top, 0), c_height);\n\t\t\tlet page_y1 = Math.min(Math.max($page.outerHeight() + position.top, 0), c_height);\n\t\t\tlet page_x0 = Math.min(Math.max(position.left, 0), c_width);\n\t\t\tlet page_x1 = Math.min(Math.max($page.outerWidth() + position.left, 0), c_width);\n\t\t\tlet vis_x = page_x1 - page_x0;\n\t\t\tlet vis_y = page_y1 - page_y0;\n\t\t\treturn vis_x * vis_y;\n\t\t}\n\t\tisPageVisible(i) {\n\t\t\tif (this.pdf === null || i === undefined || i === null || i < 1 || i > this.pdf.numPages) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (typeof i === \"string\") {\n\t\t\t\ti = parseInt(i);\n\t\t\t}\n\t\t\tlet $page = i;\n\t\t\tif (typeof i === \"number\") {\n\t\t\t\tif (this.pages[i] === undefined) return false;\n\t\t\t\t$page = this.pages[i].$div;\n\t\t\t}\n\t\t\treturn this._areaOfPageVisible($page) > $page.outerWidth() * $page.outerHeight() * this.settings.visibleThreshold;\n\t\t}\n\t\t_visiblePages(forceRedraw = false) {\n\t\t\tlet max_area = 0;\n\t\t\tlet i_page = null;\n\t\t\tif (this.pages.length === 0) {\n\t\t\t\tthis._visibles = [];\n\t\t\t\tthis._setActivePage(0);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet $visibles = this.pages.filter(function (pageinfo) {\n\t\t\t\tlet areaVisible = this._areaOfPageVisible(pageinfo.$div);\n\t\t\t\tif (areaVisible > max_area) {\n\t\t\t\t\tmax_area = areaVisible;\n\t\t\t\t\ti_page = pageinfo.$div.data(\"page\");\n\t\t\t\t}\n\t\t\t\treturn areaVisible > 0;\n\t\t\t}.bind(this)).map(x => x.$div);\n\t\t\tthis._setActivePage(i_page);\n\t\t\tlet visibles = $visibles.map(x => {\n\t\t\t\treturn parseInt($(x).data(\"page\"));\n\t\t\t});\n\t\t\tif (visibles.length > 0) {\n\t\t\t\tlet minVisible = Math.min(...visibles);\n\t\t\t\tlet maxVisible = Math.max(...visibles);\n\t\t\t\tfor (let i = Math.max(1, minVisible - this.settings.extraPagesToLoad); i < minVisible; i++) {\n\t\t\t\t\tif (!visibles.includes(i)) visibles.push(i);\n\t\t\t\t}\n\t\t\t\tfor (let i = maxVisible + 1; i <= Math.min(maxVisible + this.settings.extraPagesToLoad, this.pdf.numPages); i++) {\n\t\t\t\t\tif (!visibles.includes(i)) visibles.push(i);\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet nowVisibles = visibles;\n\t\t\tif (!forceRedraw) {\n\t\t\t\tnowVisibles = visibles.filter(function (x) {\n\t\t\t\t\treturn !this._visibles.includes(x);\n\t\t\t\t}.bind(this));\n\t\t\t}\n\t\t\tthis._visibles.filter(function (x) {\n\t\t\t\treturn !visibles.includes(x);\n\t\t\t}).forEach(function (i) {\n\t\t\t\tthis._cleanPage(this.pages[i].$div);\n\t\t\t}.bind(this));\n\t\t\tthis._visibles = visibles;\n\t\t\tthis.loadPages(...nowVisibles);\n\t\t}\n\t\tloadPages(...pages) {\n\t\t\tthis._pagesLoading.push(...pages);\n\t\t\tif (this._loading) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis._loadingTask();\n\t\t}\n\t\t_loadingTask() {\n\t\t\tthis._loading = true;\n\t\t\tif (this._pagesLoading.length > 0) {\n\t\t\t\tlet pagei = this._pagesLoading.shift();\n\t\t\t\tthis.pdf.getPage(pagei).then(function (page) {\n\t\t\t\t\tthis._renderPage(page, pagei);\n\t\t\t\t}.bind(this)).then(function (pageinfo) {\n\t\t\t\t\tif (this._pagesLoading.length > 0) {\n\t\t\t\t\t\tthis._loadingTask();\n\t\t\t\t\t}\n\t\t\t\t}.bind(this));\n\t\t\t}\n\t\t\tthis._loading = false;\n\t\t}\n\t\tscrollToPage(i) {\n\t\t\tif (this.pages.length === 0 || this.pages[i] === undefined) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet $page = this.pages[i].$div;\n\t\t\tif ($page.length === 0) {\n\t\t\t\tconsole.warn(`Page ${i} not found`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet position = $page.position();\n\t\t\tlet containerPosition = this.$container.position();\n\t\t\tif (position !== undefined) {\n\t\t\t\tthis.$container.get(0).scrollTop = this.$container.get(0).scrollTop + position.top - containerPosition.top;\n\t\t\t\tthis.$container.get(0).scrollLeft = this.$container.get(0).scrollLeft + position.left - containerPosition.left;\n\t\t\t}\n\t\t\tthis._setActivePage(i);\n\t\t}\n\t\t_renderPage(page, i) {\n\t\t\tlet pageinfo = this.pages[i];\n\t\t\tlet scale = this.settings.renderingScale;\n\t\t\tlet pixel_ratio = window.devicePixelRatio || 1;\n\t\t\tlet viewport = page.getViewport({\n\t\t\t\trotation: this._rotation,\n\t\t\t\tscale: this._zoom.current * scale\n\t\t\t});\n\t\t\tpageinfo.width = viewport.width / this._zoom.current / scale;\n\t\t\tpageinfo.height = viewport.height / this._zoom.current / scale;\n\t\t\tpageinfo.$div.data(\"width\", pageinfo.width);\n\t\t\tpageinfo.$div.data(\"height\", pageinfo.height);\n\t\t\tpageinfo.$div.width(pageinfo.width * this._zoom.current);\n\t\t\tpageinfo.$div.height(pageinfo.height * this._zoom.current);\n\t\t\tpageinfo.loaded = true;\n\t\t\tlet $canvas = $(\"\");\n\t\t\tlet canvas = $canvas.get(0);\n\t\t\tlet context = canvas.getContext(\"2d\");\n\t\t\tcanvas.height = viewport.height * pixel_ratio;\n\t\t\tcanvas.width = viewport.width * pixel_ratio;\n\t\t\tcanvas.getContext(\"2d\");\n\t\t\tvar transform = pixel_ratio !== 1 ? [pixel_ratio, 0, 0, pixel_ratio, 0, 0] : null;\n\t\t\tvar renderContext = {\n\t\t\t\tcanvasContext: context,\n\t\t\t\tviewport: viewport,\n\t\t\t\ttransform: transform\n\t\t\t};\n\t\t\treturn page.render(renderContext).promise.then(function () {\n\t\t\t\tthis._setPageContent(pageinfo.$div, $canvas);\n\t\t\t\tif (this._documentReady) {\n\t\t\t\t\tif (typeof this.settings.onPageRender === \"function\") {\n\t\t\t\t\t\tthis.settings.onPageRender.call(this, pageinfo.$div.get(0), i);\n\t\t\t\t\t}\n\t\t\t\t\tthis.$container.get(0).dispatchEvent(new CustomEvent(\"pagerender\", {\n\t\t\t\t\t\tdetail: {\n\t\t\t\t\t\t\tpageNumber: i,\n\t\t\t\t\t\t\tpage: pageinfo.$div.get(0)\n\t\t\t\t\t\t}\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t\treturn pageinfo;\n\t\t\t}.bind(this));\n\t\t}\n\t\tgetActivePage() {\n\t\t\tif (this._activePage === null || this.pdf === null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tif (this._activePage < 1 || this._activePage > this.pdf.numPages) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn this.pages[this._activePage].$div;\n\t\t}\n\t\tgetPages() {\n\t\t\treturn this.pages;\n\t\t}\n\t\tgetPageCount() {\n\t\t\tif (this.pdf === null) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\treturn this.pdf.numPages;\n\t\t}\n\t\tnext() {\n\t\t\tif (this._activePage < this.pdf.numPages) {\n\t\t\t\tthis.scrollToPage(this._activePage + 1);\n\t\t\t}\n\t\t}\n\t\tprev() {\n\t\t\tif (this._activePage > 1) {\n\t\t\t\tthis.scrollToPage(this._activePage - 1);\n\t\t\t}\n\t\t}\n\t\tfirst() {\n\t\t\tif (this._activePage !== 1) {\n\t\t\t\tthis.scrollToPage(1);\n\t\t\t}\n\t\t}\n\t\tlast() {\n\t\t\tif (this.pdf === null) return;\n\t\t\tif (this._activePage !== this.pdf.numPages) {\n\t\t\t\tthis.scrollToPage(this.pdf.numPages);\n\t\t\t}\n\t\t}\n\t\trotate(deg, accumulate = false) {\n\t\t\tif (accumulate) {\n\t\t\t\tdeg = deg + this._rotation;\n\t\t\t}\n\t\t\tthis._rotation = deg;\n\t\t\tlet container = this.$container.get(0);\n\t\t\tlet prevScroll = {\n\t\t\t\ttop: container.scrollTop,\n\t\t\t\tleft: container.scrollLeft,\n\t\t\t\theight: container.scrollHeight,\n\t\t\t\twidth: container.scrollWidth\n\t\t\t};\n\t\t\treturn this.forceViewerInitialization().then(function () {\n\t\t\t\tlet newScroll = {\n\t\t\t\t\ttop: container.scrollTop,\n\t\t\t\t\tleft: container.scrollLeft,\n\t\t\t\t\theight: container.scrollHeight,\n\t\t\t\t\twidth: container.scrollWidth\n\t\t\t\t};\n\t\t\t\tcontainer.scrollTop = prevScroll.top * (newScroll.height / prevScroll.height);\n\t\t\t\tcontainer.scrollLeft = prevScroll.left * (newScroll.width / prevScroll.width);\n\t\t\t}.bind(this));\n\t\t}\n\t\tforceViewerInitialization() {\n\t\t\tthis.pages = [];\n\t\t\tthis.$container.find(`.${this.settings.pageClass}`).remove();\n\t\t\tthis._pagesLoading = [];\n\t\t\tthis._loading = false;\n\t\t\tthis._visibles = [];\n\t\t\tthis._activePage = null;\n\t\t\treturn this.pdf.getPage(1).then(function (page) {\n\t\t\t\tthis._createSkeletons(page);\n\t\t\t\tthis._visiblePages();\n\t\t\t\tthis._setActivePage(1);\n\t\t\t}.bind(this));\n\t\t}\n\t\tasync loadDocument(document) {\n\t\t\tthis._documentReady = false;\n\t\t\tthis.pages = [];\n\t\t\tthis.$container.find(`.${this.settings.pageClass}`).remove();\n\t\t\tthis.pdf = null;\n\t\t\tlet loadingTask = pdfjsLib.getDocument(document);\n\t\t\treturn loadingTask.promise.then(function (pdf) {\n\t\t\t\tthis.pdf = pdf;\n\t\t\t\tthis.pageCount = pdf.numPages;\n\t\t\t\tthis._rotation = 0;\n\t\t\t\treturn this.forceViewerInitialization();\n\t\t\t}.bind(this)).then(function () {\n\t\t\t\tif (typeof this.settings.onDocumentReady === \"function\") {\n\t\t\t\t\tthis.settings.onDocumentReady.call(this);\n\t\t\t\t}\n\t\t\t\tthis.$container.get(0).dispatchEvent(new CustomEvent(\"documentready\", {\n\t\t\t\t\tdetail: {\n\t\t\t\t\t\tdocument: this.pdf\n\t\t\t\t\t}\n\t\t\t\t}));\n\t\t\t\tthis._setActivePage(0);\n\t\t\t\tthis._documentReady = true;\n\t\t\t\tthis._setActivePage(1);\n\t\t\t}.bind(this));\n\t\t}\n\t}\n\n\tfunction recoverAttributes(target, attributeDefaults) {\n\t\tconst camelcaseToSnakecase = str => str.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);\n\t\tlet $target = $(target);\n\t\tlet result = {};\n\t\tif ($target.length > 0) {\n\t\t\t$target = $($target[0]);\n\t\t\tfor (let originalAttributeName in attributeDefaults) {\n\t\t\t\tlet attributeName = camelcaseToSnakecase(originalAttributeName);\n\t\t\t\tlet attributeValue = $target.attr(attributeName);\n\t\t\t\tif (attributeValue != null) {\n\t\t\t\t\tswitch (typeof attributeDefaults[originalAttributeName]) {\n\t\t\t\t\tcase \"float\":\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tattributeValue = parseFloat(attributeValue);\n\t\t\t\t\t\t} catch (_) {}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"number\":\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tattributeValue = parseInt(attributeValue);\n\t\t\t\t\t\t} catch (_) {}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"function\":\n\t\t\t\t\t\tlet functionString = attributeValue;\n\t\t\t\t\t\tattributeValue = function () {\n\t\t\t\t\t\t\teval(functionString);\n\t\t\t\t\t\t}.bind(target[0]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tresult[originalAttributeName] = attributeValue;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tfunction init(element) {\n\t\tlet options = recoverAttributes(element, Object.assign({\n\t\t\tpdfDocument: \"\",\n\t\t\tinitialZoom: \"\"\n\t\t}, defaults));\n\t\tif (options[\"pdfDocument\"] != null) {\n\t\t\tlet pdfViewer = new PDFjsViewer($(element), options);\n\t\t\tpdfViewer.loadDocument(options[\"pdfDocument\"]).then(function () {\n\t\t\t\tif (options[\"initialZoom\"] != null) {\n\t\t\t\t\tpdfViewer.setZoom(options[\"initialZoom\"]);\n\t\t\t\t}\n\t\t\t});\n\t\t\telement.get(0).pdfViewer = pdfViewer;\n\t\t}\n\t}\n\t$(function () {\n\t\t$(\".pdfjs-viewer\").each(function () {\n\t\t\tlet $viewer = $(this);\n\t\t\tinit($viewer);\n\t\t});\n\t});\n\texports.PDFjsViewer = PDFjsViewer;\n})(window, window._$ ?? window.jQuery ?? undefined);\n"],"names":["exports","$","undefined","console","error","let","defaults","visibleThreshold","extraPagesToLoad","pageClass","contentClass","onDocumentReady","onNewPage","page","i","onPageRender","zoomValues","onZoomChange","zoomlevel","onActivePageChanged","zoomFillArea","emptyContent","renderingScale","Zoomer","constructor","viewer","options","this","current","settings","Object","assign","fillArea","sort","get","zoom","parseFloat","$activepage","getActivePage","filter","x","length","Math","min","max","$container","width","data","height","zoomPages","getPages","forEach","$page","$div","c_width","c_height","find","bind","PDFjsViewer","version","_zoom","_pdfjsViewer","_setScrollListener","pages","pdf","_documentReady","setZoom","container","prevzoom","prevScroll","scrollTop","scrollLeft","_visiblePages","call","dispatchEvent","CustomEvent","detail","getZoom","_cleanPage","$emptyContent","html","append","_setPageContent","$content","refreshAll","scrollLock","scrollPos","top","left","__scrollHandler","e","abs","clientHeight","clientWidth","off","on","_createSkeleton","pageinfo","loaded","getViewport","viewport","rotation","_rotation","scale","assert","attr","addClass","_placeSkeleton","prevpage","$prevpage","after","_createSkeletons","pageCount","pageNumber","_setActivePage","_activePage","activePage","activePageNumber","_areaOfPageVisible","position","page_y0","page_y1","page_x0","c_offset","offset","bottom","outerHeight","right","outerWidth","isPageVisible","numPages","parseInt","forceRedraw","max_area","i_page","_visibles","$visibles","areaVisible","map","visibles","minVisible","maxVisible","includes","push","nowVisibles","loadPages","_pagesLoading","_loading","_loadingTask","pagei","shift","getPage","then","_renderPage","scrollToPage","containerPosition","warn","pixel_ratio","window","devicePixelRatio","$canvas","canvas","context","getContext","render","canvasContext","transform","promise","getPageCount","next","prev","first","last","rotate","deg","accumulate","scrollHeight","scrollWidth","forceViewerInitialization","newScroll","remove","loadDocument","document","pdfjsLib","getDocument","recoverAttributes","target","attributeDefaults","camelcaseToSnakecase","str","replace","letter","toLowerCase","$target","result","originalAttributeName","attributeName","attributeValue","_","functionString","eval","init","element","pdfDocument","initialZoom","pdfViewer","each","_$","jQuery"],"mappings":";AAgBA,CAAA,SAAWA,QAASC,GAEnB,GAAUC,KAAAA,IAAND,EACHE,QAAQC,MAAM,mCAAmC,MADlD,CAIAC,IAAIC,SAAW,CACdC,iBAAkB,GAClBC,iBAAkB,EAClBC,UAAW,UACXC,aAAc,kBACdC,gBAAiB,OACjBC,UAAW,CAACC,EAAMC,OAClBC,aAAc,CAACF,EAAMC,OACrBE,WAAY,CAAC,IAAK,GAAI,IAAK,EAAG,KAAM,IAAK,EAAG,EAAG,GAC/CC,aAAcC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QxK,IAAI,CAAC,EAAE2K,UAAYA,CAC5B,CACD,CACA5M,EAAE,WACDA,EAAE,eAAe,EAAE6M,KAAK,WAEvBL,KADcxM,EAAE0B,IAAI,CACR,CACb,CAAC,CACF,CAAC,EACD3B,QAAQ0D,YAAcA,WAliBtB,CAmiBA,EAAEoG,OAAQA,OAAOiD,IAAMjD,OAAOkD,QAAU9M,KAAAA,CAAS"} \ No newline at end of file diff --git a/pdfjs-viewer.css b/dist/pdfjs-viewer.css similarity index 100% rename from pdfjs-viewer.css rename to dist/pdfjs-viewer.css diff --git a/dist/pdfjs-viewer.js b/dist/pdfjs-viewer.js new file mode 100644 index 0000000..c911c17 --- /dev/null +++ b/dist/pdfjs-viewer.js @@ -0,0 +1,569 @@ +/** + Copyright 2021 Carlos A. (https://github.com/dealfonso) + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +(function (exports, $) { + "use strict"; + if ($ === undefined) { + console.error("jQuery-like library not available"); + return; + } + let defaults = { + visibleThreshold: .5, + extraPagesToLoad: 3, + pageClass: "pdfpage", + contentClass: "content-wrapper", + onDocumentReady: () => {}, + onNewPage: (page, i) => {}, + onPageRender: (page, i) => {}, + zoomValues: [.25, .5, .75, 1, 1.25, 1.5, 2, 4, 8], + onZoomChange: zoomlevel => {}, + onActivePageChanged: (page, i) => {}, + zoomFillArea: .95, + emptyContent: () => $('
'), + renderingScale: 1.5 + }; + class Zoomer { + constructor(viewer, options = {}) { + let defaults = { + zoomValues: [.25, .5, .75, 1, 1.25, 1.5, 2, 4, 8], + fillArea: .9 + }; + this.current = 1; + this.viewer = viewer; + this.settings = Object.assign({}, defaults, options); + this.settings.zoomValues = this.settings.zoomValues.sort(); + } + get(zoom = null) { + if (zoom === null) { + return this.current; + } + if (parseFloat(zoom) == zoom) { + return zoom; + } + let $activepage = this.viewer.getActivePage(); + let zoomValues = []; + switch (zoom) { + case "in": + zoom = this.current; + zoomValues = this.settings.zoomValues.filter(x => x > zoom); + if (zoomValues.length > 0) { + zoom = Math.min(...zoomValues); + } + break; + case "out": + zoom = this.current; + zoomValues = this.settings.zoomValues.filter(x => x < zoom); + if (zoomValues.length > 0) { + zoom = Math.max(...zoomValues); + } + break; + case "fit": + zoom = Math.min(this.get("width"), this.get("height")); + break; + case "width": + zoom = this.settings.fillArea * this.viewer.$container.width() / $activepage.data("width"); + break; + case "height": + zoom = this.settings.fillArea * this.viewer.$container.height() / $activepage.data("height"); + break; + default: + zoom = this.current; + break; + } + return zoom; + } + zoomPages(zoom) { + zoom = this.get(zoom); + this.viewer.getPages().forEach(function (page) { + let $page = page.$div; + let c_width = $page.data("width"); + let c_height = $page.data("height"); + $page.width(c_width * zoom).height(c_height * zoom); + $page.data("zoom", zoom); + $page.find(`.${this.viewer.settings.contentClass}`).width(c_width * zoom).height(c_height * zoom); + }.bind(this)); + this.current = zoom; + } + } + class PDFjsViewer { + version = "2.0.0"; + constructor($container, options = {}) { + this.settings = Object.assign({}, defaults, options); + this._zoom = new Zoomer(this, { + zoomValues: this.settings.zoomValues, + fillArea: this.settings.zoomFillArea + }); + $container = $($container); + this.$container = $container; + $container.get(0)._pdfjsViewer = this; + this._setScrollListener(); + this.pages = []; + this.pdf = null; + this._documentReady = false; + } + setZoom(zoom) { + let container = this.$container.get(0); + let prevzoom = this._zoom.current; + let prevScroll = { + top: container.scrollTop, + left: container.scrollLeft + }; + this._zoom.zoomPages(zoom); + container.scrollLeft = prevScroll.left * this._zoom.current / prevzoom; + container.scrollTop = prevScroll.top * this._zoom.current / prevzoom; + this._visiblePages(true); + if (this._documentReady) { + if (typeof this.settings.onZoomChange === "function") this.settings.onZoomChange.call(this, this._zoom.current); + this.$container.get(0).dispatchEvent(new CustomEvent("zoomchange", { + detail: { + zoom: this._zoom.current + } + })); + } + return this._zoom.current; + } + getZoom() { + return this._zoom.current; + } + _cleanPage($page) { + let $emptyContent = this.settings.emptyContent(); + $page.find(`.${this.settings.contentClass}`).html("").append($emptyContent); + } + _setPageContent($page, $content) { + $page.find(`.${this.settings.contentClass}`).html("").append($content); + } + refreshAll() { + this._visiblePages(true); + } + _setScrollListener() { + let scrollLock = false; + let scrollPos = { + top: 0, + left: 0 + }; + this.__scrollHandler = function (e) { + if (scrollLock === true) { + return; + } + scrollLock = true; + let container = this.$container.get(0); + if (Math.abs(container.scrollTop - scrollPos.top) > container.clientHeight * .2 * this._zoom.current || Math.abs(container.scrollLeft - scrollPos.left) > container.clientWidth * .2 * this._zoom.current) { + scrollPos = { + top: container.scrollTop, + left: container.scrollLeft + }; + this._visiblePages(); + } + scrollLock = false; + }.bind(this); + this.$container.off("scroll"); + this.$container.on("scroll", this.__scrollHandler); + } + _createSkeleton(page, i) { + let pageinfo = { + $div: null, + width: 0, + height: 0, + loaded: false + }; + if (page.getViewport !== undefined) { + let viewport = page.getViewport({ + rotation: this._rotation, + scale: 1 + }); + pageinfo.width = viewport.width; + pageinfo.height = viewport.height; + pageinfo.loaded = true; + } else { + pageinfo.width = page.width; + pageinfo.height = page.height; + } + console.assert(pageinfo.width > 0 && pageinfo.height > 0, "Page width and height must be greater than 0"); + pageinfo.$div = $(`
`).attr("data-page", i).data("width", pageinfo.width).data("height", pageinfo.height).data("zoom", this._zoom.current).addClass(this.settings.pageClass).width(pageinfo.width * this._zoom.current).height(pageinfo.height * this._zoom.current); + let $content = $(`
`).width(pageinfo.width).height(pageinfo.height); + pageinfo.$div.append($content); + this._cleanPage(pageinfo.$div); + return pageinfo; + } + _placeSkeleton(pageinfo, i) { + let prevpage = i - 1; + let $prevpage = null; + while (prevpage > 0 && ($prevpage = this.$container.find(`.${this.settings.pageClass}[data-page="${prevpage}"]`)).length === 0) { + prevpage--; + } + if (prevpage === 0) { + this.$container.append(pageinfo.$div); + } else { + $prevpage.after(pageinfo.$div); + } + } + _createSkeletons(pageinfo) { + for (let i = 1; i <= this.pageCount; i++) { + if (this.pages[i] === undefined) { + pageinfo = this._createSkeleton(pageinfo, i); + this.pages[i] = pageinfo; + this._placeSkeleton(pageinfo, i); + if (typeof this.settings.onNewPage === "function") { + this.settings.onNewPage.call(this, pageinfo.$div.get(0), i); + } + this.$container.get(0).dispatchEvent(new CustomEvent("newpage", { + detail: { + pageNumber: i, + page: pageinfo.$div.get(0) + } + })); + } + } + } + _setActivePage(i) { + if (this._activePage !== i) { + this._activePage = i; + let activePage = this.getActivePage(); + if (this._documentReady) { + activePage = activePage == null ? null : activePage.get(0); + if (typeof this.settings.onActivePageChanged === "function") { + this.settings.onActivePageChanged.call(this, activePage, i); + } + this.$container.get(0).dispatchEvent(new CustomEvent("activepagechanged", { + detail: { + activePageNumber: i, + activePage: activePage + } + })); + } + } + } + _areaOfPageVisible($page) { + if ($page === undefined) { + return 0; + } + let c_offset = this.$container.offset(); + let c_width = this.$container.width(); + let c_height = this.$container.height(); + let position = $page.offset(); + position.top -= c_offset.top; + position.left -= c_offset.left; + position.bottom = position.top + $page.outerHeight(); + position.right = position.left + $page.outerWidth(); + let page_y0 = Math.min(Math.max(position.top, 0), c_height); + let page_y1 = Math.min(Math.max($page.outerHeight() + position.top, 0), c_height); + let page_x0 = Math.min(Math.max(position.left, 0), c_width); + let page_x1 = Math.min(Math.max($page.outerWidth() + position.left, 0), c_width); + let vis_x = page_x1 - page_x0; + let vis_y = page_y1 - page_y0; + return vis_x * vis_y; + } + isPageVisible(i) { + if (this.pdf === null || i === undefined || i === null || i < 1 || i > this.pdf.numPages) { + return false; + } + if (typeof i === "string") { + i = parseInt(i); + } + let $page = i; + if (typeof i === "number") { + if (this.pages[i] === undefined) return false; + $page = this.pages[i].$div; + } + return this._areaOfPageVisible($page) > $page.outerWidth() * $page.outerHeight() * this.settings.visibleThreshold; + } + _visiblePages(forceRedraw = false) { + let max_area = 0; + let i_page = null; + if (this.pages.length === 0) { + this._visibles = []; + this._setActivePage(0); + return; + } + let $visibles = this.pages.filter(function (pageinfo) { + let areaVisible = this._areaOfPageVisible(pageinfo.$div); + if (areaVisible > max_area) { + max_area = areaVisible; + i_page = pageinfo.$div.data("page"); + } + return areaVisible > 0; + }.bind(this)).map(x => x.$div); + this._setActivePage(i_page); + let visibles = $visibles.map(x => { + return parseInt($(x).data("page")); + }); + if (visibles.length > 0) { + let minVisible = Math.min(...visibles); + let maxVisible = Math.max(...visibles); + for (let i = Math.max(1, minVisible - this.settings.extraPagesToLoad); i < minVisible; i++) { + if (!visibles.includes(i)) visibles.push(i); + } + for (let i = maxVisible + 1; i <= Math.min(maxVisible + this.settings.extraPagesToLoad, this.pdf.numPages); i++) { + if (!visibles.includes(i)) visibles.push(i); + } + } + let nowVisibles = visibles; + if (!forceRedraw) { + nowVisibles = visibles.filter(function (x) { + return !this._visibles.includes(x); + }.bind(this)); + } + this._visibles.filter(function (x) { + return !visibles.includes(x); + }).forEach(function (i) { + this._cleanPage(this.pages[i].$div); + }.bind(this)); + this._visibles = visibles; + this.loadPages(...nowVisibles); + } + loadPages(...pages) { + this._pagesLoading.push(...pages); + if (this._loading) { + return; + } + this._loadingTask(); + } + _loadingTask() { + this._loading = true; + if (this._pagesLoading.length > 0) { + let pagei = this._pagesLoading.shift(); + this.pdf.getPage(pagei).then(function (page) { + this._renderPage(page, pagei); + }.bind(this)).then(function (pageinfo) { + if (this._pagesLoading.length > 0) { + this._loadingTask(); + } + }.bind(this)); + } + this._loading = false; + } + scrollToPage(i) { + if (this.pages.length === 0 || this.pages[i] === undefined) { + return; + } + let $page = this.pages[i].$div; + if ($page.length === 0) { + console.warn(`Page ${i} not found`); + return; + } + let position = $page.position(); + let containerPosition = this.$container.position(); + if (position !== undefined) { + this.$container.get(0).scrollTop = this.$container.get(0).scrollTop + position.top - containerPosition.top; + this.$container.get(0).scrollLeft = this.$container.get(0).scrollLeft + position.left - containerPosition.left; + } + this._setActivePage(i); + } + _renderPage(page, i) { + let pageinfo = this.pages[i]; + let scale = this.settings.renderingScale; + let pixel_ratio = window.devicePixelRatio || 1; + let viewport = page.getViewport({ + rotation: this._rotation, + scale: this._zoom.current * scale + }); + pageinfo.width = viewport.width / this._zoom.current / scale; + pageinfo.height = viewport.height / this._zoom.current / scale; + pageinfo.$div.data("width", pageinfo.width); + pageinfo.$div.data("height", pageinfo.height); + pageinfo.$div.width(pageinfo.width * this._zoom.current); + pageinfo.$div.height(pageinfo.height * this._zoom.current); + pageinfo.loaded = true; + let $canvas = $(""); + let canvas = $canvas.get(0); + let context = canvas.getContext("2d"); + canvas.height = viewport.height * pixel_ratio; + canvas.width = viewport.width * pixel_ratio; + canvas.getContext("2d"); + var transform = pixel_ratio !== 1 ? [pixel_ratio, 0, 0, pixel_ratio, 0, 0] : null; + var renderContext = { + canvasContext: context, + viewport: viewport, + transform: transform + }; + return page.render(renderContext).promise.then(function () { + this._setPageContent(pageinfo.$div, $canvas); + if (this._documentReady) { + if (typeof this.settings.onPageRender === "function") { + this.settings.onPageRender.call(this, pageinfo.$div.get(0), i); + } + this.$container.get(0).dispatchEvent(new CustomEvent("pagerender", { + detail: { + pageNumber: i, + page: pageinfo.$div.get(0) + } + })); + } + return pageinfo; + }.bind(this)); + } + getActivePage() { + if (this._activePage === null || this.pdf === null) { + return null; + } + if (this._activePage < 1 || this._activePage > this.pdf.numPages) { + return null; + } + return this.pages[this._activePage].$div; + } + getPages() { + return this.pages; + } + getPageCount() { + if (this.pdf === null) { + return 0; + } + return this.pdf.numPages; + } + next() { + if (this._activePage < this.pdf.numPages) { + this.scrollToPage(this._activePage + 1); + } + } + prev() { + if (this._activePage > 1) { + this.scrollToPage(this._activePage - 1); + } + } + first() { + if (this._activePage !== 1) { + this.scrollToPage(1); + } + } + last() { + if (this.pdf === null) return; + if (this._activePage !== this.pdf.numPages) { + this.scrollToPage(this.pdf.numPages); + } + } + rotate(deg, accumulate = false) { + if (accumulate) { + deg = deg + this._rotation; + } + this._rotation = deg; + let container = this.$container.get(0); + let prevScroll = { + top: container.scrollTop, + left: container.scrollLeft, + height: container.scrollHeight, + width: container.scrollWidth + }; + return this.forceViewerInitialization().then(function () { + let newScroll = { + top: container.scrollTop, + left: container.scrollLeft, + height: container.scrollHeight, + width: container.scrollWidth + }; + container.scrollTop = prevScroll.top * (newScroll.height / prevScroll.height); + container.scrollLeft = prevScroll.left * (newScroll.width / prevScroll.width); + }.bind(this)); + } + forceViewerInitialization() { + this.pages = []; + this.$container.find(`.${this.settings.pageClass}`).remove(); + this._pagesLoading = []; + this._loading = false; + this._visibles = []; + this._activePage = null; + return this.pdf.getPage(1).then(function (page) { + this._createSkeletons(page); + this._visiblePages(); + this._setActivePage(1); + }.bind(this)); + } + async loadDocument(document) { + this._documentReady = false; + this.pages = []; + this.$container.find(`.${this.settings.pageClass}`).remove(); + this.pdf = null; + let loadingTask = pdfjsLib.getDocument(document); + return loadingTask.promise.then(function (pdf) { + this.pdf = pdf; + this.pageCount = pdf.numPages; + this._rotation = 0; + return this.forceViewerInitialization(); + }.bind(this)).then(function () { + if (typeof this.settings.onDocumentReady === "function") { + this.settings.onDocumentReady.call(this); + } + this.$container.get(0).dispatchEvent(new CustomEvent("documentready", { + detail: { + document: this.pdf + } + })); + this._setActivePage(0); + this._documentReady = true; + this._setActivePage(1); + }.bind(this)); + } + } + + function recoverAttributes(target, attributeDefaults) { + const camelcaseToSnakecase = str => str.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`); + let $target = $(target); + let result = {}; + if ($target.length > 0) { + $target = $($target[0]); + for (let originalAttributeName in attributeDefaults) { + let attributeName = camelcaseToSnakecase(originalAttributeName); + let attributeValue = $target.attr(attributeName); + if (attributeValue != null) { + switch (typeof attributeDefaults[originalAttributeName]) { + case "float": + try { + attributeValue = parseFloat(attributeValue); + } catch (_) {} + break; + case "number": + try { + attributeValue = parseInt(attributeValue); + } catch (_) {} + break; + case "function": + let functionString = attributeValue; + attributeValue = function () { + eval(functionString); + }.bind(target[0]); + break; + default: + break; + } + result[originalAttributeName] = attributeValue; + } + } + } + return result; + } + + function init(element) { + let options = recoverAttributes(element, Object.assign({ + pdfDocument: "", + initialZoom: "" + }, defaults)); + if (options["pdfDocument"] != null) { + let pdfViewer = new PDFjsViewer($(element), options); + pdfViewer.loadDocument(options["pdfDocument"]).then(function () { + if (options["initialZoom"] != null) { + pdfViewer.setZoom(options["initialZoom"]); + } + }); + element.get(0).pdfViewer = pdfViewer; + } + } + $(function () { + $(".pdfjs-viewer").each(function () { + let $viewer = $(this); + init($viewer); + }); + }); + exports.PDFjsViewer = PDFjsViewer; +})(window, window._$ ?? window.jQuery ?? undefined); diff --git a/pdfjs-viewer.min.css b/dist/pdfjs-viewer.min.css similarity index 95% rename from pdfjs-viewer.min.css rename to dist/pdfjs-viewer.min.css index bc59ea9..ea745a9 100644 --- a/pdfjs-viewer.min.css +++ b/dist/pdfjs-viewer.min.css @@ -1,2 +1,2 @@ -/* Copyright 2021 Carlos A. (https://github.com/dealfonso); License: http://www.apache.org/licenses/LICENSE-2.0 */ -.pdfjs-viewer{overflow:auto;border:1px solid #aaa;background:#ccc}.pdfjs-viewer.horizontal-scroll{display:flex}.pdfjs-viewer.horizontal-scroll .pdfpage{margin-left:1em;margin-top:.25em!important;margin-bottom:.25em!important;display:block}.pdfpage{position:relative;margin-bottom:1em;margin-top:1em;margin-left:auto;margin-right:auto;box-shadow:0 4px 8px 0 rgba(0,0,0,.1),0 6px 20px 0 rgba(0,0,0,.09)}.pdfpage canvas{position:absolute;left:0;top:0;height:100%;width:100%}.pdfpage.placeholder{display:flex;margin-bottom:0!important;margin-top:0!important;height:100%;width:100%}.pdfpage .content-wrapper{margin:0!important;padding:0!important;display:flex!important}.pdfpage .content-wrapper .loader{border:2px solid #f3f3f3;border-top:3px solid #3498db;border-radius:50%;width:24px;height:24px;animation:spin 1s linear infinite;margin:auto}@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}.pdfjs-toolbar{width:100%;height:32px;background:#ddd;z-index:100;vertical-align:middle;display:flex;margin:0;padding:0}.pdfjs-toolbar *{margin:auto 0}.pdfjs-toolbar span{margin-right:.5em;margin-left:.5em;width:4em!important;font-size:12px}.pdfjs-toolbar a.button,.pdfjs-toolbar button,.pdfjs-toolbar label.button{min-width:26px;height:28px;border:none;padding:2px 4px 0;margin:auto 1px;border-radius:2px;line-height:12px;font-size:14px;background-color:#ddd;cursor:pointer}.pdfjs-toolbar button i,.pdfjs-toolbar label.button i{font-size:26px;padding:0;margin:0}.pdfjs-toolbar a.button:hover,.pdfjs-toolbar button:hover,.pdfjs-toolbar label.button:hover{background-color:#ccc}button.pushed{background-color:#aaa!important}.pdfjs-toolbar a.button{color:inherit}.pdfjs-toolbar .divider{flex:1}.pdfjs-toolbar .v-sep{width:0;height:20px;border-left:1px solid #bbb}.pdfjs-toolbar .h-sep{width:100%;height:0;border-top:1px solid #bbb;margin:.25em 0}.pdfjs-toolbar .dropdown.dropdown-right,.pdfjs-toolbar .dropdown.right{float:right}.pdfjs-toolbar .dropdown.dropdown-right .dropdown-content,.pdfjs-toolbar .dropdown.right .dropdown-content{right:0;left:auto}.pdfjs-toolbar .dropdown-value{background-color:#ccc;padding:0 4px 2;cursor:pointer}.pdfjs-toolbar .dropdown-value i{width:auto;font-size:12px}.pdfjs-toolbar .dropdown-content{display:none;position:absolute;margin-top:0;background-color:#eee;min-width:10em;z-index:1;font-size:12px;box-shadow:0 4px 8px 0 rgba(0,0,0,.1),0 6px 20px 0 rgba(0,0,0,.09)}.pdfjs-toolbar .dropdown-content a{all:initial;font:inherit;color:#000;padding:6px 8px;text-decoration:none;display:flex;cursor:pointer}.pdfjs-toolbar .dropdown-content i{font-size:16px;padding-right:.5em}.pdfjs-toolbar .dropdown-content a:hover{background-color:#ddd}.dropdown .dropdown-content:hover,.pdfjs-toolbar .dropdown:hover .dropdown-content{display:block} \ No newline at end of file +.pdfjs-viewer{overflow:auto;border:1px solid #aaa;background:#ccc}.pdfjs-viewer.horizontal-scroll{display:flex}.pdfjs-viewer.horizontal-scroll .pdfpage{margin-left:1em;margin-top:.25em!important;margin-bottom:.25em!important;display:block}.pdfpage{position:relative;margin-bottom:1em;margin-top:1em;margin-left:auto;margin-right:auto;box-shadow:0 4px 8px 0 rgba(0,0,0,.1),0 6px 20px 0 rgba(0,0,0,.09)}.pdfpage canvas{position:absolute;left:0;top:0;height:100%;width:100%}.pdfpage.placeholder{display:flex;margin-bottom:0!important;margin-top:0!important;height:100%;width:100%}.pdfpage .content-wrapper{margin:0!important;padding:0!important;display:flex!important}.pdfpage .content-wrapper .loader{border:2px solid #f3f3f3;border-top:3px solid #3498db;border-radius:50%;width:24px;height:24px;animation:spin 1s linear infinite;margin:auto}@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}.pdfjs-toolbar{width:100%;height:32px;background:#ddd;z-index:100;vertical-align:middle;display:flex;margin:0;padding:0}.pdfjs-toolbar *{margin:auto 0}.pdfjs-toolbar span{margin-right:.5em;margin-left:.5em;width:4em!important;font-size:12px}.pdfjs-toolbar a.button,.pdfjs-toolbar button,.pdfjs-toolbar label.button{min-width:26px;height:28px;border:none;padding:2px 4px 0;margin:auto 1px;border-radius:2px;line-height:12px;font-size:14px;background-color:#ddd;cursor:pointer}.pdfjs-toolbar button i,.pdfjs-toolbar label.button i{font-size:26px;padding:0;margin:0}.pdfjs-toolbar a.button:hover,.pdfjs-toolbar button:hover,.pdfjs-toolbar label.button:hover{background-color:#ccc}button.pushed{background-color:#aaa!important}.pdfjs-toolbar a.button{color:inherit}.pdfjs-toolbar .divider{flex:1}.pdfjs-toolbar .v-sep{width:0;height:20px;border-left:1px solid #bbb}.pdfjs-toolbar .h-sep{width:100%;height:0;border-top:1px solid #bbb;margin:.25em 0}.pdfjs-toolbar .dropdown.dropdown-right,.pdfjs-toolbar .dropdown.right{float:right}.pdfjs-toolbar .dropdown.dropdown-right .dropdown-content,.pdfjs-toolbar .dropdown.right .dropdown-content{right:0;left:auto}.pdfjs-toolbar .dropdown-value{background-color:#ccc;padding:0 4px 2;cursor:pointer}.pdfjs-toolbar .dropdown-value i{width:auto;font-size:12px}.pdfjs-toolbar .dropdown-content{display:none;position:absolute;margin-top:0;background-color:#eee;min-width:10em;z-index:1;font-size:12px;box-shadow:0 4px 8px 0 rgba(0,0,0,.1),0 6px 20px 0 rgba(0,0,0,.09)}.pdfjs-toolbar .dropdown-content a{all:initial;font:inherit;color:#000;padding:6px 8px;text-decoration:none;display:flex;cursor:pointer}.pdfjs-toolbar .dropdown-content i{font-size:16px;padding-right:.5em}.pdfjs-toolbar .dropdown-content a:hover{background-color:#ddd}.dropdown .dropdown-content:hover,.pdfjs-toolbar .dropdown:hover .dropdown-content{display:block} +/*# sourceMappingURL=pdfjs-viewer.min.css.map */ \ No newline at end of file diff --git a/dist/pdfjs-viewer.min.css.map b/dist/pdfjs-viewer.min.css.map new file mode 100644 index 0000000..1ff709a --- /dev/null +++ b/dist/pdfjs-viewer.min.css.map @@ -0,0 +1 @@ +{"version":3,"sources":["dist/pdfjs-viewer.css"],"names":[],"mappings":"AAgBA,cACE,SAAU,KACV,OAAQ,IAAI,MAAM,KAClB,WAAY,KAEd,gCACE,QAAS,KAEX,yCACE,YAAa,IACb,WAAY,gBACZ,cAAe,gBACf,QAAS,MAEX,SACE,SAAU,SACV,cAAe,IACf,WAAY,IACZ,YAAa,KACb,aAAc,KACd,WAAY,EAAE,IAAI,IAAI,EAAE,cAAc,CAAC,EAAE,IAAI,KAAK,EAAE,gBAEtD,gBACE,SAAU,SACV,KAAM,EACN,IAAK,EACL,OAAQ,KACR,MAAO,KAET,qBACE,QAAS,KACT,cAAe,YACf,WAAY,YACZ,OAAQ,KACR,MAAO,KAET,0BACE,OAAQ,YACR,QAAS,YACT,QAAS,eAEX,kCACE,OAAQ,IAAI,MAAM,QAClB,WAAY,IAAI,MAAM,QACtB,cAAe,IACf,MAAO,KACP,OAAQ,KACR,UAAW,KAAK,GAAG,OAAO,SAC1B,OAAQ,KAEV,gBACE,GACE,UAAW,UAEb,KACE,UAAW,gBAGf,eACE,MAAO,KACP,OAAQ,KACR,WAAY,KACZ,QAAS,IACT,eAAgB,OAChB,QAAS,KACT,OAAQ,EACR,QAAS,EAEX,iBACE,OAAQ,KAAK,EAEf,oBACE,aAAc,KACd,YAAa,KACb,MAAO,cACP,UAAW,KAEb,wBACA,sBACA,4BACE,UAAW,KACX,OAAQ,KACR,OAAQ,KACR,QAAS,IAAI,IAAI,EACjB,OAAQ,KAAK,IACb,cAAe,IACf,YAAa,KACb,UAAW,KACX,iBAAkB,KAClB,OAAQ,QAEV,wBACA,8BACE,UAAW,KACX,QAAS,EACT,OAAQ,EAEV,8BACA,4BACA,kCACE,iBAAkB,KAEpB,cACE,iBAAkB,eAEpB,wBACE,MAAO,QAET,wBACE,KAAM,EAER,sBACE,MAAO,EACP,OAAQ,KACR,YAAa,IAAI,MAAM,KAEzB,sBACE,MAAO,KACP,OAAQ,EACR,WAAY,IAAI,MAAM,KACtB,OAAQ,MAAM,EAEhB,wCACA,+BACE,MAAO,MAET,0DACA,iDACE,MAAO,EACP,KAAM,KAER,+BACE,iBAAkB,KAClB,QAAS,EAAE,IAAI,EACf,OAAQ,QAEV,iCACE,MAAO,KACP,UAAW,KAEb,iCACE,QAAS,KACT,SAAU,SACV,WAAY,EACZ,iBAAkB,KAClB,UAAW,KACX,QAAS,EACT,UAAW,KACX,WAAY,EAAE,IAAI,IAAI,EAAE,cAAc,CAAC,EAAE,IAAI,KAAK,EAAE,gBAEtD,mCACE,IAAK,QACL,KAAM,QACN,MAAO,KACP,QAAS,IAAI,IACb,gBAAiB,KACjB,QAAS,KACT,OAAQ,QAEV,mCACE,UAAW,KACX,cAAe,KAEjB,yCACE,iBAAkB,KAEpB,kCACA,iDACE,QAAS","sourcesContent":["/**\n Copyright 2021 Carlos A. (https://github.com/dealfonso)\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\n.pdfjs-viewer {\n overflow: auto;\n border: 1px solid #aaa;\n background: #ccc\n}\n.pdfjs-viewer.horizontal-scroll {\n display: flex\n}\n.pdfjs-viewer.horizontal-scroll .pdfpage {\n margin-left: 1em;\n margin-top: .25em!important;\n margin-bottom: .25em!important;\n display: block\n}\n.pdfpage {\n position: relative;\n margin-bottom: 1em;\n margin-top: 1em;\n margin-left: auto;\n margin-right: auto;\n box-shadow: 0 4px 8px 0 rgba(0,0,0,.1),0 6px 20px 0 rgba(0,0,0,.09)\n}\n.pdfpage canvas {\n position: absolute;\n left: 0;\n top: 0;\n height: 100%;\n width: 100%\n}\n.pdfpage.placeholder {\n display: flex;\n margin-bottom: 0!important;\n margin-top: 0!important;\n height: 100%;\n width: 100%\n}\n.pdfpage .content-wrapper {\n margin: 0!important;\n padding: 0!important;\n display: flex!important\n}\n.pdfpage .content-wrapper .loader {\n border: 2px solid #f3f3f3;\n border-top: 3px solid #3498db;\n border-radius: 50%;\n width: 24px;\n height: 24px;\n animation: spin 1s linear infinite;\n margin: auto\n}\n@keyframes spin {\n 0% {\n transform: rotate(0)\n }\n 100% {\n transform: rotate(360deg)\n }\n}\n.pdfjs-toolbar {\n width: 100%;\n height: 32px;\n background: #ddd;\n z-index: 100;\n vertical-align: middle;\n display: flex;\n margin: 0;\n padding: 0\n}\n.pdfjs-toolbar * {\n margin: auto 0\n}\n.pdfjs-toolbar span {\n margin-right: .5em;\n margin-left: .5em;\n width: 4em!important;\n font-size: 12px\n}\n.pdfjs-toolbar a.button,\n.pdfjs-toolbar button,\n.pdfjs-toolbar label.button {\n min-width: 26px;\n height: 28px;\n border: none;\n padding: 2px 4px 0;\n margin: auto 1px;\n border-radius: 2px;\n line-height: 12px;\n font-size: 14px;\n background-color: #ddd;\n cursor: pointer\n}\n.pdfjs-toolbar button i,\n.pdfjs-toolbar label.button i {\n font-size: 26px;\n padding: 0;\n margin: 0\n}\n.pdfjs-toolbar a.button:hover,\n.pdfjs-toolbar button:hover,\n.pdfjs-toolbar label.button:hover {\n background-color: #ccc\n}\nbutton.pushed {\n background-color: #aaa!important\n}\n.pdfjs-toolbar a.button {\n color: inherit\n}\n.pdfjs-toolbar .divider {\n flex: 1\n}\n.pdfjs-toolbar .v-sep {\n width: 0;\n height: 20px;\n border-left: 1px solid #bbb\n}\n.pdfjs-toolbar .h-sep {\n width: 100%;\n height: 0;\n border-top: 1px solid #bbb;\n margin: .25em 0\n}\n.pdfjs-toolbar .dropdown.dropdown-right,\n.pdfjs-toolbar .dropdown.right {\n float: right\n}\n.pdfjs-toolbar .dropdown.dropdown-right .dropdown-content,\n.pdfjs-toolbar .dropdown.right .dropdown-content {\n right: 0;\n left: auto\n}\n.pdfjs-toolbar .dropdown-value {\n background-color: #ccc;\n padding: 0 4px 2;\n cursor: pointer\n}\n.pdfjs-toolbar .dropdown-value i {\n width: auto;\n font-size: 12px\n}\n.pdfjs-toolbar .dropdown-content {\n display: none;\n position: absolute;\n margin-top: 0;\n background-color: #eee;\n min-width: 10em;\n z-index: 1;\n font-size: 12px;\n box-shadow: 0 4px 8px 0 rgba(0,0,0,.1),0 6px 20px 0 rgba(0,0,0,.09)\n}\n.pdfjs-toolbar .dropdown-content a {\n all: initial;\n font: inherit;\n color: #000;\n padding: 6px 8px;\n text-decoration: none;\n display: flex;\n cursor: pointer\n}\n.pdfjs-toolbar .dropdown-content i {\n font-size: 16px;\n padding-right: .5em\n}\n.pdfjs-toolbar .dropdown-content a:hover {\n background-color: #ddd\n}\n.dropdown .dropdown-content:hover,\n.pdfjs-toolbar .dropdown:hover .dropdown-content {\n display: block\n}"]} \ No newline at end of file diff --git a/dist/pdfjs-viewer.min.js b/dist/pdfjs-viewer.min.js new file mode 100644 index 0000000..2f22de9 --- /dev/null +++ b/dist/pdfjs-viewer.min.js @@ -0,0 +1,2 @@ +/* Copyright 2021 Carlos A. (https://github.com/dealfonso); License: http://www.apache.org/licenses/LICENSE-2.0 */ +(function(exports,$){"use strict";if($===undefined){console.error("jQuery-like library not available");return}let defaults={visibleThreshold:.5,extraPagesToLoad:3,pageClass:"pdfpage",contentClass:"content-wrapper",onDocumentReady:()=>{},onNewPage:(t,e)=>{},onPageRender:(t,e)=>{},zoomValues:[.25,.5,.75,1,1.25,1.5,2,4,8],onZoomChange:t=>{},onActivePageChanged:(t,e)=>{},zoomFillArea:.95,emptyContent:()=>$('
'),renderingScale:1.5};class Zoomer{constructor(t,e={}){let i={zoomValues:[.25,.5,.75,1,1.25,1.5,2,4,8],fillArea:.9};this.current=1;this.viewer=t;this.settings=Object.assign({},i,e);this.settings.zoomValues=this.settings.zoomValues.sort()}get(e=null){if(e===null){return this.current}if(parseFloat(e)==e){return e}let t=this.viewer.getActivePage();let i=[];switch(e){case"in":e=this.current;i=this.settings.zoomValues.filter(t=>t>e);if(i.length>0){e=Math.min(...i)}break;case"out":e=this.current;i=this.settings.zoomValues.filter(t=>t0){e=Math.max(...i)}break;case"fit":e=Math.min(this.get("width"),this.get("height"));break;case"width":e=this.settings.fillArea*this.viewer.$container.width()/t.data("width");break;case"height":e=this.settings.fillArea*this.viewer.$container.height()/t.data("height");break;default:e=this.current;break}return e}zoomPages(n){n=this.get(n);this.viewer.getPages().forEach(function(t){let e=t.$div;let i=e.data("width");let s=e.data("height");e.width(i*n).height(s*n);e.data("zoom",n);e.find(`.${this.viewer.settings.contentClass}`).width(i*n).height(s*n)}.bind(this));this.current=n}}class PDFjsViewer{version="2.0.0";constructor(t,e={}){this.settings=Object.assign({},defaults,e);this._zoom=new Zoomer(this,{zoomValues:this.settings.zoomValues,fillArea:this.settings.zoomFillArea});t=$(t);this.$container=t;t.get(0)._pdfjsViewer=this;this._setScrollListener();this.pages=[];this.pdf=null;this._documentReady=false}setZoom(t){let e=this.$container.get(0);let i=this._zoom.current;let s={top:e.scrollTop,left:e.scrollLeft};this._zoom.zoomPages(t);e.scrollLeft=s.left*this._zoom.current/i;e.scrollTop=s.top*this._zoom.current/i;this._visiblePages(true);if(this._documentReady){if(typeof this.settings.onZoomChange==="function")this.settings.onZoomChange.call(this,this._zoom.current);this.$container.get(0).dispatchEvent(new CustomEvent("zoomchange",{detail:{zoom:this._zoom.current}}))}return this._zoom.current}getZoom(){return this._zoom.current}_cleanPage(t){let e=this.settings.emptyContent();t.find(`.${this.settings.contentClass}`).html("").append(e)}_setPageContent(t,e){t.find(`.${this.settings.contentClass}`).html("").append(e)}refreshAll(){this._visiblePages(true)}_setScrollListener(){let i=false;let s={top:0,left:0};this.__scrollHandler=function(t){if(i===true){return}i=true;let e=this.$container.get(0);if(Math.abs(e.scrollTop-s.top)>e.clientHeight*.2*this._zoom.current||Math.abs(e.scrollLeft-s.left)>e.clientWidth*.2*this._zoom.current){s={top:e.scrollTop,left:e.scrollLeft};this._visiblePages()}i=false}.bind(this);this.$container.off("scroll");this.$container.on("scroll",this.__scrollHandler)}_createSkeleton(e,t){let i={$div:null,width:0,height:0,loaded:false};if(e.getViewport!==undefined){let t=e.getViewport({rotation:this._rotation,scale:1});i.width=t.width;i.height=t.height;i.loaded=true}else{i.width=e.width;i.height=e.height}console.assert(i.width>0&&i.height>0,"Page width and height must be greater than 0");i.$div=$(`
`).attr("data-page",t).data("width",i.width).data("height",i.height).data("zoom",this._zoom.current).addClass(this.settings.pageClass).width(i.width*this._zoom.current).height(i.height*this._zoom.current);let s=$(`
`).width(i.width).height(i.height);i.$div.append(s);this._cleanPage(i.$div);return i}_placeSkeleton(t,e){let i=e-1;let s=null;while(i>0&&(s=this.$container.find(`.${this.settings.pageClass}[data-page="${i}"]`)).length===0){i--}if(i===0){this.$container.append(t.$div)}else{s.after(t.$div)}}_createSkeletons(e){for(let t=1;t<=this.pageCount;t++){if(this.pages[t]===undefined){e=this._createSkeleton(e,t);this.pages[t]=e;this._placeSkeleton(e,t);if(typeof this.settings.onNewPage==="function"){this.settings.onNewPage.call(this,e.$div.get(0),t)}this.$container.get(0).dispatchEvent(new CustomEvent("newpage",{detail:{pageNumber:t,page:e.$div.get(0)}}))}}}_setActivePage(e){if(this._activePage!==e){this._activePage=e;let t=this.getActivePage();if(this._documentReady){t=t==null?null:t.get(0);if(typeof this.settings.onActivePageChanged==="function"){this.settings.onActivePageChanged.call(this,t,e)}this.$container.get(0).dispatchEvent(new CustomEvent("activepagechanged",{detail:{activePageNumber:e,activePage:t}}))}}}_areaOfPageVisible(t){if(t===undefined){return 0}let e=this.$container.offset();let i=this.$container.width();let s=this.$container.height();let n=t.offset();n.top-=e.top;n.left-=e.left;n.bottom=n.top+t.outerHeight();n.right=n.left+t.outerWidth();let a=Math.min(Math.max(n.top,0),s);let h=Math.min(Math.max(t.outerHeight()+n.top,0),s);let o=Math.min(Math.max(n.left,0),i);let l=Math.min(Math.max(t.outerWidth()+n.left,0),i);let r=l-o;let g=h-a;return r*g}isPageVisible(t){if(this.pdf===null||t===undefined||t===null||t<1||t>this.pdf.numPages){return false}if(typeof t==="string"){t=parseInt(t)}let e=t;if(typeof t==="number"){if(this.pages[t]===undefined)return false;e=this.pages[t].$div}return this._areaOfPageVisible(e)>e.outerWidth()*e.outerHeight()*this.settings.visibleThreshold}_visiblePages(t=false){let i=0;let s=null;if(this.pages.length===0){this._visibles=[];this._setActivePage(0);return}let e=this.pages.filter(function(t){let e=this._areaOfPageVisible(t.$div);if(e>i){i=e;s=t.$div.data("page")}return e>0}.bind(this)).map(t=>t.$div);this._setActivePage(s);let n=e.map(t=>{return parseInt($(t).data("page"))});if(n.length>0){let e=Math.min(...n);let i=Math.max(...n);for(let t=Math.max(1,e-this.settings.extraPagesToLoad);t0){let e=this._pagesLoading.shift();this.pdf.getPage(e).then(function(t){this._renderPage(t,e)}.bind(this)).then(function(t){if(this._pagesLoading.length>0){this._loadingTask()}}.bind(this))}this._loading=false}scrollToPage(t){if(this.pages.length===0||this.pages[t]===undefined){return}let e=this.pages[t].$div;if(e.length===0){console.warn(`Page ${t} not found`);return}let i=e.position();let s=this.$container.position();if(i!==undefined){this.$container.get(0).scrollTop=this.$container.get(0).scrollTop+i.top-s.top;this.$container.get(0).scrollLeft=this.$container.get(0).scrollLeft+i.left-s.left}this._setActivePage(t)}_renderPage(t,e){let i=this.pages[e];let s=this.settings.renderingScale;let n=window.devicePixelRatio||1;let a=t.getViewport({rotation:this._rotation,scale:this._zoom.current*s});i.width=a.width/this._zoom.current/s;i.height=a.height/this._zoom.current/s;i.$div.data("width",i.width);i.$div.data("height",i.height);i.$div.width(i.width*this._zoom.current);i.$div.height(i.height*this._zoom.current);i.loaded=true;let h=$("");let o=h.get(0);let l=o.getContext("2d");o.height=a.height*n;o.width=a.width*n;o.getContext("2d");var r=n!==1?[n,0,0,n,0,0]:null;var g={canvasContext:l,viewport:a,transform:r};return t.render(g).promise.then(function(){this._setPageContent(i.$div,h);if(this._documentReady){if(typeof this.settings.onPageRender==="function"){this.settings.onPageRender.call(this,i.$div.get(0),e)}this.$container.get(0).dispatchEvent(new CustomEvent("pagerender",{detail:{pageNumber:e,page:i.$div.get(0)}}))}return i}.bind(this))}getActivePage(){if(this._activePage===null||this.pdf===null){return null}if(this._activePage<1||this._activePage>this.pdf.numPages){return null}return this.pages[this._activePage].$div}getPages(){return this.pages}getPageCount(){if(this.pdf===null){return 0}return this.pdf.numPages}next(){if(this._activePage1){this.scrollToPage(this._activePage-1)}}first(){if(this._activePage!==1){this.scrollToPage(1)}}last(){if(this.pdf===null)return;if(this._activePage!==this.pdf.numPages){this.scrollToPage(this.pdf.numPages)}}rotate(t,e=false){if(e){t=t+this._rotation}this._rotation=t;let i=this.$container.get(0);let s={top:i.scrollTop,left:i.scrollLeft,height:i.scrollHeight,width:i.scrollWidth};return this.forceViewerInitialization().then(function(){let t={top:i.scrollTop,left:i.scrollLeft,height:i.scrollHeight,width:i.scrollWidth};i.scrollTop=s.top*(t.height/s.height);i.scrollLeft=s.left*(t.width/s.width)}.bind(this))}forceViewerInitialization(){this.pages=[];this.$container.find(`.${this.settings.pageClass}`).remove();this._pagesLoading=[];this._loading=false;this._visibles=[];this._activePage=null;return this.pdf.getPage(1).then(function(t){this._createSkeletons(t);this._visiblePages();this._setActivePage(1)}.bind(this))}async loadDocument(t){this._documentReady=false;this.pages=[];this.$container.find(`.${this.settings.pageClass}`).remove();this.pdf=null;let e=pdfjsLib.getDocument(t);return e.promise.then(function(t){this.pdf=t;this.pageCount=t.numPages;this._rotation=0;return this.forceViewerInitialization()}.bind(this)).then(function(){if(typeof this.settings.onDocumentReady==="function"){this.settings.onDocumentReady.call(this)}this.$container.get(0).dispatchEvent(new CustomEvent("documentready",{detail:{document:this.pdf}}));this._setActivePage(0);this._documentReady=true;this._setActivePage(1)}.bind(this))}}function recoverAttributes(target,attributeDefaults){const camelcaseToSnakecase=t=>t.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`);let $target=$(target);let result={};if($target.length>0){$target=$($target[0]);for(let originalAttributeName in attributeDefaults){let attributeName=camelcaseToSnakecase(originalAttributeName);let attributeValue=$target.attr(attributeName);if(attributeValue!=null){switch(typeof attributeDefaults[originalAttributeName]){case"float":try{attributeValue=parseFloat(attributeValue)}catch(_){}break;case"number":try{attributeValue=parseInt(attributeValue)}catch(_){}break;case"function":let functionString=attributeValue;attributeValue=function(){eval(functionString)}.bind(target[0]);break;default:break}result[originalAttributeName]=attributeValue}}}return result}function init(e){let i=recoverAttributes(e,Object.assign({pdfDocument:"",initialZoom:""},defaults));if(i["pdfDocument"]!=null){let t=new PDFjsViewer($(e),i);t.loadDocument(i["pdfDocument"]).then(function(){if(i["initialZoom"]!=null){t.setZoom(i["initialZoom"])}});e.get(0).pdfViewer=t}}$(function(){$(".pdfjs-viewer").each(function(){let t=$(this);init(t)})});exports.PDFjsViewer=PDFjsViewer})(window,window._$??window.jQuery??undefined); \ No newline at end of file diff --git a/dist/pdfjs-viewer.min.js.map b/dist/pdfjs-viewer.min.js.map new file mode 100644 index 0000000..980f569 --- /dev/null +++ b/dist/pdfjs-viewer.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"pdfjs-viewer.min.js.map","sources":["pdfjs-viewer.js"],"sourcesContent":["/**\n Copyright 2021 Carlos A. (https://github.com/dealfonso)\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\n(function (exports, $) {\n\t\"use strict\";\n\tif ($ === undefined) {\n\t\tconsole.error(\"jQuery-like library not available\");\n\t\treturn;\n\t}\n\tlet defaults = {\n\t\tvisibleThreshold: .5,\n\t\textraPagesToLoad: 3,\n\t\tpageClass: \"pdfpage\",\n\t\tcontentClass: \"content-wrapper\",\n\t\tonDocumentReady: () => {},\n\t\tonNewPage: (page, i) => {},\n\t\tonPageRender: (page, i) => {},\n\t\tzoomValues: [.25, .5, .75, 1, 1.25, 1.5, 2, 4, 8],\n\t\tonZoomChange: zoomlevel => {},\n\t\tonActivePageChanged: (page, i) => {},\n\t\tzoomFillArea: .95,\n\t\temptyContent: () => $('
'),\n\t\trenderingScale: 1.5\n\t};\n\tclass Zoomer {\n\t\tconstructor(viewer, options = {}) {\n\t\t\tlet defaults = {\n\t\t\t\tzoomValues: [.25, .5, .75, 1, 1.25, 1.5, 2, 4, 8],\n\t\t\t\tfillArea: .9\n\t\t\t};\n\t\t\tthis.current = 1;\n\t\t\tthis.viewer = viewer;\n\t\t\tthis.settings = Object.assign({}, defaults, options);\n\t\t\tthis.settings.zoomValues = this.settings.zoomValues.sort();\n\t\t}\n\t\tget(zoom = null) {\n\t\t\tif (zoom === null) {\n\t\t\t\treturn this.current;\n\t\t\t}\n\t\t\tif (parseFloat(zoom) == zoom) {\n\t\t\t\treturn zoom;\n\t\t\t}\n\t\t\tlet $activepage = this.viewer.getActivePage();\n\t\t\tlet zoomValues = [];\n\t\t\tswitch (zoom) {\n\t\t\tcase \"in\":\n\t\t\t\tzoom = this.current;\n\t\t\t\tzoomValues = this.settings.zoomValues.filter(x => x > zoom);\n\t\t\t\tif (zoomValues.length > 0) {\n\t\t\t\t\tzoom = Math.min(...zoomValues);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"out\":\n\t\t\t\tzoom = this.current;\n\t\t\t\tzoomValues = this.settings.zoomValues.filter(x => x < zoom);\n\t\t\t\tif (zoomValues.length > 0) {\n\t\t\t\t\tzoom = Math.max(...zoomValues);\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase \"fit\":\n\t\t\t\tzoom = Math.min(this.get(\"width\"), this.get(\"height\"));\n\t\t\t\tbreak;\n\t\t\tcase \"width\":\n\t\t\t\tzoom = this.settings.fillArea * this.viewer.$container.width() / $activepage.data(\"width\");\n\t\t\t\tbreak;\n\t\t\tcase \"height\":\n\t\t\t\tzoom = this.settings.fillArea * this.viewer.$container.height() / $activepage.data(\"height\");\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tzoom = this.current;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\treturn zoom;\n\t\t}\n\t\tzoomPages(zoom) {\n\t\t\tzoom = this.get(zoom);\n\t\t\tthis.viewer.getPages().forEach(function (page) {\n\t\t\t\tlet $page = page.$div;\n\t\t\t\tlet c_width = $page.data(\"width\");\n\t\t\t\tlet c_height = $page.data(\"height\");\n\t\t\t\t$page.width(c_width * zoom).height(c_height * zoom);\n\t\t\t\t$page.data(\"zoom\", zoom);\n\t\t\t\t$page.find(`.${this.viewer.settings.contentClass}`).width(c_width * zoom).height(c_height * zoom);\n\t\t\t}.bind(this));\n\t\t\tthis.current = zoom;\n\t\t}\n\t}\n\tclass PDFjsViewer {\n\t\tversion = \"2.0.0\";\n\t\tconstructor($container, options = {}) {\n\t\t\tthis.settings = Object.assign({}, defaults, options);\n\t\t\tthis._zoom = new Zoomer(this, {\n\t\t\t\tzoomValues: this.settings.zoomValues,\n\t\t\t\tfillArea: this.settings.zoomFillArea\n\t\t\t});\n\t\t\t$container = $($container);\n\t\t\tthis.$container = $container;\n\t\t\t$container.get(0)._pdfjsViewer = this;\n\t\t\tthis._setScrollListener();\n\t\t\tthis.pages = [];\n\t\t\tthis.pdf = null;\n\t\t\tthis._documentReady = false;\n\t\t}\n\t\tsetZoom(zoom) {\n\t\t\tlet container = this.$container.get(0);\n\t\t\tlet prevzoom = this._zoom.current;\n\t\t\tlet prevScroll = {\n\t\t\t\ttop: container.scrollTop,\n\t\t\t\tleft: container.scrollLeft\n\t\t\t};\n\t\t\tthis._zoom.zoomPages(zoom);\n\t\t\tcontainer.scrollLeft = prevScroll.left * this._zoom.current / prevzoom;\n\t\t\tcontainer.scrollTop = prevScroll.top * this._zoom.current / prevzoom;\n\t\t\tthis._visiblePages(true);\n\t\t\tif (this._documentReady) {\n\t\t\t\tif (typeof this.settings.onZoomChange === \"function\") this.settings.onZoomChange.call(this, this._zoom.current);\n\t\t\t\tthis.$container.get(0).dispatchEvent(new CustomEvent(\"zoomchange\", {\n\t\t\t\t\tdetail: {\n\t\t\t\t\t\tzoom: this._zoom.current\n\t\t\t\t\t}\n\t\t\t\t}));\n\t\t\t}\n\t\t\treturn this._zoom.current;\n\t\t}\n\t\tgetZoom() {\n\t\t\treturn this._zoom.current;\n\t\t}\n\t\t_cleanPage($page) {\n\t\t\tlet $emptyContent = this.settings.emptyContent();\n\t\t\t$page.find(`.${this.settings.contentClass}`).html(\"\").append($emptyContent);\n\t\t}\n\t\t_setPageContent($page, $content) {\n\t\t\t$page.find(`.${this.settings.contentClass}`).html(\"\").append($content);\n\t\t}\n\t\trefreshAll() {\n\t\t\tthis._visiblePages(true);\n\t\t}\n\t\t_setScrollListener() {\n\t\t\tlet scrollLock = false;\n\t\t\tlet scrollPos = {\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0\n\t\t\t};\n\t\t\tthis.__scrollHandler = function (e) {\n\t\t\t\tif (scrollLock === true) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tscrollLock = true;\n\t\t\t\tlet container = this.$container.get(0);\n\t\t\t\tif (Math.abs(container.scrollTop - scrollPos.top) > container.clientHeight * .2 * this._zoom.current || Math.abs(container.scrollLeft - scrollPos.left) > container.clientWidth * .2 * this._zoom.current) {\n\t\t\t\t\tscrollPos = {\n\t\t\t\t\t\ttop: container.scrollTop,\n\t\t\t\t\t\tleft: container.scrollLeft\n\t\t\t\t\t};\n\t\t\t\t\tthis._visiblePages();\n\t\t\t\t}\n\t\t\t\tscrollLock = false;\n\t\t\t}.bind(this);\n\t\t\tthis.$container.off(\"scroll\");\n\t\t\tthis.$container.on(\"scroll\", this.__scrollHandler);\n\t\t}\n\t\t_createSkeleton(page, i) {\n\t\t\tlet pageinfo = {\n\t\t\t\t$div: null,\n\t\t\t\twidth: 0,\n\t\t\t\theight: 0,\n\t\t\t\tloaded: false\n\t\t\t};\n\t\t\tif (page.getViewport !== undefined) {\n\t\t\t\tlet viewport = page.getViewport({\n\t\t\t\t\trotation: this._rotation,\n\t\t\t\t\tscale: 1\n\t\t\t\t});\n\t\t\t\tpageinfo.width = viewport.width;\n\t\t\t\tpageinfo.height = viewport.height;\n\t\t\t\tpageinfo.loaded = true;\n\t\t\t} else {\n\t\t\t\tpageinfo.width = page.width;\n\t\t\t\tpageinfo.height = page.height;\n\t\t\t}\n\t\t\tconsole.assert(pageinfo.width > 0 && pageinfo.height > 0, \"Page width and height must be greater than 0\");\n\t\t\tpageinfo.$div = $(`
`).attr(\"data-page\", i).data(\"width\", pageinfo.width).data(\"height\", pageinfo.height).data(\"zoom\", this._zoom.current).addClass(this.settings.pageClass).width(pageinfo.width * this._zoom.current).height(pageinfo.height * this._zoom.current);\n\t\t\tlet $content = $(`
`).width(pageinfo.width).height(pageinfo.height);\n\t\t\tpageinfo.$div.append($content);\n\t\t\tthis._cleanPage(pageinfo.$div);\n\t\t\treturn pageinfo;\n\t\t}\n\t\t_placeSkeleton(pageinfo, i) {\n\t\t\tlet prevpage = i - 1;\n\t\t\tlet $prevpage = null;\n\t\t\twhile (prevpage > 0 && ($prevpage = this.$container.find(`.${this.settings.pageClass}[data-page=\"${prevpage}\"]`)).length === 0) {\n\t\t\t\tprevpage--;\n\t\t\t}\n\t\t\tif (prevpage === 0) {\n\t\t\t\tthis.$container.append(pageinfo.$div);\n\t\t\t} else {\n\t\t\t\t$prevpage.after(pageinfo.$div);\n\t\t\t}\n\t\t}\n\t\t_createSkeletons(pageinfo) {\n\t\t\tfor (let i = 1; i <= this.pageCount; i++) {\n\t\t\t\tif (this.pages[i] === undefined) {\n\t\t\t\t\tpageinfo = this._createSkeleton(pageinfo, i);\n\t\t\t\t\tthis.pages[i] = pageinfo;\n\t\t\t\t\tthis._placeSkeleton(pageinfo, i);\n\t\t\t\t\tif (typeof this.settings.onNewPage === \"function\") {\n\t\t\t\t\t\tthis.settings.onNewPage.call(this, pageinfo.$div.get(0), i);\n\t\t\t\t\t}\n\t\t\t\t\tthis.$container.get(0).dispatchEvent(new CustomEvent(\"newpage\", {\n\t\t\t\t\t\tdetail: {\n\t\t\t\t\t\t\tpageNumber: i,\n\t\t\t\t\t\t\tpage: pageinfo.$div.get(0)\n\t\t\t\t\t\t}\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t_setActivePage(i) {\n\t\t\tif (this._activePage !== i) {\n\t\t\t\tthis._activePage = i;\n\t\t\t\tlet activePage = this.getActivePage();\n\t\t\t\tif (this._documentReady) {\n\t\t\t\t\tactivePage = activePage == null ? null : activePage.get(0);\n\t\t\t\t\tif (typeof this.settings.onActivePageChanged === \"function\") {\n\t\t\t\t\t\tthis.settings.onActivePageChanged.call(this, activePage, i);\n\t\t\t\t\t}\n\t\t\t\t\tthis.$container.get(0).dispatchEvent(new CustomEvent(\"activepagechanged\", {\n\t\t\t\t\t\tdetail: {\n\t\t\t\t\t\t\tactivePageNumber: i,\n\t\t\t\t\t\t\tactivePage: activePage\n\t\t\t\t\t\t}\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t_areaOfPageVisible($page) {\n\t\t\tif ($page === undefined) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\tlet c_offset = this.$container.offset();\n\t\t\tlet c_width = this.$container.width();\n\t\t\tlet c_height = this.$container.height();\n\t\t\tlet position = $page.offset();\n\t\t\tposition.top -= c_offset.top;\n\t\t\tposition.left -= c_offset.left;\n\t\t\tposition.bottom = position.top + $page.outerHeight();\n\t\t\tposition.right = position.left + $page.outerWidth();\n\t\t\tlet page_y0 = Math.min(Math.max(position.top, 0), c_height);\n\t\t\tlet page_y1 = Math.min(Math.max($page.outerHeight() + position.top, 0), c_height);\n\t\t\tlet page_x0 = Math.min(Math.max(position.left, 0), c_width);\n\t\t\tlet page_x1 = Math.min(Math.max($page.outerWidth() + position.left, 0), c_width);\n\t\t\tlet vis_x = page_x1 - page_x0;\n\t\t\tlet vis_y = page_y1 - page_y0;\n\t\t\treturn vis_x * vis_y;\n\t\t}\n\t\tisPageVisible(i) {\n\t\t\tif (this.pdf === null || i === undefined || i === null || i < 1 || i > this.pdf.numPages) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (typeof i === \"string\") {\n\t\t\t\ti = parseInt(i);\n\t\t\t}\n\t\t\tlet $page = i;\n\t\t\tif (typeof i === \"number\") {\n\t\t\t\tif (this.pages[i] === undefined) return false;\n\t\t\t\t$page = this.pages[i].$div;\n\t\t\t}\n\t\t\treturn this._areaOfPageVisible($page) > $page.outerWidth() * $page.outerHeight() * this.settings.visibleThreshold;\n\t\t}\n\t\t_visiblePages(forceRedraw = false) {\n\t\t\tlet max_area = 0;\n\t\t\tlet i_page = null;\n\t\t\tif (this.pages.length === 0) {\n\t\t\t\tthis._visibles = [];\n\t\t\t\tthis._setActivePage(0);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet $visibles = this.pages.filter(function (pageinfo) {\n\t\t\t\tlet areaVisible = this._areaOfPageVisible(pageinfo.$div);\n\t\t\t\tif (areaVisible > max_area) {\n\t\t\t\t\tmax_area = areaVisible;\n\t\t\t\t\ti_page = pageinfo.$div.data(\"page\");\n\t\t\t\t}\n\t\t\t\treturn areaVisible > 0;\n\t\t\t}.bind(this)).map(x => x.$div);\n\t\t\tthis._setActivePage(i_page);\n\t\t\tlet visibles = $visibles.map(x => {\n\t\t\t\treturn parseInt($(x).data(\"page\"));\n\t\t\t});\n\t\t\tif (visibles.length > 0) {\n\t\t\t\tlet minVisible = Math.min(...visibles);\n\t\t\t\tlet maxVisible = Math.max(...visibles);\n\t\t\t\tfor (let i = Math.max(1, minVisible - this.settings.extraPagesToLoad); i < minVisible; i++) {\n\t\t\t\t\tif (!visibles.includes(i)) visibles.push(i);\n\t\t\t\t}\n\t\t\t\tfor (let i = maxVisible + 1; i <= Math.min(maxVisible + this.settings.extraPagesToLoad, this.pdf.numPages); i++) {\n\t\t\t\t\tif (!visibles.includes(i)) visibles.push(i);\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet nowVisibles = visibles;\n\t\t\tif (!forceRedraw) {\n\t\t\t\tnowVisibles = visibles.filter(function (x) {\n\t\t\t\t\treturn !this._visibles.includes(x);\n\t\t\t\t}.bind(this));\n\t\t\t}\n\t\t\tthis._visibles.filter(function (x) {\n\t\t\t\treturn !visibles.includes(x);\n\t\t\t}).forEach(function (i) {\n\t\t\t\tthis._cleanPage(this.pages[i].$div);\n\t\t\t}.bind(this));\n\t\t\tthis._visibles = visibles;\n\t\t\tthis.loadPages(...nowVisibles);\n\t\t}\n\t\tloadPages(...pages) {\n\t\t\tthis._pagesLoading.push(...pages);\n\t\t\tif (this._loading) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis._loadingTask();\n\t\t}\n\t\t_loadingTask() {\n\t\t\tthis._loading = true;\n\t\t\tif (this._pagesLoading.length > 0) {\n\t\t\t\tlet pagei = this._pagesLoading.shift();\n\t\t\t\tthis.pdf.getPage(pagei).then(function (page) {\n\t\t\t\t\tthis._renderPage(page, pagei);\n\t\t\t\t}.bind(this)).then(function (pageinfo) {\n\t\t\t\t\tif (this._pagesLoading.length > 0) {\n\t\t\t\t\t\tthis._loadingTask();\n\t\t\t\t\t}\n\t\t\t\t}.bind(this));\n\t\t\t}\n\t\t\tthis._loading = false;\n\t\t}\n\t\tscrollToPage(i) {\n\t\t\tif (this.pages.length === 0 || this.pages[i] === undefined) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet $page = this.pages[i].$div;\n\t\t\tif ($page.length === 0) {\n\t\t\t\tconsole.warn(`Page ${i} not found`);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet position = $page.position();\n\t\t\tlet containerPosition = this.$container.position();\n\t\t\tif (position !== undefined) {\n\t\t\t\tthis.$container.get(0).scrollTop = this.$container.get(0).scrollTop + position.top - containerPosition.top;\n\t\t\t\tthis.$container.get(0).scrollLeft = this.$container.get(0).scrollLeft + position.left - containerPosition.left;\n\t\t\t}\n\t\t\tthis._setActivePage(i);\n\t\t}\n\t\t_renderPage(page, i) {\n\t\t\tlet pageinfo = this.pages[i];\n\t\t\tlet scale = this.settings.renderingScale;\n\t\t\tlet pixel_ratio = window.devicePixelRatio || 1;\n\t\t\tlet viewport = page.getViewport({\n\t\t\t\trotation: this._rotation,\n\t\t\t\tscale: this._zoom.current * scale\n\t\t\t});\n\t\t\tpageinfo.width = viewport.width / this._zoom.current / scale;\n\t\t\tpageinfo.height = viewport.height / this._zoom.current / scale;\n\t\t\tpageinfo.$div.data(\"width\", pageinfo.width);\n\t\t\tpageinfo.$div.data(\"height\", pageinfo.height);\n\t\t\tpageinfo.$div.width(pageinfo.width * this._zoom.current);\n\t\t\tpageinfo.$div.height(pageinfo.height * this._zoom.current);\n\t\t\tpageinfo.loaded = true;\n\t\t\tlet $canvas = $(\"\");\n\t\t\tlet canvas = $canvas.get(0);\n\t\t\tlet context = canvas.getContext(\"2d\");\n\t\t\tcanvas.height = viewport.height * pixel_ratio;\n\t\t\tcanvas.width = viewport.width * pixel_ratio;\n\t\t\tcanvas.getContext(\"2d\");\n\t\t\tvar transform = pixel_ratio !== 1 ? [pixel_ratio, 0, 0, pixel_ratio, 0, 0] : null;\n\t\t\tvar renderContext = {\n\t\t\t\tcanvasContext: context,\n\t\t\t\tviewport: viewport,\n\t\t\t\ttransform: transform\n\t\t\t};\n\t\t\treturn page.render(renderContext).promise.then(function () {\n\t\t\t\tthis._setPageContent(pageinfo.$div, $canvas);\n\t\t\t\tif (this._documentReady) {\n\t\t\t\t\tif (typeof this.settings.onPageRender === \"function\") {\n\t\t\t\t\t\tthis.settings.onPageRender.call(this, pageinfo.$div.get(0), i);\n\t\t\t\t\t}\n\t\t\t\t\tthis.$container.get(0).dispatchEvent(new CustomEvent(\"pagerender\", {\n\t\t\t\t\t\tdetail: {\n\t\t\t\t\t\t\tpageNumber: i,\n\t\t\t\t\t\t\tpage: pageinfo.$div.get(0)\n\t\t\t\t\t\t}\n\t\t\t\t\t}));\n\t\t\t\t}\n\t\t\t\treturn pageinfo;\n\t\t\t}.bind(this));\n\t\t}\n\t\tgetActivePage() {\n\t\t\tif (this._activePage === null || this.pdf === null) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tif (this._activePage < 1 || this._activePage > this.pdf.numPages) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn this.pages[this._activePage].$div;\n\t\t}\n\t\tgetPages() {\n\t\t\treturn this.pages;\n\t\t}\n\t\tgetPageCount() {\n\t\t\tif (this.pdf === null) {\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t\treturn this.pdf.numPages;\n\t\t}\n\t\tnext() {\n\t\t\tif (this._activePage < this.pdf.numPages) {\n\t\t\t\tthis.scrollToPage(this._activePage + 1);\n\t\t\t}\n\t\t}\n\t\tprev() {\n\t\t\tif (this._activePage > 1) {\n\t\t\t\tthis.scrollToPage(this._activePage - 1);\n\t\t\t}\n\t\t}\n\t\tfirst() {\n\t\t\tif (this._activePage !== 1) {\n\t\t\t\tthis.scrollToPage(1);\n\t\t\t}\n\t\t}\n\t\tlast() {\n\t\t\tif (this.pdf === null) return;\n\t\t\tif (this._activePage !== this.pdf.numPages) {\n\t\t\t\tthis.scrollToPage(this.pdf.numPages);\n\t\t\t}\n\t\t}\n\t\trotate(deg, accumulate = false) {\n\t\t\tif (accumulate) {\n\t\t\t\tdeg = deg + this._rotation;\n\t\t\t}\n\t\t\tthis._rotation = deg;\n\t\t\tlet container = this.$container.get(0);\n\t\t\tlet prevScroll = {\n\t\t\t\ttop: container.scrollTop,\n\t\t\t\tleft: container.scrollLeft,\n\t\t\t\theight: container.scrollHeight,\n\t\t\t\twidth: container.scrollWidth\n\t\t\t};\n\t\t\treturn this.forceViewerInitialization().then(function () {\n\t\t\t\tlet newScroll = {\n\t\t\t\t\ttop: container.scrollTop,\n\t\t\t\t\tleft: container.scrollLeft,\n\t\t\t\t\theight: container.scrollHeight,\n\t\t\t\t\twidth: container.scrollWidth\n\t\t\t\t};\n\t\t\t\tcontainer.scrollTop = prevScroll.top * (newScroll.height / prevScroll.height);\n\t\t\t\tcontainer.scrollLeft = prevScroll.left * (newScroll.width / prevScroll.width);\n\t\t\t}.bind(this));\n\t\t}\n\t\tforceViewerInitialization() {\n\t\t\tthis.pages = [];\n\t\t\tthis.$container.find(`.${this.settings.pageClass}`).remove();\n\t\t\tthis._pagesLoading = [];\n\t\t\tthis._loading = false;\n\t\t\tthis._visibles = [];\n\t\t\tthis._activePage = null;\n\t\t\treturn this.pdf.getPage(1).then(function (page) {\n\t\t\t\tthis._createSkeletons(page);\n\t\t\t\tthis._visiblePages();\n\t\t\t\tthis._setActivePage(1);\n\t\t\t}.bind(this));\n\t\t}\n\t\tasync loadDocument(document) {\n\t\t\tthis._documentReady = false;\n\t\t\tthis.pages = [];\n\t\t\tthis.$container.find(`.${this.settings.pageClass}`).remove();\n\t\t\tthis.pdf = null;\n\t\t\tlet loadingTask = pdfjsLib.getDocument(document);\n\t\t\treturn loadingTask.promise.then(function (pdf) {\n\t\t\t\tthis.pdf = pdf;\n\t\t\t\tthis.pageCount = pdf.numPages;\n\t\t\t\tthis._rotation = 0;\n\t\t\t\treturn this.forceViewerInitialization();\n\t\t\t}.bind(this)).then(function () {\n\t\t\t\tif (typeof this.settings.onDocumentReady === \"function\") {\n\t\t\t\t\tthis.settings.onDocumentReady.call(this);\n\t\t\t\t}\n\t\t\t\tthis.$container.get(0).dispatchEvent(new CustomEvent(\"documentready\", {\n\t\t\t\t\tdetail: {\n\t\t\t\t\t\tdocument: this.pdf\n\t\t\t\t\t}\n\t\t\t\t}));\n\t\t\t\tthis._setActivePage(0);\n\t\t\t\tthis._documentReady = true;\n\t\t\t\tthis._setActivePage(1);\n\t\t\t}.bind(this));\n\t\t}\n\t}\n\n\tfunction recoverAttributes(target, attributeDefaults) {\n\t\tconst camelcaseToSnakecase = str => str.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`);\n\t\tlet $target = $(target);\n\t\tlet result = {};\n\t\tif ($target.length > 0) {\n\t\t\t$target = $($target[0]);\n\t\t\tfor (let originalAttributeName in attributeDefaults) {\n\t\t\t\tlet attributeName = camelcaseToSnakecase(originalAttributeName);\n\t\t\t\tlet attributeValue = $target.attr(attributeName);\n\t\t\t\tif (attributeValue != null) {\n\t\t\t\t\tswitch (typeof attributeDefaults[originalAttributeName]) {\n\t\t\t\t\tcase \"float\":\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tattributeValue = parseFloat(attributeValue);\n\t\t\t\t\t\t} catch (_) {}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"number\":\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tattributeValue = parseInt(attributeValue);\n\t\t\t\t\t\t} catch (_) {}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"function\":\n\t\t\t\t\t\tlet functionString = attributeValue;\n\t\t\t\t\t\tattributeValue = function () {\n\t\t\t\t\t\t\teval(functionString);\n\t\t\t\t\t\t}.bind(target[0]);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tresult[originalAttributeName] = attributeValue;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t}\n\n\tfunction init(element) {\n\t\tlet options = recoverAttributes(element, Object.assign({\n\t\t\tpdfDocument: \"\",\n\t\t\tinitialZoom: \"\"\n\t\t}, defaults));\n\t\tif (options[\"pdfDocument\"] != null) {\n\t\t\tlet pdfViewer = new PDFjsViewer($(element), options);\n\t\t\tpdfViewer.loadDocument(options[\"pdfDocument\"]).then(function () {\n\t\t\t\tif (options[\"initialZoom\"] != null) {\n\t\t\t\t\tpdfViewer.setZoom(options[\"initialZoom\"]);\n\t\t\t\t}\n\t\t\t});\n\t\t\telement.get(0).pdfViewer = pdfViewer;\n\t\t}\n\t}\n\t$(function () {\n\t\t$(\".pdfjs-viewer\").each(function () {\n\t\t\tlet $viewer = $(this);\n\t\t\tinit($viewer);\n\t\t});\n\t});\n\texports.PDFjsViewer = PDFjsViewer;\n})(window, window._$ ?? window.jQuery ?? undefined);\n"],"names":["exports","$","undefined","console","error","let","defaults","visibleThreshold","extraPagesToLoad","pageClass","contentClass","onDocumentReady","onNewPage","page","i","onPageRender","zoomValues","onZoomChange","zoomlevel","onActivePageChanged","zoomFillArea","emptyContent","renderingScale","Zoomer","constructor","viewer","options","fillArea","this","current","settings","Object","assign","sort","get","zoom","parseFloat","$activepage","getActivePage","filter","x","length","Math","min","max","$container","width","data","height","zoomPages","getPages","forEach","$page","$div","c_width","c_height","find","bind","PDFjsViewer","version","_zoom","_pdfjsViewer","_setScrollListener","pages","pdf","_documentReady","setZoom","container","prevzoom","prevScroll","top","scrollTop","left","scrollLeft","_visiblePages","call","dispatchEvent","CustomEvent","detail","getZoom","_cleanPage","$emptyContent","html","append","_setPageContent","$content","refreshAll","scrollLock","scrollPos","__scrollHandler","e","abs","clientHeight","clientWidth","off","on","_createSkeleton","pageinfo","loaded","getViewport","viewport","rotation","_rotation","scale","assert","attr","addClass","_placeSkeleton","prevpage","$prevpage","after","_createSkeletons","pageCount","pageNumber","_setActivePage","_activePage","activePage","activePageNumber","_areaOfPageVisible","c_offset","offset","position","bottom","outerHeight","right","outerWidth","page_y0","page_y1","page_x0","page_x1","vis_x","vis_y","isPageVisible","numPages","parseInt","forceRedraw","max_area","i_page","_visibles","$visibles","areaVisible","map","visibles","minVisible","maxVisible","includes","push","nowVisibles","loadPages","_pagesLoading","_loading","_loadingTask","pagei","shift","getPage","then","_renderPage","scrollToPage","warn","containerPosition","pixel_ratio","window","devicePixelRatio","$canvas","canvas","context","getContext","transform","renderContext","canvasContext","render","promise","getPageCount","next","prev","first","last","rotate","deg","accumulate","scrollHeight","scrollWidth","forceViewerInitialization","newScroll","remove","loadDocument","document","loadingTask","pdfjsLib","getDocument","recoverAttributes","target","attributeDefaults","camelcaseToSnakecase","str","replace","letter","toLowerCase","$target","result","originalAttributeName","attributeName","attributeValue","_","functionString","eval","init","element","pdfDocument","initialZoom","pdfViewer","each","$viewer","_$","jQuery"],"mappings":";CAgBA,SAAWA,QAASC,GACnB,aACA,GAAIA,IAAMC,UAAW,CACpBC,QAAQC,MAAM,mCAAmC,EACjD,MACD,CACAC,IAAIC,SAAW,CACdC,iBAAkB,GAClBC,iBAAkB,EAClBC,UAAW,UACXC,aAAc,kBACdC,gBAAiB,OACjBC,UAAW,CAACC,EAAMC,OAClBC,aAAc,CAACF,EAAMC,OACrBE,WAAY,CAAC,IAAK,GAAI,IAAK,EAAG,KAAM,IAAK,EAAG,EAAG,GAC/CC,aAAcC,MACdC,oBAAqB,CAACN,EAAMC,OAC5BM,aAAc,IACdC,aAAc,IAAMpB,EAAE,4BAA4B,EAClDqB,eAAgB,GACjB,QACMC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IAAIoM,cAAgBR,qBAAqBO,qBAAqB,EAC9DnM,IAAIqM,eAAiBJ,QAAQ7F,KAAKgG,aAAa,EAC/C,GAAIC,gBAAkB,KAAM,CAC3B,OAAQ,OAAOV,kBAAkBQ,wBACjC,IAAK,QACJ,IACCE,eAAiBtK,WAAWsK,cAAc,CAC9B,CAAX,MAAOC,IACT,MACD,IAAK,SACJ,IACCD,eAAiBpE,SAASoE,cAAc,CAC5B,CAAX,MAAOC,IACT,MACD,IAAK,WACJtM,IAAIuM,eAAiBF,eACrBA,eAAiB,WAChBG,KAAKD,cAAc,CACpB,EAAEnJ,KAAKsI,OAAO,EAAE,EAChB,MACD,QACC,KACD,CACAQ,OAAOC,uBAAyBE,cACjC,CACD,CACD,CACA,OAAOH,MACR,CAEA,SAASO,KAAKC,GACb1M,IAAIqB,EAAUoK,kBAAkBiB,EAAShL,OAAOC,OAAO,CACtDgL,YAAa,GACbC,YAAa,EACd,EAAG3M,QAAQ,CAAC,EACZ,GAAIoB,EAAQ,gBAAkB,KAAM,CACnCrB,IAAI6M,EAAY,IAAIxJ,YAAYzD,EAAE8M,CAAO,EAAGrL,CAAO,EACnDwL,EAAUzB,aAAa/J,EAAQ,cAAc,EAAEiI,KAAK,WACnD,GAAIjI,EAAQ,gBAAkB,KAAM,CACnCwL,EAAUhJ,QAAQxC,EAAQ,cAAc,CACzC,CACD,CAAC,EACDqL,EAAQ7K,IAAI,CAAC,EAAEgL,UAAYA,CAC5B,CACD,CACAjN,EAAE,WACDA,EAAE,eAAe,EAAEkN,KAAK,WACvB9M,IAAI+M,EAAUnN,EAAE2B,IAAI,EACpBkL,KAAKM,CAAO,CACb,CAAC,CACF,CAAC,EACDpN,QAAQ0D,YAAcA,WACtB,GAAEuG,OAAQA,OAAOoD,IAAMpD,OAAOqD,QAAUpN,SAAS"} \ No newline at end of file diff --git a/pdfjs-viewer.js b/pdfjs-viewer.js deleted file mode 100644 index 0d4e0ad..0000000 --- a/pdfjs-viewer.js +++ /dev/null @@ -1,566 +0,0 @@ -/** - Copyright 2021 Carlos A. (https://github.com/dealfonso) - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -(function(exports, $) { - "use strict"; - let defaults = { - visibleThreshold: .5, - extraPagesToLoad: 3, - pageClass: "pdfpage", - contentClass: "content-wrapper", - onDocumentReady: () => {}, - onNewPage: (page, i) => {}, - onPageRender: (page, i) => {}, - errorPage: () => { - $(`
`).addClass(this.settings.pageClass).append($(`

`).text("could not load document")); - }, - zoomValues: [ .25, .5, .75, 1, 1.25, 1.5, 2, 4, 8 ], - onZoomChange: zoomlevel => {}, - onActivePageChanged: (page, i) => {}, - zoomFillArea: .95, - emptyContent: () => $('
'), - renderingScale: 1.5 - }; - class Zoomer { - constructor(viewer, options = {}) { - let defaults = { - zoomValues: [ .25, .5, .75, 1, 1.25, 1.5, 2, 4, 8 ], - fillArea: .9 - }; - this.current = 1; - this.viewer = viewer; - this.settings = $.extend(defaults, options); - this.settings.zoomValues = this.settings.zoomValues.sort(); - } - get(zoom = null) { - if (zoom === null) { - return this.current; - } - if (parseFloat(zoom) == zoom) { - return zoom; - } - let $activepage = this.viewer.getActivePage(); - let zoomValues = []; - switch (zoom) { - case "in": - zoom = this.current; - zoomValues = this.settings.zoomValues.filter(x => x > zoom); - if (zoomValues.length > 0) { - zoom = Math.min(...zoomValues); - } - break; - - case "out": - zoom = this.current; - zoomValues = this.settings.zoomValues.filter(x => x < zoom); - if (zoomValues.length > 0) { - zoom = Math.max(...zoomValues); - } - break; - - case "fit": - zoom = Math.min(this.get("width"), this.get("height")); - break; - - case "width": - zoom = this.settings.fillArea * this.viewer.$container.width() / $activepage.data("width"); - break; - - case "height": - zoom = this.settings.fillArea * this.viewer.$container.height() / $activepage.data("height"); - break; - - default: - zoom = this.current; - break; - } - return zoom; - } - zoomPages(zoom) { - zoom = this.get(zoom); - this.viewer.getPages().forEach(function(page) { - let $page = page.$div; - let c_width = $page.data("width"); - let c_height = $page.data("height"); - $page.width(c_width * zoom).height(c_height * zoom); - $page.data("zoom", zoom); - $page.find(`.${this.viewer.settings.contentClass}`).width(c_width * zoom).height(c_height * zoom); - }.bind(this)); - this.current = zoom; - } - } - class PDFjsViewer { - constructor($container, options = {}) { - this.settings = $.extend(Object.assign({}, defaults), options); - this._zoom = new Zoomer(this, { - zoomValues: this.settings.zoomValues, - fillArea: this.settings.zoomFillArea - }); - this.$container = $container; - $container.get(0)._pdfjsViewer = this; - this._setScrollListener(); - this.pages = []; - this.pdf = null; - this._documentReady = false; - } - setZoom(zoom) { - let container = this.$container.get(0); - let prevzoom = this._zoom.current; - let prevScroll = { - top: container.scrollTop, - left: container.scrollLeft - }; - this._zoom.zoomPages(zoom); - container.scrollLeft = prevScroll.left * this._zoom.current / prevzoom; - container.scrollTop = prevScroll.top * this._zoom.current / prevzoom; - this._visiblePages(true); - if (this._documentReady) { - if (typeof this.settings.onZoomChange === "function") this.settings.onZoomChange.call(this, this._zoom.current); - this.$container.get(0).dispatchEvent(new CustomEvent("zoomchange", { - detail: { - zoom: this._zoom.current - } - })); - } - return this._zoom.current; - } - getZoom() { - return this._zoom.current; - } - _cleanPage($page) { - let $emptyContent = this.settings.emptyContent(); - $page.find(`.${this.settings.contentClass}`).empty().append($emptyContent); - } - _setPageContent($page, $content) { - $page.find(`.${this.settings.contentClass}`).empty().append($content); - } - refreshAll() { - this._visiblePages(true); - } - _setScrollListener() { - let scrollLock = false; - let scrollPos = { - top: 0, - left: 0 - }; - this.__scrollHandler = function(e) { - if (scrollLock === true) { - return; - } - scrollLock = true; - let container = this.$container.get(0); - if (Math.abs(container.scrollTop - scrollPos.top) > container.clientHeight * .2 * this._zoom.current || Math.abs(container.scrollLeft - scrollPos.left) > container.clientWidth * .2 * this._zoom.current) { - scrollPos = { - top: container.scrollTop, - left: container.scrollLeft - }; - this._visiblePages(); - } - scrollLock = false; - }.bind(this); - this.$container.off("scroll"); - this.$container.on("scroll", this.__scrollHandler); - } - _createSkeleton(page, i) { - let pageinfo = { - $div: null, - width: 0, - height: 0, - loaded: false - }; - if (page.getViewport !== undefined) { - let viewport = page.getViewport({ - rotation: this._rotation, - scale: 1 - }); - pageinfo.width = viewport.width; - pageinfo.height = viewport.height; - pageinfo.loaded = true; - } else { - pageinfo.width = page.width; - pageinfo.height = page.height; - } - console.assert(pageinfo.width > 0 && pageinfo.height > 0, "Page width and height must be greater than 0"); - pageinfo.$div = $(`
`).attr("data-page", i).data("width", pageinfo.width).data("height", pageinfo.height).data("zoom", this._zoom.current).addClass(this.settings.pageClass).width(pageinfo.width * this._zoom.current).height(pageinfo.height * this._zoom.current); - let $content = $(`
`).width(pageinfo.width).height(pageinfo.height); - pageinfo.$div.append($content); - this._cleanPage(pageinfo.$div); - return pageinfo; - } - _placeSkeleton(pageinfo, i) { - let prevpage = i - 1; - let $prevpage = null; - while (prevpage > 0 && ($prevpage = this.$container.find(`.${this.settings.pageClass}[data-page="${prevpage}"]`)).length === 0) { - prevpage--; - } - if (prevpage === 0) { - this.$container.append(pageinfo.$div); - } else { - $prevpage.after(pageinfo.$div); - } - } - _createSkeletons(pageinfo) { - for (let i = 1; i <= this.pageCount; i++) { - if (this.pages[i] === undefined) { - pageinfo = this._createSkeleton(pageinfo, i); - this.pages[i] = pageinfo; - this._placeSkeleton(pageinfo, i); - if (this._documentReady) { - if (typeof this.settings.onNewPage === "function") { - this.settings.onNewPage.call(this, pageinfo.$div, i); - } - this.$container.get(0).dispatchEvent(new CustomEvent("newpage", { - detail: { - pageNumber: i, - page: pageinfo.$div.get(0) - } - })); - } - } - } - } - _setActivePage(i) { - if (this._activePage !== i) { - this._activePage = i; - let activePage = this.getActivePage(); - if (this._documentReady) { - if (typeof this.settings.onActivePageChanged === "function") this.settings.onActivePageChanged.call(this, activePage, i); - this.$container.get(0).dispatchEvent(new CustomEvent("activepagechanged", { - detail: { - activePageNumber: i, - activePage: activePage == null ? null : activePage.get(0) - } - })); - } - } - } - _areaOfPageVisible($page) { - if ($page === undefined) { - return 0; - } - let c_offset = this.$container.offset(); - let c_width = this.$container.width(); - let c_height = this.$container.height(); - let position = $page.offset(); - position.top -= c_offset.top; - position.left -= c_offset.left; - position.bottom = position.top + $page.outerHeight(); - position.right = position.left + $page.outerWidth(); - let page_y0 = Math.min(Math.max(position.top, 0), c_height); - let page_y1 = Math.min(Math.max($page.outerHeight() + position.top, 0), c_height); - let page_x0 = Math.min(Math.max(position.left, 0), c_width); - let page_x1 = Math.min(Math.max($page.outerWidth() + position.left, 0), c_width); - let vis_x = page_x1 - page_x0; - let vis_y = page_y1 - page_y0; - return vis_x * vis_y; - } - isPageVisible(i) { - if (this.pdf === null || i === undefined || i === null || i < 1 || i > this.pdf.numPages) { - return false; - } - let $page = i; - if (typeof i === "number") { - if (this.pages[i] === undefined) return false; - $page = this.pages[i].$div; - } - return this._areaOfPageVisible($page) > $page.outerWidth() * $page.outerHeight() * this.settings.visibleThreshold; - } - _visiblePages(forceRedraw = false) { - let max_area = 0; - let i_page = null; - if (this.pages.length === 0) { - this._visibles = []; - this._setActivePage(0); - return; - } - let $visibles = this.pages.filter(function(pageinfo) { - let areaVisible = this._areaOfPageVisible(pageinfo.$div); - if (areaVisible > max_area) { - max_area = areaVisible; - i_page = pageinfo.$div.data("page"); - } - return areaVisible > 0; - }.bind(this)).map(x => x.$div); - this._setActivePage(i_page); - let visibles = $visibles.map(x => $(x).data("page")); - if (visibles.length > 0) { - let minVisible = Math.min(...visibles); - let maxVisible = Math.max(...visibles); - for (let i = Math.max(1, minVisible - this.settings.extraPagesToLoad); i < minVisible; i++) { - if (!visibles.includes(i)) visibles.push(i); - } - for (let i = maxVisible + 1; i <= Math.min(maxVisible + this.settings.extraPagesToLoad, this.pdf.numPages); i++) { - if (!visibles.includes(i)) visibles.push(i); - } - } - let nowVisibles = visibles; - if (!forceRedraw) { - nowVisibles = visibles.filter(function(x) { - return !this._visibles.includes(x); - }.bind(this)); - } - this._visibles.filter(function(x) { - return !visibles.includes(x); - }).forEach(function(i) { - this._cleanPage(this.pages[i].$div); - }.bind(this)); - this._visibles = visibles; - this.loadPages(...nowVisibles); - } - loadPages(...pages) { - this._pagesLoading.push(...pages); - if (this._loading) { - return; - } - this._loadingTask(); - } - _loadingTask() { - this._loading = true; - if (this._pagesLoading.length > 0) { - let pagei = this._pagesLoading.shift(); - this.pdf.getPage(pagei).then(function(page) { - this._renderPage(page, pagei); - }.bind(this)).then(function(pageinfo) { - if (this._pagesLoading.length > 0) { - this._loadingTask(); - } - }.bind(this)); - } - this._loading = false; - } - scrollToPage(i) { - if (this.pages.length === 0 || this.pages[i] === undefined) { - return; - } - let $page = this.pages[i].$div; - if ($page.length === 0) { - console.warn(`Page ${i} not found`); - return; - } - let position = $page.position(); - let containerPosition = this.$container.position(); - if (position !== undefined) { - this.$container.get(0).scrollTop = this.$container.get(0).scrollTop + position.top - containerPosition.top; - this.$container.get(0).scrollLeft = this.$container.get(0).scrollLeft + position.left - containerPosition.left; - } - this._setActivePage(i); - } - _renderPage(page, i) { - let pageinfo = this.pages[i]; - let scale = this.settings.renderingScale; - let pixel_ratio = window.devicePixelRatio || 1; - let viewport = page.getViewport({ - rotation: this._rotation, - scale: this._zoom.current * scale - }); - pageinfo.width = viewport.width / this._zoom.current / scale; - pageinfo.height = viewport.height / this._zoom.current / scale; - pageinfo.$div.data("width", pageinfo.width); - pageinfo.$div.data("height", pageinfo.height); - pageinfo.$div.width(pageinfo.width * this._zoom.current); - pageinfo.$div.height(pageinfo.height * this._zoom.current); - pageinfo.loaded = true; - let $canvas = $(""); - let canvas = $canvas.get(0); - let context = canvas.getContext("2d"); - canvas.height = viewport.height * pixel_ratio; - canvas.width = viewport.width * pixel_ratio; - canvas.getContext("2d"); - var transform = pixel_ratio !== 1 ? [ pixel_ratio, 0, 0, pixel_ratio, 0, 0 ] : null; - var renderContext = { - canvasContext: context, - viewport: viewport, - transform: transform - }; - return page.render(renderContext).promise.then(function() { - this._setPageContent(pageinfo.$div, $canvas); - if (this._documentReady) { - if (typeof this.settings.onPageRender === "function") { - this.settings.onPageRender.call(this, pageinfo.$div, i); - } - this.$container.get(0).dispatchEvent(new CustomEvent("pagerender", { - detail: { - pageNumber: i, - page: pageinfo.$div.get(0) - } - })); - } - return pageinfo; - }.bind(this)); - } - getActivePage() { - if (this._activePage === null || this.pdf === null) { - return null; - } - if (this._activePage < 1 || this._activePage > this.pdf.numPages) { - return null; - } - return this.pages[this._activePage].$div; - } - getPages() { - return this.pages; - } - getPageCount() { - if (this.pdf === null) { - return 0; - } - return this.pdf.numPages; - } - next() { - if (this._activePage < this.pdf.numPages) { - this.scrollToPage(this._activePage + 1); - } - } - prev() { - if (this._activePage > 1) { - this.scrollToPage(this._activePage - 1); - } - } - first() { - if (this._activePage !== 1) { - this.scrollToPage(1); - } - } - last() { - if (this.pdf === null) return; - if (this._activePage !== this.pdf.numPages) { - this.scrollToPage(this.pdf.numPages); - } - } - rotate(deg, accumulate = false) { - if (accumulate) { - deg = deg + this._rotation; - } - this._rotation = deg; - let container = this.$container.get(0); - let prevScroll = { - top: container.scrollTop, - left: container.scrollLeft, - height: container.scrollHeight, - width: container.scrollWidth - }; - return this.forceViewerInitialization().then(function() { - let newScroll = { - top: container.scrollTop, - left: container.scrollLeft, - height: container.scrollHeight, - width: container.scrollWidth - }; - container.scrollTop = prevScroll.top * (newScroll.height / prevScroll.height); - container.scrollLeft = prevScroll.left * (newScroll.width / prevScroll.width); - }.bind(this)); - } - forceViewerInitialization() { - this.pages = []; - this.$container.find(`.${this.settings.pageClass}`).remove(); - this._pagesLoading = []; - this._loading = false; - this._visibles = []; - this._activePage = null; - return this.pdf.getPage(1).then(function(page) { - this._createSkeletons(page); - this._visiblePages(); - this._setActivePage(1); - }.bind(this)); - } - async loadDocument(document) { - this._documentReady = false; - this.pages = []; - this.$container.find(`.${this.settings.pageClass}`).remove(); - this.pdf = null; - let loadingTask = pdfjsLib.getDocument(document); - return loadingTask.promise.then(function(pdf) { - this.pdf = pdf; - this.pageCount = pdf.numPages; - this._rotation = 0; - return this.forceViewerInitialization(); - }.bind(this)).then(function() { - if (typeof this.settings.onDocumentReady === "function") { - this.settings.onDocumentReady.call(this); - } - this.$container.get(0).dispatchEvent(new CustomEvent("documentready", { - detail: { - document: this.pdf - } - })); - this._setActivePage(0); - this._documentReady = true; - this._setActivePage(1); - }.bind(this)); - } - } - function recoverAttributes(target, attributeDefaults) { - const camelcaseToSnakecase = str => str.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`); - let $target = $(target); - let result = {}; - if ($target.length > 0) { - $target = $($target[0]); - for (let originalAttributeName in attributeDefaults) { - let attributeName = camelcaseToSnakecase(originalAttributeName); - let attributeValue = $target.attr(attributeName); - if (attributeValue != null) { - switch (typeof attributeDefaults[originalAttributeName]) { - case "float": - try { - attributeValue = parseFloat(attributeValue); - } catch (_) {} - break; - - case "number": - try { - attributeValue = parseInt(attributeValue); - } catch (_) {} - break; - - case "function": - let functionString = attributeValue; - attributeValue = function() { - eval(functionString); - }.bind(target[0]); - break; - - default: - break; - } - result[originalAttributeName] = attributeValue; - } - } - } - return result; - } - function init(element) { - let options = recoverAttributes(element, Object.assign({ - pdfDocument: "", - initialZoom: "" - }, defaults)); - if (options["pdfDocument"] != null) { - let pdfViewer = new PDFjsViewer($(element), options); - pdfViewer.loadDocument(options["pdfDocument"]).then(function() { - if (options["initialZoom"] != null) { - pdfViewer.setZoom(options["initialZoom"]); - } - }); - element.get(0).pdfViewer = pdfViewer; - } - } - $(function() { - $(".pdfjs-viewer").each(function() { - let $viewer = $(this); - init($viewer); - }); - }); - exports.PDFjsViewer = PDFjsViewer; -})(window, jQuery); diff --git a/pdfjs-viewer.min.js b/pdfjs-viewer.min.js deleted file mode 100644 index b031903..0000000 --- a/pdfjs-viewer.min.js +++ /dev/null @@ -1,2 +0,0 @@ -/* Copyright 2021 Carlos A. (https://github.com/dealfonso); License: http://www.apache.org/licenses/LICENSE-2.0 */ -(function(exports,$){"use strict";let defaults={visibleThreshold:.5,extraPagesToLoad:3,pageClass:"pdfpage",contentClass:"content-wrapper",onDocumentReady:()=>{},onNewPage:(page,i)=>{},onPageRender:(page,i)=>{},errorPage:()=>{$(`
`).addClass(this.settings.pageClass).append($(`

`).text("could not load document"))},zoomValues:[.25,.5,.75,1,1.25,1.5,2,4,8],onZoomChange:zoomlevel=>{},onActivePageChanged:(page,i)=>{},zoomFillArea:.95,emptyContent:()=>$('
'),renderingScale:1.5};class Zoomer{constructor(viewer,options={}){let defaults={zoomValues:[.25,.5,.75,1,1.25,1.5,2,4,8],fillArea:.9};this.current=1;this.viewer=viewer;this.settings=$.extend(defaults,options);this.settings.zoomValues=this.settings.zoomValues.sort()}get(zoom=null){if(zoom===null){return this.current}if(parseFloat(zoom)==zoom){return zoom}let $activepage=this.viewer.getActivePage();let zoomValues=[];switch(zoom){case"in":zoom=this.current;zoomValues=this.settings.zoomValues.filter(x=>x>zoom);if(zoomValues.length>0){zoom=Math.min(...zoomValues)}break;case"out":zoom=this.current;zoomValues=this.settings.zoomValues.filter(x=>x0){zoom=Math.max(...zoomValues)}break;case"fit":zoom=Math.min(this.get("width"),this.get("height"));break;case"width":zoom=this.settings.fillArea*this.viewer.$container.width()/$activepage.data("width");break;case"height":zoom=this.settings.fillArea*this.viewer.$container.height()/$activepage.data("height");break;default:zoom=this.current;break}return zoom}zoomPages(zoom){zoom=this.get(zoom);this.viewer.getPages().forEach(function(page){let $page=page.$div;let c_width=$page.data("width");let c_height=$page.data("height");$page.width(c_width*zoom).height(c_height*zoom);$page.data("zoom",zoom);$page.find(`.${this.viewer.settings.contentClass}`).width(c_width*zoom).height(c_height*zoom)}.bind(this));this.current=zoom}}class PDFjsViewer{constructor($container,options={}){this.settings=$.extend(Object.assign({},defaults),options);this._zoom=new Zoomer(this,{zoomValues:this.settings.zoomValues,fillArea:this.settings.zoomFillArea});this.$container=$container;$container.get(0)._pdfjsViewer=this;this._setScrollListener();this.pages=[];this.pdf=null;this._documentReady=false}setZoom(zoom){let container=this.$container.get(0);let prevzoom=this._zoom.current;let prevScroll={top:container.scrollTop,left:container.scrollLeft};this._zoom.zoomPages(zoom);container.scrollLeft=prevScroll.left*this._zoom.current/prevzoom;container.scrollTop=prevScroll.top*this._zoom.current/prevzoom;this._visiblePages(true);if(this._documentReady){if(typeof this.settings.onZoomChange==="function")this.settings.onZoomChange.call(this,this._zoom.current);this.$container.get(0).dispatchEvent(new CustomEvent("zoomchange",{detail:{zoom:this._zoom.current}}))}return this._zoom.current}getZoom(){return this._zoom.current}_cleanPage($page){let $emptyContent=this.settings.emptyContent();$page.find(`.${this.settings.contentClass}`).empty().append($emptyContent)}_setPageContent($page,$content){$page.find(`.${this.settings.contentClass}`).empty().append($content)}refreshAll(){this._visiblePages(true)}_setScrollListener(){let scrollLock=false;let scrollPos={top:0,left:0};this.__scrollHandler=function(e){if(scrollLock===true){return}scrollLock=true;let container=this.$container.get(0);if(Math.abs(container.scrollTop-scrollPos.top)>container.clientHeight*.2*this._zoom.current||Math.abs(container.scrollLeft-scrollPos.left)>container.clientWidth*.2*this._zoom.current){scrollPos={top:container.scrollTop,left:container.scrollLeft};this._visiblePages()}scrollLock=false}.bind(this);this.$container.off("scroll");this.$container.on("scroll",this.__scrollHandler)}_createSkeleton(page,i){let pageinfo={$div:null,width:0,height:0,loaded:false};if(page.getViewport!==undefined){let viewport=page.getViewport({rotation:this._rotation,scale:1});pageinfo.width=viewport.width;pageinfo.height=viewport.height;pageinfo.loaded=true}else{pageinfo.width=page.width;pageinfo.height=page.height}console.assert(pageinfo.width>0&&pageinfo.height>0,"Page width and height must be greater than 0");pageinfo.$div=$(`
`).attr("data-page",i).data("width",pageinfo.width).data("height",pageinfo.height).data("zoom",this._zoom.current).addClass(this.settings.pageClass).width(pageinfo.width*this._zoom.current).height(pageinfo.height*this._zoom.current);let $content=$(`
`).width(pageinfo.width).height(pageinfo.height);pageinfo.$div.append($content);this._cleanPage(pageinfo.$div);return pageinfo}_placeSkeleton(pageinfo,i){let prevpage=i-1;let $prevpage=null;while(prevpage>0&&($prevpage=this.$container.find(`.${this.settings.pageClass}[data-page="${prevpage}"]`)).length===0){prevpage--}if(prevpage===0){this.$container.append(pageinfo.$div)}else{$prevpage.after(pageinfo.$div)}}_createSkeletons(pageinfo){for(let i=1;i<=this.pageCount;i++){if(this.pages[i]===undefined){pageinfo=this._createSkeleton(pageinfo,i);this.pages[i]=pageinfo;this._placeSkeleton(pageinfo,i);if(this._documentReady){if(typeof this.settings.onNewPage==="function"){this.settings.onNewPage.call(this,pageinfo.$div,i)}this.$container.get(0).dispatchEvent(new CustomEvent("newpage",{detail:{pageNumber:i,page:pageinfo.$div.get(0)}}))}}}}_setActivePage(i){if(this._activePage!==i){this._activePage=i;let activePage=this.getActivePage();if(this._documentReady){if(typeof this.settings.onActivePageChanged==="function")this.settings.onActivePageChanged.call(this,activePage,i);this.$container.get(0).dispatchEvent(new CustomEvent("activepagechanged",{detail:{activePageNumber:i,activePage:activePage==null?null:activePage.get(0)}}))}}}_areaOfPageVisible($page){if($page===undefined){return 0}let c_offset=this.$container.offset();let c_width=this.$container.width();let c_height=this.$container.height();let position=$page.offset();position.top-=c_offset.top;position.left-=c_offset.left;position.bottom=position.top+$page.outerHeight();position.right=position.left+$page.outerWidth();let page_y0=Math.min(Math.max(position.top,0),c_height);let page_y1=Math.min(Math.max($page.outerHeight()+position.top,0),c_height);let page_x0=Math.min(Math.max(position.left,0),c_width);let page_x1=Math.min(Math.max($page.outerWidth()+position.left,0),c_width);let vis_x=page_x1-page_x0;let vis_y=page_y1-page_y0;return vis_x*vis_y}isPageVisible(i){if(this.pdf===null||i===undefined||i===null||i<1||i>this.pdf.numPages){return false}let $page=i;if(typeof i==="number"){if(this.pages[i]===undefined)return false;$page=this.pages[i].$div}return this._areaOfPageVisible($page)>$page.outerWidth()*$page.outerHeight()*this.settings.visibleThreshold}_visiblePages(forceRedraw=false){let max_area=0;let i_page=null;if(this.pages.length===0){this._visibles=[];this._setActivePage(0);return}let $visibles=this.pages.filter(function(pageinfo){let areaVisible=this._areaOfPageVisible(pageinfo.$div);if(areaVisible>max_area){max_area=areaVisible;i_page=pageinfo.$div.data("page")}return areaVisible>0}.bind(this)).map(x=>x.$div);this._setActivePage(i_page);let visibles=$visibles.map(x=>$(x).data("page"));if(visibles.length>0){let minVisible=Math.min(...visibles);let maxVisible=Math.max(...visibles);for(let i=Math.max(1,minVisible-this.settings.extraPagesToLoad);i0){let pagei=this._pagesLoading.shift();this.pdf.getPage(pagei).then(function(page){this._renderPage(page,pagei)}.bind(this)).then(function(pageinfo){if(this._pagesLoading.length>0){this._loadingTask()}}.bind(this))}this._loading=false}scrollToPage(i){if(this.pages.length===0||this.pages[i]===undefined){return}let $page=this.pages[i].$div;if($page.length===0){console.warn(`Page ${i} not found`);return}let position=$page.position();let containerPosition=this.$container.position();if(position!==undefined){this.$container.get(0).scrollTop=this.$container.get(0).scrollTop+position.top-containerPosition.top;this.$container.get(0).scrollLeft=this.$container.get(0).scrollLeft+position.left-containerPosition.left}this._setActivePage(i)}_renderPage(page,i){let pageinfo=this.pages[i];let scale=this.settings.renderingScale;let pixel_ratio=window.devicePixelRatio||1;let viewport=page.getViewport({rotation:this._rotation,scale:this._zoom.current*scale});pageinfo.width=viewport.width/this._zoom.current/scale;pageinfo.height=viewport.height/this._zoom.current/scale;pageinfo.$div.data("width",pageinfo.width);pageinfo.$div.data("height",pageinfo.height);pageinfo.$div.width(pageinfo.width*this._zoom.current);pageinfo.$div.height(pageinfo.height*this._zoom.current);pageinfo.loaded=true;let $canvas=$("");let canvas=$canvas.get(0);let context=canvas.getContext("2d");canvas.height=viewport.height*pixel_ratio;canvas.width=viewport.width*pixel_ratio;canvas.getContext("2d");var transform=pixel_ratio!==1?[pixel_ratio,0,0,pixel_ratio,0,0]:null;var renderContext={canvasContext:context,viewport:viewport,transform:transform};return page.render(renderContext).promise.then(function(){this._setPageContent(pageinfo.$div,$canvas);if(this._documentReady){if(typeof this.settings.onPageRender==="function"){this.settings.onPageRender.call(this,pageinfo.$div,i)}this.$container.get(0).dispatchEvent(new CustomEvent("pagerender",{detail:{pageNumber:i,page:pageinfo.$div.get(0)}}))}return pageinfo}.bind(this))}getActivePage(){if(this._activePage===null||this.pdf===null){return null}if(this._activePage<1||this._activePage>this.pdf.numPages){return null}return this.pages[this._activePage].$div}getPages(){return this.pages}getPageCount(){if(this.pdf===null){return 0}return this.pdf.numPages}next(){if(this._activePage1){this.scrollToPage(this._activePage-1)}}first(){if(this._activePage!==1){this.scrollToPage(1)}}last(){if(this.pdf===null)return;if(this._activePage!==this.pdf.numPages){this.scrollToPage(this.pdf.numPages)}}rotate(deg,accumulate=false){if(accumulate){deg=deg+this._rotation}this._rotation=deg;let container=this.$container.get(0);let prevScroll={top:container.scrollTop,left:container.scrollLeft,height:container.scrollHeight,width:container.scrollWidth};return this.forceViewerInitialization().then(function(){let newScroll={top:container.scrollTop,left:container.scrollLeft,height:container.scrollHeight,width:container.scrollWidth};container.scrollTop=prevScroll.top*(newScroll.height/prevScroll.height);container.scrollLeft=prevScroll.left*(newScroll.width/prevScroll.width)}.bind(this))}forceViewerInitialization(){this.pages=[];this.$container.find(`.${this.settings.pageClass}`).remove();this._pagesLoading=[];this._loading=false;this._visibles=[];this._activePage=null;return this.pdf.getPage(1).then(function(page){this._createSkeletons(page);this._visiblePages();this._setActivePage(1)}.bind(this))}async loadDocument(document){this._documentReady=false;this.pages=[];this.$container.find(`.${this.settings.pageClass}`).remove();this.pdf=null;let loadingTask=pdfjsLib.getDocument(document);return loadingTask.promise.then(function(pdf){this.pdf=pdf;this.pageCount=pdf.numPages;this._rotation=0;return this.forceViewerInitialization()}.bind(this)).then(function(){if(typeof this.settings.onDocumentReady==="function"){this.settings.onDocumentReady.call(this)}this.$container.get(0).dispatchEvent(new CustomEvent("documentready",{detail:{document:this.pdf}}));this._setActivePage(0);this._documentReady=true;this._setActivePage(1)}.bind(this))}}function recoverAttributes(target,attributeDefaults){const camelcaseToSnakecase=str=>str.replace(/[A-Z]/g,letter=>`-${letter.toLowerCase()}`);let $target=$(target);let result={};if($target.length>0){$target=$($target[0]);for(let originalAttributeName in attributeDefaults){let attributeName=camelcaseToSnakecase(originalAttributeName);let attributeValue=$target.attr(attributeName);if(attributeValue!=null){switch(typeof attributeDefaults[originalAttributeName]){case"float":try{attributeValue=parseFloat(attributeValue)}catch(_){}break;case"number":try{attributeValue=parseInt(attributeValue)}catch(_){}break;case"function":let functionString=attributeValue;attributeValue=function(){eval(functionString)}.bind(target[0]);break;default:break}result[originalAttributeName]=attributeValue}}}return result}function init(element){let options=recoverAttributes(element,Object.assign({pdfDocument:"",initialZoom:""},defaults));if(options["pdfDocument"]!=null){let pdfViewer=new PDFjsViewer($(element),options);pdfViewer.loadDocument(options["pdfDocument"]).then(function(){if(options["initialZoom"]!=null){pdfViewer.setZoom(options["initialZoom"])}});element.get(0).pdfViewer=pdfViewer}}$(function(){$(".pdfjs-viewer").each(function(){let $viewer=$(this);init($viewer)})});exports.PDFjsViewer=PDFjsViewer})(window,jQuery);