@react-aria/utils
Advanced tools
Comparing version 3.4.1 to 3.5.0
@@ -325,2 +325,27 @@ var _clsx = $parcel$interopDefault(require("clsx")); | ||
exports.clamp = clamp; | ||
function snapValueToStep(value, min, max, step) { | ||
let remainder = (value - min) % step; | ||
let snappedValue = Math.abs(remainder) * 2 >= step ? value - Math.abs(remainder) + step : value - remainder; | ||
if (snappedValue < min) { | ||
snappedValue = min; | ||
} else if (snappedValue > max) { | ||
snappedValue = min + Math.floor((max - min) / step) * step; | ||
} // correct floating point behavior by rounding to step precision | ||
let string = step.toString(); | ||
let index = string.indexOf('.'); | ||
let precision = index >= 0 ? string.length - index : 0; | ||
if (precision > 0) { | ||
let pow = Math.pow(10, precision); | ||
snappedValue = Math.round(snappedValue * pow) / pow; | ||
} | ||
return snappedValue; | ||
} | ||
exports.snapValueToStep = snapValueToStep; | ||
// mapped to a set of CSS properties that are transitioning for that element. | ||
@@ -327,0 +352,0 @@ // This is necessary rather than a simple count of transitions because of browser |
@@ -284,2 +284,24 @@ import _clsx from "clsx"; | ||
} | ||
export function snapValueToStep(value, min, max, step) { | ||
let remainder = (value - min) % step; | ||
let snappedValue = Math.abs(remainder) * 2 >= step ? value - Math.abs(remainder) + step : value - remainder; | ||
if (snappedValue < min) { | ||
snappedValue = min; | ||
} else if (snappedValue > max) { | ||
snappedValue = min + Math.floor((max - min) / step) * step; | ||
} // correct floating point behavior by rounding to step precision | ||
let string = step.toString(); | ||
let index = string.indexOf('.'); | ||
let precision = index >= 0 ? string.length - index : 0; | ||
if (precision > 0) { | ||
let pow = Math.pow(10, precision); | ||
snappedValue = Math.round(snappedValue * pow) / pow; | ||
} | ||
return snappedValue; | ||
} | ||
// mapped to a set of CSS properties that are transitioning for that element. | ||
@@ -286,0 +308,0 @@ // This is necessary rather than a simple count of transitions because of browser |
@@ -60,2 +60,3 @@ import React, { HTMLAttributes, MutableRefObject, EffectCallback, RefObject } from "react"; | ||
export function clamp(value: number, min?: number, max?: number): number; | ||
export function snapValueToStep(value: number, min: number, max: number, step: number): number; | ||
export function runAfterTransition(fn: () => void): void; | ||
@@ -62,0 +63,0 @@ interface UseDrag1DProps { |
{ | ||
"name": "@react-aria/utils", | ||
"version": "3.4.1", | ||
"version": "3.5.0", | ||
"description": "Spectrum UI components in React", | ||
@@ -31,3 +31,3 @@ "license": "Apache-2.0", | ||
}, | ||
"gitHead": "f5b429ee8615248f2e3c76754bad2ece83f1c444" | ||
"gitHead": "0159136997a4b18166b0e660b929fd8e243410c8" | ||
} |
@@ -19,1 +19,26 @@ /* | ||
} | ||
export function snapValueToStep(value: number, min: number, max: number, step: number): number { | ||
let remainder = ((value - min) % step); | ||
let snappedValue = Math.abs(remainder) * 2 >= step | ||
? (value - Math.abs(remainder)) + step | ||
: value - remainder; | ||
if (snappedValue < min) { | ||
snappedValue = min; | ||
} else if (snappedValue > max) { | ||
snappedValue = min + Math.floor((max - min) / step) * step; | ||
} | ||
// correct floating point behavior by rounding to step precision | ||
let string = step.toString(); | ||
let index = string.indexOf('.'); | ||
let precision = index >= 0 ? string.length - index : 0; | ||
if (precision > 0) { | ||
let pow = Math.pow(10, precision); | ||
snappedValue = Math.round(snappedValue * pow) / pow; | ||
} | ||
return snappedValue; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
214453
2251