@inizioevoke/astro-core 1.4.0 → 1.4.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.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -38,7 +38,7 @@ if (innerWidth) {
38
38
  contentAttrs.style = `width:${typeof innerWidth == 'number' || /^\d+$/.test(innerWidth) ? `${innerWidth}px` : innerWidth};`
39
39
  }
40
40
  ---
41
- <scroll-container class:list={['evo-scroll-container', cssClass]} {...containerAttrs}>
41
+ <evo-scroll-container class:list={['evo-scroll-container', cssClass]} {...containerAttrs}>
42
42
  <div class="evo-scroll-content" {...contentAttrs}>
43
43
  <slot />
44
44
  </div>
@@ -48,7 +48,7 @@ if (innerWidth) {
48
48
  {horizontal && <div class="evo-scroll-track evo-scroll-track-x">
49
49
  <div class="evo-scroll-thumb"></div>
50
50
  </div>}
51
- </scroll-container>
51
+ </evo-scroll-container>
52
52
 
53
53
  <script>
54
54
  import './ScrollContainer';
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  const intersectionObserver = new IntersectionObserver((entries) => {
4
2
  entries.forEach((entry) => {
5
3
  if (entry.isIntersecting) {
@@ -26,15 +24,12 @@ const mutationObserver = new MutationObserver((mutations) => {
26
24
  });
27
25
  });
28
26
 
29
- export interface IScrollContainer {
30
- scroll(args?: { left?: number | string, top?: number | string, behavior?: 'auto' | 'instant' | 'smooth' }): void;
31
- getScroll(): { left: number, top: number }
32
- resize(args: { height?: number }): void;
33
- refresh(): void;
34
- }
35
27
 
28
+ export class EvoScrollContainerElement extends HTMLElement {
29
+ static get htmlTagName() {
30
+ return 'evo-scroll-container';
31
+ }
36
32
 
37
- export class ScrollContainer extends HTMLElement implements IScrollContainer {
38
33
  // #container: HTMLElement & { evoScrollContainer: ScrollContainer };
39
34
  #content!: HTMLElement;
40
35
  #track!: HTMLElement;
@@ -238,9 +233,13 @@ export class ScrollContainer extends HTMLElement implements IScrollContainer {
238
233
  this.#thumb.style.top = `${top}px`;
239
234
  }
240
235
  }
241
- customElements.define('scroll-container', ScrollContainer);
236
+ if (!customElements.get(EvoScrollContainerElement.htmlTagName)) {
237
+ customElements.define(EvoScrollContainerElement.htmlTagName, EvoScrollContainerElement);
238
+ }
239
+
240
+ export type IScrollContainer = InstanceType<typeof EvoScrollContainerElement>;
242
241
 
243
- export function resize(selector: string | HTMLElement | ScrollContainer, { height }: { height?: number }) {
242
+ export function resize(selector: string | HTMLElement, { height }: { height?: number }) {
244
243
  if (typeof height == 'number') {
245
244
  const sc = getScrollContainer(selector);
246
245
  if (sc) {
@@ -249,20 +248,20 @@ export function resize(selector: string | HTMLElement | ScrollContainer, { heigh
249
248
  }
250
249
  }
251
250
 
252
- export function refresh(selector?: string | HTMLElement | ScrollContainer) {
251
+ export function refresh(selector?: string | HTMLElement) {
253
252
  if (selector) {
254
253
  const sc = getScrollContainer(selector);
255
254
  if (sc) {
256
255
  sc.refresh()
257
256
  }
258
257
  } else {
259
- [...scrollContainers.values()].forEach((selector) => {
258
+ [...document.querySelectorAll<EvoScrollContainerElement>(EvoScrollContainerElement.htmlTagName)].forEach((selector) => {
260
259
  selector.refresh();
261
260
  });
262
261
  }
263
262
  }
264
263
 
265
- export function getScroll(selector: string | HTMLElement | ScrollContainer): { left: number, top: number } | undefined {
264
+ export function getScroll(selector: string | HTMLElement): { left: number, top: number } | undefined {
266
265
  const sc = getScrollContainer(selector);
267
266
  if (sc) {
268
267
  return sc.getScroll();
@@ -271,7 +270,7 @@ export function getScroll(selector: string | HTMLElement | ScrollContainer): { l
271
270
  }
272
271
  }
273
272
 
274
- export function scroll(selector: string | HTMLElement | ScrollContainer, { left, top, behavior = 'auto' }: { left?: number, top?: number, behavior?: 'auto' | 'instant' | 'smooth' } = {}) {
273
+ export function scroll(selector: string | HTMLElement, { left, top, behavior = 'auto' }: { left?: number, top?: number, behavior?: 'auto' | 'instant' | 'smooth' } = {}) {
275
274
  const sc = getScrollContainer(selector);
276
275
  if (sc) {
277
276
  const current = sc.getScroll();
@@ -279,12 +278,12 @@ export function scroll(selector: string | HTMLElement | ScrollContainer, { left,
279
278
  }
280
279
  }
281
280
 
282
- export function getScrollContainer(selector: string | HTMLElement | ScrollContainer): IScrollContainer | undefined {
283
- if (selector instanceof ScrollContainer) {
281
+ export function getScrollContainer(selector: string | HTMLElement): IScrollContainer | undefined {
282
+ if (selector instanceof EvoScrollContainerElement) {
284
283
  return selector;
285
284
  }
286
285
  const scrollContainer = typeof selector == 'string' ? document.querySelector<HTMLElement>(selector) : selector;
287
- return scrollContainer instanceof ScrollContainer ? scrollContainer as IScrollContainer : undefined;
286
+ return scrollContainer instanceof EvoScrollContainerElement ? scrollContainer as IScrollContainer : undefined;
288
287
  // const key = typeof selector == 'string' ? document.querySelector<HTMLElement>(selector) : selector;
289
288
  // return key ? scrollContainers.get(key) : undefined;
290
289
  }