@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.mjs CHANGED
@@ -411,6 +411,27 @@ findByTypeahead.defaultOptions = {
411
411
  timer: -1
412
412
  };
413
413
 
414
+ // ../../utilities/rect/dist/index.mjs
415
+ var isDom2 = () => typeof window !== "undefined";
416
+ var isArray2 = (v) => Array.isArray(v);
417
+ var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
418
+ var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
419
+ var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
420
+ var isTouchEvent2 = (v) => isObject2(v) && hasProp2(v, "touches");
421
+ var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
422
+ function getEventPoint(e, t = "page") {
423
+ const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
424
+ return { x: p[`${t}X`], y: p[`${t}Y`] };
425
+ }
426
+ function relativeToNode(p, el) {
427
+ const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
428
+ const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
429
+ return {
430
+ point: { x: dx, y: dy },
431
+ progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
432
+ };
433
+ }
434
+
414
435
  // ../../utilities/number/dist/index.mjs
415
436
  var __pow2 = Math.pow;
416
437
  function round(v, t) {
@@ -471,50 +492,7 @@ var transform = (a, b) => {
471
492
  };
472
493
  };
473
494
 
474
- // ../../utilities/rect/dist/index.mjs
475
- var isDom2 = () => typeof window !== "undefined";
476
- var isArray2 = (v) => Array.isArray(v);
477
- var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
478
- var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
479
- var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
480
- var isTouchEvent2 = (v) => isObject2(v) && hasProp2(v, "touches");
481
- var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
482
- function getEventPoint(e, t = "page") {
483
- const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
484
- return { x: p[`${t}X`], y: p[`${t}Y`] };
485
- }
486
- function relativeToNode(p, el) {
487
- const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
488
- const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
489
- return {
490
- point: { x: dx, y: dy },
491
- progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
492
- };
493
- }
494
-
495
- // src/slider.utils.ts
496
- var utils = {
497
- fromPercent(ctx, percent) {
498
- percent = clamp(percent, { min: 0, max: 1 });
499
- return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
500
- },
501
- clamp(ctx, value) {
502
- return clamp(value, ctx);
503
- },
504
- convert(ctx, value) {
505
- return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
506
- },
507
- decrement(ctx, step) {
508
- let value = decrement(ctx.value, step != null ? step : ctx.step);
509
- return utils.convert(ctx, value);
510
- },
511
- increment(ctx, step) {
512
- let value = increment(ctx.value, step != null ? step : ctx.step);
513
- return utils.convert(ctx, value);
514
- }
515
- };
516
-
517
- // src/slider.dom.ts
495
+ // src/slider.style.ts
518
496
  function getVerticalThumbOffset(ctx) {
519
497
  var _a;
520
498
  const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
@@ -531,54 +509,117 @@ function getHorizontalThumbOffset(ctx) {
531
509
  const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
532
510
  return parseFloat(getValue(ctx.value).toFixed(2));
533
511
  }
534
- function getThumbStyle(ctx) {
512
+ function getThumbOffset(ctx) {
535
513
  const percent = valueToPercent(ctx.value, ctx);
536
514
  const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
537
- const style = {
515
+ return `calc(${percent}% - ${offset}px)`;
516
+ }
517
+ function getThumbStyle(ctx) {
518
+ const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
519
+ return {
538
520
  visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
539
521
  position: "absolute",
540
522
  transform: "var(--slider-thumb-transform)",
541
- "--slider-thumb-placement": `calc(${percent}% - ${offset}px)`
523
+ [placementProp]: "var(--slider-thumb-offset)"
542
524
  };
543
- if (ctx.isVertical) {
544
- style.bottom = "var(--slider-thumb-placement)";
545
- } else {
546
- style[ctx.isRtl ? "right" : "left"] = "var(--slider-thumb-placement)";
547
- }
548
- return style;
549
525
  }
550
- function getRangeStyle(ctx) {
526
+ function getRangeOffsets(ctx) {
551
527
  const percent = valueToPercent(ctx.value, ctx);
552
- const style = {
553
- position: "absolute"
554
- };
555
- let startValue = "0%";
556
- let endValue = `${100 - percent}%`;
528
+ let start = "0%";
529
+ let end = `${100 - percent}%`;
557
530
  if (ctx.origin === "center") {
558
531
  const isNegative = percent < 50;
559
- startValue = isNegative ? `${percent}%` : "50%";
560
- endValue = isNegative ? "50%" : endValue;
532
+ start = isNegative ? `${percent}%` : "50%";
533
+ end = isNegative ? "50%" : end;
561
534
  }
535
+ return { start, end };
536
+ }
537
+ function getRangeStyle(ctx) {
562
538
  if (ctx.isVertical) {
563
- return __spreadProps(__spreadValues({}, style), {
564
- bottom: startValue,
565
- top: endValue
566
- });
539
+ return {
540
+ position: "absolute",
541
+ bottom: "var(--slider-range-start)",
542
+ top: "var(--slider-range-end)"
543
+ };
567
544
  }
568
- return __spreadProps(__spreadValues({}, style), {
569
- [ctx.isRtl ? "right" : "left"]: startValue,
570
- [ctx.isRtl ? "left" : "right"]: endValue
571
- });
545
+ return {
546
+ position: "absolute",
547
+ [ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
548
+ [ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
549
+ };
572
550
  }
573
- function getControlStyle(ctx) {
551
+ function getControlStyle() {
574
552
  return {
575
553
  touchAction: "none",
576
554
  userSelect: "none",
555
+ position: "relative"
556
+ };
557
+ }
558
+ function getRootStyle(ctx) {
559
+ const range = getRangeOffsets(ctx);
560
+ return {
577
561
  "--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
562
+ "--slider-thumb-offset": getThumbOffset(ctx),
563
+ "--slider-range-start": range.start,
564
+ "--slider-range-end": range.end
565
+ };
566
+ }
567
+ function getMarkerStyle(ctx, percent) {
568
+ return {
569
+ position: "absolute",
570
+ pointerEvents: "none",
571
+ [ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
572
+ };
573
+ }
574
+ function getLabelStyle() {
575
+ return { userSelect: "none" };
576
+ }
577
+ function getTrackStyle() {
578
+ return { position: "relative" };
579
+ }
580
+ function getMarkerGroupStyle() {
581
+ return {
582
+ userSelect: "none",
583
+ pointerEvents: "none",
578
584
  position: "relative"
579
585
  };
580
586
  }
581
- var dom = {
587
+ var styles = {
588
+ getThumbOffset,
589
+ getControlStyle,
590
+ getThumbStyle,
591
+ getRangeStyle,
592
+ getRootStyle,
593
+ getMarkerStyle,
594
+ getLabelStyle,
595
+ getTrackStyle,
596
+ getMarkerGroupStyle
597
+ };
598
+
599
+ // src/slider.utils.ts
600
+ var utils = {
601
+ fromPercent(ctx, percent) {
602
+ percent = clamp(percent, { min: 0, max: 1 });
603
+ return parseFloat(snapToStep(percentToValue(percent, ctx), ctx.step));
604
+ },
605
+ clamp(ctx, value) {
606
+ return clamp(value, ctx);
607
+ },
608
+ convert(ctx, value) {
609
+ return clamp(parseFloat(snapToStep(value, ctx.step)), ctx);
610
+ },
611
+ decrement(ctx, step) {
612
+ let value = decrement(ctx.value, step != null ? step : ctx.step);
613
+ return utils.convert(ctx, value);
614
+ },
615
+ increment(ctx, step) {
616
+ let value = increment(ctx.value, step != null ? step : ctx.step);
617
+ return utils.convert(ctx, value);
618
+ }
619
+ };
620
+
621
+ // src/slider.dom.ts
622
+ var dom = __spreadProps(__spreadValues({}, styles), {
582
623
  getDoc: (ctx) => {
583
624
  var _a;
584
625
  return (_a = ctx.doc) != null ? _a : document;
@@ -606,7 +647,7 @@ var dom = {
606
647
  },
607
648
  getTrackId: (ctx) => {
608
649
  var _a, _b;
609
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:-${ctx.uid}track`;
650
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}track`;
610
651
  },
611
652
  getRangeId: (ctx) => {
612
653
  var _a, _b;
@@ -621,9 +662,6 @@ var dom = {
621
662
  getThumbEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getThumbId(ctx)),
622
663
  getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
623
664
  getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
624
- getControlStyle,
625
- getThumbStyle,
626
- getRangeStyle,
627
665
  getValueFromPoint(ctx, point) {
628
666
  const control = dom.getControlEl(ctx);
629
667
  if (!control)
@@ -642,21 +680,8 @@ var dom = {
642
680
  if (!input)
643
681
  return;
644
682
  dispatchInputValueEvent(input, ctx.value);
645
- },
646
- getMarkerStyle(ctx, percent) {
647
- const style = {
648
- position: "absolute",
649
- pointerEvents: "none"
650
- };
651
- if (ctx.isHorizontal) {
652
- percent = ctx.isRtl ? 100 - percent : percent;
653
- style.left = `${percent}%`;
654
- } else {
655
- style.bottom = `${percent}%`;
656
- }
657
- return style;
658
683
  }
659
- };
684
+ });
660
685
 
661
686
  // ../../types/dist/index.mjs
662
687
  function createNormalizer(fn) {
@@ -711,7 +736,8 @@ function connect(state2, send, normalize = normalizeProp) {
711
736
  "data-disabled": dataAttr(isDisabled),
712
737
  "data-orientation": state2.context.orientation,
713
738
  id: dom.getRootId(state2.context),
714
- dir: state2.context.dir
739
+ dir: state2.context.dir,
740
+ style: dom.getRootStyle(state2.context)
715
741
  }),
716
742
  labelProps: normalize.label({
717
743
  "data-part": "label",
@@ -726,9 +752,7 @@ function connect(state2, send, normalize = normalizeProp) {
726
752
  event.preventDefault();
727
753
  (_a2 = dom.getThumbEl(state2.context)) == null ? void 0 : _a2.focus();
728
754
  },
729
- style: {
730
- userSelect: "none"
731
- }
755
+ style: dom.getLabelStyle()
732
756
  }),
733
757
  thumbProps: normalize.element({
734
758
  "data-part": "thumb",
@@ -828,7 +852,7 @@ function connect(state2, send, normalize = normalizeProp) {
828
852
  "data-invalid": dataAttr(isInvalid),
829
853
  "data-orientation": state2.context.orientation,
830
854
  "data-focus": dataAttr(isFocused),
831
- style: { position: "relative" }
855
+ style: dom.getTrackStyle()
832
856
  }),
833
857
  rangeProps: normalize.element({
834
858
  "data-part": "range",
@@ -856,18 +880,14 @@ function connect(state2, send, normalize = normalizeProp) {
856
880
  event.preventDefault();
857
881
  event.stopPropagation();
858
882
  },
859
- style: dom.getControlStyle(state2.context)
883
+ style: dom.getControlStyle()
860
884
  }),
861
885
  markerGroupProps: normalize.element({
862
886
  "data-part": "marker-group",
863
887
  role: "presentation",
864
888
  "aria-hidden": true,
865
889
  "data-orientation": state2.context.orientation,
866
- style: {
867
- userSelect: "none",
868
- pointerEvents: "none",
869
- position: "relative"
870
- }
890
+ style: dom.getMarkerGroupStyle()
871
891
  }),
872
892
  getMarkerProps({ value }) {
873
893
  const percent = valueToPercent(value, state2.context);