@evermade/overflow-slider 3.3.1 → 4.0.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/.nvmrc +1 -1
- package/README.md +115 -29
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +609 -1
- package/dist/index.esm.js.map +1 -0
- package/dist/index.min.js +2 -1
- package/dist/index.min.js.map +1 -0
- package/dist/mixins.scss +14 -0
- package/dist/overflow-slider.css +1 -1
- package/dist/plugins/arrows/index.d.ts +26 -0
- package/dist/plugins/arrows/index.min.js +1 -1
- package/dist/plugins/autoplay/index.d.ts +41 -0
- package/dist/plugins/autoplay/index.esm.js +233 -0
- package/dist/plugins/autoplay/index.min.js +1 -0
- package/dist/plugins/core/index.d.ts +75 -0
- package/dist/plugins/core/index.d2.ts +23 -0
- package/dist/plugins/dots/index.d.ts +16 -0
- package/dist/plugins/dots/index.min.js +1 -1
- package/dist/plugins/drag-scrolling/index.d.ts +9 -0
- package/dist/plugins/drag-scrolling/index.esm.js +2 -2
- package/dist/plugins/drag-scrolling/index.min.js +1 -1
- package/dist/plugins/fade/index.d.ts +16 -0
- package/dist/plugins/fade/index.min.js +1 -1
- package/dist/plugins/full-width/index.d.ts +11 -0
- package/dist/plugins/full-width/index.esm.js +14 -3
- package/dist/plugins/full-width/index.min.js +1 -1
- package/dist/plugins/infinite-scroll/index.d.ts +25 -0
- package/dist/plugins/infinite-scroll/index.esm.js +75 -0
- package/dist/plugins/infinite-scroll/index.min.js +1 -0
- package/dist/plugins/scroll-indicator/index.d.ts +14 -0
- package/dist/plugins/scroll-indicator/index.esm.js +3 -1
- package/dist/plugins/scroll-indicator/index.min.js +1 -1
- package/dist/plugins/skip-links/index.d.ts +17 -0
- package/dist/plugins/skip-links/index.esm.js +7 -1
- package/dist/plugins/skip-links/index.min.js +1 -1
- package/dist/plugins/thumbnails/index.d.ts +9 -0
- package/dist/plugins/thumbnails/index.min.js +1 -1
- package/dist/{core/utils.min.js → utils-Sxwcz8zp.js} +1 -1
- package/dist/{core/utils.esm.js → utils-ayDxlweP.js} +1 -1
- package/docs/assets/demo.css +115 -0
- package/docs/assets/demo.js +68 -0
- package/docs/dist/index.d.ts +1 -0
- package/docs/dist/index.esm.js +609 -1
- package/docs/dist/index.esm.js.map +1 -0
- package/docs/dist/index.min.js +2 -1
- package/docs/dist/index.min.js.map +1 -0
- package/docs/dist/mixins.scss +14 -0
- package/docs/dist/overflow-slider.css +1 -1
- package/docs/dist/plugins/arrows/index.d.ts +26 -0
- package/docs/dist/plugins/arrows/index.min.js +1 -1
- package/docs/dist/plugins/autoplay/index.d.ts +41 -0
- package/docs/dist/plugins/autoplay/index.esm.js +233 -0
- package/docs/dist/plugins/autoplay/index.min.js +1 -0
- package/docs/dist/plugins/core/index.d.ts +23 -0
- package/docs/dist/plugins/core/index.d2.ts +75 -0
- package/docs/dist/plugins/dots/index.d.ts +16 -0
- package/docs/dist/plugins/dots/index.min.js +1 -1
- package/docs/dist/plugins/drag-scrolling/index.d.ts +9 -0
- package/docs/dist/plugins/drag-scrolling/index.esm.js +2 -2
- package/docs/dist/plugins/drag-scrolling/index.min.js +1 -1
- package/docs/dist/plugins/fade/index.d.ts +16 -0
- package/docs/dist/plugins/fade/index.min.js +1 -1
- package/docs/dist/plugins/full-width/index.d.ts +11 -0
- package/docs/dist/plugins/full-width/index.esm.js +14 -3
- package/docs/dist/plugins/full-width/index.min.js +1 -1
- package/docs/dist/plugins/infinite-scroll/index.d.ts +25 -0
- package/docs/dist/plugins/infinite-scroll/index.esm.js +75 -0
- package/docs/dist/plugins/infinite-scroll/index.min.js +1 -0
- package/docs/dist/plugins/scroll-indicator/index.d.ts +14 -0
- package/docs/dist/plugins/scroll-indicator/index.esm.js +3 -1
- package/docs/dist/plugins/scroll-indicator/index.min.js +1 -1
- package/docs/dist/plugins/skip-links/index.d.ts +17 -0
- package/docs/dist/plugins/skip-links/index.esm.js +7 -1
- package/docs/dist/plugins/skip-links/index.min.js +1 -1
- package/docs/dist/plugins/thumbnails/index.d.ts +9 -0
- package/docs/dist/plugins/thumbnails/index.min.js +1 -1
- package/docs/dist/{core/utils.min.js → utils-Sxwcz8zp.js} +1 -1
- package/docs/dist/{core/utils.esm.js → utils-ayDxlweP.js} +1 -1
- package/docs/index-rtl.html +78 -2
- package/docs/index.html +77 -1
- package/package.json +50 -27
- package/rollup.config.js +90 -66
- package/src/core/details.ts +4 -0
- package/src/core/overflow-slider.ts +4 -2
- package/src/core/slider.ts +91 -64
- package/src/core/types.ts +29 -1
- package/src/mixins.scss +14 -0
- package/src/overflow-slider.scss +12 -10
- package/src/plugins/arrows/index.ts +2 -2
- package/src/plugins/autoplay/index.ts +276 -0
- package/src/plugins/autoplay/styles.scss +11 -0
- package/src/plugins/dots/index.ts +2 -2
- package/src/plugins/drag-scrolling/index.ts +4 -4
- package/src/plugins/fade/index.ts +2 -2
- package/src/plugins/full-width/index.ts +17 -5
- package/src/plugins/infinite-scroll/index.ts +109 -0
- package/src/plugins/scroll-indicator/index.ts +5 -3
- package/src/plugins/skip-links/index.ts +2 -2
- package/src/plugins/thumbnails/index.ts +2 -2
- package/tsconfig.json +4 -2
- package/changelog.md +0 -5
- package/dist/core/details.esm.js +0 -35
- package/dist/core/details.min.js +0 -1
- package/dist/core/overflow-slider.esm.js +0 -29
- package/dist/core/overflow-slider.min.js +0 -1
- package/dist/core/slider.esm.js +0 -499
- package/dist/core/slider.min.js +0 -1
- package/docs/dist/core/details.esm.js +0 -35
- package/docs/dist/core/details.min.js +0 -1
- package/docs/dist/core/overflow-slider.esm.js +0 -29
- package/docs/dist/core/overflow-slider.min.js +0 -1
- package/docs/dist/core/slider.esm.js +0 -499
- package/docs/dist/core/slider.min.js +0 -1
package/dist/core/slider.esm.js
DELETED
|
@@ -1,499 +0,0 @@
|
|
|
1
|
-
import details from './details.esm.js';
|
|
2
|
-
import { generateId, objectsAreEqual, getOutermostChildrenEdgeMarginSum } from './utils.esm.js';
|
|
3
|
-
|
|
4
|
-
function Slider(container, options, plugins) {
|
|
5
|
-
let slider;
|
|
6
|
-
let subs = {};
|
|
7
|
-
function init() {
|
|
8
|
-
slider.container = container;
|
|
9
|
-
// ensure container has id
|
|
10
|
-
let containerId = container.getAttribute('id');
|
|
11
|
-
if (containerId === null) {
|
|
12
|
-
containerId = generateId('overflow-slider');
|
|
13
|
-
container.setAttribute('id', containerId);
|
|
14
|
-
}
|
|
15
|
-
setSlides();
|
|
16
|
-
setDetails(true);
|
|
17
|
-
setActiveSlideIdx();
|
|
18
|
-
slider.on('contentsChanged', () => {
|
|
19
|
-
setSlides();
|
|
20
|
-
setDetails();
|
|
21
|
-
setActiveSlideIdx();
|
|
22
|
-
});
|
|
23
|
-
slider.on('containerSizeChanged', () => setDetails());
|
|
24
|
-
let requestId = 0;
|
|
25
|
-
const setDetailsDebounce = () => {
|
|
26
|
-
if (requestId) {
|
|
27
|
-
window.cancelAnimationFrame(requestId);
|
|
28
|
-
}
|
|
29
|
-
requestId = window.requestAnimationFrame(() => {
|
|
30
|
-
setDetails();
|
|
31
|
-
setActiveSlideIdx();
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
slider.on('scroll', setDetailsDebounce);
|
|
35
|
-
addEventListeners();
|
|
36
|
-
setDataAttributes();
|
|
37
|
-
setCSSVariables();
|
|
38
|
-
if (plugins) {
|
|
39
|
-
for (const plugin of plugins) {
|
|
40
|
-
plugin(slider);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
slider.on('detailsChanged', () => {
|
|
44
|
-
setDataAttributes();
|
|
45
|
-
setCSSVariables();
|
|
46
|
-
});
|
|
47
|
-
slider.emit('created');
|
|
48
|
-
slider.container.setAttribute('data-ready', 'true');
|
|
49
|
-
}
|
|
50
|
-
function setDetails(isInit = false) {
|
|
51
|
-
const oldDetails = slider.details;
|
|
52
|
-
const newDetails = details(slider);
|
|
53
|
-
slider.details = newDetails;
|
|
54
|
-
if (!isInit && !objectsAreEqual(oldDetails, newDetails)) {
|
|
55
|
-
slider.emit('detailsChanged');
|
|
56
|
-
}
|
|
57
|
-
else if (isInit) {
|
|
58
|
-
slider.emit('detailsChanged');
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function setSlides() {
|
|
62
|
-
slider.slides = Array.from(slider.container.querySelectorAll(slider.options.slidesSelector));
|
|
63
|
-
}
|
|
64
|
-
function addEventListeners() {
|
|
65
|
-
// changes to DOM
|
|
66
|
-
const observer = new MutationObserver(() => slider.emit('contentsChanged'));
|
|
67
|
-
observer.observe(slider.container, { childList: true });
|
|
68
|
-
// container size changes
|
|
69
|
-
const resizeObserver = new ResizeObserver(() => slider.emit('containerSizeChanged'));
|
|
70
|
-
resizeObserver.observe(slider.container);
|
|
71
|
-
// scroll event with debouncing
|
|
72
|
-
let scrollTimeout;
|
|
73
|
-
let nativeScrollTimeout;
|
|
74
|
-
let programmaticScrollTimeout;
|
|
75
|
-
let scrollLeft = slider.container.scrollLeft;
|
|
76
|
-
let nativeScrollLeft = slider.container.scrollLeft;
|
|
77
|
-
let programmaticScrollLeft = slider.container.scrollLeft;
|
|
78
|
-
let isScrolling = false;
|
|
79
|
-
let isUserScrolling = false;
|
|
80
|
-
let isProgrammaticScrolling = false;
|
|
81
|
-
// all types of scroll
|
|
82
|
-
slider.container.addEventListener('scroll', () => {
|
|
83
|
-
const newScrollLeft = slider.container.scrollLeft;
|
|
84
|
-
if (Math.floor(scrollLeft) !== Math.floor(newScrollLeft)) {
|
|
85
|
-
if (!isScrolling) {
|
|
86
|
-
isScrolling = true;
|
|
87
|
-
slider.emit('scrollStart');
|
|
88
|
-
}
|
|
89
|
-
scrollLeft = newScrollLeft;
|
|
90
|
-
clearTimeout(scrollTimeout);
|
|
91
|
-
scrollTimeout = setTimeout(() => {
|
|
92
|
-
isScrolling = false;
|
|
93
|
-
slider.emit('scrollEnd');
|
|
94
|
-
}, 50);
|
|
95
|
-
slider.emit('scroll');
|
|
96
|
-
}
|
|
97
|
-
// keep up nativeScrolling to take into account scroll-snap
|
|
98
|
-
if (isUserScrolling) {
|
|
99
|
-
nativeScrollHandler();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
// user initted scroll (touchmove, mouse wheel, etc.)
|
|
103
|
-
const nativeScrollHandler = () => {
|
|
104
|
-
const newScrollLeft = slider.container.scrollLeft;
|
|
105
|
-
if (Math.floor(nativeScrollLeft) !== Math.floor(newScrollLeft) && !isProgrammaticScrolling) {
|
|
106
|
-
if (!isUserScrolling) {
|
|
107
|
-
slider.emit('nativeScrollStart');
|
|
108
|
-
isUserScrolling = true;
|
|
109
|
-
}
|
|
110
|
-
slider.emit('nativeScroll');
|
|
111
|
-
nativeScrollLeft = newScrollLeft;
|
|
112
|
-
clearTimeout(nativeScrollTimeout);
|
|
113
|
-
nativeScrollTimeout = setTimeout(() => {
|
|
114
|
-
isUserScrolling = false;
|
|
115
|
-
slider.emit('nativeScrollEnd');
|
|
116
|
-
// update programmaticScrollLeft to match nativeScrollLeft
|
|
117
|
-
// this prevents programmaticScroll triggering with no real change to scrollLeft
|
|
118
|
-
programmaticScrollLeft = nativeScrollLeft;
|
|
119
|
-
}, 50);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
slider.container.addEventListener('touchmove', nativeScrollHandler);
|
|
123
|
-
slider.container.addEventListener('mousewheel', nativeScrollHandler);
|
|
124
|
-
slider.container.addEventListener('wheel', nativeScrollHandler);
|
|
125
|
-
// programmatic scroll (scrollTo, etc.)
|
|
126
|
-
slider.on('programmaticScrollStart', () => {
|
|
127
|
-
isProgrammaticScrolling = true;
|
|
128
|
-
});
|
|
129
|
-
slider.container.addEventListener('scroll', () => {
|
|
130
|
-
const newScrollLeft = slider.container.scrollLeft;
|
|
131
|
-
if (Math.floor(programmaticScrollLeft) !== Math.floor(newScrollLeft) && !isUserScrolling && isProgrammaticScrolling) {
|
|
132
|
-
programmaticScrollLeft = newScrollLeft;
|
|
133
|
-
clearTimeout(programmaticScrollTimeout);
|
|
134
|
-
programmaticScrollTimeout = setTimeout(() => {
|
|
135
|
-
isProgrammaticScrolling = false;
|
|
136
|
-
slider.emit('programmaticScrollEnd');
|
|
137
|
-
// update nativeScrollLeft to match programmaticScrollLeft
|
|
138
|
-
// this prevents nativeScroll triggering with no real change to scrollLeft
|
|
139
|
-
nativeScrollLeft = programmaticScrollLeft;
|
|
140
|
-
}, 50);
|
|
141
|
-
slider.emit('programmaticScroll');
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
// Fix issues on scroll snapping not working on programmatic scroll (it's not smooth)
|
|
145
|
-
// by disabling scroll snap if scrolling is programmatic
|
|
146
|
-
slider.on('programmaticScrollStart', () => {
|
|
147
|
-
slider.container.style.scrollSnapType = 'none';
|
|
148
|
-
});
|
|
149
|
-
// restore scroll snap if user scroll starts
|
|
150
|
-
slider.on('nativeScrollStart', () => {
|
|
151
|
-
slider.container.style.scrollSnapType = '';
|
|
152
|
-
});
|
|
153
|
-
// Listen for mouse down and touch start events on the document
|
|
154
|
-
// This handles both mouse clicks and touch interactions
|
|
155
|
-
let wasInteractedWith = false;
|
|
156
|
-
slider.container.addEventListener('mousedown', () => {
|
|
157
|
-
wasInteractedWith = true;
|
|
158
|
-
});
|
|
159
|
-
slider.container.addEventListener('touchstart', () => {
|
|
160
|
-
wasInteractedWith = true;
|
|
161
|
-
}, { passive: true });
|
|
162
|
-
slider.container.addEventListener('focusin', (e) => {
|
|
163
|
-
// move target parents as long as they are not the container
|
|
164
|
-
// but only if focus didn't start from mouse or touch
|
|
165
|
-
if (!wasInteractedWith) {
|
|
166
|
-
let target = e.target;
|
|
167
|
-
while (target.parentElement !== slider.container) {
|
|
168
|
-
if (target.parentElement) {
|
|
169
|
-
target = target.parentElement;
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
ensureSlideIsInView(target, 'auto');
|
|
176
|
-
}
|
|
177
|
-
wasInteractedWith = false;
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
function setCSSVariables() {
|
|
181
|
-
slider.container.style.setProperty('--slider-container-width', `${slider.details.containerWidth}px`);
|
|
182
|
-
slider.container.style.setProperty('--slider-scrollable-width', `${slider.details.scrollableAreaWidth}px`);
|
|
183
|
-
slider.container.style.setProperty('--slider-slides-count', `${slider.details.slideCount}`);
|
|
184
|
-
}
|
|
185
|
-
function setDataAttributes() {
|
|
186
|
-
slider.container.setAttribute('data-has-overflow', slider.details.hasOverflow ? 'true' : 'false');
|
|
187
|
-
if (slider.options.rtl) {
|
|
188
|
-
slider.container.setAttribute('dir', 'rtl');
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
function ensureSlideIsInView(slide, scrollBehavior = null) {
|
|
192
|
-
const behavior = scrollBehavior || slider.options.scrollBehavior;
|
|
193
|
-
const slideRect = slide.getBoundingClientRect();
|
|
194
|
-
const sliderRect = slider.container.getBoundingClientRect();
|
|
195
|
-
const containerWidth = slider.container.offsetWidth;
|
|
196
|
-
const scrollLeft = slider.container.scrollLeft;
|
|
197
|
-
const slideStart = slideRect.left - sliderRect.left + scrollLeft;
|
|
198
|
-
const slideEnd = slideStart + slideRect.width;
|
|
199
|
-
let scrollTarget = null;
|
|
200
|
-
if (Math.floor(slideStart) < Math.floor(scrollLeft)) {
|
|
201
|
-
scrollTarget = slideStart;
|
|
202
|
-
}
|
|
203
|
-
else if (Math.floor(slideEnd) > Math.floor(scrollLeft) + Math.floor(containerWidth)) {
|
|
204
|
-
scrollTarget = slideEnd - containerWidth;
|
|
205
|
-
}
|
|
206
|
-
else if (Math.floor(slideStart) === 0) {
|
|
207
|
-
scrollTarget = 0;
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
scrollTarget = slideStart;
|
|
211
|
-
}
|
|
212
|
-
if (scrollTarget !== null) {
|
|
213
|
-
setTimeout((scrollTarget) => {
|
|
214
|
-
slider.emit('programmaticScrollStart');
|
|
215
|
-
slider.container.scrollTo({ left: scrollTarget, behavior: behavior });
|
|
216
|
-
}, 50, scrollTarget);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
function setActiveSlideIdx() {
|
|
220
|
-
const sliderRect = slider.container.getBoundingClientRect();
|
|
221
|
-
const scrollLeft = slider.getScrollLeft();
|
|
222
|
-
const slides = slider.slides;
|
|
223
|
-
let activeSlideIdx = 0;
|
|
224
|
-
let scrolledPastLastSlide = false;
|
|
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;
|
|
250
|
-
}
|
|
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
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
if (scrolledPastLastSlide) {
|
|
266
|
-
activeSlideIdx = slides.length - 1;
|
|
267
|
-
}
|
|
268
|
-
const oldActiveSlideIdx = slider.activeSlideIdx;
|
|
269
|
-
slider.activeSlideIdx = activeSlideIdx;
|
|
270
|
-
if (oldActiveSlideIdx !== activeSlideIdx) {
|
|
271
|
-
slider.emit('activeSlideChanged');
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
function moveToSlide(idx) {
|
|
275
|
-
const slide = slider.slides[idx];
|
|
276
|
-
if (slide) {
|
|
277
|
-
ensureSlideIsInView(slide);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
function moveToSlideInDirection(direction) {
|
|
281
|
-
const activeSlideIdx = slider.activeSlideIdx;
|
|
282
|
-
if (direction === 'prev') {
|
|
283
|
-
if (activeSlideIdx > 0) {
|
|
284
|
-
moveToSlide(activeSlideIdx - 1);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
else if (direction === 'next') {
|
|
288
|
-
if (activeSlideIdx < slider.slides.length - 1) {
|
|
289
|
-
moveToSlide(activeSlideIdx + 1);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
function getInclusiveScrollWidth() {
|
|
294
|
-
return slider.container.scrollWidth + getOutermostChildrenEdgeMarginSum(slider.container);
|
|
295
|
-
}
|
|
296
|
-
function getInclusiveClientWidth() {
|
|
297
|
-
return slider.container.clientWidth + getOutermostChildrenEdgeMarginSum(slider.container);
|
|
298
|
-
}
|
|
299
|
-
function getScrollLeft() {
|
|
300
|
-
return slider.options.rtl ? Math.abs(slider.container.scrollLeft) : slider.container.scrollLeft;
|
|
301
|
-
}
|
|
302
|
-
function setScrollLeft(value) {
|
|
303
|
-
slider.container.scrollLeft = slider.options.rtl ? -value : value;
|
|
304
|
-
}
|
|
305
|
-
function getGapSize() {
|
|
306
|
-
let gapSize = 0;
|
|
307
|
-
if (slider.slides.length > 1) {
|
|
308
|
-
const firstSlideRect = slider.slides[0].getBoundingClientRect();
|
|
309
|
-
const secondSlideRect = slider.slides[1].getBoundingClientRect();
|
|
310
|
-
gapSize = slider.options.rtl ? Math.abs(Math.floor(secondSlideRect.right - firstSlideRect.left)) : Math.floor(secondSlideRect.left - firstSlideRect.right);
|
|
311
|
-
}
|
|
312
|
-
return gapSize;
|
|
313
|
-
}
|
|
314
|
-
function getLeftOffset() {
|
|
315
|
-
let offset = 0;
|
|
316
|
-
const fullWidthOffset = slider.container.getAttribute('data-full-width-offset');
|
|
317
|
-
if (fullWidthOffset) {
|
|
318
|
-
offset = parseInt(fullWidthOffset);
|
|
319
|
-
}
|
|
320
|
-
return Math.floor(offset);
|
|
321
|
-
}
|
|
322
|
-
function moveToDirection(direction = "prev") {
|
|
323
|
-
const scrollStrategy = slider.options.scrollStrategy;
|
|
324
|
-
const scrollLeft = slider.container.scrollLeft;
|
|
325
|
-
const sliderRect = slider.container.getBoundingClientRect();
|
|
326
|
-
const containerWidth = slider.container.offsetWidth;
|
|
327
|
-
let targetScrollPosition = scrollLeft;
|
|
328
|
-
const realDirection = slider.options.rtl ? (direction === 'prev' ? 'next' : 'prev') : direction;
|
|
329
|
-
if (realDirection === 'prev') {
|
|
330
|
-
targetScrollPosition = Math.max(0, scrollLeft - slider.container.offsetWidth);
|
|
331
|
-
}
|
|
332
|
-
else if (realDirection === 'next') {
|
|
333
|
-
targetScrollPosition = Math.min(slider.getInclusiveScrollWidth(), scrollLeft + slider.container.offsetWidth);
|
|
334
|
-
}
|
|
335
|
-
if (scrollStrategy === 'fullSlide') {
|
|
336
|
-
let fullSlideTargetScrollPosition = null;
|
|
337
|
-
// extend targetScrollPosition to include gap
|
|
338
|
-
if (realDirection === 'prev') {
|
|
339
|
-
fullSlideTargetScrollPosition = Math.max(0, targetScrollPosition - getGapSize());
|
|
340
|
-
}
|
|
341
|
-
else {
|
|
342
|
-
fullSlideTargetScrollPosition = Math.min(slider.getInclusiveScrollWidth(), targetScrollPosition + getGapSize());
|
|
343
|
-
}
|
|
344
|
-
if (realDirection === 'next') {
|
|
345
|
-
let partialSlideFound = false;
|
|
346
|
-
for (let slide of slider.slides) {
|
|
347
|
-
const slideRect = slide.getBoundingClientRect();
|
|
348
|
-
const slideStart = slideRect.left - sliderRect.left + scrollLeft;
|
|
349
|
-
const slideEnd = slideStart + slideRect.width;
|
|
350
|
-
if (Math.floor(slideStart) < Math.floor(targetScrollPosition) && Math.floor(slideEnd) > Math.floor(targetScrollPosition)) {
|
|
351
|
-
fullSlideTargetScrollPosition = slideStart;
|
|
352
|
-
partialSlideFound = true;
|
|
353
|
-
break;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
if (!partialSlideFound) {
|
|
357
|
-
fullSlideTargetScrollPosition = Math.min(targetScrollPosition, slider.getInclusiveScrollWidth() - slider.container.offsetWidth);
|
|
358
|
-
}
|
|
359
|
-
if (fullSlideTargetScrollPosition) {
|
|
360
|
-
if (Math.floor(fullSlideTargetScrollPosition) > Math.floor(scrollLeft)) {
|
|
361
|
-
// make sure fullSlideTargetScrollPosition is possible considering the container width
|
|
362
|
-
const maxScrollPosition = Math.floor(slider.getInclusiveScrollWidth()) - Math.floor(containerWidth);
|
|
363
|
-
targetScrollPosition = Math.min(fullSlideTargetScrollPosition, maxScrollPosition);
|
|
364
|
-
}
|
|
365
|
-
else {
|
|
366
|
-
// cannot snap to slide, move one page worth of distance
|
|
367
|
-
targetScrollPosition = Math.min(slider.getInclusiveScrollWidth(), scrollLeft + containerWidth);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
else {
|
|
372
|
-
let partialSlideFound = false;
|
|
373
|
-
for (let slide of slider.slides) {
|
|
374
|
-
const slideRect = slide.getBoundingClientRect();
|
|
375
|
-
const slideStart = slideRect.left - sliderRect.left + scrollLeft;
|
|
376
|
-
const slideEnd = slideStart + slideRect.width;
|
|
377
|
-
if (Math.floor(slideStart) < Math.floor(scrollLeft) && Math.floor(slideEnd) > Math.floor(scrollLeft)) {
|
|
378
|
-
fullSlideTargetScrollPosition = slideEnd - containerWidth;
|
|
379
|
-
partialSlideFound = true;
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
if (!partialSlideFound) {
|
|
384
|
-
fullSlideTargetScrollPosition = Math.max(0, scrollLeft - containerWidth);
|
|
385
|
-
}
|
|
386
|
-
if (fullSlideTargetScrollPosition && Math.floor(fullSlideTargetScrollPosition) < Math.floor(scrollLeft)) {
|
|
387
|
-
targetScrollPosition = fullSlideTargetScrollPosition;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
// add left offset
|
|
392
|
-
const offsettedTargetScrollPosition = targetScrollPosition - getLeftOffset();
|
|
393
|
-
if (Math.floor(offsettedTargetScrollPosition) >= 0) {
|
|
394
|
-
targetScrollPosition = offsettedTargetScrollPosition;
|
|
395
|
-
}
|
|
396
|
-
slider.emit('programmaticScrollStart');
|
|
397
|
-
slider.container.style.scrollBehavior = slider.options.scrollBehavior;
|
|
398
|
-
slider.container.scrollLeft = targetScrollPosition;
|
|
399
|
-
setTimeout(() => slider.container.style.scrollBehavior = '', 50);
|
|
400
|
-
}
|
|
401
|
-
function snapToClosestSlide(direction = "prev") {
|
|
402
|
-
const isMovingForward = slider.options.rtl ? direction === 'prev' : direction === 'next';
|
|
403
|
-
const slideReference = [];
|
|
404
|
-
for (let i = 0; i < slider.slides.length; i++) {
|
|
405
|
-
const slide = slider.slides[i];
|
|
406
|
-
const slideWidth = slide.offsetWidth;
|
|
407
|
-
const slideStart = slider.options.rtl ? Math.abs(slide.offsetLeft + slideWidth - slider.details.containerWidth) : slide.offsetLeft;
|
|
408
|
-
const slideEnd = slideStart + slideWidth;
|
|
409
|
-
const slideMiddle = slideStart + slideWidth / 2;
|
|
410
|
-
const trigger = Math.min(slideMiddle, slideStart + slider.options.emulateScrollSnapMaxThreshold);
|
|
411
|
-
slideReference.push({
|
|
412
|
-
start: slideStart,
|
|
413
|
-
middle: slideMiddle,
|
|
414
|
-
end: slideEnd,
|
|
415
|
-
width: slideWidth,
|
|
416
|
-
trigger: trigger,
|
|
417
|
-
slide: slide,
|
|
418
|
-
// debug
|
|
419
|
-
offSetleft: slide.offsetLeft,
|
|
420
|
-
rect: slide.getBoundingClientRect(),
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
let snapTarget = null;
|
|
424
|
-
const scrollPosition = getScrollLeft();
|
|
425
|
-
if (isMovingForward) {
|
|
426
|
-
for (let i = 0; i < slideReference.length; i++) {
|
|
427
|
-
const item = slideReference[i];
|
|
428
|
-
if (i === 0 && Math.floor(scrollPosition) <= Math.floor(item.trigger)) {
|
|
429
|
-
snapTarget = 0;
|
|
430
|
-
break;
|
|
431
|
-
}
|
|
432
|
-
if (Math.floor(getScrollLeft()) <= Math.floor(item.trigger)) {
|
|
433
|
-
snapTarget = item.start;
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
else {
|
|
439
|
-
for (let i = slideReference.length - 1; i >= 0; i--) {
|
|
440
|
-
const item = slideReference[i];
|
|
441
|
-
if (i === slideReference.length - 1 && Math.floor(scrollPosition) >= Math.floor(item.trigger)) {
|
|
442
|
-
snapTarget = item.start;
|
|
443
|
-
break;
|
|
444
|
-
}
|
|
445
|
-
if (Math.floor(getScrollLeft()) >= Math.floor(item.trigger)) {
|
|
446
|
-
snapTarget = item.start;
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
if (snapTarget !== null) {
|
|
452
|
-
const offsettedSnapTarget = snapTarget - getLeftOffset();
|
|
453
|
-
if (Math.floor(offsettedSnapTarget) >= 0) {
|
|
454
|
-
snapTarget = offsettedSnapTarget;
|
|
455
|
-
}
|
|
456
|
-
const scrollBehavior = slider.options.scrollBehavior || 'smooth';
|
|
457
|
-
slider.container.scrollTo({
|
|
458
|
-
left: slider.options.rtl ? -snapTarget : snapTarget,
|
|
459
|
-
behavior: scrollBehavior
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
function on(name, cb) {
|
|
464
|
-
if (!subs[name]) {
|
|
465
|
-
subs[name] = [];
|
|
466
|
-
}
|
|
467
|
-
subs[name].push(cb);
|
|
468
|
-
}
|
|
469
|
-
function emit(name) {
|
|
470
|
-
var _a;
|
|
471
|
-
if (subs && subs[name]) {
|
|
472
|
-
subs[name].forEach(cb => {
|
|
473
|
-
cb(slider);
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
const optionCallBack = (_a = slider === null || slider === void 0 ? void 0 : slider.options) === null || _a === void 0 ? void 0 : _a[name];
|
|
477
|
-
// Type guard to check if the option callback is a function
|
|
478
|
-
if (typeof optionCallBack === 'function') {
|
|
479
|
-
optionCallBack(slider); // Type assertion here
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
slider = {
|
|
483
|
-
emit,
|
|
484
|
-
moveToDirection,
|
|
485
|
-
moveToSlide,
|
|
486
|
-
moveToSlideInDirection,
|
|
487
|
-
snapToClosestSlide,
|
|
488
|
-
getInclusiveScrollWidth,
|
|
489
|
-
getInclusiveClientWidth,
|
|
490
|
-
getScrollLeft,
|
|
491
|
-
setScrollLeft,
|
|
492
|
-
on,
|
|
493
|
-
options,
|
|
494
|
-
};
|
|
495
|
-
init();
|
|
496
|
-
return slider;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
export { Slider as default };
|
package/dist/core/slider.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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+v();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(t){const e=a.slides[t];e&&u(e)}function M(){return a.options.rtl?Math.abs(a.container.scrollLeft):a.container.scrollLeft}function v(){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-v()):Math.min(a.getInclusiveScrollWidth(),i+v()),"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:m,moveToSlideInDirection:function(t){const e=a.activeSlideIdx;"prev"===t?e>0&&m(e-1):"next"===t&&e<a.slides.length-1&&m(e+1)},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()})}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,35 +0,0 @@
|
|
|
1
|
-
function details(slider) {
|
|
2
|
-
var _a;
|
|
3
|
-
let instance;
|
|
4
|
-
let hasOverflow = false;
|
|
5
|
-
let slideCount = 0;
|
|
6
|
-
let containerWidth = 0;
|
|
7
|
-
let scrollableAreaWidth = 0;
|
|
8
|
-
let amountOfPages = 0;
|
|
9
|
-
let currentPage = 1;
|
|
10
|
-
if (Math.floor(slider.getInclusiveScrollWidth()) > Math.floor(slider.getInclusiveClientWidth())) {
|
|
11
|
-
hasOverflow = true;
|
|
12
|
-
}
|
|
13
|
-
slideCount = (_a = slider.slides.length) !== null && _a !== void 0 ? _a : 0;
|
|
14
|
-
containerWidth = slider.container.offsetWidth;
|
|
15
|
-
scrollableAreaWidth = slider.getInclusiveScrollWidth();
|
|
16
|
-
amountOfPages = Math.ceil(scrollableAreaWidth / containerWidth);
|
|
17
|
-
if (Math.floor(slider.getScrollLeft()) >= 0) {
|
|
18
|
-
currentPage = Math.floor(slider.getScrollLeft() / containerWidth);
|
|
19
|
-
// consider as last page if the scrollLeft + containerWidth is equal to scrollWidth
|
|
20
|
-
if (Math.floor(slider.getScrollLeft() + containerWidth) === Math.floor(scrollableAreaWidth)) {
|
|
21
|
-
currentPage = amountOfPages - 1;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
instance = {
|
|
25
|
-
hasOverflow,
|
|
26
|
-
slideCount,
|
|
27
|
-
containerWidth,
|
|
28
|
-
scrollableAreaWidth,
|
|
29
|
-
amountOfPages,
|
|
30
|
-
currentPage,
|
|
31
|
-
};
|
|
32
|
-
return instance;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { details as default };
|
|
@@ -1 +0,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};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import Slider from './slider.esm.js';
|
|
2
|
-
|
|
3
|
-
function OverflowSlider(container, options, plugins) {
|
|
4
|
-
try {
|
|
5
|
-
// check that container HTML element
|
|
6
|
-
if (!(container instanceof Element)) {
|
|
7
|
-
throw new Error(`Container must be HTML element, found ${typeof container}`);
|
|
8
|
-
}
|
|
9
|
-
const defaults = {
|
|
10
|
-
scrollBehavior: "smooth",
|
|
11
|
-
scrollStrategy: "fullSlide",
|
|
12
|
-
slidesSelector: ":scope > *",
|
|
13
|
-
emulateScrollSnap: false,
|
|
14
|
-
emulateScrollSnapMaxThreshold: 64,
|
|
15
|
-
rtl: false,
|
|
16
|
-
};
|
|
17
|
-
const sliderOptions = Object.assign(Object.assign({}, defaults), options);
|
|
18
|
-
// disable smooth scrolling if user prefers reduced motion
|
|
19
|
-
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
|
20
|
-
sliderOptions.scrollBehavior = "auto";
|
|
21
|
-
}
|
|
22
|
-
return Slider(container, sliderOptions, plugins);
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
console.error(e);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { OverflowSlider as default };
|
|
@@ -1 +0,0 @@
|
|
|
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};
|