vanilla-drawers 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,8 +22,8 @@ var ne = { exports: {} };
22
22
  function f(h, i, o, c, O) {
23
23
  if (typeof o != "function")
24
24
  throw new TypeError("The listener must be a function");
25
- var g = new s(o, c || h, O), m = e ? e + i : i;
26
- return h._events[m] ? h._events[m].fn ? h._events[m] = [h._events[m], g] : h._events[m].push(g) : (h._events[m] = g, h._eventsCount++), h;
25
+ var g = new s(o, c || h, O), w = e ? e + i : i;
26
+ return h._events[w] ? h._events[w].fn ? h._events[w] = [h._events[w], g] : h._events[w].push(g) : (h._events[w] = g, h._eventsCount++), h;
27
27
  }
28
28
  function d(h, i) {
29
29
  --h._eventsCount === 0 ? h._events = new a() : delete h._events[i];
@@ -44,17 +44,17 @@ var ne = { exports: {} };
44
44
  return [];
45
45
  if (c.fn)
46
46
  return [c.fn];
47
- for (var O = 0, g = c.length, m = new Array(g); O < g; O++)
48
- m[O] = c[O].fn;
49
- return m;
47
+ for (var O = 0, g = c.length, w = new Array(g); O < g; O++)
48
+ w[O] = c[O].fn;
49
+ return w;
50
50
  }, u.prototype.listenerCount = function(i) {
51
51
  var o = e ? e + i : i, c = this._events[o];
52
52
  return c ? c.fn ? 1 : c.length : 0;
53
- }, u.prototype.emit = function(i, o, c, O, g, m) {
53
+ }, u.prototype.emit = function(i, o, c, O, g, w) {
54
54
  var _ = e ? e + i : i;
55
55
  if (!this._events[_])
56
56
  return !1;
57
- var l = this._events[_], j = arguments.length, M, w;
57
+ var l = this._events[_], j = arguments.length, M, m;
58
58
  if (l.fn) {
59
59
  switch (l.once && this.removeListener(i, l.fn, void 0, !0), j) {
60
60
  case 1:
@@ -68,32 +68,32 @@ var ne = { exports: {} };
68
68
  case 5:
69
69
  return l.fn.call(l.context, o, c, O, g), !0;
70
70
  case 6:
71
- return l.fn.call(l.context, o, c, O, g, m), !0;
71
+ return l.fn.call(l.context, o, c, O, g, w), !0;
72
72
  }
73
- for (w = 1, M = new Array(j - 1); w < j; w++)
74
- M[w - 1] = arguments[w];
73
+ for (m = 1, M = new Array(j - 1); m < j; m++)
74
+ M[m - 1] = arguments[m];
75
75
  l.fn.apply(l.context, M);
76
76
  } else {
77
77
  var se = l.length, N;
78
- for (w = 0; w < se; w++)
79
- switch (l[w].once && this.removeListener(i, l[w].fn, void 0, !0), j) {
78
+ for (m = 0; m < se; m++)
79
+ switch (l[m].once && this.removeListener(i, l[m].fn, void 0, !0), j) {
80
80
  case 1:
81
- l[w].fn.call(l[w].context);
81
+ l[m].fn.call(l[m].context);
82
82
  break;
83
83
  case 2:
84
- l[w].fn.call(l[w].context, o);
84
+ l[m].fn.call(l[m].context, o);
85
85
  break;
86
86
  case 3:
87
- l[w].fn.call(l[w].context, o, c);
87
+ l[m].fn.call(l[m].context, o, c);
88
88
  break;
89
89
  case 4:
90
- l[w].fn.call(l[w].context, o, c, O);
90
+ l[m].fn.call(l[m].context, o, c, O);
91
91
  break;
92
92
  default:
93
93
  if (!M)
94
94
  for (N = 1, M = new Array(j - 1); N < j; N++)
95
95
  M[N - 1] = arguments[N];
96
- l[w].fn.apply(l[w].context, M);
96
+ l[m].fn.apply(l[m].context, M);
97
97
  }
98
98
  }
99
99
  return !0;
@@ -107,12 +107,12 @@ var ne = { exports: {} };
107
107
  return this;
108
108
  if (!o)
109
109
  return d(this, g), this;
110
- var m = this._events[g];
111
- if (m.fn)
112
- m.fn === o && (!O || m.once) && (!c || m.context === c) && d(this, g);
110
+ var w = this._events[g];
111
+ if (w.fn)
112
+ w.fn === o && (!O || w.once) && (!c || w.context === c) && d(this, g);
113
113
  else {
114
- for (var _ = 0, l = [], j = m.length; _ < j; _++)
115
- (m[_].fn !== o || O && !m[_].once || c && m[_].context !== c) && l.push(m[_]);
114
+ for (var _ = 0, l = [], j = w.length; _ < j; _++)
115
+ (w[_].fn !== o || O && !w[_].once || c && w[_].context !== c) && l.push(w[_]);
116
116
  l.length ? this._events[g] = l.length === 1 ? l[0] : l : d(this, g);
117
117
  }
118
118
  return this;
@@ -148,19 +148,19 @@ function pe(n, t, e) {
148
148
  return R(a, e);
149
149
  });
150
150
  }
151
- function me(n, t) {
151
+ function we(n, t) {
152
152
  if (!t.customMerge)
153
153
  return U;
154
154
  var e = t.customMerge(n);
155
155
  return typeof e == "function" ? e : U;
156
156
  }
157
- function we(n) {
157
+ function me(n) {
158
158
  return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(n).filter(function(t) {
159
159
  return Object.propertyIsEnumerable.call(n, t);
160
160
  }) : [];
161
161
  }
162
162
  function Q(n) {
163
- return Object.keys(n).concat(we(n));
163
+ return Object.keys(n).concat(me(n));
164
164
  }
165
165
  function re(n, t) {
166
166
  try {
@@ -177,7 +177,7 @@ function be(n, t, e) {
177
177
  return e.isMergeableObject(n) && Q(n).forEach(function(s) {
178
178
  a[s] = R(n[s], e);
179
179
  }), Q(t).forEach(function(s) {
180
- ye(n, s) || (re(n, s) && e.isMergeableObject(t[s]) ? a[s] = me(s, e)(n[s], t[s], e) : a[s] = R(t[s], e));
180
+ ye(n, s) || (re(n, s) && e.isMergeableObject(t[s]) ? a[s] = we(s, e)(n[s], t[s], e) : a[s] = R(t[s], e));
181
181
  }), a;
182
182
  }
183
183
  function U(n, t, e) {
@@ -336,10 +336,10 @@ class _e extends oe {
336
336
  }
337
337
  // Methods
338
338
  async open(e) {
339
- await F(0), !r(this, k) && (this.emit("beforeOpen", { drawer: this, trigger: e }), b(this, k, !0), this.dom.root.classList.add(r(this, p).openClass), this.emit("open", { drawer: this, trigger: e }), typeof r(this, p).openAnimationDuration == "number" && F(r(this, p).openAnimationDuration), this.emit("openAnimationEnd", { drawer: this, trigger: e }), this.focus(), this.addEventListeners());
339
+ await F(0), !r(this, k) && (this.emit("beforeOpen", { drawer: this, trigger: e }), b(this, k, !0), this.dom.root.classList.add(r(this, p).openClass), this.emit("open", { drawer: this, trigger: e }), typeof r(this, p).openAnimationDuration == "number" && await F(r(this, p).openAnimationDuration), this.emit("openAnimationEnd", { drawer: this, trigger: e }), this.focus(), this.addEventListeners());
340
340
  }
341
341
  async close(e) {
342
- r(this, p).onCloseConfirm && !r(this, p).onCloseConfirm(this, e) || (this.emit("beforeClose", { drawer: this, trigger: e }), this.removeEventListeners(), b(this, k, !1), this.dom.root.classList.remove(r(this, p).openClass), this.emit("close", { drawer: this, trigger: e }), typeof r(this, p).closeAnimationDuration == "number" && F(r(this, p).closeAnimationDuration), this.emit("closeAnimationEnd", { drawer: this, trigger: e }));
342
+ r(this, p).onCloseConfirm && !r(this, p).onCloseConfirm(this, e) || (this.emit("beforeClose", { drawer: this, trigger: e }), this.removeEventListeners(), b(this, k, !1), this.dom.root.classList.remove(r(this, p).openClass), this.emit("close", { drawer: this, trigger: e }), typeof r(this, p).closeAnimationDuration == "number" && await F(r(this, p).closeAnimationDuration), this.emit("closeAnimationEnd", { drawer: this, trigger: e }));
343
343
  }
344
344
  handleOtherDrawerClick(e) {
345
345
  }
@@ -1,6 +1,6 @@
1
- (function(p,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(p=typeof globalThis<"u"?globalThis:p||self,b(p.Drawers={}))})(this,function(p){"use strict";var oe=(p,b,C)=>{if(!b.has(p))throw TypeError("Cannot "+C)};var t=(p,b,C)=>(oe(p,b,"read from private field"),C?C.call(p):b.get(p)),g=(p,b,C)=>{if(b.has(p))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(p):b.set(p,C)},O=(p,b,C,H)=>(oe(p,b,"write to private field"),H?H.call(p,C):b.set(p,C),C);var _,E,z,B,m,$,T,Q,U,P,j,S,N,M,k,q,G;function b(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var C={exports:{}};(function(r){var n=Object.prototype.hasOwnProperty,e="~";function a(){}Object.create&&(a.prototype=Object.create(null),new a().__proto__||(e=!1));function s(u,i,o){this.fn=u,this.context=i,this.once=o||!1}function f(u,i,o,c,A){if(typeof o!="function")throw new TypeError("The listener must be a function");var v=new s(o,c||u,A),w=e?e+i:i;return u._events[w]?u._events[w].fn?u._events[w]=[u._events[w],v]:u._events[w].push(v):(u._events[w]=v,u._eventsCount++),u}function d(u,i){--u._eventsCount===0?u._events=new a:delete u._events[i]}function h(){this._events=new a,this._eventsCount=0}h.prototype.eventNames=function(){var i=[],o,c;if(this._eventsCount===0)return i;for(c in o=this._events)n.call(o,c)&&i.push(e?c.slice(1):c);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(o)):i},h.prototype.listeners=function(i){var o=e?e+i:i,c=this._events[o];if(!c)return[];if(c.fn)return[c.fn];for(var A=0,v=c.length,w=new Array(v);A<v;A++)w[A]=c[A].fn;return w},h.prototype.listenerCount=function(i){var o=e?e+i:i,c=this._events[o];return c?c.fn?1:c.length:0},h.prototype.emit=function(i,o,c,A,v,w){var L=e?e+i:i;if(!this._events[L])return!1;var l=this._events[L],x=arguments.length,D,y;if(l.fn){switch(l.once&&this.removeListener(i,l.fn,void 0,!0),x){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,o),!0;case 3:return l.fn.call(l.context,o,c),!0;case 4:return l.fn.call(l.context,o,c,A),!0;case 5:return l.fn.call(l.context,o,c,A,v),!0;case 6:return l.fn.call(l.context,o,c,A,v,w),!0}for(y=1,D=new Array(x-1);y<x;y++)D[y-1]=arguments[y];l.fn.apply(l.context,D)}else{var je=l.length,F;for(y=0;y<je;y++)switch(l[y].once&&this.removeListener(i,l[y].fn,void 0,!0),x){case 1:l[y].fn.call(l[y].context);break;case 2:l[y].fn.call(l[y].context,o);break;case 3:l[y].fn.call(l[y].context,o,c);break;case 4:l[y].fn.call(l[y].context,o,c,A);break;default:if(!D)for(F=1,D=new Array(x-1);F<x;F++)D[F-1]=arguments[F];l[y].fn.apply(l[y].context,D)}}return!0},h.prototype.on=function(i,o,c){return f(this,i,o,c,!1)},h.prototype.once=function(i,o,c){return f(this,i,o,c,!0)},h.prototype.removeListener=function(i,o,c,A){var v=e?e+i:i;if(!this._events[v])return this;if(!o)return d(this,v),this;var w=this._events[v];if(w.fn)w.fn===o&&(!A||w.once)&&(!c||w.context===c)&&d(this,v);else{for(var L=0,l=[],x=w.length;L<x;L++)(w[L].fn!==o||A&&!w[L].once||c&&w[L].context!==c)&&l.push(w[L]);l.length?this._events[v]=l.length===1?l[0]:l:d(this,v)}return this},h.prototype.removeAllListeners=function(i){var o;return i?(o=e?e+i:i,this._events[o]&&d(this,o)):(this._events=new a,this._eventsCount=0),this},h.prototype.off=h.prototype.removeListener,h.prototype.addListener=h.prototype.on,h.prefixed=e,h.EventEmitter=h,r.exports=h})(C);var H=C.exports;const le=b(H);var ae=function(n){return ce(n)&&!ue(n)};function ce(r){return!!r&&typeof r=="object"}function ue(r){var n=Object.prototype.toString.call(r);return n==="[object RegExp]"||n==="[object Date]"||de(r)}var he=typeof Symbol=="function"&&Symbol.for,fe=he?Symbol.for("react.element"):60103;function de(r){return r.$$typeof===fe}function pe(r){return Array.isArray(r)?[]:{}}function R(r,n){return n.clone!==!1&&n.isMergeableObject(r)?I(pe(r),r,n):r}function me(r,n,e){return r.concat(n).map(function(a){return R(a,e)})}function we(r,n){if(!n.customMerge)return I;var e=n.customMerge(r);return typeof e=="function"?e:I}function ye(r){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(r).filter(function(n){return Object.propertyIsEnumerable.call(r,n)}):[]}function ee(r){return Object.keys(r).concat(ye(r))}function te(r,n){try{return n in r}catch{return!1}}function be(r,n){return te(r,n)&&!(Object.hasOwnProperty.call(r,n)&&Object.propertyIsEnumerable.call(r,n))}function ge(r,n,e){var a={};return e.isMergeableObject(r)&&ee(r).forEach(function(s){a[s]=R(r[s],e)}),ee(n).forEach(function(s){be(r,s)||(te(r,s)&&e.isMergeableObject(n[s])?a[s]=we(s,e)(r[s],n[s],e):a[s]=R(n[s],e))}),a}function I(r,n,e){e=e||{},e.arrayMerge=e.arrayMerge||me,e.isMergeableObject=e.isMergeableObject||ae,e.cloneUnlessOtherwiseSpecified=R;var a=Array.isArray(n),s=Array.isArray(r),f=a===s;return f?a?e.arrayMerge(r,n,e):ge(r,n,e):R(n,e)}I.all=function(n,e){if(!Array.isArray(n))throw new Error("first argument should be an array");return n.reduce(function(a,s){return I(a,s,e)},{})};var Oe=I,ve=Oe;const Ee=b(ve);/*!
1
+ (function(p,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(p=typeof globalThis<"u"?globalThis:p||self,b(p.Drawers={}))})(this,function(p){"use strict";var oe=(p,b,C)=>{if(!b.has(p))throw TypeError("Cannot "+C)};var t=(p,b,C)=>(oe(p,b,"read from private field"),C?C.call(p):b.get(p)),g=(p,b,C)=>{if(b.has(p))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(p):b.set(p,C)},O=(p,b,C,H)=>(oe(p,b,"write to private field"),H?H.call(p,C):b.set(p,C),C);var _,E,z,B,w,$,T,Q,U,P,j,S,N,M,k,q,G;function b(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var C={exports:{}};(function(r){var n=Object.prototype.hasOwnProperty,e="~";function l(){}Object.create&&(l.prototype=Object.create(null),new l().__proto__||(e=!1));function s(u,i,o){this.fn=u,this.context=i,this.once=o||!1}function f(u,i,o,c,A){if(typeof o!="function")throw new TypeError("The listener must be a function");var v=new s(o,c||u,A),m=e?e+i:i;return u._events[m]?u._events[m].fn?u._events[m]=[u._events[m],v]:u._events[m].push(v):(u._events[m]=v,u._eventsCount++),u}function d(u,i){--u._eventsCount===0?u._events=new l:delete u._events[i]}function h(){this._events=new l,this._eventsCount=0}h.prototype.eventNames=function(){var i=[],o,c;if(this._eventsCount===0)return i;for(c in o=this._events)n.call(o,c)&&i.push(e?c.slice(1):c);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(o)):i},h.prototype.listeners=function(i){var o=e?e+i:i,c=this._events[o];if(!c)return[];if(c.fn)return[c.fn];for(var A=0,v=c.length,m=new Array(v);A<v;A++)m[A]=c[A].fn;return m},h.prototype.listenerCount=function(i){var o=e?e+i:i,c=this._events[o];return c?c.fn?1:c.length:0},h.prototype.emit=function(i,o,c,A,v,m){var L=e?e+i:i;if(!this._events[L])return!1;var a=this._events[L],x=arguments.length,D,y;if(a.fn){switch(a.once&&this.removeListener(i,a.fn,void 0,!0),x){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,o),!0;case 3:return a.fn.call(a.context,o,c),!0;case 4:return a.fn.call(a.context,o,c,A),!0;case 5:return a.fn.call(a.context,o,c,A,v),!0;case 6:return a.fn.call(a.context,o,c,A,v,m),!0}for(y=1,D=new Array(x-1);y<x;y++)D[y-1]=arguments[y];a.fn.apply(a.context,D)}else{var je=a.length,F;for(y=0;y<je;y++)switch(a[y].once&&this.removeListener(i,a[y].fn,void 0,!0),x){case 1:a[y].fn.call(a[y].context);break;case 2:a[y].fn.call(a[y].context,o);break;case 3:a[y].fn.call(a[y].context,o,c);break;case 4:a[y].fn.call(a[y].context,o,c,A);break;default:if(!D)for(F=1,D=new Array(x-1);F<x;F++)D[F-1]=arguments[F];a[y].fn.apply(a[y].context,D)}}return!0},h.prototype.on=function(i,o,c){return f(this,i,o,c,!1)},h.prototype.once=function(i,o,c){return f(this,i,o,c,!0)},h.prototype.removeListener=function(i,o,c,A){var v=e?e+i:i;if(!this._events[v])return this;if(!o)return d(this,v),this;var m=this._events[v];if(m.fn)m.fn===o&&(!A||m.once)&&(!c||m.context===c)&&d(this,v);else{for(var L=0,a=[],x=m.length;L<x;L++)(m[L].fn!==o||A&&!m[L].once||c&&m[L].context!==c)&&a.push(m[L]);a.length?this._events[v]=a.length===1?a[0]:a:d(this,v)}return this},h.prototype.removeAllListeners=function(i){var o;return i?(o=e?e+i:i,this._events[o]&&d(this,o)):(this._events=new l,this._eventsCount=0),this},h.prototype.off=h.prototype.removeListener,h.prototype.addListener=h.prototype.on,h.prefixed=e,h.EventEmitter=h,r.exports=h})(C);var H=C.exports;const ae=b(H);var le=function(n){return ce(n)&&!ue(n)};function ce(r){return!!r&&typeof r=="object"}function ue(r){var n=Object.prototype.toString.call(r);return n==="[object RegExp]"||n==="[object Date]"||de(r)}var he=typeof Symbol=="function"&&Symbol.for,fe=he?Symbol.for("react.element"):60103;function de(r){return r.$$typeof===fe}function pe(r){return Array.isArray(r)?[]:{}}function R(r,n){return n.clone!==!1&&n.isMergeableObject(r)?I(pe(r),r,n):r}function we(r,n,e){return r.concat(n).map(function(l){return R(l,e)})}function me(r,n){if(!n.customMerge)return I;var e=n.customMerge(r);return typeof e=="function"?e:I}function ye(r){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(r).filter(function(n){return Object.propertyIsEnumerable.call(r,n)}):[]}function ee(r){return Object.keys(r).concat(ye(r))}function te(r,n){try{return n in r}catch{return!1}}function be(r,n){return te(r,n)&&!(Object.hasOwnProperty.call(r,n)&&Object.propertyIsEnumerable.call(r,n))}function ge(r,n,e){var l={};return e.isMergeableObject(r)&&ee(r).forEach(function(s){l[s]=R(r[s],e)}),ee(n).forEach(function(s){be(r,s)||(te(r,s)&&e.isMergeableObject(n[s])?l[s]=me(s,e)(r[s],n[s],e):l[s]=R(n[s],e))}),l}function I(r,n,e){e=e||{},e.arrayMerge=e.arrayMerge||we,e.isMergeableObject=e.isMergeableObject||le,e.cloneUnlessOtherwiseSpecified=R;var l=Array.isArray(n),s=Array.isArray(r),f=l===s;return f?l?e.arrayMerge(r,n,e):ge(r,n,e):R(n,e)}I.all=function(n,e){if(!Array.isArray(n))throw new Error("first argument should be an array");return n.reduce(function(l,s){return I(l,s,e)},{})};var Oe=I,ve=Oe;const Ee=b(ve);/*!
2
2
  * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
3
3
  *
4
4
  * Copyright (c) 2014-2017, Jon Schlinkert.
5
5
  * Released under the MIT License.
6
- */function ne(r){return Object.prototype.toString.call(r)==="[object Object]"}function Ae(r){var n,e;return ne(r)===!1?!1:(n=r.constructor,n===void 0?!0:(e=n.prototype,!(ne(e)===!1||e.hasOwnProperty("isPrototypeOf")===!1)))}function W(r){return r instanceof Element?r:document.querySelector(r)}async function X(r){return await new Promise(n=>setTimeout(n,r))}const Ce='[data-elem="drawer.panel"]',V="data-drawers-group",_e=["a[href]","area[href]",'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',"select:not([disabled]):not([aria-hidden])","textarea:not([disabled]):not([aria-hidden])","button:not([disabled]):not([aria-hidden])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'],re={modal:!0,focusOnChild:!0,closeOnEsc:!0,closeOnOutsideClick:!0,closeOnUnderlayClick:!0,onCloseConfirm:()=>!0,onBeforeClose:null,onClose:null,onCloseAnimationEnd:null,onBeforeOpen:null,onOpen:null,onOpenAnimationEnd:null,openClass:"drawer_open",openAnimationDuration:0,closeAnimationDuration:0,lockPageScroll:!0};function se(r){return Ee.all(r,{isMergeableObject:Ae})}class Y{constructor({target:n,type:e,owner:a}){g(this,_,void 0);g(this,E,void 0);g(this,z,void 0);g(this,B,!1);const s=W(n);if(!s)throw new Error("Trigger element cannot be found");O(this,_,s),O(this,E,a),O(this,z,e),this.init()}get isActive(){return t(this,B)}get owner(){return t(this,E)}init(){t(this,_).addEventListener("click",n=>this.clickHandler(n)),t(this,E).on("open",()=>this.setActive(!0)),t(this,E).on("close",()=>this.setActive(!1))}clickHandler(n){n.__drawerTrigger=this,t(this,z)==="open"?t(this,E).isOpen||t(this,E).open(t(this,_)):t(this,z)==="close"?t(this,E).isOpen&&t(this,E).close(t(this,_)):t(this,E).isOpen?t(this,E).close(t(this,_)):t(this,E).open(t(this,_))}setActive(n){O(this,B,n),n?t(this,_).classList.add("drawer-trigger_active"):t(this,_).classList.remove("drawer-trigger_active")}}_=new WeakMap,E=new WeakMap,z=new WeakMap,B=new WeakMap;class ie extends le{constructor({target:e,options:a}){super();g(this,m,void 0);g(this,$,void 0);g(this,T,void 0);g(this,Q,void 0);g(this,U,void 0);this.handleDocumentClick=async h=>{var o;if(((o=h.__drawerTrigger)==null?void 0:o.owner)===this)return;const u=h.target;if(h.composedPath(),this.dom.panel.contains(u))return;const i=u==null?void 0:u.closest("[data-drawer]");i?i.getAttribute("data-drawer")===t(this,U)?this.handleUnderlayClick(h):this.handleOtherDrawerClick(h):this.handleOutsideClick(h)},this.handleKeydown=h=>{t(this,m).closeOnEsc&&h.key==="Escape"&&this.close()};const s=se(a?[re,a]:[re]),f=W(e);if(f===null)throw new Error("Drawer's root cannot be found");O(this,U,f.getAttribute("data-drawer"));const d=f.querySelector(Ce);if(d===null)throw new Error(`Drawer's panel cannot be found. Alias: ${t(this,U)}`);this.dom={root:f,panel:d},this.setOptions(s),this.dom.panel.setAttribute("tabindex","-1"),this.dom.root.classList.add("drawer_initialized")}addEventListeners(){this.dom.root.addEventListener("keydown",this.handleKeydown),document.addEventListener("click",this.handleDocumentClick)}removeEventListeners(){this.dom.root.removeEventListener("keydown",this.handleKeydown),document.removeEventListener("click",this.handleDocumentClick)}get isOpen(){return t(this,T)}get isModal(){return t(this,m).modal}set isModal(e){this.dom.root.classList[e?"add":"remove"]("drawer_modal")}set zIndex(e){this.dom.root.style.setProperty("--z-index",String(e)),O(this,$,e)}get zIndex(){return t(this,$)}async open(e){await X(0),!t(this,T)&&(this.emit("beforeOpen",{drawer:this,trigger:e}),O(this,T,!0),this.dom.root.classList.add(t(this,m).openClass),this.emit("open",{drawer:this,trigger:e}),typeof t(this,m).openAnimationDuration=="number"&&X(t(this,m).openAnimationDuration),this.emit("openAnimationEnd",{drawer:this,trigger:e}),this.focus(),this.addEventListeners())}async close(e){t(this,m).onCloseConfirm&&!t(this,m).onCloseConfirm(this,e)||(this.emit("beforeClose",{drawer:this,trigger:e}),this.removeEventListeners(),O(this,T,!1),this.dom.root.classList.remove(t(this,m).openClass),this.emit("close",{drawer:this,trigger:e}),typeof t(this,m).closeAnimationDuration=="number"&&X(t(this,m).closeAnimationDuration),this.emit("closeAnimationEnd",{drawer:this,trigger:e}))}handleOtherDrawerClick(e){}handleOutsideClick(e){t(this,m).closeOnOutsideClick&&(typeof t(this,m).closeOnOutsideClick=="object"&&t(this,m).closeOnOutsideClick.hasOwnProperty("checkTarget")?t(this,m).closeOnOutsideClick.checkTarget(e.target)&&this.close():this.close())}handleUnderlayClick(e){t(this,m).closeOnOutsideClick&&this.close()}focus(){t(this,m).focusOnChild&&this.focusChild()||this.focusSelf()}focusSelf(){this.dom.panel.focus()}focusChild(){const e=this.dom.panel.querySelector(_e.join(","));return e?(e.focus(),!0):!1}setOptions(e){var a;e.hasOwnProperty("modal")&&((a=t(this,m))==null?void 0:a.modal)!==e.modal&&(this.isModal=e.modal),O(this,m,t(this,m)?se([t(this,m),e]):e)}assignGroup(e){O(this,Q,e)}}m=new WeakMap,$=new WeakMap,T=new WeakMap,Q=new WeakMap,U=new WeakMap;class Z{constructor(n){g(this,P,void 0);g(this,j,void 0);g(this,S,void 0);g(this,N,void 0);g(this,M,void 0);g(this,k,void 0);O(this,j,[]),O(this,S,[]),O(this,M,new Set),O(this,k,new Map),this.onBeforeOpen=({drawer:s,trigger:f})=>{s.isModal?(t(this,k).set(s,t(this,j).length),t(this,j).push(s),s.zIndex=t(this,S).length+t(this,j).length):(t(this,k).set(s,t(this,S).length),t(this,S).push(s),s.zIndex=t(this,S).length,t(this,j).length>0&&t(this,j).forEach((d,h)=>d.zIndex=t(this,S).length+h+1)),this.lockScroll(s)},this.onCloseAnimationEnd=({drawer:s,trigger:f})=>{const d=s.isModal?t(this,j):t(this,S);for(delete d[t(this,k).get(s)];d.length&&!d.at(-1);)d.pop();t(this,k).delete(s),this.unlockScroll(s)};const e=W(n);if(e===null)throw new Error("Drawer's group root cannot be found");O(this,P,e);const a=t(this,P).closest("[data-scrollable], html")||t(this,P).matches("[data-scrollable], html")&&t(this,P);if(a===null)throw new Error("Scrollable container for group root cannot be found");O(this,N,a)}add(n){n.on("beforeOpen",this.onBeforeOpen),n.on("closeAnimationEnd",this.onCloseAnimationEnd),n.assignGroup(this)}lockScroll(n){t(this,M).size===0&&t(this,N).classList.add("scroll-lock-by-drawer"),t(this,M).add(n)}unlockScroll(n){t(this,M).delete(n),t(this,M).size===0&&t(this,N).classList.remove("scroll-lock-by-drawer")}}P=new WeakMap,j=new WeakMap,S=new WeakMap,N=new WeakMap,M=new WeakMap,k=new WeakMap;const K=class K{constructor(){g(this,q,new Map);g(this,G,new Map);if(K.instance)return K.instance;K.instance=this}init(n){document.querySelectorAll(`[${V}]`).forEach(f=>{const d=f.getAttribute(V);typeof d=="string"&&t(this,G).set(d,new Z(f))}),t(this,G).set("default",new Z(document.documentElement)),document.querySelectorAll("[data-drawer]").forEach(f=>{var o;const d=f.getAttribute("data-drawer");if(typeof d!="string")return;const h=new ie({target:f,options:n});t(this,q).set(d,h);const u=f.closest(`[${V}]`),i=u?u.getAttribute(V):"default";if(typeof i!="string")throw new Error("Group doesn't have alias set correctly");(o=t(this,G).get(i))==null||o.add(h)}),document.querySelectorAll("[data-drawer-open], [data-drawer-close], [data-drawer-toggle]").forEach(f=>{if(f.hasAttribute("data-drawer-open")){const d=f.getAttribute("data-drawer-open");new Y({target:f,type:"open",owner:this.get(d)})}else if(f.hasAttribute("data-drawer-close")){const d=f.getAttribute("data-drawer-close");new Y({target:f,type:"close",owner:this.get(d)})}else{const d=f.getAttribute("data-drawer-toggle");new Y({target:f,type:"toggle",owner:this.get(d)})}})}open(n,{trigger:e,options:a}={}){var s;(s=this.get(n))==null||s.open(e)}close(n,{trigger:e,options:a}={}){var s;(s=this.get(n))==null||s.close(e)}get(n){return typeof n=="string"&&t(this,q).get(n)||null}on(n,e,a){var s;if(n)(s=this.get(n))==null||s.on(e,a);else for(const[f,d]of t(this,q))d.on(e,a)}};q=new WeakMap,G=new WeakMap;let J=K;typeof window<"u"&&(window.hasOwnProperty("app")||(window.app={}),window.app.drawers=new J),p.Drawer=ie,p.DrawersGroup=Z,p.Trigger=Y,p.default=J,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
6
+ */function ne(r){return Object.prototype.toString.call(r)==="[object Object]"}function Ae(r){var n,e;return ne(r)===!1?!1:(n=r.constructor,n===void 0?!0:(e=n.prototype,!(ne(e)===!1||e.hasOwnProperty("isPrototypeOf")===!1)))}function W(r){return r instanceof Element?r:document.querySelector(r)}async function X(r){return await new Promise(n=>setTimeout(n,r))}const Ce='[data-elem="drawer.panel"]',V="data-drawers-group",_e=["a[href]","area[href]",'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',"select:not([disabled]):not([aria-hidden])","textarea:not([disabled]):not([aria-hidden])","button:not([disabled]):not([aria-hidden])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'],re={modal:!0,focusOnChild:!0,closeOnEsc:!0,closeOnOutsideClick:!0,closeOnUnderlayClick:!0,onCloseConfirm:()=>!0,onBeforeClose:null,onClose:null,onCloseAnimationEnd:null,onBeforeOpen:null,onOpen:null,onOpenAnimationEnd:null,openClass:"drawer_open",openAnimationDuration:0,closeAnimationDuration:0,lockPageScroll:!0};function se(r){return Ee.all(r,{isMergeableObject:Ae})}class Y{constructor({target:n,type:e,owner:l}){g(this,_,void 0);g(this,E,void 0);g(this,z,void 0);g(this,B,!1);const s=W(n);if(!s)throw new Error("Trigger element cannot be found");O(this,_,s),O(this,E,l),O(this,z,e),this.init()}get isActive(){return t(this,B)}get owner(){return t(this,E)}init(){t(this,_).addEventListener("click",n=>this.clickHandler(n)),t(this,E).on("open",()=>this.setActive(!0)),t(this,E).on("close",()=>this.setActive(!1))}clickHandler(n){n.__drawerTrigger=this,t(this,z)==="open"?t(this,E).isOpen||t(this,E).open(t(this,_)):t(this,z)==="close"?t(this,E).isOpen&&t(this,E).close(t(this,_)):t(this,E).isOpen?t(this,E).close(t(this,_)):t(this,E).open(t(this,_))}setActive(n){O(this,B,n),n?t(this,_).classList.add("drawer-trigger_active"):t(this,_).classList.remove("drawer-trigger_active")}}_=new WeakMap,E=new WeakMap,z=new WeakMap,B=new WeakMap;class ie extends ae{constructor({target:e,options:l}){super();g(this,w,void 0);g(this,$,void 0);g(this,T,void 0);g(this,Q,void 0);g(this,U,void 0);this.handleDocumentClick=async h=>{var o;if(((o=h.__drawerTrigger)==null?void 0:o.owner)===this)return;const u=h.target;if(h.composedPath(),this.dom.panel.contains(u))return;const i=u==null?void 0:u.closest("[data-drawer]");i?i.getAttribute("data-drawer")===t(this,U)?this.handleUnderlayClick(h):this.handleOtherDrawerClick(h):this.handleOutsideClick(h)},this.handleKeydown=h=>{t(this,w).closeOnEsc&&h.key==="Escape"&&this.close()};const s=se(l?[re,l]:[re]),f=W(e);if(f===null)throw new Error("Drawer's root cannot be found");O(this,U,f.getAttribute("data-drawer"));const d=f.querySelector(Ce);if(d===null)throw new Error(`Drawer's panel cannot be found. Alias: ${t(this,U)}`);this.dom={root:f,panel:d},this.setOptions(s),this.dom.panel.setAttribute("tabindex","-1"),this.dom.root.classList.add("drawer_initialized")}addEventListeners(){this.dom.root.addEventListener("keydown",this.handleKeydown),document.addEventListener("click",this.handleDocumentClick)}removeEventListeners(){this.dom.root.removeEventListener("keydown",this.handleKeydown),document.removeEventListener("click",this.handleDocumentClick)}get isOpen(){return t(this,T)}get isModal(){return t(this,w).modal}set isModal(e){this.dom.root.classList[e?"add":"remove"]("drawer_modal")}set zIndex(e){this.dom.root.style.setProperty("--z-index",String(e)),O(this,$,e)}get zIndex(){return t(this,$)}async open(e){await X(0),!t(this,T)&&(this.emit("beforeOpen",{drawer:this,trigger:e}),O(this,T,!0),this.dom.root.classList.add(t(this,w).openClass),this.emit("open",{drawer:this,trigger:e}),typeof t(this,w).openAnimationDuration=="number"&&await X(t(this,w).openAnimationDuration),this.emit("openAnimationEnd",{drawer:this,trigger:e}),this.focus(),this.addEventListeners())}async close(e){t(this,w).onCloseConfirm&&!t(this,w).onCloseConfirm(this,e)||(this.emit("beforeClose",{drawer:this,trigger:e}),this.removeEventListeners(),O(this,T,!1),this.dom.root.classList.remove(t(this,w).openClass),this.emit("close",{drawer:this,trigger:e}),typeof t(this,w).closeAnimationDuration=="number"&&await X(t(this,w).closeAnimationDuration),this.emit("closeAnimationEnd",{drawer:this,trigger:e}))}handleOtherDrawerClick(e){}handleOutsideClick(e){t(this,w).closeOnOutsideClick&&(typeof t(this,w).closeOnOutsideClick=="object"&&t(this,w).closeOnOutsideClick.hasOwnProperty("checkTarget")?t(this,w).closeOnOutsideClick.checkTarget(e.target)&&this.close():this.close())}handleUnderlayClick(e){t(this,w).closeOnOutsideClick&&this.close()}focus(){t(this,w).focusOnChild&&this.focusChild()||this.focusSelf()}focusSelf(){this.dom.panel.focus()}focusChild(){const e=this.dom.panel.querySelector(_e.join(","));return e?(e.focus(),!0):!1}setOptions(e){var l;e.hasOwnProperty("modal")&&((l=t(this,w))==null?void 0:l.modal)!==e.modal&&(this.isModal=e.modal),O(this,w,t(this,w)?se([t(this,w),e]):e)}assignGroup(e){O(this,Q,e)}}w=new WeakMap,$=new WeakMap,T=new WeakMap,Q=new WeakMap,U=new WeakMap;class Z{constructor(n){g(this,P,void 0);g(this,j,void 0);g(this,S,void 0);g(this,N,void 0);g(this,M,void 0);g(this,k,void 0);O(this,j,[]),O(this,S,[]),O(this,M,new Set),O(this,k,new Map),this.onBeforeOpen=({drawer:s,trigger:f})=>{s.isModal?(t(this,k).set(s,t(this,j).length),t(this,j).push(s),s.zIndex=t(this,S).length+t(this,j).length):(t(this,k).set(s,t(this,S).length),t(this,S).push(s),s.zIndex=t(this,S).length,t(this,j).length>0&&t(this,j).forEach((d,h)=>d.zIndex=t(this,S).length+h+1)),this.lockScroll(s)},this.onCloseAnimationEnd=({drawer:s,trigger:f})=>{const d=s.isModal?t(this,j):t(this,S);for(delete d[t(this,k).get(s)];d.length&&!d.at(-1);)d.pop();t(this,k).delete(s),this.unlockScroll(s)};const e=W(n);if(e===null)throw new Error("Drawer's group root cannot be found");O(this,P,e);const l=t(this,P).closest("[data-scrollable], html")||t(this,P).matches("[data-scrollable], html")&&t(this,P);if(l===null)throw new Error("Scrollable container for group root cannot be found");O(this,N,l)}add(n){n.on("beforeOpen",this.onBeforeOpen),n.on("closeAnimationEnd",this.onCloseAnimationEnd),n.assignGroup(this)}lockScroll(n){t(this,M).size===0&&t(this,N).classList.add("scroll-lock-by-drawer"),t(this,M).add(n)}unlockScroll(n){t(this,M).delete(n),t(this,M).size===0&&t(this,N).classList.remove("scroll-lock-by-drawer")}}P=new WeakMap,j=new WeakMap,S=new WeakMap,N=new WeakMap,M=new WeakMap,k=new WeakMap;const K=class K{constructor(){g(this,q,new Map);g(this,G,new Map);if(K.instance)return K.instance;K.instance=this}init(n){document.querySelectorAll(`[${V}]`).forEach(f=>{const d=f.getAttribute(V);typeof d=="string"&&t(this,G).set(d,new Z(f))}),t(this,G).set("default",new Z(document.documentElement)),document.querySelectorAll("[data-drawer]").forEach(f=>{var o;const d=f.getAttribute("data-drawer");if(typeof d!="string")return;const h=new ie({target:f,options:n});t(this,q).set(d,h);const u=f.closest(`[${V}]`),i=u?u.getAttribute(V):"default";if(typeof i!="string")throw new Error("Group doesn't have alias set correctly");(o=t(this,G).get(i))==null||o.add(h)}),document.querySelectorAll("[data-drawer-open], [data-drawer-close], [data-drawer-toggle]").forEach(f=>{if(f.hasAttribute("data-drawer-open")){const d=f.getAttribute("data-drawer-open");new Y({target:f,type:"open",owner:this.get(d)})}else if(f.hasAttribute("data-drawer-close")){const d=f.getAttribute("data-drawer-close");new Y({target:f,type:"close",owner:this.get(d)})}else{const d=f.getAttribute("data-drawer-toggle");new Y({target:f,type:"toggle",owner:this.get(d)})}})}open(n,{trigger:e,options:l}={}){var s;(s=this.get(n))==null||s.open(e)}close(n,{trigger:e,options:l}={}){var s;(s=this.get(n))==null||s.close(e)}get(n){return typeof n=="string"&&t(this,q).get(n)||null}on(n,e,l){var s;if(n)(s=this.get(n))==null||s.on(e,l);else for(const[f,d]of t(this,q))d.on(e,l)}};q=new WeakMap,G=new WeakMap;let J=K;typeof window<"u"&&(window.hasOwnProperty("app")||(window.app={}),window.app.drawers=new J),p.Drawer=ie,p.DrawersGroup=Z,p.Trigger=Y,p.default=J,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vanilla-drawers",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Drawers controller.",
5
5
  "files": [
6
6
  "dist"