From b7edc34bddfb88172f906dfc143c2e5a1dfaff30 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 6 Dec 2024 18:41:25 +0800 Subject: [PATCH] bugfix --- bricks/build.sh | 2 +- bricks/pdfviewer.js | 68 --------------------------------------------- 2 files changed, 1 insertion(+), 69 deletions(-) delete mode 100644 bricks/pdfviewer.js diff --git a/bricks/build.sh b/bricks/build.sh index 84bc196..81a9310 100755 --- a/bricks/build.sh +++ b/bricks/build.sh @@ -8,7 +8,7 @@ SOURCES=" page_data_loader.js factory.js uitypesdef.js utils.js uitype.js \ floaticonbar.js miniform.js wterm.js dynamicaccordion.js \ binstreaming.js streaming_audio.js vadtext.js rtc.js docxviewer.js \ llm_dialog.js llm.js websocket.js datarow.js tabular.js \ - line.js pie.js bar.js gobang.js period.js pdfviewer.js" + line.js pie.js bar.js gobang.js period.js " echo ${SOURCES} cat ${SOURCES} > ../dist/bricks.js # uglifyjs --compress --mangle -- ../dist/bricks.js > ../dist/bricks.min.js diff --git a/bricks/pdfviewer.js b/bricks/pdfviewer.js deleted file mode 100644 index d4268c1..0000000 --- a/bricks/pdfviewer.js +++ /dev/null @@ -1,68 +0,0 @@ -/* -https://mozilla.github.io/pdf.js download pdf from here -or add follow line to html file body tag - -*/ - -var bricks = window.bricks || {} - -bricks.PDFviewer = class extends bricks.VBox { - /* - url: - */ - constructor(opts){ - super(opts); - this.curpage = null; - this.pdf = null; - bricks.app.bind('keydown', this.key_action.bind(this)); - schedule_once(this.renderPage(1), 1); - } - key_action(e){ - if (!this.curpage) return; - switch(e.key){ - case 'Enter': - case ' ': - case 'ArrowDown': - this.renderPage(this.curpage+1); - break; - case 'ArrowUp': - this.renderPage(this.curpage-1); - break; - } - } - async renderPage(pn){ - if (pn < 1) return; - this.curpage = pn; - if (!this.pdf) { - pdfjsLib.getDocument(this.url).promise.then(function(pdf){ - this.pdf = pdf; - pdf.getPage(pn).promise.then(function(page){ - this._render_page(page); - }); - }); - return; - } - this.pdf.getPage(pn).promise.then(function(page){ - this._render_page(page); - }); - } - _render_page(page){ - var scale = 1.5; - var viewport = page.getViewport({scale: scale}); - var canvasElement = document.createElement('canvas'); - var context = canvasElement.getContext('2d'); - - canvasElement.height = viewport.height; - canvasElement.width = viewport.width; - - var renderContext = { - canvasContext: context, - viewport: viewport - }; - page.render(renderContext); - this.dom_element.innerHTML = ''; - this.dom_element.appendChild(canvasElement); - } -} - -bricks.Factory.register('PDFviewer', bricks.PDFviewer);