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

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
@@ -319,30 +319,6 @@ function getEventStep(event) {
319
319
  return isSkipKey ? 10 : 1;
320
320
  }
321
321
  }
322
- function itemById(v, id) {
323
- return v.find((node) => node.id === id);
324
- }
325
- function indexOfId(v, id) {
326
- const item = itemById(v, id);
327
- return item ? v.indexOf(item) : -1;
328
- }
329
- var getValueText = (item) => {
330
- var _a, _b;
331
- return (_b = (_a = item.dataset.valuetext) != null ? _a : item.textContent) != null ? _b : "";
332
- };
333
- var match = (valueText, query2) => valueText.toLowerCase().startsWith(query2.toLowerCase());
334
- var wrap = (v, idx) => {
335
- return v.map((_, index) => v[(Math.max(idx, 0) + index) % v.length]);
336
- };
337
- function findByText(v, text, currentId) {
338
- const index = currentId ? indexOfId(v, currentId) : -1;
339
- let items = currentId ? wrap(v, index) : v;
340
- const isSingleKey = text.length === 1;
341
- if (isSingleKey) {
342
- items = items.filter((item) => item.id !== currentId);
343
- }
344
- return items.find((item) => match(getValueText(item), text));
345
- }
346
322
  var state = "default";
347
323
  var savedUserSelect = "";
348
324
  var modifiedElementMap = /* @__PURE__ */ new WeakMap();
@@ -406,34 +382,27 @@ function trackPointerMove(opts) {
406
382
  };
407
383
  return pipe(addPointerEvent(doc, "pointermove", handlePointerMove, false), addPointerEvent(doc, "pointerup", onPointerUp, false), addPointerEvent(doc, "pointercancel", onPointerUp, false), addPointerEvent(doc, "contextmenu", onPointerUp, false), disableTextSelection({ doc }));
408
384
  }
409
- function findByTypeahead(_items, options) {
410
- const { state: state2, activeId, key, timeout = 350 } = options;
411
- const search = state2.keysSoFar + key;
412
- const isRepeated = search.length > 1 && Array.from(search).every((char) => char === search[0]);
413
- const query2 = isRepeated ? search[0] : search;
414
- let items = _items.slice();
415
- const next = findByText(items, query2, activeId);
416
- function cleanup() {
417
- clearTimeout(state2.timer);
418
- state2.timer = -1;
419
- }
420
- function update(value) {
421
- state2.keysSoFar = value;
422
- cleanup();
423
- if (value !== "") {
424
- state2.timer = +setTimeout(() => {
425
- update("");
426
- cleanup();
427
- }, timeout);
428
- }
429
- }
430
- update(search);
431
- return next;
385
+
386
+ // ../../utilities/rect/dist/index.mjs
387
+ var isDom2 = () => typeof window !== "undefined";
388
+ var isArray2 = (v) => Array.isArray(v);
389
+ var isObject2 = (v) => !(v == null || typeof v !== "object" || isArray2(v));
390
+ var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
391
+ var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
392
+ var isTouchEvent2 = (v) => isObject2(v) && hasProp2(v, "touches");
393
+ var fallback2 = { pageX: 0, pageY: 0, clientX: 0, clientY: 0 };
394
+ function getEventPoint(e, t = "page") {
395
+ const p = isTouchEvent2(e) ? e.touches[0] || e.changedTouches[0] || fallback2 : e;
396
+ return { x: p[`${t}X`], y: p[`${t}Y`] };
397
+ }
398
+ function relativeToNode(p, el) {
399
+ const dx = p.x - el.offsetLeft - el.clientLeft + el.scrollLeft;
400
+ const dy = p.y - el.offsetTop - el.clientTop + el.scrollTop;
401
+ return {
402
+ point: { x: dx, y: dy },
403
+ progress: { x: dx / el.offsetWidth, y: dy / el.offsetHeight }
404
+ };
432
405
  }
433
- findByTypeahead.defaultOptions = {
434
- keysSoFar: "",
435
- timer: -1
436
- };
437
406
 
438
407
  // ../../utilities/number/dist/index.mjs
439
408
  var __pow2 = Math.pow;
@@ -495,50 +464,7 @@ var transform = (a, b) => {
495
464
  };
496
465
  };
497
466
 
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
467
+ // src/slider.style.ts
542
468
  function getVerticalThumbOffset(ctx) {
543
469
  var _a;
544
470
  const { height = 0 } = (_a = ctx.thumbSize) != null ? _a : {};
@@ -555,54 +481,117 @@ function getHorizontalThumbOffset(ctx) {
555
481
  const getValue = transform([ctx.min, ctx.max], [-width / 2, width / 2]);
556
482
  return parseFloat(getValue(ctx.value).toFixed(2));
557
483
  }
558
- function getThumbStyle(ctx) {
484
+ function getThumbOffset(ctx) {
559
485
  const percent = valueToPercent(ctx.value, ctx);
560
486
  const offset = ctx.isVertical ? getVerticalThumbOffset(ctx) : getHorizontalThumbOffset(ctx);
561
- const style = {
487
+ return `calc(${percent}% - ${offset}px)`;
488
+ }
489
+ function getThumbStyle(ctx) {
490
+ const placementProp = ctx.isVertical ? "bottom" : ctx.isRtl ? "right" : "left";
491
+ return {
562
492
  visibility: ctx.hasMeasuredThumbSize ? "visible" : "hidden",
563
493
  position: "absolute",
564
494
  transform: "var(--slider-thumb-transform)",
565
- "--slider-thumb-placement": `calc(${percent}% - ${offset}px)`
495
+ [placementProp]: "var(--slider-thumb-offset)"
566
496
  };
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
497
  }
574
- function getRangeStyle(ctx) {
498
+ function getRangeOffsets(ctx) {
575
499
  const percent = valueToPercent(ctx.value, ctx);
576
- const style = {
577
- position: "absolute"
578
- };
579
- let startValue = "0%";
580
- let endValue = `${100 - percent}%`;
500
+ let start = "0%";
501
+ let end = `${100 - percent}%`;
581
502
  if (ctx.origin === "center") {
582
503
  const isNegative = percent < 50;
583
- startValue = isNegative ? `${percent}%` : "50%";
584
- endValue = isNegative ? "50%" : endValue;
504
+ start = isNegative ? `${percent}%` : "50%";
505
+ end = isNegative ? "50%" : end;
585
506
  }
507
+ return { start, end };
508
+ }
509
+ function getRangeStyle(ctx) {
586
510
  if (ctx.isVertical) {
587
- return __spreadProps(__spreadValues({}, style), {
588
- bottom: startValue,
589
- top: endValue
590
- });
511
+ return {
512
+ position: "absolute",
513
+ bottom: "var(--slider-range-start)",
514
+ top: "var(--slider-range-end)"
515
+ };
591
516
  }
592
- return __spreadProps(__spreadValues({}, style), {
593
- [ctx.isRtl ? "right" : "left"]: startValue,
594
- [ctx.isRtl ? "left" : "right"]: endValue
595
- });
517
+ return {
518
+ position: "absolute",
519
+ [ctx.isRtl ? "right" : "left"]: "var(--slider-range-start)",
520
+ [ctx.isRtl ? "left" : "right"]: "var(--slider-range-end)"
521
+ };
596
522
  }
597
- function getControlStyle(ctx) {
523
+ function getControlStyle() {
598
524
  return {
599
525
  touchAction: "none",
600
526
  userSelect: "none",
527
+ position: "relative"
528
+ };
529
+ }
530
+ function getRootStyle(ctx) {
531
+ const range = getRangeOffsets(ctx);
532
+ return {
601
533
  "--slider-thumb-transform": ctx.isVertical ? "translateY(50%)" : "translateX(-50%)",
534
+ "--slider-thumb-offset": getThumbOffset(ctx),
535
+ "--slider-range-start": range.start,
536
+ "--slider-range-end": range.end
537
+ };
538
+ }
539
+ function getMarkerStyle(ctx, percent) {
540
+ return {
541
+ position: "absolute",
542
+ pointerEvents: "none",
543
+ [ctx.isHorizontal ? "left" : "bottom"]: `${ctx.isRtl ? 100 - percent : percent}%`
544
+ };
545
+ }
546
+ function getLabelStyle() {
547
+ return { userSelect: "none" };
548
+ }
549
+ function getTrackStyle() {
550
+ return { position: "relative" };
551
+ }
552
+ function getMarkerGroupStyle() {
553
+ return {
554
+ userSelect: "none",
555
+ pointerEvents: "none",
602
556
  position: "relative"
603
557
  };
604
558
  }
605
- var dom = {
559
+ var styles = {
560
+ getThumbOffset,
561
+ getControlStyle,
562
+ getThumbStyle,
563
+ getRangeStyle,
564
+ getRootStyle,
565
+ getMarkerStyle,
566
+ getLabelStyle,
567
+ getTrackStyle,
568
+ getMarkerGroupStyle
569
+ };
570
+
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
+ // src/slider.dom.ts
594
+ var dom = __spreadProps(__spreadValues({}, styles), {
606
595
  getDoc: (ctx) => {
607
596
  var _a;
608
597
  return (_a = ctx.doc) != null ? _a : document;
@@ -630,7 +619,7 @@ var dom = {
630
619
  },
631
620
  getTrackId: (ctx) => {
632
621
  var _a, _b;
633
- return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:-${ctx.uid}track`;
622
+ return (_b = (_a = ctx.ids) == null ? void 0 : _a.track) != null ? _b : `slider:${ctx.uid}track`;
634
623
  },
635
624
  getRangeId: (ctx) => {
636
625
  var _a, _b;
@@ -645,9 +634,6 @@ var dom = {
645
634
  getThumbEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getThumbId(ctx)),
646
635
  getControlEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getControlId(ctx)),
647
636
  getInputEl: (ctx) => dom.getRootNode(ctx).getElementById(dom.getInputId(ctx)),
648
- getControlStyle,
649
- getThumbStyle,
650
- getRangeStyle,
651
637
  getValueFromPoint(ctx, point) {
652
638
  const control = dom.getControlEl(ctx);
653
639
  if (!control)
@@ -666,21 +652,8 @@ var dom = {
666
652
  if (!input)
667
653
  return;
668
654
  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
655
  }
683
- };
656
+ });
684
657
 
685
658
  // ../../types/dist/index.mjs
686
659
  function createNormalizer(fn) {
@@ -735,7 +708,8 @@ function connect(state2, send, normalize = normalizeProp) {
735
708
  "data-disabled": dataAttr(isDisabled),
736
709
  "data-orientation": state2.context.orientation,
737
710
  id: dom.getRootId(state2.context),
738
- dir: state2.context.dir
711
+ dir: state2.context.dir,
712
+ style: dom.getRootStyle(state2.context)
739
713
  }),
740
714
  labelProps: normalize.label({
741
715
  "data-part": "label",
@@ -750,9 +724,7 @@ function connect(state2, send, normalize = normalizeProp) {
750
724
  event.preventDefault();
751
725
  (_a2 = dom.getThumbEl(state2.context)) == null ? void 0 : _a2.focus();
752
726
  },
753
- style: {
754
- userSelect: "none"
755
- }
727
+ style: dom.getLabelStyle()
756
728
  }),
757
729
  thumbProps: normalize.element({
758
730
  "data-part": "thumb",
@@ -852,7 +824,7 @@ function connect(state2, send, normalize = normalizeProp) {
852
824
  "data-invalid": dataAttr(isInvalid),
853
825
  "data-orientation": state2.context.orientation,
854
826
  "data-focus": dataAttr(isFocused),
855
- style: { position: "relative" }
827
+ style: dom.getTrackStyle()
856
828
  }),
857
829
  rangeProps: normalize.element({
858
830
  "data-part": "range",
@@ -880,18 +852,14 @@ function connect(state2, send, normalize = normalizeProp) {
880
852
  event.preventDefault();
881
853
  event.stopPropagation();
882
854
  },
883
- style: dom.getControlStyle(state2.context)
855
+ style: dom.getControlStyle()
884
856
  }),
885
857
  markerGroupProps: normalize.element({
886
858
  "data-part": "marker-group",
887
859
  role: "presentation",
888
860
  "aria-hidden": true,
889
861
  "data-orientation": state2.context.orientation,
890
- style: {
891
- userSelect: "none",
892
- pointerEvents: "none",
893
- position: "relative"
894
- }
862
+ style: dom.getMarkerGroupStyle()
895
863
  }),
896
864
  getMarkerProps({ value }) {
897
865
  const percent = valueToPercent(value, state2.context);