@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.
@@ -94,25 +94,7 @@ function defineDomHelpers(helpers) {
94
94
  return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
95
95
  },
96
96
  getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
97
- getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
98
- createEmitter: (ctx, target) => {
99
- const win = dom2.getWin(ctx);
100
- return function emit(evt, detail, options) {
101
- const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
102
- const eventName = `zag:${evt}`;
103
- const init = { bubbles, cancelable, composed, detail };
104
- const event = new win.CustomEvent(eventName, init);
105
- target.dispatchEvent(event);
106
- };
107
- },
108
- createListener: (target) => {
109
- return function listen(evt, handler) {
110
- const eventName = `zag:${evt}`;
111
- const listener = (e) => handler(e);
112
- target.addEventListener(eventName, listener);
113
- return () => target.removeEventListener(eventName, listener);
114
- };
115
- }
97
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
116
98
  };
117
99
  return {
118
100
  ...dom2,
@@ -337,6 +319,9 @@ function trackPointerMove(doc, opts) {
337
319
  );
338
320
  }
339
321
 
322
+ // src/slider.machine.ts
323
+ var import_element_size = require("@zag-js/element-size");
324
+
340
325
  // ../../utilities/form-utils/src/input-event.ts
341
326
  function getDescriptor(el, options) {
342
327
  var _a;
@@ -400,108 +385,59 @@ function trackFormControl(el, options) {
400
385
  }
401
386
 
402
387
  // src/slider.machine.ts
403
- var import_element_size = require("@zag-js/element-size");
388
+ var import_numeric_range4 = require("@zag-js/numeric-range");
404
389
 
405
- // ../../utilities/number/src/number.ts
406
- function round(v, t) {
407
- let num = valueOf(v);
408
- const p = 10 ** (t != null ? t : 10);
409
- num = Math.round(num * p) / p;
410
- return t ? num.toFixed(t) : v.toString();
411
- }
412
- var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
413
- var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
414
- function clamp(v, o) {
415
- return Math.min(Math.max(valueOf(v), o.min), o.max);
416
- }
417
- function countDecimals(value) {
418
- if (!Number.isFinite(value))
419
- return 0;
420
- let e = 1, p = 0;
421
- while (Math.round(value * e) / e !== value) {
422
- e *= 10;
423
- p += 1;
424
- }
425
- return p;
426
- }
427
- var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
428
- var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
429
- function snapToStep(value, step) {
430
- const num = valueOf(value);
431
- const p = countDecimals(step);
432
- const v = Math.round(num / step) * step;
433
- return round(v, p);
434
- }
435
- function valueOf(v) {
436
- if (typeof v === "number")
437
- return v;
438
- const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
439
- return !Number.isNaN(num) ? num : 0;
440
- }
441
- function decimalOperation(a, op, b) {
442
- let result = op === "+" ? a + b : a - b;
443
- if (a % 1 !== 0 || b % 1 !== 0) {
444
- const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
445
- a = Math.round(a * multiplier);
446
- b = Math.round(b * multiplier);
447
- result = op === "+" ? a + b : a - b;
448
- result /= multiplier;
449
- }
450
- return result;
451
- }
452
-
453
- // ../../utilities/number/src/transform.ts
454
- var transform = (a, b) => {
455
- const i = { min: a[0], max: a[1] };
456
- const o = { min: b[0], max: b[1] };
457
- return (v) => {
458
- if (i.min === i.max || o.min === o.max)
459
- return o.min;
460
- const ratio = (o.max - o.min) / (i.max - i.min);
461
- return o.min + ratio * (v - i.min);
462
- };
463
- };
390
+ // src/slider.dom.ts
391
+ var import_numeric_range2 = require("@zag-js/numeric-range");
464
392
 
465
393
  // src/slider.style.ts
394
+ var import_numeric_range = require("@zag-js/numeric-range");
466
395
  function getVerticalThumbOffset(ctx) {
467
396
  var _a;
468
397
  const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
469
- const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
398
+ const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-height / 2, height / 2]);
470
399
  return parseFloat(getValue(ctx.value).toFixed(2));
471
400
  }
472
401
  function getHorizontalThumbOffset(ctx) {
473
402
  var _a;
474
403
  const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
475
404
  if (ctx.isRtl) {
476
- const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
405
+ const getValue2 = (0, import_numeric_range.getValueTransformer)([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
477
406
  return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
478
407
  }
479
- const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
408
+ const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-width / 2, width / 2]);
480
409
  return parseFloat(getValue(ctx.value).toFixed(2));
481
410
  }
482
411
  function getThumbOffset(ctx) {
483
- const percent = valueToPercent(ctx.value, ctx);
484
- if (ctx.thumbAlignment === "center")
412
+ const percent = (0, import_numeric_range.getValuePercent)(ctx.value, ctx.min, ctx.max) * 100;
413
+ if (ctx.thumbAlignment === "center") {
485
414
  return `${percent}%`;
415
+ }
486
416
  const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
487
417
  return `calc(${percent}% - ${offset}px)`;
488
418
  }
419
+ function getVisibility(ctx) {
420
+ let visibility = "visible";
421
+ if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
422
+ visibility = "hidden";
423
+ }
424
+ return visibility;
425
+ }
489
426
  function getThumbStyle(ctx) {
490
427
  const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
491
428
  return {
492
- visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
429
+ visibility: getVisibility(ctx),
493
430
  position: "absolute",
494
431
  transform: "var(--slider-thumb-transform)",
495
432
  [placementProp]: "var(--slider-thumb-offset)"
496
433
  };
497
434
  }
498
435
  function getRangeOffsets(ctx) {
499
- const percent = valueToPercent(ctx.value, ctx);
500
436
  let start = "0%";
501
- let end = `${100 - percent}%`;
437
+ let end = `${100 - ctx.valuePercent}%`;
502
438
  if (ctx.origin === "center") {
503
- const isNegative = percent < 50;
504
- start = isNegative ? `${percent}%` : "50%";
439
+ const isNegative = ctx.valuePercent < 50;
440
+ start = isNegative ? `${ctx.valuePercent}%` : "50%";
505
441
  end = isNegative ? "50%" : end;
506
442
  }
507
443
  return { start, end };
@@ -540,7 +476,7 @@ function getMarkerStyle(ctx, percent) {
540
476
  return {
541
477
  position: "absolute",
542
478
  pointerEvents: "none",
543
- [ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
479
+ [ctx.isHorizontal ? "left" : "bottom"]: `${(ctx.isRtl ? 1 - percent : percent) * 100}%`
544
480
  };
545
481
  }
546
482
  function getLabelStyle() {
@@ -568,28 +504,6 @@ var styles = {
568
504
  getMarkerGroupStyle
569
505
  };
570
506
 
571
- // src/slider.utils.ts
572
- var utils = {
573
- fromPercent(ctx, percent) {
574
- percent = clamp(percent, { min: 0, max: 1 });
575
- return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
576
- },
577
- clamp(ctx, value) {
578
- return clamp(value, ctx);
579
- },
580
- convert(ctx, value) {
581
- return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
582
- },
583
- decrement(ctx, step) {
584
- let value = decrement(ctx.value, step != null ? step : ctx.step);
585
- return utils.convert(ctx, value);
586
- },
587
- increment(ctx, step) {
588
- let value = increment(ctx.value, step != null ? step : ctx.step);
589
- return utils.convert(ctx, value);
590
- }
591
- };
592
-
593
507
  // src/slider.dom.ts
594
508
  var dom = defineDomHelpers({
595
509
  ...styles,
@@ -640,7 +554,7 @@ var dom = defineDomHelpers({
640
554
  } else {
641
555
  percent = 1 - percentY;
642
556
  }
643
- return utils.fromPercent(ctx, percent);
557
+ return (0, import_numeric_range2.getPercentValue)(percent, ctx.min, ctx.max, ctx.step);
644
558
  },
645
559
  dispatchChangeEvent(ctx) {
646
560
  const input = dom.getHiddenInputEl(ctx);
@@ -650,6 +564,31 @@ var dom = defineDomHelpers({
650
564
  }
651
565
  });
652
566
 
567
+ // src/slider.utils.ts
568
+ var import_numeric_range3 = require("@zag-js/numeric-range");
569
+ function constrainValue(ctx, value) {
570
+ const snapValue = (0, import_numeric_range3.snapValueToStep)(value, ctx.min, ctx.max, ctx.step);
571
+ return (0, import_numeric_range3.clampValue)(snapValue, ctx.min, ctx.max);
572
+ }
573
+ function decrement(ctx, step) {
574
+ const index = 0;
575
+ const values = (0, import_numeric_range3.getPreviousStepValue)(index, {
576
+ ...ctx,
577
+ step: step != null ? step : ctx.step,
578
+ values: [ctx.value]
579
+ });
580
+ return values[index];
581
+ }
582
+ function increment(ctx, step) {
583
+ const index = 0;
584
+ const values = (0, import_numeric_range3.getNextStepValue)(index, {
585
+ ...ctx,
586
+ step: step != null ? step : ctx.step,
587
+ values: [ctx.value]
588
+ });
589
+ return values[index];
590
+ }
591
+
653
592
  // src/slider.machine.ts
654
593
  function machine(userContext) {
655
594
  const ctx = compact(userContext);
@@ -677,7 +616,8 @@ function machine(userContext) {
677
616
  isVertical: (ctx2) => ctx2.orientation === "vertical",
678
617
  isRtl: (ctx2) => ctx2.orientation === "horizontal" && ctx2.dir === "rtl",
679
618
  isInteractive: (ctx2) => !(ctx2.disabled || ctx2.readOnly),
680
- hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null
619
+ hasMeasuredThumbSize: (ctx2) => ctx2.thumbSize !== null,
620
+ valuePercent: (ctx2) => 100 * (0, import_numeric_range4.getValuePercent)(ctx2.value, ctx2.min, ctx2.max)
681
621
  },
682
622
  watch: {
683
623
  value: ["invokeOnChange", "dispatchChangeEvent"]
@@ -804,7 +744,7 @@ function machine(userContext) {
804
744
  },
805
745
  actions: {
806
746
  checkValue(ctx2) {
807
- const value = utils.convert(ctx2, ctx2.value);
747
+ const value = constrainValue(ctx2, ctx2.value);
808
748
  ctx2.value = value;
809
749
  ctx2.initialValue = value;
810
750
  },
@@ -827,7 +767,7 @@ function machine(userContext) {
827
767
  const value = dom.getValueFromPoint(ctx2, evt.point);
828
768
  if (value == null)
829
769
  return;
830
- ctx2.value = utils.clamp(ctx2, value);
770
+ ctx2.value = (0, import_numeric_range4.clampValue)(value, ctx2.min, ctx2.max);
831
771
  },
832
772
  focusThumb(ctx2) {
833
773
  raf(() => {
@@ -836,10 +776,10 @@ function machine(userContext) {
836
776
  });
837
777
  },
838
778
  decrement(ctx2, evt) {
839
- ctx2.value = utils.decrement(ctx2, evt.step);
779
+ ctx2.value = decrement(ctx2, evt.step);
840
780
  },
841
781
  increment(ctx2, evt) {
842
- ctx2.value = utils.increment(ctx2, evt.step);
782
+ ctx2.value = increment(ctx2, evt.step);
843
783
  },
844
784
  setToMin(ctx2) {
845
785
  ctx2.value = ctx2.min;
@@ -848,7 +788,7 @@ function machine(userContext) {
848
788
  ctx2.value = ctx2.max;
849
789
  },
850
790
  setValue(ctx2, evt) {
851
- ctx2.value = utils.convert(ctx2, evt.value);
791
+ ctx2.value = constrainValue(ctx2, evt.value);
852
792
  }
853
793
  }
854
794
  }
@@ -1,11 +1,10 @@
1
1
  import {
2
2
  machine
3
- } from "./chunk-3JMGYHB3.mjs";
3
+ } from "./chunk-A2ZK6G4F.mjs";
4
4
  import "./chunk-SGCWELVB.mjs";
5
- import "./chunk-MR2MUD77.mjs";
6
- import "./chunk-MXJ3RGFD.mjs";
7
- import "./chunk-FUTBDWTA.mjs";
8
- import "./chunk-GBYBRQZL.mjs";
5
+ import "./chunk-J5IGGBVE.mjs";
6
+ import "./chunk-YREEXXZP.mjs";
7
+ import "./chunk-DRAPR6JV.mjs";
9
8
  export {
10
9
  machine
11
10
  };
@@ -23,68 +23,53 @@ __export(slider_style_exports, {
23
23
  styles: () => styles
24
24
  });
25
25
  module.exports = __toCommonJS(slider_style_exports);
26
-
27
- // ../../utilities/number/src/number.ts
28
- var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
29
- function valueOf(v) {
30
- if (typeof v === "number")
31
- return v;
32
- const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
33
- return !Number.isNaN(num) ? num : 0;
34
- }
35
-
36
- // ../../utilities/number/src/transform.ts
37
- var transform = (a, b) => {
38
- const i = { min: a[0], max: a[1] };
39
- const o = { min: b[0], max: b[1] };
40
- return (v) => {
41
- if (i.min === i.max || o.min === o.max)
42
- return o.min;
43
- const ratio = (o.max - o.min) / (i.max - i.min);
44
- return o.min + ratio * (v - i.min);
45
- };
46
- };
47
-
48
- // src/slider.style.ts
26
+ var import_numeric_range = require("@zag-js/numeric-range");
49
27
  function getVerticalThumbOffset(ctx) {
50
28
  var _a;
51
29
  const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
52
- const getValue = transform([ctx.min, ctx.max], [-height / 2, height / 2]);
30
+ const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-height / 2, height / 2]);
53
31
  return parseFloat(getValue(ctx.value).toFixed(2));
54
32
  }
55
33
  function getHorizontalThumbOffset(ctx) {
56
34
  var _a;
57
35
  const { width = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
58
36
  if (ctx.isRtl) {
59
- const getValue2 = transform([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
37
+ const getValue2 = (0, import_numeric_range.getValueTransformer)([ctx.max, ctx.min], [-width * 1.5, -width / 2]);
60
38
  return -1 * parseFloat(getValue2(ctx.value).toFixed(2));
61
39
  }
62
- const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
40
+ const getValue = (0, import_numeric_range.getValueTransformer)([ctx.min, ctx.max], [-width / 2, width / 2]);
63
41
  return parseFloat(getValue(ctx.value).toFixed(2));
64
42
  }
65
43
  function getThumbOffset(ctx) {
66
- const percent = valueToPercent(ctx.value, ctx);
67
- if (ctx.thumbAlignment === "center")
44
+ const percent = (0, import_numeric_range.getValuePercent)(ctx.value, ctx.min, ctx.max) * 100;
45
+ if (ctx.thumbAlignment === "center") {
68
46
  return `${percent}%`;
47
+ }
69
48
  const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
70
49
  return `calc(${percent}% - ${offset}px)`;
71
50
  }
51
+ function getVisibility(ctx) {
52
+ let visibility = "visible";
53
+ if (ctx.thumbAlignment === "contain" && !ctx.hasMeasuredThumbSize) {
54
+ visibility = "hidden";
55
+ }
56
+ return visibility;
57
+ }
72
58
  function getThumbStyle(ctx) {
73
59
  const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
74
60
  return {
75
- visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
61
+ visibility: getVisibility(ctx),
76
62
  position: "absolute",
77
63
  transform: "var(--slider-thumb-transform)",
78
64
  [placementProp]: "var(--slider-thumb-offset)"
79
65
  };
80
66
  }
81
67
  function getRangeOffsets(ctx) {
82
- const percent = valueToPercent(ctx.value, ctx);
83
68
  let start = "0%";
84
- let end = `${100 - percent}%`;
69
+ let end = `${100 - ctx.valuePercent}%`;
85
70
  if (ctx.origin === "center") {
86
- const isNegative = percent < 50;
87
- start = isNegative ? `${percent}%` : "50%";
71
+ const isNegative = ctx.valuePercent < 50;
72
+ start = isNegative ? `${ctx.valuePercent}%` : "50%";
88
73
  end = isNegative ? "50%" : end;
89
74
  }
90
75
  return { start, end };
@@ -123,7 +108,7 @@ function getMarkerStyle(ctx, percent) {
123
108
  return {
124
109
  position: "absolute",
125
110
  pointerEvents: "none",
126
- [ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
111
+ [ctx.isHorizontal ? "left" : "bottom"]: `${(ctx.isRtl ? 1 - percent : percent) * 100}%`
127
112
  };
128
113
  }
129
114
  function getLabelStyle() {
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  styles
3
- } from "./chunk-MXJ3RGFD.mjs";
4
- import "./chunk-GBYBRQZL.mjs";
3
+ } from "./chunk-YREEXXZP.mjs";
5
4
  export {
6
5
  styles
7
6
  };
@@ -128,6 +128,11 @@ type ComputedContext = Readonly<{
128
128
  * Whether the slider is in RTL mode
129
129
  */
130
130
  readonly isRtl: boolean;
131
+ /**
132
+ * @computed
133
+ * The value of the slider as a percentage
134
+ */
135
+ readonly valuePercent: number;
131
136
  }>;
132
137
  type PrivateContext = Context<{}>;
133
138
  type MachineContext = PublicContext & ComputedContext & PrivateContext;
@@ -2,12 +2,9 @@ import { MachineContext } from './slider.types.js';
2
2
  import '@zag-js/core';
3
3
  import '@zag-js/types';
4
4
 
5
- declare const utils: {
6
- fromPercent(ctx: MachineContext, percent: number): number;
7
- clamp(ctx: MachineContext, value: number): number;
8
- convert(ctx: MachineContext, value: number): number;
9
- decrement(ctx: MachineContext, step?: number): number;
10
- increment(ctx: MachineContext, step?: number): number;
11
- };
5
+ declare function clampPercent(percent: number): number;
6
+ declare function constrainValue(ctx: MachineContext, value: number): number;
7
+ declare function decrement(ctx: MachineContext, step?: number): number;
8
+ declare function increment(ctx: MachineContext, step?: number): number;
12
9
 
13
- export { utils };
10
+ export { clampPercent, constrainValue, decrement, increment };
@@ -20,79 +20,42 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/slider.utils.ts
21
21
  var slider_utils_exports = {};
22
22
  __export(slider_utils_exports, {
23
- utils: () => utils
23
+ clampPercent: () => clampPercent,
24
+ constrainValue: () => constrainValue,
25
+ decrement: () => decrement,
26
+ increment: () => increment
24
27
  });
25
28
  module.exports = __toCommonJS(slider_utils_exports);
26
-
27
- // ../../utilities/number/src/number.ts
28
- function round(v, t) {
29
- let num = valueOf(v);
30
- const p = 10 ** (t != null ? t : 10);
31
- num = Math.round(num * p) / p;
32
- return t ? num.toFixed(t) : v.toString();
33
- }
34
- var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
35
- function clamp(v, o) {
36
- return Math.min(Math.max(valueOf(v), o.min), o.max);
29
+ var import_numeric_range = require("@zag-js/numeric-range");
30
+ function clampPercent(percent) {
31
+ return (0, import_numeric_range.clampValue)(percent, 0, 1);
37
32
  }
38
- function countDecimals(value) {
39
- if (!Number.isFinite(value))
40
- return 0;
41
- let e = 1, p = 0;
42
- while (Math.round(value * e) / e !== value) {
43
- e *= 10;
44
- p += 1;
45
- }
46
- return p;
33
+ function constrainValue(ctx, value) {
34
+ const snapValue = (0, import_numeric_range.snapValueToStep)(value, ctx.min, ctx.max, ctx.step);
35
+ return (0, import_numeric_range.clampValue)(snapValue, ctx.min, ctx.max);
47
36
  }
48
- var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
49
- var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
50
- function snapToStep(value, step) {
51
- const num = valueOf(value);
52
- const p = countDecimals(step);
53
- const v = Math.round(num / step) * step;
54
- return round(v, p);
37
+ function decrement(ctx, step) {
38
+ const index = 0;
39
+ const values = (0, import_numeric_range.getPreviousStepValue)(index, {
40
+ ...ctx,
41
+ step: step != null ? step : ctx.step,
42
+ values: [ctx.value]
43
+ });
44
+ return values[index];
55
45
  }
56
- function valueOf(v) {
57
- if (typeof v === "number")
58
- return v;
59
- const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
60
- return !Number.isNaN(num) ? num : 0;
61
- }
62
- function decimalOperation(a, op, b) {
63
- let result = op === "+" ? a + b : a - b;
64
- if (a % 1 !== 0 || b % 1 !== 0) {
65
- const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
66
- a = Math.round(a * multiplier);
67
- b = Math.round(b * multiplier);
68
- result = op === "+" ? a + b : a - b;
69
- result /= multiplier;
70
- }
71
- return result;
46
+ function increment(ctx, step) {
47
+ const index = 0;
48
+ const values = (0, import_numeric_range.getNextStepValue)(index, {
49
+ ...ctx,
50
+ step: step != null ? step : ctx.step,
51
+ values: [ctx.value]
52
+ });
53
+ return values[index];
72
54
  }
73
-
74
- // src/slider.utils.ts
75
- var utils = {
76
- fromPercent(ctx, percent) {
77
- percent = clamp(percent, { min: 0, max: 1 });
78
- return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
79
- },
80
- clamp(ctx, value) {
81
- return clamp(value, ctx);
82
- },
83
- convert(ctx, value) {
84
- return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
85
- },
86
- decrement(ctx, step) {
87
- let value = decrement(ctx.value, step != null ? step : ctx.step);
88
- return utils.convert(ctx, value);
89
- },
90
- increment(ctx, step) {
91
- let value = increment(ctx.value, step != null ? step : ctx.step);
92
- return utils.convert(ctx, value);
93
- }
94
- };
95
55
  // Annotate the CommonJS export names for ESM import in node:
96
56
  0 && (module.exports = {
97
- utils
57
+ clampPercent,
58
+ constrainValue,
59
+ decrement,
60
+ increment
98
61
  });
@@ -1,7 +1,12 @@
1
1
  import {
2
- utils
3
- } from "./chunk-FUTBDWTA.mjs";
4
- import "./chunk-GBYBRQZL.mjs";
2
+ clampPercent,
3
+ constrainValue,
4
+ decrement,
5
+ increment
6
+ } from "./chunk-DRAPR6JV.mjs";
5
7
  export {
6
- utils
8
+ clampPercent,
9
+ constrainValue,
10
+ decrement,
11
+ increment
7
12
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/slider",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "Core logic for the slider widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -27,16 +27,16 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@zag-js/anatomy": "0.1.3",
30
- "@zag-js/core": "0.2.4",
30
+ "@zag-js/core": "0.2.5",
31
31
  "@zag-js/element-size": "0.3.1",
32
- "@zag-js/types": "0.3.2"
32
+ "@zag-js/numeric-range": "0.1.0",
33
+ "@zag-js/types": "0.3.3"
33
34
  },
34
35
  "devDependencies": {
35
36
  "clean-package": "2.2.0",
36
- "@zag-js/dom-utils": "0.2.2",
37
+ "@zag-js/dom-utils": "0.2.3",
37
38
  "@zag-js/form-utils": "0.2.3",
38
- "@zag-js/utils": "0.3.2",
39
- "@zag-js/number-utils": "0.2.2"
39
+ "@zag-js/utils": "0.3.2"
40
40
  },
41
41
  "clean-package": "../../../clean-package.config.json",
42
42
  "main": "dist/index.js",
@@ -1,33 +0,0 @@
1
- import {
2
- clamp,
3
- decrement,
4
- increment,
5
- percentToValue,
6
- snapToStep
7
- } from "./chunk-GBYBRQZL.mjs";
8
-
9
- // src/slider.utils.ts
10
- var utils = {
11
- fromPercent(ctx, percent) {
12
- percent = clamp(percent, { min: 0, max: 1 });
13
- return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
14
- },
15
- clamp(ctx, value) {
16
- return clamp(value, ctx);
17
- },
18
- convert(ctx, value) {
19
- return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
20
- },
21
- decrement(ctx, step) {
22
- let value = decrement(ctx.value, step != null ? step : ctx.step);
23
- return utils.convert(ctx, value);
24
- },
25
- increment(ctx, step) {
26
- let value = increment(ctx.value, step != null ? step : ctx.step);
27
- return utils.convert(ctx, value);
28
- }
29
- };
30
-
31
- export {
32
- utils
33
- };