1 | import { clamp } from '@mui/utils';
|
2 | export function clampStepwise(val, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER, stepProp = NaN) {
|
3 | if (Number.isNaN(stepProp)) {
|
4 | return clamp(val, min, max);
|
5 | }
|
6 | const step = stepProp || 1;
|
7 | const remainder = val % step;
|
8 | const positivity = Math.sign(remainder);
|
9 | if (Math.abs(remainder) > step / 2) {
|
10 | return clamp(val + positivity * (step - Math.abs(remainder)), min, max);
|
11 | }
|
12 | return clamp(val - positivity * Math.abs(remainder), min, max);
|
13 | }
|
14 | export function isNumber(val) {
|
15 | return typeof val === 'number' && !Number.isNaN(val) && Number.isFinite(val);
|
16 | } |
\ | No newline at end of file |