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)
|
2023-11-14 04:51:30 -05:00
|
|
|
import getMeta from '@/utils/meta'
|
|
|
|
import { createWorker } from '@/utils/worker'
|
2022-03-18 06:27:29 -04:00
|
|
|
|
2023-11-14 04:51:30 -05:00
|
|
|
async function importPDFJS401() {
|
|
|
|
const cMapUrl = '/js/pdfjs-dist401/cmaps/'
|
|
|
|
const standardFontDataUrl = '/fonts/pdfjs-dist401/'
|
|
|
|
const imageResourcesPath = '/images/pdfjs-dist401/'
|
2022-03-18 06:27:29 -04:00
|
|
|
|
2023-11-14 04:51:30 -05:00
|
|
|
// ensure that PDF.js is loaded before importing the viewer
|
|
|
|
const PDFJS = await import('pdfjs-dist401/legacy/build/pdf')
|
|
|
|
|
|
|
|
const [PDFJSViewer] = await Promise.all([
|
|
|
|
import('pdfjs-dist401/legacy/web/pdf_viewer'),
|
|
|
|
import('pdfjs-dist401/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(
|
2023-11-14 04:51:30 -05:00
|
|
|
new URL('pdfjs-dist401/legacy/build/pdf.worker.mjs', import.meta.url) // NOTE: .mjs extension
|
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
|
|
|
|
2023-11-14 04:51:30 -05:00
|
|
|
// ensure that PDF.js is loaded before importing the viewer
|
|
|
|
const PDFJS = await import('pdfjs-dist213/legacy/build/pdf')
|
|
|
|
|
|
|
|
const [PDFJSViewer] = await Promise.all([
|
2022-03-18 06:27:29 -04:00
|
|
|
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(
|
2023-10-13 04:31:16 -04:00
|
|
|
new URL('pdfjs-dist213/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 importPDFJS() {
|
|
|
|
const variant = getMeta('ol-pdfjsVariant', 'default')
|
|
|
|
|
2023-05-17 08:57:36 -04:00
|
|
|
// NOTE: split test variants must have at least 3 characters
|
2022-03-18 06:27:29 -04:00
|
|
|
switch (variant) {
|
|
|
|
case '213':
|
2022-05-16 05:42:16 -04:00
|
|
|
case 'default':
|
2022-03-18 06:27:29 -04:00
|
|
|
return importPDFJS213()
|
|
|
|
|
2023-11-14 04:51:30 -05:00
|
|
|
case '401':
|
|
|
|
return importPDFJS401()
|
2022-03-18 06:27:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default importPDFJS()
|