@inizioevoke/astro-core 1.3.5 → 1.3.6

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": "@inizioevoke/astro-core",
3
- "version": "1.3.5",
3
+ "version": "1.3.6",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -5,8 +5,13 @@ export interface IScrollContainer {
5
5
  refresh(): void;
6
6
  }
7
7
 
8
+ interface ScrollbarSettings {
9
+ trackVisible?: boolean;
10
+ thumbHeight?: number;
11
+ }
12
+
8
13
  class ScrollContainer implements IScrollContainer {
9
- #container: HTMLElement;
14
+ #container: HTMLElement & { evoScrollContainer: ScrollContainer };
10
15
  #content: HTMLElement;
11
16
  #track: HTMLElement;
12
17
  #thumb: HTMLElement;
@@ -14,12 +19,14 @@ class ScrollContainer implements IScrollContainer {
14
19
  #startY: number;
15
20
  #startScrollTop: number;
16
21
 
22
+ #scrollbarSettings: ScrollbarSettings = {};
17
23
  #mouseupHandler: any = undefined;
18
24
  #mousemoveHandler: any = undefined;
19
25
 
20
26
  constructor(container: HTMLElement) {
21
27
  // const _this = this;
22
- this.#container = container;
28
+ this.#container = container as HTMLElement & { evoScrollContainer: ScrollContainer };
29
+ this.#container.evoScrollContainer = this;
23
30
  this.#content = container.querySelector('.evo-scroll-content') as HTMLElement;
24
31
  this.#track = container.querySelector('.evo-scroll-track') as HTMLElement;
25
32
  this.#thumb = container.querySelector('.evo-scroll-thumb') as HTMLElement;
@@ -78,6 +85,13 @@ class ScrollContainer implements IScrollContainer {
78
85
  }
79
86
  }
80
87
 
88
+ configureScrollbar({ trackVisible, thumbHeight }: ScrollbarSettings) {
89
+ this.#scrollbarSettings = { trackVisible, thumbHeight };
90
+ this.refresh();
91
+ }
92
+ resetScrollbar() {
93
+ this.configureScrollbar({});
94
+ }
81
95
  refresh() {
82
96
  this.#updateThumbSize();
83
97
  }
@@ -86,9 +100,18 @@ class ScrollContainer implements IScrollContainer {
86
100
  const scrollHeight = this.#content.scrollHeight - getPaddingY(this.#content);
87
101
  const containerHeight = this.#container.clientHeight - getPaddingY(this.#container);
88
102
  const visibleRatio = containerHeight / scrollHeight;
89
- const thumbHeight = this.#container.getAttribute('data-evo-scroll-thumb-height') ? parseInt(this.#container.getAttribute('data-evo-scroll-thumb-height') as string, 10) : visibleRatio * containerHeight;
90
- this.#thumb.style.height = `${thumbHeight > 20 ? thumbHeight : 20}px`;
91
- this.#track.style.display = this.#container.classList.contains('evo-scroll-track-visible') ? 'block' : visibleRatio < 1 ? 'block' : 'none';
103
+ const thumbHeight = visibleRatio * containerHeight;
104
+ if (this.#scrollbarSettings.thumbHeight != undefined) {
105
+ this.#thumb.style.height = `${this.#scrollbarSettings.thumbHeight < 0 ? 0 : this.#scrollbarSettings.thumbHeight > containerHeight ? containerHeight : this.#scrollbarSettings.thumbHeight}px`;
106
+ } else {
107
+ this.#thumb.style.height = `${thumbHeight > 20 ? thumbHeight : 20}px`;
108
+ }
109
+ if (this.#scrollbarSettings.trackVisible !== undefined) {
110
+ this.#track.style.display = this.#scrollbarSettings.trackVisible === true ? 'block' : 'none';
111
+ } else {
112
+ this.#track.style.display = visibleRatio < 1 ? 'block' : 'none';
113
+ }
114
+
92
115
  }
93
116
 
94
117
  #thumbMouseDown(e: MouseEvent) {