@paroicms/tiny-modal 0.7.0 → 0.7.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/dist/tiny-modal.css +14 -4
- package/dist/tiny-modal.d.ts +2 -0
- package/dist/tiny-modal.js +64 -6
- package/package.json +3 -3
package/dist/tiny-modal.css
CHANGED
|
@@ -2,18 +2,22 @@
|
|
|
2
2
|
.TinyModal {
|
|
3
3
|
background: transparent;
|
|
4
4
|
border: none;
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
5
7
|
margin: auto;
|
|
8
|
+
max-height: 100dvh;
|
|
9
|
+
max-width: 100dvw;
|
|
6
10
|
padding: 0;
|
|
7
11
|
position: fixed;
|
|
8
|
-
overflow: visible;
|
|
9
|
-
max-width: 100vw;
|
|
10
|
-
max-height: 100vh;
|
|
11
12
|
}
|
|
12
13
|
.TinyModal::backdrop {
|
|
13
14
|
background-color: rgba(34, 34, 34, 0.7333333333);
|
|
14
15
|
}
|
|
15
16
|
.TinyModal-body {
|
|
16
|
-
|
|
17
|
+
flex: 1;
|
|
18
|
+
max-width: 100%;
|
|
19
|
+
min-height: 0;
|
|
20
|
+
overflow: auto;
|
|
17
21
|
}
|
|
18
22
|
.TinyModal-closeButton {
|
|
19
23
|
align-items: center;
|
|
@@ -40,6 +44,12 @@
|
|
|
40
44
|
right: -18px;
|
|
41
45
|
}
|
|
42
46
|
}
|
|
47
|
+
.TinyModal.fullHeight .TinyModal-closeButton {
|
|
48
|
+
top: 5px;
|
|
49
|
+
}
|
|
50
|
+
.TinyModal.fullWidth .TinyModal-closeButton {
|
|
51
|
+
right: 5px;
|
|
52
|
+
}
|
|
43
53
|
|
|
44
54
|
.TinyModalHidden {
|
|
45
55
|
display: none !important;
|
package/dist/tiny-modal.d.ts
CHANGED
|
@@ -8,9 +8,11 @@ export default function initializeTinyModal(options: {
|
|
|
8
8
|
dialogContent: HTMLElement;
|
|
9
9
|
openButton?: string | HTMLElement;
|
|
10
10
|
modalClass?: string;
|
|
11
|
+
loadCss?: boolean;
|
|
11
12
|
}): TinyModal;
|
|
12
13
|
export default function initializeTinyModal(options: {
|
|
13
14
|
dialogContent: string;
|
|
14
15
|
openButton?: string | HTMLElement;
|
|
15
16
|
modalClass?: string;
|
|
17
|
+
loadCss?: boolean;
|
|
16
18
|
}): TinyModal | undefined;
|
package/dist/tiny-modal.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
let cssLoaded = false;
|
|
2
|
+
export default function initializeTinyModal({ openButton, dialogContent, modalClass, loadCss, }) {
|
|
3
|
+
if (loadCss) {
|
|
4
|
+
loadCssFromModuleUrl();
|
|
5
|
+
}
|
|
2
6
|
const openBtnEl = openButton
|
|
3
7
|
? typeof openButton === "string"
|
|
4
8
|
? document.querySelector(openButton)
|
|
@@ -24,17 +28,44 @@ export default function initializeTinyModal({ openButton, dialogContent, modalCl
|
|
|
24
28
|
dialogEl.appendChild(bodyEl);
|
|
25
29
|
document.body.appendChild(dialogEl);
|
|
26
30
|
const eventListeners = new Map();
|
|
27
|
-
function on(
|
|
28
|
-
if (!eventListeners.has(
|
|
29
|
-
eventListeners.set(
|
|
31
|
+
function on(eventName, listener) {
|
|
32
|
+
if (!eventListeners.has(eventName)) {
|
|
33
|
+
eventListeners.set(eventName, []);
|
|
30
34
|
}
|
|
31
|
-
eventListeners.get(
|
|
35
|
+
eventListeners.get(eventName)?.push(listener);
|
|
32
36
|
}
|
|
33
37
|
function trigger(eventName) {
|
|
34
38
|
if (eventListeners.has(eventName)) {
|
|
35
|
-
eventListeners.get(eventName)?.forEach((listener) =>
|
|
39
|
+
eventListeners.get(eventName)?.forEach((listener) => {
|
|
40
|
+
listener();
|
|
41
|
+
});
|
|
36
42
|
}
|
|
37
43
|
}
|
|
44
|
+
function updateCloseButtonPosition() {
|
|
45
|
+
const dialogRect = dialogEl.getBoundingClientRect();
|
|
46
|
+
const viewportHeight = window.innerHeight;
|
|
47
|
+
const viewportWidth = window.innerWidth;
|
|
48
|
+
// Check if dialog is full height (with small tolerance for rounding)
|
|
49
|
+
if (Math.abs(dialogRect.height - viewportHeight) < 2) {
|
|
50
|
+
dialogEl.classList.add("fullHeight");
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
dialogEl.classList.remove("fullHeight");
|
|
54
|
+
}
|
|
55
|
+
// Check if dialog is full width (with small tolerance for rounding)
|
|
56
|
+
if (Math.abs(dialogRect.width - viewportWidth) < 2) {
|
|
57
|
+
dialogEl.classList.add("fullWidth");
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
dialogEl.classList.remove("fullWidth");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
64
|
+
if (dialogEl.open) {
|
|
65
|
+
updateCloseButtonPosition();
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
resizeObserver.observe(dialogEl);
|
|
38
69
|
function open() {
|
|
39
70
|
dialogEl.showModal();
|
|
40
71
|
document.body.style.overflow = "hidden";
|
|
@@ -53,3 +84,30 @@ export default function initializeTinyModal({ openButton, dialogContent, modalCl
|
|
|
53
84
|
});
|
|
54
85
|
return { open, close, on };
|
|
55
86
|
}
|
|
87
|
+
function loadCssFromModuleUrl() {
|
|
88
|
+
if (cssLoaded)
|
|
89
|
+
return;
|
|
90
|
+
const moduleUrl = import.meta.url;
|
|
91
|
+
if (!moduleUrl)
|
|
92
|
+
throw new Error("import.meta.url not available");
|
|
93
|
+
// Derive CSS URL from the module URL
|
|
94
|
+
// e.g., https://esm.sh/@paroicms/tiny-modal@0.7.1 -> https://esm.sh/@paroicms/tiny-modal@0.7.1/dist/tiny-modal.css
|
|
95
|
+
// or https://esm.sh/@paroicms/tiny-modal@0.7.1/dist/tiny-modal.js -> https://esm.sh/@paroicms/tiny-modal@0.7.1/dist/tiny-modal.css
|
|
96
|
+
const cssUrl = moduleUrl.replace(/\/[^/]+\.m?js$/, () => {
|
|
97
|
+
if (moduleUrl.includes("/dist/")) {
|
|
98
|
+
return "/tiny-modal.css";
|
|
99
|
+
}
|
|
100
|
+
return "/dist/tiny-modal.css";
|
|
101
|
+
});
|
|
102
|
+
// Check if CSS is already loaded
|
|
103
|
+
if (document.querySelector(`link[href="${cssUrl}"]`)) {
|
|
104
|
+
cssLoaded = true;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
// Inject CSS link
|
|
108
|
+
const link = document.createElement("link");
|
|
109
|
+
link.rel = "stylesheet";
|
|
110
|
+
link.href = cssUrl;
|
|
111
|
+
document.head.appendChild(link);
|
|
112
|
+
cssLoaded = true;
|
|
113
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paroicms/tiny-modal",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Tiny modal library for creating modal dialogs",
|
|
5
5
|
"author": "Paroi Team",
|
|
6
6
|
"repository": {
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"typings": "dist/tiny-modal.d.ts",
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"rimraf": "~6.0.1",
|
|
28
|
-
"sass": "~1.
|
|
29
|
-
"typescript": "~5.9.
|
|
28
|
+
"sass": "~1.93.2",
|
|
29
|
+
"typescript": "~5.9.3"
|
|
30
30
|
},
|
|
31
31
|
"files": [
|
|
32
32
|
"dist"
|