Convert PDF.js code to TypeScript

GitOrigin-RevId: 840bc48816d78497131b927522b4f6f7940bb0c4
This commit is contained in:
Alf Eaton
2024-10-14 11:00:45 +00:00
committed by Copybot
parent be45aec5b5
commit df6147bb4d
11 changed files with 135 additions and 164 deletions
@@ -140,14 +140,16 @@ export class GraphicsWidget extends WidgetType {
}
async renderPDF(view: EditorView, canvas: HTMLCanvasElement, url: string) {
const { PDFJS } = await this.importPDFJS()
const { loadPdfDocumentFromUrl } = await import(
'@/features/pdf-preview/util/pdf-js'
)
// bail out if loading PDF.js took too long
if (this.destroyed) {
return
}
const pdf = await PDFJS.getDocument({ url, isEvalSupported: false }).promise
const pdf = await loadPdfDocumentFromUrl(url).promise
const page = await pdf.getPage(1)
// bail out if loading the PDF took too long
@@ -162,16 +164,10 @@ export class GraphicsWidget extends WidgetType {
canvas.style.width = width
canvas.style.maxWidth = width
page.render({
canvasContext: canvas.getContext('2d'),
canvasContext: canvas.getContext('2d')!,
viewport,
})
this.height = viewport.height
view.requestMeasure()
}
async importPDFJS(): Promise<any> {
return import('../../../../pdf-preview/util/pdf-js-versions').then(
m => m.default
)
}
}