1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Simplify logic to insert canvas as first element

Instead of conditionally checking if the `.cavnasWrapper` already
has a child element and then inserting the `canvas` before it, we can
use `.prepend` which always injects the new element as the first
child.
This commit is contained in:
Nicolò Ribaudo 2024-12-10 12:00:09 +01:00
parent 44421d36f6
commit 62db66dd46
No known key found for this signature in database
GPG key ID: AAFDA9101C58F338

View file

@ -989,12 +989,7 @@ class PDFPageView {
// drawing is complete when `!this.renderingQueue`, to prevent black
// flickering.
// In whatever case, the canvas must be the first child.
const { firstChild } = canvasWrapper;
if (firstChild) {
firstChild.before(canvas);
} else {
canvasWrapper.append(canvas);
}
canvasWrapper.prepend(canvas);
showCanvas = null;
return;
}
@ -1006,12 +1001,7 @@ class PDFPageView {
prevCanvas.replaceWith(canvas);
prevCanvas.width = prevCanvas.height = 0;
} else {
const { firstChild } = canvasWrapper;
if (firstChild) {
firstChild.before(canvas);
} else {
canvasWrapper.append(canvas);
}
canvasWrapper.prepend(canvas);
}
showCanvas = null;