@zag-js/number-input 0.0.0-dev-20220508172505 → 0.0.0-dev-20220508184419

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
@@ -297,9 +297,16 @@ function roundToPx(num) {
297
297
  function clamp(v, o) {
298
298
  return Math.min(Math.max(valueOf(v), o.min), o.max);
299
299
  }
300
- function countDecimals(v) {
301
- var _a, _b;
302
- return (_b = (_a = nf.formatToParts(v).find((p) => p.type === "fraction")) == null ? void 0 : _a.value.length) != null ? _b : 0;
300
+ function countDecimals(value) {
301
+ if (!Number.isFinite(value))
302
+ return 0;
303
+ let e = 1;
304
+ let p = 0;
305
+ while (Math.round(value * e) / e !== value) {
306
+ e *= 10;
307
+ p += 1;
308
+ }
309
+ return p;
303
310
  }
304
311
  var increment = (v, s) => formatter(valueOf(v) + s);
305
312
  var decrement = (v, s) => formatter(valueOf(v) - s);
@@ -313,9 +320,7 @@ function valueOf(v) {
313
320
  function getMaxPrecision(o) {
314
321
  var _a;
315
322
  const stepPrecision = countDecimals(o.step);
316
- const val = valueOf(o.value);
317
- const valuePrecision = Number.isNaN(val) ? stepPrecision : Math.max(countDecimals(val), stepPrecision);
318
- return Math.max(valuePrecision, (_a = o.precision) != null ? _a : 0);
323
+ return Math.max(stepPrecision, (_a = o.precision) != null ? _a : 0);
319
324
  }
320
325
  function roundToPrecision(v, o) {
321
326
  return round(v, getMaxPrecision(__spreadProps2(__spreadValues2({}, o), { value: v })));