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

Update `pdf.js` to `2.6.347`

GitOrigin-RevId: fd2a6708077e574a909ff05105ab70ea7c99daf5
This commit is contained in:
Miguel Serrano 2021-04-27 12:12:56 +02:00 committed by Copybot
parent 855f815277
commit bac110ee46
7 changed files with 75 additions and 70 deletions

View file

@ -1,5 +1,5 @@
import App from '../../../base'
import PDFJS from './pdfJsLoader'
import { Util } from './pdfJsLoader'
const EXTERNAL_LINK_TARGET = '_blank'
const REL_NOOPENER = 'noreferrer noopener'
@ -34,7 +34,7 @@ App.factory('pdfAnnotations', function () {
buildLinkElementFromRect(rect) {
rect = this.viewport.convertToViewportRectangle(rect)
rect = PDFJS.Util.normalizeRect(rect)
rect = Util.normalizeRect(rect)
const element = document.createElement('a')
element.style.left = Math.floor(rect[0]) + 'px'
element.style.top = Math.floor(rect[1]) + 'px'

View file

@ -13,7 +13,7 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import App from '../../../base'
import PDFJS from './pdfJsLoader'
import { Util } from './pdfJsLoader'
export default App.factory('pdfHighlights', function () {
let pdfHighlights
@ -30,7 +30,7 @@ export default App.factory('pdfHighlights', function () {
left + width,
top + height,
])
rect = PDFJS.Util.normalizeRect(rect)
rect = Util.normalizeRect(rect)
const element = document.createElement('div')
element.style.left = Math.floor(rect[0]) + 'px'
element.style.top = Math.floor(rect[1]) + 'px'

View file

@ -8,18 +8,9 @@
* to customise the loader's options. However the rest of the file is identical
* to the one provided by PDF.js.
*/
/*
* Adapted from https://github.com/mozilla/pdfjs-dist/blob/e9492b7a725ec4edd466880223474f4295a5fb45/webpack.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')
const pdfjs = require('pdfjs-dist/es5/build/pdf.js')
const PdfjsWorker = require('pdfjs-dist/es5/build/pdf.worker.js')
if (typeof window !== 'undefined' && 'Worker' in window) {
pdfjs.GlobalWorkerOptions.workerPort = new PdfjsWorker()

View file

@ -18,8 +18,9 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import App from '../../../base'
import PDFJS from './pdfJsLoader'
import { getDocument, renderTextLayer } from './pdfJsLoader'
import { captureMessage } from '../../../infrastructure/error-reporter'
import OError from '@overleaf/o-error'
export default App.factory(
'PDFRenderer',
@ -53,7 +54,7 @@ export default App.factory(
} else {
disableFontFace = false
}
this.pdfjs = PDFJS.getDocument({
this.pdfjs = getDocument({
url: this.url,
cMapUrl: window.pdfCMapsPath,
cMapPacked: true,
@ -83,9 +84,13 @@ export default App.factory(
})
this.errorCallback = this.options.errorCallback
this.pageSizeChangeCallback = this.options.pageSizeChangeCallback
this.pdfjs.promise.catch(exception => {
this.pdfjs.promise.catch(error => {
// error getting document
return this.errorCallback(exception)
this.errorCallback(
error
? OError.tag(error)
: new UnknownPDFError('pdfJsLoader.getDocument()')
)
})
}
@ -132,9 +137,14 @@ export default App.factory(
return (viewport = page.getViewport({ scale: scale }))
},
error => {
return typeof this.errorCallback === 'function'
? this.errorCallback(error)
: undefined
this.errorCallback(
error
? OError.tag(error)
: new UnknownPDFError('getPdfViewport', {
pageNum,
scale,
})
)
}
)
})
@ -150,9 +160,11 @@ export default App.factory(
return this.document.promise.then(
pdfDocument => pdfDocument.getDestination(dest),
error => {
return typeof this.errorCallback === 'function'
? this.errorCallback(error)
: undefined
this.errorCallback(
error
? OError.tag(error)
: new UnknownPDFError('getDestination', { dest })
)
}
)
}
@ -162,9 +174,11 @@ export default App.factory(
return pdfDocument.getPageIndex(ref).then(
idx => idx,
error => {
return typeof this.errorCallback === 'function'
? this.errorCallback(error)
: undefined
this.errorCallback(
error
? OError.tag(error)
: new UnknownPDFError('getPageIndex', { ref })
)
}
)
})
@ -342,9 +356,7 @@ export default App.factory(
this.clearIndicator(page)
// @jobs = @jobs - 1
// @triggerRenderQueue(0)
return typeof this.errorCallback === 'function'
? this.errorCallback('timeout')
: undefined
this.errorCallback(new OError('timeout'))
}, this.PAGE_LOAD_TIMEOUT)
var loadTask = this.getPage(pagenum)
@ -447,7 +459,7 @@ export default App.factory(
const textLayer = new pdfTextLayer({
textLayerDiv: element.text[0],
viewport,
renderer: PDFJS.renderTextLayer,
renderer: renderTextLayer,
})
const annotationsLayer = new pdfAnnotations({
@ -474,16 +486,20 @@ export default App.factory(
return textLayer.render(textLayerTimeout)
},
error =>
typeof self.errorCallback === 'function'
? self.errorCallback(error)
: undefined
self.errorCallback(
error
? OError.tag(error)
: new UnknownPDFError('page.getTextContent')
)
)
return page.getAnnotations().then(
annotations => annotationsLayer.setAnnotations(annotations),
error =>
typeof self.errorCallback === 'function'
? self.errorCallback(error)
: undefined
self.errorCallback(
error
? OError.tag(error)
: new UnknownPDFError('page.getAnnotations')
)
)
})
.catch(function (error) {
@ -491,9 +507,9 @@ export default App.factory(
if (error.name === 'RenderingCancelledException') {
// do nothing when cancelled
} else {
return typeof self.errorCallback === 'function'
? self.errorCallback(error)
: undefined
self.errorCallback(
error ? OError.tag(error) : new UnknownPDFError('page.render')
)
}
})
@ -531,3 +547,9 @@ function __guardMethod__(obj, methodName, transform) {
return undefined
}
}
class UnknownPDFError extends OError {
constructor(location, info) {
super(`Unknown pdfRenderer error from ${location}`, info)
}
}

View file

@ -75,7 +75,7 @@ App.controller(
// but we plan to add this in the future
// (https://github.com/overleaf/issues/issues/2985) and this error
// is causing noise in Sentry so ignore it
if (!error || error.name !== 'MissingPDFException') {
if (error.name !== 'MissingPDFException') {
captureMessage(`pdfng 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) {
if (error.name === 'RenderingCancelledException') {
if (error?.name === 'RenderingCancelledException') {
return
}
// check if too many retries or file is missing
const message = (error != null ? error.message : undefined) || error
const message = error?.message
if (
scope.loadCount > 3 ||
/^Missing PDF/i.test(message) ||
@ -516,7 +516,7 @@ export default App.directive('pdfViewer', ($q, $timeout, pdfSpinner) => ({
// trigger a redraw
(scope.scale = angular.copy(scope.scale))
)
.catch(error => scope.$emit('pdf:error:display'))
.catch(() => scope.$emit('pdf:error:display'))
} else {
scope.$emit('pdf:error:display')
}

View file

@ -8681,7 +8681,7 @@
"bintrees": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/bintrees/-/bintrees-1.0.1.tgz",
"integrity": "sha1-DmVcm5wkNeqraL9AJyJtK1WjRSQ="
"integrity": "sha512-tbaUB1QpTIj4cKY8c1rvNAvEQXA+ekzHmbe4jzNfW3QWsF9GnnP/BRWyl6/qqS53heoYJ93naaFcm/jooONH8g=="
},
"bl": {
"version": "4.0.3",
@ -9977,7 +9977,7 @@
"character-parser": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/character-parser/-/character-parser-2.2.0.tgz",
"integrity": "sha1-x84o821LzZdE5f/CxfzeHHMmH8A=",
"integrity": "sha512-+UqJQjFEFaTAs3bNsF2j2kEN1baG/zghZbdqoYEDxGZtJo9LBzl1A+m0D4n3qKx8N2FNv8/Xp6yV9mQmBuptaw==",
"requires": {
"is-regex": "^1.0.3"
}
@ -12273,7 +12273,7 @@
"doctypes": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/doctypes/-/doctypes-1.1.0.tgz",
"integrity": "sha1-6oCxBqh1OHdOijpKWv4pPeSJ4Kk="
"integrity": "sha512-LLBi6pEqS6Do3EKQ3J0NqHWV5hhb78Pi8vvESYwyOy2c31ZEZVdtitdzsQsKb7878PEERhzUk0ftqGhG6Mz+pQ=="
},
"dom-accessibility-api": {
"version": "0.5.4",
@ -14986,7 +14986,7 @@
"findit2": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/findit2/-/findit2-2.2.3.tgz",
"integrity": "sha1-WKRmaX34piBc39vzlVNri9d3pfY="
"integrity": "sha512-lg/Moejf4qXovVutL0Lz4IsaPoNYMuxt4PA0nGqFxnJ1CTTGGlEO2wKgoDpwknhvZ8k4Q2F+eesgkLbG2Mxfog=="
},
"findup-sync": {
"version": "3.0.0",
@ -15502,7 +15502,7 @@
"functional-red-black-tree": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz",
"integrity": "sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g==",
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
"dev": true
},
"functions-have-names": {
@ -18667,7 +18667,7 @@
"js-stringify": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/js-stringify/-/js-stringify-1.0.2.tgz",
"integrity": "sha1-Fzb939lyTyijaCrcYjCufk6Weds="
"integrity": "sha512-rtS5ATOo2Q5k1G+DADISilDA6lv79zIiwFd6CcjuIxGKLFm5C+RLImRscVap9k55i+MOZwgliw+NejvkLuGD5g=="
},
"js-tokens": {
"version": "3.0.2",
@ -18910,7 +18910,7 @@
"jstransformer": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/jstransformer/-/jstransformer-1.0.0.tgz",
"integrity": "sha1-7Yvwkh4vPx7U1cGkT2hwntJHIsM=",
"integrity": "sha512-C9YK3Rf8q6VAPDCCU9fnqo3mAfOH6vUGnMcP4AQAYIEpWtfGLpwOTmZ+igtdK5y+VvI2n3CyYSzy4Qh34eq24A==",
"requires": {
"is-promise": "^2.0.0",
"promise": "^7.0.1"
@ -21170,7 +21170,7 @@
"module-details-from-path": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/module-details-from-path/-/module-details-from-path-1.0.3.tgz",
"integrity": "sha1-EUyUlnPiqKNenTV4hSeqN7Z52is="
"integrity": "sha512-ySViT69/76t8VhE1xXHK6Ch4NcDd26gx0MzKXLO+F7NOtnqH68d9zF94nT8ZWSxXh8ELOERsnJO/sWt1xZYw5A=="
},
"moment": {
"version": "2.24.0",
@ -21509,7 +21509,7 @@
"natural-compare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
"integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==",
"integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=",
"dev": true
},
"ncp": {
@ -21653,11 +21653,6 @@
"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": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
@ -23590,13 +23585,9 @@
}
},
"pdfjs-dist": {
"version": "2.2.228",
"resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-2.2.228.tgz",
"integrity": "sha512-W5LhYPMS2UKX0ELIa4u+CFCMoox5qQNQElt0bAK2mwz1V8jZL0rvLao+0tBujce84PK6PvWG36Nwr7agCCWFGQ==",
"requires": {
"node-ensure": "^0.0.0",
"worker-loader": "^2.0.0"
}
"version": "2.7.570",
"resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-2.7.570.tgz",
"integrity": "sha512-/ZkA1FwkEOyDaq11JhMLazdwQAA0F9uwrP7h/1L9Akt9KWh1G5/tkzS+bPuUELq2s2GDFnaT+kooN/aSjT7DXQ=="
},
"pend": {
"version": "1.2.0",
@ -27314,7 +27305,7 @@
"require-like": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/require-like/-/require-like-0.1.2.tgz",
"integrity": "sha1-rW8wwTvs15cBDEaK+ndcDAprR/o=",
"integrity": "sha512-oyrU88skkMtDdauHDuKVrgR+zuItqr6/c//FXzvmxRGMexSDc6hNvJInGW3LL46n+8b50RykrvwSUIIQH2LQ5A==",
"dev": true
},
"require-main-filename": {
@ -30370,7 +30361,7 @@
"tdigest": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/tdigest/-/tdigest-0.1.1.tgz",
"integrity": "sha1-Ljyyw56kSeVdHmzZEReszKRYgCE=",
"integrity": "sha512-CXcDY/NIgIbKZPx5H4JJNpq6JwJhU5Z4+yWj4ZghDc7/9nVajiRlPPyMXRePPPlBfcayUqtoCXjo7/Hm82ecUA==",
"requires": {
"bintrees": "1.0.1"
}

View file

@ -132,7 +132,7 @@
"passport-orcid": "0.0.4",
"passport-saml": "^1.3.3",
"passport-twitter": "^1.0.4",
"pdfjs-dist": "^2.2.228",
"pdfjs-dist": "^2.6.347",
"prop-types": "^15.7.2",
"pug": "^3.0.1",
"qrcode": "^1.4.4",
@ -162,6 +162,7 @@
"uuid": "^3.0.1",
"valid-data-url": "^2.0.0",
"valid-url": "^1.0.9",
"worker-loader": "^2.0.0",
"xml2js": "^0.4.22",
"xregexp": "^4.3.0",
"yauzl": "^2.10.0"