@zag-js/slider 0.2.7 → 0.2.8

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.
@@ -9,11 +9,7 @@ import {
9
9
  } from "./chunk-SGCWELVB.mjs";
10
10
  import {
11
11
  dom
12
- } from "./chunk-MR2MUD77.mjs";
13
- import {
14
- percentToValue,
15
- valueToPercent
16
- } from "./chunk-GBYBRQZL.mjs";
12
+ } from "./chunk-J5IGGBVE.mjs";
17
13
 
18
14
  // ../../utilities/dom/src/attrs.ts
19
15
  var dataAttr = (guard) => {
@@ -71,6 +67,7 @@ function getEventStep(event) {
71
67
  }
72
68
 
73
69
  // src/slider.connect.ts
70
+ import { getPercentValue, getValuePercent } from "@zag-js/numeric-range";
74
71
  function connect(state, send, normalize) {
75
72
  var _a, _b;
76
73
  const ariaLabel = state.context["aria-label"];
@@ -85,12 +82,15 @@ function connect(state, send, normalize) {
85
82
  isFocused,
86
83
  isDragging,
87
84
  value: state.context.value,
88
- percent: valueToPercent(state.context.value, state.context),
85
+ percent: getValuePercent(state.context.value, state.context.min, state.context.max),
89
86
  setValue(value) {
90
87
  send({ type: "SET_VALUE", value });
91
88
  },
92
89
  getPercentValue(percent) {
93
- return percentToValue(percent, state.context);
90
+ return getPercentValue(percent, state.context.min, state.context.max, state.context.step);
91
+ },
92
+ getValuePercent(value) {
93
+ return getValuePercent(value, state.context.min, state.context.max);
94
94
  },
95
95
  focus() {
96
96
  var _a2;
@@ -266,7 +266,7 @@ function connect(state, send, normalize) {
266
266
  style: dom.getMarkerGroupStyle()
267
267
  }),
268
268
  getMarkerProps({ value }) {
269
- const percent = valueToPercent(value, state.context);
269
+ const percent = this.getValuePercent(value);
270
270
  const style = dom.getMarkerStyle(state.context, percent);
271
271
  const markerState = value > state.context.value ? "over-value" : value < state.context.value ? "under-value" : "at-value";
272
272
  return normalize.element({
@@ -11,10 +11,12 @@ import {
11
11
  } from "./chunk-SGCWELVB.mjs";
12
12
  import {
13
13
  dom
14
- } from "./chunk-MR2MUD77.mjs";
14
+ } from "./chunk-J5IGGBVE.mjs";
15
15
  import {
16
- utils
17
- } from "./chunk-FUTBDWTA.mjs";
16
+ constrainValue,
17
+ decrement,
18
+ increment
19
+ } from "./chunk-DRAPR6JV.mjs";
18
20
 
19
21
  // src/slider.machine.ts
20
22
  import { createMachine } from "@zag-js/core";
@@ -216,6 +218,9 @@ function trackPointerMove(doc, opts) {
216
218
  );
217
219
  }
218
220
 
221
+ // src/slider.machine.ts
222
+ import { trackElementSize } from "@zag-js/element-size";
223
+
219
224
  // ../../utilities/form-utils/src/form.ts
220
225
  function getClosestForm(el) {
221
226
  if (isFormElement(el))
@@ -259,7 +264,7 @@ function trackFormControl(el, options) {
259
264
  }
260
265
 
261
266
  // src/slider.machine.ts
262
- import { trackElementSize } from "@zag-js/element-size";
267
+ import { clampValue, getValuePercent } from "@zag-js/numeric-range";
263
268
  function machine(userContext) {
264
269
  const ctx = compact(userContext);
265
270
  return createMachine(
@@ -286,7 +291,8 @@ function machine(userContext) {
286
291
  isVertical: (ctx2) => ctx2.orientation === "vertical",
287
292
  isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
288
293
  isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly),
289
- hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
294
+ hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null,
295
+ valuePercent: (ctx2) => 100 * getValuePercent(ctx2.value, ctx2.min, ctx2.max)
290
296
  },
291
297
  watch: {
292
298
  value: ["invokeOnChange", "dispatchChangeEvent"]
@@ -413,7 +419,7 @@ function machine(userContext) {
413
419
  },
414
420
  actions: {
415
421
  checkValue(ctx2) {
416
- const value = utils.convert(ctx2, ctx2.value);
422
+ const value = constrainValue(ctx2, ctx2.value);
417
423
  ctx2.value = value;
418
424
  ctx2.initialValue = value;
419
425
  },
@@ -436,7 +442,7 @@ function machine(userContext) {
436
442
  const value = dom.getValueFromPoint(ctx2, evt.point);
437
443
  if (value == null)
438
444
  return;
439
- ctx2.value = utils.clamp(ctx2, value);
445
+ ctx2.value = clampValue(value, ctx2.min, ctx2.max);
440
446
  },
441
447
  focusThumb(ctx2) {
442
448
  raf(() => {
@@ -445,10 +451,10 @@ function machine(userContext) {
445
451
  });
446
452
  },
447
453
  decrement(ctx2, evt) {
448
- ctx2.value = utils.decrement(ctx2, evt.step);
454
+ ctx2.value = decrement(ctx2, evt.step);
449
455
  },
450
456
  increment(ctx2, evt) {
451
- ctx2.value = utils.increment(ctx2, evt.step);
457
+ ctx2.value = increment(ctx2, evt.step);
452
458
  },
453
459
  setToMin(ctx2) {
454
460
  ctx2.value = ctx2.min;
@@ -457,7 +463,7 @@ function machine(userContext) {
457
463
  ctx2.value = ctx2.max;
458
464
  },
459
465
  setValue(ctx2, evt) {
460
- ctx2.value = utils.convert(ctx2, evt.value);
466
+ ctx2.value = constrainValue(ctx2, evt.value);
461
467
  }
462
468
  }
463
469
  }
@@ -0,0 +1,34 @@
1
+ // src/slider.utils.ts
2
+ import { clampValue, getNextStepValue, getPreviousStepValue, snapValueToStep } from "@zag-js/numeric-range";
3
+ function clampPercent(percent) {
4
+ return clampValue(percent, 0, 1);
5
+ }
6
+ function constrainValue(ctx, value) {
7
+ const snapValue = snapValueToStep(value, ctx.min, ctx.max, ctx.step);
8
+ return clampValue(snapValue, ctx.min, ctx.max);
9
+ }
10
+ function decrement(ctx, step) {
11
+ const index = 0;
12
+ const values = getPreviousStepValue(index, {
13
+ ...ctx,
14
+ step: step != null ? step : ctx.step,
15
+ values: [ctx.value]
16
+ });
17
+ return values[index];
18
+ }
19
+ function increment(ctx, step) {
20
+ const index = 0;
21
+ const values = getNextStepValue(index, {
22
+ ...ctx,
23
+ step: step != null ? step : ctx.step,
24
+ values: [ctx.value]
25
+ });
26
+ return values[index];
27
+ }
28
+
29
+ export {
30
+ clampPercent,
31
+ constrainValue,
32
+ decrement,
33
+ increment
34
+ };
@@ -1,9 +1,6 @@
1
1
  import {
2
2
  styles
3
- } from "./chunk-MXJ3RGFD.mjs";
4
- import {
5
- utils
6
- } from "./chunk-FUTBDWTA.mjs";
3
+ } from "./chunk-YREEXXZP.mjs";
7
4
 
8
5
  // ../../utilities/dom/src/query.ts
9
6
  function isDocument(el) {
@@ -36,25 +33,7 @@ function defineDomHelpers(helpers) {
36
33
  return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
37
34
  },
38
35
  getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
39
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
40
- createEmitter: (ctx, target) => {
41
- const win = dom2.getWin(ctx);
42
- return function emit(evt, detail, options) {
43
- const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
44
- const eventName = `zag:${evt}`;
45
- const init = { bubbles, cancelable, composed, detail };
46
- const event = new win.CustomEvent(eventName, init);
47
- target.dispatchEvent(event);
48
- };
49
- },
50
- createListener: (target) => {
51
- return function listen(evt, handler) {
52
- const eventName = `zag:${evt}`;
53
- const listener = (e) => handler(e);
54
- target.addEventListener(eventName, listener);
55
- return () => target.removeEventListener(eventName, listener);
56
- };
57
- }
36
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
58
37
  };
59
38
  return {
60
39
  ...dom2,
@@ -115,6 +94,7 @@ function dispatchInputValueEvent(el, value) {
115
94
  }
116
95
 
117
96
  // src/slider.dom.ts
97
+ import { getPercentValue } from "@zag-js/numeric-range";
118
98
  var dom = defineDomHelpers({
119
99
  ...styles,
120
100
  getRootId: (ctx) => {
@@ -164,7 +144,7 @@ var dom = defineDomHelpers({
164
144
  } else {
165
145
  percent = 1 - percentY;
166
146
  }
167
- return utils.fromPercent(ctx, percent);
147
+ return getPercentValue(percent, ctx.min, ctx.max, ctx.step);
168
148
  },
169
149
  dispatchChangeEvent(ctx) {
170
150
  const input = dom.getHiddenInputEl(ctx);
@@ -1,59 +1,51 @@
1
- import {
2
- valueToPercent
3
- } from "./chunk-GBYBRQZL.mjs";
4
-
5
- // ../../utilities/number/src/transform.ts
6
- var transform = (a, b) => {
7
- const i = { min: a[0], max: a[1] };
8
- const o = { min: b[0], max: b[1] };
9
- return (v) => {
10
- if (i.min === i.max || o.min === o.max)
11
- return o.min;
12
- const ratio = (o.max - o.min) / (i.max - i.min);
13
- return o.min + ratio * (v - i.min);
14
- };
15
- };
16
-
17
1
  // src/slider.style.ts
2
+ import { getValuePercent, getValueTransformer } from "@zag-js/numeric-range";
18
3
  function getVerticalThumbOffset(ctx) {
19
4
  var _a;
20
5
  const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
21
- const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
6
+ const getValue = getValueTransformer([ctx.min, ctx.max], [-height / 2, height / 2]);
22
7
  return parseFloat(getValue(ctx.value).toFixed(2));
23
8
  }
24
9
  function getHorizontalThumbOffset(ctx) {
25
10
  var _a;
26
11
  const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
27
12
  if (ctx.isRtl) {
28
- const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
13
+ const getValue2 = getValueTransformer([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
29
14
  return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
30
15
  }
31
- const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
16
+ const getValue = getValueTransformer([ctx.min, ctx.max], [-width / 2, width / 2]);
32
17
  return parseFloat(getValue(ctx.value).toFixed(2));
33
18
  }
34
19
  function getThumbOffset(ctx) {
35
- const percent = valueToPercent(ctx.value, ctx);
36
- if (ctx.thumbAlignment === "center")
20
+ const percent = getValuePercent(ctx.value, ctx.min, ctx.max) * 100;
21
+ if (ctx.thumbAlignment === "center") {
37
22
  return `${percent}%`;
23
+ }
38
24
  const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
39
25
  return `calc(${percent}% - ${offset}px)`;
40
26
  }
27
+ function getVisibility(ctx) {
28
+ let visibility = "visible";
29
+ if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
30
+ visibility = "hidden";
31
+ }
32
+ return visibility;
33
+ }
41
34
  function getThumbStyle(ctx) {
42
35
  const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
43
36
  return {
44
- visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
37
+ visibility: getVisibility(ctx),
45
38
  position: "absolute",
46
39
  transform: "var(--slider-thumb-transform)",
47
40
  [placementProp]: "var(--slider-thumb-offset)"
48
41
  };
49
42
  }
50
43
  function getRangeOffsets(ctx) {
51
- const percent = valueToPercent(ctx.value, ctx);
52
44
  let start = "0%";
53
- let end = `${100 - percent}%`;
45
+ let end = `${100 - ctx.valuePercent}%`;
54
46
  if (ctx.origin === "center") {
55
- const isNegative = percent < 50;
56
- start = isNegative ? `${percent}%` : "50%";
47
+ const isNegative = ctx.valuePercent < 50;
48
+ start = isNegative ? `${ctx.valuePercent}%` : "50%";
57
49
  end = isNegative ? "50%" : end;
58
50
  }
59
51
  return { start, end };
@@ -92,7 +84,7 @@ function getMarkerStyle(ctx, percent) {
92
84
  return {
93
85
  position: "absolute",
94
86
  pointerEvents: "none",
95
- [ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
87
+ [ctx.isHorizontal ? "left" : "bottom"]: `${(ctx.isRtl ? 1 - percent : percent) * 100}%`
96
88
  };
97
89
  }
98
90
  function getLabelStyle() {
package/dist/index.js CHANGED
@@ -117,25 +117,7 @@ function defineDomHelpers(helpers) {
117
117
  return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
118
118
  },
119
119
  getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
120
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
121
- createEmitter: (ctx, target) => {
122
- const win = dom2.getWin(ctx);
123
- return function emit(evt, detail, options) {
124
- const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
125
- const eventName = `zag:${evt}`;
126
- const init = { bubbles, cancelable, composed, detail };
127
- const event = new win.CustomEvent(eventName, init);
128
- target.dispatchEvent(event);
129
- };
130
- },
131
- createListener: (target) => {
132
- return function listen(evt, handler) {
133
- const eventName = `zag:${evt}`;
134
- const listener = (e) => handler(e);
135
- target.addEventListener(eventName, listener);
136
- return () => target.removeEventListener(eventName, listener);
137
- };
138
- }
120
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
139
121
  };
140
122
  return {
141
123
  ...dom2,
@@ -415,65 +397,8 @@ function trackPointerMove(doc, opts) {
415
397
  );
416
398
  }
417
399
 
418
- // ../../utilities/number/src/number.ts
419
- function round(v, t) {
420
- let num = valueOf(v);
421
- const p = 10 ** (t != null ? t : 10);
422
- num = Math.round(num * p) / p;
423
- return t ? num.toFixed(t) : v.toString();
424
- }
425
- var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
426
- var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
427
- function clamp(v, o) {
428
- return Math.min(Math.max(valueOf(v), o.min), o.max);
429
- }
430
- function countDecimals(value) {
431
- if (!Number.isFinite(value))
432
- return 0;
433
- let e = 1, p = 0;
434
- while (Math.round(value * e) / e !== value) {
435
- e *= 10;
436
- p += 1;
437
- }
438
- return p;
439
- }
440
- var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
441
- var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
442
- function snapToStep(value, step) {
443
- const num = valueOf(value);
444
- const p = countDecimals(step);
445
- const v = Math.round(num / step) * step;
446
- return round(v, p);
447
- }
448
- function valueOf(v) {
449
- if (typeof v === "number")
450
- return v;
451
- const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
452
- return !Number.isNaN(num) ? num : 0;
453
- }
454
- function decimalOperation(a, op, b) {
455
- let result = op === "+" ? a + b : a - b;
456
- if (a % 1 !== 0 || b % 1 !== 0) {
457
- const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
458
- a = Math.round(a * multiplier);
459
- b = Math.round(b * multiplier);
460
- result = op === "+" ? a + b : a - b;
461
- result /= multiplier;
462
- }
463
- return result;
464
- }
465
-
466
- // ../../utilities/number/src/transform.ts
467
- var transform = (a, b) => {
468
- const i = { min: a[0], max: a[1] };
469
- const o = { min: b[0], max: b[1] };
470
- return (v) => {
471
- if (i.min === i.max || o.min === o.max)
472
- return o.min;
473
- const ratio = (o.max - o.min) / (i.max - i.min);
474
- return o.min + ratio * (v - i.min);
475
- };
476
- };
400
+ // src/slider.connect.ts
401
+ var import_numeric_range3 = require("@zag-js/numeric-range");
477
402
 
478
403
  // ../../utilities/form-utils/src/input-event.ts
479
404
  function getDescriptor(el, options) {
@@ -537,46 +462,57 @@ function trackFormControl(el, options) {
537
462
  };
538
463
  }
539
464
 
465
+ // src/slider.dom.ts
466
+ var import_numeric_range2 = require("@zag-js/numeric-range");
467
+
540
468
  // src/slider.style.ts
469
+ var import_numeric_range = require("@zag-js/numeric-range");
541
470
  function getVerticalThumbOffset(ctx) {
542
471
  var _a;
543
472
  const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
544
- const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
473
+ const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-height / 2, height / 2]);
545
474
  return parseFloat(getValue(ctx.value).toFixed(2));
546
475
  }
547
476
  function getHorizontalThumbOffset(ctx) {
548
477
  var _a;
549
478
  const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
550
479
  if (ctx.isRtl) {
551
- const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
480
+ const getValue2 = (0, import_numeric_range.getValueTransformer)([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
552
481
  return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
553
482
  }
554
- const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
483
+ const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-width / 2, width / 2]);
555
484
  return parseFloat(getValue(ctx.value).toFixed(2));
556
485
  }
557
486
  function getThumbOffset(ctx) {
558
- const percent = valueToPercent(ctx.value, ctx);
559
- if (ctx.thumbAlignment === "center")
487
+ const percent = (0, import_numeric_range.getValuePercent)(ctx.value, ctx.min, ctx.max) * 100;
488
+ if (ctx.thumbAlignment === "center") {
560
489
  return `${percent}%`;
490
+ }
561
491
  const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
562
492
  return `calc(${percent}% - ${offset}px)`;
563
493
  }
494
+ function getVisibility(ctx) {
495
+ let visibility = "visible";
496
+ if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
497
+ visibility = "hidden";
498
+ }
499
+ return visibility;
500
+ }
564
501
  function getThumbStyle(ctx) {
565
502
  const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
566
503
  return {
567
- visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
504
+ visibility: getVisibility(ctx),
568
505
  position: "absolute",
569
506
  transform: "var(--slider-thumb-transform)",
570
507
  [placementProp]: "var(--slider-thumb-offset)"
571
508
  };
572
509
  }
573
510
  function getRangeOffsets(ctx) {
574
- const percent = valueToPercent(ctx.value, ctx);
575
511
  let start = "0%";
576
- let end = `${100 - percent}%`;
512
+ let end = `${100 - ctx.valuePercent}%`;
577
513
  if (ctx.origin === "center") {
578
- const isNegative = percent < 50;
579
- start = isNegative ? `${percent}%` : "50%";
514
+ const isNegative = ctx.valuePercent < 50;
515
+ start = isNegative ? `${ctx.valuePercent}%` : "50%";
580
516
  end = isNegative ? "50%" : end;
581
517
  }
582
518
  return { start, end };
@@ -615,7 +551,7 @@ function getMarkerStyle(ctx, percent) {
615
551
  return {
616
552
  position: "absolute",
617
553
  pointerEvents: "none",
618
- [ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
554
+ [ctx.isHorizontal ? "left" : "bottom"]: `${(ctx.isRtl ? 1 - percent : percent) * 100}%`
619
555
  };
620
556
  }
621
557
  function getLabelStyle() {
@@ -643,28 +579,6 @@ var styles = {
643
579
  getMarkerGroupStyle
644
580
  };
645
581
 
646
- // src/slider.utils.ts
647
- var utils = {
648
- fromPercent(ctx, percent) {
649
- percent = clamp(percent, { min: 0, max: 1 });
650
- return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
651
- },
652
- clamp(ctx, value) {
653
- return clamp(value, ctx);
654
- },
655
- convert(ctx, value) {
656
- return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
657
- },
658
- decrement(ctx, step) {
659
- let value = decrement(ctx.value, step != null ? step : ctx.step);
660
- return utils.convert(ctx, value);
661
- },
662
- increment(ctx, step) {
663
- let value = increment(ctx.value, step != null ? step : ctx.step);
664
- return utils.convert(ctx, value);
665
- }
666
- };
667
-
668
582
  // src/slider.dom.ts
669
583
  var dom = defineDomHelpers({
670
584
  ...styles,
@@ -715,7 +629,7 @@ var dom = defineDomHelpers({
715
629
  } else {
716
630
  percent = 1 - percentY;
717
631
  }
718
- return utils.fromPercent(ctx, percent);
632
+ return (0, import_numeric_range2.getPercentValue)(percent, ctx.min, ctx.max, ctx.step);
719
633
  },
720
634
  dispatchChangeEvent(ctx) {
721
635
  const input = dom.getHiddenInputEl(ctx);
@@ -740,12 +654,15 @@ function connect(state2, send, normalize) {
740
654
  isFocused,
741
655
  isDragging,
742
656
  value: state2.context.value,
743
- percent: valueToPercent(state2.context.value, state2.context),
657
+ percent: (0, import_numeric_range3.getValuePercent)(state2.context.value, state2.context.min, state2.context.max),
744
658
  setValue(value) {
745
659
  send({ type: "SET_VALUE", value });
746
660
  },
747
661
  getPercentValue(percent) {
748
- return percentToValue(percent, state2.context);
662
+ return (0, import_numeric_range3.getPercentValue)(percent, state2.context.min, state2.context.max, state2.context.step);
663
+ },
664
+ getValuePercent(value) {
665
+ return (0, import_numeric_range3.getValuePercent)(value, state2.context.min, state2.context.max);
749
666
  },
750
667
  focus() {
751
668
  var _a2;
@@ -921,7 +838,7 @@ function connect(state2, send, normalize) {
921
838
  style: dom.getMarkerGroupStyle()
922
839
  }),
923
840
  getMarkerProps({ value }) {
924
- const percent = valueToPercent(value, state2.context);
841
+ const percent = this.getValuePercent(value);
925
842
  const style = dom.getMarkerStyle(state2.context, percent);
926
843
  const markerState = value > state2.context.value ? "over-value" : value < state2.context.value ? "under-value" : "at-value";
927
844
  return normalize.element({
@@ -941,6 +858,34 @@ function connect(state2, send, normalize) {
941
858
  // src/slider.machine.ts
942
859
  var import_core = require("@zag-js/core");
943
860
  var import_element_size = require("@zag-js/element-size");
861
+ var import_numeric_range5 = require("@zag-js/numeric-range");
862
+
863
+ // src/slider.utils.ts
864
+ var import_numeric_range4 = require("@zag-js/numeric-range");
865
+ function constrainValue(ctx, value) {
866
+ const snapValue = (0, import_numeric_range4.snapValueToStep)(value, ctx.min, ctx.max, ctx.step);
867
+ return (0, import_numeric_range4.clampValue)(snapValue, ctx.min, ctx.max);
868
+ }
869
+ function decrement(ctx, step) {
870
+ const index = 0;
871
+ const values = (0, import_numeric_range4.getPreviousStepValue)(index, {
872
+ ...ctx,
873
+ step: step != null ? step : ctx.step,
874
+ values: [ctx.value]
875
+ });
876
+ return values[index];
877
+ }
878
+ function increment(ctx, step) {
879
+ const index = 0;
880
+ const values = (0, import_numeric_range4.getNextStepValue)(index, {
881
+ ...ctx,
882
+ step: step != null ? step : ctx.step,
883
+ values: [ctx.value]
884
+ });
885
+ return values[index];
886
+ }
887
+
888
+ // src/slider.machine.ts
944
889
  function machine(userContext) {
945
890
  const ctx = compact(userContext);
946
891
  return (0, import_core.createMachine)(
@@ -967,7 +912,8 @@ function machine(userContext) {
967
912
  isVertical: (ctx2) => ctx2.orientation === "vertical",
968
913
  isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
969
914
  isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly),
970
- hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
915
+ hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null,
916
+ valuePercent: (ctx2) => 100 * (0, import_numeric_range5.getValuePercent)(ctx2.value, ctx2.min, ctx2.max)
971
917
  },
972
918
  watch: {
973
919
  value: ["invokeOnChange", "dispatchChangeEvent"]
@@ -1094,7 +1040,7 @@ function machine(userContext) {
1094
1040
  },
1095
1041
  actions: {
1096
1042
  checkValue(ctx2) {
1097
- const value = utils.convert(ctx2, ctx2.value);
1043
+ const value = constrainValue(ctx2, ctx2.value);
1098
1044
  ctx2.value = value;
1099
1045
  ctx2.initialValue = value;
1100
1046
  },
@@ -1117,7 +1063,7 @@ function machine(userContext) {
1117
1063
  const value = dom.getValueFromPoint(ctx2, evt.point);
1118
1064
  if (value == null)
1119
1065
  return;
1120
- ctx2.value = utils.clamp(ctx2, value);
1066
+ ctx2.value = (0, import_numeric_range5.clampValue)(value, ctx2.min, ctx2.max);
1121
1067
  },
1122
1068
  focusThumb(ctx2) {
1123
1069
  raf(() => {
@@ -1126,10 +1072,10 @@ function machine(userContext) {
1126
1072
  });
1127
1073
  },
1128
1074
  decrement(ctx2, evt) {
1129
- ctx2.value = utils.decrement(ctx2, evt.step);
1075
+ ctx2.value = decrement(ctx2, evt.step);
1130
1076
  },
1131
1077
  increment(ctx2, evt) {
1132
- ctx2.value = utils.increment(ctx2, evt.step);
1078
+ ctx2.value = increment(ctx2, evt.step);
1133
1079
  },
1134
1080
  setToMin(ctx2) {
1135
1081
  ctx2.value = ctx2.min;
@@ -1138,7 +1084,7 @@ function machine(userContext) {
1138
1084
  ctx2.value = ctx2.max;
1139
1085
  },
1140
1086
  setValue(ctx2, evt) {
1141
- ctx2.value = utils.convert(ctx2, evt.value);
1087
+ ctx2.value = constrainValue(ctx2, evt.value);
1142
1088
  }
1143
1089
  }
1144
1090
  }
package/dist/index.mjs CHANGED
@@ -1,19 +1,18 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-YCRSV2RE.mjs";
3
+ } from "./chunk-6D4ETNPG.mjs";
4
4
  import {
5
5
  anatomy
6
6
  } from "./chunk-3Y7IIPR5.mjs";
7
7
  import {
8
8
  machine
9
- } from "./chunk-3JMGYHB3.mjs";
9
+ } from "./chunk-A2ZK6G4F.mjs";
10
10
  import "./chunk-SGCWELVB.mjs";
11
11
  import {
12
12
  dom
13
- } from "./chunk-MR2MUD77.mjs";
14
- import "./chunk-MXJ3RGFD.mjs";
15
- import "./chunk-FUTBDWTA.mjs";
16
- import "./chunk-GBYBRQZL.mjs";
13
+ } from "./chunk-J5IGGBVE.mjs";
14
+ import "./chunk-YREEXXZP.mjs";
15
+ import "./chunk-DRAPR6JV.mjs";
17
16
  export {
18
17
  anatomy,
19
18
  connect,
@@ -9,6 +9,7 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
9
9
  percent: number;
10
10
  setValue(value: number): void;
11
11
  getPercentValue(percent: number): number;
12
+ getValuePercent(value: number): number;
12
13
  focus(): void;
13
14
  increment(): void;
14
15
  decrement(): void;