@inizioevoke/astro-core 1.3.1 → 1.3.3

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.1",
3
+ "version": "1.3.3",
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);
@@ -4,7 +4,8 @@ export interface IScrollContainer {
4
4
  resize(args: { height?: number }): void;
5
5
  refresh(): void;
6
6
  }
7
- export class ScrollContainer implements IScrollContainer {
7
+
8
+ class ScrollContainer implements IScrollContainer {
8
9
  #container: HTMLElement;
9
10
  #content: HTMLElement;
10
11
  #track: HTMLElement;
@@ -17,7 +18,7 @@ export class ScrollContainer implements IScrollContainer {
17
18
  #mousemoveHandler: any = undefined;
18
19
 
19
20
  constructor(container: HTMLElement) {
20
- const _this = this;
21
+ // const _this = this;
21
22
  this.#container = container;
22
23
  this.#content = container.querySelector('.evo-scroll-content') as HTMLElement;
23
24
  this.#track = container.querySelector('.evo-scroll-track') as HTMLElement;
@@ -25,19 +26,9 @@ export class ScrollContainer implements IScrollContainer {
25
26
  this.#isDragging = false;
26
27
  this.#startY = 0;
27
28
  this.#startScrollTop = 0;
28
- // this.#enabled = enabled ?? true;
29
-
30
- this.#thumb.addEventListener('mousedown', (e) => {
31
- _this.#thumbMouseDown(e);
32
- }, { passive: true });
33
-
34
- // this.#thumb.addEventListener('mouseup', (e) => {
35
- // _this.#thumbMouseUp(e);
36
- // }, { passive: true });
37
29
 
38
- this.#content.addEventListener('scroll', () => {
39
- _this.#scrollContent();
40
- }, { passive: true });
30
+ this.#thumb.addEventListener('mousedown', this.#thumbMouseDown.bind(this), { passive: true });
31
+ this.#content.addEventListener('scroll', this.#scrollContent.bind(this), { passive: true });
41
32
  }
42
33
 
43
34
  scroll({ left, top, behavior = 'auto' }: { left?: number | string, top?: number | string, behavior?: 'auto' | 'instant' | 'smooth' } = {}) {
@@ -113,6 +104,7 @@ export class ScrollContainer implements IScrollContainer {
113
104
  }
114
105
 
115
106
  #thumbMouseMove(e: MouseEvent) {
107
+ // console.log(performance.now());
116
108
  if (this.#isDragging) {
117
109
  const deltaY = e.clientY - this.#startY;
118
110
  const scrollRatio =
@@ -141,30 +133,30 @@ export class ScrollContainer implements IScrollContainer {
141
133
  }
142
134
  }
143
135
 
144
- export function resize(scrollContainer: string | HTMLElement | ScrollContainer, { height }: { height?: number }) {
136
+ export function resize(selector: string | HTMLElement | ScrollContainer, { height }: { height?: number }) {
145
137
  if (typeof height == 'number') {
146
- const sc = getScrollContainer(scrollContainer);
138
+ const sc = getScrollContainer(selector);
147
139
  if (sc) {
148
140
  sc.resize({ height })
149
141
  }
150
142
  }
151
143
  }
152
144
 
153
- export function refresh(scrollContainer?: string | HTMLElement | ScrollContainer) {
154
- if (scrollContainer) {
155
- const sc = getScrollContainer(scrollContainer);
145
+ export function refresh(selector?: string | HTMLElement | ScrollContainer) {
146
+ if (selector) {
147
+ const sc = getScrollContainer(selector);
156
148
  if (sc) {
157
149
  sc.refresh()
158
150
  }
159
151
  } else {
160
- [...scrollContainers.values()].forEach((scrollContainer) => {
161
- scrollContainer.refresh();
152
+ [...scrollContainers.values()].forEach((selector) => {
153
+ selector.refresh();
162
154
  });
163
155
  }
164
156
  }
165
157
 
166
- export function getScroll(scrollContainer: string | HTMLElement | ScrollContainer): { left: number, top: number } | undefined {
167
- const sc = getScrollContainer(scrollContainer);
158
+ export function getScroll(selector: string | HTMLElement | ScrollContainer): { left: number, top: number } | undefined {
159
+ const sc = getScrollContainer(selector);
168
160
  if (sc) {
169
161
  return sc.getScroll();
170
162
  } else {
@@ -172,8 +164,8 @@ export function getScroll(scrollContainer: string | HTMLElement | ScrollContaine
172
164
  }
173
165
  }
174
166
 
175
- export function scroll(scrollContainer: string | HTMLElement | ScrollContainer, { left, top, behavior = 'auto' }: { left?: number, top?: number, behavior?: 'auto' | 'instant' | 'smooth' } = {}) {
176
- const sc = getScrollContainer(scrollContainer);
167
+ export function scroll(selector: string | HTMLElement | ScrollContainer, { left, top, behavior = 'auto' }: { left?: number, top?: number, behavior?: 'auto' | 'instant' | 'smooth' } = {}) {
168
+ const sc = getScrollContainer(selector);
177
169
  if (sc) {
178
170
  const current = sc.getScroll();
179
171
  sc.scroll({ left: left ?? current.left, top: top ?? current.top, behavior });
@@ -188,6 +180,21 @@ export function getScrollContainer(selector: string | HTMLElement | ScrollContai
188
180
  return key ? scrollContainers.get(key) : undefined;
189
181
  }
190
182
 
183
+ export function createScrollContainer(selector: string | HTMLElement): IScrollContainer | undefined {
184
+ const container = typeof selector == 'string' ? document.querySelector<HTMLElement>(selector) : selector;
185
+ if (container) {
186
+ if (scrollContainers.has(container)) {
187
+ return scrollContainers.get(container);
188
+ } else {
189
+ const scrollContainer = new ScrollContainer(container);
190
+ initNewScrollContainer(container, scrollContainer);
191
+ return scrollContainer;
192
+ }
193
+ } else {
194
+ return undefined;
195
+ }
196
+ }
197
+
191
198
  function getPaddingY(content: HTMLElement): number {
192
199
  const style = getComputedStyle(content);
193
200
  return parseFloat(style.paddingTop) + parseFloat(style.paddingBottom);
@@ -221,16 +228,20 @@ const mutationObserver = new MutationObserver((mutations) => {
221
228
  });
222
229
  });
223
230
 
224
- document.querySelectorAll<HTMLElement>('.evo-scroll-container').forEach((container) => {
225
- const scrollContainer = new ScrollContainer(container);
231
+ function initNewScrollContainer(container: HTMLElement, scrollContainer: ScrollContainer) {
226
232
  scrollContainers.set(container, scrollContainer);
227
233
 
228
234
  intersectionObserver.observe(container);
229
235
  mutationObserver.observe(container, { attributes: true, childList: true, subtree: true });
236
+ }
237
+
238
+ document.querySelectorAll<HTMLElement>('.evo-scroll-container').forEach((container) => {
239
+ const scrollContainer = new ScrollContainer(container);
240
+ initNewScrollContainer(container, scrollContainer);
230
241
  });
231
242
 
232
243
  window.addEventListener('resize', () => {
233
244
  [...scrollContainers.values()].forEach((scrollContainer) => {
234
245
  scrollContainer.refresh();
235
246
  });
236
- });
247
+ }, { passive: true });