@zag-js/slider 0.0.0-dev-20220514160702 → 0.0.0-dev-20220517103524

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
@@ -427,10 +427,6 @@ findByTypeahead.defaultOptions = {
427
427
 
428
428
  // ../../utilities/number/dist/index.mjs
429
429
  var __pow2 = Math.pow;
430
- var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
431
- function formatter(n) {
432
- return parseFloat(nf.format(n));
433
- }
434
430
  function round(v, t2) {
435
431
  let num = valueOf(v);
436
432
  const p = __pow2(10, t2 != null ? t2 : 10);
@@ -445,17 +441,15 @@ function clamp(v, o) {
445
441
  function countDecimals(value) {
446
442
  if (!Number.isFinite(value))
447
443
  return 0;
448
- let e = 1;
449
- let p = 0;
444
+ let e = 1, p = 0;
450
445
  while (Math.round(value * e) / e !== value) {
451
446
  e *= 10;
452
447
  p += 1;
453
448
  }
454
449
  return p;
455
450
  }
456
- var increment = (v, s) => formatter(valueOf(v) + s);
457
- var decrement = (v, s) => formatter(valueOf(v) - s);
458
- var multiply = (v, s) => formatter(valueOf(v) * s);
451
+ var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
452
+ var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
459
453
  function snapToStep(value, step) {
460
454
  const num = valueOf(value);
461
455
  const p = countDecimals(step);
@@ -468,6 +462,18 @@ function valueOf(v) {
468
462
  const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
469
463
  return !Number.isNaN(num) ? num : 0;
470
464
  }
465
+ function decimalOperation(a, op, b) {
466
+ let result = op === "+" ? a + b : a - b;
467
+ if (a % 1 !== 0 || b % 1 !== 0) {
468
+ const multiplier = __pow2(10, Math.max(countDecimals(a), countDecimals(b)));
469
+ a = Math.round(a * multiplier);
470
+ b = Math.round(b * multiplier);
471
+ result = op === "+" ? a + b : a - b;
472
+ result /= multiplier;
473
+ }
474
+ return result;
475
+ }
476
+ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
471
477
  var transform = (a, b) => {
472
478
  const i = { min: a[0], max: a[1] };
473
479
  const o = { min: b[0], max: b[1] };
@@ -760,7 +766,7 @@ function connect(state2, send, normalize = normalizeProp) {
760
766
  onKeyDown(event) {
761
767
  if (!isInteractive)
762
768
  return;
763
- const step = multiply(getEventStep(event), state2.context.step);
769
+ const step = getEventStep(event) * state2.context.step;
764
770
  let prevent = true;
765
771
  const keyMap = {
766
772
  ArrowUp() {