overleaf/services/web/frontend/js/ide/pdfng/directives/pdfTextLayer.js
Alf Eaton 1be43911b4 Merge pull request #3942 from overleaf/prettier-trailing-comma
Set Prettier's "trailingComma" setting to "es5"

GitOrigin-RevId: 9f14150511929a855b27467ad17be6ab262fe5d5
2021-04-28 02:10:01 +00:00

77 lines
2.1 KiB
JavaScript

/* 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
*/
import App from '../../../base'
// uses the PDFJS text layer renderer to provide invisible overlayed
// text for searching
App.factory('pdfTextLayer', function () {
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
}
render(timeout) {
if (this.renderingDone || !this.divContentDone) {
return
}
if (this.textLayerRenderTask != null) {
this.textLayerRenderTask.cancel()
this.textLayerRenderTask = null
}
this.textDivs = []
const textLayerFrag = document.createDocumentFragment()
this.textLayerRenderTask = this.renderer({
textContent: this.textContent,
container: textLayerFrag,
viewport: this.viewport,
textDivs: this.textDivs,
timeout,
enhanceTextSelection: this.enhanceTextSelection,
})
const textLayerSuccess = () => {
this.textLayerDiv.appendChild(textLayerFrag)
return (this.renderingDone = true)
}
const textLayerFailure = function () {
// canceled or failed to render text layer -- skipping errors
}
return this.textLayerRenderTask.promise.then(
textLayerSuccess,
textLayerFailure
)
}
setTextContent(textContent) {
if (this.textLayerRenderTask) {
this.textLayerRenderTask.cancel()
this.textLayerRenderTask = null
}
this.textContent = textContent
return (this.divContentDone = true)
}
})
})