@madj2k/fe-frontend-kit 2.0.35 → 2.0.36

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madj2k/fe-frontend-kit",
3
- "version": "2.0.35",
3
+ "version": "2.0.36",
4
4
  "description": "Shared frontend utilities, menus and mixins for projects",
5
5
  "main": "index.js",
6
6
  "style": "index.scss",
@@ -6,6 +6,15 @@
6
6
  * 2. Smooth anchor scrolling with optional offset
7
7
  * 3. Automatic scrolling when collapsible elements (like Bootstrap .collapse) open
8
8
  * 4. Appear-on-scroll animations for elements
9
+ * 5. Wrapper-based smooth scrolling with easing (BETA-VERSION)
10
+ *
11
+ * New in 2.0.4:
12
+ * - Support for wrapper-based smooth scrolling (config.smoothScroll)
13
+ * - Nested config normalization for flat CMS field names
14
+ * - Improved config merging with `enabled` toggles per feature
15
+ * - Collapse scroll behavior can now be selectively disabled
16
+ * - Configurable offset via selector for anchor scroll
17
+ * - Script-controlled blocking of scroll direction classes during auto-scrolling
9
18
  *
10
19
  * The class is fully configurable via options and is designed to be used in CMS contexts
11
20
  * where elements can be added, removed or re-ordered dynamically.
@@ -38,6 +47,12 @@
38
47
  * timeout: 500,
39
48
  * threshold: 25
40
49
  * },
50
+ * smoothScroll: {
51
+ * enabled: true,
52
+ * wrapperClass: '.js-smooth-scroll-wrapper',
53
+ * contentClass: '.js-smooth-scroll-content',
54
+ * easing: 0.075
55
+ * },
41
56
  * debug: false
42
57
  * });
43
58
  *
@@ -57,22 +72,20 @@
57
72
  * </div>
58
73
  *
59
74
  * @example
60
- * // Suggested SCSS for appear on scroll:
61
- * .js-appear-on-scroll {
62
- * opacity: 0;
63
- * transition: opacity 0.5s ease-out, transform 0.5s ease-out;
64
- * transform: translateY(1rem);
65
- *
66
- * &[data-appear-on-scroll="0"] {
67
- * opacity: 1;
68
- * transform: translateY(0);
69
- * }
70
- * }
75
+ * // Example HTML for smooth scroll wrapper:
76
+ * <div class="js-smooth-scroll-wrapper">
77
+ * <div class="js-smooth-scroll-content">
78
+ * <section>Section 1</section>
79
+ * <section>Section 2</section>
80
+ * <section>Section 3</section>
81
+ * </div>
82
+ * </div>
71
83
  */
72
84
 
73
85
  class Madj2kScrolling {
74
86
  config = {
75
87
  anchorScrolling: {
88
+ enabled: true,
76
89
  selector: ['a[href^="#"]', 'a[href*="#"]'],
77
90
  offsetSelector: null,
78
91
  disableSelector: '.js-no-scroll',
@@ -83,10 +96,20 @@ class Madj2kScrolling {
83
96
  threshold: 40
84
97
  },
85
98
  appearOnScroll: {
99
+ enabled: true,
86
100
  selector: ['.js-appear-on-scroll'],
87
101
  timeout: 500,
88
102
  threshold: 25
89
103
  },
104
+ scrollClasses: {
105
+ enabled: true,
106
+ },
107
+ smoothScroll: {
108
+ enabled: false,
109
+ easing: 0.075,
110
+ wrapperClass: '.js-smooth-scroll-wrapper',
111
+ contentClass: '.js-smooth-scroll-content'
112
+ },
90
113
  debug: false
91
114
  };
92
115
 
@@ -100,6 +123,8 @@ class Madj2kScrolling {
100
123
  // backwards compatibility
101
124
  this._normalizeNestedConfig(config, 'anchorScrolling', 'anchorScrolling');
102
125
  this._normalizeNestedConfig(config, 'appearOnScroll', 'appearOnScroll');
126
+ this._normalizeNestedConfig(config, 'scrollClasses', 'scrollClasses');
127
+ this._normalizeNestedConfig(config, 'smoothScroll', 'smoothScroll');
103
128
 
104
129
  this.config = {
105
130
  ...this.config,
@@ -111,6 +136,14 @@ class Madj2kScrolling {
111
136
  appearOnScroll: {
112
137
  ...this.config.appearOnScroll,
113
138
  ...config.appearOnScroll
139
+ },
140
+ scrollClasses: {
141
+ ...this.config.scrollClasses,
142
+ ...config.scrollClasses
143
+ },
144
+ smoothScroll: {
145
+ ...this.config.smoothScroll,
146
+ ...config.smoothScroll
114
147
  }
115
148
  };
116
149
 
@@ -119,9 +152,18 @@ class Madj2kScrolling {
119
152
 
120
153
  this._log('Initialized with config:', this.config);
121
154
 
122
- this.initScrollClassesForBody();
123
- this.initAnchorScrolling();
124
- this.initAppearOnScroll();
155
+ if (this.config.anchorScrolling.enabled) {
156
+ this.initAnchorScrolling();
157
+ }
158
+ if (this.config.appearOnScroll.enabled) {
159
+ this.initAppearOnScroll();
160
+ }
161
+ if (this.config.scrollClasses.enabled) {
162
+ this.initScrollClassesForBody();
163
+ }
164
+ if (this.config.smoothScroll.enabled) {
165
+ this.initSmoothScroll();
166
+ }
125
167
  }
126
168
 
127
169
  /**
@@ -319,6 +361,57 @@ class Madj2kScrolling {
319
361
  window.addEventListener('scroll', updateOnScroll);
320
362
  }
321
363
 
364
+ /**
365
+ * Initializes wrapper-based smoothScroll scrolling
366
+ */
367
+ initSmoothScroll() {
368
+ const wrapper = document.querySelector(this.config.smoothScroll.wrapperClass);
369
+ const content = document.querySelector(this.config.smoothScroll.contentClass);
370
+
371
+ if (!wrapper || !content) {
372
+ this._log('Smooth Scroll wrapper or content element missing.');
373
+ return;
374
+ }
375
+
376
+ const body = document.body;
377
+ const html = document.documentElement;
378
+
379
+ const height = content.offsetHeight;
380
+ body.style.height = `${height}px`;
381
+
382
+ this._smoothScroll = {
383
+ wrapper,
384
+ content,
385
+ current: 0,
386
+ target: 0,
387
+ ease: this.config.smoothScroll.easing
388
+ };
389
+
390
+ window.addEventListener('scroll', () => {
391
+ this._smoothScroll.target = window.scrollY;
392
+ });
393
+
394
+ const animate = () => {
395
+ this._smoothScroll.current += (this._smoothScroll.target - this._smoothScroll.current) * this._smoothScroll.ease;
396
+ this._smoothScroll.wrapper.style.transform = `translateY(-${this._smoothScroll.current}px)`;
397
+ requestAnimationFrame(animate);
398
+ };
399
+
400
+ requestAnimationFrame(animate);
401
+ this._log('Smooth Scroll Scroll activated');
402
+ }
403
+
404
+ /**
405
+ * Sets the target scroll position for smoothScroll-based scrolling
406
+ * @param {Number} position - The vertical scroll target in px
407
+ * @private
408
+ */
409
+ _setSmoothScrollTarget(position) {
410
+ if (this._smoothScroll) {
411
+ this._smoothScroll.target = position;
412
+ }
413
+ }
414
+
322
415
  /**
323
416
  * Debug logging helper
324
417
  * @private
@@ -8,3 +8,11 @@
8
8
  transform: translateY(0);
9
9
  }
10
10
  }
11
+
12
+ .js-smooth-scroll-wrapper {
13
+ position: fixed;
14
+ top: 0;
15
+ left: 0;
16
+ width: 100%;
17
+ will-change: transform;
18
+ }