`).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,IA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tB,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=>x
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);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);