@evermade/overflow-slider 3.1.0 → 3.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/README.md +59 -6
- package/dist/core/details.esm.js +3 -3
- package/dist/core/details.min.js +1 -1
- package/dist/core/overflow-slider.esm.js +1 -0
- package/dist/core/overflow-slider.min.js +1 -1
- package/dist/core/slider.esm.js +66 -20
- package/dist/core/slider.min.js +1 -1
- package/dist/overflow-slider.css +1 -1
- package/dist/plugins/arrows/arrows/index.esm.js +7 -4
- package/dist/plugins/arrows/arrows/index.min.js +1 -1
- package/dist/plugins/dots/dots/index.esm.js +0 -4
- package/dist/plugins/fade/fade/index.esm.js +4 -4
- package/dist/plugins/fade/fade/index.min.js +1 -1
- package/dist/plugins/full-width/full-width/index.esm.js +7 -2
- package/dist/plugins/full-width/full-width/index.min.js +1 -1
- package/dist/plugins/scroll-indicator/scroll-indicator/index.esm.js +18 -18
- package/dist/plugins/scroll-indicator/scroll-indicator/index.min.js +1 -1
- package/dist/plugins/thumbnails/thumbnails/index.esm.js +8 -5
- package/dist/plugins/thumbnails/thumbnails/index.min.js +1 -1
- package/docs/assets/demo.css +11 -1
- package/docs/assets/demo.js +38 -12
- package/docs/dist/core/details.esm.js +3 -3
- package/docs/dist/core/details.min.js +1 -1
- package/docs/dist/core/overflow-slider.esm.js +1 -0
- package/docs/dist/core/overflow-slider.min.js +1 -1
- package/docs/dist/core/slider.esm.js +66 -20
- package/docs/dist/core/slider.min.js +1 -1
- package/docs/dist/overflow-slider.css +1 -1
- package/docs/dist/plugins/arrows/arrows/index.esm.js +7 -4
- package/docs/dist/plugins/arrows/arrows/index.min.js +1 -1
- package/docs/dist/plugins/dots/dots/index.esm.js +0 -4
- package/docs/dist/plugins/fade/fade/index.esm.js +4 -4
- package/docs/dist/plugins/fade/fade/index.min.js +1 -1
- package/docs/dist/plugins/full-width/full-width/index.esm.js +7 -2
- package/docs/dist/plugins/full-width/full-width/index.min.js +1 -1
- package/docs/dist/plugins/scroll-indicator/scroll-indicator/index.esm.js +18 -18
- package/docs/dist/plugins/scroll-indicator/scroll-indicator/index.min.js +1 -1
- package/docs/dist/plugins/thumbnails/thumbnails/index.esm.js +8 -5
- package/docs/dist/plugins/thumbnails/thumbnails/index.min.js +1 -1
- package/docs/index-rtl.html +396 -0
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/src/core/details.ts +3 -3
- package/src/core/overflow-slider.ts +1 -0
- package/src/core/slider.ts +71 -21
- package/src/core/types.ts +3 -0
- package/src/plugins/arrows/index.ts +7 -5
- package/src/plugins/dots/index.ts +0 -4
- package/src/plugins/fade/index.ts +4 -4
- package/src/plugins/fade/styles.scss +10 -0
- package/src/plugins/full-width/index.ts +8 -2
- package/src/plugins/scroll-indicator/index.ts +60 -62
- package/src/plugins/thumbnails/index.ts +8 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
const t={scrollIndicator:"overflow-slider__scroll-indicator",scrollIndicatorBar:"overflow-slider__scroll-indicator-bar",scrollIndicatorButton:"overflow-slider__scroll-indicator-button"};function e(e){return o=>{var n,
|
|
1
|
+
const t={scrollIndicator:"overflow-slider__scroll-indicator",scrollIndicatorBar:"overflow-slider__scroll-indicator-bar",scrollIndicatorButton:"overflow-slider__scroll-indicator-button"};function e(e){return o=>{var r,n,i;const a={classNames:Object.assign(Object.assign({},t),(null==e?void 0:e.classNames)||[]),container:null!==(r=null==e?void 0:e.container)&&void 0!==r?r:null},s=document.createElement("div");s.setAttribute("class",a.classNames.scrollIndicator),s.setAttribute("tabindex","0"),s.setAttribute("role","scrollbar"),s.setAttribute("aria-controls",null!==(n=o.container.getAttribute("id"))&&void 0!==n?n:""),s.setAttribute("aria-orientation","horizontal"),s.setAttribute("aria-valuemax","100"),s.setAttribute("aria-valuemin","0"),s.setAttribute("aria-valuenow","0");const l=document.createElement("div");l.setAttribute("class",a.classNames.scrollIndicatorBar);const c=document.createElement("div");c.setAttribute("class",a.classNames.scrollIndicatorButton),c.setAttribute("data-is-grabbed","false"),l.appendChild(c),s.appendChild(l);const d=()=>{s.setAttribute("data-has-overflow",o.details.hasOverflow.toString())};d();const u=()=>{const t=c.offsetWidth/o.details.containerWidth,e=o.getScrollLeft()*t;return o.options.rtl?l.offsetWidth-c.offsetWidth-e:e};let f=0;const v=()=>{f&&window.cancelAnimationFrame(f),f=window.requestAnimationFrame((()=>{const t=o.details.containerWidth/o.container.scrollWidth*100,e=u();c.style.width=`${t}%`,c.style.transform=`translateX(${e}px)`;const r=o.getScrollLeft()/(o.getInclusiveScrollWidth()-o.container.offsetWidth)*100;s.setAttribute("aria-valuenow",Math.round(Number.isNaN(r)?0:r).toString())}))};a.container?a.container.appendChild(s):null===(i=o.container.parentNode)||void 0===i||i.insertBefore(s,o.container.nextSibling),v(),o.on("scroll",v),o.on("contentsChanged",v),o.on("containerSizeChanged",v),o.on("detailsChanged",d),s.addEventListener("keydown",(t=>{"ArrowLeft"===t.key?o.moveToDirection("prev"):"ArrowRight"===t.key&&o.moveToDirection("next")}));let b=!1,h=0,m=o.getScrollLeft();s.addEventListener("click",(t=>{if(t.target==c)return;const e=c.offsetWidth,r=u(),n=r+e,i=t.pageX-Math.abs(s.offsetLeft);Math.floor(i)<Math.floor(r)?o.moveToDirection(o.options.rtl?"next":"prev"):Math.floor(i)>Math.floor(n)&&o.moveToDirection(o.options.rtl?"prev":"next")}));const g=t=>{b=!0;const e=t.pageX||t.touches[0].pageX;h=e-s.offsetLeft,m=o.getScrollLeft(),c.style.cursor="grabbing",c.setAttribute("data-is-grabbed","true"),t.preventDefault(),t.stopPropagation()},p=t=>{if(!b)return;t.preventDefault();const e=(t.pageX||t.touches[0].pageX)-s.offsetLeft,r=o.details.scrollableAreaWidth/s.offsetWidth,n=(e-h)*r,i=o.options.rtl?m-n:m+n;o.setScrollLeft(i)},w=()=>{b=!1,c.style.cursor="",c.setAttribute("data-is-grabbed","false")};c.addEventListener("mousedown",g),c.addEventListener("touchstart",g),window.addEventListener("mousemove",p),window.addEventListener("touchmove",p,{passive:!1}),window.addEventListener("mouseup",w),window.addEventListener("touchend",w)}}export{e as default};
|
|
@@ -27,13 +27,16 @@ function FullWidthPlugin(args) {
|
|
|
27
27
|
};
|
|
28
28
|
setActiveThumbnail();
|
|
29
29
|
addClickListeners();
|
|
30
|
-
|
|
31
|
-
mainSlider.on('activeSlideChanged', () => {
|
|
30
|
+
mainSlider.on('scrollEnd', () => {
|
|
32
31
|
setTimeout(() => {
|
|
33
|
-
const
|
|
34
|
-
const
|
|
32
|
+
const mainActiveSlideIdx = mainSlider.activeSlideIdx;
|
|
33
|
+
const thumbActiveSlideIdx = slider.activeSlideIdx;
|
|
34
|
+
if (thumbActiveSlideIdx === mainActiveSlideIdx) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const activeThumbnail = slider.slides[mainActiveSlideIdx];
|
|
35
38
|
setActiveThumbnail(activeThumbnail);
|
|
36
|
-
slider.moveToSlide(
|
|
39
|
+
slider.moveToSlide(mainActiveSlideIdx);
|
|
37
40
|
}, 50);
|
|
38
41
|
});
|
|
39
42
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e){return i=>{const t={mainSlider:e.mainSlider}.mainSlider,l=(e=null)=>{null===e&&i.slides.length>0&&(e=i.slides[0]),null!==e&&(i.slides.forEach((e=>{e.setAttribute("aria-current","false")})),e.setAttribute("aria-current","true"))};l(),i.slides.forEach(((e,i)=>{e.addEventListener("click",(()=>{t.moveToSlide(i),l(e)}))})),t.on("
|
|
1
|
+
function e(e){return i=>{const t={mainSlider:e.mainSlider}.mainSlider,l=(e=null)=>{null===e&&i.slides.length>0&&(e=i.slides[0]),null!==e&&(i.slides.forEach((e=>{e.setAttribute("aria-current","false")})),e.setAttribute("aria-current","true"))};l(),i.slides.forEach(((e,i)=>{e.addEventListener("click",(()=>{t.moveToSlide(i),l(e)}))})),t.on("scrollEnd",(()=>{setTimeout((()=>{const e=t.activeSlideIdx;if(i.activeSlideIdx===e)return;const r=i.slides[e];l(r),i.moveToSlide(e)}),50)}))}}export{e as default};
|
package/docs/assets/demo.css
CHANGED
|
@@ -579,10 +579,20 @@ h3:before {
|
|
|
579
579
|
left: 0;
|
|
580
580
|
}
|
|
581
581
|
|
|
582
|
+
[dir="rtl"] .example-4-filters-previous {
|
|
583
|
+
right: 0;
|
|
584
|
+
left: auto;
|
|
585
|
+
}
|
|
586
|
+
|
|
582
587
|
.example-4-filters-next {
|
|
583
588
|
right: 0;
|
|
584
589
|
}
|
|
585
590
|
|
|
591
|
+
[dir="rtl"] .example-4-filters-next {
|
|
592
|
+
left: 0;
|
|
593
|
+
right: auto;
|
|
594
|
+
}
|
|
595
|
+
|
|
586
596
|
.example-4-filters-previous:has([data-has-content="false"]),
|
|
587
597
|
.example-4-filters-next:has([data-has-content="false"]) {
|
|
588
598
|
opacity: 0;
|
|
@@ -630,7 +640,7 @@ h3:before {
|
|
|
630
640
|
|
|
631
641
|
.example-container-4-full-width {
|
|
632
642
|
width: 100vw;
|
|
633
|
-
margin-
|
|
643
|
+
margin-inline-start: calc(-50vw + 50%);
|
|
634
644
|
}
|
|
635
645
|
|
|
636
646
|
/* ===========================================================================
|
package/docs/assets/demo.js
CHANGED
|
@@ -30,7 +30,9 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
30
30
|
|
|
31
31
|
const example1DragScrolling = new OverflowSlider(
|
|
32
32
|
document.querySelector( '.example-container-1-drag-scrolling-clickable' ),
|
|
33
|
-
{
|
|
33
|
+
{
|
|
34
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
35
|
+
},
|
|
34
36
|
[
|
|
35
37
|
DragScrollingPlugin(),
|
|
36
38
|
SkipLinksPlugin(),
|
|
@@ -40,7 +42,9 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
40
42
|
|
|
41
43
|
const example1DragScrollingNotClickable = new OverflowSlider(
|
|
42
44
|
document.querySelector( '.example-container-1-drag-scrolling-not-clickable' ),
|
|
43
|
-
{
|
|
45
|
+
{
|
|
46
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
47
|
+
},
|
|
44
48
|
[
|
|
45
49
|
DragScrollingPlugin(),
|
|
46
50
|
SkipLinksPlugin(),
|
|
@@ -51,6 +55,7 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
51
55
|
document.querySelector( '.example-container-1-drag-scrolling-scroll-snap' ),
|
|
52
56
|
{
|
|
53
57
|
emulateScrollSnap: true,
|
|
58
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
54
59
|
},
|
|
55
60
|
[
|
|
56
61
|
DragScrollingPlugin(),
|
|
@@ -60,7 +65,9 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
60
65
|
|
|
61
66
|
const example1Arrows = new OverflowSlider(
|
|
62
67
|
document.querySelector( '.example-container-1-arrows' ),
|
|
63
|
-
{
|
|
68
|
+
{
|
|
69
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
70
|
+
},
|
|
64
71
|
[
|
|
65
72
|
DragScrollingPlugin(),
|
|
66
73
|
SkipLinksPlugin(),
|
|
@@ -71,7 +78,9 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
71
78
|
|
|
72
79
|
const example1ScrollIndicator = new OverflowSlider(
|
|
73
80
|
document.querySelector( '.example-container-1-scroll-indicator' ),
|
|
74
|
-
{
|
|
81
|
+
{
|
|
82
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
83
|
+
},
|
|
75
84
|
[
|
|
76
85
|
DragScrollingPlugin(),
|
|
77
86
|
SkipLinksPlugin(),
|
|
@@ -84,6 +93,7 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
84
93
|
document.querySelector( '.example-container-1-dots' ),
|
|
85
94
|
{
|
|
86
95
|
emulateScrollSnap: true,
|
|
96
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
87
97
|
},
|
|
88
98
|
[
|
|
89
99
|
DragScrollingPlugin(),
|
|
@@ -97,6 +107,7 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
97
107
|
document.querySelector( '.example-container-1-fade' ),
|
|
98
108
|
{
|
|
99
109
|
emulateScrollSnap: true,
|
|
110
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
100
111
|
},
|
|
101
112
|
[
|
|
102
113
|
DragScrollingPlugin(),
|
|
@@ -109,7 +120,9 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
109
120
|
|
|
110
121
|
const example2PerfectFit = new OverflowSlider(
|
|
111
122
|
document.querySelector( '.example-container-2-perfect-fit' ),
|
|
112
|
-
{
|
|
123
|
+
{
|
|
124
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
125
|
+
},
|
|
113
126
|
[
|
|
114
127
|
DragScrollingPlugin(),
|
|
115
128
|
ScrollIndicatorPlugin(),
|
|
@@ -119,7 +132,9 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
119
132
|
|
|
120
133
|
const example2VaryingWidths = new OverflowSlider(
|
|
121
134
|
document.querySelector( '.example-container-2-varying-widths' ),
|
|
122
|
-
{
|
|
135
|
+
{
|
|
136
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
137
|
+
},
|
|
123
138
|
[
|
|
124
139
|
DragScrollingPlugin(),
|
|
125
140
|
ScrollIndicatorPlugin(),
|
|
@@ -129,7 +144,9 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
129
144
|
|
|
130
145
|
const example2OnlyFewSlides = new OverflowSlider(
|
|
131
146
|
document.querySelector( '.example-container-2-only-few-slides' ),
|
|
132
|
-
{
|
|
147
|
+
{
|
|
148
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
149
|
+
},
|
|
133
150
|
[
|
|
134
151
|
DragScrollingPlugin(),
|
|
135
152
|
ScrollIndicatorPlugin(),
|
|
@@ -141,6 +158,7 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
141
158
|
document.querySelector( '.example-container-3-scroll-snapping-mandatory' ),
|
|
142
159
|
{
|
|
143
160
|
emulateScrollSnap: true,
|
|
161
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
144
162
|
},
|
|
145
163
|
[
|
|
146
164
|
DragScrollingPlugin(),
|
|
@@ -153,6 +171,7 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
153
171
|
document.querySelector( '.example-container-3-scroll-snapping-proximity' ),
|
|
154
172
|
{
|
|
155
173
|
emulateScrollSnap: true,
|
|
174
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
156
175
|
},
|
|
157
176
|
[
|
|
158
177
|
DragScrollingPlugin(),
|
|
@@ -163,7 +182,9 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
163
182
|
|
|
164
183
|
const example3EntranceAnimation = new OverflowSlider(
|
|
165
184
|
document.querySelector( '.example-container-3-entrance-animation' ),
|
|
166
|
-
{
|
|
185
|
+
{
|
|
186
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
187
|
+
},
|
|
167
188
|
[
|
|
168
189
|
DragScrollingPlugin(),
|
|
169
190
|
ScrollIndicatorPlugin(),
|
|
@@ -173,7 +194,9 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
173
194
|
|
|
174
195
|
const example4Filters = new OverflowSlider(
|
|
175
196
|
document.querySelector( '.example-container-4-filters' ),
|
|
176
|
-
{
|
|
197
|
+
{
|
|
198
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
199
|
+
},
|
|
177
200
|
[
|
|
178
201
|
DragScrollingPlugin(),
|
|
179
202
|
ArrowsPlugin({
|
|
@@ -188,6 +211,7 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
188
211
|
document.querySelector( '.example-container-4-grid-or-slider' ),
|
|
189
212
|
{
|
|
190
213
|
emulateScrollSnap: true,
|
|
214
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
191
215
|
},
|
|
192
216
|
[
|
|
193
217
|
DragScrollingPlugin(),
|
|
@@ -198,7 +222,9 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
198
222
|
|
|
199
223
|
const example4FullWidth = new OverflowSlider(
|
|
200
224
|
document.querySelector( '.example-container-4-full-width' ),
|
|
201
|
-
{
|
|
225
|
+
{
|
|
226
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
227
|
+
},
|
|
202
228
|
[
|
|
203
229
|
DragScrollingPlugin(),
|
|
204
230
|
FullWidthPlugin(
|
|
@@ -218,6 +244,7 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
218
244
|
document.querySelector( '.example-container-4-synced-main' ),
|
|
219
245
|
{
|
|
220
246
|
emulateScrollSnap: true,
|
|
247
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
221
248
|
},
|
|
222
249
|
[
|
|
223
250
|
DragScrollingPlugin(),
|
|
@@ -229,6 +256,7 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
229
256
|
document.querySelector( '.example-container-4-synced-thumbnails' ),
|
|
230
257
|
{
|
|
231
258
|
emulateScrollSnap: true,
|
|
259
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
232
260
|
},
|
|
233
261
|
[
|
|
234
262
|
DragScrollingPlugin(),
|
|
@@ -239,8 +267,6 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
239
267
|
);
|
|
240
268
|
console.log( '4-synced-thumbnails', example4SyncedThumbnails );
|
|
241
269
|
|
|
242
|
-
|
|
243
|
-
|
|
244
270
|
};
|
|
245
271
|
|
|
246
272
|
init();
|
|
@@ -14,10 +14,10 @@ function details(slider) {
|
|
|
14
14
|
containerWidth = slider.container.offsetWidth;
|
|
15
15
|
scrollableAreaWidth = slider.getInclusiveScrollWidth();
|
|
16
16
|
amountOfPages = Math.ceil(scrollableAreaWidth / containerWidth);
|
|
17
|
-
if (Math.floor(slider.
|
|
18
|
-
currentPage = Math.floor(slider.
|
|
17
|
+
if (Math.floor(slider.getScrollLeft()) >= 0) {
|
|
18
|
+
currentPage = Math.floor(slider.getScrollLeft() / containerWidth);
|
|
19
19
|
// consider as last page if the scrollLeft + containerWidth is equal to scrollWidth
|
|
20
|
-
if (Math.floor(slider.
|
|
20
|
+
if (Math.floor(slider.getScrollLeft() + containerWidth) === Math.floor(scrollableAreaWidth)) {
|
|
21
21
|
currentPage = amountOfPages - 1;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t){var l;let e,o=!1,r=0,
|
|
1
|
+
function t(t){var l;let e,o=!1,r=0,a=0,i=0,n=0,f=1;return Math.floor(t.getInclusiveScrollWidth())>Math.floor(t.getInclusiveClientWidth())&&(o=!0),r=null!==(l=t.slides.length)&&void 0!==l?l:0,a=t.container.offsetWidth,i=t.getInclusiveScrollWidth(),n=Math.ceil(i/a),Math.floor(t.getScrollLeft())>=0&&(f=Math.floor(t.getScrollLeft()/a),Math.floor(t.getScrollLeft()+a)===Math.floor(i)&&(f=n-1)),e={hasOverflow:o,slideCount:r,containerWidth:a,scrollableAreaWidth:i,amountOfPages:n,currentPage:f},e}export{t as default};
|
|
@@ -12,6 +12,7 @@ function OverflowSlider(container, options, plugins) {
|
|
|
12
12
|
slidesSelector: ":scope > *",
|
|
13
13
|
emulateScrollSnap: false,
|
|
14
14
|
emulateScrollSnapMaxThreshold: 64,
|
|
15
|
+
rtl: false,
|
|
15
16
|
};
|
|
16
17
|
const sliderOptions = Object.assign(Object.assign({}, defaults), options);
|
|
17
18
|
// disable smooth scrolling if user prefers reduced motion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"./slider.min.js";function o(o,r,t){try{if(!(o instanceof Element))throw new Error("Container must be HTML element, found "+typeof o);const l={scrollBehavior:"smooth",scrollStrategy:"fullSlide",slidesSelector:":scope > *",emulateScrollSnap:!1,emulateScrollSnapMaxThreshold:64},s=Object.assign(Object.assign({},l),r);return window.matchMedia("(prefers-reduced-motion: reduce)").matches&&(s.scrollBehavior="auto"),e(o,s,t)}catch(e){console.error(e)}}export{o as default};
|
|
1
|
+
import e from"./slider.min.js";function o(o,r,t){try{if(!(o instanceof Element))throw new Error("Container must be HTML element, found "+typeof o);const l={scrollBehavior:"smooth",scrollStrategy:"fullSlide",slidesSelector:":scope > *",emulateScrollSnap:!1,emulateScrollSnapMaxThreshold:64,rtl:!1},s=Object.assign(Object.assign({},l),r);return window.matchMedia("(prefers-reduced-motion: reduce)").matches&&(s.scrollBehavior="auto"),e(o,s,t)}catch(e){console.error(e)}}export{o as default};
|
|
@@ -184,6 +184,9 @@ function Slider(container, options, plugins) {
|
|
|
184
184
|
}
|
|
185
185
|
function setDataAttributes() {
|
|
186
186
|
slider.container.setAttribute('data-has-overflow', slider.details.hasOverflow ? 'true' : 'false');
|
|
187
|
+
if (slider.options.rtl) {
|
|
188
|
+
slider.container.setAttribute('dir', 'rtl');
|
|
189
|
+
}
|
|
187
190
|
}
|
|
188
191
|
function ensureSlideIsInView(slide, scrollBehavior = null) {
|
|
189
192
|
const behavior = scrollBehavior || slider.options.scrollBehavior;
|
|
@@ -215,19 +218,48 @@ function Slider(container, options, plugins) {
|
|
|
215
218
|
}
|
|
216
219
|
function setActiveSlideIdx() {
|
|
217
220
|
const sliderRect = slider.container.getBoundingClientRect();
|
|
218
|
-
const scrollLeft = slider.
|
|
221
|
+
const scrollLeft = slider.getScrollLeft();
|
|
219
222
|
const slides = slider.slides;
|
|
220
223
|
let activeSlideIdx = 0;
|
|
221
224
|
let scrolledPastLastSlide = false;
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
225
|
+
if (slider.options.rtl) {
|
|
226
|
+
const scrolledDistance = slider.getInclusiveScrollWidth() - scrollLeft - slider.getInclusiveClientWidth();
|
|
227
|
+
const slidePositions = [];
|
|
228
|
+
for (let i = slides.length - 1; i >= 0; i--) {
|
|
229
|
+
const slideRect = slides[i].getBoundingClientRect();
|
|
230
|
+
const slideEnd = Math.abs(slideRect.left) - Math.abs(sliderRect.left) + scrolledDistance;
|
|
231
|
+
slidePositions.push({
|
|
232
|
+
slide: slides[i],
|
|
233
|
+
slideEnd: slideEnd,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
let closestSlide = null;
|
|
237
|
+
let closestDistance = null;
|
|
238
|
+
for (let i = 0; i < slidePositions.length; i++) {
|
|
239
|
+
const distance = Math.abs(slidePositions[i].slideEnd - scrolledDistance);
|
|
240
|
+
if (closestDistance === null || distance < closestDistance) {
|
|
241
|
+
closestDistance = distance;
|
|
242
|
+
closestSlide = slidePositions[i].slide;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (closestSlide) {
|
|
246
|
+
activeSlideIdx = slides.indexOf(closestSlide);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
activeSlideIdx = slides.length - 1;
|
|
228
250
|
}
|
|
229
|
-
|
|
230
|
-
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
for (let i = 0; i < slides.length; i++) {
|
|
254
|
+
const slideRect = slides[i].getBoundingClientRect();
|
|
255
|
+
const slideStart = slideRect.left - sliderRect.left + scrollLeft + getGapSize();
|
|
256
|
+
if (Math.floor(slideStart) >= Math.floor(scrollLeft)) {
|
|
257
|
+
activeSlideIdx = i;
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
if (i === slides.length - 1) {
|
|
261
|
+
scrolledPastLastSlide = true;
|
|
262
|
+
}
|
|
231
263
|
}
|
|
232
264
|
}
|
|
233
265
|
if (scrolledPastLastSlide) {
|
|
@@ -235,6 +267,7 @@ function Slider(container, options, plugins) {
|
|
|
235
267
|
}
|
|
236
268
|
const oldActiveSlideIdx = slider.activeSlideIdx;
|
|
237
269
|
slider.activeSlideIdx = activeSlideIdx;
|
|
270
|
+
// console.log('activeSlideIdx', activeSlideIdx);
|
|
238
271
|
if (oldActiveSlideIdx !== activeSlideIdx) {
|
|
239
272
|
slider.emit('activeSlideChanged');
|
|
240
273
|
}
|
|
@@ -251,12 +284,18 @@ function Slider(container, options, plugins) {
|
|
|
251
284
|
function getInclusiveClientWidth() {
|
|
252
285
|
return slider.container.clientWidth + getOutermostChildrenEdgeMarginSum(slider.container);
|
|
253
286
|
}
|
|
287
|
+
function getScrollLeft() {
|
|
288
|
+
return slider.options.rtl ? Math.abs(slider.container.scrollLeft) : slider.container.scrollLeft;
|
|
289
|
+
}
|
|
290
|
+
function setScrollLeft(value) {
|
|
291
|
+
slider.container.scrollLeft = slider.options.rtl ? -value : value;
|
|
292
|
+
}
|
|
254
293
|
function getGapSize() {
|
|
255
294
|
let gapSize = 0;
|
|
256
295
|
if (slider.slides.length > 1) {
|
|
257
296
|
const firstSlideRect = slider.slides[0].getBoundingClientRect();
|
|
258
297
|
const secondSlideRect = slider.slides[1].getBoundingClientRect();
|
|
259
|
-
gapSize = Math.floor(secondSlideRect.left - firstSlideRect.right);
|
|
298
|
+
gapSize = slider.options.rtl ? Math.abs(Math.floor(secondSlideRect.right - firstSlideRect.left)) : Math.floor(secondSlideRect.left - firstSlideRect.right);
|
|
260
299
|
}
|
|
261
300
|
return gapSize;
|
|
262
301
|
}
|
|
@@ -274,22 +313,23 @@ function Slider(container, options, plugins) {
|
|
|
274
313
|
const sliderRect = slider.container.getBoundingClientRect();
|
|
275
314
|
const containerWidth = slider.container.offsetWidth;
|
|
276
315
|
let targetScrollPosition = scrollLeft;
|
|
277
|
-
|
|
316
|
+
const realDirection = slider.options.rtl ? (direction === 'prev' ? 'next' : 'prev') : direction;
|
|
317
|
+
if (realDirection === 'prev') {
|
|
278
318
|
targetScrollPosition = Math.max(0, scrollLeft - slider.container.offsetWidth);
|
|
279
319
|
}
|
|
280
|
-
else if (
|
|
320
|
+
else if (realDirection === 'next') {
|
|
281
321
|
targetScrollPosition = Math.min(slider.getInclusiveScrollWidth(), scrollLeft + slider.container.offsetWidth);
|
|
282
322
|
}
|
|
283
323
|
if (scrollStrategy === 'fullSlide') {
|
|
284
324
|
let fullSlideTargetScrollPosition = null;
|
|
285
325
|
// extend targetScrollPosition to include gap
|
|
286
|
-
if (
|
|
326
|
+
if (realDirection === 'prev') {
|
|
287
327
|
fullSlideTargetScrollPosition = Math.max(0, targetScrollPosition - getGapSize());
|
|
288
328
|
}
|
|
289
329
|
else {
|
|
290
330
|
fullSlideTargetScrollPosition = Math.min(slider.getInclusiveScrollWidth(), targetScrollPosition + getGapSize());
|
|
291
331
|
}
|
|
292
|
-
if (
|
|
332
|
+
if (realDirection === 'next') {
|
|
293
333
|
let partialSlideFound = false;
|
|
294
334
|
for (let slide of slider.slides) {
|
|
295
335
|
const slideRect = slide.getBoundingClientRect();
|
|
@@ -347,12 +387,12 @@ function Slider(container, options, plugins) {
|
|
|
347
387
|
setTimeout(() => slider.container.style.scrollBehavior = '', 50);
|
|
348
388
|
}
|
|
349
389
|
function snapToClosestSlide(direction = "prev") {
|
|
350
|
-
const isMovingForward = direction === 'next';
|
|
390
|
+
const isMovingForward = slider.options.rtl ? direction === 'prev' : direction === 'next';
|
|
351
391
|
const slideReference = [];
|
|
352
392
|
for (let i = 0; i < slider.slides.length; i++) {
|
|
353
393
|
const slide = slider.slides[i];
|
|
354
394
|
const slideWidth = slide.offsetWidth;
|
|
355
|
-
const slideStart = slide.offsetLeft;
|
|
395
|
+
const slideStart = slider.options.rtl ? Math.abs(slide.offsetLeft + slideWidth - slider.details.containerWidth) : slide.offsetLeft;
|
|
356
396
|
const slideEnd = slideStart + slideWidth;
|
|
357
397
|
const slideMiddle = slideStart + slideWidth / 2;
|
|
358
398
|
const trigger = Math.min(slideMiddle, slideStart + slider.options.emulateScrollSnapMaxThreshold);
|
|
@@ -363,10 +403,14 @@ function Slider(container, options, plugins) {
|
|
|
363
403
|
width: slideWidth,
|
|
364
404
|
trigger: trigger,
|
|
365
405
|
slide: slide,
|
|
406
|
+
// debug
|
|
407
|
+
offSetleft: slide.offsetLeft,
|
|
408
|
+
rect: slide.getBoundingClientRect(),
|
|
366
409
|
});
|
|
367
410
|
}
|
|
411
|
+
console.log('slideReference', slideReference);
|
|
368
412
|
let snapTarget = null;
|
|
369
|
-
const scrollPosition =
|
|
413
|
+
const scrollPosition = getScrollLeft();
|
|
370
414
|
if (isMovingForward) {
|
|
371
415
|
for (let i = 0; i < slideReference.length; i++) {
|
|
372
416
|
const item = slideReference[i];
|
|
@@ -374,7 +418,7 @@ function Slider(container, options, plugins) {
|
|
|
374
418
|
snapTarget = 0;
|
|
375
419
|
break;
|
|
376
420
|
}
|
|
377
|
-
if (Math.floor(
|
|
421
|
+
if (Math.floor(getScrollLeft()) <= Math.floor(item.trigger)) {
|
|
378
422
|
snapTarget = item.start;
|
|
379
423
|
break;
|
|
380
424
|
}
|
|
@@ -387,7 +431,7 @@ function Slider(container, options, plugins) {
|
|
|
387
431
|
snapTarget = item.start;
|
|
388
432
|
break;
|
|
389
433
|
}
|
|
390
|
-
if (Math.floor(
|
|
434
|
+
if (Math.floor(getScrollLeft()) >= Math.floor(item.trigger)) {
|
|
391
435
|
snapTarget = item.start;
|
|
392
436
|
break;
|
|
393
437
|
}
|
|
@@ -400,7 +444,7 @@ function Slider(container, options, plugins) {
|
|
|
400
444
|
}
|
|
401
445
|
const scrollBehavior = slider.options.scrollBehavior || 'smooth';
|
|
402
446
|
slider.container.scrollTo({
|
|
403
|
-
left: snapTarget,
|
|
447
|
+
left: slider.options.rtl ? -snapTarget : snapTarget,
|
|
404
448
|
behavior: scrollBehavior
|
|
405
449
|
});
|
|
406
450
|
}
|
|
@@ -430,6 +474,8 @@ function Slider(container, options, plugins) {
|
|
|
430
474
|
snapToClosestSlide,
|
|
431
475
|
getInclusiveScrollWidth,
|
|
432
476
|
getInclusiveClientWidth,
|
|
477
|
+
getScrollLeft,
|
|
478
|
+
setScrollLeft,
|
|
433
479
|
on,
|
|
434
480
|
options,
|
|
435
481
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"./details.min.js";import{generateId as e,objectsAreEqual as o,getOutermostChildrenEdgeMarginSum as n}from"./utils.min.js";function l(l,i,r){let a,
|
|
1
|
+
import t from"./details.min.js";import{generateId as e,objectsAreEqual as o,getOutermostChildrenEdgeMarginSum as n}from"./utils.min.js";function l(l,i,r){let a,s={};function c(e=!1){const n=a.details,l=t(a);a.details=l,e||o(n,l)?e&&a.emit("detailsChanged"):a.emit("detailsChanged")}function f(){a.slides=Array.from(a.container.querySelectorAll(a.options.slidesSelector))}function d(){a.container.style.setProperty("--slider-container-width",`${a.details.containerWidth}px`),a.container.style.setProperty("--slider-scrollable-width",`${a.details.scrollableAreaWidth}px`),a.container.style.setProperty("--slider-slides-count",`${a.details.slideCount}`)}function h(){a.container.setAttribute("data-has-overflow",a.details.hasOverflow?"true":"false"),a.options.rtl&&a.container.setAttribute("dir","rtl")}function u(t,e=null){const o=e||a.options.scrollBehavior,n=t.getBoundingClientRect(),l=a.container.getBoundingClientRect(),i=a.container.offsetWidth,r=a.container.scrollLeft,s=n.left-l.left+r,c=s+n.width;let f=null;f=Math.floor(s)<Math.floor(r)?s:Math.floor(c)>Math.floor(r)+Math.floor(i)?c-i:0===Math.floor(s)?0:s,null!==f&&setTimeout((t=>{a.emit("programmaticScrollStart"),a.container.scrollTo({left:t,behavior:o})}),50,f)}function g(){const t=a.container.getBoundingClientRect(),e=a.getScrollLeft(),o=a.slides;let n=0,l=!1;if(a.options.rtl){const l=a.getInclusiveScrollWidth()-e-a.getInclusiveClientWidth(),i=[];for(let e=o.length-1;e>=0;e--){const n=o[e].getBoundingClientRect(),r=Math.abs(n.left)-Math.abs(t.left)+l;i.push({slide:o[e],slideEnd:r})}let r=null,s=null;for(let t=0;t<i.length;t++){const e=Math.abs(i[t].slideEnd-l);(null===s||e<s)&&(s=e,r=i[t].slide)}n=r?o.indexOf(r):o.length-1}else for(let i=0;i<o.length;i++){const r=o[i].getBoundingClientRect().left-t.left+e+M();if(Math.floor(r)>=Math.floor(e)){n=i;break}i===o.length-1&&(l=!0)}l&&(n=o.length-1);const i=a.activeSlideIdx;a.activeSlideIdx=n,i!==n&&a.emit("activeSlideChanged")}function m(){return a.options.rtl?Math.abs(a.container.scrollLeft):a.container.scrollLeft}function M(){let t=0;if(a.slides.length>1){const e=a.slides[0].getBoundingClientRect(),o=a.slides[1].getBoundingClientRect();t=a.options.rtl?Math.abs(Math.floor(o.right-e.left)):Math.floor(o.left-e.right)}return t}function p(){let t=0;const e=a.container.getAttribute("data-full-width-offset");return e&&(t=parseInt(e)),Math.floor(t)}return a={emit:function(t){var e;s&&s[t]&&s[t].forEach((t=>{t(a)}));const o=null===(e=null==a?void 0:a.options)||void 0===e?void 0:e[t];"function"==typeof o&&o(a)},moveToDirection:function(t="prev"){const e=a.options.scrollStrategy,o=a.container.scrollLeft,n=a.container.getBoundingClientRect(),l=a.container.offsetWidth;let i=o;const r=a.options.rtl?"prev"===t?"next":"prev":t;if("prev"===r?i=Math.max(0,o-a.container.offsetWidth):"next"===r&&(i=Math.min(a.getInclusiveScrollWidth(),o+a.container.offsetWidth)),"fullSlide"===e){let t=null;if(t="prev"===r?Math.max(0,i-M()):Math.min(a.getInclusiveScrollWidth(),i+M()),"next"===r){let e=!1;for(let l of a.slides){const r=l.getBoundingClientRect(),a=r.left-n.left+o,s=a+r.width;if(Math.floor(a)<Math.floor(i)&&Math.floor(s)>Math.floor(i)){t=a,e=!0;break}}if(e||(t=Math.min(i,a.getInclusiveScrollWidth()-a.container.offsetWidth)),t)if(Math.floor(t)>Math.floor(o)){const e=Math.floor(a.getInclusiveScrollWidth())-Math.floor(l);i=Math.min(t,e)}else i=Math.min(a.getInclusiveScrollWidth(),o+l)}else{let e=!1;for(let i of a.slides){const r=i.getBoundingClientRect(),a=r.left-n.left+o,s=a+r.width;if(Math.floor(a)<Math.floor(o)&&Math.floor(s)>Math.floor(o)){t=s-l,e=!0;break}}e||(t=Math.max(0,o-l)),t&&Math.floor(t)<Math.floor(o)&&(i=t)}}const s=i-p();Math.floor(s)>=0&&(i=s),a.emit("programmaticScrollStart"),a.container.style.scrollBehavior=a.options.scrollBehavior,a.container.scrollLeft=i,setTimeout((()=>a.container.style.scrollBehavior=""),50)},moveToSlide:function(t){const e=a.slides[t];e&&u(e)},snapToClosestSlide:function(t="prev"){const e=a.options.rtl?"prev"===t:"next"===t,o=[];for(let t=0;t<a.slides.length;t++){const e=a.slides[t],n=e.offsetWidth,l=a.options.rtl?Math.abs(e.offsetLeft+n-a.details.containerWidth):e.offsetLeft,i=l+n,r=l+n/2,s=Math.min(r,l+a.options.emulateScrollSnapMaxThreshold);o.push({start:l,middle:r,end:i,width:n,trigger:s,slide:e,offSetleft:e.offsetLeft,rect:e.getBoundingClientRect()})}console.log("slideReference",o);let n=null;const l=m();if(e)for(let t=0;t<o.length;t++){const e=o[t];if(0===t&&Math.floor(l)<=Math.floor(e.trigger)){n=0;break}if(Math.floor(m())<=Math.floor(e.trigger)){n=e.start;break}}else for(let t=o.length-1;t>=0;t--){const e=o[t];if(t===o.length-1&&Math.floor(l)>=Math.floor(e.trigger)){n=e.start;break}if(Math.floor(m())>=Math.floor(e.trigger)){n=e.start;break}}if(null!==n){const t=n-p();Math.floor(t)>=0&&(n=t);const e=a.options.scrollBehavior||"smooth";a.container.scrollTo({left:a.options.rtl?-n:n,behavior:e})}},getInclusiveScrollWidth:function(){return a.container.scrollWidth+n(a.container)},getInclusiveClientWidth:function(){return a.container.clientWidth+n(a.container)},getScrollLeft:m,setScrollLeft:function(t){a.container.scrollLeft=a.options.rtl?-t:t},on:function(t,e){s[t]||(s[t]=[]),s[t].push(e)},options:i},function(){a.container=l;let t=l.getAttribute("id");null===t&&(t=e("overflow-slider"),l.setAttribute("id",t)),f(),c(!0),g(),a.on("contentsChanged",(()=>{f(),c(),g()})),a.on("containerSizeChanged",(()=>c()));let o=0;if(a.on("scroll",(()=>{o&&window.cancelAnimationFrame(o),o=window.requestAnimationFrame((()=>{c(),g()}))})),function(){new MutationObserver((()=>a.emit("contentsChanged"))).observe(a.container,{childList:!0});let t,e,o;new ResizeObserver((()=>a.emit("containerSizeChanged"))).observe(a.container);let n=a.container.scrollLeft,l=a.container.scrollLeft,i=a.container.scrollLeft,r=!1,s=!1,c=!1;a.container.addEventListener("scroll",(()=>{const e=a.container.scrollLeft;Math.floor(n)!==Math.floor(e)&&(r||(r=!0,a.emit("scrollStart")),n=e,clearTimeout(t),t=setTimeout((()=>{r=!1,a.emit("scrollEnd")}),50),a.emit("scroll")),s&&f()}));const f=()=>{const t=a.container.scrollLeft;Math.floor(l)===Math.floor(t)||c||(s||(a.emit("nativeScrollStart"),s=!0),a.emit("nativeScroll"),l=t,clearTimeout(e),e=setTimeout((()=>{s=!1,a.emit("nativeScrollEnd"),i=l}),50))};a.container.addEventListener("touchmove",f),a.container.addEventListener("mousewheel",f),a.container.addEventListener("wheel",f),a.on("programmaticScrollStart",(()=>{c=!0})),a.container.addEventListener("scroll",(()=>{const t=a.container.scrollLeft;Math.floor(i)!==Math.floor(t)&&!s&&c&&(i=t,clearTimeout(o),o=setTimeout((()=>{c=!1,a.emit("programmaticScrollEnd"),l=i}),50),a.emit("programmaticScroll"))})),a.on("programmaticScrollStart",(()=>{a.container.style.scrollSnapType="none"})),a.on("nativeScrollStart",(()=>{a.container.style.scrollSnapType=""}));let d=!1;a.container.addEventListener("mousedown",(()=>{d=!0})),a.container.addEventListener("touchstart",(()=>{d=!0}),{passive:!0}),a.container.addEventListener("focusin",(t=>{if(!d){let e=t.target;for(;e.parentElement!==a.container&&e.parentElement;)e=e.parentElement;u(e,"auto")}d=!1}))}(),h(),d(),r)for(const t of r)t(a);a.on("detailsChanged",(()=>{h(),d()})),a.emit("created"),a.container.setAttribute("data-ready","true")}(),a}export{l as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.overflow-slider{-ms-overflow-style:none;display:grid;grid-auto-flow:column;grid-template-columns:max-content;max-width:-moz-max-content;max-width:max-content;overflow:auto;position:relative;scrollbar-width:none;width:100%}.overflow-slider::-webkit-scrollbar{display:none}.overflow-slider>*{outline-offset:-2px;scroll-snap-align:start}:root{--overflow-slider-arrows-size:1.5rem;--overflow-slider-arrows-gap:.5rem;--overflow-slider-arrows-inactive-opacity:0.5}.overflow-slider__arrows{display:flex;gap:var(--overflow-slider-arrows-gap)}.overflow-slider__arrows-button{align-items:center;cursor:pointer;display:flex;outline-offset:-2px}.overflow-slider__arrows-button svg{height:var(--overflow-slider-arrows-size);width:var(--overflow-slider-arrows-size)}.overflow-slider__arrows-button[data-has-content=false]{opacity:var(--overflow-slider-arrows-inactive-opacity)}:root{--overflow-slider-dots-gap:0.5rem;--overflow-slider-dot-size:0.75rem;--overflow-slider-dot-inactive-color:rgba(0,0,0,.1);--overflow-slider-dot-active-color:rgba(0,0,0,.8)}.overflow-slider__dots{align-items:center;display:flex;justify-content:center}.overflow-slider__dots ul{display:flex;flex-wrap:wrap;gap:var(--overflow-slider-dots-gap);list-style:none;margin:0;padding:0}.overflow-slider__dots li{line-height:0;margin:0;padding:0}.overflow-slider__dot-item{background:var(--overflow-slider-dot-inactive-color);border-radius:50%;cursor:pointer;height:var(--overflow-slider-dot-size);margin:0;outline-offset:2px;padding:0;position:relative;width:var(--overflow-slider-dot-size)}.overflow-slider__dot-item:after{bottom:calc(var(--overflow-slider-dots-gap)*-1);content:"";display:block;left:calc(var(--overflow-slider-dots-gap)*-1);position:absolute;right:calc(var(--overflow-slider-dots-gap)*-1);top:calc(var(--overflow-slider-dots-gap)*-1)}.overflow-slider__dot-item:focus,.overflow-slider__dot-item:hover,.overflow-slider__dot-item[aria-pressed=true]{background:var(--overflow-slider-dot-active-color)}:root{--overflow-slider-fade-color:#fff;--overflow-slider-fade-width:3rem}.overflow-slider-fade{height:100%;pointer-events:none;position:absolute;top:0;width:var(--overflow-slider-fade-width);z-index:1}.overflow-slider-fade--start{background:linear-gradient(to right,var(--overflow-slider-fade-color) 0,transparent 100%);left:0}.overflow-slider-fade--end{background:linear-gradient(to left,var(--overflow-slider-fade-color) 0,transparent 100%);right:0}[data-has-drag-scrolling][data-has-overflow=true]{cursor:grab;-webkit-user-select:none;-moz-user-select:none;user-select:none}:root{--overflow-slider-scroll-indicator-button-height:4px;--overflow-slider-scroll-indicator-padding:1rem;--overflow-slider-scroll-indicator-button-color:rgba(0,0,0,.75);--overflow-slider-scroll-indicator-bar-color:rgba(0,0,0,.25)}.overflow-slider__scroll-indicator{cursor:pointer;outline:0;padding-block:var(--overflow-slider-scroll-indicator-padding);position:relative;width:100%}.overflow-slider__scroll-indicator[data-has-overflow=false]{display:none}.overflow-slider__scroll-indicator:focus-visible .overflow-slider__scroll-indicator-button{outline:2px solid;outline-offset:2px}.overflow-slider__scroll-indicator-bar{background:var(--overflow-slider-scroll-indicator-bar-color);border-radius:3px;height:2px;left:0;position:absolute;top:50%;transform:translateY(-50%);width:100%}.overflow-slider__scroll-indicator-button{background:var(--overflow-slider-scroll-indicator-button-color);border-radius:3px;cursor:grab;height:var(--overflow-slider-scroll-indicator-button-height);left:0;position:absolute;top:calc(50% - var(--overflow-slider-scroll-indicator-button-height)/2)}.overflow-slider__scroll-indicator-button:hover,.overflow-slider__scroll-indicator-button[data-is-grabbed=true]{--overflow-slider-scroll-indicator-button-height:6px}.overflow-slider__scroll-indicator-button:after{bottom:calc(var(--overflow-slider-scroll-indicator-padding)*-1);content:"";display:block;position:absolute;top:calc(var(--overflow-slider-scroll-indicator-padding)*-1);width:100%}
|
|
1
|
+
.overflow-slider{-ms-overflow-style:none;display:grid;grid-auto-flow:column;grid-template-columns:max-content;max-width:-moz-max-content;max-width:max-content;overflow:auto;position:relative;scrollbar-width:none;width:100%}.overflow-slider::-webkit-scrollbar{display:none}.overflow-slider>*{outline-offset:-2px;scroll-snap-align:start}:root{--overflow-slider-arrows-size:1.5rem;--overflow-slider-arrows-gap:.5rem;--overflow-slider-arrows-inactive-opacity:0.5}.overflow-slider__arrows{display:flex;gap:var(--overflow-slider-arrows-gap)}.overflow-slider__arrows-button{align-items:center;cursor:pointer;display:flex;outline-offset:-2px}.overflow-slider__arrows-button svg{height:var(--overflow-slider-arrows-size);width:var(--overflow-slider-arrows-size)}.overflow-slider__arrows-button[data-has-content=false]{opacity:var(--overflow-slider-arrows-inactive-opacity)}:root{--overflow-slider-dots-gap:0.5rem;--overflow-slider-dot-size:0.75rem;--overflow-slider-dot-inactive-color:rgba(0,0,0,.1);--overflow-slider-dot-active-color:rgba(0,0,0,.8)}.overflow-slider__dots{align-items:center;display:flex;justify-content:center}.overflow-slider__dots ul{display:flex;flex-wrap:wrap;gap:var(--overflow-slider-dots-gap);list-style:none;margin:0;padding:0}.overflow-slider__dots li{line-height:0;margin:0;padding:0}.overflow-slider__dot-item{background:var(--overflow-slider-dot-inactive-color);border-radius:50%;cursor:pointer;height:var(--overflow-slider-dot-size);margin:0;outline-offset:2px;padding:0;position:relative;width:var(--overflow-slider-dot-size)}.overflow-slider__dot-item:after{bottom:calc(var(--overflow-slider-dots-gap)*-1);content:"";display:block;left:calc(var(--overflow-slider-dots-gap)*-1);position:absolute;right:calc(var(--overflow-slider-dots-gap)*-1);top:calc(var(--overflow-slider-dots-gap)*-1)}.overflow-slider__dot-item:focus,.overflow-slider__dot-item:hover,.overflow-slider__dot-item[aria-pressed=true]{background:var(--overflow-slider-dot-active-color)}:root{--overflow-slider-fade-color:#fff;--overflow-slider-fade-width:3rem}.overflow-slider-fade{height:100%;pointer-events:none;position:absolute;top:0;width:var(--overflow-slider-fade-width);z-index:1}.overflow-slider-fade--start{background:linear-gradient(to right,var(--overflow-slider-fade-color) 0,transparent 100%);left:0}[dir=rtl] .overflow-slider-fade--start{left:auto}.overflow-slider-fade--end,[dir=rtl] .overflow-slider-fade--start{background:linear-gradient(to left,var(--overflow-slider-fade-color) 0,transparent 100%);right:0}[dir=rtl] .overflow-slider-fade--end{background:linear-gradient(to right,var(--overflow-slider-fade-color) 0,transparent 100%);left:0;right:auto}[data-has-drag-scrolling][data-has-overflow=true]{cursor:grab;-webkit-user-select:none;-moz-user-select:none;user-select:none}:root{--overflow-slider-scroll-indicator-button-height:4px;--overflow-slider-scroll-indicator-padding:1rem;--overflow-slider-scroll-indicator-button-color:rgba(0,0,0,.75);--overflow-slider-scroll-indicator-bar-color:rgba(0,0,0,.25)}.overflow-slider__scroll-indicator{cursor:pointer;outline:0;padding-block:var(--overflow-slider-scroll-indicator-padding);position:relative;width:100%}.overflow-slider__scroll-indicator[data-has-overflow=false]{display:none}.overflow-slider__scroll-indicator:focus-visible .overflow-slider__scroll-indicator-button{outline:2px solid;outline-offset:2px}.overflow-slider__scroll-indicator-bar{background:var(--overflow-slider-scroll-indicator-bar-color);border-radius:3px;height:2px;left:0;position:absolute;top:50%;transform:translateY(-50%);width:100%}.overflow-slider__scroll-indicator-button{background:var(--overflow-slider-scroll-indicator-button-color);border-radius:3px;cursor:grab;height:var(--overflow-slider-scroll-indicator-button-height);left:0;position:absolute;top:calc(50% - var(--overflow-slider-scroll-indicator-button-height)/2)}.overflow-slider__scroll-indicator-button:hover,.overflow-slider__scroll-indicator-button[data-is-grabbed=true]{--overflow-slider-scroll-indicator-button-height:6px}.overflow-slider__scroll-indicator-button:after{bottom:calc(var(--overflow-slider-scroll-indicator-padding)*-1);content:"";display:block;position:absolute;top:calc(var(--overflow-slider-scroll-indicator-padding)*-1);width:100%}
|
|
@@ -30,7 +30,7 @@ function ArrowsPlugin(args) {
|
|
|
30
30
|
prev.setAttribute('aria-label', options.texts.buttonPrevious);
|
|
31
31
|
prev.setAttribute('aria-controls', (_d = slider.container.getAttribute('id')) !== null && _d !== void 0 ? _d : '');
|
|
32
32
|
prev.setAttribute('data-type', 'prev');
|
|
33
|
-
prev.innerHTML = options.icons.prev;
|
|
33
|
+
prev.innerHTML = slider.options.rtl ? options.icons.next : options.icons.prev;
|
|
34
34
|
prev.addEventListener('click', () => {
|
|
35
35
|
if (prev.getAttribute('data-has-content') === 'true') {
|
|
36
36
|
slider.moveToDirection('prev');
|
|
@@ -42,7 +42,7 @@ function ArrowsPlugin(args) {
|
|
|
42
42
|
next.setAttribute('aria-label', options.texts.buttonNext);
|
|
43
43
|
next.setAttribute('aria-controls', (_e = slider.container.getAttribute('id')) !== null && _e !== void 0 ? _e : '');
|
|
44
44
|
next.setAttribute('data-type', 'next');
|
|
45
|
-
next.innerHTML = options.icons.next;
|
|
45
|
+
next.innerHTML = slider.options.rtl ? options.icons.prev : options.icons.next;
|
|
46
46
|
next.addEventListener('click', () => {
|
|
47
47
|
if (next.getAttribute('data-has-content') === 'true') {
|
|
48
48
|
slider.moveToDirection('next');
|
|
@@ -52,21 +52,24 @@ function ArrowsPlugin(args) {
|
|
|
52
52
|
nav.appendChild(prev);
|
|
53
53
|
nav.appendChild(next);
|
|
54
54
|
const update = () => {
|
|
55
|
-
const scrollLeft = slider.
|
|
55
|
+
const scrollLeft = slider.getScrollLeft();
|
|
56
56
|
const scrollWidth = slider.getInclusiveScrollWidth();
|
|
57
57
|
const clientWidth = slider.getInclusiveClientWidth();
|
|
58
|
+
const buffer = 1;
|
|
58
59
|
if (Math.floor(scrollLeft) === 0) {
|
|
59
60
|
prev.setAttribute('data-has-content', 'false');
|
|
60
61
|
}
|
|
61
62
|
else {
|
|
62
63
|
prev.setAttribute('data-has-content', 'true');
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
+
const maxWidthDifference = Math.abs(Math.floor(scrollLeft + clientWidth) - Math.floor(scrollWidth));
|
|
66
|
+
if (maxWidthDifference <= buffer) {
|
|
65
67
|
next.setAttribute('data-has-content', 'false');
|
|
66
68
|
}
|
|
67
69
|
else {
|
|
68
70
|
next.setAttribute('data-has-content', 'true');
|
|
69
71
|
}
|
|
72
|
+
console.log('next', scrollLeft + clientWidth, scrollWidth);
|
|
70
73
|
};
|
|
71
74
|
if (options.containerNext && options.containerPrev) {
|
|
72
75
|
options.containerPrev.appendChild(prev);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const t={buttonPrevious:"Previous items",buttonNext:"Next items"},e={prev:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.6 3.4l-7.6 7.6 7.6 7.6 1.4-1.4-5-5h12.6v-2h-12.6l5-5z"/></svg>',next:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.4 3.4l-1.4 1.4 5 5h-12.6v2h12.6l-5 5 1.4 1.4 7.6-7.6z"/></svg>'},n={navContainer:"overflow-slider__arrows",prevButton:"overflow-slider__arrows-button overflow-slider__arrows-button--prev",nextButton:"overflow-slider__arrows-button overflow-slider__arrows-button--next"};function o(o){return
|
|
1
|
+
const t={buttonPrevious:"Previous items",buttonNext:"Next items"},e={prev:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.6 3.4l-7.6 7.6 7.6 7.6 1.4-1.4-5-5h12.6v-2h-12.6l5-5z"/></svg>',next:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.4 3.4l-1.4 1.4 5 5h-12.6v2h12.6l-5 5 1.4 1.4 7.6-7.6z"/></svg>'},n={navContainer:"overflow-slider__arrows",prevButton:"overflow-slider__arrows-button overflow-slider__arrows-button--prev",nextButton:"overflow-slider__arrows-button overflow-slider__arrows-button--next"};function o(o){return s=>{var i,r,a,l,c,u;const d={texts:Object.assign(Object.assign({},t),(null==o?void 0:o.texts)||[]),icons:Object.assign(Object.assign({},e),(null==o?void 0:o.icons)||[]),classNames:Object.assign(Object.assign({},n),(null==o?void 0:o.classNames)||[]),container:null!==(i=null==o?void 0:o.container)&&void 0!==i?i:null,containerPrev:null!==(r=null==o?void 0:o.containerPrev)&&void 0!==r?r:null,containerNext:null!==(a=null==o?void 0:o.containerNext)&&void 0!==a?a:null},v=document.createElement("div");v.classList.add(d.classNames.navContainer);const b=document.createElement("button");b.setAttribute("class",d.classNames.prevButton),b.setAttribute("type","button"),b.setAttribute("aria-label",d.texts.buttonPrevious),b.setAttribute("aria-controls",null!==(l=s.container.getAttribute("id"))&&void 0!==l?l:""),b.setAttribute("data-type","prev"),b.innerHTML=s.options.rtl?d.icons.next:d.icons.prev,b.addEventListener("click",(()=>{"true"===b.getAttribute("data-has-content")&&s.moveToDirection("prev")}));const p=document.createElement("button");p.setAttribute("class",d.classNames.nextButton),p.setAttribute("type","button"),p.setAttribute("aria-label",d.texts.buttonNext),p.setAttribute("aria-controls",null!==(c=s.container.getAttribute("id"))&&void 0!==c?c:""),p.setAttribute("data-type","next"),p.innerHTML=s.options.rtl?d.icons.prev:d.icons.next,p.addEventListener("click",(()=>{"true"===p.getAttribute("data-has-content")&&s.moveToDirection("next")})),v.appendChild(b),v.appendChild(p);const h=()=>{const t=s.getScrollLeft(),e=s.getInclusiveScrollWidth(),n=s.getInclusiveClientWidth();0===Math.floor(t)?b.setAttribute("data-has-content","false"):b.setAttribute("data-has-content","true");Math.abs(Math.floor(t+n)-Math.floor(e))<=1?p.setAttribute("data-has-content","false"):p.setAttribute("data-has-content","true"),console.log("next",t+n,e)};d.containerNext&&d.containerPrev?(d.containerPrev.appendChild(b),d.containerNext.appendChild(p)):d.container?d.container.appendChild(v):null===(u=s.container.parentNode)||void 0===u||u.insertBefore(v,s.container.nextSibling),h(),s.on("scrollEnd",h),s.on("contentsChanged",h),s.on("containerSizeChanged",h)}}export{o as default};
|
|
@@ -76,10 +76,6 @@ function DotsPlugin(args) {
|
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
const activateDot = (item) => {
|
|
79
|
-
// const scrollTargetPosition = slider.details.containerWidth * ( page - 1 );
|
|
80
|
-
// slider.container.style.scrollBehavior = slider.options.scrollBehavior;
|
|
81
|
-
// slider.container.scrollLeft = scrollTargetPosition;
|
|
82
|
-
// slider.container.style.scrollBehavior = '';
|
|
83
79
|
slider.moveToSlide(item - 1);
|
|
84
80
|
};
|
|
85
81
|
buildDots();
|