@evermade/overflow-slider 3.3.1 → 4.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 +158 -33
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +645 -1
- package/dist/index.esm.js.map +1 -0
- package/dist/index.min.js +2 -1
- package/dist/index.min.js.map +1 -0
- package/dist/mixins.scss +14 -0
- package/dist/overflow-slider.css +1 -1
- package/dist/plugins/arrows/index.d.ts +26 -0
- package/dist/plugins/arrows/index.min.js +1 -1
- package/dist/plugins/autoplay/index.d.ts +41 -0
- package/dist/plugins/autoplay/index.esm.js +233 -0
- package/dist/plugins/autoplay/index.min.js +1 -0
- package/dist/plugins/classnames/index.d.ts +14 -0
- package/dist/plugins/classnames/index.esm.js +108 -0
- package/dist/plugins/classnames/index.min.js +1 -0
- package/dist/plugins/core/index.d.ts +76 -0
- package/dist/plugins/core/index.d2.ts +23 -0
- package/dist/plugins/dots/index.d.ts +16 -0
- package/dist/plugins/dots/index.min.js +1 -1
- package/dist/plugins/drag-scrolling/index.d.ts +9 -0
- package/dist/plugins/drag-scrolling/index.esm.js +2 -2
- package/dist/plugins/drag-scrolling/index.min.js +1 -1
- package/dist/plugins/fade/index.d.ts +16 -0
- package/dist/plugins/fade/index.min.js +1 -1
- package/dist/plugins/full-width/index.d.ts +11 -0
- package/dist/plugins/full-width/index.esm.js +37 -9
- package/dist/plugins/full-width/index.min.js +1 -1
- package/dist/plugins/infinite-scroll/index.d.ts +25 -0
- package/dist/plugins/infinite-scroll/index.esm.js +75 -0
- package/dist/plugins/infinite-scroll/index.min.js +1 -0
- package/dist/plugins/scroll-indicator/index.d.ts +14 -0
- package/dist/plugins/scroll-indicator/index.esm.js +3 -1
- package/dist/plugins/scroll-indicator/index.min.js +1 -1
- package/dist/plugins/skip-links/index.d.ts +17 -0
- package/dist/plugins/skip-links/index.esm.js +7 -1
- package/dist/plugins/skip-links/index.min.js +1 -1
- package/dist/plugins/thumbnails/index.d.ts +9 -0
- package/dist/plugins/thumbnails/index.min.js +1 -1
- package/dist/{core/utils.min.js → utils-Sxwcz8zp.js} +1 -1
- package/dist/{core/utils.esm.js → utils-ayDxlweP.js} +1 -1
- package/docs/assets/demo.css +156 -0
- package/docs/assets/demo.js +92 -8
- package/docs/dist/index.d.ts +1 -0
- package/docs/dist/index.esm.js +645 -1
- package/docs/dist/index.esm.js.map +1 -0
- package/docs/dist/index.min.js +2 -1
- package/docs/dist/index.min.js.map +1 -0
- package/docs/dist/mixins.scss +14 -0
- package/docs/dist/overflow-slider.css +1 -1
- package/docs/dist/plugins/arrows/index.d.ts +26 -0
- package/docs/dist/plugins/arrows/index.min.js +1 -1
- package/docs/dist/plugins/autoplay/index.d.ts +41 -0
- package/docs/dist/plugins/autoplay/index.esm.js +233 -0
- package/docs/dist/plugins/autoplay/index.min.js +1 -0
- package/docs/dist/plugins/classnames/index.d.ts +14 -0
- package/docs/dist/plugins/classnames/index.esm.js +108 -0
- package/docs/dist/plugins/classnames/index.min.js +1 -0
- package/docs/dist/plugins/core/index.d.ts +76 -0
- package/docs/dist/plugins/core/index.d2.ts +23 -0
- package/docs/dist/plugins/dots/index.d.ts +16 -0
- package/docs/dist/plugins/dots/index.min.js +1 -1
- package/docs/dist/plugins/drag-scrolling/index.d.ts +9 -0
- package/docs/dist/plugins/drag-scrolling/index.esm.js +2 -2
- package/docs/dist/plugins/drag-scrolling/index.min.js +1 -1
- package/docs/dist/plugins/fade/index.d.ts +16 -0
- package/docs/dist/plugins/fade/index.min.js +1 -1
- package/docs/dist/plugins/full-width/index.d.ts +11 -0
- package/docs/dist/plugins/full-width/index.esm.js +37 -9
- package/docs/dist/plugins/full-width/index.min.js +1 -1
- package/docs/dist/plugins/infinite-scroll/index.d.ts +25 -0
- package/docs/dist/plugins/infinite-scroll/index.esm.js +75 -0
- package/docs/dist/plugins/infinite-scroll/index.min.js +1 -0
- package/docs/dist/plugins/scroll-indicator/index.d.ts +14 -0
- package/docs/dist/plugins/scroll-indicator/index.esm.js +3 -1
- package/docs/dist/plugins/scroll-indicator/index.min.js +1 -1
- package/docs/dist/plugins/skip-links/index.d.ts +17 -0
- package/docs/dist/plugins/skip-links/index.esm.js +7 -1
- package/docs/dist/plugins/skip-links/index.min.js +1 -1
- package/docs/dist/plugins/thumbnails/index.d.ts +9 -0
- package/docs/dist/plugins/thumbnails/index.min.js +1 -1
- package/docs/dist/{core/utils.min.js → utils-Sxwcz8zp.js} +1 -1
- package/docs/dist/{core/utils.esm.js → utils-ayDxlweP.js} +1 -1
- package/docs/index-rtl.html +78 -2
- package/docs/index.html +86 -1
- package/package.json +50 -27
- package/rollup.config.js +90 -66
- package/src/core/details.ts +4 -0
- package/src/core/overflow-slider.ts +4 -2
- package/src/core/slider.ts +127 -62
- package/src/core/types.ts +30 -1
- package/src/mixins.scss +14 -0
- package/src/overflow-slider.scss +12 -10
- package/src/plugins/arrows/index.ts +2 -2
- package/src/plugins/autoplay/index.ts +276 -0
- package/src/plugins/autoplay/styles.scss +11 -0
- package/src/plugins/classnames/index.ts +147 -0
- package/src/plugins/dots/index.ts +2 -2
- package/src/plugins/drag-scrolling/index.ts +4 -4
- package/src/plugins/fade/index.ts +2 -2
- package/src/plugins/full-width/index.ts +43 -11
- package/src/plugins/scroll-indicator/index.ts +5 -3
- package/src/plugins/skip-links/index.ts +2 -2
- package/src/plugins/thumbnails/index.ts +2 -2
- package/tsconfig.json +4 -2
- package/changelog.md +0 -5
- package/dist/core/details.esm.js +0 -35
- package/dist/core/details.min.js +0 -1
- package/dist/core/overflow-slider.esm.js +0 -29
- package/dist/core/overflow-slider.min.js +0 -1
- package/dist/core/slider.esm.js +0 -499
- package/dist/core/slider.min.js +0 -1
- package/docs/dist/core/details.esm.js +0 -35
- package/docs/dist/core/details.min.js +0 -1
- package/docs/dist/core/overflow-slider.esm.js +0 -29
- package/docs/dist/core/overflow-slider.min.js +0 -1
- package/docs/dist/core/slider.esm.js +0 -499
- package/docs/dist/core/slider.min.js +0 -1
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Slider, DeepPartial } from '../../core/types';
|
|
2
|
+
|
|
3
|
+
export type ClassnameOptions = {
|
|
4
|
+
classNames: {
|
|
5
|
+
visible: string;
|
|
6
|
+
partlyVisible: string;
|
|
7
|
+
hidden: string;
|
|
8
|
+
},
|
|
9
|
+
freezeStateOnVisible: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const DEFAULT_CLASS_NAMES: ClassnameOptions['classNames'] = {
|
|
13
|
+
visible: 'is-visible',
|
|
14
|
+
partlyVisible: 'is-partly-visible',
|
|
15
|
+
hidden: 'is-hidden',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type VisibilityState = keyof ClassnameOptions['classNames'];
|
|
19
|
+
|
|
20
|
+
export default function ClassNamesPlugin( args?: DeepPartial<ClassnameOptions> ) {
|
|
21
|
+
return ( slider: Slider ) => {
|
|
22
|
+
|
|
23
|
+
const providedClassNames = args?.classNames ?? (args as { classnames?: DeepPartial<ClassnameOptions['classNames']> })?.classnames;
|
|
24
|
+
|
|
25
|
+
const options = <ClassnameOptions>{
|
|
26
|
+
classNames: {
|
|
27
|
+
...DEFAULT_CLASS_NAMES,
|
|
28
|
+
...providedClassNames ?? {},
|
|
29
|
+
},
|
|
30
|
+
freezeStateOnVisible: args?.freezeStateOnVisible ?? false,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const slideStates = new WeakMap<HTMLElement, VisibilityState>();
|
|
34
|
+
const uniqueClassNames = Array.from(
|
|
35
|
+
new Set(
|
|
36
|
+
Object.values( options.classNames ).filter( ( className ): className is string => Boolean( className ) )
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const getTargetBounds = () => {
|
|
41
|
+
const sliderRect = slider.container.getBoundingClientRect();
|
|
42
|
+
const sliderWidth = sliderRect.width;
|
|
43
|
+
if (!sliderWidth) {
|
|
44
|
+
return { targetStart: sliderRect.left, targetEnd: sliderRect.right };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let targetWidth = 0;
|
|
48
|
+
if ( typeof slider.options.targetWidth === 'function' ) {
|
|
49
|
+
try {
|
|
50
|
+
targetWidth = slider.options.targetWidth( slider );
|
|
51
|
+
} catch ( error ) {
|
|
52
|
+
targetWidth = 0;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if ( !Number.isFinite( targetWidth ) || targetWidth <= 0 ) {
|
|
57
|
+
targetWidth = sliderWidth;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const effectiveTargetWidth = Math.min( targetWidth, sliderWidth );
|
|
61
|
+
const offset = ( sliderWidth - effectiveTargetWidth ) / 2;
|
|
62
|
+
const clampedOffset = Math.max( offset, 0 );
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
targetStart: sliderRect.left + clampedOffset,
|
|
66
|
+
targetEnd: sliderRect.right - clampedOffset,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const update = () => {
|
|
71
|
+
const { targetStart, targetEnd } = getTargetBounds();
|
|
72
|
+
|
|
73
|
+
console.log( 'targetStart:', targetStart, 'targetEnd:', targetEnd );
|
|
74
|
+
|
|
75
|
+
slider.slides.forEach( ( slide ) => {
|
|
76
|
+
const slideRect = slide.getBoundingClientRect();
|
|
77
|
+
const slideLeft = slideRect.left;
|
|
78
|
+
const slideRight = slideRect.right;
|
|
79
|
+
|
|
80
|
+
const tolerance = 2;
|
|
81
|
+
const overlapsTarget = (slideRight - tolerance) > targetStart && (slideLeft + tolerance) < targetEnd;
|
|
82
|
+
const fullyInsideTarget = (slideLeft + tolerance) >= targetStart && (slideRight - tolerance) <= targetEnd;
|
|
83
|
+
|
|
84
|
+
let nextState: VisibilityState = 'hidden';
|
|
85
|
+
if ( overlapsTarget ) {
|
|
86
|
+
nextState = fullyInsideTarget ? 'visible' : 'partlyVisible';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const prevState = slideStates.get( slide );
|
|
90
|
+
|
|
91
|
+
// If freezeStateOnVisible is enabled and slide was previously visible, keep it frozen
|
|
92
|
+
if ( options.freezeStateOnVisible && prevState === 'visible' ) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if ( prevState === nextState ) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const nextClass = options.classNames[ nextState ];
|
|
101
|
+
if ( prevState ) {
|
|
102
|
+
const prevClass = options.classNames[ prevState ];
|
|
103
|
+
if ( prevClass !== nextClass && prevClass ) {
|
|
104
|
+
slide.classList.remove( prevClass );
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
uniqueClassNames.forEach( ( className ) => {
|
|
108
|
+
if ( className !== nextClass ) {
|
|
109
|
+
slide.classList.remove( className );
|
|
110
|
+
}
|
|
111
|
+
} );
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if ( nextClass && !slide.classList.contains( nextClass ) ) {
|
|
115
|
+
slide.classList.add( nextClass );
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
slideStates.set( slide, nextState );
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
slider.on( 'created', update );
|
|
123
|
+
slider.on( 'pluginsLoaded', update );
|
|
124
|
+
slider.on( 'fullWidthPluginUpdate', update );
|
|
125
|
+
slider.on( 'contentsChanged', update );
|
|
126
|
+
slider.on( 'containerSizeChanged', update );
|
|
127
|
+
slider.on( 'detailsChanged', update );
|
|
128
|
+
slider.on( 'scrollEnd', update );
|
|
129
|
+
slider.on( 'scrollStart', update );
|
|
130
|
+
|
|
131
|
+
requestAnimationFrame(() => {
|
|
132
|
+
requestAnimationFrame(() => update());
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
let requestId = 0;
|
|
136
|
+
const debouncedUpdate = () => {
|
|
137
|
+
if ( requestId ) {
|
|
138
|
+
window.cancelAnimationFrame( requestId );
|
|
139
|
+
}
|
|
140
|
+
requestId = window.requestAnimationFrame(() => {
|
|
141
|
+
update();
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
slider.on('scroll', debouncedUpdate);
|
|
145
|
+
|
|
146
|
+
};
|
|
147
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Slider } from '../../core/types';
|
|
1
|
+
import { Slider, DeepPartial } from '../../core/types';
|
|
2
2
|
|
|
3
3
|
export type DotsOptions = {
|
|
4
4
|
texts: {
|
|
@@ -20,7 +20,7 @@ const DEFAULT_CLASS_NAMES = {
|
|
|
20
20
|
dotsItem: 'overflow-slider__dot-item',
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
export default function DotsPlugin( args
|
|
23
|
+
export default function DotsPlugin( args?: DeepPartial<DotsOptions> ) {
|
|
24
24
|
return ( slider: Slider ) => {
|
|
25
25
|
const options = <DotsOptions>{
|
|
26
26
|
texts: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Slider } from '../../core/types';
|
|
1
|
+
import { Slider, DeepPartial } from '../../core/types';
|
|
2
2
|
|
|
3
3
|
const DEFAULT_DRAGGED_DISTANCE_THAT_PREVENTS_CLICK = 20;
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ export type DragScrollingOptions = {
|
|
|
6
6
|
draggedDistanceThatPreventsClick: number,
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
export default function DragScrollingPlugin( args
|
|
9
|
+
export default function DragScrollingPlugin( args?: DeepPartial<DragScrollingOptions> ) {
|
|
10
10
|
const options = <DragScrollingOptions>{
|
|
11
11
|
draggedDistanceThatPreventsClick: args?.draggedDistanceThatPreventsClick ?? DEFAULT_DRAGGED_DISTANCE_THAT_PREVENTS_CLICK,
|
|
12
12
|
};
|
|
@@ -31,7 +31,7 @@ export default function DragScrollingPlugin( args: { [key: string]: unknown } )
|
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
isMouseDown = true;
|
|
34
|
-
startX = e.pageX - slider.container.
|
|
34
|
+
startX = e.pageX - slider.container.getBoundingClientRect().left;
|
|
35
35
|
scrollLeft = slider.container.scrollLeft;
|
|
36
36
|
// change cursor to grabbing
|
|
37
37
|
slider.container.style.cursor = 'grabbing';
|
|
@@ -55,7 +55,7 @@ export default function DragScrollingPlugin( args: { [key: string]: unknown } )
|
|
|
55
55
|
programmaticScrollStarted = true;
|
|
56
56
|
slider.emit('programmaticScrollStart');
|
|
57
57
|
}
|
|
58
|
-
const x = e.pageX - slider.container.
|
|
58
|
+
const x = e.pageX - slider.container.getBoundingClientRect().left;
|
|
59
59
|
const walk = (x - startX);
|
|
60
60
|
const newScrollLeft = scrollLeft - walk;
|
|
61
61
|
mayNeedToSnap = true;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Slider } from '../../core/types';
|
|
1
|
+
import { Slider, DeepPartial } from '../../core/types';
|
|
2
2
|
|
|
3
3
|
export type FadeOptions = {
|
|
4
4
|
classNames: {
|
|
@@ -11,7 +11,7 @@ export type FadeOptions = {
|
|
|
11
11
|
containerEnd: HTMLElement | null,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export default function FadePlugin( args
|
|
14
|
+
export default function FadePlugin( args?: DeepPartial<FadeOptions> ) {
|
|
15
15
|
return ( slider: Slider ) => {
|
|
16
16
|
|
|
17
17
|
const options = <FadeOptions>{
|
|
@@ -1,22 +1,33 @@
|
|
|
1
|
-
import { Slider } from '../../core/types';
|
|
1
|
+
import { Slider, DeepPartial } from '../../core/types';
|
|
2
2
|
|
|
3
3
|
const DEFAULT_TARGET_WIDTH = ( slider: Slider ) => slider.container.parentElement?.offsetWidth ?? window.innerWidth;
|
|
4
4
|
|
|
5
5
|
export type FullWidthOptions = {
|
|
6
|
-
targetWidth
|
|
6
|
+
targetWidth?: ( slider: Slider ) => number,
|
|
7
7
|
addMarginBefore: boolean,
|
|
8
8
|
addMarginAfter: boolean,
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export default function FullWidthPlugin( args
|
|
11
|
+
export default function FullWidthPlugin( args?: DeepPartial<FullWidthOptions> ) {
|
|
12
12
|
return ( slider: Slider ) => {
|
|
13
13
|
|
|
14
14
|
const options = <FullWidthOptions>{
|
|
15
|
-
targetWidth: args?.targetWidth ??
|
|
15
|
+
targetWidth: args?.targetWidth ?? undefined,
|
|
16
16
|
addMarginBefore: args?.addMarginBefore ?? true,
|
|
17
17
|
addMarginAfter: args?.addMarginAfter ?? true,
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
if ( typeof slider.options.targetWidth !== 'function' ) {
|
|
21
|
+
slider.options.targetWidth = options.targetWidth ?? DEFAULT_TARGET_WIDTH;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const resolveTargetWidth = () => {
|
|
25
|
+
if ( typeof slider.options.targetWidth === 'function' ) {
|
|
26
|
+
return slider.options.targetWidth;
|
|
27
|
+
}
|
|
28
|
+
return options.targetWidth ?? DEFAULT_TARGET_WIDTH;
|
|
29
|
+
};
|
|
30
|
+
|
|
20
31
|
const update = () => {
|
|
21
32
|
const slides = slider.container.querySelectorAll( slider.options.slidesSelector );
|
|
22
33
|
|
|
@@ -24,22 +35,43 @@ export default function FullWidthPlugin( args: { [key: string]: unknown } ) {
|
|
|
24
35
|
return;
|
|
25
36
|
}
|
|
26
37
|
|
|
38
|
+
const targetWidthFn = resolveTargetWidth();
|
|
39
|
+
const rawMargin = ( window.innerWidth - targetWidthFn( slider ) ) / 2;
|
|
40
|
+
const marginAmount = Math.max( 0, Math.floor( rawMargin ) );
|
|
41
|
+
const marginValue = marginAmount ? `${marginAmount}px` : '';
|
|
42
|
+
|
|
43
|
+
slides.forEach( ( slide ) => {
|
|
44
|
+
const element = slide as HTMLElement;
|
|
45
|
+
element.style.marginInlineStart = '';
|
|
46
|
+
element.style.marginInlineEnd = '';
|
|
47
|
+
} );
|
|
48
|
+
|
|
27
49
|
const firstSlide = slides[0] as HTMLElement;
|
|
28
50
|
const lastSlide = slides[slides.length - 1] as HTMLElement;
|
|
29
51
|
|
|
30
|
-
const marginAmount = Math.floor((window.innerWidth - options.targetWidth(slider)) / 2);
|
|
31
52
|
if ( options.addMarginBefore ) {
|
|
32
|
-
firstSlide.style.marginInlineStart =
|
|
53
|
+
firstSlide.style.marginInlineStart = marginValue;
|
|
54
|
+
slider.container.style.setProperty( 'scroll-padding-inline-start', marginValue || '0px' );
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
slider.container.style.removeProperty( 'scroll-padding-inline-start' );
|
|
33
58
|
}
|
|
34
59
|
if ( options.addMarginAfter ) {
|
|
35
|
-
lastSlide.style.marginInlineEnd =
|
|
60
|
+
lastSlide.style.marginInlineEnd = marginValue;
|
|
61
|
+
slider.container.style.setProperty( 'scroll-padding-inline-end', marginValue || '0px' );
|
|
36
62
|
}
|
|
37
|
-
|
|
38
|
-
|
|
63
|
+
else {
|
|
64
|
+
slider.container.style.removeProperty( 'scroll-padding-inline-end' );
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
slider.container.setAttribute( 'data-full-width-offset', `${marginAmount}` );
|
|
68
|
+
setCSS( targetWidthFn );
|
|
69
|
+
slider.emit( 'fullWidthPluginUpdate' );
|
|
39
70
|
};
|
|
40
71
|
|
|
41
|
-
const setCSS = () => {
|
|
42
|
-
|
|
72
|
+
const setCSS = ( targetWidthFn: ( slider: Slider ) => number ) => {
|
|
73
|
+
const width = targetWidthFn( slider );
|
|
74
|
+
slider.options.cssVariableContainer.style.setProperty('--slider-container-target-width', `${width}px`);
|
|
43
75
|
};
|
|
44
76
|
|
|
45
77
|
update();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Slider } from '../../core/types';
|
|
1
|
+
import { Slider, DeepPartial } from '../../core/types';
|
|
2
2
|
|
|
3
3
|
const DEFAULT_CLASS_NAMES = {
|
|
4
4
|
scrollIndicator: 'overflow-slider__scroll-indicator',
|
|
@@ -15,7 +15,7 @@ export type ScrollIndicatorOptions = {
|
|
|
15
15
|
container: HTMLElement | null,
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export default function ScrollIndicatorPlugin(args
|
|
18
|
+
export default function ScrollIndicatorPlugin(args?: DeepPartial<ScrollIndicatorOptions>) {
|
|
19
19
|
return (slider: Slider) => {
|
|
20
20
|
|
|
21
21
|
const options = <ScrollIndicatorOptions>{
|
|
@@ -112,10 +112,12 @@ export default function ScrollIndicatorPlugin(args: { [key: string]: unknown })
|
|
|
112
112
|
const scrollbarButtonWidth = scrollbarButton.offsetWidth;
|
|
113
113
|
const scrollbarButtonLeft = getScrollbarButtonLeftOffset();
|
|
114
114
|
const scrollbarButtonRight = scrollbarButtonLeft + scrollbarButtonWidth;
|
|
115
|
-
const clickX = e.pageX -
|
|
115
|
+
const clickX = (e as MouseEvent).pageX - scrollbarContainer.getBoundingClientRect().left;
|
|
116
116
|
if (Math.floor(clickX) < Math.floor(scrollbarButtonLeft)) {
|
|
117
|
+
console.log('move left');
|
|
117
118
|
slider.moveToDirection(slider.options.rtl ? 'next' : 'prev');
|
|
118
119
|
} else if (Math.floor(clickX) > Math.floor(scrollbarButtonRight)) {
|
|
120
|
+
console.log('move right');
|
|
119
121
|
slider.moveToDirection(slider.options.rtl ? 'prev' : 'next');
|
|
120
122
|
}
|
|
121
123
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Slider } from '../../core/types';
|
|
1
|
+
import { Slider, DeepPartial } from '../../core/types';
|
|
2
2
|
import { generateId } from '../../core/utils';
|
|
3
3
|
|
|
4
4
|
const DEFAULT_TEXTS = {
|
|
@@ -22,7 +22,7 @@ export type SkipLinkOptions = {
|
|
|
22
22
|
containerAfter: HTMLElement | null,
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
export default function SkipLinksPlugin( args
|
|
25
|
+
export default function SkipLinksPlugin( args?: DeepPartial<SkipLinkOptions> ) {
|
|
26
26
|
return ( slider: Slider ) => {
|
|
27
27
|
const options = <SkipLinkOptions>{
|
|
28
28
|
texts: {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Slider } from '../../core/types';
|
|
1
|
+
import { Slider, DeepPartial } from '../../core/types';
|
|
2
2
|
|
|
3
3
|
export type ThumbnailsOptions = {
|
|
4
4
|
mainSlider: Slider,
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
export default function FullWidthPlugin( args:
|
|
7
|
+
export default function FullWidthPlugin( args: DeepPartial<ThumbnailsOptions> ) {
|
|
8
8
|
return ( slider: Slider ) => {
|
|
9
9
|
|
|
10
10
|
const options = <ThumbnailsOptions>{
|
package/tsconfig.json
CHANGED
package/changelog.md
DELETED
package/dist/core/details.esm.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
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 (Math.floor(slider.getInclusiveScrollWidth()) > Math.floor(slider.getInclusiveClientWidth())) {
|
|
11
|
-
hasOverflow = true;
|
|
12
|
-
}
|
|
13
|
-
slideCount = (_a = slider.slides.length) !== null && _a !== void 0 ? _a : 0;
|
|
14
|
-
containerWidth = slider.container.offsetWidth;
|
|
15
|
-
scrollableAreaWidth = slider.getInclusiveScrollWidth();
|
|
16
|
-
amountOfPages = Math.ceil(scrollableAreaWidth / containerWidth);
|
|
17
|
-
if (Math.floor(slider.getScrollLeft()) >= 0) {
|
|
18
|
-
currentPage = Math.floor(slider.getScrollLeft() / containerWidth);
|
|
19
|
-
// consider as last page if the scrollLeft + containerWidth is equal to scrollWidth
|
|
20
|
-
if (Math.floor(slider.getScrollLeft() + containerWidth) === Math.floor(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 };
|
package/dist/core/details.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function t(t){var l;let e,o=!1,r=0,a=0,i=0,n=0,f=1;return Math.floor(t.getInclusiveScrollWidth())>Math.floor(t.getInclusiveClientWidth())&&(o=!0),r=null!==(l=t.slides.length)&&void 0!==l?l:0,a=t.container.offsetWidth,i=t.getInclusiveScrollWidth(),n=Math.ceil(i/a),Math.floor(t.getScrollLeft())>=0&&(f=Math.floor(t.getScrollLeft()/a),Math.floor(t.getScrollLeft()+a)===Math.floor(i)&&(f=n-1)),e={hasOverflow:o,slideCount:r,containerWidth:a,scrollableAreaWidth:i,amountOfPages:n,currentPage:f},e}export{t as default};
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
emulateScrollSnap: false,
|
|
14
|
-
emulateScrollSnapMaxThreshold: 64,
|
|
15
|
-
rtl: false,
|
|
16
|
-
};
|
|
17
|
-
const sliderOptions = Object.assign(Object.assign({}, defaults), options);
|
|
18
|
-
// disable smooth scrolling if user prefers reduced motion
|
|
19
|
-
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
|
20
|
-
sliderOptions.scrollBehavior = "auto";
|
|
21
|
-
}
|
|
22
|
-
return Slider(container, sliderOptions, plugins);
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
console.error(e);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { OverflowSlider as default };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"./slider.min.js";function o(o,r,t){try{if(!(o instanceof Element))throw new Error("Container must be HTML element, found "+typeof o);const l={scrollBehavior:"smooth",scrollStrategy:"fullSlide",slidesSelector:":scope > *",emulateScrollSnap:!1,emulateScrollSnapMaxThreshold:64,rtl:!1},s=Object.assign(Object.assign({},l),r);return window.matchMedia("(prefers-reduced-motion: reduce)").matches&&(s.scrollBehavior="auto"),e(o,s,t)}catch(e){console.error(e)}}export{o as default};
|