@zag-js/slider 0.2.3 → 0.2.4

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
@@ -20,12 +20,29 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ anatomy: () => anatomy,
23
24
  connect: () => connect,
24
25
  machine: () => machine,
25
26
  unstable__dom: () => dom
26
27
  });
27
28
  module.exports = __toCommonJS(src_exports);
28
29
 
30
+ // src/slider.anatomy.ts
31
+ var import_anatomy = require("@zag-js/anatomy");
32
+ var anatomy = (0, import_anatomy.createAnatomy)("slider").parts(
33
+ "root",
34
+ "label",
35
+ "thumb",
36
+ "input",
37
+ "output",
38
+ "track",
39
+ "range",
40
+ "control",
41
+ "markerGroup",
42
+ "marker"
43
+ );
44
+ var parts = anatomy.build();
45
+
29
46
  // ../../utilities/dom/dist/index.mjs
30
47
  var dataAttr = (guard) => {
31
48
  return guard ? "" : void 0;
@@ -342,6 +359,65 @@ function trackPointerMove(doc, opts) {
342
359
  );
343
360
  }
344
361
 
362
+ // ../../utilities/number/dist/index.mjs
363
+ function round(v, t) {
364
+ let num = valueOf(v);
365
+ const p = 10 ** (t != null ? t : 10);
366
+ num = Math.round(num * p) / p;
367
+ return t ? num.toFixed(t) : v.toString();
368
+ }
369
+ var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
370
+ var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
371
+ function clamp(v, o) {
372
+ return Math.min(Math.max(valueOf(v), o.min), o.max);
373
+ }
374
+ function countDecimals(value) {
375
+ if (!Number.isFinite(value))
376
+ return 0;
377
+ let e = 1, p = 0;
378
+ while (Math.round(value * e) / e !== value) {
379
+ e *= 10;
380
+ p += 1;
381
+ }
382
+ return p;
383
+ }
384
+ var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
385
+ var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
386
+ function snapToStep(value, step) {
387
+ const num = valueOf(value);
388
+ const p = countDecimals(step);
389
+ const v = Math.round(num / step) * step;
390
+ return round(v, p);
391
+ }
392
+ function valueOf(v) {
393
+ if (typeof v === "number")
394
+ return v;
395
+ const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
396
+ return !Number.isNaN(num) ? num : 0;
397
+ }
398
+ function decimalOperation(a, op, b) {
399
+ let result = op === "+" ? a + b : a - b;
400
+ if (a % 1 !== 0 || b % 1 !== 0) {
401
+ const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
402
+ a = Math.round(a * multiplier);
403
+ b = Math.round(b * multiplier);
404
+ result = op === "+" ? a + b : a - b;
405
+ result /= multiplier;
406
+ }
407
+ return result;
408
+ }
409
+ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
410
+ var transform = (a, b) => {
411
+ const i = { min: a[0], max: a[1] };
412
+ const o = { min: b[0], max: b[1] };
413
+ return (v) => {
414
+ if (i.min === i.max || o.min === o.max)
415
+ return o.min;
416
+ const ratio = (o.max - o.min) / (i.max - i.min);
417
+ return o.min + ratio * (v - i.min);
418
+ };
419
+ };
420
+
345
421
  // ../../utilities/form-utils/dist/index.mjs
346
422
  function getWindow(el) {
347
423
  var _a;
@@ -421,65 +497,6 @@ function trackFormControl(el, options) {
421
497
  };
422
498
  }
423
499
 
424
- // ../../utilities/number/dist/index.mjs
425
- function round(v, t) {
426
- let num = valueOf(v);
427
- const p = 10 ** (t != null ? t : 10);
428
- num = Math.round(num * p) / p;
429
- return t ? num.toFixed(t) : v.toString();
430
- }
431
- var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
432
- var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
433
- function clamp(v, o) {
434
- return Math.min(Math.max(valueOf(v), o.min), o.max);
435
- }
436
- function countDecimals(value) {
437
- if (!Number.isFinite(value))
438
- return 0;
439
- let e = 1, p = 0;
440
- while (Math.round(value * e) / e !== value) {
441
- e *= 10;
442
- p += 1;
443
- }
444
- return p;
445
- }
446
- var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
447
- var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
448
- function snapToStep(value, step) {
449
- const num = valueOf(value);
450
- const p = countDecimals(step);
451
- const v = Math.round(num / step) * step;
452
- return round(v, p);
453
- }
454
- function valueOf(v) {
455
- if (typeof v === "number")
456
- return v;
457
- const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
458
- return !Number.isNaN(num) ? num : 0;
459
- }
460
- function decimalOperation(a, op, b) {
461
- let result = op === "+" ? a + b : a - b;
462
- if (a % 1 !== 0 || b % 1 !== 0) {
463
- const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
464
- a = Math.round(a * multiplier);
465
- b = Math.round(b * multiplier);
466
- result = op === "+" ? a + b : a - b;
467
- result /= multiplier;
468
- }
469
- return result;
470
- }
471
- var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
472
- var transform = (a, b) => {
473
- const i = { min: a[0], max: a[1] };
474
- const o = { min: b[0], max: b[1] };
475
- return (v) => {
476
- if (i.min === i.max || o.min === o.max)
477
- return o.min;
478
- const ratio = (o.max - o.min) / (i.max - i.min);
479
- return o.min + ratio * (v - i.min);
480
- };
481
- };
482
-
483
500
  // src/slider.style.ts
484
501
  function getVerticalThumbOffset(ctx) {
485
502
  var _a;
@@ -701,7 +718,7 @@ function connect(state2, send, normalize) {
701
718
  send("DECREMENT");
702
719
  },
703
720
  rootProps: normalize.element({
704
- "data-part": "root",
721
+ ...parts.root.attrs,
705
722
  "data-disabled": dataAttr(isDisabled),
706
723
  "data-focus": dataAttr(isFocused),
707
724
  "data-orientation": state2.context.orientation,
@@ -711,7 +728,7 @@ function connect(state2, send, normalize) {
711
728
  style: dom.getRootStyle(state2.context)
712
729
  }),
713
730
  labelProps: normalize.label({
714
- "data-part": "label",
731
+ ...parts.label.attrs,
715
732
  "data-disabled": dataAttr(isDisabled),
716
733
  "data-invalid": dataAttr(isInvalid),
717
734
  "data-focus": dataAttr(isFocused),
@@ -727,7 +744,7 @@ function connect(state2, send, normalize) {
727
744
  style: dom.getLabelStyle()
728
745
  }),
729
746
  thumbProps: normalize.element({
730
- "data-part": "thumb",
747
+ ...parts.thumb.attrs,
731
748
  id: dom.getThumbId(state2.context),
732
749
  "data-disabled": dataAttr(isDisabled),
733
750
  "data-orientation": state2.context.orientation,
@@ -802,7 +819,7 @@ function connect(state2, send, normalize) {
802
819
  style: dom.getThumbStyle(state2.context)
803
820
  }),
804
821
  inputProps: normalize.input({
805
- "data-part": "input",
822
+ ...parts.input.attrs,
806
823
  type: "text",
807
824
  defaultValue: state2.context.value,
808
825
  name: state2.context.name,
@@ -811,7 +828,7 @@ function connect(state2, send, normalize) {
811
828
  hidden: true
812
829
  }),
813
830
  outputProps: normalize.output({
814
- "data-part": "output",
831
+ ...parts.output.attrs,
815
832
  "data-disabled": dataAttr(isDisabled),
816
833
  "data-invalid": dataAttr(isInvalid),
817
834
  id: dom.getOutputId(state2.context),
@@ -819,7 +836,7 @@ function connect(state2, send, normalize) {
819
836
  "aria-live": "off"
820
837
  }),
821
838
  trackProps: normalize.element({
822
- "data-part": "track",
839
+ ...parts.track.attrs,
823
840
  id: dom.getTrackId(state2.context),
824
841
  "data-disabled": dataAttr(isDisabled),
825
842
  "data-focus": dataAttr(isFocused),
@@ -828,7 +845,7 @@ function connect(state2, send, normalize) {
828
845
  style: dom.getTrackStyle()
829
846
  }),
830
847
  rangeProps: normalize.element({
831
- "data-part": "range",
848
+ ...parts.range.attrs,
832
849
  id: dom.getRangeId(state2.context),
833
850
  "data-focus": dataAttr(isFocused),
834
851
  "data-invalid": dataAttr(isInvalid),
@@ -837,7 +854,7 @@ function connect(state2, send, normalize) {
837
854
  style: dom.getRangeStyle(state2.context)
838
855
  }),
839
856
  controlProps: normalize.element({
840
- "data-part": "control",
857
+ ...parts.control.attrs,
841
858
  id: dom.getControlId(state2.context),
842
859
  "data-disabled": dataAttr(isDisabled),
843
860
  "data-invalid": dataAttr(isInvalid),
@@ -857,7 +874,7 @@ function connect(state2, send, normalize) {
857
874
  style: dom.getControlStyle()
858
875
  }),
859
876
  markerGroupProps: normalize.element({
860
- "data-part": "marker-group",
877
+ ...parts.markerGroup.attrs,
861
878
  role: "presentation",
862
879
  "aria-hidden": true,
863
880
  "data-orientation": state2.context.orientation,
@@ -868,7 +885,7 @@ function connect(state2, send, normalize) {
868
885
  const style = dom.getMarkerStyle(state2.context, percent);
869
886
  const markerState = value > state2.context.value ? "over-value" : value < state2.context.value ? "under-value" : "at-value";
870
887
  return normalize.element({
871
- "data-part": "marker",
888
+ ...parts.marker.attrs,
872
889
  role: "presentation",
873
890
  "data-orientation": state2.context.orientation,
874
891
  id: dom.getMarkerId(state2.context, value),
@@ -1102,6 +1119,7 @@ function machine(userContext) {
1102
1119
  }
1103
1120
  // Annotate the CommonJS export names for ESM import in node:
1104
1121
  0 && (module.exports = {
1122
+ anatomy,
1105
1123
  connect,
1106
1124
  machine,
1107
1125
  unstable__dom
package/dist/index.mjs CHANGED
@@ -1,3 +1,19 @@
1
+ // src/slider.anatomy.ts
2
+ import { createAnatomy } from "@zag-js/anatomy";
3
+ var anatomy = createAnatomy("slider").parts(
4
+ "root",
5
+ "label",
6
+ "thumb",
7
+ "input",
8
+ "output",
9
+ "track",
10
+ "range",
11
+ "control",
12
+ "markerGroup",
13
+ "marker"
14
+ );
15
+ var parts = anatomy.build();
16
+
1
17
  // ../../utilities/dom/dist/index.mjs
2
18
  var dataAttr = (guard) => {
3
19
  return guard ? "" : void 0;
@@ -314,6 +330,65 @@ function trackPointerMove(doc, opts) {
314
330
  );
315
331
  }
316
332
 
333
+ // ../../utilities/number/dist/index.mjs
334
+ function round(v, t) {
335
+ let num = valueOf(v);
336
+ const p = 10 ** (t != null ? t : 10);
337
+ num = Math.round(num * p) / p;
338
+ return t ? num.toFixed(t) : v.toString();
339
+ }
340
+ var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
341
+ var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
342
+ function clamp(v, o) {
343
+ return Math.min(Math.max(valueOf(v), o.min), o.max);
344
+ }
345
+ function countDecimals(value) {
346
+ if (!Number.isFinite(value))
347
+ return 0;
348
+ let e = 1, p = 0;
349
+ while (Math.round(value * e) / e !== value) {
350
+ e *= 10;
351
+ p += 1;
352
+ }
353
+ return p;
354
+ }
355
+ var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
356
+ var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
357
+ function snapToStep(value, step) {
358
+ const num = valueOf(value);
359
+ const p = countDecimals(step);
360
+ const v = Math.round(num / step) * step;
361
+ return round(v, p);
362
+ }
363
+ function valueOf(v) {
364
+ if (typeof v === "number")
365
+ return v;
366
+ const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
367
+ return !Number.isNaN(num) ? num : 0;
368
+ }
369
+ function decimalOperation(a, op, b) {
370
+ let result = op === "+" ? a + b : a - b;
371
+ if (a % 1 !== 0 || b % 1 !== 0) {
372
+ const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
373
+ a = Math.round(a * multiplier);
374
+ b = Math.round(b * multiplier);
375
+ result = op === "+" ? a + b : a - b;
376
+ result /= multiplier;
377
+ }
378
+ return result;
379
+ }
380
+ var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
381
+ var transform = (a, b) => {
382
+ const i = { min: a[0], max: a[1] };
383
+ const o = { min: b[0], max: b[1] };
384
+ return (v) => {
385
+ if (i.min === i.max || o.min === o.max)
386
+ return o.min;
387
+ const ratio = (o.max - o.min) / (i.max - i.min);
388
+ return o.min + ratio * (v - i.min);
389
+ };
390
+ };
391
+
317
392
  // ../../utilities/form-utils/dist/index.mjs
318
393
  function getWindow(el) {
319
394
  var _a;
@@ -393,65 +468,6 @@ function trackFormControl(el, options) {
393
468
  };
394
469
  }
395
470
 
396
- // ../../utilities/number/dist/index.mjs
397
- function round(v, t) {
398
- let num = valueOf(v);
399
- const p = 10 ** (t != null ? t : 10);
400
- num = Math.round(num * p) / p;
401
- return t ? num.toFixed(t) : v.toString();
402
- }
403
- var valueToPercent = (v, r) => (valueOf(v) - r.min) * 100 / (r.max - r.min);
404
- var percentToValue = (v, r) => r.min + (r.max - r.min) * valueOf(v);
405
- function clamp(v, o) {
406
- return Math.min(Math.max(valueOf(v), o.min), o.max);
407
- }
408
- function countDecimals(value) {
409
- if (!Number.isFinite(value))
410
- return 0;
411
- let e = 1, p = 0;
412
- while (Math.round(value * e) / e !== value) {
413
- e *= 10;
414
- p += 1;
415
- }
416
- return p;
417
- }
418
- var increment = (v, s) => decimalOperation(valueOf(v), "+", s);
419
- var decrement = (v, s) => decimalOperation(valueOf(v), "-", s);
420
- function snapToStep(value, step) {
421
- const num = valueOf(value);
422
- const p = countDecimals(step);
423
- const v = Math.round(num / step) * step;
424
- return round(v, p);
425
- }
426
- function valueOf(v) {
427
- if (typeof v === "number")
428
- return v;
429
- const num = parseFloat(v.toString().replace(/[^\w.-]+/g, ""));
430
- return !Number.isNaN(num) ? num : 0;
431
- }
432
- function decimalOperation(a, op, b) {
433
- let result = op === "+" ? a + b : a - b;
434
- if (a % 1 !== 0 || b % 1 !== 0) {
435
- const multiplier = 10 ** Math.max(countDecimals(a), countDecimals(b));
436
- a = Math.round(a * multiplier);
437
- b = Math.round(b * multiplier);
438
- result = op === "+" ? a + b : a - b;
439
- result /= multiplier;
440
- }
441
- return result;
442
- }
443
- var nf = new Intl.NumberFormat("en-US", { style: "decimal", maximumFractionDigits: 20 });
444
- var transform = (a, b) => {
445
- const i = { min: a[0], max: a[1] };
446
- const o = { min: b[0], max: b[1] };
447
- return (v) => {
448
- if (i.min === i.max || o.min === o.max)
449
- return o.min;
450
- const ratio = (o.max - o.min) / (i.max - i.min);
451
- return o.min + ratio * (v - i.min);
452
- };
453
- };
454
-
455
471
  // src/slider.style.ts
456
472
  function getVerticalThumbOffset(ctx) {
457
473
  var _a;
@@ -673,7 +689,7 @@ function connect(state2, send, normalize) {
673
689
  send("DECREMENT");
674
690
  },
675
691
  rootProps: normalize.element({
676
- "data-part": "root",
692
+ ...parts.root.attrs,
677
693
  "data-disabled": dataAttr(isDisabled),
678
694
  "data-focus": dataAttr(isFocused),
679
695
  "data-orientation": state2.context.orientation,
@@ -683,7 +699,7 @@ function connect(state2, send, normalize) {
683
699
  style: dom.getRootStyle(state2.context)
684
700
  }),
685
701
  labelProps: normalize.label({
686
- "data-part": "label",
702
+ ...parts.label.attrs,
687
703
  "data-disabled": dataAttr(isDisabled),
688
704
  "data-invalid": dataAttr(isInvalid),
689
705
  "data-focus": dataAttr(isFocused),
@@ -699,7 +715,7 @@ function connect(state2, send, normalize) {
699
715
  style: dom.getLabelStyle()
700
716
  }),
701
717
  thumbProps: normalize.element({
702
- "data-part": "thumb",
718
+ ...parts.thumb.attrs,
703
719
  id: dom.getThumbId(state2.context),
704
720
  "data-disabled": dataAttr(isDisabled),
705
721
  "data-orientation": state2.context.orientation,
@@ -774,7 +790,7 @@ function connect(state2, send, normalize) {
774
790
  style: dom.getThumbStyle(state2.context)
775
791
  }),
776
792
  inputProps: normalize.input({
777
- "data-part": "input",
793
+ ...parts.input.attrs,
778
794
  type: "text",
779
795
  defaultValue: state2.context.value,
780
796
  name: state2.context.name,
@@ -783,7 +799,7 @@ function connect(state2, send, normalize) {
783
799
  hidden: true
784
800
  }),
785
801
  outputProps: normalize.output({
786
- "data-part": "output",
802
+ ...parts.output.attrs,
787
803
  "data-disabled": dataAttr(isDisabled),
788
804
  "data-invalid": dataAttr(isInvalid),
789
805
  id: dom.getOutputId(state2.context),
@@ -791,7 +807,7 @@ function connect(state2, send, normalize) {
791
807
  "aria-live": "off"
792
808
  }),
793
809
  trackProps: normalize.element({
794
- "data-part": "track",
810
+ ...parts.track.attrs,
795
811
  id: dom.getTrackId(state2.context),
796
812
  "data-disabled": dataAttr(isDisabled),
797
813
  "data-focus": dataAttr(isFocused),
@@ -800,7 +816,7 @@ function connect(state2, send, normalize) {
800
816
  style: dom.getTrackStyle()
801
817
  }),
802
818
  rangeProps: normalize.element({
803
- "data-part": "range",
819
+ ...parts.range.attrs,
804
820
  id: dom.getRangeId(state2.context),
805
821
  "data-focus": dataAttr(isFocused),
806
822
  "data-invalid": dataAttr(isInvalid),
@@ -809,7 +825,7 @@ function connect(state2, send, normalize) {
809
825
  style: dom.getRangeStyle(state2.context)
810
826
  }),
811
827
  controlProps: normalize.element({
812
- "data-part": "control",
828
+ ...parts.control.attrs,
813
829
  id: dom.getControlId(state2.context),
814
830
  "data-disabled": dataAttr(isDisabled),
815
831
  "data-invalid": dataAttr(isInvalid),
@@ -829,7 +845,7 @@ function connect(state2, send, normalize) {
829
845
  style: dom.getControlStyle()
830
846
  }),
831
847
  markerGroupProps: normalize.element({
832
- "data-part": "marker-group",
848
+ ...parts.markerGroup.attrs,
833
849
  role: "presentation",
834
850
  "aria-hidden": true,
835
851
  "data-orientation": state2.context.orientation,
@@ -840,7 +856,7 @@ function connect(state2, send, normalize) {
840
856
  const style = dom.getMarkerStyle(state2.context, percent);
841
857
  const markerState = value > state2.context.value ? "over-value" : value < state2.context.value ? "under-value" : "at-value";
842
858
  return normalize.element({
843
- "data-part": "marker",
859
+ ...parts.marker.attrs,
844
860
  role: "presentation",
845
861
  "data-orientation": state2.context.orientation,
846
862
  id: dom.getMarkerId(state2.context, value),
@@ -1073,6 +1089,7 @@ function machine(userContext) {
1073
1089
  );
1074
1090
  }
1075
1091
  export {
1092
+ anatomy,
1076
1093
  connect,
1077
1094
  machine,
1078
1095
  dom as unstable__dom
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/slider",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Core logic for the slider widget implemented as a state machine",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -29,6 +29,7 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
+ "@zag-js/anatomy": "0.1.1",
32
33
  "@zag-js/core": "0.2.2",
33
34
  "@zag-js/element-size": "0.3.0",
34
35
  "@zag-js/types": "0.3.1"
@@ -37,7 +38,7 @@
37
38
  "@zag-js/dom-utils": "0.2.1",
38
39
  "@zag-js/form-utils": "0.2.2",
39
40
  "@zag-js/utils": "0.3.1",
40
- "@zag-js/number-utils": "0.2.0"
41
+ "@zag-js/number-utils": "0.2.1"
41
42
  },
42
43
  "scripts": {
43
44
  "build-fast": "tsup src/index.ts --format=esm,cjs",