@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
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
const DEFAULT_CLASS_NAMES = {
|
|
2
|
+
visible: 'is-visible',
|
|
3
|
+
partlyVisible: 'is-partly-visible',
|
|
4
|
+
hidden: 'is-hidden',
|
|
5
|
+
};
|
|
6
|
+
function ClassNamesPlugin(args) {
|
|
7
|
+
return (slider) => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
const providedClassNames = (_a = args === null || args === void 0 ? void 0 : args.classNames) !== null && _a !== void 0 ? _a : args === null || args === void 0 ? void 0 : args.classnames;
|
|
10
|
+
const options = {
|
|
11
|
+
classNames: Object.assign(Object.assign({}, DEFAULT_CLASS_NAMES), providedClassNames !== null && providedClassNames !== void 0 ? providedClassNames : {}),
|
|
12
|
+
freezeStateOnVisible: (_b = args === null || args === void 0 ? void 0 : args.freezeStateOnVisible) !== null && _b !== void 0 ? _b : false,
|
|
13
|
+
};
|
|
14
|
+
const slideStates = new WeakMap();
|
|
15
|
+
const uniqueClassNames = Array.from(new Set(Object.values(options.classNames).filter((className) => Boolean(className))));
|
|
16
|
+
const getTargetBounds = () => {
|
|
17
|
+
const sliderRect = slider.container.getBoundingClientRect();
|
|
18
|
+
const sliderWidth = sliderRect.width;
|
|
19
|
+
if (!sliderWidth) {
|
|
20
|
+
return { targetStart: sliderRect.left, targetEnd: sliderRect.right };
|
|
21
|
+
}
|
|
22
|
+
let targetWidth = 0;
|
|
23
|
+
if (typeof slider.options.targetWidth === 'function') {
|
|
24
|
+
try {
|
|
25
|
+
targetWidth = slider.options.targetWidth(slider);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
targetWidth = 0;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (!Number.isFinite(targetWidth) || targetWidth <= 0) {
|
|
32
|
+
targetWidth = sliderWidth;
|
|
33
|
+
}
|
|
34
|
+
const effectiveTargetWidth = Math.min(targetWidth, sliderWidth);
|
|
35
|
+
const offset = (sliderWidth - effectiveTargetWidth) / 2;
|
|
36
|
+
const clampedOffset = Math.max(offset, 0);
|
|
37
|
+
return {
|
|
38
|
+
targetStart: sliderRect.left + clampedOffset,
|
|
39
|
+
targetEnd: sliderRect.right - clampedOffset,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const update = () => {
|
|
43
|
+
const { targetStart, targetEnd } = getTargetBounds();
|
|
44
|
+
slider.slides.forEach((slide) => {
|
|
45
|
+
const slideRect = slide.getBoundingClientRect();
|
|
46
|
+
const slideLeft = slideRect.left;
|
|
47
|
+
const slideRight = slideRect.right;
|
|
48
|
+
const tolerance = 2;
|
|
49
|
+
const overlapsTarget = (slideRight - tolerance) > targetStart && (slideLeft + tolerance) < targetEnd;
|
|
50
|
+
const fullyInsideTarget = (slideLeft + tolerance) >= targetStart && (slideRight - tolerance) <= targetEnd;
|
|
51
|
+
let nextState = 'hidden';
|
|
52
|
+
if (overlapsTarget) {
|
|
53
|
+
nextState = fullyInsideTarget ? 'visible' : 'partlyVisible';
|
|
54
|
+
}
|
|
55
|
+
const prevState = slideStates.get(slide);
|
|
56
|
+
// If freezeStateOnVisible is enabled and slide was previously visible, keep it frozen
|
|
57
|
+
if (options.freezeStateOnVisible && prevState === 'visible') {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (prevState === nextState) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const nextClass = options.classNames[nextState];
|
|
64
|
+
if (prevState) {
|
|
65
|
+
const prevClass = options.classNames[prevState];
|
|
66
|
+
if (prevClass !== nextClass && prevClass) {
|
|
67
|
+
slide.classList.remove(prevClass);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
uniqueClassNames.forEach((className) => {
|
|
72
|
+
if (className !== nextClass) {
|
|
73
|
+
slide.classList.remove(className);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (nextClass && !slide.classList.contains(nextClass)) {
|
|
78
|
+
slide.classList.add(nextClass);
|
|
79
|
+
}
|
|
80
|
+
slideStates.set(slide, nextState);
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
slider.on('created', update);
|
|
84
|
+
slider.on('pluginsLoaded', update);
|
|
85
|
+
slider.on('fullWidthPluginUpdate', update);
|
|
86
|
+
slider.on('contentsChanged', update);
|
|
87
|
+
slider.on('containerSizeChanged', update);
|
|
88
|
+
slider.on('detailsChanged', update);
|
|
89
|
+
slider.on('scrollEnd', update);
|
|
90
|
+
slider.on('scrollStart', update);
|
|
91
|
+
requestAnimationFrame(() => {
|
|
92
|
+
requestAnimationFrame(() => update());
|
|
93
|
+
});
|
|
94
|
+
let requestId = 0;
|
|
95
|
+
const debouncedUpdate = () => {
|
|
96
|
+
if (requestId) {
|
|
97
|
+
window.cancelAnimationFrame(requestId);
|
|
98
|
+
}
|
|
99
|
+
requestId = window.requestAnimationFrame(() => {
|
|
100
|
+
update();
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
slider.on('scroll', debouncedUpdate);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { ClassNamesPlugin as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t={visible:"is-visible",partlyVisible:"is-partly-visible",hidden:"is-hidden"};function e(e){return n=>{var i,s;const a=null!==(i=null==e?void 0:e.classNames)&&void 0!==i?i:null==e?void 0:e.classnames,l={classNames:Object.assign(Object.assign({},t),null!=a?a:{}),freezeStateOnVisible:null!==(s=null==e?void 0:e.freezeStateOnVisible)&&void 0!==s&&s},r=new WeakMap,o=Array.from(new Set(Object.values(l.classNames).filter(t=>Boolean(t)))),c=()=>{const{targetStart:t,targetEnd:e}=(()=>{const t=n.container.getBoundingClientRect(),e=t.width;if(!e)return{targetStart:t.left,targetEnd:t.right};let i=0;if("function"==typeof n.options.targetWidth)try{i=n.options.targetWidth(n)}catch(t){i=0}(!Number.isFinite(i)||i<=0)&&(i=e);const s=(e-Math.min(i,e))/2,a=Math.max(s,0);return{targetStart:t.left+a,targetEnd:t.right-a}})();n.slides.forEach(n=>{const i=n.getBoundingClientRect(),s=i.left,a=i.right;let c="hidden";a-2>t&&s+2<e&&(c=s+2>=t&&a-2<=e?"visible":"partlyVisible");const d=r.get(n);if(l.freezeStateOnVisible&&"visible"===d)return;if(d===c)return;const u=l.classNames[c];if(d){const t=l.classNames[d];t!==u&&t&&n.classList.remove(t)}else o.forEach(t=>{t!==u&&n.classList.remove(t)});u&&!n.classList.contains(u)&&n.classList.add(u),r.set(n,c)})};n.on("created",c),n.on("pluginsLoaded",c),n.on("fullWidthPluginUpdate",c),n.on("contentsChanged",c),n.on("containerSizeChanged",c),n.on("detailsChanged",c),n.on("scrollEnd",c),n.on("scrollStart",c),requestAnimationFrame(()=>{requestAnimationFrame(()=>c())});let d=0;n.on("scroll",()=>{d&&window.cancelAnimationFrame(d),d=window.requestAnimationFrame(()=>{c()})})}}export{e as default};
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare function OverflowSlider(container: HTMLElement, options?: SliderOptionArgs, plugins?: SliderPlugin[]): {
|
|
1
|
+
type Slider<O = {}, C = {}, H extends string = string> = {
|
|
4
2
|
container: HTMLElement;
|
|
5
3
|
slides: HTMLElement[];
|
|
6
|
-
emit: (name:
|
|
7
|
-
moveToDirection: (direction:
|
|
8
|
-
moveToSlideInDirection: (direction:
|
|
9
|
-
snapToClosestSlide: (direction:
|
|
4
|
+
emit: (name: H | SliderHooks) => void;
|
|
5
|
+
moveToDirection: (direction: 'prev' | 'next') => void;
|
|
6
|
+
moveToSlideInDirection: (direction: 'prev' | 'next') => void;
|
|
7
|
+
snapToClosestSlide: (direction: 'prev' | 'next') => void;
|
|
10
8
|
moveToSlide: (index: number) => void;
|
|
11
9
|
canMoveToSlide: (index: number) => boolean;
|
|
12
10
|
getInclusiveScrollWidth: () => number;
|
|
@@ -14,10 +12,65 @@ declare function OverflowSlider(container: HTMLElement, options?: SliderOptionAr
|
|
|
14
12
|
getScrollLeft: () => number;
|
|
15
13
|
setScrollLeft: (value: number) => void;
|
|
16
14
|
setActiveSlideIdx: () => void;
|
|
17
|
-
on: (name:
|
|
15
|
+
on: (name: H | SliderHooks, cb: SliderCallback) => void;
|
|
18
16
|
options: SliderOptions;
|
|
19
17
|
details: SliderDetails;
|
|
20
18
|
activeSlideIdx: number;
|
|
21
|
-
}
|
|
19
|
+
} & C;
|
|
20
|
+
type SliderCallback<O = {}, C = {}, H extends string = string> = (props: Slider<O, C, H>) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Recursively makes all properties of T optional.
|
|
23
|
+
* @see https://www.typescriptlang.org/docs/handbook/utility-types.html#mapped-types
|
|
24
|
+
*/
|
|
25
|
+
type DeepPartial<T> = {
|
|
26
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
27
|
+
};
|
|
28
|
+
type SliderOptions = {
|
|
29
|
+
scrollBehavior: string;
|
|
30
|
+
scrollStrategy: string;
|
|
31
|
+
slidesSelector: string;
|
|
32
|
+
emulateScrollSnap: boolean;
|
|
33
|
+
emulateScrollSnapMaxThreshold?: number;
|
|
34
|
+
cssVariableContainer: HTMLElement;
|
|
35
|
+
rtl: boolean;
|
|
36
|
+
targetWidth?: (slider: Slider) => number;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
};
|
|
39
|
+
type SliderOptionArgs = {
|
|
40
|
+
scrollBehavior?: 'smooth' | 'auto';
|
|
41
|
+
scrollStrategy?: 'fullSlide' | 'partialSlide';
|
|
42
|
+
slidesSelector?: string;
|
|
43
|
+
emulateScrollSnap?: boolean;
|
|
44
|
+
emulateScrollSnapMaxThreshold?: number;
|
|
45
|
+
cssVariableContainer?: HTMLElement;
|
|
46
|
+
rtl?: boolean;
|
|
47
|
+
targetWidth?: (slider: Slider) => number;
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
};
|
|
50
|
+
type SliderDetails = {
|
|
51
|
+
hasOverflow: boolean;
|
|
52
|
+
slideCount: number;
|
|
53
|
+
containerWidth: number;
|
|
54
|
+
containerHeight: number;
|
|
55
|
+
scrollableAreaWidth: number;
|
|
56
|
+
amountOfPages: number;
|
|
57
|
+
currentPage: number;
|
|
58
|
+
};
|
|
59
|
+
type SliderHooks = HOOK_CREATED | HOOK_CONTENTS_CHANGED | HOOK_DETAILS_CHANGED | HOOK_CONTAINER_SIZE_CHANGED | HOOK_ACTIVE_SLIDE_CHANGED | HOOK_SCROLL_START | HOOK_SCROLL | HOOK_SCROLL_END | HOOK_NATIVE_SCROLL_START | HOOK_NATIVE_SCROLL | HOOK_NATIVE_SCROLL_END | HOOK_PROGRAMMATIC_SCROLL_START | HOOK_PROGRAMMATIC_SCROLL | HOOK_PROGRAMMATIC_SCROLL_END;
|
|
60
|
+
type HOOK_CREATED = 'created';
|
|
61
|
+
type HOOK_DETAILS_CHANGED = 'detailsChanged';
|
|
62
|
+
type HOOK_CONTENTS_CHANGED = 'contentsChanged';
|
|
63
|
+
type HOOK_CONTAINER_SIZE_CHANGED = 'containerSizeChanged';
|
|
64
|
+
type HOOK_ACTIVE_SLIDE_CHANGED = 'activeSlideChanged';
|
|
65
|
+
type HOOK_SCROLL_START = 'scrollStart';
|
|
66
|
+
type HOOK_SCROLL = 'scroll';
|
|
67
|
+
type HOOK_SCROLL_END = 'scrollEnd';
|
|
68
|
+
type HOOK_NATIVE_SCROLL_START = 'nativeScrollStart';
|
|
69
|
+
type HOOK_NATIVE_SCROLL = 'nativeScroll';
|
|
70
|
+
type HOOK_NATIVE_SCROLL_END = 'nativeScrollEnd';
|
|
71
|
+
type HOOK_PROGRAMMATIC_SCROLL_START = 'programmaticScrollStart';
|
|
72
|
+
type HOOK_PROGRAMMATIC_SCROLL = 'programmaticScroll';
|
|
73
|
+
type HOOK_PROGRAMMATIC_SCROLL_END = 'programmaticScrollEnd';
|
|
74
|
+
type SliderPlugin = (slider: Slider) => void;
|
|
22
75
|
|
|
23
|
-
export {
|
|
76
|
+
export type { DeepPartial, HOOK_ACTIVE_SLIDE_CHANGED, HOOK_CONTAINER_SIZE_CHANGED, HOOK_CONTENTS_CHANGED, HOOK_CREATED, HOOK_DETAILS_CHANGED, HOOK_NATIVE_SCROLL, HOOK_NATIVE_SCROLL_END, HOOK_NATIVE_SCROLL_START, HOOK_PROGRAMMATIC_SCROLL, HOOK_PROGRAMMATIC_SCROLL_END, HOOK_PROGRAMMATIC_SCROLL_START, HOOK_SCROLL, HOOK_SCROLL_END, HOOK_SCROLL_START, Slider, SliderCallback, SliderDetails, SliderHooks, SliderOptionArgs, SliderOptions, SliderPlugin };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { SliderOptionArgs, SliderPlugin, SliderCallback, SliderOptions, SliderDetails } from './index.js';
|
|
2
|
+
|
|
3
|
+
declare function OverflowSlider(container: HTMLElement, options?: SliderOptionArgs, plugins?: SliderPlugin[]): {
|
|
2
4
|
container: HTMLElement;
|
|
3
5
|
slides: HTMLElement[];
|
|
4
|
-
emit: (name:
|
|
5
|
-
moveToDirection: (direction:
|
|
6
|
-
moveToSlideInDirection: (direction:
|
|
7
|
-
snapToClosestSlide: (direction:
|
|
6
|
+
emit: (name: string) => void;
|
|
7
|
+
moveToDirection: (direction: "prev" | "next") => void;
|
|
8
|
+
moveToSlideInDirection: (direction: "prev" | "next") => void;
|
|
9
|
+
snapToClosestSlide: (direction: "prev" | "next") => void;
|
|
8
10
|
moveToSlide: (index: number) => void;
|
|
9
11
|
canMoveToSlide: (index: number) => boolean;
|
|
10
12
|
getInclusiveScrollWidth: () => number;
|
|
@@ -12,64 +14,10 @@ type Slider<O = {}, C = {}, H extends string = string> = {
|
|
|
12
14
|
getScrollLeft: () => number;
|
|
13
15
|
setScrollLeft: (value: number) => void;
|
|
14
16
|
setActiveSlideIdx: () => void;
|
|
15
|
-
on: (name:
|
|
17
|
+
on: (name: string, cb: SliderCallback) => void;
|
|
16
18
|
options: SliderOptions;
|
|
17
19
|
details: SliderDetails;
|
|
18
20
|
activeSlideIdx: number;
|
|
19
|
-
}
|
|
20
|
-
type SliderCallback<O = {}, C = {}, H extends string = string> = (props: Slider<O, C, H>) => void;
|
|
21
|
-
/**
|
|
22
|
-
* Recursively makes all properties of T optional.
|
|
23
|
-
* @see https://www.typescriptlang.org/docs/handbook/utility-types.html#mapped-types
|
|
24
|
-
*/
|
|
25
|
-
type DeepPartial<T> = {
|
|
26
|
-
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
27
|
-
};
|
|
28
|
-
type SliderOptions = {
|
|
29
|
-
scrollBehavior: string;
|
|
30
|
-
scrollStrategy: string;
|
|
31
|
-
slidesSelector: string;
|
|
32
|
-
emulateScrollSnap: boolean;
|
|
33
|
-
emulateScrollSnapMaxThreshold?: number;
|
|
34
|
-
cssVariableContainer: HTMLElement;
|
|
35
|
-
rtl: boolean;
|
|
36
|
-
targetWidth?: (slider: Slider) => number;
|
|
37
|
-
[key: string]: unknown;
|
|
38
|
-
};
|
|
39
|
-
type SliderOptionArgs = {
|
|
40
|
-
scrollBehavior?: 'smooth' | 'auto';
|
|
41
|
-
scrollStrategy?: 'fullSlide' | 'partialSlide';
|
|
42
|
-
slidesSelector?: string;
|
|
43
|
-
emulateScrollSnap?: boolean;
|
|
44
|
-
emulateScrollSnapMaxThreshold?: number;
|
|
45
|
-
cssVariableContainer?: HTMLElement;
|
|
46
|
-
rtl?: boolean;
|
|
47
|
-
[key: string]: unknown;
|
|
48
|
-
};
|
|
49
|
-
type SliderDetails = {
|
|
50
|
-
hasOverflow: boolean;
|
|
51
|
-
slideCount: number;
|
|
52
|
-
containerWidth: number;
|
|
53
|
-
containerHeight: number;
|
|
54
|
-
scrollableAreaWidth: number;
|
|
55
|
-
amountOfPages: number;
|
|
56
|
-
currentPage: number;
|
|
57
|
-
};
|
|
58
|
-
type SliderHooks = HOOK_CREATED | HOOK_CONTENTS_CHANGED | HOOK_DETAILS_CHANGED | HOOK_CONTAINER_SIZE_CHANGED | HOOK_ACTIVE_SLIDE_CHANGED | HOOK_SCROLL_START | HOOK_SCROLL | HOOK_SCROLL_END | HOOK_NATIVE_SCROLL_START | HOOK_NATIVE_SCROLL | HOOK_NATIVE_SCROLL_END | HOOK_PROGRAMMATIC_SCROLL_START | HOOK_PROGRAMMATIC_SCROLL | HOOK_PROGRAMMATIC_SCROLL_END;
|
|
59
|
-
type HOOK_CREATED = 'created';
|
|
60
|
-
type HOOK_DETAILS_CHANGED = 'detailsChanged';
|
|
61
|
-
type HOOK_CONTENTS_CHANGED = 'contentsChanged';
|
|
62
|
-
type HOOK_CONTAINER_SIZE_CHANGED = 'containerSizeChanged';
|
|
63
|
-
type HOOK_ACTIVE_SLIDE_CHANGED = 'activeSlideChanged';
|
|
64
|
-
type HOOK_SCROLL_START = 'scrollStart';
|
|
65
|
-
type HOOK_SCROLL = 'scroll';
|
|
66
|
-
type HOOK_SCROLL_END = 'scrollEnd';
|
|
67
|
-
type HOOK_NATIVE_SCROLL_START = 'nativeScrollStart';
|
|
68
|
-
type HOOK_NATIVE_SCROLL = 'nativeScroll';
|
|
69
|
-
type HOOK_NATIVE_SCROLL_END = 'nativeScrollEnd';
|
|
70
|
-
type HOOK_PROGRAMMATIC_SCROLL_START = 'programmaticScrollStart';
|
|
71
|
-
type HOOK_PROGRAMMATIC_SCROLL = 'programmaticScroll';
|
|
72
|
-
type HOOK_PROGRAMMATIC_SCROLL_END = 'programmaticScrollEnd';
|
|
73
|
-
type SliderPlugin = (slider: Slider) => void;
|
|
21
|
+
} | undefined;
|
|
74
22
|
|
|
75
|
-
export
|
|
23
|
+
export { OverflowSlider as default };
|
|
@@ -7,11 +7,12 @@ const DEFAULT_CLASS_NAMES = {
|
|
|
7
7
|
};
|
|
8
8
|
function DotsPlugin(args) {
|
|
9
9
|
return (slider) => {
|
|
10
|
-
var _a, _b;
|
|
10
|
+
var _a, _b, _c;
|
|
11
11
|
const options = {
|
|
12
|
+
type: (_a = args === null || args === void 0 ? void 0 : args.type) !== null && _a !== void 0 ? _a : 'slide',
|
|
12
13
|
texts: Object.assign(Object.assign({}, DEFAULT_TEXTS), (args === null || args === void 0 ? void 0 : args.texts) || []),
|
|
13
14
|
classNames: Object.assign(Object.assign({}, DEFAULT_CLASS_NAMES), (args === null || args === void 0 ? void 0 : args.classNames) || []),
|
|
14
|
-
container: (
|
|
15
|
+
container: (_b = args === null || args === void 0 ? void 0 : args.container) !== null && _b !== void 0 ? _b : null,
|
|
15
16
|
};
|
|
16
17
|
const dots = document.createElement('div');
|
|
17
18
|
dots.classList.add(options.classNames.dotsContainer);
|
|
@@ -20,18 +21,18 @@ function DotsPlugin(args) {
|
|
|
20
21
|
dots.setAttribute('data-has-content', slider.details.hasOverflow.toString());
|
|
21
22
|
dots.innerHTML = '';
|
|
22
23
|
const dotsList = document.createElement('ul');
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
24
|
+
const count = options.type === 'view' ? slider.details.amountOfPages : slider.details.slideCount;
|
|
25
|
+
const currentIndex = options.type === 'view' ? slider.details.currentPage : slider.activeSlideIdx;
|
|
26
|
+
if (count <= 1) {
|
|
26
27
|
return;
|
|
27
28
|
}
|
|
28
|
-
for (let i = 0; i <
|
|
29
|
+
for (let i = 0; i < count; i++) {
|
|
29
30
|
const dotListItem = document.createElement('li');
|
|
30
31
|
const dot = document.createElement('button');
|
|
31
32
|
dot.setAttribute('type', 'button');
|
|
32
33
|
dot.setAttribute('class', options.classNames.dotsItem);
|
|
33
|
-
dot.setAttribute('aria-label', options.texts.dotDescription.replace('%d', (i + 1).toString()).replace('%d',
|
|
34
|
-
dot.setAttribute('aria-pressed', (i ===
|
|
34
|
+
dot.setAttribute('aria-label', options.texts.dotDescription.replace('%d', (i + 1).toString()).replace('%d', count.toString()));
|
|
35
|
+
dot.setAttribute('aria-pressed', (i === currentIndex).toString());
|
|
35
36
|
dot.setAttribute('data-item', (i + 1).toString());
|
|
36
37
|
dotListItem.appendChild(dot);
|
|
37
38
|
dotsList.appendChild(dotListItem);
|
|
@@ -45,23 +46,23 @@ function DotsPlugin(args) {
|
|
|
45
46
|
}
|
|
46
47
|
const currentItem = parseInt((_a = currentItemItem.getAttribute('data-item')) !== null && _a !== void 0 ? _a : '1');
|
|
47
48
|
if (e.key === 'ArrowLeft') {
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
50
|
-
const matchingDot = dots.querySelector(`[data-item="${
|
|
49
|
+
const previousIndex = currentItem - 1;
|
|
50
|
+
if (previousIndex > 0) {
|
|
51
|
+
const matchingDot = dots.querySelector(`[data-item="${previousIndex}"]`);
|
|
51
52
|
if (matchingDot) {
|
|
52
53
|
matchingDot.focus();
|
|
53
54
|
}
|
|
54
|
-
activateDot(
|
|
55
|
+
activateDot(previousIndex);
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
if (e.key === 'ArrowRight') {
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
60
|
-
const matchingDot = dots.querySelector(`[data-item="${
|
|
59
|
+
const nextIndex = currentItem + 1;
|
|
60
|
+
if (nextIndex <= count) {
|
|
61
|
+
const matchingDot = dots.querySelector(`[data-item="${nextIndex}"]`);
|
|
61
62
|
if (matchingDot) {
|
|
62
63
|
matchingDot.focus();
|
|
63
64
|
}
|
|
64
|
-
activateDot(
|
|
65
|
+
activateDot(nextIndex);
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
});
|
|
@@ -75,19 +76,30 @@ function DotsPlugin(args) {
|
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
};
|
|
78
|
-
const activateDot = (
|
|
79
|
-
|
|
79
|
+
const activateDot = (index) => {
|
|
80
|
+
if (options.type === 'view') {
|
|
81
|
+
const targetPosition = slider.details.containerWidth * (index - 1);
|
|
82
|
+
const scrollLeft = slider.options.rtl ? -targetPosition : targetPosition;
|
|
83
|
+
slider.container.scrollTo({
|
|
84
|
+
left: scrollLeft,
|
|
85
|
+
behavior: slider.options.scrollBehavior
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
slider.moveToSlide(index - 1);
|
|
90
|
+
}
|
|
80
91
|
};
|
|
81
92
|
buildDots();
|
|
82
93
|
if (options.container) {
|
|
83
94
|
options.container.appendChild(dots);
|
|
84
95
|
}
|
|
85
96
|
else {
|
|
86
|
-
(
|
|
97
|
+
(_c = slider.container.parentNode) === null || _c === void 0 ? void 0 : _c.insertBefore(dots, slider.container.nextSibling);
|
|
87
98
|
}
|
|
88
99
|
slider.on('scrollEnd', buildDots);
|
|
89
100
|
slider.on('contentsChanged', buildDots);
|
|
90
101
|
slider.on('containerSizeChanged', buildDots);
|
|
102
|
+
slider.on('detailsChanged', buildDots);
|
|
91
103
|
};
|
|
92
104
|
}
|
|
93
105
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const t={dotDescription:"Page %d of %d"},e={dotsContainer:"overflow-slider__dots",dotsItem:"overflow-slider__dot-item"};function n(n){return
|
|
1
|
+
const t={dotDescription:"Page %d of %d"},e={dotsContainer:"overflow-slider__dots",dotsItem:"overflow-slider__dot-item"};function n(n){return i=>{var o,s,a;const r={type:null!==(o=null==n?void 0:n.type)&&void 0!==o?o:"slide",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!==(s=null==n?void 0:n.container)&&void 0!==s?s:null},l=document.createElement("div");l.classList.add(r.classNames.dotsContainer);let d=null;const c=()=>{l.setAttribute("data-has-content",i.details.hasOverflow.toString()),l.innerHTML="";const t=document.createElement("ul"),e="view"===r.type?i.details.amountOfPages:i.details.slideCount,n="view"===r.type?i.details.currentPage:i.activeSlideIdx;if(!(e<=1)){for(let i=0;i<e;i++){const o=document.createElement("li"),s=document.createElement("button");s.setAttribute("type","button"),s.setAttribute("class",r.classNames.dotsItem),s.setAttribute("aria-label",r.texts.dotDescription.replace("%d",(i+1).toString()).replace("%d",e.toString())),s.setAttribute("aria-pressed",(i===n).toString()),s.setAttribute("data-item",(i+1).toString()),o.appendChild(s),t.appendChild(o),s.addEventListener("click",()=>u(i+1)),s.addEventListener("focus",()=>d=i+1),s.addEventListener("keydown",t=>{var n;const i=l.querySelector('[aria-pressed="true"]');if(!i)return;const o=parseInt(null!==(n=i.getAttribute("data-item"))&&void 0!==n?n:"1");if("ArrowLeft"===t.key){const t=o-1;if(t>0){const e=l.querySelector(`[data-item="${t}"]`);e&&e.focus(),u(t)}}if("ArrowRight"===t.key){const t=o+1;if(t<=e){const e=l.querySelector(`[data-item="${t}"]`);e&&e.focus(),u(t)}}})}if(l.appendChild(t),d){const t=l.querySelector(`[data-item="${d}"]`);t&&t.focus()}}},u=t=>{if("view"===r.type){const e=i.details.containerWidth*(t-1),n=i.options.rtl?-e:e;i.container.scrollTo({left:n,behavior:i.options.scrollBehavior})}else i.moveToSlide(t-1)};c(),r.container?r.container.appendChild(l):null===(a=i.container.parentNode)||void 0===a||a.insertBefore(l,i.container.nextSibling),i.on("scrollEnd",c),i.on("contentsChanged",c),i.on("containerSizeChanged",c),i.on("detailsChanged",c)}}export{n as default};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DeepPartial, Slider } from '../core/index.
|
|
1
|
+
import { DeepPartial, Slider } from '../core/index.js';
|
|
2
2
|
|
|
3
3
|
type FullWidthOptions = {
|
|
4
|
-
targetWidth
|
|
4
|
+
targetWidth?: (slider: Slider) => number;
|
|
5
5
|
addMarginBefore: boolean;
|
|
6
6
|
addMarginAfter: boolean;
|
|
7
7
|
};
|
|
@@ -1,42 +1,59 @@
|
|
|
1
1
|
const DEFAULT_TARGET_WIDTH = (slider) => { var _a, _b; return (_b = (_a = slider.container.parentElement) === null || _a === void 0 ? void 0 : _a.offsetWidth) !== null && _b !== void 0 ? _b : window.innerWidth; };
|
|
2
2
|
function FullWidthPlugin(args) {
|
|
3
3
|
return (slider) => {
|
|
4
|
-
var _a, _b, _c;
|
|
4
|
+
var _a, _b, _c, _d;
|
|
5
5
|
const options = {
|
|
6
|
-
targetWidth: (_a = args === null || args === void 0 ? void 0 : args.targetWidth) !== null && _a !== void 0 ? _a :
|
|
6
|
+
targetWidth: (_a = args === null || args === void 0 ? void 0 : args.targetWidth) !== null && _a !== void 0 ? _a : undefined,
|
|
7
7
|
addMarginBefore: (_b = args === null || args === void 0 ? void 0 : args.addMarginBefore) !== null && _b !== void 0 ? _b : true,
|
|
8
8
|
addMarginAfter: (_c = args === null || args === void 0 ? void 0 : args.addMarginAfter) !== null && _c !== void 0 ? _c : true,
|
|
9
9
|
};
|
|
10
|
+
if (typeof slider.options.targetWidth !== 'function') {
|
|
11
|
+
slider.options.targetWidth = (_d = options.targetWidth) !== null && _d !== void 0 ? _d : DEFAULT_TARGET_WIDTH;
|
|
12
|
+
}
|
|
13
|
+
const resolveTargetWidth = () => {
|
|
14
|
+
var _a;
|
|
15
|
+
if (typeof slider.options.targetWidth === 'function') {
|
|
16
|
+
return slider.options.targetWidth;
|
|
17
|
+
}
|
|
18
|
+
return (_a = options.targetWidth) !== null && _a !== void 0 ? _a : DEFAULT_TARGET_WIDTH;
|
|
19
|
+
};
|
|
10
20
|
const update = () => {
|
|
11
21
|
const slides = slider.container.querySelectorAll(slider.options.slidesSelector);
|
|
12
22
|
if (!slides.length) {
|
|
13
23
|
return;
|
|
14
24
|
}
|
|
25
|
+
const targetWidthFn = resolveTargetWidth();
|
|
26
|
+
const rawMargin = (window.innerWidth - targetWidthFn(slider)) / 2;
|
|
27
|
+
const marginAmount = Math.max(0, Math.floor(rawMargin));
|
|
28
|
+
const marginValue = marginAmount ? `${marginAmount}px` : '';
|
|
29
|
+
slides.forEach((slide) => {
|
|
30
|
+
const element = slide;
|
|
31
|
+
element.style.marginInlineStart = '';
|
|
32
|
+
element.style.marginInlineEnd = '';
|
|
33
|
+
});
|
|
15
34
|
const firstSlide = slides[0];
|
|
16
35
|
const lastSlide = slides[slides.length - 1];
|
|
17
|
-
const marginAmount = Math.floor((window.innerWidth - getTargetWidth()) / 2);
|
|
18
36
|
if (options.addMarginBefore) {
|
|
19
|
-
firstSlide.style.marginInlineStart =
|
|
37
|
+
firstSlide.style.marginInlineStart = marginValue;
|
|
38
|
+
slider.container.style.setProperty('scroll-padding-inline-start', marginValue || '0px');
|
|
20
39
|
}
|
|
21
|
-
|
|
22
|
-
|
|
40
|
+
else {
|
|
41
|
+
slider.container.style.removeProperty('scroll-padding-inline-start');
|
|
23
42
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const getTargetWidth = () => {
|
|
28
|
-
if (typeof options.targetWidth === 'function') {
|
|
29
|
-
return options.targetWidth(slider);
|
|
43
|
+
if (options.addMarginAfter) {
|
|
44
|
+
lastSlide.style.marginInlineEnd = marginValue;
|
|
45
|
+
slider.container.style.setProperty('scroll-padding-inline-end', marginValue || '0px');
|
|
30
46
|
}
|
|
31
|
-
|
|
32
|
-
|
|
47
|
+
else {
|
|
48
|
+
slider.container.style.removeProperty('scroll-padding-inline-end');
|
|
33
49
|
}
|
|
34
|
-
|
|
50
|
+
slider.container.setAttribute('data-full-width-offset', `${marginAmount}`);
|
|
51
|
+
setCSS(targetWidthFn);
|
|
52
|
+
slider.emit('fullWidthPluginUpdate');
|
|
35
53
|
};
|
|
36
|
-
const setCSS = () => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
54
|
+
const setCSS = (targetWidthFn) => {
|
|
55
|
+
const width = targetWidthFn(slider);
|
|
56
|
+
slider.options.cssVariableContainer.style.setProperty('--slider-container-target-width', `${width}px`);
|
|
40
57
|
};
|
|
41
58
|
update();
|
|
42
59
|
slider.on('contentsChanged', update);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
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,d;const l={targetWidth:null!==(i=null==n?void 0:n.targetWidth)&&void 0!==i?i:void 0,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};"function"!=typeof e.options.targetWidth&&(e.options.targetWidth=null!==(d=l.targetWidth)&&void 0!==d?d:t);const a=()=>{const n=e.container.querySelectorAll(e.options.slidesSelector);if(!n.length)return;const i=(()=>{var n;return"function"==typeof e.options.targetWidth?e.options.targetWidth:null!==(n=l.targetWidth)&&void 0!==n?n:t})(),r=(window.innerWidth-i(e))/2,o=Math.max(0,Math.floor(r)),d=o?`${o}px`:"";n.forEach(t=>{const n=t;n.style.marginInlineStart="",n.style.marginInlineEnd=""});const a=n[0],c=n[n.length-1];l.addMarginBefore?(a.style.marginInlineStart=d,e.container.style.setProperty("scroll-padding-inline-start",d||"0px")):e.container.style.removeProperty("scroll-padding-inline-start"),l.addMarginAfter?(c.style.marginInlineEnd=d,e.container.style.setProperty("scroll-padding-inline-end",d||"0px")):e.container.style.removeProperty("scroll-padding-inline-end"),e.container.setAttribute("data-full-width-offset",`${o}`),s(i),e.emit("fullWidthPluginUpdate")},s=t=>{const n=t(e);e.options.cssVariableContainer.style.setProperty("--slider-container-target-width",`${n}px`)};a(),e.on("contentsChanged",a),e.on("containerSizeChanged",a),window.addEventListener("resize",a)}}export{n as default};
|