|
@@ -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(
|
|
|
|
|
- error
|
|
|
|
|
- ? OError.tag(error)
|
|
|
|
|
- : new UnknownPDFError('pdfJsLoader.getDocument()')
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ return this.errorCallback(exception)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -137,14 +132,9 @@ export default App.factory(
|
|
|
return (viewport = page.getViewport({ scale: scale }))
|
|
return (viewport = page.getViewport({ scale: scale }))
|
|
|
},
|
|
},
|
|
|
error => {
|
|
error => {
|
|
|
- this.errorCallback(
|
|
|
|
|
- error
|
|
|
|
|
- ? OError.tag(error)
|
|
|
|
|
- : new UnknownPDFError('getPdfViewport', {
|
|
|
|
|
- pageNum,
|
|
|
|
|
- scale,
|
|
|
|
|
- })
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ return typeof this.errorCallback === 'function'
|
|
|
|
|
+ ? this.errorCallback(error)
|
|
|
|
|
+ : undefined
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -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(
|
|
|
|
|
- error
|
|
|
|
|
- ? OError.tag(error)
|
|
|
|
|
- : new UnknownPDFError('getDestination', { dest })
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ return typeof this.errorCallback === 'function'
|
|
|
|
|
+ ? this.errorCallback(error)
|
|
|
|
|
+ : undefined
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
@@ -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(
|
|
|
|
|
- error
|
|
|
|
|
- ? OError.tag(error)
|
|
|
|
|
- : new UnknownPDFError('getPageIndex', { ref })
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ return typeof this.errorCallback === 'function'
|
|
|
|
|
+ ? this.errorCallback(error)
|
|
|
|
|
+ : undefined
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
@@ -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(
|
|
|
|
|
- error
|
|
|
|
|
- ? OError.tag(error)
|
|
|
|
|
- : new UnknownPDFError('page.getTextContent')
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ typeof self.errorCallback === 'function'
|
|
|
|
|
+ ? self.errorCallback(error)
|
|
|
|
|
+ : undefined
|
|
|
)
|
|
)
|
|
|
return page.getAnnotations().then(
|
|
return page.getAnnotations().then(
|
|
|
annotations => annotationsLayer.setAnnotations(annotations),
|
|
annotations => annotationsLayer.setAnnotations(annotations),
|
|
|
error =>
|
|
error =>
|
|
|
- self.errorCallback(
|
|
|
|
|
- error
|
|
|
|
|
- ? OError.tag(error)
|
|
|
|
|
- : new UnknownPDFError('page.getAnnotations')
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ typeof self.errorCallback === 'function'
|
|
|
|
|
+ ? self.errorCallback(error)
|
|
|
|
|
+ : undefined
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
.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(
|
|
|
|
|
- error ? OError.tag(error) : new UnknownPDFError('page.render')
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ return typeof self.errorCallback === 'function'
|
|
|
|
|
+ ? 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)
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|