mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-02-08 00:21:11 +01:00
Limit the Math.sumPrecise polyfill to non-MOZCENTRAL builds
After https://bugzilla.mozilla.org/show_bug.cgi?id=1985121 this functionality is now guaranteed to be available in Firefox. Unfortunately general browser support is still somewhat lacking; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sumPrecise#browser_compatibility Also, while unrelated, use the `MathClamp` helper in the `applyOpacity` function.
This commit is contained in:
parent
d25f13d1fd
commit
76dabeddb3
@ -799,7 +799,7 @@ class CSSConstants {
|
||||
}
|
||||
|
||||
function applyOpacity(r, g, b, opacity) {
|
||||
opacity = Math.min(Math.max(opacity ?? 1, 0), 1);
|
||||
opacity = MathClamp(opacity ?? 1, 0, 1);
|
||||
const white = 255 * (1 - opacity);
|
||||
r = Math.round(r * opacity + white);
|
||||
g = Math.round(g * opacity + white);
|
||||
|
||||
@ -1235,9 +1235,12 @@ function MathClamp(v, min, max) {
|
||||
return Math.min(Math.max(v, min), max);
|
||||
}
|
||||
|
||||
// TODO: Remove this once the `javascript.options.experimental.math_sumprecise`
|
||||
// preference is removed from Firefox.
|
||||
if (typeof Math.sumPrecise !== "function") {
|
||||
// TODO: Remove this once `Math.sumPrecise` is generally available.
|
||||
if (
|
||||
(typeof PDFJSDev === "undefined" ||
|
||||
PDFJSDev.test("SKIP_BABEL && !MOZCENTRAL")) &&
|
||||
typeof Math.sumPrecise !== "function"
|
||||
) {
|
||||
// Note that this isn't a "proper" polyfill, but since we're only using it to
|
||||
// replace `Array.prototype.reduce()` invocations it should be fine.
|
||||
Math.sumPrecise = function (numbers) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user