@paroicms/tiny-modal 0.7.8 → 0.7.10

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.
Files changed (2) hide show
  1. package/dist/tiny-modal.js +19 -5
  2. package/package.json +3 -3
@@ -43,17 +43,23 @@ export default function initializeTinyModal({ openButton, dialogContent, modalCl
43
43
  }
44
44
  function updateCloseButtonPosition() {
45
45
  const dialogRect = dialogEl.getBoundingClientRect();
46
- const viewportHeight = window.innerHeight;
47
46
  const viewportWidth = window.innerWidth;
48
- // Check if dialog is full height (with small tolerance for rounding)
49
- if (Math.abs(dialogRect.height - viewportHeight) < 2) {
47
+ // Close button is 40px and positioned at -30px outside the dialog
48
+ // We need at least 30px of space to fit the button outside, plus some margin (5px minimum from edge)
49
+ const buttonOffset = 30;
50
+ const minMarginFromEdge = 5;
51
+ const minSpaceNeeded = buttonOffset + minMarginFromEdge; // 35px
52
+ // Check if there's enough space at the top for the button
53
+ const spaceAtTop = dialogRect.top;
54
+ if (spaceAtTop < minSpaceNeeded) {
50
55
  dialogEl.classList.add("fullHeight");
51
56
  }
52
57
  else {
53
58
  dialogEl.classList.remove("fullHeight");
54
59
  }
55
- // Check if dialog is full width (with small tolerance for rounding)
56
- if (Math.abs(dialogRect.width - viewportWidth) < 2) {
60
+ // Check if there's enough space at the right for the button
61
+ const spaceAtRight = viewportWidth - dialogRect.right;
62
+ if (spaceAtRight < minSpaceNeeded) {
57
63
  dialogEl.classList.add("fullWidth");
58
64
  }
59
65
  else {
@@ -66,6 +72,12 @@ export default function initializeTinyModal({ openButton, dialogContent, modalCl
66
72
  }
67
73
  });
68
74
  resizeObserver.observe(dialogEl);
75
+ const handleWindowResize = () => {
76
+ if (dialogEl.open) {
77
+ updateCloseButtonPosition();
78
+ }
79
+ };
80
+ window.addEventListener("resize", handleWindowResize);
69
81
  function open() {
70
82
  dialogEl.showModal();
71
83
  document.body.style.overflow = "hidden";
@@ -80,6 +92,8 @@ export default function initializeTinyModal({ openButton, dialogContent, modalCl
80
92
  dialogEl.addEventListener("close", () => {
81
93
  document.body.style.removeProperty("overflow");
82
94
  document.documentElement.style.removeProperty("overflow");
95
+ resizeObserver.disconnect();
96
+ window.removeEventListener("resize", handleWindowResize);
83
97
  trigger("close");
84
98
  });
85
99
  return { open, close, on };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paroicms/tiny-modal",
3
- "version": "0.7.8",
3
+ "version": "0.7.10",
4
4
  "description": "Tiny modal library for creating modal dialogs",
5
5
  "author": "Paroi Team",
6
6
  "repository": {
@@ -24,8 +24,8 @@
24
24
  "main": "dist/tiny-modal.js",
25
25
  "typings": "dist/tiny-modal.d.ts",
26
26
  "devDependencies": {
27
- "rimraf": "~6.1.0",
28
- "sass": "~1.94.0",
27
+ "rimraf": "~6.1.2",
28
+ "sass": "~1.94.2",
29
29
  "typescript": "~5.9.3"
30
30
  },
31
31
  "files": [