@evermade/overflow-slider 2.0.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -1
- package/README.md +26 -4
- package/dist/core/details.esm.js +4 -4
- package/dist/core/details.min.js +1 -1
- package/dist/core/overflow-slider.esm.js +2 -0
- package/dist/core/overflow-slider.min.js +1 -1
- package/dist/core/slider.esm.js +202 -29
- package/dist/core/slider.min.js +1 -1
- package/dist/core/utils.esm.js +15 -1
- package/dist/core/utils.min.js +1 -1
- package/dist/overflow-slider.css +1 -1
- package/dist/plugins/arrows/arrows/index.esm.js +15 -8
- package/dist/plugins/arrows/arrows/index.min.js +1 -1
- package/dist/plugins/dots/dots/index.esm.js +21 -22
- package/dist/plugins/dots/dots/index.min.js +1 -1
- package/dist/plugins/drag-scrolling/drag-scrolling/index.esm.js +30 -3
- package/dist/plugins/drag-scrolling/drag-scrolling/index.min.js +1 -1
- package/dist/plugins/fade/fade/index.esm.js +81 -0
- package/dist/plugins/fade/fade/index.min.js +1 -0
- package/dist/plugins/full-width/full-width/index.esm.js +1 -0
- package/dist/plugins/full-width/full-width/index.min.js +1 -1
- package/dist/plugins/scroll-indicator/scroll-indicator/index.esm.js +4 -6
- package/dist/plugins/scroll-indicator/scroll-indicator/index.min.js +1 -1
- package/dist/plugins/thumbnails/thumbnails/index.esm.js +1 -0
- package/docs/assets/demo.css +16 -0
- package/docs/assets/demo.js +44 -7
- package/docs/dist/core/details.esm.js +4 -4
- package/docs/dist/core/details.min.js +1 -1
- package/docs/dist/core/overflow-slider.esm.js +2 -0
- package/docs/dist/core/overflow-slider.min.js +1 -1
- package/docs/dist/core/slider.esm.js +202 -29
- package/docs/dist/core/slider.min.js +1 -1
- package/docs/dist/core/utils.esm.js +15 -1
- package/docs/dist/core/utils.min.js +1 -1
- package/docs/dist/overflow-slider.css +1 -1
- package/docs/dist/plugins/arrows/arrows/index.esm.js +15 -8
- package/docs/dist/plugins/arrows/arrows/index.min.js +1 -1
- package/docs/dist/plugins/dots/dots/index.esm.js +21 -22
- package/docs/dist/plugins/dots/dots/index.min.js +1 -1
- package/docs/dist/plugins/drag-scrolling/drag-scrolling/index.esm.js +30 -3
- package/docs/dist/plugins/drag-scrolling/drag-scrolling/index.min.js +1 -1
- package/docs/dist/plugins/fade/fade/index.esm.js +81 -0
- package/docs/dist/plugins/fade/fade/index.min.js +1 -0
- package/docs/dist/plugins/full-width/full-width/index.esm.js +1 -0
- package/docs/dist/plugins/full-width/full-width/index.min.js +1 -1
- package/docs/dist/plugins/scroll-indicator/scroll-indicator/index.esm.js +4 -6
- package/docs/dist/plugins/scroll-indicator/scroll-indicator/index.min.js +1 -1
- package/docs/dist/plugins/thumbnails/thumbnails/index.esm.js +1 -0
- package/docs/index.html +39 -7
- package/package.json +5 -1
- package/src/core/details.ts +4 -4
- package/src/core/overflow-slider.ts +2 -0
- package/src/core/slider.ts +226 -36
- package/src/core/types.ts +33 -1
- package/src/core/utils.ts +19 -1
- package/src/overflow-slider.scss +2 -1
- package/src/plugins/arrows/index.ts +16 -8
- package/src/plugins/dots/index.ts +21 -23
- package/src/plugins/drag-scrolling/index.ts +34 -5
- package/src/plugins/fade/index.ts +101 -0
- package/src/plugins/fade/styles.scss +27 -0
- package/src/plugins/full-width/index.ts +1 -0
- package/src/plugins/scroll-indicator/index.ts +4 -6
- package/src/plugins/thumbnails/index.ts +1 -1
|
@@ -20,8 +20,8 @@ function DotsPlugin(args) {
|
|
|
20
20
|
dots.setAttribute('data-has-content', slider.details.hasOverflow.toString());
|
|
21
21
|
dots.innerHTML = '';
|
|
22
22
|
const dotsList = document.createElement('ul');
|
|
23
|
-
const pages = slider.details.
|
|
24
|
-
const
|
|
23
|
+
const pages = slider.details.slideCount;
|
|
24
|
+
const currentItem = slider.activeSlideIdx;
|
|
25
25
|
if (pages <= 1) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
@@ -31,23 +31,23 @@ function DotsPlugin(args) {
|
|
|
31
31
|
dot.setAttribute('type', 'button');
|
|
32
32
|
dot.setAttribute('class', options.classNames.dotsItem);
|
|
33
33
|
dot.setAttribute('aria-label', options.texts.dotDescription.replace('%d', (i + 1).toString()).replace('%d', pages.toString()));
|
|
34
|
-
dot.setAttribute('aria-pressed', (i ===
|
|
35
|
-
dot.setAttribute('data-
|
|
34
|
+
dot.setAttribute('aria-pressed', (i === currentItem).toString());
|
|
35
|
+
dot.setAttribute('data-item', (i + 1).toString());
|
|
36
36
|
dotListItem.appendChild(dot);
|
|
37
37
|
dotsList.appendChild(dotListItem);
|
|
38
38
|
dot.addEventListener('click', () => activateDot(i + 1));
|
|
39
39
|
dot.addEventListener('focus', () => pageFocused = i + 1);
|
|
40
40
|
dot.addEventListener('keydown', (e) => {
|
|
41
41
|
var _a;
|
|
42
|
-
const
|
|
43
|
-
if (!
|
|
42
|
+
const currentItemItem = dots.querySelector(`[aria-pressed="true"]`);
|
|
43
|
+
if (!currentItemItem) {
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
|
-
const
|
|
46
|
+
const currentItem = parseInt((_a = currentItemItem.getAttribute('data-item')) !== null && _a !== void 0 ? _a : '1');
|
|
47
47
|
if (e.key === 'ArrowLeft') {
|
|
48
|
-
const previousPage =
|
|
48
|
+
const previousPage = currentItem - 1;
|
|
49
49
|
if (previousPage > 0) {
|
|
50
|
-
const matchingDot = dots.querySelector(`[data-
|
|
50
|
+
const matchingDot = dots.querySelector(`[data-item="${previousPage}"]`);
|
|
51
51
|
if (matchingDot) {
|
|
52
52
|
matchingDot.focus();
|
|
53
53
|
}
|
|
@@ -55,9 +55,9 @@ function DotsPlugin(args) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
if (e.key === 'ArrowRight') {
|
|
58
|
-
const nextPage =
|
|
58
|
+
const nextPage = currentItem + 1;
|
|
59
59
|
if (nextPage <= pages) {
|
|
60
|
-
const matchingDot = dots.querySelector(`[data-
|
|
60
|
+
const matchingDot = dots.querySelector(`[data-item="${nextPage}"]`);
|
|
61
61
|
if (matchingDot) {
|
|
62
62
|
matchingDot.focus();
|
|
63
63
|
}
|
|
@@ -69,19 +69,18 @@ function DotsPlugin(args) {
|
|
|
69
69
|
dots.appendChild(dotsList);
|
|
70
70
|
// return focus to same page after rebuild
|
|
71
71
|
if (pageFocused) {
|
|
72
|
-
const matchingDot = dots.querySelector(`[data-
|
|
72
|
+
const matchingDot = dots.querySelector(`[data-item="${pageFocused}"]`);
|
|
73
73
|
if (matchingDot) {
|
|
74
74
|
matchingDot.focus();
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
|
-
const activateDot = (
|
|
79
|
-
const scrollTargetPosition = slider.details.containerWidth * (page - 1);
|
|
80
|
-
slider.container.style.scrollBehavior = slider.options.scrollBehavior;
|
|
81
|
-
slider.container.
|
|
82
|
-
slider.container.
|
|
83
|
-
slider.
|
|
84
|
-
slider.container.style.scrollSnapType = '';
|
|
78
|
+
const activateDot = (item) => {
|
|
79
|
+
// const scrollTargetPosition = slider.details.containerWidth * ( page - 1 );
|
|
80
|
+
// slider.container.style.scrollBehavior = slider.options.scrollBehavior;
|
|
81
|
+
// slider.container.scrollLeft = scrollTargetPosition;
|
|
82
|
+
// slider.container.style.scrollBehavior = '';
|
|
83
|
+
slider.moveToSlide(item - 1);
|
|
85
84
|
};
|
|
86
85
|
buildDots();
|
|
87
86
|
if (options.container) {
|
|
@@ -90,9 +89,9 @@ function DotsPlugin(args) {
|
|
|
90
89
|
else {
|
|
91
90
|
(_b = slider.container.parentNode) === null || _b === void 0 ? void 0 : _b.insertBefore(dots, slider.container.nextSibling);
|
|
92
91
|
}
|
|
93
|
-
slider.on('
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
slider.on('scrollEnd', buildDots);
|
|
93
|
+
slider.on('contentsChanged', buildDots);
|
|
94
|
+
slider.on('containerSizeChanged', buildDots);
|
|
96
95
|
};
|
|
97
96
|
}
|
|
98
97
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const t={dotDescription:"Page %d of %d"},e={dotsContainer:"overflow-slider__dots",dotsItem:"overflow-slider__dot-item"};function n(n){return o=>{var
|
|
1
|
+
const t={dotDescription:"Page %d of %d"},e={dotsContainer:"overflow-slider__dots",dotsItem:"overflow-slider__dot-item"};function n(n){return o=>{var i,s;const a={texts:Object.assign(Object.assign({},t),(null==n?void 0:n.texts)||[]),classNames:Object.assign(Object.assign({},e),(null==n?void 0:n.classNames)||[]),container:null!==(i=null==n?void 0:n.container)&&void 0!==i?i:null},r=document.createElement("div");r.classList.add(a.classNames.dotsContainer);let d=null;const l=()=>{r.setAttribute("data-has-content",o.details.hasOverflow.toString()),r.innerHTML="";const t=document.createElement("ul"),e=o.details.slideCount,n=o.activeSlideIdx;if(!(e<=1)){for(let o=0;o<e;o++){const i=document.createElement("li"),s=document.createElement("button");s.setAttribute("type","button"),s.setAttribute("class",a.classNames.dotsItem),s.setAttribute("aria-label",a.texts.dotDescription.replace("%d",(o+1).toString()).replace("%d",e.toString())),s.setAttribute("aria-pressed",(o===n).toString()),s.setAttribute("data-item",(o+1).toString()),i.appendChild(s),t.appendChild(i),s.addEventListener("click",(()=>c(o+1))),s.addEventListener("focus",(()=>d=o+1)),s.addEventListener("keydown",(t=>{var n;const o=r.querySelector('[aria-pressed="true"]');if(!o)return;const i=parseInt(null!==(n=o.getAttribute("data-item"))&&void 0!==n?n:"1");if("ArrowLeft"===t.key){const t=i-1;if(t>0){const e=r.querySelector(`[data-item="${t}"]`);e&&e.focus(),c(t)}}if("ArrowRight"===t.key){const t=i+1;if(t<=e){const e=r.querySelector(`[data-item="${t}"]`);e&&e.focus(),c(t)}}}))}if(r.appendChild(t),d){const t=r.querySelector(`[data-item="${d}"]`);t&&t.focus()}}},c=t=>{o.moveToSlide(t-1)};l(),a.container?a.container.appendChild(r):null===(s=o.container.parentNode)||void 0===s||s.insertBefore(r,o.container.nextSibling),o.on("scrollEnd",l),o.on("contentsChanged",l),o.on("containerSizeChanged",l)}}export{n as default};
|
|
@@ -8,9 +8,13 @@ function DragScrollingPlugin(args) {
|
|
|
8
8
|
let isMouseDown = false;
|
|
9
9
|
let startX = 0;
|
|
10
10
|
let scrollLeft = 0;
|
|
11
|
+
let isMovingForward = false;
|
|
12
|
+
let programmaticScrollStarted = false;
|
|
13
|
+
let mayNeedToSnap = false;
|
|
11
14
|
// add data attribute to container
|
|
12
15
|
slider.container.setAttribute('data-has-drag-scrolling', 'true');
|
|
13
16
|
const mouseDown = (e) => {
|
|
17
|
+
programmaticScrollStarted = false;
|
|
14
18
|
if (!slider.details.hasOverflow) {
|
|
15
19
|
return;
|
|
16
20
|
}
|
|
@@ -22,7 +26,6 @@ function DragScrollingPlugin(args) {
|
|
|
22
26
|
scrollLeft = slider.container.scrollLeft;
|
|
23
27
|
// change cursor to grabbing
|
|
24
28
|
slider.container.style.cursor = 'grabbing';
|
|
25
|
-
slider.container.style.scrollSnapType = 'none';
|
|
26
29
|
slider.container.style.scrollBehavior = 'auto';
|
|
27
30
|
// prevent focus going to the slides
|
|
28
31
|
e.preventDefault();
|
|
@@ -30,15 +33,26 @@ function DragScrollingPlugin(args) {
|
|
|
30
33
|
};
|
|
31
34
|
const mouseMove = (e) => {
|
|
32
35
|
if (!slider.details.hasOverflow) {
|
|
36
|
+
programmaticScrollStarted = false;
|
|
33
37
|
return;
|
|
34
38
|
}
|
|
35
39
|
if (!isMouseDown) {
|
|
40
|
+
programmaticScrollStarted = false;
|
|
36
41
|
return;
|
|
37
42
|
}
|
|
38
43
|
e.preventDefault();
|
|
44
|
+
if (!programmaticScrollStarted) {
|
|
45
|
+
programmaticScrollStarted = true;
|
|
46
|
+
slider.emit('programmaticScrollStart');
|
|
47
|
+
}
|
|
39
48
|
const x = e.pageX - slider.container.offsetLeft;
|
|
40
49
|
const walk = (x - startX);
|
|
41
|
-
|
|
50
|
+
const newScrollLeft = scrollLeft - walk;
|
|
51
|
+
mayNeedToSnap = true;
|
|
52
|
+
if (Math.floor(slider.container.scrollLeft) !== Math.floor(newScrollLeft)) {
|
|
53
|
+
isMovingForward = slider.container.scrollLeft < newScrollLeft;
|
|
54
|
+
}
|
|
55
|
+
slider.container.scrollLeft = newScrollLeft;
|
|
42
56
|
const absWalk = Math.abs(walk);
|
|
43
57
|
const slides = slider.container.querySelectorAll(slider.options.slidesSelector);
|
|
44
58
|
const pointerEvents = absWalk > options.draggedDistanceThatPreventsClick ? 'none' : '';
|
|
@@ -48,12 +62,13 @@ function DragScrollingPlugin(args) {
|
|
|
48
62
|
};
|
|
49
63
|
const mouseUp = () => {
|
|
50
64
|
if (!slider.details.hasOverflow) {
|
|
65
|
+
programmaticScrollStarted = false;
|
|
51
66
|
return;
|
|
52
67
|
}
|
|
53
68
|
isMouseDown = false;
|
|
54
69
|
slider.container.style.cursor = '';
|
|
55
70
|
setTimeout(() => {
|
|
56
|
-
|
|
71
|
+
programmaticScrollStarted = false;
|
|
57
72
|
slider.container.style.scrollBehavior = '';
|
|
58
73
|
const slides = slider.container.querySelectorAll(slider.options.slidesSelector);
|
|
59
74
|
slides.forEach((slide) => {
|
|
@@ -64,6 +79,18 @@ function DragScrollingPlugin(args) {
|
|
|
64
79
|
window.addEventListener('mousedown', mouseDown);
|
|
65
80
|
window.addEventListener('mousemove', mouseMove);
|
|
66
81
|
window.addEventListener('mouseup', mouseUp);
|
|
82
|
+
// emulate scroll snapping
|
|
83
|
+
if (slider.options.emulateScrollSnap) {
|
|
84
|
+
const snap = () => {
|
|
85
|
+
if (!mayNeedToSnap || isMouseDown) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
mayNeedToSnap = false;
|
|
89
|
+
slider.snapToClosestSlide(isMovingForward ? 'next' : 'prev');
|
|
90
|
+
};
|
|
91
|
+
slider.on('programmaticScrollEnd', snap);
|
|
92
|
+
window.addEventListener('mouseup', snap);
|
|
93
|
+
}
|
|
67
94
|
};
|
|
68
95
|
}
|
|
69
96
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e){var t;const
|
|
1
|
+
function e(e){var t;const o=null!==(t=null==e?void 0:e.draggedDistanceThatPreventsClick)&&void 0!==t?t:20;return e=>{let t=!1,n=0,r=0,a=!1,l=!1,s=!1;e.container.setAttribute("data-has-drag-scrolling","true");if(window.addEventListener("mousedown",(o=>{l=!1,e.details.hasOverflow&&e.container.contains(o.target)&&(t=!0,n=o.pageX-e.container.offsetLeft,r=e.container.scrollLeft,e.container.style.cursor="grabbing",e.container.style.scrollBehavior="auto",o.preventDefault(),o.stopPropagation())})),window.addEventListener("mousemove",(i=>{if(!e.details.hasOverflow)return void(l=!1);if(!t)return void(l=!1);i.preventDefault(),l||(l=!0,e.emit("programmaticScrollStart"));const c=i.pageX-e.container.offsetLeft-n,d=r-c;s=!0,Math.floor(e.container.scrollLeft)!==Math.floor(d)&&(a=e.container.scrollLeft<d),e.container.scrollLeft=d;const f=Math.abs(c),u=e.container.querySelectorAll(e.options.slidesSelector),v=f>o?"none":"";u.forEach((e=>{e.style.pointerEvents=v}))})),window.addEventListener("mouseup",(()=>{e.details.hasOverflow?(t=!1,e.container.style.cursor="",setTimeout((()=>{l=!1,e.container.style.scrollBehavior="";e.container.querySelectorAll(e.options.slidesSelector).forEach((e=>{e.style.pointerEvents=""}))}),50)):l=!1})),e.options.emulateScrollSnap){const o=()=>{s&&!t&&(s=!1,e.snapToClosestSlide(a?"next":"prev"))};e.on("programmaticScrollEnd",o),window.addEventListener("mouseup",o)}}}export{e as default};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
function FadePlugin(args) {
|
|
2
|
+
return (slider) => {
|
|
3
|
+
var _a, _b, _c;
|
|
4
|
+
const options = {
|
|
5
|
+
classNames: {
|
|
6
|
+
fadeItem: 'overflow-slider-fade',
|
|
7
|
+
fadeItemStart: 'overflow-slider-fade--start',
|
|
8
|
+
fadeItemEnd: 'overflow-slider-fade--end',
|
|
9
|
+
},
|
|
10
|
+
container: (_a = args === null || args === void 0 ? void 0 : args.container) !== null && _a !== void 0 ? _a : null,
|
|
11
|
+
containerStart: (_b = args === null || args === void 0 ? void 0 : args.containerStart) !== null && _b !== void 0 ? _b : null,
|
|
12
|
+
containerEnd: (_c = args === null || args === void 0 ? void 0 : args.containerEnd) !== null && _c !== void 0 ? _c : null,
|
|
13
|
+
};
|
|
14
|
+
const fadeItemStart = document.createElement('div');
|
|
15
|
+
fadeItemStart.classList.add(options.classNames.fadeItem, options.classNames.fadeItemStart);
|
|
16
|
+
fadeItemStart.setAttribute('aria-hidden', 'true');
|
|
17
|
+
fadeItemStart.setAttribute('tabindex', '-1');
|
|
18
|
+
const fadeItemEnd = document.createElement('div');
|
|
19
|
+
fadeItemEnd.classList.add(options.classNames.fadeItem, options.classNames.fadeItemEnd);
|
|
20
|
+
fadeItemEnd.setAttribute('aria-hidden', 'true');
|
|
21
|
+
fadeItemEnd.setAttribute('tabindex', '-1');
|
|
22
|
+
if (options.containerStart) {
|
|
23
|
+
options.containerStart.appendChild(fadeItemStart);
|
|
24
|
+
}
|
|
25
|
+
else if (options.container) {
|
|
26
|
+
options.container.appendChild(fadeItemStart);
|
|
27
|
+
}
|
|
28
|
+
if (options.containerEnd) {
|
|
29
|
+
options.containerEnd.appendChild(fadeItemEnd);
|
|
30
|
+
}
|
|
31
|
+
else if (options.container) {
|
|
32
|
+
options.container.appendChild(fadeItemEnd);
|
|
33
|
+
}
|
|
34
|
+
const hasFadeAtStart = () => {
|
|
35
|
+
return slider.container.scrollLeft > fadeItemStart.offsetWidth;
|
|
36
|
+
};
|
|
37
|
+
const fadeAtStartOpacity = () => {
|
|
38
|
+
const position = slider.container.scrollLeft;
|
|
39
|
+
if (Math.floor(position) <= Math.floor(fadeItemStart.offsetWidth)) {
|
|
40
|
+
return position / Math.max(fadeItemStart.offsetWidth, 1);
|
|
41
|
+
}
|
|
42
|
+
return 1;
|
|
43
|
+
};
|
|
44
|
+
const hasFadeAtEnd = () => {
|
|
45
|
+
return Math.floor(slider.container.scrollLeft) < Math.floor(slider.getInclusiveScrollWidth() - slider.getInclusiveClientWidth() - fadeItemEnd.offsetWidth);
|
|
46
|
+
};
|
|
47
|
+
const fadeAtEndOpacity = () => {
|
|
48
|
+
const position = slider.container.scrollLeft;
|
|
49
|
+
const maxPosition = slider.getInclusiveScrollWidth() - slider.getInclusiveClientWidth();
|
|
50
|
+
const maxFadePosition = maxPosition - fadeItemEnd.offsetWidth;
|
|
51
|
+
if (Math.floor(position) >= Math.floor(maxFadePosition)) {
|
|
52
|
+
return ((maxFadePosition - position) / Math.max(fadeItemEnd.offsetWidth, 1)) + 1;
|
|
53
|
+
}
|
|
54
|
+
return 1;
|
|
55
|
+
};
|
|
56
|
+
const update = () => {
|
|
57
|
+
fadeItemStart.setAttribute('data-has-fade', hasFadeAtStart().toString());
|
|
58
|
+
fadeItemStart.style.opacity = fadeAtStartOpacity().toString();
|
|
59
|
+
fadeItemEnd.setAttribute('data-has-fade', hasFadeAtEnd().toString());
|
|
60
|
+
fadeItemEnd.style.opacity = fadeAtEndOpacity().toString();
|
|
61
|
+
};
|
|
62
|
+
update();
|
|
63
|
+
slider.on('created', update);
|
|
64
|
+
slider.on('contentsChanged', update);
|
|
65
|
+
slider.on('containerSizeChanged', update);
|
|
66
|
+
slider.on('scrollEnd', update);
|
|
67
|
+
slider.on('scrollStart', update);
|
|
68
|
+
let requestId = 0;
|
|
69
|
+
const debouncedUpdate = () => {
|
|
70
|
+
if (requestId) {
|
|
71
|
+
window.cancelAnimationFrame(requestId);
|
|
72
|
+
}
|
|
73
|
+
requestId = window.requestAnimationFrame(() => {
|
|
74
|
+
update();
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
slider.on('scroll', debouncedUpdate);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { FadePlugin as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(t){return e=>{var n,a,o;const i={classNames:{fadeItem:"overflow-slider-fade",fadeItemStart:"overflow-slider-fade--start",fadeItemEnd:"overflow-slider-fade--end"},container:null!==(n=null==t?void 0:t.container)&&void 0!==n?n:null,containerStart:null!==(a=null==t?void 0:t.containerStart)&&void 0!==a?a:null,containerEnd:null!==(o=null==t?void 0:t.containerEnd)&&void 0!==o?o:null},r=document.createElement("div");r.classList.add(i.classNames.fadeItem,i.classNames.fadeItemStart),r.setAttribute("aria-hidden","true"),r.setAttribute("tabindex","-1");const l=document.createElement("div");l.classList.add(i.classNames.fadeItem,i.classNames.fadeItemEnd),l.setAttribute("aria-hidden","true"),l.setAttribute("tabindex","-1"),i.containerStart?i.containerStart.appendChild(r):i.container&&i.container.appendChild(r),i.containerEnd?i.containerEnd.appendChild(l):i.container&&i.container.appendChild(l);const d=()=>{r.setAttribute("data-has-fade",(e.container.scrollLeft>r.offsetWidth).toString()),r.style.opacity=(()=>{const t=e.container.scrollLeft;return Math.floor(t)<=Math.floor(r.offsetWidth)?t/Math.max(r.offsetWidth,1):1})().toString(),l.setAttribute("data-has-fade",(Math.floor(e.container.scrollLeft)<Math.floor(e.getInclusiveScrollWidth()-e.getInclusiveClientWidth()-l.offsetWidth)).toString()),l.style.opacity=(()=>{const t=e.container.scrollLeft,n=e.getInclusiveScrollWidth()-e.getInclusiveClientWidth()-l.offsetWidth;return Math.floor(t)>=Math.floor(n)?(n-t)/Math.max(l.offsetWidth,1)+1:1})().toString()};d(),e.on("created",d),e.on("contentsChanged",d),e.on("containerSizeChanged",d),e.on("scrollEnd",d),e.on("scrollStart",d);let s=0;e.on("scroll",(()=>{s&&window.cancelAnimationFrame(s),s=window.requestAnimationFrame((()=>{d()}))}))}}export{t as default};
|
|
@@ -21,6 +21,7 @@ function FullWidthPlugin(args) {
|
|
|
21
21
|
if (options.addMarginAfter) {
|
|
22
22
|
lastSlide.style.marginRight = `${marginAmount}px`;
|
|
23
23
|
}
|
|
24
|
+
slider.container.setAttribute('data-full-width-offset', marginAmount.toString());
|
|
24
25
|
};
|
|
25
26
|
update();
|
|
26
27
|
slider.on('contentsChanged', update);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const t=t=>{var n,e;return null!==(e=null===(n=t.container.parentElement)||void 0===n?void 0:n.offsetWidth)&&void 0!==e?e:window.innerWidth};function n(n){return e=>{var i,r,o;const d={targetWidth:null!==(i=null==n?void 0:n.targetWidth)&&void 0!==i?i:t,addMarginBefore:null===(r=null==n?void 0:n.addMarginBefore)||void 0===r||r,addMarginAfter:null===(o=null==n?void 0:n.addMarginAfter)||void 0===o||o},a=()=>{const t=e.container.querySelectorAll(e.options.slidesSelector);if(!t.length)return;const n=t[0],i=t[t.length-1],r=Math.floor((window.innerWidth-d.targetWidth(e))/2);d.addMarginBefore&&(n.style.marginLeft=`${r}px`),d.addMarginAfter&&(i.style.marginRight=`${r}px`),e.container.setAttribute("data-full-width-offset",r.toString())};a(),e.on("contentsChanged",a),e.on("containerSizeChanged",a)}}export{n as default};
|
|
@@ -41,13 +41,13 @@ function ScrollIndicatorPlugin(args) {
|
|
|
41
41
|
window.cancelAnimationFrame(requestId);
|
|
42
42
|
}
|
|
43
43
|
requestId = window.requestAnimationFrame(() => {
|
|
44
|
-
const scrollbarButtonWidth = (slider.details.containerWidth / slider.
|
|
44
|
+
const scrollbarButtonWidth = (slider.details.containerWidth / slider.container.scrollWidth) * 100;
|
|
45
45
|
const scrollLeftInPortion = getScrollbarButtonLeftOffset();
|
|
46
46
|
scrollbarButton.style.width = `${scrollbarButtonWidth}%`;
|
|
47
47
|
scrollbarButton.style.transform = `translateX(${scrollLeftInPortion}px)`;
|
|
48
48
|
// aria-valuenow
|
|
49
49
|
const scrollLeft = slider.container.scrollLeft;
|
|
50
|
-
const scrollWidth = slider.
|
|
50
|
+
const scrollWidth = slider.getInclusiveScrollWidth();
|
|
51
51
|
const containerWidth = slider.container.offsetWidth;
|
|
52
52
|
const scrollPercentage = (scrollLeft / (scrollWidth - containerWidth)) * 100;
|
|
53
53
|
scrollbarContainer.setAttribute('aria-valuenow', Math.round(Number.isNaN(scrollPercentage) ? 0 : scrollPercentage).toString());
|
|
@@ -81,10 +81,10 @@ function ScrollIndicatorPlugin(args) {
|
|
|
81
81
|
const scrollbarButtonLeft = getScrollbarButtonLeftOffset();
|
|
82
82
|
const scrollbarButtonRight = scrollbarButtonLeft + scrollbarButtonWidth;
|
|
83
83
|
const clickX = e.pageX - scrollbarContainer.offsetLeft;
|
|
84
|
-
if (clickX < scrollbarButtonLeft) {
|
|
84
|
+
if (Math.floor(clickX) < Math.floor(scrollbarButtonLeft)) {
|
|
85
85
|
slider.moveToDirection('prev');
|
|
86
86
|
}
|
|
87
|
-
else if (clickX > scrollbarButtonRight) {
|
|
87
|
+
else if (Math.floor(clickX) > Math.floor(scrollbarButtonRight)) {
|
|
88
88
|
slider.moveToDirection('next');
|
|
89
89
|
}
|
|
90
90
|
});
|
|
@@ -99,7 +99,6 @@ function ScrollIndicatorPlugin(args) {
|
|
|
99
99
|
scrollLeft = slider.container.scrollLeft;
|
|
100
100
|
// change cursor to grabbing
|
|
101
101
|
scrollbarButton.style.cursor = 'grabbing';
|
|
102
|
-
slider.container.style.scrollSnapType = 'none';
|
|
103
102
|
scrollbarButton.setAttribute('data-is-grabbed', 'true');
|
|
104
103
|
e.preventDefault();
|
|
105
104
|
e.stopPropagation();
|
|
@@ -118,7 +117,6 @@ function ScrollIndicatorPlugin(args) {
|
|
|
118
117
|
const onInteractionUp = () => {
|
|
119
118
|
isInteractionDown = false;
|
|
120
119
|
scrollbarButton.style.cursor = '';
|
|
121
|
-
slider.container.style.scrollSnapType = '';
|
|
122
120
|
scrollbarButton.setAttribute('data-is-grabbed', 'false');
|
|
123
121
|
};
|
|
124
122
|
scrollbarButton.addEventListener('mousedown', onInteractionDown);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const t={scrollIndicator:"overflow-slider__scroll-indicator",scrollIndicatorBar:"overflow-slider__scroll-indicator-bar",scrollIndicatorButton:"overflow-slider__scroll-indicator-button"};function e(e){return
|
|
1
|
+
const t={scrollIndicator:"overflow-slider__scroll-indicator",scrollIndicatorBar:"overflow-slider__scroll-indicator-bar",scrollIndicatorButton:"overflow-slider__scroll-indicator-button"};function e(e){return o=>{var n,r,a;const i={classNames:Object.assign(Object.assign({},t),(null==e?void 0:e.classNames)||[]),container:null!==(n=null==e?void 0:e.container)&&void 0!==n?n:null},s=document.createElement("div");s.setAttribute("class",i.classNames.scrollIndicator),s.setAttribute("tabindex","0"),s.setAttribute("role","scrollbar"),s.setAttribute("aria-controls",null!==(r=o.container.getAttribute("id"))&&void 0!==r?r:""),s.setAttribute("aria-orientation","horizontal"),s.setAttribute("aria-valuemax","100"),s.setAttribute("aria-valuemin","0"),s.setAttribute("aria-valuenow","0");const l=document.createElement("div");l.setAttribute("class",i.classNames.scrollIndicatorBar);const c=document.createElement("div");c.setAttribute("class",i.classNames.scrollIndicatorButton),c.setAttribute("data-is-grabbed","false"),l.appendChild(c),s.appendChild(l);const d=()=>{s.setAttribute("data-has-overflow",o.details.hasOverflow.toString())};d();const u=()=>{const t=c.offsetWidth/o.details.containerWidth;return o.container.scrollLeft*t};let f=0;const v=()=>{f&&window.cancelAnimationFrame(f),f=window.requestAnimationFrame((()=>{const t=o.details.containerWidth/o.container.scrollWidth*100,e=u();c.style.width=`${t}%`,c.style.transform=`translateX(${e}px)`;const n=o.container.scrollLeft/(o.getInclusiveScrollWidth()-o.container.offsetWidth)*100;s.setAttribute("aria-valuenow",Math.round(Number.isNaN(n)?0:n).toString())}))};i.container?i.container.appendChild(s):null===(a=o.container.parentNode)||void 0===a||a.insertBefore(s,o.container.nextSibling),v(),o.on("scroll",v),o.on("contentsChanged",v),o.on("containerSizeChanged",v),o.on("detailsChanged",d),s.addEventListener("keydown",(t=>{"ArrowLeft"===t.key?o.moveToDirection("prev"):"ArrowRight"===t.key&&o.moveToDirection("next")})),s.addEventListener("click",(t=>{const e=c.offsetWidth,n=u(),r=n+e,a=t.pageX-s.offsetLeft;Math.floor(a)<Math.floor(n)?o.moveToDirection("prev"):Math.floor(a)>Math.floor(r)&&o.moveToDirection("next")}));let b=!1,h=0,m=0;const w=t=>{b=!0;const e=t.pageX||t.touches[0].pageX;h=e-s.offsetLeft,m=o.container.scrollLeft,c.style.cursor="grabbing",c.setAttribute("data-is-grabbed","true"),t.preventDefault(),t.stopPropagation()},g=t=>{if(!b)return;t.preventDefault();const e=(t.pageX||t.touches[0].pageX)-s.offsetLeft,n=o.details.scrollableAreaWidth/s.offsetWidth,r=(e-h)*n;o.container.scrollLeft=m+r},p=()=>{b=!1,c.style.cursor="",c.setAttribute("data-is-grabbed","false")};c.addEventListener("mousedown",w),c.addEventListener("touchstart",w),window.addEventListener("mousemove",g),window.addEventListener("touchmove",g,{passive:!1}),window.addEventListener("mouseup",p),window.addEventListener("touchend",p)}}export{e as default};
|
package/docs/assets/demo.css
CHANGED
|
@@ -446,6 +446,21 @@ h3:before {
|
|
|
446
446
|
.example-container-2-perfect-fit {
|
|
447
447
|
grid-template-columns: repeat(var(--slider-slides-count, 1), calc( ( var(--slider-container-width, 900px) / 3 ) - 2/3 * var(--slide-gap, 1rem)));
|
|
448
448
|
}
|
|
449
|
+
.example-container-1-dots {
|
|
450
|
+
scroll-snap-type: x mandatory;
|
|
451
|
+
grid-template-columns: repeat(var(--slider-slides-count, 1), var(--slider-container-width, 900px));
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
.example-container-1-dots .example-item {
|
|
455
|
+
aspect-ratio: 16/7;
|
|
456
|
+
width: 100%;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
.example-container-1-fade-wrap {
|
|
460
|
+
position: relative;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
|
|
449
464
|
.example-container-2-perfect-fit .example-item {
|
|
450
465
|
aspect-ratio: 1/1;
|
|
451
466
|
width: 100%;
|
|
@@ -557,6 +572,7 @@ h3:before {
|
|
|
557
572
|
align-items: center;
|
|
558
573
|
background: #fff;
|
|
559
574
|
padding-inline: .5rem;
|
|
575
|
+
z-index: 1;
|
|
560
576
|
}
|
|
561
577
|
|
|
562
578
|
.example-4-filters-previous {
|
package/docs/assets/demo.js
CHANGED
|
@@ -18,6 +18,7 @@ import ScrollIndicatorPlugin from '../dist/plugins/scroll-indicator/scroll-indic
|
|
|
18
18
|
import DotsPlugin from '../dist/plugins/dots/dots/index.esm.js';
|
|
19
19
|
import FullWidthPlugin from '../dist/plugins/full-width/full-width/index.esm.js';
|
|
20
20
|
import ThumbnailsPlugin from '../dist/plugins/thumbnails/thumbnails/index.esm.js';
|
|
21
|
+
import FadePlugin from '../dist/plugins/fade/fade/index.esm.js';
|
|
21
22
|
|
|
22
23
|
(function () {
|
|
23
24
|
const init = () => {
|
|
@@ -45,7 +46,17 @@ import ThumbnailsPlugin from '../dist/plugins/thumbnails/thumbnails/index.esm.js
|
|
|
45
46
|
SkipLinksPlugin(),
|
|
46
47
|
]
|
|
47
48
|
);
|
|
48
|
-
|
|
49
|
+
|
|
50
|
+
const example1DragScrollingScrollSnap = new OverflowSlider(
|
|
51
|
+
document.querySelector( '.example-container-1-drag-scrolling-scroll-snap' ),
|
|
52
|
+
{
|
|
53
|
+
emulateScrollSnap: true,
|
|
54
|
+
},
|
|
55
|
+
[
|
|
56
|
+
DragScrollingPlugin(),
|
|
57
|
+
]
|
|
58
|
+
);
|
|
59
|
+
console.log( '1-drag-scrolling-scroll-snap', example1DragScrollingScrollSnap );
|
|
49
60
|
|
|
50
61
|
const example1Arrows = new OverflowSlider(
|
|
51
62
|
document.querySelector( '.example-container-1-arrows' ),
|
|
@@ -71,7 +82,9 @@ import ThumbnailsPlugin from '../dist/plugins/thumbnails/thumbnails/index.esm.js
|
|
|
71
82
|
|
|
72
83
|
const example1Dots = new OverflowSlider(
|
|
73
84
|
document.querySelector( '.example-container-1-dots' ),
|
|
74
|
-
{
|
|
85
|
+
{
|
|
86
|
+
emulateScrollSnap: true,
|
|
87
|
+
},
|
|
75
88
|
[
|
|
76
89
|
DragScrollingPlugin(),
|
|
77
90
|
SkipLinksPlugin(),
|
|
@@ -80,6 +93,20 @@ import ThumbnailsPlugin from '../dist/plugins/thumbnails/thumbnails/index.esm.js
|
|
|
80
93
|
);
|
|
81
94
|
console.log( '1-dots', example1Dots );
|
|
82
95
|
|
|
96
|
+
const example1Fade = new OverflowSlider(
|
|
97
|
+
document.querySelector( '.example-container-1-fade' ),
|
|
98
|
+
{
|
|
99
|
+
emulateScrollSnap: true,
|
|
100
|
+
},
|
|
101
|
+
[
|
|
102
|
+
DragScrollingPlugin(),
|
|
103
|
+
FadePlugin({
|
|
104
|
+
containerEnd: document.querySelector( '.example-container-1-fade__end' ),
|
|
105
|
+
}),
|
|
106
|
+
]
|
|
107
|
+
);
|
|
108
|
+
console.log( '1-fade', example1Fade );
|
|
109
|
+
|
|
83
110
|
const example2PerfectFit = new OverflowSlider(
|
|
84
111
|
document.querySelector( '.example-container-2-perfect-fit' ),
|
|
85
112
|
{},
|
|
@@ -112,7 +139,9 @@ import ThumbnailsPlugin from '../dist/plugins/thumbnails/thumbnails/index.esm.js
|
|
|
112
139
|
|
|
113
140
|
const example3ScrollSnappingMandatory = new OverflowSlider(
|
|
114
141
|
document.querySelector( '.example-container-3-scroll-snapping-mandatory' ),
|
|
115
|
-
{
|
|
142
|
+
{
|
|
143
|
+
emulateScrollSnap: true,
|
|
144
|
+
},
|
|
116
145
|
[
|
|
117
146
|
DragScrollingPlugin(),
|
|
118
147
|
ScrollIndicatorPlugin(),
|
|
@@ -122,7 +151,9 @@ import ThumbnailsPlugin from '../dist/plugins/thumbnails/thumbnails/index.esm.js
|
|
|
122
151
|
|
|
123
152
|
const example3ScrollSnappingProximity = new OverflowSlider(
|
|
124
153
|
document.querySelector( '.example-container-3-scroll-snapping-proximity' ),
|
|
125
|
-
{
|
|
154
|
+
{
|
|
155
|
+
emulateScrollSnap: true,
|
|
156
|
+
},
|
|
126
157
|
[
|
|
127
158
|
DragScrollingPlugin(),
|
|
128
159
|
ScrollIndicatorPlugin(),
|
|
@@ -155,7 +186,9 @@ import ThumbnailsPlugin from '../dist/plugins/thumbnails/thumbnails/index.esm.js
|
|
|
155
186
|
|
|
156
187
|
const example4GridOrSliders = new OverflowSlider(
|
|
157
188
|
document.querySelector( '.example-container-4-grid-or-slider' ),
|
|
158
|
-
{
|
|
189
|
+
{
|
|
190
|
+
emulateScrollSnap: true,
|
|
191
|
+
},
|
|
159
192
|
[
|
|
160
193
|
DragScrollingPlugin(),
|
|
161
194
|
ScrollIndicatorPlugin(),
|
|
@@ -183,7 +216,9 @@ import ThumbnailsPlugin from '../dist/plugins/thumbnails/thumbnails/index.esm.js
|
|
|
183
216
|
|
|
184
217
|
const example4SyncedMain = new OverflowSlider(
|
|
185
218
|
document.querySelector( '.example-container-4-synced-main' ),
|
|
186
|
-
{
|
|
219
|
+
{
|
|
220
|
+
emulateScrollSnap: true,
|
|
221
|
+
},
|
|
187
222
|
[
|
|
188
223
|
DragScrollingPlugin(),
|
|
189
224
|
]
|
|
@@ -192,7 +227,9 @@ import ThumbnailsPlugin from '../dist/plugins/thumbnails/thumbnails/index.esm.js
|
|
|
192
227
|
|
|
193
228
|
const example4SyncedThumbnails = new OverflowSlider(
|
|
194
229
|
document.querySelector( '.example-container-4-synced-thumbnails' ),
|
|
195
|
-
{
|
|
230
|
+
{
|
|
231
|
+
emulateScrollSnap: true,
|
|
232
|
+
},
|
|
196
233
|
[
|
|
197
234
|
DragScrollingPlugin(),
|
|
198
235
|
ThumbnailsPlugin({
|
|
@@ -7,17 +7,17 @@ function details(slider) {
|
|
|
7
7
|
let scrollableAreaWidth = 0;
|
|
8
8
|
let amountOfPages = 0;
|
|
9
9
|
let currentPage = 1;
|
|
10
|
-
if (slider.
|
|
10
|
+
if (Math.floor(slider.getInclusiveScrollWidth()) > Math.floor(slider.getInclusiveClientWidth())) {
|
|
11
11
|
hasOverflow = true;
|
|
12
12
|
}
|
|
13
13
|
slideCount = (_a = slider.slides.length) !== null && _a !== void 0 ? _a : 0;
|
|
14
14
|
containerWidth = slider.container.offsetWidth;
|
|
15
|
-
scrollableAreaWidth = slider.
|
|
15
|
+
scrollableAreaWidth = slider.getInclusiveScrollWidth();
|
|
16
16
|
amountOfPages = Math.ceil(scrollableAreaWidth / containerWidth);
|
|
17
|
-
if (slider.container.scrollLeft >= 0) {
|
|
17
|
+
if (Math.floor(slider.container.scrollLeft) >= 0) {
|
|
18
18
|
currentPage = Math.floor(slider.container.scrollLeft / containerWidth);
|
|
19
19
|
// consider as last page if the scrollLeft + containerWidth is equal to scrollWidth
|
|
20
|
-
if (slider.container.scrollLeft + containerWidth === scrollableAreaWidth) {
|
|
20
|
+
if (Math.floor(slider.container.scrollLeft + containerWidth) === Math.floor(scrollableAreaWidth)) {
|
|
21
21
|
currentPage = amountOfPages - 1;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t){var
|
|
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};
|
|
@@ -10,6 +10,8 @@ function OverflowSlider(container, options, plugins) {
|
|
|
10
10
|
scrollBehavior: "smooth",
|
|
11
11
|
scrollStrategy: "fullSlide",
|
|
12
12
|
slidesSelector: ":scope > *",
|
|
13
|
+
emulateScrollSnap: false,
|
|
14
|
+
emulateScrollSnapMaxThreshold: 64,
|
|
13
15
|
};
|
|
14
16
|
const sliderOptions = Object.assign(Object.assign({}, defaults), options);
|
|
15
17
|
// 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
|
|
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};
|