@inizioevoke/astro-core 1.3.0 → 1.3.2

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.0",
3
+ "version": "1.3.2",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -4,6 +4,7 @@
4
4
  --evo-scroll-container-track-width: 8px;
5
5
  --evo-scroll-container-track-top: 0px;
6
6
  --evo-scroll-container-track-bottom: 0px;
7
+ --evo-scroll-container-track-right: 0px;
7
8
  --evo-scroll-container-track-color: #dddddd;
8
9
  --evo-scroll-container-thumb-color: #666666;
9
10
  --evo-scroll-container-thumb-border-width: 0px;
@@ -42,7 +43,7 @@
42
43
  .evo-scroll-track {
43
44
  position: absolute;
44
45
  top: var(--evo-scroll-container-track-top);
45
- right: 0px;
46
+ right: var(--evo-scroll-container-track-right);
46
47
  width: var(--evo-scroll-container-track-width);
47
48
  height: calc(100% - var(--evo-scroll-container-track-top) - var(--evo-scroll-container-track-bottom));
48
49
  background: var(--evo-scroll-container-track-color);
@@ -1,4 +1,10 @@
1
- export class ScrollContainer {
1
+ export interface IScrollContainer {
2
+ scroll(args?: { left?: number | string, top?: number | string, behavior?: 'auto' | 'instant' | 'smooth' }): void;
3
+ getScroll(): { left: number, top: number }
4
+ resize(args: { height?: number }): void;
5
+ refresh(): void;
6
+ }
7
+ export class ScrollContainer implements IScrollContainer {
2
8
  #container: HTMLElement;
3
9
  #content: HTMLElement;
4
10
  #track: HTMLElement;
@@ -6,12 +12,11 @@ export class ScrollContainer {
6
12
  #isDragging: boolean;
7
13
  #startY: number;
8
14
  #startScrollTop: number;
9
- // #enabled: boolean;
10
15
 
11
- #mouseupHandler: any = undefined; // [] = [];
12
- #mousemoveHandler: any = undefined; // [] = [];
16
+ #mouseupHandler: any = undefined;
17
+ #mousemoveHandler: any = undefined;
13
18
 
14
- constructor(container: HTMLElement) { // , { enabled }: { enabled?: boolean } = {}) {
19
+ constructor(container: HTMLElement) {
15
20
  const _this = this;
16
21
  this.#container = container;
17
22
  this.#content = container.querySelector('.evo-scroll-content') as HTMLElement;
@@ -35,13 +40,6 @@ export class ScrollContainer {
35
40
  }, { passive: true });
36
41
  }
37
42
 
38
- // enable(flag?: boolean) {
39
- // this.#enabled = flag ?? true;
40
- // }
41
- // get isEnabled() {
42
- // return this.#enabled === true;
43
- // }
44
-
45
43
  scroll({ left, top, behavior = 'auto' }: { left?: number | string, top?: number | string, behavior?: 'auto' | 'instant' | 'smooth' } = {}) {
46
44
  const current = this.getScroll();
47
45
  if (typeof left == 'string') {
@@ -103,11 +101,11 @@ export class ScrollContainer {
103
101
  }
104
102
 
105
103
  #thumbMouseDown(e: MouseEvent) {
106
- this.#mouseupHandler = this.#mouseDetach.bind(this); // .push(this.#mouseDetach.bind(this));
107
- this.#mousemoveHandler = this.#thumbMouseMove.bind(this); // .push(this.#thumbMouseMove.bind(this));
108
- document.addEventListener('mouseup', this.#mouseupHandler, { passive: true }); // this.#mouseupHandler[this.#mouseupHandler.length - 1]);
109
- document.addEventListener('dragend', this.#mouseupHandler, { passive: true }); // this.#mouseupHandler[this.#mouseupHandler.length - 1]);
110
- document.addEventListener('mousemove', this.#mousemoveHandler, { passive: true }); // this.#mousemoveHandler[this.#mousemoveHandler.length - 1]);
104
+ this.#mouseupHandler = this.#mouseDetach.bind(this);
105
+ this.#mousemoveHandler = this.#thumbMouseMove.bind(this);
106
+ document.addEventListener('mouseup', this.#mouseupHandler, { passive: true });
107
+ document.addEventListener('dragend', this.#mouseupHandler, { passive: true });
108
+ document.addEventListener('mousemove', this.#mousemoveHandler, { passive: true });
111
109
  this.#isDragging = true;
112
110
  this.#startY = e.clientY;
113
111
  this.#startScrollTop = this.#content.scrollTop;
@@ -115,7 +113,6 @@ export class ScrollContainer {
115
113
  }
116
114
 
117
115
  #thumbMouseMove(e: MouseEvent) {
118
- // console.log(performance.now());
119
116
  if (this.#isDragging) {
120
117
  const deltaY = e.clientY - this.#startY;
121
118
  const scrollRatio =
@@ -127,26 +124,12 @@ export class ScrollContainer {
127
124
  }
128
125
  }
129
126
 
130
- // #thumbMouseUp(e: MouseEvent) {
131
- // this.#isDragging = false;
132
- // this.#thumb.style.cursor = 'grab';
133
- // }
134
-
135
127
  #mouseDetach() {
136
128
  this.#isDragging = false;
137
129
  this.#thumb.style.cursor = 'grab';
138
130
  document.removeEventListener('mouseup', this.#mouseupHandler);
139
131
  document.removeEventListener('dragend', this.#mouseupHandler);
140
132
  document.removeEventListener('mousemove', this.#mousemoveHandler);
141
- // for (const m of this.#mouseupHandler) {
142
- // document.removeEventListener('mouseup', m);
143
- // document.removeEventListener('dragend', m);
144
- // }
145
- // for (const m of this.#mousemoveHandler) {
146
- // document.removeEventListener('mousemove', m);
147
- // }
148
- // this.#mouseupHandler = [];
149
- // this.#mousemoveHandler = [];
150
133
  }
151
134
 
152
135
  #scrollContent() {
@@ -156,7 +139,6 @@ export class ScrollContainer {
156
139
  const top = scrollRatio * (this.#track.clientHeight - this.#thumb.clientHeight);
157
140
  this.#thumb.style.top = `${top}px`;
158
141
  }
159
-
160
142
  }
161
143
 
162
144
  export function resize(scrollContainer: string | HTMLElement | ScrollContainer, { height }: { height?: number }) {
@@ -198,7 +180,7 @@ export function scroll(scrollContainer: string | HTMLElement | ScrollContainer,
198
180
  }
199
181
  }
200
182
 
201
- export function getScrollContainer(selector: string | HTMLElement | ScrollContainer): ScrollContainer | undefined {
183
+ export function getScrollContainer(selector: string | HTMLElement | ScrollContainer): IScrollContainer | undefined {
202
184
  if (selector instanceof ScrollContainer) {
203
185
  return selector;
204
186
  }
@@ -227,7 +209,7 @@ const intersectionObserver = new IntersectionObserver((entries) => {
227
209
  );
228
210
 
229
211
  const mutationObserver = new MutationObserver((mutations) => {
230
- const containers = new Set<ScrollContainer>();
212
+ const containers = new Set<IScrollContainer>();
231
213
  mutations.forEach((mutation) => {
232
214
  const sc = getScrollContainer(mutation.target as HTMLElement);
233
215
  if (sc) {