Fix clamp function
This commit is contained in:
parent
f35077afce
commit
15a0521408
|
@ -327,7 +327,7 @@ function configDialog(style) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clamp input[type=number] to a valid range
|
// Clamp input[type=number] to a valid range
|
||||||
function clampValue(value, va) {
|
function clampValue(value, va, break = false) {
|
||||||
const max = isNumber(va.max) ? va.max : 100;
|
const max = isNumber(va.max) ? va.max : 100;
|
||||||
if (isNumber(va.min) && value < va.min) {
|
if (isNumber(va.min) && value < va.min) {
|
||||||
return min;
|
return min;
|
||||||
|
@ -336,14 +336,14 @@ function configDialog(style) {
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
// Don't restrict to integer values if step is undefined.
|
// Don't restrict to integer values if step is undefined.
|
||||||
if (!isNumber(va.step)) {
|
if (!isNumber(va.step) || break) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
const step = va.step || 1;
|
const step = va.step || 1;
|
||||||
const precision = (step.toString().split('.')[1] || 0).length + 1;
|
const scale = 10 ** (step.toString().split('.')[1] || '').length;
|
||||||
const inv = 1 / step;
|
value = Math.round((value * scale) / (step * scale)) * (step * scale) / scale;
|
||||||
// ECMA-262 only requires a precision of up to 21 significant digits
|
// clamp modified value; skip step check
|
||||||
return Number((Math.floor(inv * value) / inv).toPrecision(precision > 21 ? 21 : precision));
|
return clampValue(value, va, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateVarOnInput(event, debounced = false) {
|
function updateVarOnInput(event, debounced = false) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user