2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-05-19 05:02:56 -04:00
|
|
|
import App from '../../../base'
|
|
|
|
// uses the PDFJS text layer renderer to provide invisible overlayed
|
|
|
|
// text for searching
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.factory('pdfTextLayer', function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
let pdfTextLayer
|
|
|
|
return (pdfTextLayer = class pdfTextLayer {
|
|
|
|
constructor(options) {
|
|
|
|
this.textLayerDiv = options.textLayerDiv
|
|
|
|
this.divContentDone = false
|
|
|
|
this.viewport = options.viewport
|
|
|
|
this.textDivs = []
|
|
|
|
this.renderer = options.renderer
|
|
|
|
this.renderingDone = false
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
render(timeout) {
|
|
|
|
if (this.renderingDone || !this.divContentDone) {
|
|
|
|
return
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (this.textLayerRenderTask != null) {
|
|
|
|
this.textLayerRenderTask.cancel()
|
|
|
|
this.textLayerRenderTask = null
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
this.textDivs = []
|
|
|
|
const textLayerFrag = document.createDocumentFragment()
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
this.textLayerRenderTask = this.renderer({
|
|
|
|
textContent: this.textContent,
|
|
|
|
container: textLayerFrag,
|
|
|
|
viewport: this.viewport,
|
|
|
|
textDivs: this.textDivs,
|
|
|
|
timeout,
|
2021-04-27 03:52:58 -04:00
|
|
|
enhanceTextSelection: this.enhanceTextSelection,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const textLayerSuccess = () => {
|
|
|
|
this.textLayerDiv.appendChild(textLayerFrag)
|
|
|
|
return (this.renderingDone = true)
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const textLayerFailure = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
// canceled or failed to render text layer -- skipping errors
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
return this.textLayerRenderTask.promise.then(
|
|
|
|
textLayerSuccess,
|
|
|
|
textLayerFailure
|
|
|
|
)
|
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
setTextContent(textContent) {
|
|
|
|
if (this.textLayerRenderTask) {
|
|
|
|
this.textLayerRenderTask.cancel()
|
|
|
|
this.textLayerRenderTask = null
|
2019-07-16 05:13:18 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
|
|
|
this.textContent = textContent
|
|
|
|
return (this.divContentDone = true)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|