@flexilla/alpine-offcanvas 0.1.2 → 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.
package/dist/cdn.js CHANGED
@@ -1,10 +1,10 @@
1
1
  (() => {
2
2
  // ../../node_modules/@flexilla/offcanvas/dist/offcanvas.js
3
- var w = Object.defineProperty;
4
- var b = (t, e, n) => e in t ? w(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n;
5
- var o = (t, e, n) => b(t, typeof e != "symbol" ? e + "" : e, n);
3
+ var g = Object.defineProperty;
4
+ var w = (t, e, n) => e in t ? g(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n;
5
+ var o = (t, e, n) => w(t, typeof e != "symbol" ? e + "" : e, n);
6
6
  var m = (t, e = document.body) => e.querySelector(t);
7
- var d = (t, e = document.body) => Array.from(e.querySelectorAll(t));
7
+ var h = (t, e = document.body) => Array.from(e.querySelectorAll(t));
8
8
  var y = ({
9
9
  newElement: t,
10
10
  existingElement: e
@@ -25,10 +25,10 @@
25
25
  }) => {
26
26
  const a = getComputedStyle(t), i = a.transition;
27
27
  if (i !== "none" && i !== "" && !s.includes(i)) {
28
- const l = "transitionend", r = () => {
29
- t.removeEventListener(l, r), e();
28
+ const l = "transitionend", c = () => {
29
+ t.removeEventListener(l, c), e();
30
30
  };
31
- t.addEventListener(l, r, { once: true });
31
+ t.addEventListener(l, c, { once: true });
32
32
  } else
33
33
  e();
34
34
  };
@@ -47,7 +47,15 @@
47
47
  const s = new CustomEvent(e, { detail: n });
48
48
  t.dispatchEvent(s);
49
49
  };
50
- function B(t, e, n = "move") {
50
+ function B(t) {
51
+ const e = () => {
52
+ document.querySelector(
53
+ "[data-fx-component]:not([data-component-initialized])"
54
+ ) ? requestAnimationFrame(e) : t();
55
+ };
56
+ e();
57
+ }
58
+ function A(t, e, n = "move") {
51
59
  if (!(t instanceof HTMLElement))
52
60
  throw new Error("Source element must be an HTMLElement");
53
61
  if (!(e instanceof HTMLElement))
@@ -78,7 +86,7 @@
78
86
  }
79
87
  });
80
88
  }
81
- var A = (t) => {
89
+ var I = (t) => {
82
90
  var e;
83
91
  return (e = t.parentElement) == null ? void 0 : e.removeChild(t);
84
92
  };
@@ -86,7 +94,7 @@
86
94
  t.setAttribute("data-state", "invisible"), O({
87
95
  element: t,
88
96
  callback() {
89
- A(t);
97
+ I(t);
90
98
  }
91
99
  });
92
100
  };
@@ -106,7 +114,7 @@
106
114
  var S = (t) => {
107
115
  document.body.style.overflow = t === "open" ? "hidden" : "", document.body.style.overflowY = t === "open" ? "hidden" : "auto";
108
116
  };
109
- var I = (t, e) => {
117
+ var T = (t, e) => {
110
118
  if (t === e)
111
119
  return;
112
120
  t.setAttribute("aria-hidden", "true"), t.setAttribute("data-state", "close");
@@ -114,12 +122,12 @@
114
122
  n instanceof HTMLElement && C(n);
115
123
  };
116
124
  var x = (t) => {
117
- const e = d("[data-fx-offcanvas][data-state=open]");
125
+ const e = h("[data-fx-offcanvas][data-state=open]");
118
126
  if (!(e.length <= 0))
119
127
  for (const n of e)
120
- I(n, t);
128
+ T(n, t);
121
129
  };
122
- var h = class {
130
+ var d = class {
123
131
  static initGlobalRegistry() {
124
132
  window.$flexillaInstances || (window.$flexillaInstances = {});
125
133
  }
@@ -137,6 +145,12 @@
137
145
  (s) => s.element !== n
138
146
  ));
139
147
  }
148
+ static setup(e) {
149
+ e.setAttribute("data-fx-component", "fx");
150
+ }
151
+ static initialized(e) {
152
+ e.setAttribute("data-component-initialized", "initialized");
153
+ }
140
154
  };
141
155
  var f = class f2 {
142
156
  /**
@@ -160,58 +174,72 @@
160
174
  o(this, "offCanvasElement");
161
175
  o(this, "offCanvasTriggers");
162
176
  o(this, "offCanvasCloseBtns");
177
+ o(this, "offCanvasId", "");
178
+ o(this, "dispatchEventToDocument");
163
179
  o(this, "allowBodyScroll");
164
180
  o(this, "staticBackdrop");
165
181
  o(this, "backdrop");
166
182
  o(this, "options");
167
183
  o(this, "teleporter");
168
184
  o(this, "moveElOnInit", () => {
169
- this.teleporter.append();
185
+ B(() => this.teleporter.append());
170
186
  });
171
187
  o(this, "closeWhenClickOutSide", (e2) => {
172
188
  const n2 = this.offCanvasElement.getAttribute("data-state") === "open", s2 = !this.offCanvasElement.contains(e2.target) && ![...this.offCanvasTriggers].includes(e2.target);
173
189
  n2 && s2 && this.closeOffCanvas();
174
190
  });
175
191
  o(this, "closeOffCanvas", () => {
176
- var i2, l2, r2, c2, p;
192
+ var i2, l2, c2, r2, p;
177
193
  let e2 = false;
178
194
  if (v(this.offCanvasElement, "offcanvas-before-hide", {
179
195
  offcanvasId: this.offCanvasElement.id,
180
- setExitAction: (g) => {
181
- e2 = g;
196
+ setExitAction: (b) => {
197
+ e2 = b;
182
198
  }
183
- }), ((r2 = (l2 = (i2 = this.options).beforeHide) == null ? void 0 : l2.call(i2)) == null ? void 0 : r2.cancelAction) || e2)
199
+ }), ((c2 = (l2 = (i2 = this.options).beforeHide) == null ? void 0 : l2.call(i2)) == null ? void 0 : c2.cancelAction) || e2)
184
200
  return;
185
201
  const s2 = this.offCanvasElement.getAttribute("id"), a2 = m(`[data-fx-offcanvas-overlay][data-offcanvas-el=${s2}]`);
186
- a2 instanceof HTMLElement && C(a2), u(
202
+ a2 instanceof HTMLElement && C(a2), this.offCanvasElement.blur(), u(
187
203
  this.offCanvasElement,
188
204
  this.allowBodyScroll,
189
205
  "close"
190
- ), document.removeEventListener("keydown", this.closeWithEsc), !this.allowBodyScroll && !a2 && document.removeEventListener("click", this.closeWhenClickOutSide), (p = (c2 = this.options).onHide) == null || p.call(c2), v(this.offCanvasElement, "offcanvas-close", { offcanvasId: this.offCanvasElement.id });
206
+ ), document.removeEventListener("keydown", this.closeWithEsc), !this.allowBodyScroll && !a2 && document.removeEventListener("click", this.closeWhenClickOutSide), (p = (r2 = this.options).onHide) == null || p.call(r2), v(this.offCanvasElement, "offcanvas-close", { offcanvasId: this.offCanvasElement.id });
191
207
  });
192
208
  o(this, "closeWithEsc", (e2) => {
193
209
  e2.key === "Escape" && (e2.preventDefault(), this.closeOffCanvas());
194
210
  });
211
+ o(this, "closeFromCloseBtn", (e2) => {
212
+ e2.target.blur(), this.closeOffCanvas();
213
+ });
195
214
  o(this, "changeState", () => {
196
215
  this.offCanvasElement.getAttribute("data-state") === "open" ? this.closeOffCanvas() : this.openOffCanvas();
197
216
  });
217
+ o(this, "open", () => {
218
+ this.openOffCanvas();
219
+ });
220
+ o(this, "close", () => {
221
+ this.closeOffCanvas();
222
+ });
198
223
  o(this, "setOptions", ({ allowBodyscroll: e2 }) => {
199
224
  e2 !== void 0 && (this.allowBodyScroll = e2);
200
225
  });
201
226
  const s = typeof e == "string" ? m(e) : e;
202
227
  if (!(s instanceof HTMLElement))
203
228
  throw new Error("Invalid Offcanvas, the provided Element is not a valid HTMLElement");
204
- const a = h.getInstance("offcanvas", s);
229
+ this.offCanvasElement = s;
230
+ const a = d.getInstance("offcanvas", s);
205
231
  if (a)
206
232
  return a;
207
- this.options = n;
208
- const { staticBackdrop: i, allowBodyScroll: l, backdrop: r } = this.options;
209
- this.offCanvasElement = s, this.setupAttributes(), this.staticBackdrop = i || s.hasAttribute("data-static-backdrop") && s.dataset.staticBackdrop !== "false" || false, this.allowBodyScroll = l || s.hasAttribute("data-allow-body-scroll") && s.dataset.allowBodyScroll !== "false" || false;
210
- const c = this.offCanvasElement.getAttribute("id");
211
- this.offCanvasTriggers = this.findOffCanvasElements("[data-offcanvas-trigger]", false, c), this.offCanvasCloseBtns = this.findOffCanvasElements("[data-offcanvas-close]", true, c, this.offCanvasElement), this.backdrop = r || this.offCanvasElement.dataset.offcanvasBackdrop || "", this.teleporter = B(this.offCanvasElement, document.body, "move"), this.setupOffcanvas(), this.moveElOnInit(), h.register("offcanvas", this.offCanvasElement, this);
233
+ d.setup(this.offCanvasElement), this.options = n;
234
+ const { staticBackdrop: i, allowBodyScroll: l, backdrop: c } = this.options;
235
+ this.setupAttributes(), this.staticBackdrop = i || s.hasAttribute("data-static-backdrop") && s.dataset.staticBackdrop !== "false" || false, this.allowBodyScroll = l || s.hasAttribute("data-allow-body-scroll") && s.dataset.allowBodyScroll !== "false" || false;
236
+ const r = this.offCanvasElement.getAttribute("id");
237
+ if (!r || r === "")
238
+ throw new Error("\u274C id is required but missing on element:");
239
+ this.offCanvasId = r, this.offCanvasTriggers = this.findOffCanvasElements("[data-offcanvas-trigger]", false, r), this.offCanvasCloseBtns = this.findOffCanvasElements("[data-offcanvas-close]", true, r, this.offCanvasElement), this.backdrop = c || this.offCanvasElement.dataset.offcanvasBackdrop || "", this.dispatchEventToDocument = this.dispatchEventToDocument = this.options.dispatchEventToDocument || true, this.teleporter = A(this.offCanvasElement, document.body, "move"), this.setupOffcanvas(), this.moveElOnInit(), d.register("offcanvas", this.offCanvasElement, this), d.initialized(this.offCanvasElement);
212
240
  }
213
241
  findOffCanvasElements(e, n, s, a) {
214
- return n ? d(`${e}`, a) : d(`${e}[data-target=${s}]`);
242
+ return n ? h(`${e}`, a) : h(`${e}[data-target=${s}]`);
215
243
  }
216
244
  setupAttributes() {
217
245
  this.offCanvasElement.hasAttribute("data-fx-offcanvas") || this.offCanvasElement.setAttribute("data-fx-offcanvas", "");
@@ -231,39 +259,14 @@
231
259
  }
232
260
  initCloseBtns() {
233
261
  for (const e of this.offCanvasCloseBtns)
234
- e.addEventListener("click", this.closeOffCanvas);
262
+ e.addEventListener("click", this.closeFromCloseBtn);
235
263
  }
236
264
  initTriggers() {
237
265
  for (const e of this.offCanvasTriggers)
238
266
  e.addEventListener("click", this.changeState);
239
267
  }
240
268
  setupOffcanvas() {
241
- this.initTriggers(), this.initCloseBtns();
242
- }
243
- /**
244
- * Opens the offcanvas element.
245
- * @example
246
- * ```ts
247
- * const offcanvas = new Offcanvas('#sidebar');
248
- * offcanvas.open();
249
- * ```
250
- */
251
- open() {
252
- this.openOffCanvas();
253
- }
254
- /**
255
- * Closes the offcanvas element.
256
- * This method will trigger the beforeHide callback if provided,
257
- * remove the backdrop if present, and finally trigger the onHide callback.
258
- *
259
- * @example
260
- * ```ts
261
- * const offcanvas = new Offcanvas('#sidebar');
262
- * offcanvas.close();
263
- * ```
264
- */
265
- close() {
266
- this.closeOffCanvas();
269
+ this.initTriggers(), this.initCloseBtns(), this.dispatchEventToDocument && document.addEventListener(`sheet:${this.offCanvasId}:open`, this.open), this.dispatchEventToDocument && document.addEventListener(`sheet:${this.offCanvasId}:close`, this.close);
267
270
  }
268
271
  /**
269
272
  * Cleans up the offcanvas instance by removing event listeners and references.
@@ -281,11 +284,11 @@
281
284
  e.removeEventListener("click", this.changeState);
282
285
  for (const e of this.offCanvasCloseBtns)
283
286
  e.removeEventListener("click", this.closeOffCanvas);
284
- document.removeEventListener("keydown", this.closeWithEsc), this.allowBodyScroll || document.removeEventListener("click", this.closeWhenClickOutSide), h.removeInstance("offcanvas", this.offCanvasElement);
287
+ document.removeEventListener("keydown", this.closeWithEsc), this.allowBodyScroll || document.removeEventListener("click", this.closeWhenClickOutSide), this.dispatchEventToDocument && document.removeEventListener(`sheet:${this.offCanvasId}:open`, this.open), this.dispatchEventToDocument && document.removeEventListener(`sheet:${this.offCanvasId}:close`, this.close), d.removeInstance("offcanvas", this.offCanvasElement);
285
288
  }
286
289
  };
287
290
  o(f, "autoInit", (e = "[data-fx-offcanvas]") => {
288
- const n = d(e);
291
+ const n = h(e);
289
292
  for (const s of n)
290
293
  new f(s);
291
294
  }), /**
package/dist/cdn.min.js CHANGED
@@ -1 +1 @@
1
- (()=>{var x=Object.defineProperty,S=(t,e,s)=>e in t?x(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,o=(t,e,s)=>S(t,typeof e!="symbol"?e+"":e,s),E=(t,e=document.body)=>e.querySelector(t),m=(t,e=document.body)=>Array.from(e.querySelectorAll(t)),A=({newElement:t,existingElement:e})=>{if(!(t instanceof HTMLElement)||!(e instanceof HTMLElement))throw new Error("Both parameters must be valid HTML elements.");let s=e.parentElement;if(s)s.insertBefore(t,e);else throw new Error("Existing element must have a parent element.")},T=({element:t,callback:e,type:s,keysCheck:n})=>{let a=getComputedStyle(t),i=a.transition;if(i!=="none"&&i!==""&&!n.includes(i)){let l="transitionend",d=()=>{t.removeEventListener(l,d),e()};t.addEventListener(l,d,{once:!0})}else e()},$=({element:t,callback:e})=>{T({element:t,callback:e,type:"transition",keysCheck:["all 0s ease 0s","all"]})},p=(t,e,s)=>{let n=new CustomEvent(e,{detail:s});t.dispatchEvent(n)};function H(t,e,s="move"){if(!(t instanceof HTMLElement))throw new Error("Source element must be an HTMLElement");if(!(e instanceof HTMLElement))throw new Error("Target element must be an HTMLElement");if(!["move","detachable"].includes(s))throw new Error(`Invalid teleport mode: ${s}. Must be "move" or "detachable".`);let n=document.createComment("teleporter-placeholder"),a=t.parentNode;return a?a.insertBefore(n,t):console.warn("Element has no parent; placeholder not inserted."),s==="move"?(t.parentNode&&e.appendChild(t),{append(){t.parentNode!==e&&e.appendChild(t)},remove(){n!=null&&n.parentNode&&t.parentNode&&n.parentNode.insertBefore(t,n)},restore(){n!=null&&n.parentNode&&t.parentNode!==a&&n.parentNode.insertBefore(t,n)}}):(t.parentNode&&e.appendChild(t),{append(){e.contains(t)||e.appendChild(t)},remove(){t.parentNode&&t.remove()},restore(){n!=null&&n.parentNode&&!t.parentNode&&n.parentNode.insertBefore(t,n)}})}var N=t=>{var e;return(e=t.parentElement)==null?void 0:e.removeChild(t)},k=t=>{t.setAttribute("data-state","invisible"),$({element:t,callback(){N(t)}})},M=(t,e)=>{let s=t;if(s===""||!s)return;let n=document.createElement("div");if(n.setAttribute("aria-hidden","true"),n.setAttribute("data-state","visible"),n.setAttribute("data-fx-offcanvas-overlay",""),n.setAttribute("data-offcanvas-el",e),s==="")return;let a=s.split(" ");return s!==""&&n.classList.add(...a),n},y=(t,e,s)=>{t.setAttribute("aria-hidden",s==="open"?"false":"true"),t.setAttribute("data-state",s),e||W(s)},W=t=>{document.body.style.overflow=t==="open"?"hidden":"",document.body.style.overflowY=t==="open"?"hidden":"auto"},G=(t,e)=>{if(t===e)return;t.setAttribute("aria-hidden","true"),t.setAttribute("data-state","close");let s=E(`[data-fx-offcanvas-overlay][data-offcanvas-el=${t.getAttribute("id")}]`,t.parentElement);s instanceof HTMLElement&&k(s)},R=t=>{let e=m("[data-fx-offcanvas][data-state=open]");if(!(e.length<=0))for(let s of e)G(s,t)},c=class{static initGlobalRegistry(){window.$flexillaInstances||(window.$flexillaInstances={})}static register(e,s,n){return this.initGlobalRegistry(),window.$flexillaInstances[e]||(window.$flexillaInstances[e]=[]),this.getInstance(e,s)||(window.$flexillaInstances[e].push({element:s,instance:n}),n)}static getInstance(e,s){var n,a;return this.initGlobalRegistry(),(a=(n=window.$flexillaInstances[e])==null?void 0:n.find(i=>i.element===s))==null?void 0:a.instance}static removeInstance(e,s){this.initGlobalRegistry(),window.$flexillaInstances[e]&&(window.$flexillaInstances[e]=window.$flexillaInstances[e].filter(n=>n.element!==s))}},f=class{constructor(e,s={}){o(this,"offCanvasElement"),o(this,"offCanvasTriggers"),o(this,"offCanvasCloseBtns"),o(this,"allowBodyScroll"),o(this,"staticBackdrop"),o(this,"backdrop"),o(this,"options"),o(this,"teleporter"),o(this,"moveElOnInit",()=>{this.teleporter.append()}),o(this,"closeWhenClickOutSide",r=>{let v=this.offCanvasElement.getAttribute("data-state")==="open",h=!this.offCanvasElement.contains(r.target)&&![...this.offCanvasTriggers].includes(r.target);v&&h&&this.closeOffCanvas()}),o(this,"closeOffCanvas",()=>{var r,v,h,w,b;let g=!1;if(p(this.offCanvasElement,"offcanvas-before-hide",{offcanvasId:this.offCanvasElement.id,setExitAction:I=>{g=I}}),((h=(v=(r=this.options).beforeHide)==null?void 0:v.call(r))==null?void 0:h.cancelAction)||g)return;let B=this.offCanvasElement.getAttribute("id"),u=E(`[data-fx-offcanvas-overlay][data-offcanvas-el=${B}]`);u instanceof HTMLElement&&k(u),y(this.offCanvasElement,this.allowBodyScroll,"close"),document.removeEventListener("keydown",this.closeWithEsc),!this.allowBodyScroll&&!u&&document.removeEventListener("click",this.closeWhenClickOutSide),(b=(w=this.options).onHide)==null||b.call(w),p(this.offCanvasElement,"offcanvas-close",{offcanvasId:this.offCanvasElement.id})}),o(this,"closeWithEsc",r=>{r.key==="Escape"&&(r.preventDefault(),this.closeOffCanvas())}),o(this,"changeState",()=>{this.offCanvasElement.getAttribute("data-state")==="open"?this.closeOffCanvas():this.openOffCanvas()}),o(this,"setOptions",({allowBodyscroll:r})=>{r!==void 0&&(this.allowBodyScroll=r)});let n=typeof e=="string"?E(e):e;if(!(n instanceof HTMLElement))throw new Error("Invalid Offcanvas, the provided Element is not a valid HTMLElement");let a=c.getInstance("offcanvas",n);if(a)return a;this.options=s;let{staticBackdrop:i,allowBodyScroll:l,backdrop:d}=this.options;this.offCanvasElement=n,this.setupAttributes(),this.staticBackdrop=i||n.hasAttribute("data-static-backdrop")&&n.dataset.staticBackdrop!=="false"||!1,this.allowBodyScroll=l||n.hasAttribute("data-allow-body-scroll")&&n.dataset.allowBodyScroll!=="false"||!1;let C=this.offCanvasElement.getAttribute("id");this.offCanvasTriggers=this.findOffCanvasElements("[data-offcanvas-trigger]",!1,C),this.offCanvasCloseBtns=this.findOffCanvasElements("[data-offcanvas-close]",!0,C,this.offCanvasElement),this.backdrop=d||this.offCanvasElement.dataset.offcanvasBackdrop||"",this.teleporter=H(this.offCanvasElement,document.body,"move"),this.setupOffcanvas(),this.moveElOnInit(),c.register("offcanvas",this.offCanvasElement,this)}findOffCanvasElements(e,s,n,a){return s?m(`${e}`,a):m(`${e}[data-target=${n}]`)}setupAttributes(){this.offCanvasElement.hasAttribute("data-fx-offcanvas")||this.offCanvasElement.setAttribute("data-fx-offcanvas","")}openOffCanvas(){var e,s,n,a;(s=(e=this.options).beforeShow)==null||s.call(e),R(this.offCanvasElement),y(this.offCanvasElement,this.allowBodyScroll,"open");let i=this.offCanvasElement.getAttribute("id"),l=M(this.backdrop,i);l instanceof HTMLElement&&(A({newElement:l,existingElement:this.offCanvasElement}),this.staticBackdrop||l.addEventListener("click",this.closeOffCanvas)),document.addEventListener("keydown",this.closeWithEsc),(a=(n=this.options).onShow)==null||a.call(n),p(this.offCanvasElement,"offcanvas-open",{offcanvasId:this.offCanvasElement.id})}initCloseBtns(){for(let e of this.offCanvasCloseBtns)e.addEventListener("click",this.closeOffCanvas)}initTriggers(){for(let e of this.offCanvasTriggers)e.addEventListener("click",this.changeState)}setupOffcanvas(){this.initTriggers(),this.initCloseBtns()}open(){this.openOffCanvas()}close(){this.closeOffCanvas()}cleanup(){for(let e of this.offCanvasTriggers)e.removeEventListener("click",this.changeState);for(let e of this.offCanvasCloseBtns)e.removeEventListener("click",this.closeOffCanvas);document.removeEventListener("keydown",this.closeWithEsc),this.allowBodyScroll||document.removeEventListener("click",this.closeWhenClickOutSide),c.removeInstance("offcanvas",this.offCanvasElement)}};o(f,"autoInit",(t="[data-fx-offcanvas]")=>{let e=m(t);for(let s of e)new f(s)}),o(f,"init",(t,e={})=>new f(t,e));var L=f;function q(t){t.directive("offcanvas",(e,{},{cleanup:s})=>{let n=e.getAttribute("id");if(!n){console.error("\u274C id is required but missing on element:",e);return}let a=new L(e);t.store("sheets")||t.store("sheets",{}),t.store("sheets")[n]=a;let i=()=>a.open(),l=()=>a.close();document.addEventListener(`sheet:${n}:open`,i),document.addEventListener(`sheet:${n}:close`,l),s(()=>{document.removeEventListener(`sheet:${n}:open`,i),document.removeEventListener(`sheet:${n}:close`,l),a.cleanup(),delete t.store("sheets")[n]})}),t.magic("offcanvas",e=>s=>t.store("sheets")?t.store("sheets")[s]?t.store("sheets")[s]:(console.warn(`\u26A0\uFE0F No offcanvas instance found for ID: ${s}`),null):(console.warn("\u26A0\uFE0F Alpine store for Offcanvas is not initialized."),null))}var O=q;document.addEventListener("alpine:init",()=>{O(window.Alpine)});})();
1
+ (()=>{var T=Object.defineProperty,x=(t,e,s)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s,o=(t,e,s)=>x(t,typeof e!="symbol"?e+"":e,s),C=(t,e=document.body)=>e.querySelector(t),u=(t,e=document.body)=>Array.from(e.querySelectorAll(t)),A=({newElement:t,existingElement:e})=>{if(!(t instanceof HTMLElement)||!(e instanceof HTMLElement))throw new Error("Both parameters must be valid HTML elements.");let s=e.parentElement;if(s)s.insertBefore(t,e);else throw new Error("Existing element must have a parent element.")},$=({element:t,callback:e,type:s,keysCheck:n})=>{let a=getComputedStyle(t),l=a.transition;if(l!=="none"&&l!==""&&!n.includes(l)){let r="transitionend",h=()=>{t.removeEventListener(r,h),e()};t.addEventListener(r,h,{once:!0})}else e()},S=({element:t,callback:e})=>{$({element:t,callback:e,type:"transition",keysCheck:["all 0s ease 0s","all"]})},E=(t,e,s)=>{let n=new CustomEvent(e,{detail:s});t.dispatchEvent(n)};function H(t){let e=()=>{document.querySelector("[data-fx-component]:not([data-component-initialized])")?requestAnimationFrame(e):t()};e()}function N(t,e,s="move"){if(!(t instanceof HTMLElement))throw new Error("Source element must be an HTMLElement");if(!(e instanceof HTMLElement))throw new Error("Target element must be an HTMLElement");if(!["move","detachable"].includes(s))throw new Error(`Invalid teleport mode: ${s}. Must be "move" or "detachable".`);let n=document.createComment("teleporter-placeholder"),a=t.parentNode;return a?a.insertBefore(n,t):console.warn("Element has no parent; placeholder not inserted."),s==="move"?(t.parentNode&&e.appendChild(t),{append(){t.parentNode!==e&&e.appendChild(t)},remove(){n!=null&&n.parentNode&&t.parentNode&&n.parentNode.insertBefore(t,n)},restore(){n!=null&&n.parentNode&&t.parentNode!==a&&n.parentNode.insertBefore(t,n)}}):(t.parentNode&&e.appendChild(t),{append(){e.contains(t)||e.appendChild(t)},remove(){t.parentNode&&t.remove()},restore(){n!=null&&n.parentNode&&!t.parentNode&&n.parentNode.insertBefore(t,n)}})}var M=t=>{var e;return(e=t.parentElement)==null?void 0:e.removeChild(t)},L=t=>{t.setAttribute("data-state","invisible"),S({element:t,callback(){M(t)}})},D=(t,e)=>{let s=t;if(s===""||!s)return;let n=document.createElement("div");if(n.setAttribute("aria-hidden","true"),n.setAttribute("data-state","visible"),n.setAttribute("data-fx-offcanvas-overlay",""),n.setAttribute("data-offcanvas-el",e),s==="")return;let a=s.split(" ");return s!==""&&n.classList.add(...a),n},y=(t,e,s)=>{t.setAttribute("aria-hidden",s==="open"?"false":"true"),t.setAttribute("data-state",s),e||W(s)},W=t=>{document.body.style.overflow=t==="open"?"hidden":"",document.body.style.overflowY=t==="open"?"hidden":"auto"},q=(t,e)=>{if(t===e)return;t.setAttribute("aria-hidden","true"),t.setAttribute("data-state","close");let s=C(`[data-fx-offcanvas-overlay][data-offcanvas-el=${t.getAttribute("id")}]`,t.parentElement);s instanceof HTMLElement&&L(s)},z=t=>{let e=u("[data-fx-offcanvas][data-state=open]");if(!(e.length<=0))for(let s of e)q(s,t)},c=class{static initGlobalRegistry(){window.$flexillaInstances||(window.$flexillaInstances={})}static register(e,s,n){return this.initGlobalRegistry(),window.$flexillaInstances[e]||(window.$flexillaInstances[e]=[]),this.getInstance(e,s)||(window.$flexillaInstances[e].push({element:s,instance:n}),n)}static getInstance(e,s){var n,a;return this.initGlobalRegistry(),(a=(n=window.$flexillaInstances[e])==null?void 0:n.find(l=>l.element===s))==null?void 0:a.instance}static removeInstance(e,s){this.initGlobalRegistry(),window.$flexillaInstances[e]&&(window.$flexillaInstances[e]=window.$flexillaInstances[e].filter(n=>n.element!==s))}static setup(e){e.setAttribute("data-fx-component","fx")}static initialized(e){e.setAttribute("data-component-initialized","initialized")}},d=class{constructor(e,s={}){o(this,"offCanvasElement"),o(this,"offCanvasTriggers"),o(this,"offCanvasCloseBtns"),o(this,"offCanvasId",""),o(this,"dispatchEventToDocument"),o(this,"allowBodyScroll"),o(this,"staticBackdrop"),o(this,"backdrop"),o(this,"options"),o(this,"teleporter"),o(this,"moveElOnInit",()=>{H(()=>this.teleporter.append())}),o(this,"closeWhenClickOutSide",i=>{let v=this.offCanvasElement.getAttribute("data-state")==="open",m=!this.offCanvasElement.contains(i.target)&&![...this.offCanvasTriggers].includes(i.target);v&&m&&this.closeOffCanvas()}),o(this,"closeOffCanvas",()=>{var i,v,m,b,w;let g=!1;if(E(this.offCanvasElement,"offcanvas-before-hide",{offcanvasId:this.offCanvasElement.id,setExitAction:O=>{g=O}}),((m=(v=(i=this.options).beforeHide)==null?void 0:v.call(i))==null?void 0:m.cancelAction)||g)return;let I=this.offCanvasElement.getAttribute("id"),p=C(`[data-fx-offcanvas-overlay][data-offcanvas-el=${I}]`);p instanceof HTMLElement&&L(p),this.offCanvasElement.blur(),y(this.offCanvasElement,this.allowBodyScroll,"close"),document.removeEventListener("keydown",this.closeWithEsc),!this.allowBodyScroll&&!p&&document.removeEventListener("click",this.closeWhenClickOutSide),(w=(b=this.options).onHide)==null||w.call(b),E(this.offCanvasElement,"offcanvas-close",{offcanvasId:this.offCanvasElement.id})}),o(this,"closeWithEsc",i=>{i.key==="Escape"&&(i.preventDefault(),this.closeOffCanvas())}),o(this,"closeFromCloseBtn",i=>{i.target.blur(),this.closeOffCanvas()}),o(this,"changeState",()=>{this.offCanvasElement.getAttribute("data-state")==="open"?this.closeOffCanvas():this.openOffCanvas()}),o(this,"open",()=>{this.openOffCanvas()}),o(this,"close",()=>{this.closeOffCanvas()}),o(this,"setOptions",({allowBodyscroll:i})=>{i!==void 0&&(this.allowBodyScroll=i)});let n=typeof e=="string"?C(e):e;if(!(n instanceof HTMLElement))throw new Error("Invalid Offcanvas, the provided Element is not a valid HTMLElement");this.offCanvasElement=n;let a=c.getInstance("offcanvas",n);if(a)return a;c.setup(this.offCanvasElement),this.options=s;let{staticBackdrop:l,allowBodyScroll:r,backdrop:h}=this.options;this.setupAttributes(),this.staticBackdrop=l||n.hasAttribute("data-static-backdrop")&&n.dataset.staticBackdrop!=="false"||!1,this.allowBodyScroll=r||n.hasAttribute("data-allow-body-scroll")&&n.dataset.allowBodyScroll!=="false"||!1;let f=this.offCanvasElement.getAttribute("id");if(!f||f==="")throw new Error("\u274C id is required but missing on element:");this.offCanvasId=f,this.offCanvasTriggers=this.findOffCanvasElements("[data-offcanvas-trigger]",!1,f),this.offCanvasCloseBtns=this.findOffCanvasElements("[data-offcanvas-close]",!0,f,this.offCanvasElement),this.backdrop=h||this.offCanvasElement.dataset.offcanvasBackdrop||"",this.dispatchEventToDocument=this.dispatchEventToDocument=this.options.dispatchEventToDocument||!0,this.teleporter=N(this.offCanvasElement,document.body,"move"),this.setupOffcanvas(),this.moveElOnInit(),c.register("offcanvas",this.offCanvasElement,this),c.initialized(this.offCanvasElement)}findOffCanvasElements(e,s,n,a){return s?u(`${e}`,a):u(`${e}[data-target=${n}]`)}setupAttributes(){this.offCanvasElement.hasAttribute("data-fx-offcanvas")||this.offCanvasElement.setAttribute("data-fx-offcanvas","")}openOffCanvas(){var e,s,n,a;(s=(e=this.options).beforeShow)==null||s.call(e),z(this.offCanvasElement),y(this.offCanvasElement,this.allowBodyScroll,"open");let l=this.offCanvasElement.getAttribute("id"),r=D(this.backdrop,l);r instanceof HTMLElement&&(A({newElement:r,existingElement:this.offCanvasElement}),this.staticBackdrop||r.addEventListener("click",this.closeOffCanvas)),document.addEventListener("keydown",this.closeWithEsc),(a=(n=this.options).onShow)==null||a.call(n),E(this.offCanvasElement,"offcanvas-open",{offcanvasId:this.offCanvasElement.id})}initCloseBtns(){for(let e of this.offCanvasCloseBtns)e.addEventListener("click",this.closeFromCloseBtn)}initTriggers(){for(let e of this.offCanvasTriggers)e.addEventListener("click",this.changeState)}setupOffcanvas(){this.initTriggers(),this.initCloseBtns(),this.dispatchEventToDocument&&document.addEventListener(`sheet:${this.offCanvasId}:open`,this.open),this.dispatchEventToDocument&&document.addEventListener(`sheet:${this.offCanvasId}:close`,this.close)}cleanup(){for(let e of this.offCanvasTriggers)e.removeEventListener("click",this.changeState);for(let e of this.offCanvasCloseBtns)e.removeEventListener("click",this.closeOffCanvas);document.removeEventListener("keydown",this.closeWithEsc),this.allowBodyScroll||document.removeEventListener("click",this.closeWhenClickOutSide),this.dispatchEventToDocument&&document.removeEventListener(`sheet:${this.offCanvasId}:open`,this.open),this.dispatchEventToDocument&&document.removeEventListener(`sheet:${this.offCanvasId}:close`,this.close),c.removeInstance("offcanvas",this.offCanvasElement)}};o(d,"autoInit",(t="[data-fx-offcanvas]")=>{let e=u(t);for(let s of e)new d(s)}),o(d,"init",(t,e={})=>new d(t,e));var k=d;function F(t){t.directive("offcanvas",(e,{},{cleanup:s})=>{let n=e.getAttribute("id");if(!n){console.error("\u274C id is required but missing on element:",e);return}let a=new k(e);t.store("sheets")||t.store("sheets",{}),t.store("sheets")[n]=a;let l=()=>a.open(),r=()=>a.close();document.addEventListener(`sheet:${n}:open`,l),document.addEventListener(`sheet:${n}:close`,r),s(()=>{document.removeEventListener(`sheet:${n}:open`,l),document.removeEventListener(`sheet:${n}:close`,r),a.cleanup(),delete t.store("sheets")[n]})}),t.magic("offcanvas",e=>s=>t.store("sheets")?t.store("sheets")[s]?t.store("sheets")[s]:(console.warn(`\u26A0\uFE0F No offcanvas instance found for ID: ${s}`),null):(console.warn("\u26A0\uFE0F Alpine store for Offcanvas is not initialized."),null))}var B=F;document.addEventListener("alpine:init",()=>{B(window.Alpine)});})();
@@ -24,11 +24,11 @@ __export(module_exports, {
24
24
  module.exports = __toCommonJS(module_exports);
25
25
 
26
26
  // ../../node_modules/@flexilla/offcanvas/dist/offcanvas.js
27
- var w = Object.defineProperty;
28
- var b = (t, e, n) => e in t ? w(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n;
29
- var o = (t, e, n) => b(t, typeof e != "symbol" ? e + "" : e, n);
27
+ var g = Object.defineProperty;
28
+ var w = (t, e, n) => e in t ? g(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n;
29
+ var o = (t, e, n) => w(t, typeof e != "symbol" ? e + "" : e, n);
30
30
  var m = (t, e = document.body) => e.querySelector(t);
31
- var d = (t, e = document.body) => Array.from(e.querySelectorAll(t));
31
+ var h = (t, e = document.body) => Array.from(e.querySelectorAll(t));
32
32
  var y = ({
33
33
  newElement: t,
34
34
  existingElement: e
@@ -49,10 +49,10 @@ var k = ({
49
49
  }) => {
50
50
  const a = getComputedStyle(t), i = a.transition;
51
51
  if (i !== "none" && i !== "" && !s.includes(i)) {
52
- const l = "transitionend", r = () => {
53
- t.removeEventListener(l, r), e();
52
+ const l = "transitionend", c = () => {
53
+ t.removeEventListener(l, c), e();
54
54
  };
55
- t.addEventListener(l, r, { once: true });
55
+ t.addEventListener(l, c, { once: true });
56
56
  } else
57
57
  e();
58
58
  };
@@ -71,7 +71,15 @@ var v = (t, e, n) => {
71
71
  const s = new CustomEvent(e, { detail: n });
72
72
  t.dispatchEvent(s);
73
73
  };
74
- function B(t, e, n = "move") {
74
+ function B(t) {
75
+ const e = () => {
76
+ document.querySelector(
77
+ "[data-fx-component]:not([data-component-initialized])"
78
+ ) ? requestAnimationFrame(e) : t();
79
+ };
80
+ e();
81
+ }
82
+ function A(t, e, n = "move") {
75
83
  if (!(t instanceof HTMLElement))
76
84
  throw new Error("Source element must be an HTMLElement");
77
85
  if (!(e instanceof HTMLElement))
@@ -102,7 +110,7 @@ function B(t, e, n = "move") {
102
110
  }
103
111
  });
104
112
  }
105
- var A = (t) => {
113
+ var I = (t) => {
106
114
  var e;
107
115
  return (e = t.parentElement) == null ? void 0 : e.removeChild(t);
108
116
  };
@@ -110,7 +118,7 @@ var C = (t) => {
110
118
  t.setAttribute("data-state", "invisible"), O({
111
119
  element: t,
112
120
  callback() {
113
- A(t);
121
+ I(t);
114
122
  }
115
123
  });
116
124
  };
@@ -130,7 +138,7 @@ var u = (t, e, n) => {
130
138
  var S = (t) => {
131
139
  document.body.style.overflow = t === "open" ? "hidden" : "", document.body.style.overflowY = t === "open" ? "hidden" : "auto";
132
140
  };
133
- var I = (t, e) => {
141
+ var T = (t, e) => {
134
142
  if (t === e)
135
143
  return;
136
144
  t.setAttribute("aria-hidden", "true"), t.setAttribute("data-state", "close");
@@ -138,12 +146,12 @@ var I = (t, e) => {
138
146
  n instanceof HTMLElement && C(n);
139
147
  };
140
148
  var x = (t) => {
141
- const e = d("[data-fx-offcanvas][data-state=open]");
149
+ const e = h("[data-fx-offcanvas][data-state=open]");
142
150
  if (!(e.length <= 0))
143
151
  for (const n of e)
144
- I(n, t);
152
+ T(n, t);
145
153
  };
146
- var h = class {
154
+ var d = class {
147
155
  static initGlobalRegistry() {
148
156
  window.$flexillaInstances || (window.$flexillaInstances = {});
149
157
  }
@@ -161,6 +169,12 @@ var h = class {
161
169
  (s) => s.element !== n
162
170
  ));
163
171
  }
172
+ static setup(e) {
173
+ e.setAttribute("data-fx-component", "fx");
174
+ }
175
+ static initialized(e) {
176
+ e.setAttribute("data-component-initialized", "initialized");
177
+ }
164
178
  };
165
179
  var f = class f2 {
166
180
  /**
@@ -184,58 +198,72 @@ var f = class f2 {
184
198
  o(this, "offCanvasElement");
185
199
  o(this, "offCanvasTriggers");
186
200
  o(this, "offCanvasCloseBtns");
201
+ o(this, "offCanvasId", "");
202
+ o(this, "dispatchEventToDocument");
187
203
  o(this, "allowBodyScroll");
188
204
  o(this, "staticBackdrop");
189
205
  o(this, "backdrop");
190
206
  o(this, "options");
191
207
  o(this, "teleporter");
192
208
  o(this, "moveElOnInit", () => {
193
- this.teleporter.append();
209
+ B(() => this.teleporter.append());
194
210
  });
195
211
  o(this, "closeWhenClickOutSide", (e2) => {
196
212
  const n2 = this.offCanvasElement.getAttribute("data-state") === "open", s2 = !this.offCanvasElement.contains(e2.target) && ![...this.offCanvasTriggers].includes(e2.target);
197
213
  n2 && s2 && this.closeOffCanvas();
198
214
  });
199
215
  o(this, "closeOffCanvas", () => {
200
- var i2, l2, r2, c2, p;
216
+ var i2, l2, c2, r2, p;
201
217
  let e2 = false;
202
218
  if (v(this.offCanvasElement, "offcanvas-before-hide", {
203
219
  offcanvasId: this.offCanvasElement.id,
204
- setExitAction: (g) => {
205
- e2 = g;
220
+ setExitAction: (b) => {
221
+ e2 = b;
206
222
  }
207
- }), ((r2 = (l2 = (i2 = this.options).beforeHide) == null ? void 0 : l2.call(i2)) == null ? void 0 : r2.cancelAction) || e2)
223
+ }), ((c2 = (l2 = (i2 = this.options).beforeHide) == null ? void 0 : l2.call(i2)) == null ? void 0 : c2.cancelAction) || e2)
208
224
  return;
209
225
  const s2 = this.offCanvasElement.getAttribute("id"), a2 = m(`[data-fx-offcanvas-overlay][data-offcanvas-el=${s2}]`);
210
- a2 instanceof HTMLElement && C(a2), u(
226
+ a2 instanceof HTMLElement && C(a2), this.offCanvasElement.blur(), u(
211
227
  this.offCanvasElement,
212
228
  this.allowBodyScroll,
213
229
  "close"
214
- ), document.removeEventListener("keydown", this.closeWithEsc), !this.allowBodyScroll && !a2 && document.removeEventListener("click", this.closeWhenClickOutSide), (p = (c2 = this.options).onHide) == null || p.call(c2), v(this.offCanvasElement, "offcanvas-close", { offcanvasId: this.offCanvasElement.id });
230
+ ), document.removeEventListener("keydown", this.closeWithEsc), !this.allowBodyScroll && !a2 && document.removeEventListener("click", this.closeWhenClickOutSide), (p = (r2 = this.options).onHide) == null || p.call(r2), v(this.offCanvasElement, "offcanvas-close", { offcanvasId: this.offCanvasElement.id });
215
231
  });
216
232
  o(this, "closeWithEsc", (e2) => {
217
233
  e2.key === "Escape" && (e2.preventDefault(), this.closeOffCanvas());
218
234
  });
235
+ o(this, "closeFromCloseBtn", (e2) => {
236
+ e2.target.blur(), this.closeOffCanvas();
237
+ });
219
238
  o(this, "changeState", () => {
220
239
  this.offCanvasElement.getAttribute("data-state") === "open" ? this.closeOffCanvas() : this.openOffCanvas();
221
240
  });
241
+ o(this, "open", () => {
242
+ this.openOffCanvas();
243
+ });
244
+ o(this, "close", () => {
245
+ this.closeOffCanvas();
246
+ });
222
247
  o(this, "setOptions", ({ allowBodyscroll: e2 }) => {
223
248
  e2 !== void 0 && (this.allowBodyScroll = e2);
224
249
  });
225
250
  const s = typeof e == "string" ? m(e) : e;
226
251
  if (!(s instanceof HTMLElement))
227
252
  throw new Error("Invalid Offcanvas, the provided Element is not a valid HTMLElement");
228
- const a = h.getInstance("offcanvas", s);
253
+ this.offCanvasElement = s;
254
+ const a = d.getInstance("offcanvas", s);
229
255
  if (a)
230
256
  return a;
231
- this.options = n;
232
- const { staticBackdrop: i, allowBodyScroll: l, backdrop: r } = this.options;
233
- this.offCanvasElement = s, this.setupAttributes(), this.staticBackdrop = i || s.hasAttribute("data-static-backdrop") && s.dataset.staticBackdrop !== "false" || false, this.allowBodyScroll = l || s.hasAttribute("data-allow-body-scroll") && s.dataset.allowBodyScroll !== "false" || false;
234
- const c = this.offCanvasElement.getAttribute("id");
235
- this.offCanvasTriggers = this.findOffCanvasElements("[data-offcanvas-trigger]", false, c), this.offCanvasCloseBtns = this.findOffCanvasElements("[data-offcanvas-close]", true, c, this.offCanvasElement), this.backdrop = r || this.offCanvasElement.dataset.offcanvasBackdrop || "", this.teleporter = B(this.offCanvasElement, document.body, "move"), this.setupOffcanvas(), this.moveElOnInit(), h.register("offcanvas", this.offCanvasElement, this);
257
+ d.setup(this.offCanvasElement), this.options = n;
258
+ const { staticBackdrop: i, allowBodyScroll: l, backdrop: c } = this.options;
259
+ this.setupAttributes(), this.staticBackdrop = i || s.hasAttribute("data-static-backdrop") && s.dataset.staticBackdrop !== "false" || false, this.allowBodyScroll = l || s.hasAttribute("data-allow-body-scroll") && s.dataset.allowBodyScroll !== "false" || false;
260
+ const r = this.offCanvasElement.getAttribute("id");
261
+ if (!r || r === "")
262
+ throw new Error("\u274C id is required but missing on element:");
263
+ this.offCanvasId = r, this.offCanvasTriggers = this.findOffCanvasElements("[data-offcanvas-trigger]", false, r), this.offCanvasCloseBtns = this.findOffCanvasElements("[data-offcanvas-close]", true, r, this.offCanvasElement), this.backdrop = c || this.offCanvasElement.dataset.offcanvasBackdrop || "", this.dispatchEventToDocument = this.dispatchEventToDocument = this.options.dispatchEventToDocument || true, this.teleporter = A(this.offCanvasElement, document.body, "move"), this.setupOffcanvas(), this.moveElOnInit(), d.register("offcanvas", this.offCanvasElement, this), d.initialized(this.offCanvasElement);
236
264
  }
237
265
  findOffCanvasElements(e, n, s, a) {
238
- return n ? d(`${e}`, a) : d(`${e}[data-target=${s}]`);
266
+ return n ? h(`${e}`, a) : h(`${e}[data-target=${s}]`);
239
267
  }
240
268
  setupAttributes() {
241
269
  this.offCanvasElement.hasAttribute("data-fx-offcanvas") || this.offCanvasElement.setAttribute("data-fx-offcanvas", "");
@@ -255,39 +283,14 @@ var f = class f2 {
255
283
  }
256
284
  initCloseBtns() {
257
285
  for (const e of this.offCanvasCloseBtns)
258
- e.addEventListener("click", this.closeOffCanvas);
286
+ e.addEventListener("click", this.closeFromCloseBtn);
259
287
  }
260
288
  initTriggers() {
261
289
  for (const e of this.offCanvasTriggers)
262
290
  e.addEventListener("click", this.changeState);
263
291
  }
264
292
  setupOffcanvas() {
265
- this.initTriggers(), this.initCloseBtns();
266
- }
267
- /**
268
- * Opens the offcanvas element.
269
- * @example
270
- * ```ts
271
- * const offcanvas = new Offcanvas('#sidebar');
272
- * offcanvas.open();
273
- * ```
274
- */
275
- open() {
276
- this.openOffCanvas();
277
- }
278
- /**
279
- * Closes the offcanvas element.
280
- * This method will trigger the beforeHide callback if provided,
281
- * remove the backdrop if present, and finally trigger the onHide callback.
282
- *
283
- * @example
284
- * ```ts
285
- * const offcanvas = new Offcanvas('#sidebar');
286
- * offcanvas.close();
287
- * ```
288
- */
289
- close() {
290
- this.closeOffCanvas();
293
+ this.initTriggers(), this.initCloseBtns(), this.dispatchEventToDocument && document.addEventListener(`sheet:${this.offCanvasId}:open`, this.open), this.dispatchEventToDocument && document.addEventListener(`sheet:${this.offCanvasId}:close`, this.close);
291
294
  }
292
295
  /**
293
296
  * Cleans up the offcanvas instance by removing event listeners and references.
@@ -305,11 +308,11 @@ var f = class f2 {
305
308
  e.removeEventListener("click", this.changeState);
306
309
  for (const e of this.offCanvasCloseBtns)
307
310
  e.removeEventListener("click", this.closeOffCanvas);
308
- document.removeEventListener("keydown", this.closeWithEsc), this.allowBodyScroll || document.removeEventListener("click", this.closeWhenClickOutSide), h.removeInstance("offcanvas", this.offCanvasElement);
311
+ document.removeEventListener("keydown", this.closeWithEsc), this.allowBodyScroll || document.removeEventListener("click", this.closeWhenClickOutSide), this.dispatchEventToDocument && document.removeEventListener(`sheet:${this.offCanvasId}:open`, this.open), this.dispatchEventToDocument && document.removeEventListener(`sheet:${this.offCanvasId}:close`, this.close), d.removeInstance("offcanvas", this.offCanvasElement);
309
312
  }
310
313
  };
311
314
  o(f, "autoInit", (e = "[data-fx-offcanvas]") => {
312
- const n = d(e);
315
+ const n = h(e);
313
316
  for (const s of n)
314
317
  new f(s);
315
318
  }), /**
@@ -1,9 +1,9 @@
1
1
  // ../../node_modules/@flexilla/offcanvas/dist/offcanvas.js
2
- var w = Object.defineProperty;
3
- var b = (t, e, n) => e in t ? w(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n;
4
- var o = (t, e, n) => b(t, typeof e != "symbol" ? e + "" : e, n);
2
+ var g = Object.defineProperty;
3
+ var w = (t, e, n) => e in t ? g(t, e, { enumerable: true, configurable: true, writable: true, value: n }) : t[e] = n;
4
+ var o = (t, e, n) => w(t, typeof e != "symbol" ? e + "" : e, n);
5
5
  var m = (t, e = document.body) => e.querySelector(t);
6
- var d = (t, e = document.body) => Array.from(e.querySelectorAll(t));
6
+ var h = (t, e = document.body) => Array.from(e.querySelectorAll(t));
7
7
  var y = ({
8
8
  newElement: t,
9
9
  existingElement: e
@@ -24,10 +24,10 @@ var k = ({
24
24
  }) => {
25
25
  const a = getComputedStyle(t), i = a.transition;
26
26
  if (i !== "none" && i !== "" && !s.includes(i)) {
27
- const l = "transitionend", r = () => {
28
- t.removeEventListener(l, r), e();
27
+ const l = "transitionend", c = () => {
28
+ t.removeEventListener(l, c), e();
29
29
  };
30
- t.addEventListener(l, r, { once: true });
30
+ t.addEventListener(l, c, { once: true });
31
31
  } else
32
32
  e();
33
33
  };
@@ -46,7 +46,15 @@ var v = (t, e, n) => {
46
46
  const s = new CustomEvent(e, { detail: n });
47
47
  t.dispatchEvent(s);
48
48
  };
49
- function B(t, e, n = "move") {
49
+ function B(t) {
50
+ const e = () => {
51
+ document.querySelector(
52
+ "[data-fx-component]:not([data-component-initialized])"
53
+ ) ? requestAnimationFrame(e) : t();
54
+ };
55
+ e();
56
+ }
57
+ function A(t, e, n = "move") {
50
58
  if (!(t instanceof HTMLElement))
51
59
  throw new Error("Source element must be an HTMLElement");
52
60
  if (!(e instanceof HTMLElement))
@@ -77,7 +85,7 @@ function B(t, e, n = "move") {
77
85
  }
78
86
  });
79
87
  }
80
- var A = (t) => {
88
+ var I = (t) => {
81
89
  var e;
82
90
  return (e = t.parentElement) == null ? void 0 : e.removeChild(t);
83
91
  };
@@ -85,7 +93,7 @@ var C = (t) => {
85
93
  t.setAttribute("data-state", "invisible"), O({
86
94
  element: t,
87
95
  callback() {
88
- A(t);
96
+ I(t);
89
97
  }
90
98
  });
91
99
  };
@@ -105,7 +113,7 @@ var u = (t, e, n) => {
105
113
  var S = (t) => {
106
114
  document.body.style.overflow = t === "open" ? "hidden" : "", document.body.style.overflowY = t === "open" ? "hidden" : "auto";
107
115
  };
108
- var I = (t, e) => {
116
+ var T = (t, e) => {
109
117
  if (t === e)
110
118
  return;
111
119
  t.setAttribute("aria-hidden", "true"), t.setAttribute("data-state", "close");
@@ -113,12 +121,12 @@ var I = (t, e) => {
113
121
  n instanceof HTMLElement && C(n);
114
122
  };
115
123
  var x = (t) => {
116
- const e = d("[data-fx-offcanvas][data-state=open]");
124
+ const e = h("[data-fx-offcanvas][data-state=open]");
117
125
  if (!(e.length <= 0))
118
126
  for (const n of e)
119
- I(n, t);
127
+ T(n, t);
120
128
  };
121
- var h = class {
129
+ var d = class {
122
130
  static initGlobalRegistry() {
123
131
  window.$flexillaInstances || (window.$flexillaInstances = {});
124
132
  }
@@ -136,6 +144,12 @@ var h = class {
136
144
  (s) => s.element !== n
137
145
  ));
138
146
  }
147
+ static setup(e) {
148
+ e.setAttribute("data-fx-component", "fx");
149
+ }
150
+ static initialized(e) {
151
+ e.setAttribute("data-component-initialized", "initialized");
152
+ }
139
153
  };
140
154
  var f = class f2 {
141
155
  /**
@@ -159,58 +173,72 @@ var f = class f2 {
159
173
  o(this, "offCanvasElement");
160
174
  o(this, "offCanvasTriggers");
161
175
  o(this, "offCanvasCloseBtns");
176
+ o(this, "offCanvasId", "");
177
+ o(this, "dispatchEventToDocument");
162
178
  o(this, "allowBodyScroll");
163
179
  o(this, "staticBackdrop");
164
180
  o(this, "backdrop");
165
181
  o(this, "options");
166
182
  o(this, "teleporter");
167
183
  o(this, "moveElOnInit", () => {
168
- this.teleporter.append();
184
+ B(() => this.teleporter.append());
169
185
  });
170
186
  o(this, "closeWhenClickOutSide", (e2) => {
171
187
  const n2 = this.offCanvasElement.getAttribute("data-state") === "open", s2 = !this.offCanvasElement.contains(e2.target) && ![...this.offCanvasTriggers].includes(e2.target);
172
188
  n2 && s2 && this.closeOffCanvas();
173
189
  });
174
190
  o(this, "closeOffCanvas", () => {
175
- var i2, l2, r2, c2, p;
191
+ var i2, l2, c2, r2, p;
176
192
  let e2 = false;
177
193
  if (v(this.offCanvasElement, "offcanvas-before-hide", {
178
194
  offcanvasId: this.offCanvasElement.id,
179
- setExitAction: (g) => {
180
- e2 = g;
195
+ setExitAction: (b) => {
196
+ e2 = b;
181
197
  }
182
- }), ((r2 = (l2 = (i2 = this.options).beforeHide) == null ? void 0 : l2.call(i2)) == null ? void 0 : r2.cancelAction) || e2)
198
+ }), ((c2 = (l2 = (i2 = this.options).beforeHide) == null ? void 0 : l2.call(i2)) == null ? void 0 : c2.cancelAction) || e2)
183
199
  return;
184
200
  const s2 = this.offCanvasElement.getAttribute("id"), a2 = m(`[data-fx-offcanvas-overlay][data-offcanvas-el=${s2}]`);
185
- a2 instanceof HTMLElement && C(a2), u(
201
+ a2 instanceof HTMLElement && C(a2), this.offCanvasElement.blur(), u(
186
202
  this.offCanvasElement,
187
203
  this.allowBodyScroll,
188
204
  "close"
189
- ), document.removeEventListener("keydown", this.closeWithEsc), !this.allowBodyScroll && !a2 && document.removeEventListener("click", this.closeWhenClickOutSide), (p = (c2 = this.options).onHide) == null || p.call(c2), v(this.offCanvasElement, "offcanvas-close", { offcanvasId: this.offCanvasElement.id });
205
+ ), document.removeEventListener("keydown", this.closeWithEsc), !this.allowBodyScroll && !a2 && document.removeEventListener("click", this.closeWhenClickOutSide), (p = (r2 = this.options).onHide) == null || p.call(r2), v(this.offCanvasElement, "offcanvas-close", { offcanvasId: this.offCanvasElement.id });
190
206
  });
191
207
  o(this, "closeWithEsc", (e2) => {
192
208
  e2.key === "Escape" && (e2.preventDefault(), this.closeOffCanvas());
193
209
  });
210
+ o(this, "closeFromCloseBtn", (e2) => {
211
+ e2.target.blur(), this.closeOffCanvas();
212
+ });
194
213
  o(this, "changeState", () => {
195
214
  this.offCanvasElement.getAttribute("data-state") === "open" ? this.closeOffCanvas() : this.openOffCanvas();
196
215
  });
216
+ o(this, "open", () => {
217
+ this.openOffCanvas();
218
+ });
219
+ o(this, "close", () => {
220
+ this.closeOffCanvas();
221
+ });
197
222
  o(this, "setOptions", ({ allowBodyscroll: e2 }) => {
198
223
  e2 !== void 0 && (this.allowBodyScroll = e2);
199
224
  });
200
225
  const s = typeof e == "string" ? m(e) : e;
201
226
  if (!(s instanceof HTMLElement))
202
227
  throw new Error("Invalid Offcanvas, the provided Element is not a valid HTMLElement");
203
- const a = h.getInstance("offcanvas", s);
228
+ this.offCanvasElement = s;
229
+ const a = d.getInstance("offcanvas", s);
204
230
  if (a)
205
231
  return a;
206
- this.options = n;
207
- const { staticBackdrop: i, allowBodyScroll: l, backdrop: r } = this.options;
208
- this.offCanvasElement = s, this.setupAttributes(), this.staticBackdrop = i || s.hasAttribute("data-static-backdrop") && s.dataset.staticBackdrop !== "false" || false, this.allowBodyScroll = l || s.hasAttribute("data-allow-body-scroll") && s.dataset.allowBodyScroll !== "false" || false;
209
- const c = this.offCanvasElement.getAttribute("id");
210
- this.offCanvasTriggers = this.findOffCanvasElements("[data-offcanvas-trigger]", false, c), this.offCanvasCloseBtns = this.findOffCanvasElements("[data-offcanvas-close]", true, c, this.offCanvasElement), this.backdrop = r || this.offCanvasElement.dataset.offcanvasBackdrop || "", this.teleporter = B(this.offCanvasElement, document.body, "move"), this.setupOffcanvas(), this.moveElOnInit(), h.register("offcanvas", this.offCanvasElement, this);
232
+ d.setup(this.offCanvasElement), this.options = n;
233
+ const { staticBackdrop: i, allowBodyScroll: l, backdrop: c } = this.options;
234
+ this.setupAttributes(), this.staticBackdrop = i || s.hasAttribute("data-static-backdrop") && s.dataset.staticBackdrop !== "false" || false, this.allowBodyScroll = l || s.hasAttribute("data-allow-body-scroll") && s.dataset.allowBodyScroll !== "false" || false;
235
+ const r = this.offCanvasElement.getAttribute("id");
236
+ if (!r || r === "")
237
+ throw new Error("\u274C id is required but missing on element:");
238
+ this.offCanvasId = r, this.offCanvasTriggers = this.findOffCanvasElements("[data-offcanvas-trigger]", false, r), this.offCanvasCloseBtns = this.findOffCanvasElements("[data-offcanvas-close]", true, r, this.offCanvasElement), this.backdrop = c || this.offCanvasElement.dataset.offcanvasBackdrop || "", this.dispatchEventToDocument = this.dispatchEventToDocument = this.options.dispatchEventToDocument || true, this.teleporter = A(this.offCanvasElement, document.body, "move"), this.setupOffcanvas(), this.moveElOnInit(), d.register("offcanvas", this.offCanvasElement, this), d.initialized(this.offCanvasElement);
211
239
  }
212
240
  findOffCanvasElements(e, n, s, a) {
213
- return n ? d(`${e}`, a) : d(`${e}[data-target=${s}]`);
241
+ return n ? h(`${e}`, a) : h(`${e}[data-target=${s}]`);
214
242
  }
215
243
  setupAttributes() {
216
244
  this.offCanvasElement.hasAttribute("data-fx-offcanvas") || this.offCanvasElement.setAttribute("data-fx-offcanvas", "");
@@ -230,39 +258,14 @@ var f = class f2 {
230
258
  }
231
259
  initCloseBtns() {
232
260
  for (const e of this.offCanvasCloseBtns)
233
- e.addEventListener("click", this.closeOffCanvas);
261
+ e.addEventListener("click", this.closeFromCloseBtn);
234
262
  }
235
263
  initTriggers() {
236
264
  for (const e of this.offCanvasTriggers)
237
265
  e.addEventListener("click", this.changeState);
238
266
  }
239
267
  setupOffcanvas() {
240
- this.initTriggers(), this.initCloseBtns();
241
- }
242
- /**
243
- * Opens the offcanvas element.
244
- * @example
245
- * ```ts
246
- * const offcanvas = new Offcanvas('#sidebar');
247
- * offcanvas.open();
248
- * ```
249
- */
250
- open() {
251
- this.openOffCanvas();
252
- }
253
- /**
254
- * Closes the offcanvas element.
255
- * This method will trigger the beforeHide callback if provided,
256
- * remove the backdrop if present, and finally trigger the onHide callback.
257
- *
258
- * @example
259
- * ```ts
260
- * const offcanvas = new Offcanvas('#sidebar');
261
- * offcanvas.close();
262
- * ```
263
- */
264
- close() {
265
- this.closeOffCanvas();
268
+ this.initTriggers(), this.initCloseBtns(), this.dispatchEventToDocument && document.addEventListener(`sheet:${this.offCanvasId}:open`, this.open), this.dispatchEventToDocument && document.addEventListener(`sheet:${this.offCanvasId}:close`, this.close);
266
269
  }
267
270
  /**
268
271
  * Cleans up the offcanvas instance by removing event listeners and references.
@@ -280,11 +283,11 @@ var f = class f2 {
280
283
  e.removeEventListener("click", this.changeState);
281
284
  for (const e of this.offCanvasCloseBtns)
282
285
  e.removeEventListener("click", this.closeOffCanvas);
283
- document.removeEventListener("keydown", this.closeWithEsc), this.allowBodyScroll || document.removeEventListener("click", this.closeWhenClickOutSide), h.removeInstance("offcanvas", this.offCanvasElement);
286
+ document.removeEventListener("keydown", this.closeWithEsc), this.allowBodyScroll || document.removeEventListener("click", this.closeWhenClickOutSide), this.dispatchEventToDocument && document.removeEventListener(`sheet:${this.offCanvasId}:open`, this.open), this.dispatchEventToDocument && document.removeEventListener(`sheet:${this.offCanvasId}:close`, this.close), d.removeInstance("offcanvas", this.offCanvasElement);
284
287
  }
285
288
  };
286
289
  o(f, "autoInit", (e = "[data-fx-offcanvas]") => {
287
- const n = d(e);
290
+ const n = h(e);
288
291
  for (const s of n)
289
292
  new f(s);
290
293
  }), /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexilla/alpine-offcanvas",
3
- "version": "0.1.2",
3
+ "version": "0.3.0",
4
4
  "description": "AlpineJS plugin for adding offcanvas functionality to your AlpineJS components",
5
5
  "type": "module",
6
6
  "private": false,
@@ -61,7 +61,7 @@
61
61
  ],
62
62
  "dependencies": {
63
63
  "@flexilla/alpine-offcanvas": "^0.0.3",
64
- "@flexilla/offcanvas": "^2.1.1"
64
+ "@flexilla/offcanvas": "^2.2.0"
65
65
  },
66
- "gitHead": "869394b528d21d4842486a7396449aa9fbe3cbcb"
66
+ "gitHead": "c8e56ff1b93e24b1ab969b09b35afab38ca71d4c"
67
67
  }