well-waterfall 1.2.7 → 1.2.9

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/util.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Waterfall } from 'types/waterfall';
3
3
  export declare function printDebug(debug: boolean, str: string, el: any): void;
4
4
  export declare function getUniqueClasses(targetElement: HTMLElement, comparisonElement: HTMLElement): string;
5
5
  export declare function parseString(el: HTMLElement, attrName: string, defaultValue?: string): string | undefined;
6
+ export declare function parseSlidesPerView(el: HTMLElement, attrName: string, defaultValue?: number): number | "auto" | undefined;
6
7
  export declare function parseAny(el: HTMLElement, attrName: string, defaultValue?: any): any | undefined;
7
8
  export declare function parseNumber(el: HTMLElement, attrName: string, defaultValue?: number): number | undefined;
8
9
  export declare function parseBoolean(el: HTMLElement, attrName: string, defaultValue?: boolean): boolean | undefined;
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "well-waterfall",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
4
4
  "description": "Create Swipers in Webflow with attributes",
5
- "main": "dist/index.umd.js",
6
- "module": "dist/index.es.js",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
7
8
  "types": "dist/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
11
  "types": "./dist/index.d.ts",
11
- "import": "./dist/index.es.js",
12
- "require": "./dist/index.umd.js"
12
+ "import": "./dist/index.js"
13
13
  }
14
14
  },
15
15
  "scripts": {
package/src/index.ts CHANGED
@@ -49,15 +49,26 @@ function initAll(selector: string, startIndex: number): number {
49
49
 
50
50
  let indexCounter = 0;
51
51
 
52
- // Initialize all other sliders
53
- document.querySelectorAll(`[${ATTR_WATERFALL}]`).forEach((el) => {
54
- if (el.hasAttribute(ATTR_THUMBS) || el.hasAttribute(ATTR_CONTROLLER)) return;
55
- initConfig(el as HTMLElement, indexCounter++);
56
- });
52
+ document.addEventListener("DOMContentLoaded", () => {
53
+ // Initialize all other sliders
54
+ document.querySelectorAll(`[${ATTR_WATERFALL}]`).forEach((el) => {
55
+ if (el.hasAttribute(ATTR_THUMBS) || el.hasAttribute(ATTR_CONTROLLER)) return;
56
+ initConfig(el as HTMLElement, indexCounter++);
57
+ });
58
+
59
+ // Initialize Controller Sliders last
60
+ indexCounter = initAll(`[${ATTR_WATERFALL}][${ATTR_THUMBS}]`, indexCounter);
61
+ indexCounter = initAll(`[${ATTR_WATERFALL}][${ATTR_CONTROLLER}]`, indexCounter);
57
62
 
58
- // Initialize Controller Sliders last
59
- indexCounter = initAll(`[${ATTR_WATERFALL}][${ATTR_THUMBS}]`, indexCounter);
60
- indexCounter = initAll(`[${ATTR_WATERFALL}][${ATTR_CONTROLLER}]`, indexCounter);
63
+ // MANIPULATION
64
+ manipulateSlides();
65
+
66
+ // SLIDE COUNT
67
+ initSlideCount();
68
+
69
+ // ARIA ROLE FIX FOR WEBFLOW CMS LIST
70
+ fixWebflowCMSListARIARole();
71
+ });
61
72
 
62
73
  // Config
63
74
  function initConfig(el: HTMLElement, index: number) {
@@ -111,12 +122,3 @@ function initConfig(el: HTMLElement, index: number) {
111
122
  waterfalls.push({ name, swiper });
112
123
  }
113
124
  }
114
-
115
- // MANIPULATION
116
- manipulateSlides();
117
-
118
- // SLIDE COUNT
119
- initSlideCount();
120
-
121
- // ARIA ROLE FIX FOR WEBFLOW CMS LIST
122
- fixWebflowCMSListARIARole();
@@ -15,7 +15,7 @@ import {
15
15
  ATTR_SPACE_BETWEEN,
16
16
  ATTR_WIDTH,
17
17
  } from "lib/attributes";
18
- import { parseAny, parseBoolean, parseNumber, parseString } from "../util";
18
+ import { parseAny, parseBoolean, parseNumber, parseSlidesPerView, parseString } from "../util";
19
19
  import { SwiperOptions } from "swiper/types";
20
20
 
21
21
  export function layoutConfig(config: SwiperOptions, el: HTMLElement) {
@@ -33,7 +33,7 @@ export function layoutConfig(config: SwiperOptions, el: HTMLElement) {
33
33
  config.slidesPerGroup = parseNumber(el, ATTR_SLIDES_PER_GROUP, 1);
34
34
  config.slidesPerGroupAuto = parseBoolean(el, ATTR_SLIDES_PER_GROUP_AUTO, false);
35
35
  config.slidesPerGroupSkip = parseNumber(el, ATTR_SLIDES_PER_GROUP_SKIP, 0);
36
- config.slidesPerView = parseNumber(el, ATTR_SLIDES_PER_VIEW, 1);
36
+ config.slidesPerView = parseSlidesPerView(el, ATTR_SLIDES_PER_VIEW, 1);
37
37
  config.spaceBetween = parseNumber(el, ATTR_SPACE_BETWEEN, 0);
38
38
  config.width = parseNumber(el, ATTR_WIDTH);
39
39
  }
package/src/util.ts CHANGED
@@ -24,6 +24,22 @@ export function parseString(el: HTMLElement, attrName: string, defaultValue?: st
24
24
  return attrValue;
25
25
  }
26
26
 
27
+ export function parseSlidesPerView(
28
+ el: HTMLElement,
29
+ attrName: string,
30
+ defaultValue?: number,
31
+ ): number | "auto" | undefined {
32
+ const attrValue = el.getAttribute(attrName)?.trim();
33
+ if (!attrValue) return undefined;
34
+
35
+ if (attrValue.toLowerCase() === "auto") return "auto";
36
+
37
+ const parsedValue = Number(attrValue);
38
+ const validAndUnique = isNaN(parsedValue) || parsedValue === defaultValue;
39
+ if (validAndUnique) return undefined;
40
+ return parsedValue;
41
+ }
42
+
27
43
  export function parseAny(el: HTMLElement, attrName: string, defaultValue?: any): any | undefined {
28
44
  const attrValue = el.getAttribute(attrName)?.trim();
29
45
  if (!attrValue || attrValue === defaultValue) return undefined;
package/vite.config.ts CHANGED
@@ -15,8 +15,8 @@ export default defineConfig({
15
15
  lib: {
16
16
  entry: resolve(__dirname, 'src/index.ts'),
17
17
  name: 'Waterfall',
18
- formats: ['es', 'umd'],
19
- fileName: (format) => `index.${format}.js`
18
+ formats: ['es'],
19
+ fileName: () => `index.js`
20
20
  },
21
21
  outDir: 'dist',
22
22
  sourcemap: true,