@evermade/overflow-slider 1.1.0 → 2.0.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 (78) hide show
  1. package/README.md +35 -11
  2. package/dist/core/details.esm.js +35 -0
  3. package/dist/core/details.min.js +1 -0
  4. package/dist/core/overflow-slider.esm.js +26 -0
  5. package/dist/core/overflow-slider.min.js +1 -0
  6. package/dist/core/slider.esm.js +267 -0
  7. package/dist/core/slider.min.js +1 -0
  8. package/dist/core/utils.esm.js +22 -0
  9. package/dist/core/utils.min.js +1 -0
  10. package/dist/index.esm.js +1 -704
  11. package/dist/index.min.js +1 -2
  12. package/dist/overflow-slider.css +1 -1
  13. package/dist/plugins/arrows/arrows/index.esm.js +83 -0
  14. package/dist/plugins/arrows/arrows/index.min.js +1 -0
  15. package/dist/plugins/dots/dots/index.esm.js +99 -0
  16. package/dist/plugins/dots/dots/index.min.js +1 -0
  17. package/dist/plugins/drag-scrolling/drag-scrolling/index.esm.js +70 -0
  18. package/dist/plugins/drag-scrolling/drag-scrolling/index.min.js +1 -0
  19. package/dist/plugins/full-width/full-width/index.esm.js +31 -0
  20. package/dist/plugins/full-width/full-width/index.min.js +1 -0
  21. package/dist/plugins/scroll-indicator/scroll-indicator/index.esm.js +133 -0
  22. package/dist/plugins/scroll-indicator/scroll-indicator/index.min.js +1 -0
  23. package/dist/plugins/skip-links/skip-links/index.esm.js +42 -0
  24. package/dist/plugins/skip-links/skip-links/index.min.js +1 -0
  25. package/dist/plugins/thumbnails/thumbnails/index.esm.js +41 -0
  26. package/dist/plugins/thumbnails/thumbnails/index.min.js +1 -0
  27. package/docs/assets/demo.css +133 -5
  28. package/docs/assets/demo.js +97 -10
  29. package/docs/dist/core/details.esm.js +35 -0
  30. package/docs/dist/core/details.min.js +1 -0
  31. package/docs/dist/core/overflow-slider.esm.js +26 -0
  32. package/docs/dist/core/overflow-slider.min.js +1 -0
  33. package/docs/dist/core/slider.esm.js +267 -0
  34. package/docs/dist/core/slider.min.js +1 -0
  35. package/docs/dist/core/utils.esm.js +22 -0
  36. package/docs/dist/core/utils.min.js +1 -0
  37. package/docs/dist/index.esm.js +1 -0
  38. package/docs/dist/index.min.js +1 -0
  39. package/docs/dist/overflow-slider.css +1 -1
  40. package/docs/dist/plugins/arrows/arrows/index.esm.js +83 -0
  41. package/docs/dist/plugins/arrows/arrows/index.min.js +1 -0
  42. package/docs/dist/plugins/dots/dots/index.esm.js +99 -0
  43. package/docs/dist/plugins/dots/dots/index.min.js +1 -0
  44. package/docs/dist/plugins/drag-scrolling/drag-scrolling/index.esm.js +70 -0
  45. package/docs/dist/plugins/drag-scrolling/drag-scrolling/index.min.js +1 -0
  46. package/docs/dist/plugins/full-width/full-width/index.esm.js +31 -0
  47. package/docs/dist/plugins/full-width/full-width/index.min.js +1 -0
  48. package/docs/dist/plugins/scroll-indicator/scroll-indicator/index.esm.js +133 -0
  49. package/docs/dist/plugins/scroll-indicator/scroll-indicator/index.min.js +1 -0
  50. package/docs/dist/plugins/skip-links/skip-links/index.esm.js +42 -0
  51. package/docs/dist/plugins/skip-links/skip-links/index.min.js +1 -0
  52. package/docs/dist/plugins/thumbnails/thumbnails/index.esm.js +41 -0
  53. package/docs/dist/plugins/thumbnails/thumbnails/index.min.js +1 -0
  54. package/docs/index.html +120 -3
  55. package/package.json +35 -6
  56. package/rollup.config.js +58 -32
  57. package/src/core/details.ts +1 -1
  58. package/src/{overflow-slider.ts → core/overflow-slider.ts} +3 -2
  59. package/src/core/slider.ts +75 -21
  60. package/src/core/types.ts +9 -1
  61. package/src/index.ts +1 -12
  62. package/src/overflow-slider.scss +7 -191
  63. package/src/plugins/{arrows.ts → arrows/index.ts} +15 -5
  64. package/src/plugins/arrows/styles.scss +29 -0
  65. package/src/plugins/{dots.ts → dots/index.ts} +1 -1
  66. package/src/plugins/dots/styles.scss +56 -0
  67. package/src/plugins/{drag-scrolling.ts → drag-scrolling/index.ts} +34 -32
  68. package/src/plugins/drag-scrolling/styles.scss +12 -0
  69. package/src/plugins/full-width/index.ts +43 -0
  70. package/src/plugins/{scroll-indicator.ts → scroll-indicator/index.ts} +7 -5
  71. package/src/plugins/scroll-indicator/styles.scss +59 -0
  72. package/src/plugins/{skip-links.ts → skip-links/index.ts} +2 -2
  73. package/src/plugins/skip-links/styles.scss +35 -0
  74. package/src/plugins/thumbnails/index.ts +53 -0
  75. package/tsconfig.json +14 -2
  76. package/dist/index.esm.min.js +0 -2
  77. package/dist/index.js +0 -719
  78. package/docs/dist/overflow-slider.esm.js +0 -704
package/README.md CHANGED
@@ -27,20 +27,18 @@ You don't have to use even class `overflow-slider` and slides can be whatever el
27
27
  If you’re using a bundler (such as Webpack or Rollup), you can install through npm:
28
28
 
29
29
  ```bash
30
- npm install @evermade/oveflow-slider
30
+ npm install @evermade/overflow-slider
31
31
  ```
32
32
 
33
33
  Import the `OverflowSlider` along with plugins you want to use.
34
34
 
35
35
  ```js
36
- import {
37
- OverflowSlider,
38
- DragScrollingPlugin,
39
- SkipLinksPlugin,
40
- ArrowsPlugin,
41
- ScrollIndicatorPlugin,
42
- DotsPlugin
43
- } from "@evermade/overflow-slider";
36
+ import { OverflowSlider } from '@evermade/overflow-slider';
37
+ import DragScrollingPlugin from '@evermade/overflow-slider/plugins/drag-scrolling';
38
+ import SkipLinksPlugin from '@evermade/overflow-slider/plugins/skip-links';
39
+ import ArrowsPlugin from '@evermade/overflow-slider/plugins/arrows';
40
+ import ScrollIndicatorPlugin from '@evermade/overflow-slider/plugins/scroll-indicator';
41
+ import DotsPlugin from '@evermade/overflow-slider/plugins/dots';
44
42
 
45
43
  // minimal example
46
44
  const minimalSlider = new OverflowSlider(
@@ -105,9 +103,9 @@ Note that you can easily write styles from scratch if you want to. See source co
105
103
 
106
104
  ## Known issues
107
105
 
108
- ### Drag Scrolling and Firefox
106
+ ### Drag Scrolling and Smoothness
109
107
 
110
- Drag scrolling does not work very well in Firefox when slides are clikable. We are working on a fix for this if that is possible.
108
+ Scroll snapping doesn't apply smoothly to drag scrolling. It might be browser limitation or some issue with implementation here. Should look into fixing it.
111
109
 
112
110
  ## Limitations
113
111
 
@@ -127,8 +125,34 @@ Looping slides is not supported and likely never will be. It is a feature that i
127
125
 
128
126
  Auto-play is not supported at the moment but can probably be implemented as a plugin. It is not very accessible and should be avoided if possible.
129
127
 
128
+ ## To-do
129
+
130
+ * Make drag scrolling snapping smooth (might be browser limitation)
131
+ * Rethink dot amount calculation
132
+ * Maybe split styles to separate files for plugins (but keep offering bundle as well)
133
+ * Maybe add plugin that adds class for visible slides
134
+ * Document all plugins and their parameters here
135
+
130
136
  ## Changelog
131
137
 
138
+ ### 2.0.1
139
+
140
+ * Fix: Smooth scrolling for moveToSlide method
141
+ * Fix: Prev arrow sometimes leaving visible although there are no more slides to scroll to
142
+
143
+ ### 2.0.0
144
+
145
+ * Breaking: Separate plugins to their own imports/files
146
+ * Add: FullWidthPlugin to allow full width sliders
147
+ * Add: ThumbnailsPlugin to show synchronized thumbnails
148
+ * Add: Slider container 'data-ready' attribute when initialized to help writing CSS
149
+ * Add: Support for optional separate containers for prev and next arrows
150
+ * Add: Slides as array to Slider instance
151
+ * Add: Active slide ID to Slider instance as activeSlideIdx and hook activeSlideChanged
152
+ * Fix: DragScrollingPlugin dragging clickable slides in Firefox
153
+ * Fix: DragScrollingPlugin dragging outside of container bugs in Firefox/Safari
154
+ * Fix: ScrollIndicatorPlugin width calculation when scrollbar and container are not same width
155
+
132
156
  ### 1.1.0
133
157
 
134
158
  * Add: Grab cursor when hovering slider that has DragScrollingPlugin
@@ -0,0 +1,35 @@
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 (slider.container.scrollWidth > slider.container.clientWidth) {
11
+ hasOverflow = true;
12
+ }
13
+ slideCount = (_a = slider.slides.length) !== null && _a !== void 0 ? _a : 0;
14
+ containerWidth = slider.container.offsetWidth;
15
+ scrollableAreaWidth = slider.container.scrollWidth;
16
+ amountOfPages = Math.ceil(scrollableAreaWidth / containerWidth);
17
+ if (slider.container.scrollLeft >= 0) {
18
+ currentPage = Math.floor(slider.container.scrollLeft / containerWidth);
19
+ // consider as last page if the scrollLeft + containerWidth is equal to scrollWidth
20
+ if (slider.container.scrollLeft + containerWidth === 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 };
@@ -0,0 +1 @@
1
+ function t(t){var e;let n,l=!1,o=0,r=0,i=0,a=0,c=1;return t.container.scrollWidth>t.container.clientWidth&&(l=!0),o=null!==(e=t.slides.length)&&void 0!==e?e:0,r=t.container.offsetWidth,i=t.container.scrollWidth,a=Math.ceil(i/r),t.container.scrollLeft>=0&&(c=Math.floor(t.container.scrollLeft/r),t.container.scrollLeft+r===i&&(c=a-1)),n={hasOverflow:l,slideCount:o,containerWidth:r,scrollableAreaWidth:i,amountOfPages:a,currentPage:c},n}export{t as default};
@@ -0,0 +1,26 @@
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
+ };
14
+ const sliderOptions = Object.assign(Object.assign({}, defaults), options);
15
+ // disable smooth scrolling if user prefers reduced motion
16
+ if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
17
+ sliderOptions.scrollBehavior = "auto";
18
+ }
19
+ return Slider(container, sliderOptions, plugins);
20
+ }
21
+ catch (e) {
22
+ console.error(e);
23
+ }
24
+ }
25
+
26
+ export { OverflowSlider as default };
@@ -0,0 +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 s={scrollBehavior:"smooth",scrollStrategy:"fullSlide",slidesSelector:":scope > *"},n=Object.assign(Object.assign({},s),r);return window.matchMedia("(prefers-reduced-motion: reduce)").matches&&(n.scrollBehavior="auto"),e(o,n,t)}catch(e){console.error(e)}}export{o as default};
@@ -0,0 +1,267 @@
1
+ import details from './details.esm.js';
2
+ import { generateId, objectsAreEqual } 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
+ slider.container.addEventListener('scroll', () => slider.emit('scroll'));
73
+ // Listen for mouse down and touch start events on the document
74
+ // This handles both mouse clicks and touch interactions
75
+ let wasInteractedWith = false;
76
+ slider.container.addEventListener('mousedown', () => {
77
+ wasInteractedWith = true;
78
+ });
79
+ slider.container.addEventListener('touchstart', () => {
80
+ wasInteractedWith = true;
81
+ }, { passive: true });
82
+ slider.container.addEventListener('focusin', (e) => {
83
+ // move target parents as long as they are not the container
84
+ // but only if focus didn't start from mouse or touch
85
+ if (!wasInteractedWith) {
86
+ let target = e.target;
87
+ while (target.parentElement !== slider.container) {
88
+ if (target.parentElement) {
89
+ target = target.parentElement;
90
+ }
91
+ else {
92
+ break;
93
+ }
94
+ }
95
+ ensureSlideIsInView(target, 'auto');
96
+ }
97
+ wasInteractedWith = false;
98
+ });
99
+ }
100
+ function setCSSVariables() {
101
+ slider.container.style.setProperty('--slider-container-width', `${slider.details.containerWidth}px`);
102
+ slider.container.style.setProperty('--slider-scrollable-width', `${slider.details.scrollableAreaWidth}px`);
103
+ slider.container.style.setProperty('--slider-slides-count', `${slider.details.slideCount}`);
104
+ }
105
+ function setDataAttributes() {
106
+ slider.container.setAttribute('data-has-overflow', slider.details.hasOverflow ? 'true' : 'false');
107
+ }
108
+ function ensureSlideIsInView(slide, scrollBehavior = null) {
109
+ const behavior = scrollBehavior || slider.options.scrollBehavior;
110
+ const slideRect = slide.getBoundingClientRect();
111
+ const sliderRect = slider.container.getBoundingClientRect();
112
+ const containerWidth = slider.container.offsetWidth;
113
+ const scrollLeft = slider.container.scrollLeft;
114
+ const slideStart = slideRect.left - sliderRect.left + scrollLeft;
115
+ const slideEnd = slideStart + slideRect.width;
116
+ let scrollTarget = null;
117
+ if (slideStart < scrollLeft) {
118
+ scrollTarget = slideStart;
119
+ }
120
+ else if (slideEnd > scrollLeft + containerWidth) {
121
+ scrollTarget = slideEnd - containerWidth;
122
+ }
123
+ else if (slideStart === 0) {
124
+ scrollTarget = 0;
125
+ }
126
+ if (scrollTarget !== null) {
127
+ slider.container.style.scrollSnapType = 'none';
128
+ // seems like in order for scroll behavior: smooth to work, we need to wait a bit to disable scrollSnapType
129
+ setTimeout((scrollTarget) => {
130
+ slider.container.scrollTo({ left: scrollTarget, behavior: behavior });
131
+ }, 50, scrollTarget);
132
+ setTimeout(() => {
133
+ // leave snapping off to fix issues with slide moving back on focus
134
+ if (behavior == 'smooth') {
135
+ slider.container.style.scrollSnapType = '';
136
+ }
137
+ }, 500);
138
+ }
139
+ }
140
+ function setActiveSlideIdx() {
141
+ const sliderRect = slider.container.getBoundingClientRect();
142
+ const scrollLeft = slider.container.scrollLeft;
143
+ const slides = slider.slides;
144
+ let activeSlideIdx = 0;
145
+ for (let i = 0; i < slides.length; i++) {
146
+ const slideRect = slides[i].getBoundingClientRect();
147
+ const slideStart = slideRect.left - sliderRect.left + scrollLeft + getGapSize();
148
+ if (slideStart > scrollLeft) {
149
+ activeSlideIdx = i;
150
+ break;
151
+ }
152
+ }
153
+ const oldActiveSlideIdx = slider.activeSlideIdx;
154
+ slider.activeSlideIdx = activeSlideIdx;
155
+ if (oldActiveSlideIdx !== activeSlideIdx) {
156
+ slider.emit('activeSlideChanged');
157
+ }
158
+ }
159
+ function moveToSlide(idx) {
160
+ const slide = slider.slides[idx];
161
+ if (slide) {
162
+ ensureSlideIsInView(slide);
163
+ }
164
+ }
165
+ function getGapSize() {
166
+ let gapSize = 0;
167
+ if (slider.slides.length > 1) {
168
+ const firstSlideRect = slider.slides[0].getBoundingClientRect();
169
+ const secondSlideRect = slider.slides[1].getBoundingClientRect();
170
+ gapSize = secondSlideRect.left - firstSlideRect.right;
171
+ }
172
+ return gapSize;
173
+ }
174
+ function moveToDirection(direction = "prev") {
175
+ const scrollStrategy = slider.options.scrollStrategy;
176
+ const scrollLeft = slider.container.scrollLeft;
177
+ const sliderRect = slider.container.getBoundingClientRect();
178
+ const containerWidth = slider.container.offsetWidth;
179
+ let targetScrollPosition = scrollLeft;
180
+ if (direction === 'prev') {
181
+ targetScrollPosition = Math.max(0, scrollLeft - slider.container.offsetWidth);
182
+ }
183
+ else if (direction === 'next') {
184
+ targetScrollPosition = Math.min(slider.container.scrollWidth, scrollLeft + slider.container.offsetWidth);
185
+ }
186
+ if (scrollStrategy === 'fullSlide') {
187
+ let fullSldeTargetScrollPosition = null;
188
+ // extend targetScrollPosition to include gap
189
+ if (direction === 'prev') {
190
+ fullSldeTargetScrollPosition = Math.max(0, targetScrollPosition - getGapSize());
191
+ }
192
+ else {
193
+ fullSldeTargetScrollPosition = Math.min(slider.container.scrollWidth, targetScrollPosition + getGapSize());
194
+ }
195
+ if (direction === 'next') {
196
+ let partialSlideFound = false;
197
+ for (let slide of slider.slides) {
198
+ const slideRect = slide.getBoundingClientRect();
199
+ const slideStart = slideRect.left - sliderRect.left + scrollLeft;
200
+ const slideEnd = slideStart + slideRect.width;
201
+ if (slideStart < targetScrollPosition && slideEnd > targetScrollPosition) {
202
+ fullSldeTargetScrollPosition = slideStart;
203
+ partialSlideFound = true;
204
+ break;
205
+ }
206
+ }
207
+ if (!partialSlideFound) {
208
+ fullSldeTargetScrollPosition = Math.min(targetScrollPosition, slider.container.scrollWidth - slider.container.offsetWidth);
209
+ }
210
+ if (fullSldeTargetScrollPosition && fullSldeTargetScrollPosition > scrollLeft) {
211
+ targetScrollPosition = fullSldeTargetScrollPosition;
212
+ }
213
+ }
214
+ else {
215
+ let partialSlideFound = false;
216
+ for (let slide of slider.slides) {
217
+ const slideRect = slide.getBoundingClientRect();
218
+ const slideStart = slideRect.left - sliderRect.left + scrollLeft;
219
+ const slideEnd = slideStart + slideRect.width;
220
+ if (slideStart < scrollLeft && slideEnd > scrollLeft) {
221
+ fullSldeTargetScrollPosition = slideEnd - containerWidth;
222
+ partialSlideFound = true;
223
+ break;
224
+ }
225
+ }
226
+ if (!partialSlideFound) {
227
+ fullSldeTargetScrollPosition = Math.max(0, scrollLeft - containerWidth);
228
+ }
229
+ if (fullSldeTargetScrollPosition && fullSldeTargetScrollPosition < scrollLeft) {
230
+ targetScrollPosition = fullSldeTargetScrollPosition;
231
+ }
232
+ }
233
+ }
234
+ slider.container.style.scrollBehavior = slider.options.scrollBehavior;
235
+ slider.container.scrollLeft = targetScrollPosition;
236
+ setTimeout(() => slider.container.style.scrollBehavior = '', 50);
237
+ }
238
+ function on(name, cb) {
239
+ if (!subs[name]) {
240
+ subs[name] = [];
241
+ }
242
+ subs[name].push(cb);
243
+ }
244
+ function emit(name) {
245
+ var _a;
246
+ if (subs && subs[name]) {
247
+ subs[name].forEach(cb => {
248
+ cb(slider);
249
+ });
250
+ }
251
+ const optionCallBack = (_a = slider === null || slider === void 0 ? void 0 : slider.options) === null || _a === void 0 ? void 0 : _a[name];
252
+ if (typeof optionCallBack === 'function') {
253
+ optionCallBack(slider);
254
+ }
255
+ }
256
+ slider = {
257
+ emit,
258
+ moveToDirection,
259
+ moveToSlide,
260
+ on,
261
+ options,
262
+ };
263
+ init();
264
+ return slider;
265
+ }
266
+
267
+ export { Slider as default };
@@ -0,0 +1 @@
1
+ import e from"./details.min.js";import{generateId as t,objectsAreEqual as n}from"./utils.min.js";function i(i,o,l){let r,s={};function a(t=!1){const i=r.details,o=e(r);r.details=o,t||n(i,o)?t&&r.emit("detailsChanged"):r.emit("detailsChanged")}function c(){r.slides=Array.from(r.container.querySelectorAll(r.options.slidesSelector))}function d(){r.container.style.setProperty("--slider-container-width",`${r.details.containerWidth}px`),r.container.style.setProperty("--slider-scrollable-width",`${r.details.scrollableAreaWidth}px`),r.container.style.setProperty("--slider-slides-count",`${r.details.slideCount}`)}function f(){r.container.setAttribute("data-has-overflow",r.details.hasOverflow?"true":"false")}function u(e,t=null){const n=t||r.options.scrollBehavior,i=e.getBoundingClientRect(),o=r.container.getBoundingClientRect(),l=r.container.offsetWidth,s=r.container.scrollLeft,a=i.left-o.left+s,c=a+i.width;let d=null;a<s?d=a:c>s+l?d=c-l:0===a&&(d=0),null!==d&&(r.container.style.scrollSnapType="none",setTimeout((e=>{r.container.scrollTo({left:e,behavior:n})}),50,d),setTimeout((()=>{"smooth"==n&&(r.container.style.scrollSnapType="")}),500))}function h(){const e=r.container.getBoundingClientRect(),t=r.container.scrollLeft,n=r.slides;let i=0;for(let o=0;o<n.length;o++){if(n[o].getBoundingClientRect().left-e.left+t+m()>t){i=o;break}}const o=r.activeSlideIdx;r.activeSlideIdx=i,o!==i&&r.emit("activeSlideChanged")}function m(){let e=0;if(r.slides.length>1){const t=r.slides[0].getBoundingClientRect();e=r.slides[1].getBoundingClientRect().left-t.right}return e}return r={emit:function(e){var t;s&&s[e]&&s[e].forEach((e=>{e(r)}));const n=null===(t=null==r?void 0:r.options)||void 0===t?void 0:t[e];"function"==typeof n&&n(r)},moveToDirection:function(e="prev"){const t=r.options.scrollStrategy,n=r.container.scrollLeft,i=r.container.getBoundingClientRect(),o=r.container.offsetWidth;let l=n;if("prev"===e?l=Math.max(0,n-r.container.offsetWidth):"next"===e&&(l=Math.min(r.container.scrollWidth,n+r.container.offsetWidth)),"fullSlide"===t){let t=null;if(t="prev"===e?Math.max(0,l-m()):Math.min(r.container.scrollWidth,l+m()),"next"===e){let e=!1;for(let o of r.slides){const r=o.getBoundingClientRect(),s=r.left-i.left+n,a=s+r.width;if(s<l&&a>l){t=s,e=!0;break}}e||(t=Math.min(l,r.container.scrollWidth-r.container.offsetWidth)),t&&t>n&&(l=t)}else{let e=!1;for(let l of r.slides){const r=l.getBoundingClientRect(),s=r.left-i.left+n,a=s+r.width;if(s<n&&a>n){t=a-o,e=!0;break}}e||(t=Math.max(0,n-o)),t&&t<n&&(l=t)}}r.container.style.scrollBehavior=r.options.scrollBehavior,r.container.scrollLeft=l,setTimeout((()=>r.container.style.scrollBehavior=""),50)},moveToSlide:function(e){const t=r.slides[e];t&&u(t)},on:function(e,t){s[e]||(s[e]=[]),s[e].push(t)},options:o},function(){r.container=i;let e=i.getAttribute("id");null===e&&(e=t("overflow-slider"),i.setAttribute("id",e)),c(),a(!0),h(),r.on("contentsChanged",(()=>{c(),a(),h()})),r.on("containerSizeChanged",(()=>a()));let n=0;if(r.on("scroll",(()=>{n&&window.cancelAnimationFrame(n),n=window.requestAnimationFrame((()=>{a(),h()}))})),function(){new MutationObserver((()=>r.emit("contentsChanged"))).observe(r.container,{childList:!0});new ResizeObserver((()=>r.emit("containerSizeChanged"))).observe(r.container),r.container.addEventListener("scroll",(()=>r.emit("scroll")));let e=!1;r.container.addEventListener("mousedown",(()=>{e=!0})),r.container.addEventListener("touchstart",(()=>{e=!0}),{passive:!0}),r.container.addEventListener("focusin",(t=>{if(!e){let e=t.target;for(;e.parentElement!==r.container&&e.parentElement;)e=e.parentElement;u(e,"auto")}e=!1}))}(),f(),d(),l)for(const e of l)e(r);r.on("detailsChanged",(()=>{f(),d()})),r.emit("created"),r.container.setAttribute("data-ready","true")}(),r}export{i as default};
@@ -0,0 +1,22 @@
1
+ function generateId(prefix, i = 1) {
2
+ const id = `${prefix}-${i}`;
3
+ if (document.getElementById(id)) {
4
+ return generateId(prefix, i + 1);
5
+ }
6
+ return id;
7
+ }
8
+ function objectsAreEqual(obj1, obj2) {
9
+ const keys1 = Object.keys(obj1);
10
+ const keys2 = Object.keys(obj2);
11
+ if (keys1.length !== keys2.length) {
12
+ return false;
13
+ }
14
+ for (let key of keys1) {
15
+ if (obj2.hasOwnProperty(key) === false || obj1[key] !== obj2[key]) {
16
+ return false;
17
+ }
18
+ }
19
+ return true;
20
+ }
21
+
22
+ export { generateId, objectsAreEqual };
@@ -0,0 +1 @@
1
+ function t(e,n=1){const r=`${e}-${n}`;return document.getElementById(r)?t(e,n+1):r}function e(t,e){const n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(let r of n)if(!1===e.hasOwnProperty(r)||t[r]!==e[r])return!1;return!0}export{t as generateId,e as objectsAreEqual};