@evermade/overflow-slider 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +290 -5
- package/dist/core/slider.esm.js +17 -4
- package/dist/core/slider.min.js +1 -1
- package/dist/core/utils.esm.js +2 -1
- package/dist/core/utils.min.js +1 -1
- package/dist/plugins/arrows/{arrows/index.esm.js → index.esm.js} +7 -7
- package/dist/plugins/arrows/index.min.js +1 -0
- package/{docs/dist/plugins/skip-links → dist/plugins}/skip-links/index.esm.js +1 -1
- package/dist/plugins/skip-links/index.min.js +1 -0
- package/docs/assets/demo.js +23 -8
- package/docs/dist/core/slider.esm.js +17 -4
- package/docs/dist/core/slider.min.js +1 -1
- package/docs/dist/core/utils.esm.js +2 -1
- package/docs/dist/core/utils.min.js +1 -1
- package/docs/dist/plugins/arrows/{arrows/index.esm.js → index.esm.js} +7 -7
- package/docs/dist/plugins/arrows/index.min.js +1 -0
- package/{dist/plugins/skip-links → docs/dist/plugins}/skip-links/index.esm.js +1 -1
- package/docs/dist/plugins/skip-links/index.min.js +1 -0
- package/docs/index-rtl.html +16 -0
- package/docs/index.html +16 -0
- package/package.json +17 -17
- package/rollup.config.js +13 -5
- package/src/core/slider.ts +22 -9
- package/src/core/types.ts +10 -3
- package/src/core/utils.ts +9 -5
- package/src/plugins/arrows/index.ts +7 -4
- package/src/plugins/dots/index.ts +1 -1
- package/src/plugins/drag-scrolling/index.ts +1 -1
- package/src/plugins/fade/index.ts +1 -1
- package/src/plugins/full-width/index.ts +1 -1
- package/src/plugins/scroll-indicator/index.ts +1 -1
- package/src/plugins/skip-links/index.ts +1 -1
- package/src/plugins/thumbnails/index.ts +1 -1
- package/dist/plugins/arrows/arrows/index.min.js +0 -1
- package/dist/plugins/skip-links/skip-links/index.min.js +0 -1
- package/docs/dist/plugins/arrows/arrows/index.min.js +0 -1
- package/docs/dist/plugins/skip-links/skip-links/index.min.js +0 -1
- /package/dist/plugins/dots/{dots/index.esm.js → index.esm.js} +0 -0
- /package/dist/plugins/dots/{dots/index.min.js → index.min.js} +0 -0
- /package/dist/plugins/drag-scrolling/{drag-scrolling/index.esm.js → index.esm.js} +0 -0
- /package/dist/plugins/drag-scrolling/{drag-scrolling/index.min.js → index.min.js} +0 -0
- /package/dist/plugins/fade/{fade/index.esm.js → index.esm.js} +0 -0
- /package/dist/plugins/fade/{fade/index.min.js → index.min.js} +0 -0
- /package/dist/plugins/full-width/{full-width/index.esm.js → index.esm.js} +0 -0
- /package/dist/plugins/full-width/{full-width/index.min.js → index.min.js} +0 -0
- /package/dist/plugins/scroll-indicator/{scroll-indicator/index.esm.js → index.esm.js} +0 -0
- /package/dist/plugins/scroll-indicator/{scroll-indicator/index.min.js → index.min.js} +0 -0
- /package/dist/plugins/thumbnails/{thumbnails/index.esm.js → index.esm.js} +0 -0
- /package/dist/plugins/thumbnails/{thumbnails/index.min.js → index.min.js} +0 -0
- /package/docs/dist/plugins/dots/{dots/index.esm.js → index.esm.js} +0 -0
- /package/docs/dist/plugins/dots/{dots/index.min.js → index.min.js} +0 -0
- /package/docs/dist/plugins/drag-scrolling/{drag-scrolling/index.esm.js → index.esm.js} +0 -0
- /package/docs/dist/plugins/drag-scrolling/{drag-scrolling/index.min.js → index.min.js} +0 -0
- /package/docs/dist/plugins/fade/{fade/index.esm.js → index.esm.js} +0 -0
- /package/docs/dist/plugins/fade/{fade/index.min.js → index.min.js} +0 -0
- /package/docs/dist/plugins/full-width/{full-width/index.esm.js → index.esm.js} +0 -0
- /package/docs/dist/plugins/full-width/{full-width/index.min.js → index.min.js} +0 -0
- /package/docs/dist/plugins/scroll-indicator/{scroll-indicator/index.esm.js → index.esm.js} +0 -0
- /package/docs/dist/plugins/scroll-indicator/{scroll-indicator/index.min.js → index.min.js} +0 -0
- /package/docs/dist/plugins/thumbnails/{thumbnails/index.esm.js → index.esm.js} +0 -0
- /package/docs/dist/plugins/thumbnails/{thumbnails/index.min.js → index.min.js} +0 -0
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ npm install @evermade/overflow-slider
|
|
|
33
33
|
|
|
34
34
|
Import the `OverflowSlider` along with plugins you want to use.
|
|
35
35
|
|
|
36
|
-
```
|
|
36
|
+
```ts
|
|
37
37
|
import { OverflowSlider } from '@evermade/overflow-slider';
|
|
38
38
|
import DragScrollingPlugin from '@evermade/overflow-slider/plugins/drag-scrolling';
|
|
39
39
|
import SkipLinksPlugin from '@evermade/overflow-slider/plugins/skip-links';
|
|
@@ -135,9 +135,9 @@ Usage:
|
|
|
135
135
|
--gap: 1.5rem;
|
|
136
136
|
gap: var(--gap);
|
|
137
137
|
> * {
|
|
138
|
-
--
|
|
138
|
+
--slides-per-view: 3;
|
|
139
139
|
@include slideWidth(
|
|
140
|
-
var(--
|
|
140
|
+
var(--slides-per-view),
|
|
141
141
|
var(--gap),
|
|
142
142
|
var(--slider-container-width)
|
|
143
143
|
);
|
|
@@ -149,7 +149,280 @@ Note that if you are using FullWidthPlugin, you should use container width from
|
|
|
149
149
|
|
|
150
150
|
## Plugins
|
|
151
151
|
|
|
152
|
-
|
|
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
|
+
```
|
|
153
426
|
|
|
154
427
|
## Known issues
|
|
155
428
|
|
|
@@ -159,7 +432,7 @@ You can use use Overflow Slider within CSS grid but if you are using `fr` units
|
|
|
159
432
|
|
|
160
433
|
### CSS scroll-snap can be buggy
|
|
161
434
|
|
|
162
|
-
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.
|
|
163
436
|
|
|
164
437
|
## Limitations
|
|
165
438
|
|
|
@@ -183,6 +456,18 @@ Auto-play is not supported at the moment but can probably be implemented as a pl
|
|
|
183
456
|
|
|
184
457
|
## Changelog
|
|
185
458
|
|
|
459
|
+
### 3.3.0
|
|
460
|
+
|
|
461
|
+
* Add: Ability to move each direction by one slide at a time via `moveToSlideInDirection` prev/next
|
|
462
|
+
* Add: Support for ArrowsPlugin to move by one slide at a time (default is still one view at a time)
|
|
463
|
+
* Fix: Remove console logs
|
|
464
|
+
* Refactor: Plugin build paths to match import paths. Might fix some eslint warnings. If you are not using import but directly referencing the plugin files under `dist/` you might need to update your paths.
|
|
465
|
+
|
|
466
|
+
### 3.2.1
|
|
467
|
+
|
|
468
|
+
* Add: Documentation on plugins
|
|
469
|
+
* Fix: Make types more strict and remove all "any" types
|
|
470
|
+
|
|
186
471
|
### 3.2.0
|
|
187
472
|
|
|
188
473
|
* Add: RTL support
|
package/dist/core/slider.esm.js
CHANGED
|
@@ -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
|
-
//
|
|
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)) {
|
|
@@ -267,7 +267,6 @@ function Slider(container, options, plugins) {
|
|
|
267
267
|
}
|
|
268
268
|
const oldActiveSlideIdx = slider.activeSlideIdx;
|
|
269
269
|
slider.activeSlideIdx = activeSlideIdx;
|
|
270
|
-
// console.log('activeSlideIdx', activeSlideIdx);
|
|
271
270
|
if (oldActiveSlideIdx !== activeSlideIdx) {
|
|
272
271
|
slider.emit('activeSlideChanged');
|
|
273
272
|
}
|
|
@@ -278,6 +277,19 @@ function Slider(container, options, plugins) {
|
|
|
278
277
|
ensureSlideIsInView(slide);
|
|
279
278
|
}
|
|
280
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
|
+
}
|
|
281
293
|
function getInclusiveScrollWidth() {
|
|
282
294
|
return slider.container.scrollWidth + getOutermostChildrenEdgeMarginSum(slider.container);
|
|
283
295
|
}
|
|
@@ -408,7 +420,6 @@ function Slider(container, options, plugins) {
|
|
|
408
420
|
rect: slide.getBoundingClientRect(),
|
|
409
421
|
});
|
|
410
422
|
}
|
|
411
|
-
console.log('slideReference', slideReference);
|
|
412
423
|
let snapTarget = null;
|
|
413
424
|
const scrollPosition = getScrollLeft();
|
|
414
425
|
if (isMovingForward) {
|
|
@@ -463,14 +474,16 @@ function Slider(container, options, plugins) {
|
|
|
463
474
|
});
|
|
464
475
|
}
|
|
465
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
|
|
466
478
|
if (typeof optionCallBack === 'function') {
|
|
467
|
-
optionCallBack(slider);
|
|
479
|
+
optionCallBack(slider); // Type assertion here
|
|
468
480
|
}
|
|
469
481
|
}
|
|
470
482
|
slider = {
|
|
471
483
|
emit,
|
|
472
484
|
moveToDirection,
|
|
473
485
|
moveToSlide,
|
|
486
|
+
moveToSlideInDirection,
|
|
474
487
|
snapToClosestSlide,
|
|
475
488
|
getInclusiveScrollWidth,
|
|
476
489
|
getInclusiveClientWidth,
|
package/dist/core/slider.min.js
CHANGED
|
@@ -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,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+
|
|
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};
|
package/dist/core/utils.esm.js
CHANGED
|
@@ -12,7 +12,8 @@ function objectsAreEqual(obj1, obj2) {
|
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
14
|
for (let key of keys1) {
|
|
15
|
-
|
|
15
|
+
// Use `Object.prototype.hasOwnProperty.call` for better safety
|
|
16
|
+
if (!Object.prototype.hasOwnProperty.call(obj2, key) || obj1[key] !== obj2[key]) {
|
|
16
17
|
return false;
|
|
17
18
|
}
|
|
18
19
|
}
|
package/dist/core/utils.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e
|
|
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(!Object.prototype.hasOwnProperty.call(e,r)||t[r]!==e[r])return!1;return!0}function n(t){if(0===t.children.length)return 0;const e=t.children[0],n=getComputedStyle(e),r=parseFloat(n.marginLeft),o=t.children[t.children.length-1],l=getComputedStyle(o);return r+parseFloat(l.marginRight)}export{t as generateId,n as getOutermostChildrenEdgeMarginSum,e as objectsAreEqual};
|
|
@@ -13,7 +13,7 @@ const DEFAULT_CLASS_NAMES = {
|
|
|
13
13
|
};
|
|
14
14
|
function ArrowsPlugin(args) {
|
|
15
15
|
return (slider) => {
|
|
16
|
-
var _a, _b, _c, _d, _e, _f;
|
|
16
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
17
17
|
const options = {
|
|
18
18
|
texts: Object.assign(Object.assign({}, DEFAULT_TEXTS), (args === null || args === void 0 ? void 0 : args.texts) || []),
|
|
19
19
|
icons: Object.assign(Object.assign({}, DEFAULT_ICONS), (args === null || args === void 0 ? void 0 : args.icons) || []),
|
|
@@ -21,6 +21,7 @@ function ArrowsPlugin(args) {
|
|
|
21
21
|
container: (_a = args === null || args === void 0 ? void 0 : args.container) !== null && _a !== void 0 ? _a : null,
|
|
22
22
|
containerPrev: (_b = args === null || args === void 0 ? void 0 : args.containerPrev) !== null && _b !== void 0 ? _b : null,
|
|
23
23
|
containerNext: (_c = args === null || args === void 0 ? void 0 : args.containerNext) !== null && _c !== void 0 ? _c : null,
|
|
24
|
+
movementType: (_d = args === null || args === void 0 ? void 0 : args.movementType) !== null && _d !== void 0 ? _d : 'view',
|
|
24
25
|
};
|
|
25
26
|
const nav = document.createElement('div');
|
|
26
27
|
nav.classList.add(options.classNames.navContainer);
|
|
@@ -28,24 +29,24 @@ function ArrowsPlugin(args) {
|
|
|
28
29
|
prev.setAttribute('class', options.classNames.prevButton);
|
|
29
30
|
prev.setAttribute('type', 'button');
|
|
30
31
|
prev.setAttribute('aria-label', options.texts.buttonPrevious);
|
|
31
|
-
prev.setAttribute('aria-controls', (
|
|
32
|
+
prev.setAttribute('aria-controls', (_e = slider.container.getAttribute('id')) !== null && _e !== void 0 ? _e : '');
|
|
32
33
|
prev.setAttribute('data-type', 'prev');
|
|
33
34
|
prev.innerHTML = slider.options.rtl ? options.icons.next : options.icons.prev;
|
|
34
35
|
prev.addEventListener('click', () => {
|
|
35
36
|
if (prev.getAttribute('data-has-content') === 'true') {
|
|
36
|
-
slider.moveToDirection('prev');
|
|
37
|
+
options.movementType === 'slide' ? slider.moveToSlideInDirection('prev') : slider.moveToDirection('prev');
|
|
37
38
|
}
|
|
38
39
|
});
|
|
39
40
|
const next = document.createElement('button');
|
|
40
41
|
next.setAttribute('class', options.classNames.nextButton);
|
|
41
42
|
next.setAttribute('type', 'button');
|
|
42
43
|
next.setAttribute('aria-label', options.texts.buttonNext);
|
|
43
|
-
next.setAttribute('aria-controls', (
|
|
44
|
+
next.setAttribute('aria-controls', (_f = slider.container.getAttribute('id')) !== null && _f !== void 0 ? _f : '');
|
|
44
45
|
next.setAttribute('data-type', 'next');
|
|
45
46
|
next.innerHTML = slider.options.rtl ? options.icons.prev : options.icons.next;
|
|
46
47
|
next.addEventListener('click', () => {
|
|
47
48
|
if (next.getAttribute('data-has-content') === 'true') {
|
|
48
|
-
slider.moveToDirection('next');
|
|
49
|
+
options.movementType === 'slide' ? slider.moveToSlideInDirection('next') : slider.moveToDirection('next');
|
|
49
50
|
}
|
|
50
51
|
});
|
|
51
52
|
// insert buttons to the nav
|
|
@@ -69,7 +70,6 @@ function ArrowsPlugin(args) {
|
|
|
69
70
|
else {
|
|
70
71
|
next.setAttribute('data-has-content', 'true');
|
|
71
72
|
}
|
|
72
|
-
console.log('next', scrollLeft + clientWidth, scrollWidth);
|
|
73
73
|
};
|
|
74
74
|
if (options.containerNext && options.containerPrev) {
|
|
75
75
|
options.containerPrev.appendChild(prev);
|
|
@@ -80,7 +80,7 @@ function ArrowsPlugin(args) {
|
|
|
80
80
|
options.container.appendChild(nav);
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
|
-
(
|
|
83
|
+
(_g = slider.container.parentNode) === null || _g === void 0 ? void 0 : _g.insertBefore(nav, slider.container.nextSibling);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
update();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t={buttonPrevious:"Previous items",buttonNext:"Next items"},e={prev:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.6 3.4l-7.6 7.6 7.6 7.6 1.4-1.4-5-5h12.6v-2h-12.6l5-5z"/></svg>',next:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.4 3.4l-1.4 1.4 5 5h-12.6v2h12.6l-5 5 1.4 1.4 7.6-7.6z"/></svg>'},n={navContainer:"overflow-slider__arrows",prevButton:"overflow-slider__arrows-button overflow-slider__arrows-button--prev",nextButton:"overflow-slider__arrows-button overflow-slider__arrows-button--next"};function o(o){return i=>{var r,s,a,l,c,u,d;const v={texts:Object.assign(Object.assign({},t),(null==o?void 0:o.texts)||[]),icons:Object.assign(Object.assign({},e),(null==o?void 0:o.icons)||[]),classNames:Object.assign(Object.assign({},n),(null==o?void 0:o.classNames)||[]),container:null!==(r=null==o?void 0:o.container)&&void 0!==r?r:null,containerPrev:null!==(s=null==o?void 0:o.containerPrev)&&void 0!==s?s:null,containerNext:null!==(a=null==o?void 0:o.containerNext)&&void 0!==a?a:null,movementType:null!==(l=null==o?void 0:o.movementType)&&void 0!==l?l:"view"},b=document.createElement("div");b.classList.add(v.classNames.navContainer);const p=document.createElement("button");p.setAttribute("class",v.classNames.prevButton),p.setAttribute("type","button"),p.setAttribute("aria-label",v.texts.buttonPrevious),p.setAttribute("aria-controls",null!==(c=i.container.getAttribute("id"))&&void 0!==c?c:""),p.setAttribute("data-type","prev"),p.innerHTML=i.options.rtl?v.icons.next:v.icons.prev,p.addEventListener("click",(()=>{"true"===p.getAttribute("data-has-content")&&("slide"===v.movementType?i.moveToSlideInDirection("prev"):i.moveToDirection("prev"))}));const h=document.createElement("button");h.setAttribute("class",v.classNames.nextButton),h.setAttribute("type","button"),h.setAttribute("aria-label",v.texts.buttonNext),h.setAttribute("aria-controls",null!==(u=i.container.getAttribute("id"))&&void 0!==u?u:""),h.setAttribute("data-type","next"),h.innerHTML=i.options.rtl?v.icons.prev:v.icons.next,h.addEventListener("click",(()=>{"true"===h.getAttribute("data-has-content")&&("slide"===v.movementType?i.moveToSlideInDirection("next"):i.moveToDirection("next"))})),b.appendChild(p),b.appendChild(h);const m=()=>{const t=i.getScrollLeft(),e=i.getInclusiveScrollWidth(),n=i.getInclusiveClientWidth();0===Math.floor(t)?p.setAttribute("data-has-content","false"):p.setAttribute("data-has-content","true");Math.abs(Math.floor(t+n)-Math.floor(e))<=1?h.setAttribute("data-has-content","false"):h.setAttribute("data-has-content","true")};v.containerNext&&v.containerPrev?(v.containerPrev.appendChild(p),v.containerNext.appendChild(h)):v.container?v.container.appendChild(b):null===(d=i.container.parentNode)||void 0===d||d.insertBefore(b,i.container.nextSibling),m(),i.on("scrollEnd",m),i.on("contentsChanged",m),i.on("containerSizeChanged",m)}}export{o as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{generateId as e}from"../../core/utils.min.js";const t={skipList:"Skip list"},n={skipLink:"screen-reader-text",skipLinkTarget:"overflow-slider__skip-link-target"};function i(i){return r=>{var o,s,a,l,c,d;const u={texts:Object.assign(Object.assign({},t),(null==i?void 0:i.texts)||[]),classNames:Object.assign(Object.assign({},n),(null==i?void 0:i.classNames)||[]),containerBefore:null!==(o=null==i?void 0:i.containerAfter)&&void 0!==o?o:null,containerAfter:null!==(s=null==i?void 0:i.containerAfter)&&void 0!==s?s:null},f=e("overflow-slider-skip"),p=document.createElement("a");p.setAttribute("href",`#${f}`),p.textContent=u.texts.skipList,p.classList.add(u.classNames.skipLink);const v=document.createElement("div");v.setAttribute("id",f),v.setAttribute("tabindex","-1"),u.containerBefore?null===(a=u.containerBefore.parentNode)||void 0===a||a.insertBefore(p,u.containerBefore):null===(l=r.container.parentNode)||void 0===l||l.insertBefore(p,r.container),u.containerAfter?null===(c=u.containerAfter.parentNode)||void 0===c||c.insertBefore(v,u.containerAfter.nextSibling):null===(d=r.container.parentNode)||void 0===d||d.insertBefore(v,r.container.nextSibling)}}export{i as default};
|
package/docs/assets/demo.js
CHANGED
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
* import SkipLinksPlugin from '@overflow-slider/plugins/skip-links';
|
|
12
12
|
*/
|
|
13
13
|
import { OverflowSlider } from '../dist/index.esm.js';
|
|
14
|
-
import DragScrollingPlugin from '../dist/plugins/drag-scrolling/
|
|
15
|
-
import SkipLinksPlugin from '../dist/plugins/skip-links/
|
|
16
|
-
import ArrowsPlugin from '../dist/plugins/arrows/
|
|
17
|
-
import ScrollIndicatorPlugin from '../dist/plugins/scroll-indicator/
|
|
18
|
-
import DotsPlugin from '../dist/plugins/dots/
|
|
19
|
-
import FullWidthPlugin from '../dist/plugins/full-width/
|
|
20
|
-
import ThumbnailsPlugin from '../dist/plugins/thumbnails/
|
|
21
|
-
import FadePlugin from '../dist/plugins/fade/
|
|
14
|
+
import DragScrollingPlugin from '../dist/plugins/drag-scrolling/index.esm.js';
|
|
15
|
+
import SkipLinksPlugin from '../dist/plugins/skip-links/index.esm.js';
|
|
16
|
+
import ArrowsPlugin from '../dist/plugins/arrows/index.esm.js';
|
|
17
|
+
import ScrollIndicatorPlugin from '../dist/plugins/scroll-indicator/index.esm.js';
|
|
18
|
+
import DotsPlugin from '../dist/plugins/dots/index.esm.js';
|
|
19
|
+
import FullWidthPlugin from '../dist/plugins/full-width/index.esm.js';
|
|
20
|
+
import ThumbnailsPlugin from '../dist/plugins/thumbnails/index.esm.js';
|
|
21
|
+
import FadePlugin from '../dist/plugins/fade/index.esm.js';
|
|
22
22
|
|
|
23
23
|
(function () {
|
|
24
24
|
const init = () => {
|
|
@@ -76,6 +76,21 @@ import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
|
76
76
|
);
|
|
77
77
|
console.log( '1-arrows', example1Arrows );
|
|
78
78
|
|
|
79
|
+
const example1ArrowsBySlide = new OverflowSlider(
|
|
80
|
+
document.querySelector( '.example-container-1-arrows-by-slide' ),
|
|
81
|
+
{
|
|
82
|
+
rtl: document.documentElement.dir === 'rtl',
|
|
83
|
+
},
|
|
84
|
+
[
|
|
85
|
+
DragScrollingPlugin(),
|
|
86
|
+
SkipLinksPlugin(),
|
|
87
|
+
ArrowsPlugin({
|
|
88
|
+
movementType: 'slide',
|
|
89
|
+
}),
|
|
90
|
+
]
|
|
91
|
+
);
|
|
92
|
+
console.log( '1-arrows-by-slide', example1ArrowsBySlide );
|
|
93
|
+
|
|
79
94
|
const example1ScrollIndicator = new OverflowSlider(
|
|
80
95
|
document.querySelector( '.example-container-1-scroll-indicator' ),
|
|
81
96
|
{
|
|
@@ -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
|
-
//
|
|
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)) {
|
|
@@ -267,7 +267,6 @@ function Slider(container, options, plugins) {
|
|
|
267
267
|
}
|
|
268
268
|
const oldActiveSlideIdx = slider.activeSlideIdx;
|
|
269
269
|
slider.activeSlideIdx = activeSlideIdx;
|
|
270
|
-
// console.log('activeSlideIdx', activeSlideIdx);
|
|
271
270
|
if (oldActiveSlideIdx !== activeSlideIdx) {
|
|
272
271
|
slider.emit('activeSlideChanged');
|
|
273
272
|
}
|
|
@@ -278,6 +277,19 @@ function Slider(container, options, plugins) {
|
|
|
278
277
|
ensureSlideIsInView(slide);
|
|
279
278
|
}
|
|
280
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
|
+
}
|
|
281
293
|
function getInclusiveScrollWidth() {
|
|
282
294
|
return slider.container.scrollWidth + getOutermostChildrenEdgeMarginSum(slider.container);
|
|
283
295
|
}
|
|
@@ -408,7 +420,6 @@ function Slider(container, options, plugins) {
|
|
|
408
420
|
rect: slide.getBoundingClientRect(),
|
|
409
421
|
});
|
|
410
422
|
}
|
|
411
|
-
console.log('slideReference', slideReference);
|
|
412
423
|
let snapTarget = null;
|
|
413
424
|
const scrollPosition = getScrollLeft();
|
|
414
425
|
if (isMovingForward) {
|
|
@@ -463,14 +474,16 @@ function Slider(container, options, plugins) {
|
|
|
463
474
|
});
|
|
464
475
|
}
|
|
465
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
|
|
466
478
|
if (typeof optionCallBack === 'function') {
|
|
467
|
-
optionCallBack(slider);
|
|
479
|
+
optionCallBack(slider); // Type assertion here
|
|
468
480
|
}
|
|
469
481
|
}
|
|
470
482
|
slider = {
|
|
471
483
|
emit,
|
|
472
484
|
moveToDirection,
|
|
473
485
|
moveToSlide,
|
|
486
|
+
moveToSlideInDirection,
|
|
474
487
|
snapToClosestSlide,
|
|
475
488
|
getInclusiveScrollWidth,
|
|
476
489
|
getInclusiveClientWidth,
|