Merge pull request #3963 from overleaf/revert-3819-msm-update-pdfjs-2-6

Revert "Update `pdf.js` to `2.6.347`"

GitOrigin-RevId: 62402d8e0b99b302206f0edc61411c9477d29249
This commit is contained in:
Miguel Serrano
2021-04-28 02:10:27 +00:00
committed by Copybot
parent bac110ee46
commit 8fbd4e3340
7 changed files with 70 additions and 75 deletions
@@ -1,5 +1,5 @@
import App from '../../../base' import App from '../../../base'
import { Util } from './pdfJsLoader' import PDFJS from './pdfJsLoader'
const EXTERNAL_LINK_TARGET = '_blank' const EXTERNAL_LINK_TARGET = '_blank'
const REL_NOOPENER = 'noreferrer noopener' const REL_NOOPENER = 'noreferrer noopener'
@@ -34,7 +34,7 @@ App.factory('pdfAnnotations', function () {
buildLinkElementFromRect(rect) { buildLinkElementFromRect(rect) {
rect = this.viewport.convertToViewportRectangle(rect) rect = this.viewport.convertToViewportRectangle(rect)
rect = Util.normalizeRect(rect) rect = PDFJS.Util.normalizeRect(rect)
const element = document.createElement('a') const element = document.createElement('a')
element.style.left = Math.floor(rect[0]) + 'px' element.style.left = Math.floor(rect[0]) + 'px'
element.style.top = Math.floor(rect[1]) + 'px' element.style.top = Math.floor(rect[1]) + 'px'
@@ -13,7 +13,7 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
import App from '../../../base' import App from '../../../base'
import { Util } from './pdfJsLoader' import PDFJS from './pdfJsLoader'
export default App.factory('pdfHighlights', function () { export default App.factory('pdfHighlights', function () {
let pdfHighlights let pdfHighlights
@@ -30,7 +30,7 @@ export default App.factory('pdfHighlights', function () {
left + width, left + width,
top + height, top + height,
]) ])
rect = Util.normalizeRect(rect) rect = PDFJS.Util.normalizeRect(rect)
const element = document.createElement('div') const element = document.createElement('div')
element.style.left = Math.floor(rect[0]) + 'px' element.style.left = Math.floor(rect[0]) + 'px'
element.style.top = Math.floor(rect[1]) + 'px' element.style.top = Math.floor(rect[1]) + 'px'
@@ -8,9 +8,18 @@
* to customise the loader's options. However the rest of the file is identical * to customise the loader's options. However the rest of the file is identical
* to the one provided by PDF.js. * to the one provided by PDF.js.
*/ */
/*
const pdfjs = require('pdfjs-dist/es5/build/pdf.js') * Adapted from https://github.com/mozilla/pdfjs-dist/blob/e9492b7a725ec4edd466880223474f4295a5fb45/webpack.js
const PdfjsWorker = require('pdfjs-dist/es5/build/pdf.worker.js') * The PDF.js worker needs to be loaded in a Web Worker. This can be done
* automatically with webpack via worker-loader.
* PDF.js has the above file to do this, however it uses the webpack loader
* module loading syntax, which prevents us from customising the loader.
* We need to output the worker file to the public/js directory, and so we need
* to customise the loader's options. However the rest of the file is identical
* to the one provided by PDF.js.
*/
var pdfjs = require('pdfjs-dist/build/pdf.js')
var PdfjsWorker = require('pdfjs-dist/build/pdf.worker.js')
if (typeof window !== 'undefined' && 'Worker' in window) { if (typeof window !== 'undefined' && 'Worker' in window) {
pdfjs.GlobalWorkerOptions.workerPort = new PdfjsWorker() pdfjs.GlobalWorkerOptions.workerPort = new PdfjsWorker()
@@ -18,9 +18,8 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/ */
import App from '../../../base' import App from '../../../base'
import { getDocument, renderTextLayer } from './pdfJsLoader' import PDFJS from './pdfJsLoader'
import { captureMessage } from '../../../infrastructure/error-reporter' import { captureMessage } from '../../../infrastructure/error-reporter'
import OError from '@overleaf/o-error'
export default App.factory( export default App.factory(
'PDFRenderer', 'PDFRenderer',
@@ -54,7 +53,7 @@ export default App.factory(
} else { } else {
disableFontFace = false disableFontFace = false
} }
this.pdfjs = getDocument({ this.pdfjs = PDFJS.getDocument({
url: this.url, url: this.url,
cMapUrl: window.pdfCMapsPath, cMapUrl: window.pdfCMapsPath,
cMapPacked: true, cMapPacked: true,
@@ -84,13 +83,9 @@ export default App.factory(
}) })
this.errorCallback = this.options.errorCallback this.errorCallback = this.options.errorCallback
this.pageSizeChangeCallback = this.options.pageSizeChangeCallback this.pageSizeChangeCallback = this.options.pageSizeChangeCallback
this.pdfjs.promise.catch(error => { this.pdfjs.promise.catch(exception => {
// error getting document // error getting document
this.errorCallback( return this.errorCallback(exception)
error
? OError.tag(error)
: new UnknownPDFError('pdfJsLoader.getDocument()')
)
}) })
} }
@@ -137,14 +132,9 @@ export default App.factory(
return (viewport = page.getViewport({ scale: scale })) return (viewport = page.getViewport({ scale: scale }))
}, },
error => { error => {
this.errorCallback( return typeof this.errorCallback === 'function'
error ? this.errorCallback(error)
? OError.tag(error) : undefined
: new UnknownPDFError('getPdfViewport', {
pageNum,
scale,
})
)
} }
) )
}) })
@@ -160,11 +150,9 @@ export default App.factory(
return this.document.promise.then( return this.document.promise.then(
pdfDocument => pdfDocument.getDestination(dest), pdfDocument => pdfDocument.getDestination(dest),
error => { error => {
this.errorCallback( return typeof this.errorCallback === 'function'
error ? this.errorCallback(error)
? OError.tag(error) : undefined
: new UnknownPDFError('getDestination', { dest })
)
} }
) )
} }
@@ -174,11 +162,9 @@ export default App.factory(
return pdfDocument.getPageIndex(ref).then( return pdfDocument.getPageIndex(ref).then(
idx => idx, idx => idx,
error => { error => {
this.errorCallback( return typeof this.errorCallback === 'function'
error ? this.errorCallback(error)
? OError.tag(error) : undefined
: new UnknownPDFError('getPageIndex', { ref })
)
} }
) )
}) })
@@ -356,7 +342,9 @@ export default App.factory(
this.clearIndicator(page) this.clearIndicator(page)
// @jobs = @jobs - 1 // @jobs = @jobs - 1
// @triggerRenderQueue(0) // @triggerRenderQueue(0)
this.errorCallback(new OError('timeout')) return typeof this.errorCallback === 'function'
? this.errorCallback('timeout')
: undefined
}, this.PAGE_LOAD_TIMEOUT) }, this.PAGE_LOAD_TIMEOUT)
var loadTask = this.getPage(pagenum) var loadTask = this.getPage(pagenum)
@@ -459,7 +447,7 @@ export default App.factory(
const textLayer = new pdfTextLayer({ const textLayer = new pdfTextLayer({
textLayerDiv: element.text[0], textLayerDiv: element.text[0],
viewport, viewport,
renderer: renderTextLayer, renderer: PDFJS.renderTextLayer,
}) })
const annotationsLayer = new pdfAnnotations({ const annotationsLayer = new pdfAnnotations({
@@ -486,20 +474,16 @@ export default App.factory(
return textLayer.render(textLayerTimeout) return textLayer.render(textLayerTimeout)
}, },
error => error =>
self.errorCallback( typeof self.errorCallback === 'function'
error ? self.errorCallback(error)
? OError.tag(error) : undefined
: new UnknownPDFError('page.getTextContent')
)
) )
return page.getAnnotations().then( return page.getAnnotations().then(
annotations => annotationsLayer.setAnnotations(annotations), annotations => annotationsLayer.setAnnotations(annotations),
error => error =>
self.errorCallback( typeof self.errorCallback === 'function'
error ? self.errorCallback(error)
? OError.tag(error) : undefined
: new UnknownPDFError('page.getAnnotations')
)
) )
}) })
.catch(function (error) { .catch(function (error) {
@@ -507,9 +491,9 @@ export default App.factory(
if (error.name === 'RenderingCancelledException') { if (error.name === 'RenderingCancelledException') {
// do nothing when cancelled // do nothing when cancelled
} else { } else {
self.errorCallback( return typeof self.errorCallback === 'function'
error ? OError.tag(error) : new UnknownPDFError('page.render') ? self.errorCallback(error)
) : undefined
} }
}) })
@@ -547,9 +531,3 @@ function __guardMethod__(obj, methodName, transform) {
return undefined return undefined
} }
} }
class UnknownPDFError extends OError {
constructor(location, info) {
super(`Unknown pdfRenderer error from ${location}`, info)
}
}
@@ -75,7 +75,7 @@ App.controller(
// but we plan to add this in the future // but we plan to add this in the future
// (https://github.com/overleaf/issues/issues/2985) and this error // (https://github.com/overleaf/issues/issues/2985) and this error
// is causing noise in Sentry so ignore it // is causing noise in Sentry so ignore it
if (error.name !== 'MissingPDFException') { if (!error || error.name !== 'MissingPDFException') {
captureMessage(`pdfng error ${error}`) captureMessage(`pdfng error ${error}`)
} }
return $scope.$emit('pdf:error', error) return $scope.$emit('pdf:error', error)
@@ -495,11 +495,11 @@ export default App.directive('pdfViewer', ($q, $timeout, pdfSpinner) => ({
) )
scope.$on('pdf:error', function (event, error) { scope.$on('pdf:error', function (event, error) {
if (error?.name === 'RenderingCancelledException') { if (error.name === 'RenderingCancelledException') {
return return
} }
// check if too many retries or file is missing // check if too many retries or file is missing
const message = error?.message const message = (error != null ? error.message : undefined) || error
if ( if (
scope.loadCount > 3 || scope.loadCount > 3 ||
/^Missing PDF/i.test(message) || /^Missing PDF/i.test(message) ||
@@ -516,7 +516,7 @@ export default App.directive('pdfViewer', ($q, $timeout, pdfSpinner) => ({
// trigger a redraw // trigger a redraw
(scope.scale = angular.copy(scope.scale)) (scope.scale = angular.copy(scope.scale))
) )
.catch(() => scope.$emit('pdf:error:display')) .catch(error => scope.$emit('pdf:error:display'))
} else { } else {
scope.$emit('pdf:error:display') scope.$emit('pdf:error:display')
} }
+23 -14
View File
@@ -8681,7 +8681,7 @@
"bintrees": { "bintrees": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/bintrees/-/bintrees-1.0.1.tgz", "resolved": "https://registry.npmjs.org/bintrees/-/bintrees-1.0.1.tgz",
"integrity": "sha512-tbaUB1QpTIj4cKY8c1rvNAvEQXA+ekzHmbe4jzNfW3QWsF9GnnP/BRWyl6/qqS53heoYJ93naaFcm/jooONH8g==" "integrity": "sha1-DmVcm5wkNeqraL9AJyJtK1WjRSQ="
}, },
"bl": { "bl": {
"version": "4.0.3", "version": "4.0.3",
@@ -9977,7 +9977,7 @@
"character-parser": { "character-parser": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/character-parser/-/character-parser-2.2.0.tgz", "resolved": "https://registry.npmjs.org/character-parser/-/character-parser-2.2.0.tgz",
"integrity": "sha512-+UqJQjFEFaTAs3bNsF2j2kEN1baG/zghZbdqoYEDxGZtJo9LBzl1A+m0D4n3qKx8N2FNv8/Xp6yV9mQmBuptaw==", "integrity": "sha1-x84o821LzZdE5f/CxfzeHHMmH8A=",
"requires": { "requires": {
"is-regex": "^1.0.3" "is-regex": "^1.0.3"
} }
@@ -12273,7 +12273,7 @@
"doctypes": { "doctypes": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/doctypes/-/doctypes-1.1.0.tgz", "resolved": "https://registry.npmjs.org/doctypes/-/doctypes-1.1.0.tgz",
"integrity": "sha512-LLBi6pEqS6Do3EKQ3J0NqHWV5hhb78Pi8vvESYwyOy2c31ZEZVdtitdzsQsKb7878PEERhzUk0ftqGhG6Mz+pQ==" "integrity": "sha1-6oCxBqh1OHdOijpKWv4pPeSJ4Kk="
}, },
"dom-accessibility-api": { "dom-accessibility-api": {
"version": "0.5.4", "version": "0.5.4",
@@ -14986,7 +14986,7 @@
"findit2": { "findit2": {
"version": "2.2.3", "version": "2.2.3",
"resolved": "https://registry.npmjs.org/findit2/-/findit2-2.2.3.tgz", "resolved": "https://registry.npmjs.org/findit2/-/findit2-2.2.3.tgz",
"integrity": "sha512-lg/Moejf4qXovVutL0Lz4IsaPoNYMuxt4PA0nGqFxnJ1CTTGGlEO2wKgoDpwknhvZ8k4Q2F+eesgkLbG2Mxfog==" "integrity": "sha1-WKRmaX34piBc39vzlVNri9d3pfY="
}, },
"findup-sync": { "findup-sync": {
"version": "3.0.0", "version": "3.0.0",
@@ -15502,7 +15502,7 @@
"functional-red-black-tree": { "functional-red-black-tree": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz",
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "integrity": "sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g==",
"dev": true "dev": true
}, },
"functions-have-names": { "functions-have-names": {
@@ -18667,7 +18667,7 @@
"js-stringify": { "js-stringify": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/js-stringify/-/js-stringify-1.0.2.tgz", "resolved": "https://registry.npmjs.org/js-stringify/-/js-stringify-1.0.2.tgz",
"integrity": "sha512-rtS5ATOo2Q5k1G+DADISilDA6lv79zIiwFd6CcjuIxGKLFm5C+RLImRscVap9k55i+MOZwgliw+NejvkLuGD5g==" "integrity": "sha1-Fzb939lyTyijaCrcYjCufk6Weds="
}, },
"js-tokens": { "js-tokens": {
"version": "3.0.2", "version": "3.0.2",
@@ -18910,7 +18910,7 @@
"jstransformer": { "jstransformer": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/jstransformer/-/jstransformer-1.0.0.tgz", "resolved": "https://registry.npmjs.org/jstransformer/-/jstransformer-1.0.0.tgz",
"integrity": "sha512-C9YK3Rf8q6VAPDCCU9fnqo3mAfOH6vUGnMcP4AQAYIEpWtfGLpwOTmZ+igtdK5y+VvI2n3CyYSzy4Qh34eq24A==", "integrity": "sha1-7Yvwkh4vPx7U1cGkT2hwntJHIsM=",
"requires": { "requires": {
"is-promise": "^2.0.0", "is-promise": "^2.0.0",
"promise": "^7.0.1" "promise": "^7.0.1"
@@ -21170,7 +21170,7 @@
"module-details-from-path": { "module-details-from-path": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/module-details-from-path/-/module-details-from-path-1.0.3.tgz", "resolved": "https://registry.npmjs.org/module-details-from-path/-/module-details-from-path-1.0.3.tgz",
"integrity": "sha512-ySViT69/76t8VhE1xXHK6Ch4NcDd26gx0MzKXLO+F7NOtnqH68d9zF94nT8ZWSxXh8ELOERsnJO/sWt1xZYw5A==" "integrity": "sha1-EUyUlnPiqKNenTV4hSeqN7Z52is="
}, },
"moment": { "moment": {
"version": "2.24.0", "version": "2.24.0",
@@ -21509,7 +21509,7 @@
"natural-compare": { "natural-compare": {
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
"integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==",
"dev": true "dev": true
}, },
"ncp": { "ncp": {
@@ -21653,6 +21653,11 @@
"minimatch": "^3.0.2" "minimatch": "^3.0.2"
} }
}, },
"node-ensure": {
"version": "0.0.0",
"resolved": "https://registry.npmjs.org/node-ensure/-/node-ensure-0.0.0.tgz",
"integrity": "sha512-DRI60hzo2oKN1ma0ckc6nQWlHU69RH6xN0sjQTjMpChPfTYvKZdcQFfdYK2RWbJcKyUizSIy/l8OTGxMAM1QDw=="
},
"node-fetch": { "node-fetch": {
"version": "2.6.1", "version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
@@ -23585,9 +23590,13 @@
} }
}, },
"pdfjs-dist": { "pdfjs-dist": {
"version": "2.7.570", "version": "2.2.228",
"resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-2.7.570.tgz", "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-2.2.228.tgz",
"integrity": "sha512-/ZkA1FwkEOyDaq11JhMLazdwQAA0F9uwrP7h/1L9Akt9KWh1G5/tkzS+bPuUELq2s2GDFnaT+kooN/aSjT7DXQ==" "integrity": "sha512-W5LhYPMS2UKX0ELIa4u+CFCMoox5qQNQElt0bAK2mwz1V8jZL0rvLao+0tBujce84PK6PvWG36Nwr7agCCWFGQ==",
"requires": {
"node-ensure": "^0.0.0",
"worker-loader": "^2.0.0"
}
}, },
"pend": { "pend": {
"version": "1.2.0", "version": "1.2.0",
@@ -27305,7 +27314,7 @@
"require-like": { "require-like": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/require-like/-/require-like-0.1.2.tgz", "resolved": "https://registry.npmjs.org/require-like/-/require-like-0.1.2.tgz",
"integrity": "sha512-oyrU88skkMtDdauHDuKVrgR+zuItqr6/c//FXzvmxRGMexSDc6hNvJInGW3LL46n+8b50RykrvwSUIIQH2LQ5A==", "integrity": "sha1-rW8wwTvs15cBDEaK+ndcDAprR/o=",
"dev": true "dev": true
}, },
"require-main-filename": { "require-main-filename": {
@@ -30361,7 +30370,7 @@
"tdigest": { "tdigest": {
"version": "0.1.1", "version": "0.1.1",
"resolved": "https://registry.npmjs.org/tdigest/-/tdigest-0.1.1.tgz", "resolved": "https://registry.npmjs.org/tdigest/-/tdigest-0.1.1.tgz",
"integrity": "sha512-CXcDY/NIgIbKZPx5H4JJNpq6JwJhU5Z4+yWj4ZghDc7/9nVajiRlPPyMXRePPPlBfcayUqtoCXjo7/Hm82ecUA==", "integrity": "sha1-Ljyyw56kSeVdHmzZEReszKRYgCE=",
"requires": { "requires": {
"bintrees": "1.0.1" "bintrees": "1.0.1"
} }
+1 -2
View File
@@ -132,7 +132,7 @@
"passport-orcid": "0.0.4", "passport-orcid": "0.0.4",
"passport-saml": "^1.3.3", "passport-saml": "^1.3.3",
"passport-twitter": "^1.0.4", "passport-twitter": "^1.0.4",
"pdfjs-dist": "^2.6.347", "pdfjs-dist": "^2.2.228",
"prop-types": "^15.7.2", "prop-types": "^15.7.2",
"pug": "^3.0.1", "pug": "^3.0.1",
"qrcode": "^1.4.4", "qrcode": "^1.4.4",
@@ -162,7 +162,6 @@
"uuid": "^3.0.1", "uuid": "^3.0.1",
"valid-data-url": "^2.0.0", "valid-data-url": "^2.0.0",
"valid-url": "^1.0.9", "valid-url": "^1.0.9",
"worker-loader": "^2.0.0",
"xml2js": "^0.4.22", "xml2js": "^0.4.22",
"xregexp": "^4.3.0", "xregexp": "^4.3.0",
"yauzl": "^2.10.0" "yauzl": "^2.10.0"