@zag-js/utils 1.13.1 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -221,23 +221,19 @@ var roundToStepPrecision = (v, step) => {
221
221
  };
222
222
  var roundToDpr = (v, dpr) => typeof dpr === "number" ? floor(v * dpr + 0.5) / dpr : round(v);
223
223
  var snapValueToStep = (v, vmin, vmax, step) => {
224
- vmin = Number(vmin);
225
- vmax = Number(vmax);
226
- let remainder = (v - (isNaN(vmin) ? 0 : vmin)) % step;
227
- let sv = roundToStepPrecision(
228
- abs(remainder) * 2 >= step ? v + sign(remainder) * (step - abs(remainder)) : v - remainder,
229
- step
230
- );
231
- if (!isNaN(vmin)) {
232
- if (sv < vmin) {
233
- sv = vmin;
234
- } else if (!isNaN(vmax) && sv > vmax) {
235
- sv = vmin + floor(roundToStepPrecision((vmax - vmin) / step, step)) * step;
236
- }
237
- } else if (!isNaN(vmax) && sv > vmax) {
238
- sv = vmin + floor(roundToStepPrecision((vmax - vmin) / step, step)) * step;
224
+ const min2 = vmin != null ? Number(vmin) : 0;
225
+ const max2 = Number(vmax);
226
+ const remainder = (v - min2) % step;
227
+ let snapped = abs(remainder) * 2 >= step ? v + sign(remainder) * (step - abs(remainder)) : v - remainder;
228
+ snapped = roundToStepPrecision(snapped, step);
229
+ if (!isNaN(min2) && snapped < min2) {
230
+ snapped = min2;
231
+ } else if (!isNaN(max2) && snapped > max2) {
232
+ const stepsInRange = floor((max2 - min2) / step);
233
+ const largestValidStep = min2 + stepsInRange * step;
234
+ snapped = stepsInRange <= 0 || largestValidStep < min2 ? max2 : largestValidStep;
239
235
  }
240
- return roundToStepPrecision(sv, step);
236
+ return roundToStepPrecision(snapped, step);
241
237
  };
242
238
  var setValueAtIndex = (vs, i, v) => {
243
239
  if (vs[i] === v) return vs;
package/dist/index.mjs CHANGED
@@ -219,23 +219,19 @@ var roundToStepPrecision = (v, step) => {
219
219
  };
220
220
  var roundToDpr = (v, dpr) => typeof dpr === "number" ? floor(v * dpr + 0.5) / dpr : round(v);
221
221
  var snapValueToStep = (v, vmin, vmax, step) => {
222
- vmin = Number(vmin);
223
- vmax = Number(vmax);
224
- let remainder = (v - (isNaN(vmin) ? 0 : vmin)) % step;
225
- let sv = roundToStepPrecision(
226
- abs(remainder) * 2 >= step ? v + sign(remainder) * (step - abs(remainder)) : v - remainder,
227
- step
228
- );
229
- if (!isNaN(vmin)) {
230
- if (sv < vmin) {
231
- sv = vmin;
232
- } else if (!isNaN(vmax) && sv > vmax) {
233
- sv = vmin + floor(roundToStepPrecision((vmax - vmin) / step, step)) * step;
234
- }
235
- } else if (!isNaN(vmax) && sv > vmax) {
236
- sv = vmin + floor(roundToStepPrecision((vmax - vmin) / step, step)) * step;
222
+ const min2 = vmin != null ? Number(vmin) : 0;
223
+ const max2 = Number(vmax);
224
+ const remainder = (v - min2) % step;
225
+ let snapped = abs(remainder) * 2 >= step ? v + sign(remainder) * (step - abs(remainder)) : v - remainder;
226
+ snapped = roundToStepPrecision(snapped, step);
227
+ if (!isNaN(min2) && snapped < min2) {
228
+ snapped = min2;
229
+ } else if (!isNaN(max2) && snapped > max2) {
230
+ const stepsInRange = floor((max2 - min2) / step);
231
+ const largestValidStep = min2 + stepsInRange * step;
232
+ snapped = stepsInRange <= 0 || largestValidStep < min2 ? max2 : largestValidStep;
237
233
  }
238
- return roundToStepPrecision(sv, step);
234
+ return roundToStepPrecision(snapped, step);
239
235
  };
240
236
  var setValueAtIndex = (vs, i, v) => {
241
237
  if (vs[i] === v) return vs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/utils",
3
- "version": "1.13.1",
3
+ "version": "1.15.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "js",