2022-03-18 06:27:29 -04:00
|
|
|
// To add a new version, copy and adjust one of the `importPDFJS*` functions below,
|
|
|
|
// add the variant to the "switch" statement, and add to `pdfjsVersions` in webpack.config.js
|
|
|
|
|
2022-04-06 05:59:13 -04:00
|
|
|
import 'core-js/stable/global-this' // polyfill for globalThis (used by pdf.js)
|
|
|
|
import 'core-js/stable/promise/all-settled' // polyfill for Promise.allSettled (used by pdf.js)
|
2022-03-18 06:27:29 -04:00
|
|
|
import getMeta from '../../../utils/meta'
|
2022-04-06 05:59:13 -04:00
|
|
|
import { createWorker } from '../../../utils/worker'
|
2022-03-18 06:27:29 -04:00
|
|
|
|
2022-12-08 04:27:13 -05:00
|
|
|
async function importPDFJS31() {
|
|
|
|
const cMapUrl = '/js/pdfjs-dist31/cmaps/'
|
|
|
|
const standardFontDataUrl = '/fonts/pdfjs-dist31/'
|
2022-12-09 04:34:39 -05:00
|
|
|
const imageResourcesPath = '/images/pdfjs-dist31/'
|
2022-03-18 06:27:29 -04:00
|
|
|
|
2022-04-06 05:59:13 -04:00
|
|
|
const [PDFJS, PDFJSViewer] = await Promise.all([
|
2022-12-08 04:27:13 -05:00
|
|
|
import('pdfjs-dist31/legacy/build/pdf'),
|
|
|
|
import('pdfjs-dist31/legacy/web/pdf_viewer'),
|
|
|
|
import('pdfjs-dist31/legacy/web/pdf_viewer.css'),
|
2022-03-18 06:27:29 -04:00
|
|
|
])
|
|
|
|
|
2022-04-06 05:59:13 -04:00
|
|
|
createWorker(() => {
|
|
|
|
PDFJS.GlobalWorkerOptions.workerPort = new Worker(
|
2022-12-08 04:27:13 -05:00
|
|
|
new URL('pdfjs-dist31/legacy/build/pdf.worker.js', import.meta.url)
|
2022-04-06 05:59:13 -04:00
|
|
|
)
|
|
|
|
})
|
2022-03-18 06:27:29 -04:00
|
|
|
|
2022-07-27 06:15:43 -04:00
|
|
|
return {
|
|
|
|
PDFJS,
|
|
|
|
PDFJSViewer,
|
|
|
|
cMapUrl,
|
|
|
|
imageResourcesPath,
|
|
|
|
standardFontDataUrl,
|
|
|
|
}
|
2022-03-18 06:27:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function importPDFJS213() {
|
|
|
|
const cMapUrl = '/js/pdfjs-dist213/cmaps/'
|
2022-07-27 06:15:43 -04:00
|
|
|
const standardFontDataUrl = '/fonts/pdfjs-dist213/'
|
2022-12-09 04:34:39 -05:00
|
|
|
const imageResourcesPath = '/images/pdfjs-dist213/'
|
2022-03-18 06:27:29 -04:00
|
|
|
|
2022-04-06 05:59:13 -04:00
|
|
|
const [PDFJS, PDFJSViewer] = await Promise.all([
|
2022-03-18 06:27:29 -04:00
|
|
|
import('pdfjs-dist213/legacy/build/pdf'),
|
|
|
|
import('pdfjs-dist213/legacy/web/pdf_viewer'),
|
|
|
|
import('pdfjs-dist213/legacy/web/pdf_viewer.css'),
|
|
|
|
])
|
|
|
|
|
2022-04-06 05:59:13 -04:00
|
|
|
createWorker(() => {
|
|
|
|
PDFJS.GlobalWorkerOptions.workerPort = new Worker(
|
|
|
|
new URL('pdfjs-dist213/legacy/build/pdf.worker.js', import.meta.url)
|
|
|
|
)
|
|
|
|
})
|
2022-03-18 06:27:29 -04:00
|
|
|
|
2022-07-27 06:15:43 -04:00
|
|
|
return {
|
|
|
|
PDFJS,
|
|
|
|
PDFJSViewer,
|
|
|
|
cMapUrl,
|
|
|
|
imageResourcesPath,
|
|
|
|
standardFontDataUrl,
|
|
|
|
}
|
2022-03-18 06:27:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function importPDFJS() {
|
|
|
|
const variant = getMeta('ol-pdfjsVariant', 'default')
|
|
|
|
|
|
|
|
switch (variant) {
|
|
|
|
case '213':
|
2022-05-16 05:42:16 -04:00
|
|
|
case 'default':
|
2022-03-18 06:27:29 -04:00
|
|
|
return importPDFJS213()
|
|
|
|
|
2022-12-08 04:27:13 -05:00
|
|
|
case '318':
|
|
|
|
return importPDFJS31()
|
2022-03-18 06:27:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default importPDFJS()
|