@inizioevoke/astro-core 1.4.1 → 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,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,11 +233,13 @@ export class ScrollContainer extends HTMLElement implements IScrollContainer {
|
|
|
238
233
|
this.#thumb.style.top = `${top}px`;
|
|
239
234
|
}
|
|
240
235
|
}
|
|
241
|
-
if (!customElements.get(
|
|
242
|
-
customElements.define(
|
|
236
|
+
if (!customElements.get(EvoScrollContainerElement.htmlTagName)) {
|
|
237
|
+
customElements.define(EvoScrollContainerElement.htmlTagName, EvoScrollContainerElement);
|
|
243
238
|
}
|
|
244
239
|
|
|
245
|
-
export
|
|
240
|
+
export type IScrollContainer = InstanceType<typeof EvoScrollContainerElement>;
|
|
241
|
+
|
|
242
|
+
export function resize(selector: string | HTMLElement, { height }: { height?: number }) {
|
|
246
243
|
if (typeof height == 'number') {
|
|
247
244
|
const sc = getScrollContainer(selector);
|
|
248
245
|
if (sc) {
|
|
@@ -251,20 +248,20 @@ export function resize(selector: string | HTMLElement | ScrollContainer, { heigh
|
|
|
251
248
|
}
|
|
252
249
|
}
|
|
253
250
|
|
|
254
|
-
export function refresh(selector?: string | HTMLElement
|
|
251
|
+
export function refresh(selector?: string | HTMLElement) {
|
|
255
252
|
if (selector) {
|
|
256
253
|
const sc = getScrollContainer(selector);
|
|
257
254
|
if (sc) {
|
|
258
255
|
sc.refresh()
|
|
259
256
|
}
|
|
260
257
|
} else {
|
|
261
|
-
[...
|
|
258
|
+
[...document.querySelectorAll<EvoScrollContainerElement>(EvoScrollContainerElement.htmlTagName)].forEach((selector) => {
|
|
262
259
|
selector.refresh();
|
|
263
260
|
});
|
|
264
261
|
}
|
|
265
262
|
}
|
|
266
263
|
|
|
267
|
-
export function getScroll(selector: string | HTMLElement
|
|
264
|
+
export function getScroll(selector: string | HTMLElement): { left: number, top: number } | undefined {
|
|
268
265
|
const sc = getScrollContainer(selector);
|
|
269
266
|
if (sc) {
|
|
270
267
|
return sc.getScroll();
|
|
@@ -273,7 +270,7 @@ export function getScroll(selector: string | HTMLElement | ScrollContainer): { l
|
|
|
273
270
|
}
|
|
274
271
|
}
|
|
275
272
|
|
|
276
|
-
export function scroll(selector: string | HTMLElement
|
|
273
|
+
export function scroll(selector: string | HTMLElement, { left, top, behavior = 'auto' }: { left?: number, top?: number, behavior?: 'auto' | 'instant' | 'smooth' } = {}) {
|
|
277
274
|
const sc = getScrollContainer(selector);
|
|
278
275
|
if (sc) {
|
|
279
276
|
const current = sc.getScroll();
|
|
@@ -281,12 +278,12 @@ export function scroll(selector: string | HTMLElement | ScrollContainer, { left,
|
|
|
281
278
|
}
|
|
282
279
|
}
|
|
283
280
|
|
|
284
|
-
export function getScrollContainer(selector: string | HTMLElement
|
|
285
|
-
if (selector instanceof
|
|
281
|
+
export function getScrollContainer(selector: string | HTMLElement): IScrollContainer | undefined {
|
|
282
|
+
if (selector instanceof EvoScrollContainerElement) {
|
|
286
283
|
return selector;
|
|
287
284
|
}
|
|
288
285
|
const scrollContainer = typeof selector == 'string' ? document.querySelector<HTMLElement>(selector) : selector;
|
|
289
|
-
return scrollContainer instanceof
|
|
286
|
+
return scrollContainer instanceof EvoScrollContainerElement ? scrollContainer as IScrollContainer : undefined;
|
|
290
287
|
// const key = typeof selector == 'string' ? document.querySelector<HTMLElement>(selector) : selector;
|
|
291
288
|
// return key ? scrollContainers.get(key) : undefined;
|
|
292
289
|
}
|