@inizioevoke/astro-core 1.3.3 → 1.3.5
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.
|
|
3
|
+
"version": "1.3.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"index.ts"
|
|
18
18
|
],
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"astro": ">=
|
|
20
|
+
"astro": ">=5.0.0",
|
|
21
21
|
"typescript": ">=5.0.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
@@ -5,8 +5,11 @@ interface ModalEventCallbackItem {
|
|
|
5
5
|
once?: boolean;
|
|
6
6
|
callback: ModalEventCallback;
|
|
7
7
|
}
|
|
8
|
+
interface ModalEventCallbackArgs {
|
|
9
|
+
once?: boolean
|
|
10
|
+
}
|
|
8
11
|
|
|
9
|
-
type ModalEventType = 'show' | 'hide';
|
|
12
|
+
type ModalEventType = 'show' | 'hide' | 'overlay';
|
|
10
13
|
type ModalEventTypeCallbacks = Record<ModalEventType, Set<ModalEventCallbackItem>>;
|
|
11
14
|
const callbacks = new Map<HTMLElement, ModalEventTypeCallbacks>();
|
|
12
15
|
|
|
@@ -50,7 +53,7 @@ function __showOverlay(animation: ModalAnimation) {
|
|
|
50
53
|
overlay.classList.add('evo-modal-visible', `evo-modal-show-${animation}`);
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
|
-
export function onShow(selector: string | HTMLElement, callback: ModalEventCallback, { once }:
|
|
56
|
+
export function onShow(selector: string | HTMLElement, callback: ModalEventCallback, { once }: ModalEventCallbackArgs = {}) {
|
|
54
57
|
onEvent('show', selector, { once, callback });
|
|
55
58
|
}
|
|
56
59
|
|
|
@@ -105,7 +108,7 @@ function __hide(modal: HTMLElement, animation: ModalAnimation) {
|
|
|
105
108
|
}, animation !== 'none' ? animationDuration : 0);
|
|
106
109
|
});
|
|
107
110
|
}
|
|
108
|
-
export function onHide(selector: string | HTMLElement, callback: ModalEventCallback, { once }:
|
|
111
|
+
export function onHide(selector: string | HTMLElement, callback: ModalEventCallback, { once }: ModalEventCallbackArgs = {}) {
|
|
109
112
|
onEvent('hide', selector, { once, callback });
|
|
110
113
|
}
|
|
111
114
|
|
|
@@ -120,6 +123,10 @@ export function appendOverlay(selector: string | HTMLElement) {
|
|
|
120
123
|
}
|
|
121
124
|
}
|
|
122
125
|
|
|
126
|
+
export function onOverlayClick(callback: ModalEventCallback, { once }: ModalEventCallbackArgs = {}) {
|
|
127
|
+
onEvent('overlay', overlay, { once, callback });
|
|
128
|
+
}
|
|
129
|
+
|
|
123
130
|
function onEvent(type: ModalEventType, selector: string | HTMLElement, callbackItem: ModalEventCallbackItem) {
|
|
124
131
|
let modal = typeof selector == 'string' ? document.querySelector<HTMLElement>(/^[\.#]/.test(selector) ? selector : `#${selector}`) : selector;
|
|
125
132
|
if (modal) {
|
|
@@ -132,15 +139,15 @@ function onEvent(type: ModalEventType, selector: string | HTMLElement, callbackI
|
|
|
132
139
|
}
|
|
133
140
|
}
|
|
134
141
|
|
|
135
|
-
function triggerEventCallbacks(
|
|
136
|
-
if (
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
139
|
-
const items = [...
|
|
142
|
+
function triggerEventCallbacks(element: HTMLElement, eventType: ModalEventType) {
|
|
143
|
+
if (element) {
|
|
144
|
+
const eventCallbacks = callbacks.get(element);
|
|
145
|
+
if (eventCallbacks && eventCallbacks[eventType]) {
|
|
146
|
+
const items = [...eventCallbacks[eventType]];
|
|
140
147
|
const keep: ModalEventCallbackItem[] = [];
|
|
141
148
|
for (const item of items) {
|
|
142
149
|
try {
|
|
143
|
-
item.callback(
|
|
150
|
+
item.callback(element);
|
|
144
151
|
} catch (err) {
|
|
145
152
|
console.log(err);
|
|
146
153
|
} finally {
|
|
@@ -149,7 +156,7 @@ function triggerEventCallbacks(modal: HTMLElement, eventType: 'show' | 'hide') {
|
|
|
149
156
|
}
|
|
150
157
|
}
|
|
151
158
|
}
|
|
152
|
-
callbacks.set(
|
|
159
|
+
callbacks.set(element, {...eventCallbacks, [eventType]: new Set(keep)});
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
162
|
}
|
|
@@ -163,6 +170,7 @@ const overlay: HTMLElement = document.querySelector<HTMLElement>('.evo-modal-ove
|
|
|
163
170
|
})();
|
|
164
171
|
overlay.addEventListener('click', () => {
|
|
165
172
|
hide();
|
|
173
|
+
triggerEventCallbacks(overlay, 'overlay');
|
|
166
174
|
});
|
|
167
175
|
|
|
168
176
|
const animationDuration = (() => {
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
interface Props extends HTMLAttributes<'div'> {
|
|
5
|
+
class?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
class: cssClass,
|
|
10
|
+
...rest
|
|
11
|
+
} = Astro.props;
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
<div class:list={['evo-modal-overlay', cssClass]} {...rest}><slot /></div>
|
|
@@ -86,9 +86,9 @@ class ScrollContainer implements IScrollContainer {
|
|
|
86
86
|
const scrollHeight = this.#content.scrollHeight - getPaddingY(this.#content);
|
|
87
87
|
const containerHeight = this.#container.clientHeight - getPaddingY(this.#container);
|
|
88
88
|
const visibleRatio = containerHeight / scrollHeight;
|
|
89
|
-
const thumbHeight = visibleRatio * containerHeight;
|
|
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
90
|
this.#thumb.style.height = `${thumbHeight > 20 ? thumbHeight : 20}px`;
|
|
91
|
-
this.#track.style.display = visibleRatio < 1 ? 'block' : 'none';
|
|
91
|
+
this.#track.style.display = this.#container.classList.contains('evo-scroll-track-visible') ? 'block' : visibleRatio < 1 ? 'block' : 'none';
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
#thumbMouseDown(e: MouseEvent) {
|
|
@@ -129,7 +129,7 @@ const getFilePaths = (() => {
|
|
|
129
129
|
interface IntegrationProps {
|
|
130
130
|
enabled?: boolean;
|
|
131
131
|
}
|
|
132
|
-
export default function ({ enabled = true }: IntegrationProps): AstroIntegration {
|
|
132
|
+
export default function ({ enabled = true }: IntegrationProps = {}): AstroIntegration {
|
|
133
133
|
let astroConfig: AstroConfig;
|
|
134
134
|
|
|
135
135
|
return {
|