@evermade/overflow-slider 4.0.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +39 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/plugins/arrows/index.d.ts +1 -1
- package/dist/plugins/autoplay/index.d.ts +1 -1
- package/dist/plugins/classnames/index.d.ts +14 -0
- package/dist/plugins/classnames/index.esm.js +107 -0
- package/dist/plugins/classnames/index.min.js +1 -0
- package/dist/plugins/core/index.d.ts +10 -62
- package/dist/plugins/core/index.d2.ts +63 -10
- package/dist/plugins/dots/index.d.ts +2 -1
- package/dist/plugins/dots/index.esm.js +31 -19
- package/dist/plugins/dots/index.min.js +1 -1
- package/dist/plugins/drag-scrolling/index.d.ts +1 -1
- package/dist/plugins/fade/index.d.ts +1 -1
- package/dist/plugins/full-width/index.d.ts +2 -2
- package/dist/plugins/full-width/index.esm.js +36 -19
- package/dist/plugins/full-width/index.min.js +1 -1
- package/dist/plugins/scroll-indicator/index.d.ts +1 -1
- package/dist/plugins/skip-links/index.d.ts +1 -1
- package/dist/plugins/thumbnails/index.d.ts +1 -1
- package/docs/assets/demo.css +42 -0
- package/docs/assets/demo.js +62 -28
- package/docs/dist/index.d.ts +1 -1
- package/docs/dist/index.esm.js +39 -3
- package/docs/dist/index.esm.js.map +1 -1
- package/docs/dist/index.min.js +1 -1
- package/docs/dist/index.min.js.map +1 -1
- package/docs/dist/plugins/arrows/index.d.ts +1 -1
- package/docs/dist/plugins/autoplay/index.d.ts +1 -1
- package/docs/dist/plugins/classnames/index.d.ts +14 -0
- package/docs/dist/plugins/classnames/index.esm.js +107 -0
- package/docs/dist/plugins/classnames/index.min.js +1 -0
- package/docs/dist/plugins/core/index.d.ts +63 -10
- package/docs/dist/plugins/core/index.d2.ts +10 -62
- package/docs/dist/plugins/dots/index.d.ts +2 -1
- package/docs/dist/plugins/dots/index.esm.js +31 -19
- package/docs/dist/plugins/dots/index.min.js +1 -1
- package/docs/dist/plugins/drag-scrolling/index.d.ts +1 -1
- package/docs/dist/plugins/fade/index.d.ts +1 -1
- package/docs/dist/plugins/full-width/index.d.ts +2 -2
- package/docs/dist/plugins/full-width/index.esm.js +36 -19
- package/docs/dist/plugins/full-width/index.min.js +1 -1
- package/docs/dist/plugins/infinite-scroll/index.d.ts +1 -1
- package/docs/dist/plugins/scroll-indicator/index.d.ts +1 -1
- package/docs/dist/plugins/skip-links/index.d.ts +1 -1
- package/docs/dist/plugins/thumbnails/index.d.ts +1 -1
- package/docs/index.html +39 -17
- package/package.json +6 -6
- package/src/core/slider.ts +42 -4
- package/src/core/types.ts +1 -0
- package/src/plugins/classnames/index.ts +145 -0
- package/src/plugins/dots/index.ts +28 -16
- package/src/plugins/full-width/index.ts +41 -21
- package/src/plugins/infinite-scroll/index.ts +0 -109
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Infinite‐scroll plugin
|
|
3
|
-
*
|
|
4
|
-
* Experimental work-in-progress not available for public use yet.
|
|
5
|
-
*/
|
|
6
|
-
import { Slider, SliderPlugin } from '../../core/types';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @typedef {Object} InfiniteScrollOptions
|
|
10
|
-
* @property {number} [lookAheadCount=1] Number of slides to look ahead when deciding to reparent.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Creates an infinite scroll plugin for a slider that re-parents multiple slides
|
|
15
|
-
* before hitting the container edge, to avoid blank space and keep the same
|
|
16
|
-
* active slide visible.
|
|
17
|
-
*
|
|
18
|
-
* @param {InfiniteScrollOptions} [options] Plugin configuration.
|
|
19
|
-
* @returns {SliderPlugin} The configured slider plugin.
|
|
20
|
-
*/
|
|
21
|
-
export default function InfiniteScrollPlugin(
|
|
22
|
-
options: { lookAheadCount?: number } = {}
|
|
23
|
-
): SliderPlugin {
|
|
24
|
-
const { lookAheadCount = 1 } = options;
|
|
25
|
-
|
|
26
|
-
return (slider: Slider) => {
|
|
27
|
-
const { container, options: sliderOpts } = slider;
|
|
28
|
-
let rafId: number | null = null;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Sum widths of the first or last N slides for lookahead.
|
|
32
|
-
*
|
|
33
|
-
* @param {HTMLElement[]} slides List of slide elements.
|
|
34
|
-
* @param {boolean} fromEnd If true, sum last N; otherwise, first N.
|
|
35
|
-
* @returns {number} Total pixel width of N slides.
|
|
36
|
-
*/
|
|
37
|
-
function getLookAheadWidth(
|
|
38
|
-
slides: HTMLElement[],
|
|
39
|
-
fromEnd: boolean
|
|
40
|
-
): number {
|
|
41
|
-
const slice = fromEnd
|
|
42
|
-
? slides.slice(-lookAheadCount)
|
|
43
|
-
: slides.slice(0, lookAheadCount);
|
|
44
|
-
|
|
45
|
-
return slice.reduce(
|
|
46
|
-
(total, slide) => total + slide.offsetWidth,
|
|
47
|
-
0
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Handler for slider.scrollEnd event that re-parents slides
|
|
53
|
-
* and retains the active slide element by recalculating its
|
|
54
|
-
* new index after DOM shifts.
|
|
55
|
-
*/
|
|
56
|
-
function onScroll(): void {
|
|
57
|
-
const activeSlideIdx = slider.activeSlideIdx;
|
|
58
|
-
const scrollLeft = slider.getScrollLeft();
|
|
59
|
-
const viewportWidth = slider.getInclusiveClientWidth();
|
|
60
|
-
const totalWidth = slider.getInclusiveScrollWidth();
|
|
61
|
-
|
|
62
|
-
// Grab current slide elements
|
|
63
|
-
let slides = Array.from(
|
|
64
|
-
container.querySelectorAll(
|
|
65
|
-
sliderOpts.slidesSelector
|
|
66
|
-
)
|
|
67
|
-
) as HTMLElement[];
|
|
68
|
-
|
|
69
|
-
if (slides.length === 0) return;
|
|
70
|
-
|
|
71
|
-
// Store reference to currently active slide element
|
|
72
|
-
const activeSlideEl = slides[activeSlideIdx];
|
|
73
|
-
|
|
74
|
-
const aheadRight = getLookAheadWidth(slides, false);
|
|
75
|
-
const aheadLeft = getLookAheadWidth(slides, true);
|
|
76
|
-
|
|
77
|
-
// 🐆 Tip: Batch DOM reads/writes inside requestAnimationFrame to avoid thrashing.
|
|
78
|
-
if (scrollLeft + viewportWidth >= totalWidth - aheadRight) {
|
|
79
|
-
for (let i = 0; i < lookAheadCount && slides.length; i++) {
|
|
80
|
-
container.append(slides.shift()!);
|
|
81
|
-
}
|
|
82
|
-
} else if (scrollLeft <= aheadLeft) {
|
|
83
|
-
for (let i = 0; i < lookAheadCount && slides.length; i++) {
|
|
84
|
-
container.prepend(slides.pop()!);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
slider.setActiveSlideIdx();
|
|
89
|
-
|
|
90
|
-
// Re-query slides after DOM mutation
|
|
91
|
-
slides = Array.from(
|
|
92
|
-
container.querySelectorAll(
|
|
93
|
-
sliderOpts.slidesSelector
|
|
94
|
-
)
|
|
95
|
-
) as HTMLElement[];
|
|
96
|
-
|
|
97
|
-
const newIndex = slides.indexOf(activeSlideEl);
|
|
98
|
-
const newEl = slides[newIndex];
|
|
99
|
-
|
|
100
|
-
if (newIndex >= 0 && slider.canMoveToSlide(newIndex)) {
|
|
101
|
-
slider.moveToSlide(newIndex);
|
|
102
|
-
} else {
|
|
103
|
-
slider.snapToClosestSlide('next');
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
slider.on('scrollEnd', onScroll);
|
|
108
|
-
};
|
|
109
|
-
}
|