diff --git a/amd/build/pdfembed.min.js b/amd/build/pdfembed.min.js index 7eda1c05..2dcfc678 100644 --- a/amd/build/pdfembed.min.js +++ b/amd/build/pdfembed.min.js @@ -1,11 +1,10 @@ -define("mod_datalynx/pdfembed",["exports","mod_datalynx/pdf","mod_datalynx/pdf.worker"],(function(_exports,pdfjsLib,_pdf2){var obj;function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.renderPDF=function(pdfUrl,canvasContainerId){M.cfg.wwwroot;const container=document.querySelector("#".concat(canvasContainerId));console.log(pdfjsLib),console.log(pdfUrl),console.log(container), +define("mod_datalynx/pdfembed",["exports","mod_datalynx/pdf","mod_datalynx/pdf.worker"],(function(_exports,pdfjsLib,pdfjsWorker){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj} /** * This module provides functionality for embedding PDFs using pdf.js. * * @module mod_datalynx/pdfembed * @copyright 2023 David Bogner * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -function(url,canvasContainer){function renderPage(page){var viewport=page.getViewport({scale:1}),canvas=document.createElement("canvas"),renderContext={canvasContext:canvas.getContext("2d"),viewport:viewport},widthScale=canvasContainer.clientWidth/viewport.width,heightScale=canvasContainer.clientHeight/viewport.height,scale=Math.min(widthScale,heightScale);canvas.width=viewport.width*scale,canvas.height=viewport.height*scale,canvasContainer.appendChild(canvas),console.log(canvasContainer,canvas,canvas.height),page.render(renderContext)}function renderPages(pdfDoc){for(var num=1;num<=pdfDoc.numPages;num++)pdfDoc.getPage(num).then(renderPage)}pdfjsLib.GlobalWorkerOptions.workerSrc=_pdf2.default,console.log(pdfjsLib.version,_pdf2.default),pdfjsLib.getDocument(url).promise.then(renderPages)}(pdfUrl,container)},pdfjsLib=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(pdfjsLib),_pdf2=(obj=_pdf2)&&obj.__esModule?obj:{default:obj}})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.renderPDF=function(pdfUrl,canvasContainerId){M.cfg.wwwroot;const container=document.querySelector("#".concat(canvasContainerId));console.log(pdfjsLib),console.log(pdfUrl),console.log(container),function(url,canvasContainer){function renderPage(page){var viewport=page.getViewport({scale:1}),canvas=document.createElement("canvas"),renderContext={canvasContext:canvas.getContext("2d"),viewport:viewport},widthScale=canvasContainer.clientWidth/viewport.width,heightScale=canvasContainer.clientHeight/viewport.height,scale=Math.min(widthScale,heightScale);canvas.width=viewport.width*scale,canvas.height=viewport.height*scale,canvasContainer.appendChild(canvas),console.log(canvasContainer,canvas,canvas.height),page.render(renderContext)}function renderPages(pdfDoc){for(var num=1;num<=pdfDoc.numPages;num++)pdfDoc.getPage(num).then(renderPage)}pdfjsLib.GlobalWorkerOptions.workerSrc=pdfjsWorker,console.log(pdfjsLib.version,pdfjsWorker),pdfjsLib.getDocument(url).promise.then(renderPages)}(pdfUrl,container)},pdfjsLib=_interopRequireWildcard(pdfjsLib),pdfjsWorker=_interopRequireWildcard(pdfjsWorker)})); //# sourceMappingURL=pdfembed.min.js.map \ No newline at end of file diff --git a/amd/build/pdfembed.min.js.map b/amd/build/pdfembed.min.js.map index 6820217c..684c5006 100644 --- a/amd/build/pdfembed.min.js.map +++ b/amd/build/pdfembed.min.js.map @@ -1 +1 @@ -{"version":3,"file":"pdfembed.min.js","sources":["../src/pdfembed.js"],"sourcesContent":["// This file is part of the mod_coursecertificate plugin for Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This module provides functionality for embedding PDFs using pdf.js.\n *\n * @module mod_datalynx/pdfembed\n * @copyright 2023 David Bogner \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n// import 'mod_datalynx/pdf';\n\nimport * as pdfjsLib from 'mod_datalynx/pdf';\nimport pdfjsWorker from 'mod_datalynx/pdf.worker';\n\n\nfunction renderPDFfunction(url, canvasContainer) {\n\n function renderPage(page) {\n var viewport = page.getViewport({ scale: 1 });\n var canvas = document.createElement('canvas');\n var ctx = canvas.getContext('2d');\n var renderContext = {\n canvasContext: ctx,\n viewport: viewport\n };\n // Calculate the scaling factors to fit the container's width and height\n var widthScale = canvasContainer.clientWidth / viewport.width;\n var heightScale = canvasContainer.clientHeight / viewport.height;\n\n // Use the minimum scale to ensure that the entire page fits within the container\n var scale = Math.min(widthScale, heightScale);\n\n // Apply the scaling factor\n canvas.width = viewport.width * scale;\n canvas.height = viewport.height * scale;\n\n // canvas.height = canvasContainer.clientHeight;\n // canvas.width = canvasContainer.clientWidth;\n\n // canvas.height = 800;\n // canvas.width = 1200;\n\n canvasContainer.appendChild(canvas);\n\n // eslint-disable-next-line no-console\n console.log(canvasContainer, canvas, canvas.height);\n\n page.render(renderContext);\n }\n\n function renderPages(pdfDoc) {\n for (var num = 1; num <= pdfDoc.numPages; num++)\n pdfDoc.getPage(num).then(renderPage);\n }\n\n pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsWorker;\n\n // eslint-disable-next-line no-console\n console.log(pdfjsLib.version, pdfjsWorker);\n\n pdfjsLib.getDocument(url).promise.then(renderPages);\n\n}\n\n// eslint-disable-next-line require-jsdoc\nexport function renderPDF(pdfUrl, canvasContainerId) {\n\n // eslint-disable-next-line no-unused-vars\n const pdf = M.cfg.wwwroot + '/mod/datalynx/tests/turnen.pdf';\n const container = document.querySelector(`#${canvasContainerId}`);\n\n // eslint-disable-next-line no-console\n console.log(pdfjsLib);\n console.log(pdfUrl);\n console.log(container);\n\n renderPDFfunction(pdfUrl, container);\n}"],"names":["pdfUrl","canvasContainerId","M","cfg","wwwroot","container","document","querySelector","console","log","pdfjsLib","url","canvasContainer","renderPage","page","viewport","getViewport","scale","canvas","createElement","renderContext","canvasContext","getContext","widthScale","clientWidth","width","heightScale","clientHeight","height","Math","min","appendChild","render","renderPages","pdfDoc","num","numPages","getPage","then","GlobalWorkerOptions","workerSrc","pdfjsWorker","version","getDocument","promise","renderPDFfunction"],"mappings":"0eA8E0BA,OAAQC,mBAGlBC,EAAEC,IAAIC,cACZC,UAAYC,SAASC,yBAAkBN,oBAG7CO,QAAQC,IAAIC,UACZF,QAAQC,IAAIT,QACZQ,QAAQC,IAAIJ;;;;;;;;SA3DWM,IAAKC,0BAEnBC,WAAWC,UACZC,SAAWD,KAAKE,YAAY,CAAEC,MAAO,IACrCC,OAASZ,SAASa,cAAc,UAEhCC,cAAgB,CAChBC,cAFMH,OAAOI,WAAW,MAGxBP,SAAUA,UAGVQ,WAAaX,gBAAgBY,YAAcT,SAASU,MACpDC,YAAcd,gBAAgBe,aAAeZ,SAASa,OAGtDX,MAAQY,KAAKC,IAAIP,WAAYG,aAGjCR,OAAOO,MAAQV,SAASU,MAAQR,MAChCC,OAAOU,OAASb,SAASa,OAASX,MAQlCL,gBAAgBmB,YAAYb,QAG5BV,QAAQC,IAAIG,gBAAiBM,OAAQA,OAAOU,QAE5Cd,KAAKkB,OAAOZ,wBAGPa,YAAYC,YACZ,IAAIC,IAAM,EAAGA,KAAOD,OAAOE,SAAUD,MACtCD,OAAOG,QAAQF,KAAKG,KAAKzB,YAGjCH,SAAS6B,oBAAoBC,UAAYC,cAGzCjC,QAAQC,IAAIC,SAASgC,QAASD,eAE9B/B,SAASiC,YAAYhC,KAAKiC,QAAQN,KAAKL,aAgBvCY,CAAkB7C,OAAQK"} \ No newline at end of file +{"version":3,"file":"pdfembed.min.js","sources":["../src/pdfembed.js"],"sourcesContent":["// This file is part of the mod_coursecertificate plugin for Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This module provides functionality for embedding PDFs using pdf.js.\n *\n * @module mod_datalynx/pdfembed\n * @copyright 2023 David Bogner \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n// import 'mod_datalynx/pdf';\n\nimport * as pdfjsLib from 'mod_datalynx/pdf';\nimport * as pdfjsWorker from 'mod_datalynx/pdf.worker';\n\nfunction renderPDFfunction(url, canvasContainer) {\n\n function renderPage(page) {\n var viewport = page.getViewport({scale: 1});\n var canvas = document.createElement('canvas');\n var ctx = canvas.getContext('2d');\n var renderContext = {\n canvasContext: ctx,\n viewport: viewport\n };\n // Calculate the scaling factors to fit the container's width and height\n var widthScale = canvasContainer.clientWidth / viewport.width;\n var heightScale = canvasContainer.clientHeight / viewport.height;\n\n // Use the minimum scale to ensure that the entire page fits within the container\n var scale = Math.min(widthScale, heightScale);\n\n // Apply the scaling factor\n canvas.width = viewport.width * scale;\n canvas.height = viewport.height * scale;\n\n // canvas.height = canvasContainer.clientHeight;\n // canvas.width = canvasContainer.clientWidth;\n\n // canvas.height = 800;\n // canvas.width = 1200;\n\n canvasContainer.appendChild(canvas);\n\n // eslint-disable-next-line no-console\n console.log(canvasContainer, canvas, canvas.height);\n\n page.render(renderContext);\n }\n\n function renderPages(pdfDoc) {\n for (var num = 1; num <= pdfDoc.numPages; num++)\n pdfDoc.getPage(num).then(renderPage);\n }\n\n pdfjsLib.GlobalWorkerOptions.workerSrc = pdfjsWorker;\n\n // eslint-disable-next-line no-console\n console.log(pdfjsLib.version, pdfjsWorker);\n\n pdfjsLib.getDocument(url).promise.then(renderPages);\n\n}\n\n// eslint-disable-next-line require-jsdoc\nexport function renderPDF(pdfUrl, canvasContainerId) {\n\n // eslint-disable-next-line no-unused-vars\n const pdf = M.cfg.wwwroot + '/mod/datalynx/tests/turnen.pdf';\n const container = document.querySelector(`#${canvasContainerId}`);\n\n // eslint-disable-next-line no-console\n console.log(pdfjsLib);\n console.log(pdfUrl);\n console.log(container);\n\n renderPDFfunction(pdfUrl, container);\n}"],"names":["pdfUrl","canvasContainerId","M","cfg","wwwroot","container","document","querySelector","console","log","pdfjsLib","url","canvasContainer","renderPage","page","viewport","getViewport","scale","canvas","createElement","renderContext","canvasContext","getContext","widthScale","clientWidth","width","heightScale","clientHeight","height","Math","min","appendChild","render","renderPages","pdfDoc","num","numPages","getPage","then","GlobalWorkerOptions","workerSrc","pdfjsWorker","version","getDocument","promise","renderPDFfunction"],"mappings":";;;;;;;yFA6E0BA,OAAQC,mBAGlBC,EAAEC,IAAIC,cACZC,UAAYC,SAASC,yBAAkBN,oBAG7CO,QAAQC,IAAIC,UACZF,QAAQC,IAAIT,QACZQ,QAAQC,IAAIJ,oBA3DWM,IAAKC,0BAEnBC,WAAWC,UACZC,SAAWD,KAAKE,YAAY,CAACC,MAAO,IACpCC,OAASZ,SAASa,cAAc,UAEhCC,cAAgB,CAChBC,cAFMH,OAAOI,WAAW,MAGxBP,SAAUA,UAGVQ,WAAaX,gBAAgBY,YAAcT,SAASU,MACpDC,YAAcd,gBAAgBe,aAAeZ,SAASa,OAGtDX,MAAQY,KAAKC,IAAIP,WAAYG,aAGjCR,OAAOO,MAAQV,SAASU,MAAQR,MAChCC,OAAOU,OAASb,SAASa,OAASX,MAQlCL,gBAAgBmB,YAAYb,QAG5BV,QAAQC,IAAIG,gBAAiBM,OAAQA,OAAOU,QAE5Cd,KAAKkB,OAAOZ,wBAGPa,YAAYC,YACZ,IAAIC,IAAM,EAAGA,KAAOD,OAAOE,SAAUD,MACtCD,OAAOG,QAAQF,KAAKG,KAAKzB,YAGjCH,SAAS6B,oBAAoBC,UAAYC,YAGzCjC,QAAQC,IAAIC,SAASgC,QAASD,aAE9B/B,SAASiC,YAAYhC,KAAKiC,QAAQN,KAAKL,aAgBvCY,CAAkB7C,OAAQK"} \ No newline at end of file diff --git a/amd/src/pdfembed.js b/amd/src/pdfembed.js index 7e32c848..eaf39db6 100644 --- a/amd/src/pdfembed.js +++ b/amd/src/pdfembed.js @@ -23,8 +23,7 @@ // import 'mod_datalynx/pdf'; import * as pdfjsLib from 'mod_datalynx/pdf'; -import pdfjsWorker from 'mod_datalynx/pdf.worker'; - +import * as pdfjsWorker from 'mod_datalynx/pdf.worker'; function renderPDFfunction(url, canvasContainer) {