@rethink-js/rt-slider 1.0.0 → 1.2.0

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
@@ -1,4 +1,4 @@
1
- /*! @rethink-js/rt-slider v1.0.0 | MIT */
1
+ /*! @rethink-js/rt-slider v1.2.0 | MIT */
2
2
  (() => {
3
3
  // src/index.js
4
4
  (function() {
@@ -9,7 +9,7 @@
9
9
  if (typeof window.Lenis !== "undefined") return Promise.resolve();
10
10
  if (lenisLoadingPromise) return lenisLoadingPromise;
11
11
  lenisLoadingPromise = new Promise(function(resolve, reject) {
12
- var existing = document.querySelector('script[data-rt-lenis="true"]') || document.querySelector('script[src*="lenis"]');
12
+ var existing = document.querySelector('script[data-rt-slider-lenis="true"]') || document.querySelector('script[src*="lenis"]');
13
13
  if (existing) {
14
14
  if (typeof window.Lenis !== "undefined") {
15
15
  resolve();
@@ -25,7 +25,7 @@
25
25
  var s = document.createElement("script");
26
26
  s.src = "https://cdn.jsdelivr.net/npm/lenis@1.3.16/dist/lenis.min.js";
27
27
  s.async = true;
28
- s.dataset.rtLenis = "true";
28
+ s.setAttribute("data-rt-slider-lenis", "true");
29
29
  s.onload = function() {
30
30
  resolve();
31
31
  };
@@ -73,17 +73,21 @@
73
73
  return el.getAttribute(attr);
74
74
  }
75
75
  function injectOnce(key, css) {
76
- var s = document.head.querySelector('[data-rt-injected="' + key + '"]');
76
+ var s = document.head.querySelector(
77
+ '[data-rt-slider-injected="' + key + '"]'
78
+ );
77
79
  if (!s) {
78
80
  s = document.createElement("style");
79
- s.setAttribute("data-rt-injected", key);
81
+ s.setAttribute("data-rt-slider-injected", key);
80
82
  document.head.appendChild(s);
81
83
  }
82
84
  if (s.textContent !== css) s.textContent = css;
83
85
  return s;
84
86
  }
85
87
  function removeInjected(key) {
86
- var s = document.head.querySelector('[data-rt-injected="' + key + '"]');
88
+ var s = document.head.querySelector(
89
+ '[data-rt-slider-injected="' + key + '"]'
90
+ );
87
91
  if (s && s.parentNode) s.parentNode.removeChild(s);
88
92
  }
89
93
  function toSel(v) {
@@ -114,6 +118,11 @@
114
118
  function clamp(i) {
115
119
  return i < 0 ? 0 : i > 1 ? 1 : i;
116
120
  }
121
+ function round(n, d) {
122
+ if (!Number.isFinite(n)) return 0;
123
+ var m = Math.pow(10, d || 0);
124
+ return Math.round(n * m) / m;
125
+ }
117
126
  function parseEasing(name) {
118
127
  var n = String(name || "").trim();
119
128
  if (!n) return null;
@@ -306,6 +315,10 @@
306
315
  this._injectedKey = null;
307
316
  this._lastGutterPx = 0;
308
317
  this._lastGapPx = 0;
318
+ this.slideState = null;
319
+ this._slideStateSig = "";
320
+ this._lastSlideStateActiveIndex = -1;
321
+ this._lastSlideStateScrollLeft = 0;
309
322
  var self = this;
310
323
  this.ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(function() {
311
324
  if (self._roTicking) return;
@@ -518,6 +531,7 @@
518
531
  this.updateScrollbar();
519
532
  this.updateButtons();
520
533
  this.updateOverlays();
534
+ this.updateSlideState(false);
521
535
  };
522
536
  Slider.prototype.safeClampScroll = function(x) {
523
537
  var clamped = Math.min(Math.max(x, 0), this.maxScroll());
@@ -542,6 +556,7 @@
542
556
  this.updateScrollbar();
543
557
  this.updateButtons();
544
558
  this.updateOverlays();
559
+ this.updateSlideState(false);
545
560
  };
546
561
  Slider.prototype.scheduleTouchClamp = function() {
547
562
  var self = this;
@@ -563,6 +578,7 @@
563
578
  self.updateScrollbar();
564
579
  self.updateButtons();
565
580
  self.updateOverlays();
581
+ self.updateSlideState(false);
566
582
  }, 90);
567
583
  };
568
584
  Slider.prototype.onScroll = function() {
@@ -571,6 +587,7 @@
571
587
  this.updateScrollbar();
572
588
  this.updateButtons();
573
589
  this.updateOverlays();
590
+ this.updateSlideState(false);
574
591
  this.scheduleTouchClamp();
575
592
  return;
576
593
  }
@@ -590,6 +607,7 @@
590
607
  self.updateScrollbar();
591
608
  self.updateButtons();
592
609
  self.updateOverlays();
610
+ self.updateSlideState(false);
593
611
  self.ticking = false;
594
612
  });
595
613
  };
@@ -603,14 +621,413 @@
603
621
  var mr = parseFloat(cs.marginRight) || 0;
604
622
  return Math.max(1, Math.round(w + mr));
605
623
  };
606
- Slider.prototype.scrollByItems = function(n) {
607
- var step = this.itemStepWidth();
608
- var target = n > 0 ? this.scroller.scrollLeft + step * n : this.scroller.scrollLeft - step * Math.abs(n);
609
- var clamped = this.safeClampScroll(target);
624
+ Slider.prototype.getAlignTargetLeft = function() {
625
+ var ref = this.pickVisibleMarginRef();
626
+ if (ref) {
627
+ return ref.getBoundingClientRect().left;
628
+ }
629
+ var sRect = this.scroller.getBoundingClientRect();
630
+ var scrollerCS = getComputedStyle(this.scroller);
631
+ var listCS = getComputedStyle(this.list);
632
+ var scrollerBorderL = parseFloat(scrollerCS.borderLeftWidth || "0") || 0;
633
+ var scrollerPadL = parseFloat(scrollerCS.paddingLeft || "0") || 0;
634
+ var listPadL = parseFloat(listCS.paddingLeft || "0") || 0;
635
+ var gutter = Number.isFinite(this._lastGutterPx) ? this._lastGutterPx : 0;
636
+ return sRect.left + scrollerBorderL + scrollerPadL + listPadL + gutter;
637
+ };
638
+ Slider.prototype.getOrderedItems = function() {
639
+ if (!this.conf.item) return [];
640
+ var nodes = Array.from(this.list.querySelectorAll(this.conf.item));
641
+ return nodes.filter(function(n) {
642
+ return n && n.nodeType === 1;
643
+ });
644
+ };
645
+ Slider.prototype.getCurrentItemIndex = function(items) {
646
+ if (!items || !items.length) return -1;
647
+ var alignLeft = this.getAlignTargetLeft();
648
+ var bestIdx = 0;
649
+ var bestAbs = Infinity;
650
+ for (var i = 0; i < items.length; i++) {
651
+ var r = items[i].getBoundingClientRect();
652
+ var d = r.left - alignLeft;
653
+ var ad = Math.abs(d);
654
+ if (ad < bestAbs) {
655
+ bestAbs = ad;
656
+ bestIdx = i;
657
+ }
658
+ }
659
+ return bestIdx;
660
+ };
661
+ Slider.prototype.getItemAnchorScrolls = function(items) {
662
+ var current = this.safeClampScroll(this.scroller.scrollLeft);
663
+ var alignLeft = this.getAlignTargetLeft();
664
+ var anchors = [];
665
+ var last = -Infinity;
666
+ for (var i = 0; i < items.length; i++) {
667
+ var item = items[i];
668
+ item.setAttribute("data-rt-slider-item-index", String(i));
669
+ var rect = item.getBoundingClientRect();
670
+ var raw = current + (rect.left - alignLeft);
671
+ var anchor = this.safeClampScroll(raw);
672
+ if (anchor < last) anchor = last;
673
+ anchors.push(anchor);
674
+ last = anchor;
675
+ }
676
+ return anchors;
677
+ };
678
+ Slider.prototype.cloneSlideState = function(state2) {
679
+ if (!state2) return null;
680
+ return {
681
+ sliderId: state2.sliderId,
682
+ itemCount: state2.itemCount,
683
+ scroll: {
684
+ current: state2.scroll.current,
685
+ max: state2.scroll.max,
686
+ progress: state2.scroll.progress,
687
+ progressPercent: state2.scroll.progressPercent,
688
+ direction: state2.scroll.direction,
689
+ isAtStart: state2.scroll.isAtStart,
690
+ isAtEnd: state2.scroll.isAtEnd
691
+ },
692
+ active: {
693
+ index: state2.active.index,
694
+ element: state2.active.element,
695
+ anchorScrollLeft: state2.active.anchorScrollLeft,
696
+ distancePx: state2.active.distancePx
697
+ },
698
+ previous: {
699
+ index: state2.previous.index,
700
+ element: state2.previous.element
701
+ },
702
+ next: {
703
+ index: state2.next.index,
704
+ element: state2.next.element
705
+ },
706
+ segment: {
707
+ fromIndex: state2.segment.fromIndex,
708
+ fromElement: state2.segment.fromElement,
709
+ toIndex: state2.segment.toIndex,
710
+ toElement: state2.segment.toElement,
711
+ progress: state2.segment.progress,
712
+ progressPercent: state2.segment.progressPercent,
713
+ distancePx: state2.segment.distancePx,
714
+ spanPx: state2.segment.spanPx,
715
+ remainingPx: state2.segment.remainingPx,
716
+ isBetween: state2.segment.isBetween
717
+ },
718
+ slides: state2.slides.map(function(slide) {
719
+ return {
720
+ index: slide.index,
721
+ element: slide.element,
722
+ anchorScrollLeft: slide.anchorScrollLeft,
723
+ anchorProgress: slide.anchorProgress,
724
+ anchorProgressPercent: slide.anchorProgressPercent,
725
+ distanceFromCurrentPx: slide.distanceFromCurrentPx,
726
+ isActive: slide.isActive,
727
+ isPrevious: slide.isPrevious,
728
+ isNext: slide.isNext,
729
+ isFrom: slide.isFrom,
730
+ isTo: slide.isTo,
731
+ isBeforeActive: slide.isBeforeActive,
732
+ isAfterActive: slide.isAfterActive
733
+ };
734
+ })
735
+ };
736
+ };
737
+ Slider.prototype.dispatchSliderEvent = function(name, detail) {
738
+ var payload = this.cloneSlideState(detail);
739
+ try {
740
+ this.root.dispatchEvent(
741
+ new CustomEvent(name, {
742
+ bubbles: true,
743
+ detail: payload
744
+ })
745
+ );
746
+ } catch (e) {
747
+ var ev = document.createEvent("CustomEvent");
748
+ ev.initCustomEvent(name, true, false, payload);
749
+ this.root.dispatchEvent(ev);
750
+ }
751
+ };
752
+ Slider.prototype.applySlideStateAttributes = function(state2) {
753
+ var root = this.root;
754
+ root.setAttribute(
755
+ "data-rt-slider-active-index",
756
+ String(state2.active.index)
757
+ );
758
+ root.setAttribute(
759
+ "data-rt-slider-from-index",
760
+ String(state2.segment.fromIndex)
761
+ );
762
+ root.setAttribute("data-rt-slider-to-index", String(state2.segment.toIndex));
763
+ root.setAttribute(
764
+ "data-rt-slider-segment-progress",
765
+ String(round(state2.segment.progress, 6))
766
+ );
767
+ root.setAttribute(
768
+ "data-rt-slider-segment-progress-percent",
769
+ String(round(state2.segment.progressPercent, 4))
770
+ );
771
+ root.setAttribute(
772
+ "data-rt-slider-scroll-progress",
773
+ String(round(state2.scroll.progress, 6))
774
+ );
775
+ root.setAttribute(
776
+ "data-rt-slider-scroll-progress-percent",
777
+ String(round(state2.scroll.progressPercent, 4))
778
+ );
779
+ root.setAttribute(
780
+ "data-rt-slider-scroll-direction",
781
+ state2.scroll.direction
782
+ );
783
+ for (var i = 0; i < state2.slides.length; i++) {
784
+ var slide = state2.slides[i];
785
+ var el = slide.element;
786
+ if (!el) continue;
787
+ el.setAttribute("data-rt-slider-item-index", String(slide.index));
788
+ el.setAttribute(
789
+ "data-rt-slider-item-active",
790
+ slide.isActive ? "true" : "false"
791
+ );
792
+ el.setAttribute(
793
+ "data-rt-slider-item-from",
794
+ slide.isFrom ? "true" : "false"
795
+ );
796
+ el.setAttribute("data-rt-slider-item-to", slide.isTo ? "true" : "false");
797
+ el.setAttribute(
798
+ "data-rt-slider-item-previous",
799
+ slide.isPrevious ? "true" : "false"
800
+ );
801
+ el.setAttribute(
802
+ "data-rt-slider-item-next",
803
+ slide.isNext ? "true" : "false"
804
+ );
805
+ el.setAttribute(
806
+ "data-rt-slider-item-before-active",
807
+ slide.isBeforeActive ? "true" : "false"
808
+ );
809
+ el.setAttribute(
810
+ "data-rt-slider-item-after-active",
811
+ slide.isAfterActive ? "true" : "false"
812
+ );
813
+ el.setAttribute(
814
+ "data-rt-slider-item-anchor-progress",
815
+ String(round(slide.anchorProgress, 6))
816
+ );
817
+ el.setAttribute(
818
+ "data-rt-slider-item-anchor-progress-percent",
819
+ String(round(slide.anchorProgressPercent, 4))
820
+ );
821
+ el.setAttribute(
822
+ "data-rt-slider-item-distance",
823
+ String(round(slide.distanceFromCurrentPx, 4))
824
+ );
825
+ }
826
+ };
827
+ Slider.prototype.buildSlideState = function() {
828
+ var items = this.getOrderedItems();
829
+ var max = this.maxScroll();
830
+ var current = this.safeClampScroll(this.scroller.scrollLeft);
831
+ var prevScroll = this._lastSlideStateScrollLeft;
832
+ var scrollDirection = "none";
833
+ if (current > prevScroll + 0.01) scrollDirection = "forward";
834
+ else if (current < prevScroll - 0.01) scrollDirection = "backward";
835
+ if (!items.length) {
836
+ return {
837
+ sliderId: this.sliderId,
838
+ itemCount: 0,
839
+ scroll: {
840
+ current,
841
+ max,
842
+ progress: max > 0 ? clamp(current / max) : 0,
843
+ progressPercent: max > 0 ? clamp(current / max) * 100 : 0,
844
+ direction: scrollDirection,
845
+ isAtStart: current <= 0.5,
846
+ isAtEnd: current >= max - 0.5
847
+ },
848
+ active: {
849
+ index: -1,
850
+ element: null,
851
+ anchorScrollLeft: 0,
852
+ distancePx: 0
853
+ },
854
+ previous: {
855
+ index: -1,
856
+ element: null
857
+ },
858
+ next: {
859
+ index: -1,
860
+ element: null
861
+ },
862
+ segment: {
863
+ fromIndex: -1,
864
+ fromElement: null,
865
+ toIndex: -1,
866
+ toElement: null,
867
+ progress: 0,
868
+ progressPercent: 0,
869
+ distancePx: 0,
870
+ spanPx: 0,
871
+ remainingPx: 0,
872
+ isBetween: false
873
+ },
874
+ slides: []
875
+ };
876
+ }
877
+ var anchors = this.getItemAnchorScrolls(items);
878
+ var nearestIndex = 0;
879
+ var nearestDistance = Infinity;
880
+ for (var i = 0; i < anchors.length; i++) {
881
+ var distance = current - anchors[i];
882
+ var absDistance = Math.abs(distance);
883
+ if (absDistance < nearestDistance) {
884
+ nearestDistance = absDistance;
885
+ nearestIndex = i;
886
+ }
887
+ }
888
+ var fromIndex = 0;
889
+ var toIndex = 0;
890
+ var segmentProgress = 0;
891
+ var segmentDistance = 0;
892
+ var segmentSpan = 0;
893
+ var segmentRemaining = 0;
894
+ var isBetween = false;
895
+ if (current <= anchors[0]) {
896
+ fromIndex = 0;
897
+ toIndex = 0;
898
+ segmentProgress = 0;
899
+ segmentDistance = 0;
900
+ segmentSpan = 0;
901
+ segmentRemaining = 0;
902
+ isBetween = false;
903
+ } else if (current >= anchors[anchors.length - 1]) {
904
+ fromIndex = anchors.length - 1;
905
+ toIndex = anchors.length - 1;
906
+ segmentProgress = 1;
907
+ segmentDistance = 0;
908
+ segmentSpan = 0;
909
+ segmentRemaining = 0;
910
+ isBetween = false;
911
+ } else {
912
+ for (var j = 0; j < anchors.length - 1; j++) {
913
+ var a = anchors[j];
914
+ var b = anchors[j + 1];
915
+ if (current >= a && current <= b) {
916
+ fromIndex = j;
917
+ toIndex = j + 1;
918
+ segmentSpan = Math.max(0, b - a);
919
+ segmentDistance = Math.max(0, current - a);
920
+ segmentProgress = segmentSpan > 0 ? clamp(segmentDistance / segmentSpan) : 0;
921
+ segmentRemaining = Math.max(0, segmentSpan - segmentDistance);
922
+ isBetween = current > a && current < b;
923
+ break;
924
+ }
925
+ }
926
+ }
927
+ var slides = [];
928
+ for (var k = 0; k < items.length; k++) {
929
+ var anchor = anchors[k];
930
+ var anchorProgress = max > 0 ? clamp(anchor / max) : 0;
931
+ slides.push({
932
+ index: k,
933
+ element: items[k],
934
+ anchorScrollLeft: anchor,
935
+ anchorProgress,
936
+ anchorProgressPercent: anchorProgress * 100,
937
+ distanceFromCurrentPx: current - anchor,
938
+ isActive: k === nearestIndex,
939
+ isPrevious: k === nearestIndex - 1,
940
+ isNext: k === nearestIndex + 1,
941
+ isFrom: k === fromIndex,
942
+ isTo: k === toIndex,
943
+ isBeforeActive: k < nearestIndex,
944
+ isAfterActive: k > nearestIndex
945
+ });
946
+ }
947
+ return {
948
+ sliderId: this.sliderId,
949
+ itemCount: items.length,
950
+ scroll: {
951
+ current,
952
+ max,
953
+ progress: max > 0 ? clamp(current / max) : 0,
954
+ progressPercent: max > 0 ? clamp(current / max) * 100 : 0,
955
+ direction: scrollDirection,
956
+ isAtStart: current <= 0.5,
957
+ isAtEnd: current >= max - 0.5
958
+ },
959
+ active: {
960
+ index: nearestIndex,
961
+ element: items[nearestIndex] || null,
962
+ anchorScrollLeft: anchors[nearestIndex] || 0,
963
+ distancePx: current - (anchors[nearestIndex] || 0)
964
+ },
965
+ previous: {
966
+ index: nearestIndex > 0 ? nearestIndex - 1 : -1,
967
+ element: nearestIndex > 0 ? items[nearestIndex - 1] : null
968
+ },
969
+ next: {
970
+ index: nearestIndex < items.length - 1 ? nearestIndex + 1 : -1,
971
+ element: nearestIndex < items.length - 1 ? items[nearestIndex + 1] : null
972
+ },
973
+ segment: {
974
+ fromIndex,
975
+ fromElement: items[fromIndex] || null,
976
+ toIndex,
977
+ toElement: items[toIndex] || null,
978
+ progress: segmentProgress,
979
+ progressPercent: segmentProgress * 100,
980
+ distancePx: segmentDistance,
981
+ spanPx: segmentSpan,
982
+ remainingPx: segmentRemaining,
983
+ isBetween
984
+ },
985
+ slides
986
+ };
987
+ };
988
+ Slider.prototype.updateSlideState = function(force) {
989
+ var state2 = this.buildSlideState();
990
+ var prevActiveIndex = this._lastSlideStateActiveIndex;
991
+ var sig = state2.active.index + "|" + state2.segment.fromIndex + "|" + state2.segment.toIndex + "|" + round(state2.segment.progress, 4) + "|" + round(state2.scroll.progress, 4) + "|" + state2.scroll.direction;
992
+ this.slideState = state2;
993
+ this.applySlideStateAttributes(state2);
994
+ this._lastSlideStateScrollLeft = state2.scroll.current;
995
+ if (force || sig !== this._slideStateSig) {
996
+ this._slideStateSig = sig;
997
+ this.dispatchSliderEvent("rtSlider:slide", state2);
998
+ }
999
+ if (force || state2.active.index !== prevActiveIndex) {
1000
+ this._lastSlideStateActiveIndex = state2.active.index;
1001
+ this.dispatchSliderEvent("rtSlider:active", state2);
1002
+ }
1003
+ };
1004
+ Slider.prototype.getSlideState = function() {
1005
+ if (!this.slideState) this.updateSlideState(true);
1006
+ return this.cloneSlideState(this.slideState);
1007
+ };
1008
+ Slider.prototype.getActiveIndex = function() {
1009
+ var state2 = this.getSlideState();
1010
+ return state2 && state2.active ? state2.active.index : -1;
1011
+ };
1012
+ Slider.prototype.getActiveElement = function() {
1013
+ var state2 = this.getSlideState();
1014
+ return state2 && state2.active ? state2.active.element : null;
1015
+ };
1016
+ Slider.prototype.scrollAlignToItem = function(el) {
1017
+ if (!el) return;
1018
+ var total = this.scroller.scrollWidth;
1019
+ var visible = this.scroller.clientWidth;
1020
+ if (total <= visible + 1) return;
1021
+ var alignLeft = this.getAlignTargetLeft();
1022
+ var r = el.getBoundingClientRect();
1023
+ var delta = r.left - alignLeft;
1024
+ if (!Number.isFinite(delta)) return;
1025
+ var target = this.safeClampScroll(this.scroller.scrollLeft + delta);
610
1026
  if (this.lenis) {
1027
+ var duration = 1.2;
611
1028
  try {
612
- this.lenis.scrollTo(clamped, {
613
- duration: 1.2,
1029
+ this.lenis.scrollTo(target, {
1030
+ duration,
614
1031
  easing: function(t) {
615
1032
  return Math.min(1, 1.001 - Math.pow(2, -10 * t));
616
1033
  },
@@ -619,12 +1036,47 @@
619
1036
  force: true
620
1037
  });
621
1038
  } catch (e) {
622
- this.scroller.scrollTo({ left: clamped, behavior: "smooth" });
1039
+ this.scroller.scrollTo({ left: target, behavior: "smooth" });
623
1040
  }
624
1041
  } else {
625
- this.scroller.scrollTo({ left: clamped, behavior: "smooth" });
1042
+ this.scroller.scrollTo({ left: target, behavior: "smooth" });
626
1043
  }
627
1044
  };
1045
+ Slider.prototype.scrollByItems = function(n) {
1046
+ var total = this.scroller.scrollWidth;
1047
+ var visible = this.scroller.clientWidth;
1048
+ if (total <= visible + 1) return;
1049
+ var items = this.getOrderedItems();
1050
+ if (!items.length) {
1051
+ var step = this.itemStepWidth();
1052
+ var fallback = n > 0 ? this.scroller.scrollLeft + step * n : this.scroller.scrollLeft - step * Math.abs(n);
1053
+ var clamped = this.safeClampScroll(fallback);
1054
+ if (this.lenis) {
1055
+ try {
1056
+ this.lenis.scrollTo(clamped, {
1057
+ duration: 1.2,
1058
+ easing: function(t) {
1059
+ return Math.min(1, 1.001 - Math.pow(2, -10 * t));
1060
+ },
1061
+ immediate: false,
1062
+ lock: false,
1063
+ force: true
1064
+ });
1065
+ } catch (e) {
1066
+ this.scroller.scrollTo({ left: clamped, behavior: "smooth" });
1067
+ }
1068
+ } else {
1069
+ this.scroller.scrollTo({ left: clamped, behavior: "smooth" });
1070
+ }
1071
+ return;
1072
+ }
1073
+ var curIdx = this.getCurrentItemIndex(items);
1074
+ if (curIdx < 0) curIdx = 0;
1075
+ var nextIdx = curIdx;
1076
+ if (n > 0) nextIdx = Math.min(items.length - 1, curIdx + 1);
1077
+ else if (n < 0) nextIdx = Math.max(0, curIdx - 1);
1078
+ this.scrollAlignToItem(items[nextIdx]);
1079
+ };
628
1080
  Slider.prototype.onPrevClick = function(e) {
629
1081
  e.preventDefault();
630
1082
  this.scrollByItems(-1);
@@ -889,6 +1341,7 @@
889
1341
  this.updateScrollbar();
890
1342
  this.updateButtons();
891
1343
  this.updateOverlays();
1344
+ this.updateSlideState(false);
892
1345
  this.barPointerId = null;
893
1346
  };
894
1347
  Slider.prototype.detectLinksInItems = function() {
@@ -966,22 +1419,22 @@
966
1419
  );
967
1420
  };
968
1421
  Slider.prototype.applyListStyles = function() {
969
- var listUID = assignUID(this.list, "data-rt-ss-id");
970
- var scrollerUID = assignUID(this.scroller, "data-rt-ss-scroller-id");
1422
+ var listUID = assignUID(this.list, "data-rt-slider-list-uid");
1423
+ var scrollerUID = assignUID(this.scroller, "data-rt-slider-scroller-uid");
971
1424
  var isDesktop = this.mq.matches;
972
1425
  var scrollbarStyles = "";
973
1426
  if (this.scrollTrack && this.scrollBar) {
974
- var trackUID = assignUID(this.scrollTrack, "data-rt-track-id");
975
- var barUID = assignUID(this.scrollBar, "data-rt-bar-id");
1427
+ var trackUID = assignUID(this.scrollTrack, "data-rt-slider-track-uid");
1428
+ var barUID = assignUID(this.scrollBar, "data-rt-slider-bar-uid");
976
1429
  if (isDesktop) {
977
- scrollbarStyles = '[data-rt-track-id="' + trackUID + '"]{position:relative; touch-action:none; overflow: visible !important;}[data-rt-track-id="' + trackUID + '"]::before{content:"";position:absolute;top:-30px;bottom:-30px;left:0;right:0;z-index:0; cursor:pointer; pointer-events:auto;}[data-rt-bar-id="' + barUID + '"]{position:relative; z-index:2; touch-action:none;}[data-rt-bar-id="' + barUID + '"]::after{content:"";position:absolute;top:-30px;bottom:-30px;left:0;right:0;z-index:3; cursor:grab; pointer-events:auto;}';
1430
+ scrollbarStyles = '[data-rt-slider-track-uid="' + trackUID + '"]{position:relative; touch-action:none; overflow: visible !important;}[data-rt-slider-track-uid="' + trackUID + '"]::before{content:"";position:absolute;top:-30px;bottom:-30px;left:0;right:0;z-index:0; cursor:pointer; pointer-events:auto;}[data-rt-slider-bar-uid="' + barUID + '"]{position:relative; z-index:2; touch-action:none;}[data-rt-slider-bar-uid="' + barUID + '"]::after{content:"";position:absolute;top:-30px;bottom:-30px;left:0;right:0;z-index:3; cursor:grab; pointer-events:auto;}';
978
1431
  } else {
979
- scrollbarStyles = '[data-rt-track-id="' + trackUID + '"]{position:relative; touch-action:auto; overflow: visible !important; pointer-events:none !important; user-select:none !important;}[data-rt-track-id="' + trackUID + '"]::before{content:"";position:absolute;top:-30px;bottom:-30px;left:0;right:0;z-index:0; pointer-events:none !important;}[data-rt-bar-id="' + barUID + '"]{position:relative; z-index:2; touch-action:auto; pointer-events:none !important; user-select:none !important;}[data-rt-bar-id="' + barUID + '"]::after{content:"";position:absolute;top:-30px;bottom:-30px;left:0;right:0;z-index:3; pointer-events:none !important;}';
1432
+ scrollbarStyles = '[data-rt-slider-track-uid="' + trackUID + '"]{position:relative; touch-action:auto; overflow: visible !important; pointer-events:none !important; user-select:none !important;}[data-rt-slider-track-uid="' + trackUID + '"]::before{content:"";position:absolute;top:-30px;bottom:-30px;left:0;right:0;z-index:0; pointer-events:none !important;}[data-rt-slider-bar-uid="' + barUID + '"]{position:relative; z-index:2; touch-action:auto; pointer-events:none !important; user-select:none !important;}[data-rt-slider-bar-uid="' + barUID + '"]::after{content:"";position:absolute;top:-30px;bottom:-30px;left:0;right:0;z-index:3; pointer-events:none !important;}';
980
1433
  }
981
1434
  }
982
- var hideNativeScrollbarCSS = '[data-rt-ss-id="' + listUID + '"]::-webkit-scrollbar{width:0 !important;height:0 !important;display:none !important;background:transparent !important;}[data-rt-ss-id="' + listUID + '"]::-webkit-scrollbar-thumb{background:transparent !important;}[data-rt-ss-id="' + listUID + '"]::-webkit-scrollbar-track{background:transparent !important;}[data-rt-ss-id="' + listUID + '"]{scrollbar-width:none !important;-ms-overflow-style:none !important;}[data-rt-ss-scroller-id="' + scrollerUID + '"]::-webkit-scrollbar{width:0 !important;height:0 !important;display:none !important;background:transparent !important;}[data-rt-ss-scroller-id="' + scrollerUID + '"]::-webkit-scrollbar-thumb{background:transparent !important;}[data-rt-ss-scroller-id="' + scrollerUID + '"]::-webkit-scrollbar-track{background:transparent !important;}[data-rt-ss-scroller-id="' + scrollerUID + '"]{scrollbar-width:none !important;-ms-overflow-style:none !important;}';
983
- var iosMaskCSS = isDesktop ? "" : '[data-rt-ss-scroller-id="' + scrollerUID + '"]{position:relative;padding-bottom:calc(var(--rt-slider-base-pb, 0px) + var(--rt-slider-mask-h, 12px));}[data-rt-ss-scroller-id="' + scrollerUID + '"]::after{content:"";position:absolute;left:0;right:0;bottom:0;height:var(--rt-slider-mask-h, 12px);pointer-events:none;z-index:2147483647;background:var(--rt-slider-mask-bg, transparent);}';
984
- var draggingCSS = '[data-rt-ss-scroller-id="' + scrollerUID + '"].is-dragging{cursor:grabbing !important;user-select:none}[data-rt-ss-id="' + listUID + '"].is-dragging{cursor:grabbing !important;user-select:none}[data-rt-ss-scroller-id="' + scrollerUID + '"].is-dragging img,[data-rt-ss-scroller-id="' + scrollerUID + '"].is-dragging a,[data-rt-ss-scroller-id="' + scrollerUID + '"].is-dragging ' + this.conf.item + '{user-select:none;-webkit-user-drag:none}[data-rt-ss-id="' + listUID + '"] img{-webkit-user-drag:none}';
1435
+ var hideNativeScrollbarCSS = '[data-rt-slider-list-uid="' + listUID + '"]::-webkit-scrollbar{width:0 !important;height:0 !important;display:none !important;background:transparent !important;}[data-rt-slider-list-uid="' + listUID + '"]::-webkit-scrollbar-thumb{background:transparent !important;}[data-rt-slider-list-uid="' + listUID + '"]::-webkit-scrollbar-track{background:transparent !important;}[data-rt-slider-list-uid="' + listUID + '"]{scrollbar-width:none !important;-ms-overflow-style:none !important;}[data-rt-slider-scroller-uid="' + scrollerUID + '"]::-webkit-scrollbar{width:0 !important;height:0 !important;display:none !important;background:transparent !important;}[data-rt-slider-scroller-uid="' + scrollerUID + '"]::-webkit-scrollbar-thumb{background:transparent !important;}[data-rt-slider-scroller-uid="' + scrollerUID + '"]::-webkit-scrollbar-track{background:transparent !important;}[data-rt-slider-scroller-uid="' + scrollerUID + '"]{scrollbar-width:none !important;-ms-overflow-style:none !important;}';
1436
+ var iosMaskCSS = isDesktop ? "" : '[data-rt-slider-scroller-uid="' + scrollerUID + '"]{position:relative;padding-bottom:calc(var(--rt-slider-base-pb, 0px) + var(--rt-slider-mask-h, 12px));}[data-rt-slider-scroller-uid="' + scrollerUID + '"]::after{content:"";position:absolute;left:0;right:0;bottom:0;height:var(--rt-slider-mask-h, 12px);pointer-events:none;z-index:2147483647;background:var(--rt-slider-mask-bg, transparent);}';
1437
+ var draggingCSS = '[data-rt-slider-scroller-uid="' + scrollerUID + '"].is-dragging{cursor:grabbing !important;user-select:none}[data-rt-slider-list-uid="' + listUID + '"].is-dragging{cursor:grabbing !important;user-select:none}[data-rt-slider-scroller-uid="' + scrollerUID + '"].is-dragging img,[data-rt-slider-scroller-uid="' + scrollerUID + '"].is-dragging a,[data-rt-slider-scroller-uid="' + scrollerUID + '"].is-dragging ' + this.conf.item + '{user-select:none;-webkit-user-drag:none}[data-rt-slider-list-uid="' + listUID + '"] img{-webkit-user-drag:none}';
985
1438
  this._injectedKey = "rt-ss-" + listUID;
986
1439
  injectOnce(
987
1440
  this._injectedKey,
@@ -994,6 +1447,7 @@
994
1447
  this.setupCursorMode();
995
1448
  this.applyIOSScrollIndicatorMask();
996
1449
  this.applyListStyles();
1450
+ this.updateSlideState(true);
997
1451
  };
998
1452
  Slider.prototype.onClickCapture = function(e) {
999
1453
  if (!this.didDragTs) return;
@@ -1106,11 +1560,11 @@
1106
1560
  this.scrollTrack.addEventListener("pointerdown", this._onTPD);
1107
1561
  this._onTPM = this.onTrackPointerMove.bind(this);
1108
1562
  this.scrollTrack.addEventListener("pointermove", this._onTPM);
1109
- this._onTPU = this.onTrackPointerUp.bind(this);
1563
+ this._onTPU = this.endBarDrag.bind(this);
1110
1564
  this.scrollTrack.addEventListener("pointerup", this._onTPU);
1111
- this._onTPC = this.onTrackPointerCancel.bind(this);
1565
+ this._onTPC = this.endBarDrag.bind(this);
1112
1566
  this.scrollTrack.addEventListener("pointercancel", this._onTPC);
1113
- this._onTPL = this.onTrackPointerCancel.bind(this);
1567
+ this._onTPL = this.endBarDrag.bind(this);
1114
1568
  this.scrollTrack.addEventListener("pointerleave", this._onTPL);
1115
1569
  }
1116
1570
  } else {
@@ -1130,6 +1584,7 @@
1130
1584
  self.applyListStyles();
1131
1585
  self.setupCursorMode();
1132
1586
  self.rafUpdate();
1587
+ self.updateSlideState(true);
1133
1588
  };
1134
1589
  if (this.mq.addEventListener)
1135
1590
  this.mq.addEventListener("change", this._onMQ);
@@ -1142,6 +1597,7 @@
1142
1597
  self.setupCursorMode();
1143
1598
  self.applyIOSScrollIndicatorMask();
1144
1599
  self.applyListStyles();
1600
+ self.updateSlideState(true);
1145
1601
  };
1146
1602
  img.addEventListener("load", update, { once: true });
1147
1603
  img.addEventListener("error", update, { once: true });
@@ -1165,7 +1621,7 @@
1165
1621
  if (this.mq.matches) {
1166
1622
  loadLenis().then(function() {
1167
1623
  self.setupLenisInstance();
1168
- }).catch(function(e) {
1624
+ }).catch(function() {
1169
1625
  });
1170
1626
  }
1171
1627
  this.rafUpdate();
@@ -1173,10 +1629,12 @@
1173
1629
  self.rafUpdate();
1174
1630
  self.applyIOSScrollIndicatorMask();
1175
1631
  self.applyListStyles();
1632
+ self.updateSlideState(true);
1176
1633
  };
1177
1634
  window.addEventListener("load", this._onWL);
1178
1635
  this.setupCursorMode();
1179
1636
  this.bindEvents();
1637
+ this.updateSlideState(true);
1180
1638
  };
1181
1639
  Slider.prototype.destroy = function() {
1182
1640
  this.stopInertia();
@@ -1277,6 +1735,10 @@
1277
1735
  get: function(id) {
1278
1736
  return state.instances[id] || null;
1279
1737
  },
1738
+ getSlideState: function(id) {
1739
+ var inst = state.instances[id];
1740
+ return inst ? inst.getSlideState() : null;
1741
+ },
1280
1742
  refresh: function() {
1281
1743
  var keys = state.order;
1282
1744
  for (var i = 0; i < keys.length; i++) {