@evermade/overflow-slider 3.1.0 → 3.2.1

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.
Files changed (60) hide show
  1. package/README.md +339 -8
  2. package/dist/core/details.esm.js +3 -3
  3. package/dist/core/details.min.js +1 -1
  4. package/dist/core/overflow-slider.esm.js +1 -0
  5. package/dist/core/overflow-slider.min.js +1 -1
  6. package/dist/core/slider.esm.js +69 -22
  7. package/dist/core/slider.min.js +1 -1
  8. package/dist/core/utils.esm.js +2 -1
  9. package/dist/core/utils.min.js +1 -1
  10. package/dist/overflow-slider.css +1 -1
  11. package/dist/plugins/arrows/arrows/index.esm.js +7 -4
  12. package/dist/plugins/arrows/arrows/index.min.js +1 -1
  13. package/dist/plugins/dots/dots/index.esm.js +0 -4
  14. package/dist/plugins/fade/fade/index.esm.js +4 -4
  15. package/dist/plugins/fade/fade/index.min.js +1 -1
  16. package/dist/plugins/full-width/full-width/index.esm.js +7 -2
  17. package/dist/plugins/full-width/full-width/index.min.js +1 -1
  18. package/dist/plugins/scroll-indicator/scroll-indicator/index.esm.js +18 -18
  19. package/dist/plugins/scroll-indicator/scroll-indicator/index.min.js +1 -1
  20. package/dist/plugins/thumbnails/thumbnails/index.esm.js +8 -5
  21. package/dist/plugins/thumbnails/thumbnails/index.min.js +1 -1
  22. package/docs/assets/demo.css +11 -1
  23. package/docs/assets/demo.js +38 -12
  24. package/docs/dist/core/details.esm.js +3 -3
  25. package/docs/dist/core/details.min.js +1 -1
  26. package/docs/dist/core/overflow-slider.esm.js +1 -0
  27. package/docs/dist/core/overflow-slider.min.js +1 -1
  28. package/docs/dist/core/slider.esm.js +69 -22
  29. package/docs/dist/core/slider.min.js +1 -1
  30. package/docs/dist/core/utils.esm.js +2 -1
  31. package/docs/dist/core/utils.min.js +1 -1
  32. package/docs/dist/overflow-slider.css +1 -1
  33. package/docs/dist/plugins/arrows/arrows/index.esm.js +7 -4
  34. package/docs/dist/plugins/arrows/arrows/index.min.js +1 -1
  35. package/docs/dist/plugins/dots/dots/index.esm.js +0 -4
  36. package/docs/dist/plugins/fade/fade/index.esm.js +4 -4
  37. package/docs/dist/plugins/fade/fade/index.min.js +1 -1
  38. package/docs/dist/plugins/full-width/full-width/index.esm.js +7 -2
  39. package/docs/dist/plugins/full-width/full-width/index.min.js +1 -1
  40. package/docs/dist/plugins/scroll-indicator/scroll-indicator/index.esm.js +18 -18
  41. package/docs/dist/plugins/scroll-indicator/scroll-indicator/index.min.js +1 -1
  42. package/docs/dist/plugins/thumbnails/thumbnails/index.esm.js +8 -5
  43. package/docs/dist/plugins/thumbnails/thumbnails/index.min.js +1 -1
  44. package/docs/index-rtl.html +396 -0
  45. package/docs/index.html +1 -1
  46. package/package.json +1 -1
  47. package/src/core/details.ts +3 -3
  48. package/src/core/overflow-slider.ts +1 -0
  49. package/src/core/slider.ts +79 -27
  50. package/src/core/types.ts +10 -3
  51. package/src/core/utils.ts +9 -5
  52. package/src/plugins/arrows/index.ts +8 -6
  53. package/src/plugins/dots/index.ts +1 -5
  54. package/src/plugins/drag-scrolling/index.ts +1 -1
  55. package/src/plugins/fade/index.ts +5 -5
  56. package/src/plugins/fade/styles.scss +10 -0
  57. package/src/plugins/full-width/index.ts +9 -3
  58. package/src/plugins/scroll-indicator/index.ts +60 -62
  59. package/src/plugins/skip-links/index.ts +1 -1
  60. package/src/plugins/thumbnails/index.ts +9 -6
package/README.md CHANGED
@@ -9,8 +9,9 @@ Overflow Slider aims to be lightweight, mobile-first and accessible. It is desig
9
9
  ## Demos
10
10
 
11
11
  * [Example and demos](https://evermade.github.io/overflow-slider/)
12
+ * [RTL demos](https://evermade.github.io/overflow-slider/index-rtl.html)
12
13
 
13
- ### Usage
14
+ ## Getting started
14
15
 
15
16
  Markup:
16
17
 
@@ -32,7 +33,7 @@ npm install @evermade/overflow-slider
32
33
 
33
34
  Import the `OverflowSlider` along with plugins you want to use.
34
35
 
35
- ```js
36
+ ```ts
36
37
  import { OverflowSlider } from '@evermade/overflow-slider';
37
38
  import DragScrollingPlugin from '@evermade/overflow-slider/plugins/drag-scrolling';
38
39
  import SkipLinksPlugin from '@evermade/overflow-slider/plugins/skip-links';
@@ -65,7 +66,7 @@ const slider = new OverflowSlider(
65
66
  const slider = new OverflowSlider(
66
67
  document.querySelector( '.slider-container-here' ),
67
68
  {
68
- // options here
69
+ emulateScrollSnap: true,
69
70
  },
70
71
  [
71
72
  ArrowsPlugin({
@@ -101,6 +102,328 @@ You can use the CSS variables to override some values easily.
101
102
 
102
103
  Note that you can easily write styles from scratch if you want to. See source code from `src/overflow-slider.scss` for reference.
103
104
 
105
+ ## Slides per view
106
+
107
+ You control slides per view in CSS. Set gap between slides via `gap` to slider. Slide layout/size is controlled by `width` property. You can use others but `width` is the most stable.
108
+
109
+ ### A) Fixed width
110
+
111
+ Set fixed width for slides: `width: 200px;`. Note you can freely change this with media queries.
112
+
113
+ ### B) Relative width
114
+
115
+ Set relative width for slides: `width: 100vw;`. Note that you cannot use percentages because they are relative to the container and not the viewport.
116
+
117
+ ### C) Variable based width
118
+
119
+ This is most practical approach if you want to make sure exactly 3 slides are visible at all times or so. Or you want to display like 1.5 slides in mobile per view.
120
+
121
+ This is based on getting the container width and dividing it by the number of slides you want to show and subtracting the gap. It's recommended to add SCSS mixin for this in case you are using SCSS.
122
+
123
+ Mixin:
124
+
125
+ ```scss
126
+ @mixin slideWidth($slidesPerView: 3, $gap: var(--slide-gap, 1rem), $containerWidth: var(--slider-container-width, 90vw)) {
127
+ width: calc( ( #{$containerWidth} / #{$slidesPerView} ) - calc( #{$slidesPerView} - 1 ) / #{$slidesPerView} * #{$gap});
128
+ }
129
+ ```
130
+
131
+ Usage:
132
+
133
+ ```scss
134
+ .overflow-slider {
135
+ --gap: 1.5rem;
136
+ gap: var(--gap);
137
+ > * {
138
+ --slides-per-view: 3;
139
+ @include slideWidth(
140
+ var(--slides-per-view),
141
+ var(--gap),
142
+ var(--slider-container-width)
143
+ );
144
+ }
145
+ }
146
+ ```
147
+
148
+ Note that if you are using FullWidthPlugin, you should use container width from `--slider-container-target-width` instead of `--slider-container-width`.
149
+
150
+ ## Plugins
151
+
152
+ ### DragScrollingPlugin
153
+
154
+ This plugin allows you to scroll the slider by dragging with a mouse. This works with items that have links or are links themselves.
155
+
156
+ ```ts
157
+ import DragScrollingPlugin from '@evermade/overflow-slider/plugins/drag-scrolling';
158
+
159
+ const slider = new OverflowSlider(
160
+ document.querySelector( '.slider-container-here' ),
161
+ {},
162
+ [
163
+ DragScrollingPlugin(), // add options here or don't
164
+ ]
165
+ );
166
+ ```
167
+
168
+ All options are optional.
169
+
170
+ ```ts
171
+ type DragScrollingOptions = {
172
+ draggedDistanceThatPreventsClick: number, // default 10, how much user can drag before it's considered a drag and not a click in case of links
173
+ };
174
+ ```
175
+
176
+ ### ArrowsPlugin
177
+
178
+ This plugin adds previous and next arrows to the slider. You can customize the text, icons and class names.
179
+
180
+ ```ts
181
+ import ArrowsPlugin from '@evermade/overflow-slider/plugins/arrows';
182
+
183
+ const slider = new OverflowSlider(
184
+ document.querySelector( '.slider-container-here' ),
185
+ {},
186
+ [
187
+ ArrowsPlugin(), // add options here or don't
188
+ ]
189
+ );
190
+ ```
191
+
192
+ All options are optional.
193
+
194
+ ```ts
195
+ type ArrowsOptions = {
196
+ texts: {
197
+ buttonPrevious: string;
198
+ buttonNext: string;
199
+ },
200
+ icons: {
201
+ prev: string; // SVG or other HTML
202
+ next: string; // SVG or other HTML
203
+ },
204
+ classNames: {
205
+ navContainer: string;
206
+ prevButton: string;
207
+ nextButton: string;
208
+ },
209
+ container: HTMLElement | null, // container for both arrows
210
+ containerPrev: HTMLElement | null, // container for previous arrow
211
+ containerNext: HTMLElement | null, // container for next arrow
212
+ };
213
+ ```
214
+
215
+ ### ScrollIndicatorPlugin
216
+
217
+ This plugin adds a scroll indicator to the slider. The indicator is a bar that shows how much of the slider is scrolled. Scroll indicator is like a custom scrollbar that is always visible.
218
+
219
+ ```ts
220
+ import ScrollIndicatorPlugin from '@evermade/overflow-slider/plugins/scroll-indicator';
221
+
222
+ const slider = new OverflowSlider(
223
+ document.querySelector( '.slider-container-here' ),
224
+ {},
225
+ [
226
+ ScrollIndicatorPlugin(), // add options here or don't
227
+ ]
228
+ );
229
+ ```
230
+
231
+ All options are optional.
232
+
233
+ ```ts
234
+ type ScrollIndicatorOptions = {
235
+ classNames: {
236
+ scrollIndicator: string;
237
+ scrollIndicatorBar: string;
238
+ scrollIndicatorButton: string;
239
+ },
240
+ container: HTMLElement | null, // container for the scroll indicator
241
+ };
242
+ ```
243
+
244
+ ### DotsPlugin
245
+
246
+ This plugin adds dots to the slider. Dots are like pagination that shows how many slides there are and which one is active. For usability, scroll indicator is preferable.
247
+
248
+ ```ts
249
+ import DotsPlugin from '@evermade/overflow-slider/plugins/dots';
250
+
251
+ const slider = new OverflowSlider(
252
+ document.querySelector( '.slider-container-here' ),
253
+ {},
254
+ [
255
+ DotsPlugin(), // add options here or don't
256
+ ]
257
+ );
258
+ ```
259
+
260
+ All options are optional.
261
+
262
+ ```ts
263
+ type DotsOptions = {
264
+ texts: {
265
+ dotDescription: string;
266
+ },
267
+ classNames: {
268
+ dotsContainer: string;
269
+ dotsItem: string;
270
+ },
271
+ container: HTMLElement | null,
272
+ };
273
+ ```
274
+
275
+ ### SkipLinksPlugin
276
+
277
+ This plugin adds skip links to the slider for keyboard users. Skip links are links that allow users to skip the whole slider and land after it. This is useful for accessibility.
278
+
279
+ ```ts
280
+ import SkipLinksPlugin from '@evermade/overflow-slider/plugins/skip-links';
281
+
282
+ const slider = new OverflowSlider(
283
+ document.querySelector( '.slider-container-here' ),
284
+ {},
285
+ [
286
+ SkipLinksPlugin(), // add options here or don't
287
+ ]
288
+ );
289
+ ```
290
+
291
+ All options are optional.
292
+
293
+ ```ts
294
+ type SkipLinkOptions = {
295
+ texts: {
296
+ skipList: string;
297
+ },
298
+ classNames: {
299
+ skipLink: string;
300
+ skipLinkTarget: string;
301
+ },
302
+ containerBefore: HTMLElement | null,
303
+ containerAfter: HTMLElement | null,
304
+ };
305
+ ```
306
+
307
+ ### FullWidthPlugin
308
+
309
+ This plugin allows you to make the slider full width but have the start of the sliders aligned to your content width. They are scrollable to the full width but the slides are aligned to the content width for the start and end.
310
+
311
+ ```ts
312
+ import FullWidthPlugin from '@evermade/overflow-slider/plugins/full-width';
313
+
314
+ const slider = new OverflowSlider(
315
+ document.querySelector( '.slider-container-here' ),
316
+ {},
317
+ [
318
+ FullWidthPlugin(), // add options here or don't
319
+ ]
320
+ );
321
+ ```
322
+
323
+ All options are optional.
324
+
325
+ ```ts
326
+ type FullWidthOptions = {
327
+ targetWidth: ( slider: Slider ) => number,
328
+ addMarginBefore: boolean,
329
+ addMarginAfter: boolean,
330
+ };
331
+ ```
332
+
333
+ Example of `targetWidth` function:
334
+
335
+ ```ts
336
+ const sliderElement = document.querySelector( '.slider-container-here' );
337
+ const sliderWrapper = document.querySelector( '.slider-wrapper' );
338
+ if ( !sliderElement || !sliderWrapper ) {
339
+ throw new Error( 'Slider element or wrapper not found' );
340
+ }
341
+ const slider = new OverflowSlider(
342
+ sliderElement,
343
+ {},
344
+ [
345
+ FullWidthPlugin({
346
+ targetWidth: ( slider ) => {
347
+ return sliderWrapper.offsetWidth;
348
+ },
349
+ }),
350
+ ]
351
+ );
352
+ ```
353
+
354
+ ### FadePlugin
355
+
356
+ This plugin adds a hint that there are more slides to scroll to. It fades the slides at the start and end of the slider to hint that there are more slides to scroll to.
357
+
358
+ ```ts
359
+ import FadePlugin from '@evermade/overflow-slider/plugins/fade';
360
+
361
+ const slider = new OverflowSlider(
362
+ document.querySelector( '.slider-container-here' ),
363
+ {},
364
+ [
365
+ FadePlugin(), // add options here or don't
366
+ ]
367
+ );
368
+ ```
369
+
370
+ All options are optional.
371
+
372
+ ```ts
373
+ type FadeOptions = {
374
+ classNames: {
375
+ fadeItem: string;
376
+ fadeItemStart: string;
377
+ fadeItemEnd: string;
378
+ },
379
+ container: HTMLElement | null,
380
+ containerStart: HTMLElement | null,
381
+ containerEnd: HTMLElement | null,
382
+ };
383
+ ```
384
+
385
+ ### ThumbnailsPlugin
386
+
387
+ This plugin adds synchronized thumbnails to the slider. Thumbnails are like dots but they are images of the slides. They are synchronized with the main slider.
388
+
389
+ ```ts
390
+ import ThumbnailsPlugin from '@evermade/overflow-slider/plugins/thumbnails';
391
+
392
+ const slider = new OverflowSlider(
393
+ document.querySelector( '.slider-container-here' ),
394
+ {},
395
+ [
396
+ ThumbnailsPlugin(), // add options here or don't
397
+ ]
398
+ );
399
+ ```
400
+
401
+ You need to set mainSlider reference.
402
+
403
+ ```ts
404
+ type ThumbnailsOptions = {
405
+ mainSlider: Slider,
406
+ }
407
+ ```
408
+
409
+ Example:
410
+
411
+ ```ts
412
+ const mainSlider = new OverflowSlider(
413
+ document.querySelector( '.slider-container-here' ),
414
+ );
415
+
416
+ const thumbnailsSlider = new OverflowSlider(
417
+ document.querySelector( '.thumbnails-container-here' ),
418
+ {},
419
+ [
420
+ ThumbnailsPlugin({
421
+ mainSlider: mainSlider,
422
+ }),
423
+ ]
424
+ );
425
+ ```
426
+
104
427
  ## Known issues
105
428
 
106
429
  ### CSS grids and Overflow Slider
@@ -109,7 +432,7 @@ You can use use Overflow Slider within CSS grid but if you are using `fr` units
109
432
 
110
433
  ### CSS scroll-snap can be buggy
111
434
 
112
- If you are using `scroll-snap-type` CSS property, you might encounter some bugs like browser wants to snap to a slide regardless of margins.
435
+ If you are using `scroll-snap-type` CSS property, you might encounter some bugs like browser wants to snap to a slide regardless of margins. It's most reliable when there's only one slide per view.
113
436
 
114
437
  ## Limitations
115
438
 
@@ -117,10 +440,6 @@ If you are using `scroll-snap-type` CSS property, you might encounter some bugs
117
440
 
118
441
  The library is designed to work with horizontal scrolling. Vertical scrolling is not supported and likely never will because it is not a common use case for sliders.
119
442
 
120
- ### RTL support
121
-
122
- RTL support is not implemented yet. In case need arises it can be implemented but requires changes to the core and plugins.
123
-
124
443
  ### Looping slides
125
444
 
126
445
  Looping slides is not supported and likely never will be. It is a feature that is not very common and it is not very accessible.
@@ -137,6 +456,18 @@ Auto-play is not supported at the moment but can probably be implemented as a pl
137
456
 
138
457
  ## Changelog
139
458
 
459
+ ### 3.2.1
460
+
461
+ * Add: Documentation on plugins
462
+ * Fix: Make types more strict and remove all "any" types
463
+
464
+ ### 3.2.0
465
+
466
+ * Add: RTL support
467
+ * Add: `--slider-container-target-width` for FullWidthPlugin to allow CSS based on target size
468
+ * Add: Documentation how to set slides per view in CSS
469
+ * Fix: Attach ThumbnailsPlugin to scrollEnd which skips in-between slides when multiple slides are scrolled at once
470
+
140
471
  ### 3.1.0
141
472
 
142
473
  * Add: slider.getInclusiveScrollWidth and slider.getInclusiveScrollHeight methods to get widths including outermost childs outermost margins
@@ -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.container.scrollLeft) >= 0) {
18
- currentPage = Math.floor(slider.container.scrollLeft / containerWidth);
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.container.scrollLeft + containerWidth) === Math.floor(scrollableAreaWidth)) {
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,n=0,a=0,i=0,c=1;return Math.floor(t.getInclusiveScrollWidth())>Math.floor(t.getInclusiveClientWidth())&&(o=!0),r=null!==(l=t.slides.length)&&void 0!==l?l:0,n=t.container.offsetWidth,a=t.getInclusiveScrollWidth(),i=Math.ceil(a/n),Math.floor(t.container.scrollLeft)>=0&&(c=Math.floor(t.container.scrollLeft/n),Math.floor(t.container.scrollLeft+n)===Math.floor(a)&&(c=i-1)),e={hasOverflow:o,slideCount:r,containerWidth:n,scrollableAreaWidth:a,amountOfPages:i,currentPage:c},e}export{t as default};
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};
@@ -78,7 +78,7 @@ function Slider(container, options, plugins) {
78
78
  let isScrolling = false;
79
79
  let isUserScrolling = false;
80
80
  let isProgrammaticScrolling = false;
81
- // any scroll
81
+ // all types of scroll
82
82
  slider.container.addEventListener('scroll', () => {
83
83
  const newScrollLeft = slider.container.scrollLeft;
84
84
  if (Math.floor(scrollLeft) !== Math.floor(newScrollLeft)) {
@@ -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.container.scrollLeft;
221
+ const scrollLeft = slider.getScrollLeft();
219
222
  const slides = slider.slides;
220
223
  let activeSlideIdx = 0;
221
224
  let scrolledPastLastSlide = false;
222
- for (let i = 0; i < slides.length; i++) {
223
- const slideRect = slides[i].getBoundingClientRect();
224
- const slideStart = slideRect.left - sliderRect.left + scrollLeft + getGapSize();
225
- if (Math.floor(slideStart) >= Math.floor(scrollLeft)) {
226
- activeSlideIdx = i;
227
- break;
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
- if (i === slides.length - 1) {
230
- scrolledPastLastSlide = true;
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
- if (direction === 'prev') {
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 (direction === 'next') {
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 (direction === 'prev') {
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 (direction === 'next') {
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 = slider.container.scrollLeft;
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(slider.container.scrollLeft) <= Math.floor(item.trigger)) {
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(slider.container.scrollLeft) >= Math.floor(item.trigger)) {
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
  }
@@ -419,8 +463,9 @@ function Slider(container, options, plugins) {
419
463
  });
420
464
  }
421
465
  const optionCallBack = (_a = slider === null || slider === void 0 ? void 0 : slider.options) === null || _a === void 0 ? void 0 : _a[name];
466
+ // Type guard to check if the option callback is a function
422
467
  if (typeof optionCallBack === 'function') {
423
- optionCallBack(slider);
468
+ optionCallBack(slider); // Type assertion here
424
469
  }
425
470
  }
426
471
  slider = {
@@ -430,6 +475,8 @@ function Slider(container, options, plugins) {
430
475
  snapToClosestSlide,
431
476
  getInclusiveScrollWidth,
432
477
  getInclusiveClientWidth,
478
+ getScrollLeft,
479
+ setScrollLeft,
433
480
  on,
434
481
  options,
435
482
  };
@@ -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,c={};function s(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")}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,c=n.left-l.left+r,s=c+n.width;let f=null;f=Math.floor(c)<Math.floor(r)?c:Math.floor(s)>Math.floor(r)+Math.floor(i)?s-i:0===Math.floor(c)?0:c,null!==f&&setTimeout((t=>{a.emit("programmaticScrollStart"),a.container.scrollTo({left:t,behavior:o})}),50,f)}function m(){const t=a.container.getBoundingClientRect(),e=a.container.scrollLeft,o=a.slides;let n=0,l=!1;for(let i=0;i<o.length;i++){const r=o[i].getBoundingClientRect().left-t.left+e+g();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 g(){let t=0;if(a.slides.length>1){const e=a.slides[0].getBoundingClientRect(),o=a.slides[1].getBoundingClientRect();t=Math.floor(o.left-e.right)}return t}function M(){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;c&&c[t]&&c[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;if("prev"===t?i=Math.max(0,o-a.container.offsetWidth):"next"===t&&(i=Math.min(a.getInclusiveScrollWidth(),o+a.container.offsetWidth)),"fullSlide"===e){let e=null;if(e="prev"===t?Math.max(0,i-g()):Math.min(a.getInclusiveScrollWidth(),i+g()),"next"===t){let t=!1;for(let l of a.slides){const r=l.getBoundingClientRect(),a=r.left-n.left+o,c=a+r.width;if(Math.floor(a)<Math.floor(i)&&Math.floor(c)>Math.floor(i)){e=a,t=!0;break}}if(t||(e=Math.min(i,a.getInclusiveScrollWidth()-a.container.offsetWidth)),e)if(Math.floor(e)>Math.floor(o)){const t=Math.floor(a.getInclusiveScrollWidth())-Math.floor(l);i=Math.min(e,t)}else i=Math.min(a.getInclusiveScrollWidth(),o+l)}else{let t=!1;for(let i of a.slides){const r=i.getBoundingClientRect(),a=r.left-n.left+o,c=a+r.width;if(Math.floor(a)<Math.floor(o)&&Math.floor(c)>Math.floor(o)){e=c-l,t=!0;break}}t||(e=Math.max(0,o-l)),e&&Math.floor(e)<Math.floor(o)&&(i=e)}}const r=i-M();Math.floor(r)>=0&&(i=r),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="next"===t,o=[];for(let t=0;t<a.slides.length;t++){const e=a.slides[t],n=e.offsetWidth,l=e.offsetLeft,i=l+n,r=l+n/2,c=Math.min(r,l+a.options.emulateScrollSnapMaxThreshold);o.push({start:l,middle:r,end:i,width:n,trigger:c,slide:e})}let n=null;const l=a.container.scrollLeft;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(a.container.scrollLeft)<=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(a.container.scrollLeft)>=Math.floor(e.trigger)){n=e.start;break}}if(null!==n){const t=n-M();Math.floor(t)>=0&&(n=t);const e=a.options.scrollBehavior||"smooth";a.container.scrollTo({left:n,behavior:e})}},getInclusiveScrollWidth:function(){return a.container.scrollWidth+n(a.container)},getInclusiveClientWidth:function(){return a.container.clientWidth+n(a.container)},on:function(t,e){c[t]||(c[t]=[]),c[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(),s(!0),m(),a.on("contentsChanged",(()=>{f(),s(),m()})),a.on("containerSizeChanged",(()=>s()));let o=0;if(a.on("scroll",(()=>{o&&window.cancelAnimationFrame(o),o=window.requestAnimationFrame((()=>{s(),m()}))})),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,c=!1,s=!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")),c&&f()}));const f=()=>{const t=a.container.scrollLeft;Math.floor(l)===Math.floor(t)||s||(c||(a.emit("nativeScrollStart"),c=!0),a.emit("nativeScroll"),l=t,clearTimeout(e),e=setTimeout((()=>{c=!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",(()=>{s=!0})),a.container.addEventListener("scroll",(()=>{const t=a.container.scrollLeft;Math.floor(i)!==Math.floor(t)&&!c&&s&&(i=t,clearTimeout(o),o=setTimeout((()=>{s=!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
+ 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};