mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 06:38:07 +02:00
Introduce a helper function for clamping a value to a range
Currently we have a number of spots in the code-base where we need to clamp a value to a [min, max] range. This is either implemented using `Math.min`/`Math.max` or with a local helper function, which leads to some unnecessary duplication. Hence this patch adds and re-uses a single helper function for this, which we'll hopefully be able to remove in the future once https://github.com/tc39/proposal-math-clamp/ becomes generally available.
This commit is contained in:
parent
dea35aed4a
commit
07bbbf75a5
12 changed files with 57 additions and 68 deletions
|
@ -40,6 +40,7 @@ const {
|
|||
isDataScheme,
|
||||
isPdfFile,
|
||||
isValidExplicitDest,
|
||||
MathClamp,
|
||||
noContextMenu,
|
||||
normalizeUnicode,
|
||||
OPS,
|
||||
|
@ -92,6 +93,7 @@ export {
|
|||
isDataScheme,
|
||||
isPdfFile,
|
||||
isValidExplicitDest,
|
||||
MathClamp,
|
||||
noContextMenu,
|
||||
normalizeUnicode,
|
||||
OPS,
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { MathClamp } from "pdfjs-lib";
|
||||
|
||||
const DEFAULT_SCALE_VALUE = "auto";
|
||||
const DEFAULT_SCALE = 1.0;
|
||||
const DEFAULT_SCALE_DELTA = 1.1;
|
||||
|
@ -676,10 +678,6 @@ const docStyle =
|
|||
? null
|
||||
: document.documentElement.style;
|
||||
|
||||
function clamp(v, min, max) {
|
||||
return Math.min(Math.max(v, min), max);
|
||||
}
|
||||
|
||||
class ProgressBar {
|
||||
#classList = null;
|
||||
|
||||
|
@ -701,7 +699,7 @@ class ProgressBar {
|
|||
}
|
||||
|
||||
set percent(val) {
|
||||
this.#percent = clamp(val, 0, 100);
|
||||
this.#percent = MathClamp(val, 0, 100);
|
||||
|
||||
if (isNaN(val)) {
|
||||
this.#classList.add("indeterminate");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue