mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Upgrade PDF.js (#15157)
GitOrigin-RevId: a0a241da08c06a7e345a710559cb47fb59685e5a
This commit is contained in:
parent
9b4bda32a7
commit
d2d2a0ff65
8 changed files with 50 additions and 61 deletions
53
package-lock.json
generated
53
package-lock.json
generated
|
@ -29813,6 +29813,7 @@
|
||||||
"resolved": "https://registry.npmjs.org/path2d-polyfill/-/path2d-polyfill-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/path2d-polyfill/-/path2d-polyfill-2.0.1.tgz",
|
||||||
"integrity": "sha512-ad/3bsalbbWhmBo0D6FZ4RNMwsLsPpL6gnvhuSaU5Vm7b06Kr5ubSltQQ0T7YKsiJQO+g22zJ4dJKNTXIyOXtA==",
|
"integrity": "sha512-ad/3bsalbbWhmBo0D6FZ4RNMwsLsPpL6gnvhuSaU5Vm7b06Kr5ubSltQQ0T7YKsiJQO+g22zJ4dJKNTXIyOXtA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"optional": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
|
@ -29854,30 +29855,18 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/pdfjs-dist36": {
|
"node_modules/pdfjs-dist401": {
|
||||||
"name": "pdfjs-dist",
|
"name": "pdfjs-dist",
|
||||||
"version": "3.6.172",
|
"version": "4.0.189",
|
||||||
"resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-3.6.172.tgz",
|
"resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-4.0.189.tgz",
|
||||||
"integrity": "sha512-bfOhCg+S9DXh/ImWhWYTOiq3aVMFSCvzGiBzsIJtdMC71kVWDBw7UXr32xh0y56qc5wMVylIeqV3hBaRsu+e+w==",
|
"integrity": "sha512-5IWbLRJjQJhk3cu3nNFAvIYoSzT8xRYlRkFCIV1tn7hK1eq9H+6vOP0ytJhZz9YI35IXlu33uQspvmYO6Oir4g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
|
||||||
"path2d-polyfill": "^2.0.1",
|
|
||||||
"web-streams-polyfill": "^3.2.1"
|
|
||||||
},
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16"
|
"node": ">=18"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"canvas": "^2.11.2"
|
"canvas": "^2.11.2",
|
||||||
}
|
"path2d-polyfill": "^2.0.1"
|
||||||
},
|
|
||||||
"node_modules/pdfjs-dist36/node_modules/web-streams-polyfill": {
|
|
||||||
"version": "3.2.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz",
|
|
||||||
"integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==",
|
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 8"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/peek-stream": {
|
"node_modules/peek-stream": {
|
||||||
|
@ -39750,7 +39739,7 @@
|
||||||
"node-fetch": "^2.6.7",
|
"node-fetch": "^2.6.7",
|
||||||
"nvd3": "^1.8.6",
|
"nvd3": "^1.8.6",
|
||||||
"pdfjs-dist213": "npm:pdfjs-dist@2.13.216",
|
"pdfjs-dist213": "npm:pdfjs-dist@2.13.216",
|
||||||
"pdfjs-dist36": "npm:pdfjs-dist@3.6.172",
|
"pdfjs-dist401": "npm:pdfjs-dist@4.0.189",
|
||||||
"pirates": "^4.0.1",
|
"pirates": "^4.0.1",
|
||||||
"postcss": "^8.4.31",
|
"postcss": "^8.4.31",
|
||||||
"postcss-loader": "^7.3.3",
|
"postcss-loader": "^7.3.3",
|
||||||
|
@ -47966,7 +47955,7 @@
|
||||||
"passport-saml": "^3.2.4",
|
"passport-saml": "^3.2.4",
|
||||||
"passport-twitter": "^1.0.4",
|
"passport-twitter": "^1.0.4",
|
||||||
"pdfjs-dist213": "npm:pdfjs-dist@2.13.216",
|
"pdfjs-dist213": "npm:pdfjs-dist@2.13.216",
|
||||||
"pdfjs-dist36": "npm:pdfjs-dist@3.6.172",
|
"pdfjs-dist401": "npm:pdfjs-dist@4.0.189",
|
||||||
"pirates": "^4.0.1",
|
"pirates": "^4.0.1",
|
||||||
"postcss": "^8.4.31",
|
"postcss": "^8.4.31",
|
||||||
"postcss-loader": "^7.3.3",
|
"postcss-loader": "^7.3.3",
|
||||||
|
@ -65721,7 +65710,8 @@
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/path2d-polyfill/-/path2d-polyfill-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/path2d-polyfill/-/path2d-polyfill-2.0.1.tgz",
|
||||||
"integrity": "sha512-ad/3bsalbbWhmBo0D6FZ4RNMwsLsPpL6gnvhuSaU5Vm7b06Kr5ubSltQQ0T7YKsiJQO+g22zJ4dJKNTXIyOXtA==",
|
"integrity": "sha512-ad/3bsalbbWhmBo0D6FZ4RNMwsLsPpL6gnvhuSaU5Vm7b06Kr5ubSltQQ0T7YKsiJQO+g22zJ4dJKNTXIyOXtA==",
|
||||||
"dev": true
|
"dev": true,
|
||||||
|
"optional": true
|
||||||
},
|
},
|
||||||
"pathe": {
|
"pathe": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
|
@ -65748,23 +65738,14 @@
|
||||||
"web-streams-polyfill": "^3.2.0"
|
"web-streams-polyfill": "^3.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"pdfjs-dist36": {
|
"pdfjs-dist401": {
|
||||||
"version": "npm:pdfjs-dist@3.6.172",
|
"version": "npm:pdfjs-dist@4.0.189",
|
||||||
"resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-3.6.172.tgz",
|
"resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-4.0.189.tgz",
|
||||||
"integrity": "sha512-bfOhCg+S9DXh/ImWhWYTOiq3aVMFSCvzGiBzsIJtdMC71kVWDBw7UXr32xh0y56qc5wMVylIeqV3hBaRsu+e+w==",
|
"integrity": "sha512-5IWbLRJjQJhk3cu3nNFAvIYoSzT8xRYlRkFCIV1tn7hK1eq9H+6vOP0ytJhZz9YI35IXlu33uQspvmYO6Oir4g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"canvas": "^2.11.2",
|
"canvas": "^2.11.2",
|
||||||
"path2d-polyfill": "^2.0.1",
|
"path2d-polyfill": "^2.0.1"
|
||||||
"web-streams-polyfill": "^3.2.1"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"web-streams-polyfill": {
|
|
||||||
"version": "3.2.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz",
|
|
||||||
"integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==",
|
|
||||||
"dev": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"peek-stream": {
|
"peek-stream": {
|
||||||
|
|
|
@ -565,7 +565,7 @@ const ProjectController = {
|
||||||
SplitTestHandler.getAssignment(
|
SplitTestHandler.getAssignment(
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
'pdfjs-36',
|
'pdfjs-40',
|
||||||
{},
|
{},
|
||||||
(error, assignment) => {
|
(error, assignment) => {
|
||||||
// do not fail editor load if assignment fails
|
// do not fail editor load if assignment fails
|
||||||
|
|
|
@ -35,10 +35,8 @@ const buildConfig = () => {
|
||||||
)
|
)
|
||||||
|
|
||||||
// add entrypoints under '/' for pdfjs workers
|
// add entrypoints under '/' for pdfjs workers
|
||||||
const pdfjsVersions = ['pdfjs-dist213', 'pdfjs-dist36']
|
addWorker('pdfjs-dist213', 'pdfjs-dist213/legacy/build/pdf.worker.js')
|
||||||
for (const name of pdfjsVersions) {
|
addWorker('pdfjs-dist401', 'pdfjs-dist401/legacy/build/pdf.worker.mjs')
|
||||||
addWorker(name, `${name}/legacy/build/pdf.worker`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return webpackConfig
|
return webpackConfig
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,23 +3,25 @@
|
||||||
|
|
||||||
import 'core-js/stable/global-this' // polyfill for globalThis (used by pdf.js)
|
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)
|
import 'core-js/stable/promise/all-settled' // polyfill for Promise.allSettled (used by pdf.js)
|
||||||
import getMeta from '../../../utils/meta'
|
import getMeta from '@/utils/meta'
|
||||||
import { createWorker } from '../../../utils/worker'
|
import { createWorker } from '@/utils/worker'
|
||||||
|
|
||||||
async function importPDFJS36() {
|
async function importPDFJS401() {
|
||||||
const cMapUrl = '/js/pdfjs-dist36/cmaps/'
|
const cMapUrl = '/js/pdfjs-dist401/cmaps/'
|
||||||
const standardFontDataUrl = '/fonts/pdfjs-dist36/'
|
const standardFontDataUrl = '/fonts/pdfjs-dist401/'
|
||||||
const imageResourcesPath = '/images/pdfjs-dist36/'
|
const imageResourcesPath = '/images/pdfjs-dist401/'
|
||||||
|
|
||||||
const [PDFJS, PDFJSViewer] = await Promise.all([
|
// ensure that PDF.js is loaded before importing the viewer
|
||||||
import('pdfjs-dist36/legacy/build/pdf'),
|
const PDFJS = await import('pdfjs-dist401/legacy/build/pdf')
|
||||||
import('pdfjs-dist36/legacy/web/pdf_viewer'),
|
|
||||||
import('pdfjs-dist36/legacy/web/pdf_viewer.css'),
|
const [PDFJSViewer] = await Promise.all([
|
||||||
|
import('pdfjs-dist401/legacy/web/pdf_viewer'),
|
||||||
|
import('pdfjs-dist401/legacy/web/pdf_viewer.css'),
|
||||||
])
|
])
|
||||||
|
|
||||||
createWorker(() => {
|
createWorker(() => {
|
||||||
PDFJS.GlobalWorkerOptions.workerPort = new Worker(
|
PDFJS.GlobalWorkerOptions.workerPort = new Worker(
|
||||||
new URL('pdfjs-dist36/legacy/build/pdf.worker.js', import.meta.url)
|
new URL('pdfjs-dist401/legacy/build/pdf.worker.mjs', import.meta.url) // NOTE: .mjs extension
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -37,8 +39,10 @@ async function importPDFJS213() {
|
||||||
const standardFontDataUrl = '/fonts/pdfjs-dist213/'
|
const standardFontDataUrl = '/fonts/pdfjs-dist213/'
|
||||||
const imageResourcesPath = '/images/pdfjs-dist213/'
|
const imageResourcesPath = '/images/pdfjs-dist213/'
|
||||||
|
|
||||||
const [PDFJS, PDFJSViewer] = await Promise.all([
|
// ensure that PDF.js is loaded before importing the viewer
|
||||||
import('pdfjs-dist213/legacy/build/pdf'),
|
const PDFJS = await import('pdfjs-dist213/legacy/build/pdf')
|
||||||
|
|
||||||
|
const [PDFJSViewer] = await Promise.all([
|
||||||
import('pdfjs-dist213/legacy/web/pdf_viewer'),
|
import('pdfjs-dist213/legacy/web/pdf_viewer'),
|
||||||
import('pdfjs-dist213/legacy/web/pdf_viewer.css'),
|
import('pdfjs-dist213/legacy/web/pdf_viewer.css'),
|
||||||
])
|
])
|
||||||
|
@ -67,8 +71,8 @@ async function importPDFJS() {
|
||||||
case 'default':
|
case 'default':
|
||||||
return importPDFJS213()
|
return importPDFJS213()
|
||||||
|
|
||||||
case '36172':
|
case '401':
|
||||||
return importPDFJS36()
|
return importPDFJS401()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import {
|
||||||
} from './fixtures/compile'
|
} from './fixtures/compile'
|
||||||
import { cloneDeep } from 'lodash'
|
import { cloneDeep } from 'lodash'
|
||||||
import { ScopeDecorator } from './decorators/scope'
|
import { ScopeDecorator } from './decorators/scope'
|
||||||
|
import { PdfPreviewProvider } from '@/features/pdf-preview/components/pdf-preview-provider'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
title: 'Editor / PDF Preview',
|
title: 'Editor / PDF Preview',
|
||||||
|
@ -332,7 +333,9 @@ export const Logs = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="pdf">
|
<div className="pdf">
|
||||||
|
<PdfPreviewProvider>
|
||||||
<PdfLogsViewer />
|
<PdfLogsViewer />
|
||||||
|
</PdfPreviewProvider>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
} from './fixtures/compile'
|
} from './fixtures/compile'
|
||||||
import { useEffect, Suspense } from 'react'
|
import { useEffect, Suspense } from 'react'
|
||||||
import { ScopeDecorator } from './decorators/scope'
|
import { ScopeDecorator } from './decorators/scope'
|
||||||
|
import { PdfPreviewProvider } from '@/features/pdf-preview/components/pdf-preview-provider'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
title: 'Editor / PDF Viewer',
|
title: 'Editor / PDF Viewer',
|
||||||
|
@ -36,7 +37,9 @@ export const Interactive = () => {
|
||||||
<div>
|
<div>
|
||||||
<div className="pdf-viewer">
|
<div className="pdf-viewer">
|
||||||
<Suspense fallback={null}>
|
<Suspense fallback={null}>
|
||||||
|
<PdfPreviewProvider>
|
||||||
<PdfViewer />
|
<PdfViewer />
|
||||||
|
</PdfPreviewProvider>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ position: 'absolute', top: 150, left: 50 }}>
|
<div style={{ position: 'absolute', top: 150, left: 50 }}>
|
||||||
|
|
|
@ -302,7 +302,7 @@
|
||||||
"node-fetch": "^2.6.7",
|
"node-fetch": "^2.6.7",
|
||||||
"nvd3": "^1.8.6",
|
"nvd3": "^1.8.6",
|
||||||
"pdfjs-dist213": "npm:pdfjs-dist@2.13.216",
|
"pdfjs-dist213": "npm:pdfjs-dist@2.13.216",
|
||||||
"pdfjs-dist36": "npm:pdfjs-dist@3.6.172",
|
"pdfjs-dist401": "npm:pdfjs-dist@4.0.189",
|
||||||
"pirates": "^4.0.1",
|
"pirates": "^4.0.1",
|
||||||
"postcss": "^8.4.31",
|
"postcss": "^8.4.31",
|
||||||
"postcss-loader": "^7.3.3",
|
"postcss-loader": "^7.3.3",
|
||||||
|
|
|
@ -65,7 +65,7 @@ const mathjaxDir = getModuleDirectory('mathjax')
|
||||||
const mathjax3Dir = getModuleDirectory('mathjax-3')
|
const mathjax3Dir = getModuleDirectory('mathjax-3')
|
||||||
const aceDir = getModuleDirectory('ace-builds')
|
const aceDir = getModuleDirectory('ace-builds')
|
||||||
|
|
||||||
const pdfjsVersions = ['pdfjs-dist213', 'pdfjs-dist36']
|
const pdfjsVersions = ['pdfjs-dist213', 'pdfjs-dist401']
|
||||||
|
|
||||||
const vendorDir = path.join(__dirname, 'frontend/js/vendor')
|
const vendorDir = path.join(__dirname, 'frontend/js/vendor')
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ module.exports = {
|
||||||
'@': path.resolve(__dirname, './frontend/js/'),
|
'@': path.resolve(__dirname, './frontend/js/'),
|
||||||
},
|
},
|
||||||
// symlinks: false, // enable this while using `npm link`
|
// symlinks: false, // enable this while using `npm link`
|
||||||
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
|
extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs', '.json'],
|
||||||
fallback: {
|
fallback: {
|
||||||
events: require.resolve('events'),
|
events: require.resolve('events'),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue