mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
Introduce a viewer constant for document.documentElement.style
Over time, as we've been introducing JavaScript code to modify CSS variables, we've been adding shorthand properties to various classes to reduce unnecessary repetition when accessing the document-styles. Rather than repeating this in multiple places, it seems overall simpler to just introduce a constant and re-use that throughout the viewer instead.
This commit is contained in:
parent
5b02c685d6
commit
ca244d9bca
5 changed files with 21 additions and 13 deletions
|
@ -677,6 +677,13 @@ const animationStarted = new Promise(function (resolve) {
|
|||
window.requestAnimationFrame(resolve);
|
||||
});
|
||||
|
||||
const docStyle =
|
||||
typeof PDFJSDev !== "undefined" &&
|
||||
PDFJSDev.test("LIB") &&
|
||||
typeof document === "undefined"
|
||||
? null
|
||||
: document.documentElement.style;
|
||||
|
||||
function clamp(v, min, max) {
|
||||
return Math.min(Math.max(v, min), max);
|
||||
}
|
||||
|
@ -709,8 +716,7 @@ class ProgressBar {
|
|||
}
|
||||
this.div.classList.remove("indeterminate");
|
||||
|
||||
const doc = document.documentElement;
|
||||
doc.style.setProperty("--progressBar-percent", `${this._percent}%`);
|
||||
docStyle.setProperty("--progressBar-percent", `${this._percent}%`);
|
||||
}
|
||||
|
||||
get percent() {
|
||||
|
@ -730,8 +736,7 @@ class ProgressBar {
|
|||
const container = viewer.parentNode;
|
||||
const scrollbarWidth = container.offsetWidth - viewer.offsetWidth;
|
||||
if (scrollbarWidth > 0) {
|
||||
const doc = document.documentElement;
|
||||
doc.style.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
|
||||
docStyle.setProperty("--progressBar-end-offset", `${scrollbarWidth}px`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -843,6 +848,7 @@ export {
|
|||
DEFAULT_SCALE,
|
||||
DEFAULT_SCALE_DELTA,
|
||||
DEFAULT_SCALE_VALUE,
|
||||
docStyle,
|
||||
getActiveOrFocusedElement,
|
||||
getPageSizeInches,
|
||||
getVisibleElements,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue