well-waterfall 1.0.20 → 1.0.21
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/dist/index.js +17 -17
- package/package.json +1 -1
- package/src/index.ts +8 -17
- package/src/lib/attributes.ts +0 -1
- package/src/lib/debug.ts +0 -14
- package/src/modules/breakpoints.ts +21 -21
- package/src/modules/controller.ts +5 -5
- package/src/modules/effect.ts +18 -18
- package/src/modules/general.ts +96 -92
- package/src/modules/hashhistory.ts +7 -7
- package/src/modules/input.ts +13 -13
- package/src/modules/layout.ts +3 -3
- package/src/modules/navigation.ts +7 -7
- package/src/modules/pagination.ts +18 -18
- package/src/modules/playback.ts +15 -15
- package/src/modules/scrollbar.ts +10 -10
- package/src/modules/thumbs.ts +10 -17
- package/src/modules/zoom.ts +8 -8
- package/src/util.ts +3 -28
|
@@ -17,11 +17,11 @@ import {
|
|
|
17
17
|
ATTR_PAGINATION_TYPE,
|
|
18
18
|
ATTR_PAGINATION_VERTICAL_CLASS,
|
|
19
19
|
} from "lib/attributes";
|
|
20
|
-
import { getUniqueClasses,
|
|
20
|
+
import { getUniqueClasses, parseBoolean, parseNumber, parseString } from "../util";
|
|
21
21
|
import { ATTR_WATERFALL_ELEMENT, EL_PAGINATION, EL_PAGINATION_BULLET, EL_PAGINATION_BULLET_ACTIVE } from "lib/elements";
|
|
22
22
|
|
|
23
23
|
export function paginationConfig(element: HTMLElement) {
|
|
24
|
-
const paginationType =
|
|
24
|
+
const paginationType = parseString(element, ATTR_PAGINATION_TYPE);
|
|
25
25
|
|
|
26
26
|
const paginationBullet = element.querySelector<HTMLElement>(`[${ATTR_WATERFALL_ELEMENT}=${EL_PAGINATION_BULLET}]`);
|
|
27
27
|
|
|
@@ -37,37 +37,37 @@ export function paginationConfig(element: HTMLElement) {
|
|
|
37
37
|
: "swiper-pagination-bullet-active",
|
|
38
38
|
bulletClass: paginationBullet?.getAttribute("class")?.trim() || "swiper-pagination-bullet",
|
|
39
39
|
bulletElement: paginationBullet?.tagName?.toLowerCase() || "span",
|
|
40
|
-
clickable:
|
|
41
|
-
clickableClass:
|
|
42
|
-
currentClass:
|
|
43
|
-
dynamicBullets:
|
|
44
|
-
dynamicMainBullets:
|
|
40
|
+
clickable: parseBoolean(element, ATTR_PAGINATION_CLICKABLE, false),
|
|
41
|
+
clickableClass: parseString(element, ATTR_PAGINATION_CLICKABLE_CLASS, "swiper-pagination-clickable"),
|
|
42
|
+
currentClass: parseString(element, ATTR_PAGINATION_CURRENT_CLASS, "swiper-pagination-current"),
|
|
43
|
+
dynamicBullets: parseString(element, ATTR_PAGINATION_DYNAMIC_BULLETS, "swiper-pagination-current"),
|
|
44
|
+
dynamicMainBullets: parseNumber(element, ATTR_PAGINATION_DYNAMIC_MAIN_BULLETS, 1),
|
|
45
45
|
el: paginationEl || null,
|
|
46
|
-
enabled:
|
|
47
|
-
hiddenClass:
|
|
48
|
-
hideOnClick:
|
|
49
|
-
horizontalClass:
|
|
50
|
-
lockClass:
|
|
51
|
-
modifierClass:
|
|
52
|
-
paginationDisabledClass:
|
|
46
|
+
enabled: parseBoolean(element, ATTR_PAGINATION_ENABLED),
|
|
47
|
+
hiddenClass: parseString(element, ATTR_PAGINATION_HIDDEN_CLASS, "swiper-pagination-hidden"),
|
|
48
|
+
hideOnClick: parseBoolean(element, ATTR_PAGINATION_HIDE_ON_CLICK, true),
|
|
49
|
+
horizontalClass: parseString(element, ATTR_PAGINATION_HORIZONTAL_CLASS, "swiper-pagination-horizontal"),
|
|
50
|
+
lockClass: parseString(element, ATTR_NAVIGATION_LOCK_CLASS, "swiper-pagination-lock"),
|
|
51
|
+
modifierClass: parseString(element, ATTR_PAGINATION_MODIFIER_CLASS, "swiper-pagination-"),
|
|
52
|
+
paginationDisabledClass: parseString(
|
|
53
53
|
element,
|
|
54
54
|
ATTR_PAGINATION_PAGINATION_DISABLED_CLASS,
|
|
55
55
|
"swiper-pagination-disabled",
|
|
56
56
|
),
|
|
57
|
-
progressbarFillClass:
|
|
57
|
+
progressbarFillClass: parseString(
|
|
58
58
|
element,
|
|
59
59
|
ATTR_PAGINATION_PROGRESSBAR_FILL_CLASS,
|
|
60
60
|
"swiper-pagination-progressbar-fill",
|
|
61
61
|
),
|
|
62
|
-
progressbarOpposite:
|
|
62
|
+
progressbarOpposite: parseString(
|
|
63
63
|
element,
|
|
64
64
|
ATTR_PAGINATION_PROGRESSBAR_OPPOSITE,
|
|
65
65
|
"swiper-pagination-progressbar-opposite",
|
|
66
66
|
),
|
|
67
67
|
renderBullet: customRenderBullet(),
|
|
68
|
-
totalClass:
|
|
68
|
+
totalClass: parseString(element, ATTR_PAGINATION_TOTAL_CLASS, "swiper-pagination-total"),
|
|
69
69
|
type: getPaginationType(),
|
|
70
|
-
verticalClass:
|
|
70
|
+
verticalClass: parseString(element, ATTR_PAGINATION_VERTICAL_CLASS, "swiper-pagination-vertical"),
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
function customRenderBullet() {
|
package/src/modules/playback.ts
CHANGED
|
@@ -15,31 +15,31 @@ import {
|
|
|
15
15
|
ATTR_SMOOTH_AUTOPLAY,
|
|
16
16
|
ATTR_STOP_ON_LAST_SLIDE,
|
|
17
17
|
} from "lib/attributes";
|
|
18
|
-
import {
|
|
18
|
+
import { parseBoolean, parseNumber } from "../util";
|
|
19
19
|
|
|
20
20
|
export function autoplayConfig(el: HTMLElement) {
|
|
21
|
-
const autoplayMode =
|
|
21
|
+
const autoplayMode = parseBoolean(el, ATTR_AUTOPLAY, false);
|
|
22
22
|
if (!autoplayMode) return null;
|
|
23
23
|
// Add CSS for Smooth Autoplay
|
|
24
24
|
$(`[${ATTR_SMOOTH_AUTOPLAY}='true']`).find(".swiper-wrapper").css("transition-timing-function", "linear");
|
|
25
25
|
return {
|
|
26
|
-
delay:
|
|
27
|
-
disableOnInteraction:
|
|
28
|
-
reverseDirection:
|
|
29
|
-
pauseOnMouseEnter:
|
|
30
|
-
stopOnLastSlide:
|
|
26
|
+
delay: parseNumber(el, ATTR_DELAY, 3000),
|
|
27
|
+
disableOnInteraction: parseBoolean(el, ATTR_DISABLE_ON_INTERACTION, false), // documentation says default is true, doesn't appear to be correct
|
|
28
|
+
reverseDirection: parseBoolean(el, ATTR_REVERSE_DIRECTION, false),
|
|
29
|
+
pauseOnMouseEnter: parseBoolean(el, ATTR_PAUSE_ON_MOUSE_ENTER, false),
|
|
30
|
+
stopOnLastSlide: parseBoolean(el, ATTR_STOP_ON_LAST_SLIDE, false),
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export function freeModeConfig(el: HTMLElement) {
|
|
35
35
|
return {
|
|
36
|
-
enabled:
|
|
37
|
-
minimumVelocity:
|
|
38
|
-
momentum:
|
|
39
|
-
momentumBounce:
|
|
40
|
-
momentumBounceRatio:
|
|
41
|
-
momentumRatio:
|
|
42
|
-
momentumVelocityRatio:
|
|
43
|
-
sticky:
|
|
36
|
+
enabled: parseBoolean(el, ATTR_FREE_MODE_ENABLED, false),
|
|
37
|
+
minimumVelocity: parseNumber(el, ATTR_FREE_MODE_MINIMUM_VELOCITY, 0.02),
|
|
38
|
+
momentum: parseBoolean(el, ATTR_FREE_MODE_MOMENTUM, true),
|
|
39
|
+
momentumBounce: parseBoolean(el, ATTR_FREE_MODE_MOMENTUM_BOUNCE, true),
|
|
40
|
+
momentumBounceRatio: parseNumber(el, ATTR_FREE_MODE_MOMENTUM_BOUNCE_RATIO, 1),
|
|
41
|
+
momentumRatio: parseNumber(el, ATTR_FREE_MODE_MOMENTUM_RATIO, 1),
|
|
42
|
+
momentumVelocityRatio: parseNumber(el, ATTR_FREE_MODE_MOMENTUM_VELOCITY_RATIO, 1),
|
|
43
|
+
sticky: parseBoolean(el, ATTR_FREE_MODE_STICKY, false),
|
|
44
44
|
};
|
|
45
45
|
}
|
package/src/modules/scrollbar.ts
CHANGED
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
ATTR_SCROLLBAR_SNAP_ON_RELEASE,
|
|
10
10
|
ATTR_SCROLLBAR_VERTICAL_CLASS,
|
|
11
11
|
} from "lib/attributes";
|
|
12
|
-
import { parseAttr } from "../util";
|
|
13
12
|
import { ATTR_WATERFALL_ELEMENT, EL_SCROLLBAR, EL_SCROLLBAR_DRAG } from "lib/elements";
|
|
13
|
+
import { parseBoolean, parseString } from "../util";
|
|
14
14
|
|
|
15
15
|
export function scrollbarConfig(element: HTMLElement) {
|
|
16
16
|
const scrollbar = element.querySelector<HTMLElement>(`[${ATTR_WATERFALL_ELEMENT}=${EL_SCROLLBAR}]`);
|
|
@@ -18,15 +18,15 @@ export function scrollbarConfig(element: HTMLElement) {
|
|
|
18
18
|
|
|
19
19
|
return {
|
|
20
20
|
dragClass: scrollbarDrag?.getAttribute("class") || "",
|
|
21
|
-
dragSize:
|
|
22
|
-
draggable:
|
|
21
|
+
dragSize: parseString(element, ATTR_SCROLLBAR_DRAG_SIZE, "auto"),
|
|
22
|
+
draggable: parseBoolean(element, ATTR_SCROLLBAR_DRAGGABLE, false),
|
|
23
23
|
el: scrollbar || null,
|
|
24
|
-
enabled:
|
|
25
|
-
hide:
|
|
26
|
-
horizontalClass:
|
|
27
|
-
lockClass:
|
|
28
|
-
scrollbarDisabledClass:
|
|
29
|
-
snapOnRelease:
|
|
30
|
-
verticalClass:
|
|
24
|
+
enabled: parseBoolean(element, ATTR_SCROLLBAR_ENABLED),
|
|
25
|
+
hide: parseBoolean(element, ATTR_SCROLLBAR_HIDE, true),
|
|
26
|
+
horizontalClass: parseString(element, ATTR_SCROLLBAR_HORIZONTAL_CLASS, "swiper-scrollbar-horizontal"),
|
|
27
|
+
lockClass: parseString(element, ATTR_SCROLLBAR_LOCK_CLASS, "swiper-scrollbar-lock"),
|
|
28
|
+
scrollbarDisabledClass: parseString(element, ATTR_SCROLLBAR_SCROLLBAR_DISABLED_CLASS, "swiper-scrollbar-disabled"),
|
|
29
|
+
snapOnRelease: parseBoolean(element, ATTR_SCROLLBAR_SNAP_ON_RELEASE, true), // NOTE doc says false but actually true
|
|
30
|
+
verticalClass: parseString(element, ATTR_SCROLLBAR_VERTICAL_CLASS, "swiper-scrollbar-vertical"),
|
|
31
31
|
};
|
|
32
32
|
}
|
package/src/modules/thumbs.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ThumbsOptions } from "swiper/types";
|
|
2
|
-
import {
|
|
2
|
+
import { parseBoolean, parseNumber, parseString } from "../util";
|
|
3
3
|
import { Waterfall } from "types/waterfall";
|
|
4
4
|
import {
|
|
5
5
|
ATTR_THUMBS,
|
|
@@ -9,13 +9,17 @@ import {
|
|
|
9
9
|
ATTR_THUMBS_SLIDE_THUMB_ACTIVE_CLASS,
|
|
10
10
|
} from "lib/attributes";
|
|
11
11
|
|
|
12
|
-
export function thumbsConfig(el: HTMLElement, swipers: Waterfall[]) {
|
|
13
|
-
const
|
|
14
|
-
if (!
|
|
12
|
+
export function thumbsConfig(el: HTMLElement, swipers: Waterfall[], debug: boolean) {
|
|
13
|
+
const thumbsName = parseString(el, ATTR_THUMBS, "");
|
|
14
|
+
if (!thumbsName || thumbsName === "") {
|
|
15
|
+
if (debug) console.log(`[Thumbs] No thumbs attribute found on element:`, el);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const waterfall = swipers.find((slider: Waterfall) => slider.name === thumbsName);
|
|
15
20
|
|
|
16
|
-
const waterfall = getThumbsSwiper(el, swipers);
|
|
17
21
|
if (!waterfall) {
|
|
18
|
-
console.warn(
|
|
22
|
+
if (debug) console.warn("A matching thumbs waterfall was not found for ", thumbsName);
|
|
19
23
|
return;
|
|
20
24
|
}
|
|
21
25
|
|
|
@@ -28,14 +32,3 @@ export function thumbsConfig(el: HTMLElement, swipers: Waterfall[]) {
|
|
|
28
32
|
};
|
|
29
33
|
return config;
|
|
30
34
|
}
|
|
31
|
-
|
|
32
|
-
function getThumbsSwiper(el: HTMLElement, sliders: Waterfall[]): Waterfall | null {
|
|
33
|
-
const sliderName = parseAttr(el, ATTR_THUMBS, null);
|
|
34
|
-
if (sliderName === null) return null;
|
|
35
|
-
|
|
36
|
-
const foundSlider = sliders.find((slider: Waterfall) => slider.name === sliderName);
|
|
37
|
-
|
|
38
|
-
if (foundSlider) return foundSlider;
|
|
39
|
-
console.log("A matching thumbs waterfall was not found for ", sliderName);
|
|
40
|
-
return null; // Return null if no match is found
|
|
41
|
-
}
|
package/src/modules/zoom.ts
CHANGED
|
@@ -7,16 +7,16 @@ import {
|
|
|
7
7
|
ATTR_ZOOM_TOGGLE,
|
|
8
8
|
ATTR_ZOOMED_SLIDE_CLASS,
|
|
9
9
|
} from "lib/attributes";
|
|
10
|
-
import {
|
|
10
|
+
import { parseBoolean, parseNumber, parseString } from "../util";
|
|
11
11
|
|
|
12
12
|
export function zoomConfig(el: HTMLElement) {
|
|
13
13
|
return {
|
|
14
|
-
containerClass:
|
|
15
|
-
limitToOriginalSize:
|
|
16
|
-
maxRatio:
|
|
17
|
-
minRatio:
|
|
18
|
-
panOnMouseMove:
|
|
19
|
-
toggle:
|
|
20
|
-
zoomedSlideClass:
|
|
14
|
+
containerClass: parseString(el, ATTR_ZOOM_CONTAINER_CLASS, "swiper-zoom-container"),
|
|
15
|
+
limitToOriginalSize: parseBoolean(el, ATTR_ZOOM_LIMIT_TO_ORIGINAL_SIZE, false),
|
|
16
|
+
maxRatio: parseNumber(el, ATTR_ZOOM_MAX_RATIO, 3),
|
|
17
|
+
minRatio: parseNumber(el, ATTR_ZOOM_MIN_RATIO, 1),
|
|
18
|
+
panOnMouseMove: parseBoolean(el, ATTR_ZOOM_PAN_ON_MOUSE_MOVE, false),
|
|
19
|
+
toggle: parseBoolean(el, ATTR_ZOOM_TOGGLE, true),
|
|
20
|
+
zoomedSlideClass: parseString(el, ATTR_ZOOMED_SLIDE_CLASS, "swiper-slide-zoomed"),
|
|
21
21
|
};
|
|
22
22
|
}
|
package/src/util.ts
CHANGED
|
@@ -18,14 +18,14 @@ export function getUniqueClasses(targetElement: HTMLElement, comparisonElement:
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// ✅ Parse attribute as string (ignoring default value)
|
|
21
|
-
export function parseString(el: HTMLElement, attrName: string, defaultValue
|
|
21
|
+
export function parseString(el: HTMLElement, attrName: string, defaultValue?: string): string | undefined {
|
|
22
22
|
const attrValue = el.getAttribute(attrName)?.trim();
|
|
23
23
|
if (!attrValue || attrValue === defaultValue) return undefined;
|
|
24
24
|
return attrValue;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// ✅ Parse attribute as number
|
|
28
|
-
export function parseNumber(el: HTMLElement, attrName: string, defaultValue
|
|
28
|
+
export function parseNumber(el: HTMLElement, attrName: string, defaultValue?: number): number | undefined {
|
|
29
29
|
const attrValue = el.getAttribute(attrName)?.trim();
|
|
30
30
|
if (!attrValue) return undefined;
|
|
31
31
|
|
|
@@ -36,7 +36,7 @@ export function parseNumber(el: HTMLElement, attrName: string, defaultValue: num
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// ✅ Parse attribute as boolean
|
|
39
|
-
export function parseBoolean(el: HTMLElement, attrName: string, defaultValue
|
|
39
|
+
export function parseBoolean(el: HTMLElement, attrName: string, defaultValue?: boolean): boolean | undefined {
|
|
40
40
|
const attrValue = el.getAttribute(attrName)?.trim()?.toLowerCase();
|
|
41
41
|
if (!attrValue) return undefined;
|
|
42
42
|
|
|
@@ -46,31 +46,6 @@ export function parseBoolean(el: HTMLElement, attrName: string, defaultValue: bo
|
|
|
46
46
|
return undefined;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
// ✅ Generic attribute parser
|
|
50
|
-
export function parseAttr(
|
|
51
|
-
el: HTMLElement,
|
|
52
|
-
attrName: string,
|
|
53
|
-
defaultValue: string | number | boolean | null,
|
|
54
|
-
): string | number | boolean | null {
|
|
55
|
-
const attrValue = el.getAttribute(attrName);
|
|
56
|
-
if (!attrValue) return null;
|
|
57
|
-
|
|
58
|
-
const trimmedInput = attrValue.trim();
|
|
59
|
-
|
|
60
|
-
// Number check
|
|
61
|
-
if (!isNaN(Number(trimmedInput))) {
|
|
62
|
-
const parsedNumber = parseFloat(trimmedInput);
|
|
63
|
-
return parsedNumber === defaultValue ? null : parsedNumber;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Boolean check
|
|
67
|
-
if (trimmedInput.toLowerCase() === "true") return defaultValue === true ? null : true;
|
|
68
|
-
if (trimmedInput.toLowerCase() === "false") return defaultValue === false ? null : false;
|
|
69
|
-
|
|
70
|
-
// String match check
|
|
71
|
-
return trimmedInput === String(defaultValue) ? null : trimmedInput;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
49
|
function isHTMLElement(value: unknown): value is HTMLElement {
|
|
75
50
|
return typeof HTMLElement !== "undefined" && value instanceof HTMLElement;
|
|
76
51
|
}
|