@flexilla/alpine-modal 0.2.0 → 0.3.0

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.
@@ -25,120 +25,134 @@ module.exports = __toCommonJS(module_exports);
25
25
 
26
26
  // ../../node_modules/@flexilla/modal/dist/modal.js
27
27
  var w = Object.defineProperty;
28
- var b = (o, t, e) => t in o ? w(o, t, { enumerable: true, configurable: true, writable: true, value: e }) : o[t] = e;
29
- var s = (o, t, e) => b(o, typeof t != "symbol" ? t + "" : t, e);
30
- var r = (o, t = document.body) => t.querySelector(o);
31
- var c = (o, t = document.body) => Array.from(t.querySelectorAll(o));
28
+ var b = (n, t, e) => t in n ? w(n, t, { enumerable: true, configurable: true, writable: true, value: e }) : n[t] = e;
29
+ var i = (n, t, e) => b(n, typeof t != "symbol" ? t + "" : t, e);
30
+ var r = (n, t = document.body) => t.querySelector(n);
31
+ var u = (n, t = document.body) => Array.from(t.querySelectorAll(n));
32
32
  var M = ({
33
- newElement: o,
33
+ newElement: n,
34
34
  existingElement: t
35
35
  }) => {
36
- if (!(o instanceof HTMLElement) || !(t instanceof HTMLElement))
36
+ if (!(n instanceof HTMLElement) || !(t instanceof HTMLElement))
37
37
  throw new Error("Both parameters must be valid HTML elements.");
38
38
  const e = t.parentElement;
39
39
  if (e)
40
- e.insertBefore(o, t);
40
+ e.insertBefore(n, t);
41
41
  else
42
42
  throw new Error("Existing element must have a parent element.");
43
43
  };
44
- var g = ({
45
- element: o,
44
+ var A = ({
45
+ element: n,
46
46
  callback: t,
47
47
  type: e,
48
- keysCheck: n
48
+ keysCheck: o
49
49
  }) => {
50
- const a = getComputedStyle(o), i = a.animation;
51
- if (i !== "none" && i !== "" && !n.includes(i)) {
50
+ const a = getComputedStyle(n), s = a.animation;
51
+ if (s !== "none" && s !== "" && !o.includes(s)) {
52
52
  const l = "animationend", d = () => {
53
- o.removeEventListener(l, d), t();
53
+ n.removeEventListener(l, d), t();
54
54
  };
55
- o.addEventListener(l, d, { once: true });
55
+ n.addEventListener(l, d, { once: true });
56
56
  } else
57
57
  t();
58
58
  };
59
- var p = ({ element: o, callback: t }) => {
60
- g({
61
- element: o,
59
+ var p = ({ element: n, callback: t }) => {
60
+ A({
61
+ element: n,
62
62
  callback: t,
63
63
  type: "animation",
64
64
  keysCheck: ["none 0s ease 0s 1 normal none running"]
65
65
  });
66
66
  };
67
- var f = (o, t, e) => {
68
- const n = new CustomEvent(t, { detail: e });
69
- o.dispatchEvent(n);
67
+ var E = (n, t, e) => {
68
+ const o = new CustomEvent(t, { detail: e });
69
+ n.dispatchEvent(o);
70
70
  };
71
- function A(o, t, e = "move") {
72
- if (!(o instanceof HTMLElement))
71
+ function g(n) {
72
+ const t = () => {
73
+ document.querySelector(
74
+ "[data-fx-component]:not([data-component-initialized])"
75
+ ) ? requestAnimationFrame(t) : n();
76
+ };
77
+ t();
78
+ }
79
+ function C(n, t, e = "move") {
80
+ if (!(n instanceof HTMLElement))
73
81
  throw new Error("Source element must be an HTMLElement");
74
82
  if (!(t instanceof HTMLElement))
75
83
  throw new Error("Target element must be an HTMLElement");
76
84
  if (!["move", "detachable"].includes(e))
77
85
  throw new Error(`Invalid teleport mode: ${e}. Must be "move" or "detachable".`);
78
- let n = document.createComment("teleporter-placeholder");
79
- const a = o.parentNode;
80
- return a ? a.insertBefore(n, o) : console.warn("Element has no parent; placeholder not inserted."), e === "move" ? (o.parentNode && t.appendChild(o), {
86
+ let o = document.createComment("teleporter-placeholder");
87
+ const a = n.parentNode;
88
+ return a ? a.insertBefore(o, n) : console.warn("Element has no parent; placeholder not inserted."), e === "move" ? (n.parentNode && t.appendChild(n), {
81
89
  append() {
82
- o.parentNode !== t && t.appendChild(o);
90
+ n.parentNode !== t && t.appendChild(n);
83
91
  },
84
92
  remove() {
85
- n != null && n.parentNode && o.parentNode && n.parentNode.insertBefore(o, n);
93
+ o != null && o.parentNode && n.parentNode && o.parentNode.insertBefore(n, o);
86
94
  },
87
95
  restore() {
88
- n != null && n.parentNode && o.parentNode !== a && n.parentNode.insertBefore(o, n);
96
+ o != null && o.parentNode && n.parentNode !== a && o.parentNode.insertBefore(n, o);
89
97
  }
90
- }) : (o.parentNode && t.appendChild(o), {
98
+ }) : (n.parentNode && t.appendChild(n), {
91
99
  append() {
92
- t.contains(o) || t.appendChild(o);
100
+ t.contains(n) || t.appendChild(n);
93
101
  },
94
102
  remove() {
95
- o.parentNode && o.remove();
103
+ n.parentNode && n.remove();
96
104
  },
97
105
  restore() {
98
- n != null && n.parentNode && !o.parentNode && n.parentNode.insertBefore(o, n);
106
+ o != null && o.parentNode && !n.parentNode && o.parentNode.insertBefore(n, o);
99
107
  }
100
108
  });
101
109
  }
102
- var E = (o, t, e) => {
110
+ var v = (n, t, e) => {
103
111
  if (!(t instanceof HTMLElement))
104
112
  throw new Error("No modal-content found");
105
- o.setAttribute("aria-hidden", e === "open" ? "false" : "true"), o.setAttribute("data-state", e), t.setAttribute("data-state", e);
106
- const n = r("[data-modal-overlay]", o);
107
- n instanceof HTMLElement && n.setAttribute("data-state", e);
113
+ n.setAttribute("aria-hidden", e === "open" ? "false" : "true"), n.setAttribute("data-state", e), t.setAttribute("data-state", e);
114
+ const o = r("[data-modal-overlay]", n);
115
+ o instanceof HTMLElement && o.setAttribute("data-state", e);
108
116
  };
109
- var C = (o, t, e) => {
110
- if (!o) {
117
+ var L = (n, t, e) => {
118
+ if (!n) {
111
119
  t || (document.body.style.overflowY = "auto");
112
120
  return;
113
121
  }
114
- c("[data-fx-modal][data-state=open]:not([data-allow-body-scroll=true]").filter((i) => i !== e).length === 0 && !t && (document.body.style.overflowY = "auto");
122
+ u("[data-fx-modal][data-state=open]:not([data-allow-body-scroll=true]").filter((s) => s !== e).length === 0 && !t && (document.body.style.overflowY = "auto");
115
123
  };
116
- var v = class {
124
+ var c = class {
117
125
  static initGlobalRegistry() {
118
126
  window.$flexillaInstances || (window.$flexillaInstances = {});
119
127
  }
120
- static register(t, e, n) {
121
- return this.initGlobalRegistry(), window.$flexillaInstances[t] || (window.$flexillaInstances[t] = []), this.getInstance(t, e) || (window.$flexillaInstances[t].push({ element: e, instance: n }), n);
128
+ static register(t, e, o) {
129
+ return this.initGlobalRegistry(), window.$flexillaInstances[t] || (window.$flexillaInstances[t] = []), this.getInstance(t, e) || (window.$flexillaInstances[t].push({ element: e, instance: o }), o);
122
130
  }
123
131
  static getInstance(t, e) {
124
- var n, a;
125
- return this.initGlobalRegistry(), (a = (n = window.$flexillaInstances[t]) == null ? void 0 : n.find(
126
- (i) => i.element === e
132
+ var o, a;
133
+ return this.initGlobalRegistry(), (a = (o = window.$flexillaInstances[t]) == null ? void 0 : o.find(
134
+ (s) => s.element === e
127
135
  )) == null ? void 0 : a.instance;
128
136
  }
129
137
  static removeInstance(t, e) {
130
138
  this.initGlobalRegistry(), window.$flexillaInstances[t] && (window.$flexillaInstances[t] = window.$flexillaInstances[t].filter(
131
- (n) => n.element !== e
139
+ (o) => o.element !== e
132
140
  ));
133
141
  }
142
+ static setup(t) {
143
+ t.setAttribute("data-fx-component", "fx");
144
+ }
145
+ static initialized(t) {
146
+ t.setAttribute("data-component-initialized", "initialized");
147
+ }
134
148
  };
135
- var L = (o) => {
149
+ var x = (n) => {
136
150
  var t;
137
- o instanceof HTMLElement && ((t = o.parentElement) == null || t.removeChild(o));
151
+ n instanceof HTMLElement && ((t = n.parentElement) == null || t.removeChild(n));
138
152
  };
139
- var T = ({ modalContent: o, overlayClassName: t }) => {
153
+ var T = ({ modalContent: n, overlayClassName: t }) => {
140
154
  const e = document.createElement("span");
141
- return e.setAttribute("aria-hidden", "true"), M({ newElement: e, existingElement: o }), e.classList.add(...t), e.setAttribute("data-modal-overlay", ""), e;
155
+ return e.setAttribute("aria-hidden", "true"), M({ newElement: e, existingElement: n }), e.classList.add(...t), e.setAttribute("data-modal-overlay", ""), e;
142
156
  };
143
157
  var m = class m2 {
144
158
  /**
@@ -147,57 +161,59 @@ var m = class m2 {
147
161
  * @param options - Configuration options for the modal behavior
148
162
  * @param triggerElements - Optional trigger elements or selectors that open the modal
149
163
  */
150
- constructor(t, e = {}, n) {
151
- s(this, "modalElement");
152
- s(this, "modalId");
153
- s(this, "modalContent");
154
- s(this, "triggerButtons", []);
155
- s(this, "overlayElement");
156
- s(this, "dispatchEventToDocument");
157
- s(this, "options");
158
- s(this, "state");
159
- s(this, "animationEnter");
160
- s(this, "animationExit");
161
- s(this, "animateContent");
162
- s(this, "hasDefaultOverlay");
163
- s(this, "enableStackedModals");
164
- s(this, "preventCloseModal");
165
- s(this, "isKeyDownEventRegistered");
166
- s(this, "closeButtons");
167
- s(this, "overlayClassName");
168
- s(this, "allowBodyScroll");
169
- s(this, "initAsOpen");
170
- s(this, "teleporter");
171
- s(this, "moveElOnInit", () => {
172
- this.teleporter.append();
164
+ constructor(t, e = {}, o) {
165
+ i(this, "modalElement");
166
+ i(this, "modalId");
167
+ i(this, "modalContent");
168
+ i(this, "triggerButtons", []);
169
+ i(this, "overlayElement");
170
+ i(this, "dispatchEventToDocument");
171
+ i(this, "options");
172
+ i(this, "state");
173
+ i(this, "animationEnter");
174
+ i(this, "animationExit");
175
+ i(this, "animateContent");
176
+ i(this, "hasDefaultOverlay");
177
+ i(this, "enableStackedModals");
178
+ i(this, "preventCloseModal");
179
+ i(this, "isKeyDownEventRegistered");
180
+ i(this, "closeButtons");
181
+ i(this, "overlayClassName");
182
+ i(this, "allowBodyScroll");
183
+ i(this, "initAsOpen");
184
+ i(this, "teleporter");
185
+ i(this, "moveElOnInit", () => {
186
+ g(() => {
187
+ this.teleporter.append();
188
+ });
173
189
  });
174
- s(this, "closeAll", (t2) => {
190
+ i(this, "closeAll", (t2) => {
175
191
  if (this.enableStackedModals)
176
192
  return;
177
- const e2 = c("[data-fx-modal][data-state=open]");
178
- for (const n2 of e2) {
179
- const a2 = n2.dataset.modalId;
193
+ const e2 = u("[data-fx-modal][data-state=open]");
194
+ for (const o2 of e2) {
195
+ const a2 = o2.dataset.modalId;
180
196
  if (a2 !== t2.dataset.modalId) {
181
- n2.blur(), r("[data-modal-overlay]", n2).setAttribute("data-state", "close");
182
- const l2 = r("[data-modal-content]", n2);
183
- E(n2, l2, "close"), document.dispatchEvent(new CustomEvent(`modal:${a2}:close`));
197
+ o2.blur(), r("[data-modal-overlay]", o2).setAttribute("data-state", "close");
198
+ const l2 = r("[data-modal-content]", o2);
199
+ v(o2, l2, "close"), document.dispatchEvent(new CustomEvent(`modal:${a2}:close`));
184
200
  }
185
201
  }
186
202
  });
187
- s(this, "closeModalEsc", (t2) => {
203
+ i(this, "closeModalEsc", (t2) => {
188
204
  t2.key === "Escape" && (t2.preventDefault(), this.preventCloseModal || this.hideModal());
189
205
  });
190
- s(this, "initModal", (t2, e2) => {
206
+ i(this, "initModal", (t2, e2) => {
191
207
  var h;
192
208
  if (!(t2 instanceof HTMLDialogElement))
193
209
  throw new Error("Modal Element must be a valid HTMLDialog Element");
194
- const { allowBodyScroll: n2, animateContent: a2, preventCloseModal: i2, overlayClass: l2, enableStackedModals: d2 } = e2;
195
- this.allowBodyScroll = t2.hasAttribute("data-allow-body-scroll") && t2.getAttribute("data-allow-body-scroll") !== "false" || n2 || false, this.preventCloseModal = t2.hasAttribute("data-prevent-close-modal") && t2.getAttribute("data-prevent-close-modal") !== "false" || i2 || false, this.enableStackedModals = t2.hasAttribute("data-enable-stacked") && t2.getAttribute("data-enable-stacked") !== "false" || d2 || false, this.overlayClassName = ((h = t2.dataset.modalOverlay) == null ? void 0 : h.split(" ")) || (l2 == null ? void 0 : l2.split(" ")) || "", this.isKeyDownEventRegistered = false, t2.setAttribute("data-allow-body-scroll", `${this.allowBodyScroll}`), this.closeButtons = c("[data-close-modal]", t2), this.hasDefaultOverlay = false, r("[data-modal-overlay]", t2) instanceof HTMLElement && (this.overlayElement = r("[data-modal-overlay]", t2), this.overlayElement.setAttribute("data-overlay-nature", "default"), this.hasDefaultOverlay = true), this.animateContent = a2, this.animationEnter = this.modalContent.dataset.enterAnimation || "", this.animationExit = this.modalContent.dataset.exitAnimation || "", this.overlayElement && this.overlayElement.setAttribute("data-state", "close"), this.addEvents();
210
+ const { allowBodyScroll: o2, animateContent: a2, preventCloseModal: s2, overlayClass: l2, enableStackedModals: d2 } = e2;
211
+ this.allowBodyScroll = t2.hasAttribute("data-allow-body-scroll") && t2.getAttribute("data-allow-body-scroll") !== "false" || o2 || false, this.preventCloseModal = t2.hasAttribute("data-prevent-close-modal") && t2.getAttribute("data-prevent-close-modal") !== "false" || s2 || false, this.enableStackedModals = t2.hasAttribute("data-enable-stacked") && t2.getAttribute("data-enable-stacked") !== "false" || d2 || false, this.overlayClassName = ((h = t2.dataset.modalOverlay) == null ? void 0 : h.split(" ")) || (l2 == null ? void 0 : l2.split(" ")) || "", this.isKeyDownEventRegistered = false, t2.setAttribute("data-allow-body-scroll", `${this.allowBodyScroll}`), this.closeButtons = u("[data-close-modal]", t2), this.hasDefaultOverlay = false, r("[data-modal-overlay]", t2) instanceof HTMLElement && (this.overlayElement = r("[data-modal-overlay]", t2), this.overlayElement.setAttribute("data-overlay-nature", "default"), this.hasDefaultOverlay = true), this.animateContent = a2, this.animationEnter = this.modalContent.dataset.enterAnimation || "", this.animationExit = this.modalContent.dataset.exitAnimation || "", this.overlayElement && this.overlayElement.setAttribute("data-state", "close"), this.addEvents();
196
212
  });
197
- s(this, "closeModalOnX", (t2) => {
213
+ i(this, "closeModalOnX", (t2) => {
198
214
  t2.preventDefault(), this.hideModal();
199
215
  });
200
- s(this, "addEvents", () => {
216
+ i(this, "addEvents", () => {
201
217
  for (const t2 of this.triggerButtons)
202
218
  t2.addEventListener("click", this.showModal);
203
219
  if (this.closeButtons.length > 0)
@@ -205,97 +221,97 @@ var m = class m2 {
205
221
  t2.addEventListener("click", this.closeModalOnX);
206
222
  this.dispatchEventToDocument && document.addEventListener(`modal:${this.modalId}:open`, this.showModal), this.dispatchEventToDocument && document.addEventListener(`modal:${this.modalId}:close`, this.hideModal);
207
223
  });
208
- s(this, "showModal", () => {
209
- var e2, n2, a2, i2, l2;
224
+ i(this, "showModal", () => {
225
+ var e2, o2, a2, s2, l2;
210
226
  if (!(!this.initAsOpen && this.modalElement.getAttribute("data-state") === "open")) {
211
227
  if (this.initAsOpen = false, this.closeAll(this.modalElement), this.overlayElement = this.hasDefaultOverlay ? this.overlayElement : T({
212
228
  modalContent: this.modalContent,
213
229
  overlayClassName: this.overlayClassName
214
- }), (e2 = this.overlayElement) == null || e2.setAttribute("data-state", "open"), f(this.modalElement, "modal-open", { modalId: this.modalId }), this.animateContent || this.animationEnter !== "") {
230
+ }), (e2 = this.overlayElement) == null || e2.setAttribute("data-state", "open"), E(this.modalElement, "modal-open", { modalId: this.modalId }), this.animateContent || this.animationEnter !== "") {
215
231
  const d2 = this.animateContent ? this.animateContent.enterAnimation : this.animationEnter;
216
- d2 && d2 !== "" && this.modalContent.style.setProperty("--un-modal-animation", d2), E(this.modalElement, this.modalContent, "open"), p({
232
+ d2 && d2 !== "" && this.modalContent.style.setProperty("--un-modal-animation", d2), v(this.modalElement, this.modalContent, "open"), p({
217
233
  element: this.modalContent,
218
234
  callback: () => {
219
235
  this.modalContent.style.removeProperty("--un-modal-animation");
220
236
  }
221
237
  });
222
238
  } else
223
- E(this.modalElement, this.modalContent, "open");
224
- this.allowBodyScroll || (document.body.style.overflow = "hidden"), this.isKeyDownEventRegistered || (document.addEventListener("keydown", this.closeModalEsc), this.isKeyDownEventRegistered = true), this.modalContent.focus(), this.preventCloseModal || this.overlayElement.addEventListener("click", this.hideModal), (a2 = (n2 = this.options).onShow) == null || a2.call(n2), (l2 = (i2 = this.options).onToggle) == null || l2.call(i2, { isHidden: false }), this.modalElement.showModal();
239
+ v(this.modalElement, this.modalContent, "open");
240
+ this.allowBodyScroll || (document.body.style.overflow = "hidden"), this.isKeyDownEventRegistered || (document.addEventListener("keydown", this.closeModalEsc), this.isKeyDownEventRegistered = true), this.modalContent.focus(), this.preventCloseModal || this.overlayElement.addEventListener("click", this.hideModal), (a2 = (o2 = this.options).onShow) == null || a2.call(o2), (l2 = (s2 = this.options).onToggle) == null || l2.call(s2, { isHidden: false }), this.modalElement.showModal();
225
241
  }
226
242
  });
227
- s(this, "closeModal", () => {
228
- this.modalElement.setAttribute("aria-hidden", "true"), this.modalElement.setAttribute("data-state", "close"), this.modalElement.blur(), C(this.enableStackedModals || false, this.allowBodyScroll || false, this.modalElement), this.hasDefaultOverlay || L(this.overlayElement), f(this.modalElement, "modal-close", { modalId: this.modalElement.id });
243
+ i(this, "closeModal", () => {
244
+ this.modalElement.setAttribute("aria-hidden", "true"), this.modalElement.setAttribute("data-state", "close"), this.modalElement.blur(), L(this.enableStackedModals || false, this.allowBodyScroll || false, this.modalElement), this.hasDefaultOverlay || x(this.overlayElement), E(this.modalElement, "modal-close", { modalId: this.modalElement.id });
229
245
  });
230
- s(this, "closeLastAction", () => {
231
- var t2, e2, n2, a2;
232
- this.isKeyDownEventRegistered && (document.removeEventListener("keydown", this.closeModalEsc), this.isKeyDownEventRegistered = false), this.modalElement.blur(), (e2 = (t2 = this.options).onHide) == null || e2.call(t2), (a2 = (n2 = this.options).onToggle) == null || a2.call(n2, { isHidden: true });
246
+ i(this, "closeLastAction", () => {
247
+ var t2, e2, o2, a2;
248
+ this.isKeyDownEventRegistered && (document.removeEventListener("keydown", this.closeModalEsc), this.isKeyDownEventRegistered = false), this.modalElement.blur(), (e2 = (t2 = this.options).onHide) == null || e2.call(t2), (a2 = (o2 = this.options).onToggle) == null || a2.call(o2, { isHidden: true });
233
249
  });
234
- s(this, "hideModal", () => {
235
- var a2, i2, l2, d2, h;
250
+ i(this, "hideModal", () => {
251
+ var a2, s2, l2, d2, h;
236
252
  let t2 = false;
237
- f(this.modalElement, "before-hide", {
253
+ E(this.modalElement, "before-hide", {
238
254
  modalId: this.modalId,
239
- setExitAction: (u) => {
240
- t2 = u;
255
+ setExitAction: (f) => {
256
+ t2 = f;
241
257
  }
242
258
  });
243
- const e2 = (l2 = (i2 = (a2 = this.options).beforeHide) == null ? void 0 : i2.call(a2)) == null ? void 0 : l2.cancelAction;
259
+ const e2 = (l2 = (s2 = (a2 = this.options).beforeHide) == null ? void 0 : s2.call(a2)) == null ? void 0 : l2.cancelAction;
244
260
  if (t2 || e2)
245
261
  return;
246
- const n2 = ((d2 = this.animateContent) == null ? void 0 : d2.exitAnimation) && this.animateContent.exitAnimation !== "" || this.animationExit && this.animationExit !== "";
247
- if ((h = this.overlayElement) == null || h.setAttribute("data-state", "close"), this.modalContent.setAttribute("data-state", "close"), n2) {
248
- const u = this.animationExit ? this.animationExit : this.animateContent && this.animateContent.exitAnimation || "";
249
- this.modalContent.style.setProperty("--un-modal-animation", u);
262
+ const o2 = ((d2 = this.animateContent) == null ? void 0 : d2.exitAnimation) && this.animateContent.exitAnimation !== "" || this.animationExit && this.animationExit !== "";
263
+ if ((h = this.overlayElement) == null || h.setAttribute("data-state", "close"), this.modalContent.setAttribute("data-state", "close"), o2) {
264
+ const f = this.animationExit ? this.animationExit : this.animateContent && this.animateContent.exitAnimation || "";
265
+ this.modalContent.style.setProperty("--un-modal-animation", f);
250
266
  }
251
267
  p({
252
268
  element: this.modalContent,
253
269
  callback: () => {
254
- n2 && this.modalContent.style.removeProperty("--un-modal-animation"), this.closeModal(), this.closeLastAction(), document.activeElement instanceof HTMLElement && document.activeElement.blur(), this.modalElement.close("modal-closed");
270
+ o2 && this.modalContent.style.removeProperty("--un-modal-animation"), this.closeModal(), this.closeLastAction(), document.activeElement instanceof HTMLElement && document.activeElement.blur(), this.modalElement.close("modal-closed");
255
271
  }
256
272
  });
257
273
  });
258
- s(this, "cleanup", () => {
274
+ i(this, "cleanup", () => {
259
275
  for (const t2 of this.triggerButtons)
260
276
  t2.removeEventListener("click", this.showModal);
261
277
  if (this.closeButtons.length > 0)
262
278
  for (const t2 of this.closeButtons)
263
279
  t2.removeEventListener("click", this.closeModalOnX);
264
- !this.preventCloseModal && this.overlayElement instanceof HTMLElement && this.overlayElement.removeEventListener("click", this.hideModal), this.dispatchEventToDocument && document.removeEventListener(`modal:${this.modalId}:open`, this.showModal), this.dispatchEventToDocument && document.removeEventListener(`modal:${this.modalId}:close`, this.hideModal), v.removeInstance("modal", this.modalElement);
280
+ !this.preventCloseModal && this.overlayElement instanceof HTMLElement && this.overlayElement.removeEventListener("click", this.hideModal), this.dispatchEventToDocument && document.removeEventListener(`modal:${this.modalId}:open`, this.showModal), this.dispatchEventToDocument && document.removeEventListener(`modal:${this.modalId}:close`, this.hideModal), c.removeInstance("modal", this.modalElement);
265
281
  });
266
- s(this, "setOptions", ({ state: t2, allowBodyscroll: e2 }) => {
282
+ i(this, "setOptions", ({ state: t2, allowBodyscroll: e2 }) => {
267
283
  t2 && (this.state = t2), e2 !== void 0 && (this.allowBodyScroll = e2), this.state === "open" ? this.showModal() : this.state === "close" && this.hideModal();
268
284
  });
269
285
  const a = typeof t == "string" ? r(t) : t;
270
286
  if (!(a instanceof HTMLDialogElement))
271
287
  throw new Error("Modal element not found or invalid. Please provide a valid HTMLDialogElement or selector.");
272
288
  this.modalElement = a, this.options = e, this.state = (e == null ? void 0 : e.defaultState) || this.modalElement.dataset.state || "close";
273
- const i = v.getInstance("modal", this.modalElement);
274
- if (i)
275
- return i;
289
+ const s = c.getInstance("modal", this.modalElement);
290
+ if (s)
291
+ return s;
276
292
  this.modalElement.hasAttribute("data-fx-modal") || this.modalElement.setAttribute("data-fx-modal", "");
277
293
  const l = r("[data-modal-content]", a);
278
294
  if (!(l instanceof HTMLElement))
279
295
  throw new Error("Modal content element not found or invalid. Please provide a valid HTMLElement or selector.");
280
- this.modalContent = l;
296
+ c.setup(this.modalElement), this.modalContent = l;
281
297
  const d = a.dataset.modalId;
282
- this.modalId = `${d}`, this.teleporter = A(this.modalElement, document.body, "move"), this.initializeTriggers(n, d), this.dispatchEventToDocument = this.options.dispatchEventToDocument || true, this.initModal(this.modalElement, this.options), this.state === "open" ? (this.initAsOpen = true, this.showModal()) : (this.initAsOpen = false, this.modalElement.blur(), this.modalContent.setAttribute("data-state", "close"), this.modalElement.setAttribute("aria-hidden", "true"), this.modalElement.setAttribute("data-state", "close")), this.moveElOnInit(), v.register("modal", this.modalElement, this);
298
+ this.modalId = `${d}`, this.teleporter = C(this.modalElement, document.body, "move"), this.initializeTriggers(o, d), this.dispatchEventToDocument = this.options.dispatchEventToDocument || true, this.initModal(this.modalElement, this.options), this.state === "open" ? (this.initAsOpen = true, this.showModal()) : (this.initAsOpen = false, this.modalElement.blur(), this.modalContent.setAttribute("data-state", "close"), this.modalElement.setAttribute("aria-hidden", "true"), this.modalElement.setAttribute("data-state", "close")), this.moveElOnInit(), c.register("modal", this.modalElement, this), c.initialized(this.modalElement);
283
299
  }
284
300
  initializeTriggers(t, e) {
285
301
  if (!t && e) {
286
- const a = c(`[data-modal-target='${e}'], [data-modal-trigger][data-modal-id='${e}']`);
302
+ const a = u(`[data-modal-target='${e}'], [data-modal-trigger][data-modal-id='${e}']`);
287
303
  this.triggerButtons = a;
288
304
  return;
289
305
  }
290
306
  if (!t)
291
307
  return;
292
- const n = Array.isArray(t) ? t : [t];
293
- this.triggerButtons = n.map((a) => {
308
+ const o = Array.isArray(t) ? t : [t];
309
+ this.triggerButtons = o.map((a) => {
294
310
  if (typeof a == "string") {
295
- const i = r(a);
296
- if (!(i instanceof HTMLElement))
311
+ const s = r(a);
312
+ if (!(s instanceof HTMLElement))
297
313
  throw new Error(`Trigger element not found: ${a}`);
298
- return i;
314
+ return s;
299
315
  }
300
316
  if (!(a instanceof HTMLElement))
301
317
  throw new Error("Invalid trigger element provided");
@@ -303,14 +319,14 @@ var m = class m2 {
303
319
  });
304
320
  }
305
321
  };
306
- s(m, "autoInit", (t = "[data-fx-modal]") => {
307
- const e = c(t);
308
- for (const n of e)
309
- new m(n);
322
+ i(m, "autoInit", (t = "[data-fx-modal]") => {
323
+ const e = u(t);
324
+ for (const o of e)
325
+ new m(o);
310
326
  }), /**
311
327
  * Creates and initializes a new Modal instance
312
328
  */
313
- s(m, "init", (t, e = {}, n) => new m(t, e, n));
329
+ i(m, "init", (t, e = {}, o) => new m(t, e, o));
314
330
  var y = m;
315
331
 
316
332
  // src/index.js