@zag-js/slider 0.0.0-dev-20220605192656 → 0.0.0-dev-20220609054635

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
@@ -435,6 +435,27 @@ findByTypeahead.defaultOptions = {
435
435
  timer: -1
436
436
  };
437
437
 
438
+ // ../../utilities/rect/dist/index.mjs
439
+ var isDom2 = () => typeof window !== "undefined";
440
+ var isArray2 = (v) => Array.isArray(v);
441
+ var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
442
+ var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
443
+ var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
444
+ var isTouchEvent2 = (v) => isObject2(v) && hasProp2(v, "touches");
445
+ var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
446
+ function getEventPoint(e, t = "page") {
447
+ const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
448
+ return { x: p[`${t}X`], y: p[`${t}Y`] };
449
+ }
450
+ function relativeToNode(p, el) {
451
+ const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
452
+ const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
453
+ return {
454
+ point: { x: dx, y: dy },
455
+ progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
456
+ };
457
+ }
458
+
438
459
  // ../../utilities/number/dist/index.mjs
439
460
  var __pow2 = Math.pow;
440
461
  function round(v, t) {
@@ -495,50 +516,7 @@ var transform = (a, b) => {
495
516
  };
496
517
  };
497
518
 
498
- // ../../utilities/rect/dist/index.mjs
499
- var isDom2 = () => typeof window !== "undefined";
500
- var isArray2 = (v) => Array.isArray(v);
501
- var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
502
- var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
503
- var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
504
- var isTouchEvent2 = (v) => isObject2(v) && hasProp2(v, "touches");
505
- var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
506
- function getEventPoint(e, t = "page") {
507
- const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
508
- return { x: p[`${t}X`], y: p[`${t}Y`] };
509
- }
510
- function relativeToNode(p, el) {
511
- const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
512
- const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
513
- return {
514
- point: { x: dx, y: dy },
515
- progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
516
- };
517
- }
518
-
519
- // src/slider.utils.ts
520
- var utils = {
521
- fromPercent(ctx, percent) {
522
- percent = clamp(percent, { min: 0, max: 1 });
523
- return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
524
- },
525
- clamp(ctx, value) {
526
- return clamp(value, ctx);
527
- },
528
- convert(ctx, value) {
529
- return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
530
- },
531
- decrement(ctx, step) {
532
- let value = decrement(ctx.value, step != null ? step : ctx.step);
533
- return utils.convert(ctx, value);
534
- },
535
- increment(ctx, step) {
536
- let value = increment(ctx.value, step != null ? step : ctx.step);
537
- return utils.convert(ctx, value);
538
- }
539
- };
540
-
541
- // src/slider.dom.ts
519
+ // src/slider.style.ts
542
520
  function getVerticalThumbOffset(ctx) {
543
521
  var _a;
544
522
  const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
@@ -555,54 +533,117 @@ function getHorizontalThumbOffset(ctx) {
555
533
  const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
556
534
  return parseFloat(getValue(ctx.value).toFixed(2));
557
535
  }
558
- function getThumbStyle(ctx) {
536
+ function getThumbOffset(ctx) {
559
537
  const percent = valueToPercent(ctx.value, ctx);
560
538
  const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
561
- const style = {
539
+ return `calc(${percent}% - ${offset}px)`;
540
+ }
541
+ function getThumbStyle(ctx) {
542
+ const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
543
+ return {
562
544
  visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
563
545
  position: "absolute",
564
546
  transform: "var(--slider-thumb-transform)",
565
- "--slider-thumb-placement": `calc(${percent}% - ${offset}px)`
547
+ [placementProp]: "var(--slider-thumb-offset)"
566
548
  };
567
- if (ctx.isVertical) {
568
- style.bottom = "var(--slider-thumb-placement)";
569
- } else {
570
- style[ctx.isRtl ? "right" : "left"] = "var(--slider-thumb-placement)";
571
- }
572
- return style;
573
549
  }
574
- function getRangeStyle(ctx) {
550
+ function getRangeOffsets(ctx) {
575
551
  const percent = valueToPercent(ctx.value, ctx);
576
- const style = {
577
- position: "absolute"
578
- };
579
- let startValue = "0%";
580
- let endValue = `${100 - percent}%`;
552
+ let start = "0%";
553
+ let end = `${100 - percent}%`;
581
554
  if (ctx.origin === "center") {
582
555
  const isNegative = percent < 50;
583
- startValue = isNegative ? `${percent}%` : "50%";
584
- endValue = isNegative ? "50%" : endValue;
556
+ start = isNegative ? `${percent}%` : "50%";
557
+ end = isNegative ? "50%" : end;
585
558
  }
559
+ return { start, end };
560
+ }
561
+ function getRangeStyle(ctx) {
586
562
  if (ctx.isVertical) {
587
- return __spreadProps(__spreadValues({}, style), {
588
- bottom: startValue,
589
- top: endValue
590
- });
563
+ return {
564
+ position: "absolute",
565
+ bottom: "var(--slider-range-start)",
566
+ top: "var(--slider-range-end)"
567
+ };
591
568
  }
592
- return __spreadProps(__spreadValues({}, style), {
593
- [ctx.isRtl ? "right" : "left"]: startValue,
594
- [ctx.isRtl ? "left" : "right"]: endValue
595
- });
569
+ return {
570
+ position: "absolute",
571
+ [ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
572
+ [ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
573
+ };
596
574
  }
597
- function getControlStyle(ctx) {
575
+ function getControlStyle() {
598
576
  return {
599
577
  touchAction: "none",
600
578
  userSelect: "none",
579
+ position: "relative"
580
+ };
581
+ }
582
+ function getRootStyle(ctx) {
583
+ const range = getRangeOffsets(ctx);
584
+ return {
601
585
  "--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
586
+ "--slider-thumb-offset": getThumbOffset(ctx),
587
+ "--slider-range-start": range.start,
588
+ "--slider-range-end": range.end
589
+ };
590
+ }
591
+ function getMarkerStyle(ctx, percent) {
592
+ return {
593
+ position: "absolute",
594
+ pointerEvents: "none",
595
+ [ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
596
+ };
597
+ }
598
+ function getLabelStyle() {
599
+ return { userSelect: "none" };
600
+ }
601
+ function getTrackStyle() {
602
+ return { position: "relative" };
603
+ }
604
+ function getMarkerGroupStyle() {
605
+ return {
606
+ userSelect: "none",
607
+ pointerEvents: "none",
602
608
  position: "relative"
603
609
  };
604
610
  }
605
- var dom = {
611
+ var styles = {
612
+ getThumbOffset,
613
+ getControlStyle,
614
+ getThumbStyle,
615
+ getRangeStyle,
616
+ getRootStyle,
617
+ getMarkerStyle,
618
+ getLabelStyle,
619
+ getTrackStyle,
620
+ getMarkerGroupStyle
621
+ };
622
+
623
+ // src/slider.utils.ts
624
+ var utils = {
625
+ fromPercent(ctx, percent) {
626
+ percent = clamp(percent, { min: 0, max: 1 });
627
+ return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
628
+ },
629
+ clamp(ctx, value) {
630
+ return clamp(value, ctx);
631
+ },
632
+ convert(ctx, value) {
633
+ return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
634
+ },
635
+ decrement(ctx, step) {
636
+ let value = decrement(ctx.value, step != null ? step : ctx.step);
637
+ return utils.convert(ctx, value);
638
+ },
639
+ increment(ctx, step) {
640
+ let value = increment(ctx.value, step != null ? step : ctx.step);
641
+ return utils.convert(ctx, value);
642
+ }
643
+ };
644
+
645
+ // src/slider.dom.ts
646
+ var dom = __spreadProps(__spreadValues({}, styles), {
606
647
  getDoc: (ctx) => {
607
648
  var _a;
608
649
  return (_a = ctx.doc) != null ? _a : document;
@@ -630,7 +671,7 @@ var dom = {
630
671
  },
631
672
  getTrackId: (ctx) => {
632
673
  var _a, _b;
633
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:-${ctx.uid}track`;
674
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}track`;
634
675
  },
635
676
  getRangeId: (ctx) => {
636
677
  var _a, _b;
@@ -645,9 +686,6 @@ var dom = {
645
686
  getThumbEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getThumbId(ctx)),
646
687
  getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
647
688
  getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
648
- getControlStyle,
649
- getThumbStyle,
650
- getRangeStyle,
651
689
  getValueFromPoint(ctx, point) {
652
690
  const control = dom.getControlEl(ctx);
653
691
  if (!control)
@@ -666,21 +704,8 @@ var dom = {
666
704
  if (!input)
667
705
  return;
668
706
  dispatchInputValueEvent(input, ctx.value);
669
- },
670
- getMarkerStyle(ctx, percent) {
671
- const style = {
672
- position: "absolute",
673
- pointerEvents: "none"
674
- };
675
- if (ctx.isHorizontal) {
676
- percent = ctx.isRtl ? 100 - percent : percent;
677
- style.left = `${percent}%`;
678
- } else {
679
- style.bottom = `${percent}%`;
680
- }
681
- return style;
682
707
  }
683
- };
708
+ });
684
709
 
685
710
  // ../../types/dist/index.mjs
686
711
  function createNormalizer(fn) {
@@ -735,7 +760,8 @@ function connect(state2, send, normalize = normalizeProp) {
735
760
  "data-disabled": dataAttr(isDisabled),
736
761
  "data-orientation": state2.context.orientation,
737
762
  id: dom.getRootId(state2.context),
738
- dir: state2.context.dir
763
+ dir: state2.context.dir,
764
+ style: dom.getRootStyle(state2.context)
739
765
  }),
740
766
  labelProps: normalize.label({
741
767
  "data-part": "label",
@@ -750,9 +776,7 @@ function connect(state2, send, normalize = normalizeProp) {
750
776
  event.preventDefault();
751
777
  (_a2 = dom.getThumbEl(state2.context)) == null ? void 0 : _a2.focus();
752
778
  },
753
- style: {
754
- userSelect: "none"
755
- }
779
+ style: dom.getLabelStyle()
756
780
  }),
757
781
  thumbProps: normalize.element({
758
782
  "data-part": "thumb",
@@ -852,7 +876,7 @@ function connect(state2, send, normalize = normalizeProp) {
852
876
  "data-invalid": dataAttr(isInvalid),
853
877
  "data-orientation": state2.context.orientation,
854
878
  "data-focus": dataAttr(isFocused),
855
- style: { position: "relative" }
879
+ style: dom.getTrackStyle()
856
880
  }),
857
881
  rangeProps: normalize.element({
858
882
  "data-part": "range",
@@ -880,18 +904,14 @@ function connect(state2, send, normalize = normalizeProp) {
880
904
  event.preventDefault();
881
905
  event.stopPropagation();
882
906
  },
883
- style: dom.getControlStyle(state2.context)
907
+ style: dom.getControlStyle()
884
908
  }),
885
909
  markerGroupProps: normalize.element({
886
910
  "data-part": "marker-group",
887
911
  role: "presentation",
888
912
  "aria-hidden": true,
889
913
  "data-orientation": state2.context.orientation,
890
- style: {
891
- userSelect: "none",
892
- pointerEvents: "none",
893
- position: "relative"
894
- }
914
+ style: dom.getMarkerGroupStyle()
895
915
  }),
896
916
  getMarkerProps({ value }) {
897
917
  const percent = valueToPercent(value, state2.context);