mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-11 17:06:43 -05:00
bc1b73d74e
Transform absolute paths in frontend to relative GitOrigin-RevId: c1914c0fd09d68984ba6c85a1f00aa3e6858d944
78 lines
2.2 KiB
JavaScript
78 lines
2.2 KiB
JavaScript
/* eslint-disable
|
|
max-len,
|
|
no-return-assign,
|
|
no-undef,
|
|
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
|
|
*/
|
|
define(['../../../base'], App =>
|
|
// 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)
|
|
}
|
|
})
|
|
}))
|