mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
Upgrade PDF.js to v5 (#24948)
* Reapply "Upgrade PDF.js to v5 (#24646)" (#24946) * Upgrade core-js, caniuse-lite and babel GitOrigin-RevId: 63398189301b5f5adc8a17b332d92dccfc26d612
This commit is contained in:
1551
package-lock.json
generated
1551
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
patches/pdfjs-dist+5.1.91.patch
Normal file
22
patches/pdfjs-dist+5.1.91.patch
Normal file
@@ -0,0 +1,22 @@
|
||||
diff --git a/node_modules/pdfjs-dist/build/pdf.worker.mjs b/node_modules/pdfjs-dist/build/pdf.worker.mjs
|
||||
index 6c5c6f1..bb6b7d1 100644
|
||||
--- a/node_modules/pdfjs-dist/build/pdf.worker.mjs
|
||||
+++ b/node_modules/pdfjs-dist/build/pdf.worker.mjs
|
||||
@@ -1830,7 +1830,7 @@ async function __wbg_init(module_or_path) {
|
||||
}
|
||||
}
|
||||
if (typeof module_or_path === 'undefined') {
|
||||
- module_or_path = new URL('qcms_bg.wasm', import.meta.url);
|
||||
+ module_or_path = new URL(/* webpackIgnore: true */ 'qcms_bg.wasm', import.meta.url);
|
||||
}
|
||||
const imports = __wbg_get_imports();
|
||||
if (typeof module_or_path === 'string' || typeof Request === 'function' && module_or_path instanceof Request || typeof URL === 'function' && module_or_path instanceof URL) {
|
||||
@@ -5358,7 +5358,7 @@ var OpenJPEG = (() => {
|
||||
if (Module["locateFile"]) {
|
||||
return locateFile("openjpeg.wasm");
|
||||
}
|
||||
- return new URL("openjpeg.wasm", import.meta.url).href;
|
||||
+ return new URL(/* webpackIgnore: true */ "openjpeg.wasm", import.meta.url).href;
|
||||
}
|
||||
function getBinarySync(file) {
|
||||
if (file == wasmBinaryFile && wasmBinary) {
|
||||
@@ -6,7 +6,7 @@
|
||||
{
|
||||
"useBuiltIns": "usage",
|
||||
// This version must be aligned with the `core-js` version in `package.json`
|
||||
"corejs": { "version": "3.38" },
|
||||
"corejs": { "version": "3.41" },
|
||||
"exclude": [
|
||||
// Exclude Array.prototype.push polyfill, as it's not needed and affects performance in Chrome
|
||||
"es.array.push",
|
||||
|
||||
@@ -168,10 +168,10 @@ function PdfJsViewer({ url, pdfFile }: PdfJsViewerProps) {
|
||||
setStartFetch(performance.now())
|
||||
|
||||
const abortController = new AbortController()
|
||||
const handleFetchError = (err: Error) => {
|
||||
const handleFetchError = (err: any) => {
|
||||
if (abortController.signal.aborted) return
|
||||
// The error is already logged at the call-site with additional context.
|
||||
if (err instanceof PDFJS.MissingPDFException) {
|
||||
if (err instanceof PDFJS.ResponseException && err.missing) {
|
||||
setError('rendering-error-expected')
|
||||
} else {
|
||||
setError('rendering-error')
|
||||
|
||||
@@ -155,14 +155,11 @@ export function generatePdfCachingTransportFactory() {
|
||||
return blob
|
||||
})
|
||||
.catch(err => {
|
||||
const { statusCode, url } = OError.getFullInfo(err)
|
||||
throw OError.tag(
|
||||
new PDFJS.MissingPDFException(),
|
||||
new PDFJS.ResponseException(undefined, statusCode, true),
|
||||
'cache-fallback',
|
||||
{
|
||||
statusCode: OError.getFullInfo(err).statusCode,
|
||||
url: OError.getFullInfo(err).url,
|
||||
err,
|
||||
}
|
||||
{ statusCode, url, err }
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -198,11 +195,12 @@ export function generatePdfCachingTransportFactory() {
|
||||
metrics.failedCount++
|
||||
metrics.failedOnce = true
|
||||
}
|
||||
throw OError.tag(new PDFJS.MissingPDFException(), 'caching', {
|
||||
statusCode: OError.getFullInfo(err).statusCode,
|
||||
url: OError.getFullInfo(err).url,
|
||||
err,
|
||||
})
|
||||
const { statusCode, url } = OError.getFullInfo(err)
|
||||
throw OError.tag(
|
||||
new PDFJS.ResponseException(undefined, statusCode, true),
|
||||
'caching',
|
||||
{ statusCode, url, err }
|
||||
)
|
||||
}
|
||||
metrics.failedCount++
|
||||
metrics.failedOnce = true
|
||||
@@ -226,11 +224,12 @@ export function generatePdfCachingTransportFactory() {
|
||||
}).catch(err => {
|
||||
if (canTryFromCache(err)) return fetchFromCache()
|
||||
if (isExpectedError(err)) {
|
||||
throw OError.tag(new PDFJS.MissingPDFException(), 'fallback', {
|
||||
statusCode: OError.getFullInfo(err).statusCode,
|
||||
url: OError.getFullInfo(err).url,
|
||||
err,
|
||||
})
|
||||
const { statusCode, url } = OError.getFullInfo(err)
|
||||
throw OError.tag(
|
||||
new PDFJS.ResponseException(undefined, statusCode, true),
|
||||
'fallback',
|
||||
{ statusCode, url, err }
|
||||
)
|
||||
}
|
||||
throw err
|
||||
})
|
||||
@@ -251,7 +250,7 @@ export function generatePdfCachingTransportFactory() {
|
||||
if (abortSignal.aborted) return
|
||||
err = OError.tag(err, 'fatal pdf download error', getDebugInfo())
|
||||
debugConsole.error(err)
|
||||
if (!(err instanceof PDFJS.MissingPDFException)) {
|
||||
if (!(err instanceof PDFJS.ResponseException && err.missing)) {
|
||||
captureException(err, {
|
||||
tags: {
|
||||
fromPdfCaching: true,
|
||||
|
||||
@@ -57,7 +57,7 @@ export default class PDFJSWrapper {
|
||||
url: string
|
||||
pdfFile: Record<string, any>
|
||||
abortController: AbortController
|
||||
handleFetchError: (error: Error) => void
|
||||
handleFetchError: (error: any) => void
|
||||
}) {
|
||||
this.url = url
|
||||
|
||||
@@ -90,7 +90,10 @@ export default class PDFJSWrapper {
|
||||
|
||||
return doc
|
||||
} catch (error: any) {
|
||||
if (!error || error.name !== 'MissingPDFException') {
|
||||
if (
|
||||
!error ||
|
||||
!(error instanceof PDFJS.ResponseException && error.missing === true)
|
||||
) {
|
||||
captureException(error, {
|
||||
tags: { handler: 'pdf-preview' },
|
||||
})
|
||||
|
||||
@@ -11,6 +11,8 @@ PDFJS.GlobalWorkerOptions.workerPort = new Worker(
|
||||
|
||||
export const imageResourcesPath = '/images/pdfjs-dist/'
|
||||
const cMapUrl = '/js/pdfjs-dist/cmaps/'
|
||||
const wasmUrl = '/js/pdfjs-dist/wasm/'
|
||||
const iccUrl = '/js/pdfjs-dist/iccs/'
|
||||
const standardFontDataUrl = '/fonts/pdfjs-dist/'
|
||||
|
||||
const params = new URLSearchParams(window.location.search)
|
||||
@@ -24,6 +26,8 @@ export const loadPdfDocumentFromUrl = (
|
||||
PDFJS.getDocument({
|
||||
url,
|
||||
cMapUrl,
|
||||
wasmUrl,
|
||||
iccUrl,
|
||||
standardFontDataUrl,
|
||||
disableFontFace,
|
||||
disableAutoFetch: true, // only fetch the data needed for the displayed pages
|
||||
|
||||
@@ -178,12 +178,12 @@
|
||||
"yauzl": "^2.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.24.8",
|
||||
"@babel/core": "^7.25.2",
|
||||
"@babel/preset-env": "^7.25.3",
|
||||
"@babel/preset-react": "^7.24.7",
|
||||
"@babel/preset-typescript": "^7.24.7",
|
||||
"@babel/register": "^7.24.6",
|
||||
"@babel/cli": "^7.27.0",
|
||||
"@babel/core": "^7.26.10",
|
||||
"@babel/preset-env": "^7.26.9",
|
||||
"@babel/preset-react": "^7.26.3",
|
||||
"@babel/preset-typescript": "^7.27.0",
|
||||
"@babel/register": "^7.25.9",
|
||||
"@codemirror/autocomplete": "github:overleaf/codemirror-autocomplete#6445cd056671c98d12d1c597ba705e11327ec4c5",
|
||||
"@codemirror/commands": "^6.8.0",
|
||||
"@codemirror/lang-markdown": "^6.3.2",
|
||||
@@ -274,7 +274,7 @@
|
||||
"classnames": "^2.2.6",
|
||||
"cookie-signature": "^1.2.1",
|
||||
"copy-webpack-plugin": "^11.0.0",
|
||||
"core-js": "^3.38.1",
|
||||
"core-js": "^3.41.0",
|
||||
"css-loader": "^6.8.1",
|
||||
"css-minimizer-webpack-plugin": "^5.0.1",
|
||||
"cypress": "13.13.2",
|
||||
@@ -320,7 +320,7 @@
|
||||
"nock": "^13.5.6",
|
||||
"nvd3": "^1.8.6",
|
||||
"overleaf-editor-core": "*",
|
||||
"pdfjs-dist": "4.10.38",
|
||||
"pdfjs-dist": "5.1.91",
|
||||
"pirates": "^4.0.1",
|
||||
"postcss": "^8.4.31",
|
||||
"postcss-loader": "^7.3.3",
|
||||
|
||||
@@ -380,12 +380,22 @@ module.exports = {
|
||||
context: `${dictionariesDir}/dictionaries`,
|
||||
},
|
||||
// Copy CMap files (used to provide support for non-Latin characters),
|
||||
// fonts and images from pdfjs-dist package to build output.
|
||||
// wasm, ICC profiles, fonts and images from pdfjs-dist package to build output.
|
||||
{
|
||||
from: 'cmaps',
|
||||
to: 'js/pdfjs-dist/cmaps',
|
||||
context: pdfjsDir,
|
||||
},
|
||||
{
|
||||
from: 'iccs',
|
||||
to: 'js/pdfjs-dist/iccs',
|
||||
context: pdfjsDir,
|
||||
},
|
||||
{
|
||||
from: 'wasm',
|
||||
to: 'js/pdfjs-dist/wasm',
|
||||
context: pdfjsDir,
|
||||
},
|
||||
{
|
||||
from: 'standard_fonts',
|
||||
to: 'fonts/pdfjs-dist',
|
||||
|
||||
Reference in New Issue
Block a user