vrembem 3.0.10 → 4.0.0-alpha.1

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.
@@ -2,35 +2,28 @@ function _extends() {
2
2
  _extends = Object.assign ? Object.assign.bind() : function (target) {
3
3
  for (var i = 1; i < arguments.length; i++) {
4
4
  var source = arguments[i];
5
-
6
5
  for (var key in source) {
7
6
  if (Object.prototype.hasOwnProperty.call(source, key)) {
8
7
  target[key] = source[key];
9
8
  }
10
9
  }
11
10
  }
12
-
13
11
  return target;
14
12
  };
15
13
  return _extends.apply(this, arguments);
16
14
  }
17
-
18
15
  var id = 0;
19
-
20
16
  function _classPrivateFieldLooseKey(name) {
21
17
  return "__private_" + id++ + "_" + name;
22
18
  }
23
-
24
19
  function _classPrivateFieldLooseBase(receiver, privateKey) {
25
20
  if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
26
21
  throw new TypeError("attempted to use private field on non-instance");
27
22
  }
28
-
29
23
  return receiver;
30
24
  }
31
25
 
32
26
  var _handler = /*#__PURE__*/_classPrivateFieldLooseKey("handler");
33
-
34
27
  class Breakpoint {
35
28
  constructor(value, handler) {
36
29
  Object.defineProperty(this, _handler, {
@@ -41,12 +34,11 @@ class Breakpoint {
41
34
  _classPrivateFieldLooseBase(this, _handler)[_handler] = handler;
42
35
  this.mql = null;
43
36
  }
44
-
45
37
  get handler() {
46
38
  return _classPrivateFieldLooseBase(this, _handler)[_handler];
47
- } // Unmount existing handler before setting a new one.
48
-
39
+ }
49
40
 
41
+ // Unmount existing handler before setting a new one.
50
42
  set handler(func) {
51
43
  if (this.mql) {
52
44
  // Conditionally use removeListener() for IE11 support.
@@ -56,66 +48,62 @@ class Breakpoint {
56
48
  this.mql.removeListener(_classPrivateFieldLooseBase(this, _handler)[_handler]);
57
49
  }
58
50
  }
59
-
60
51
  _classPrivateFieldLooseBase(this, _handler)[_handler] = func;
61
52
  }
62
-
63
53
  mount(value, handler) {
64
54
  // Update passed params.
65
55
  if (value) this.value = value;
66
- if (handler) _classPrivateFieldLooseBase(this, _handler)[_handler] = handler; // Guard if no breakpoint was set.
56
+ if (handler) _classPrivateFieldLooseBase(this, _handler)[_handler] = handler;
67
57
 
68
- if (!this.value) return this; // Setup and store the MediaQueryList instance.
58
+ // Guard if no breakpoint was set.
59
+ if (!this.value) return this;
69
60
 
70
- this.mql = window.matchMedia(`(min-width: ${this.value})`); // Conditionally use addListener() for IE11 support.
61
+ // Setup and store the MediaQueryList instance.
62
+ this.mql = window.matchMedia(`(min-width: ${this.value})`);
71
63
 
64
+ // Conditionally use addListener() for IE11 support.
72
65
  if (typeof this.mql.addEventListener === 'function') {
73
66
  this.mql.addEventListener('change', _classPrivateFieldLooseBase(this, _handler)[_handler]);
74
67
  } else {
75
68
  this.mql.addListener(_classPrivateFieldLooseBase(this, _handler)[_handler]);
76
- } // Run the handler.
77
-
69
+ }
78
70
 
71
+ // Run the handler.
79
72
  _classPrivateFieldLooseBase(this, _handler)[_handler](this.mql);
80
-
81
73
  return this;
82
74
  }
83
-
84
75
  unmount() {
85
76
  // Guard if no MediaQueryList instance exists.
86
- if (!this.mql) return this; // Conditionally use removeListener() for IE11 support.
77
+ if (!this.mql) return this;
87
78
 
79
+ // Conditionally use removeListener() for IE11 support.
88
80
  if (typeof this.mql.removeEventListener === 'function') {
89
81
  this.mql.removeEventListener('change', _classPrivateFieldLooseBase(this, _handler)[_handler]);
90
82
  } else {
91
83
  this.mql.removeListener(_classPrivateFieldLooseBase(this, _handler)[_handler]);
92
- } // Set value, handler and MediaQueryList to null.
93
-
84
+ }
94
85
 
86
+ // Set value, handler and MediaQueryList to null.
95
87
  this.value = null;
96
88
  _classPrivateFieldLooseBase(this, _handler)[_handler] = null;
97
89
  this.mql = null;
98
90
  return this;
99
91
  }
100
-
101
92
  }
102
93
 
103
94
  class Collection {
104
95
  constructor() {
105
96
  this.collection = [];
106
97
  }
107
-
108
98
  async register(item) {
109
99
  await this.deregister(item);
110
100
  this.collection.push(item);
111
101
  return this.collection;
112
102
  }
113
-
114
103
  async deregister(ref) {
115
104
  const index = this.collection.findIndex(entry => {
116
105
  return entry === ref;
117
106
  });
118
-
119
107
  if (index >= 0) {
120
108
  const entry = this.collection[index];
121
109
  Object.getOwnPropertyNames(entry).forEach(prop => {
@@ -123,54 +111,55 @@ class Collection {
123
111
  });
124
112
  this.collection.splice(index, 1);
125
113
  }
126
-
127
114
  return this.collection;
128
115
  }
129
-
130
116
  async registerCollection(items) {
131
117
  await Promise.all(Array.from(items, item => {
132
118
  this.register(item);
133
119
  }));
134
120
  return this.collection;
135
121
  }
136
-
137
122
  async deregisterCollection() {
138
123
  while (this.collection.length > 0) {
139
124
  await this.deregister(this.collection[0]);
140
125
  }
141
-
142
126
  return this.collection;
143
127
  }
144
-
145
128
  get(value, key = 'id') {
146
129
  return this.collection.find(item => {
147
130
  return item[key] === value;
148
131
  });
149
132
  }
150
-
151
133
  }
152
134
 
153
- var focusableSelectors = [
154
- 'a[href]:not([tabindex^="-"])',
155
- 'area[href]:not([tabindex^="-"])',
156
- 'input:not([type="hidden"]):not([type="radio"]):not([disabled]):not([tabindex^="-"])',
157
- 'input[type="radio"]:not([disabled]):not([tabindex^="-"])',
158
- 'select:not([disabled]):not([tabindex^="-"])',
159
- 'textarea:not([disabled]):not([tabindex^="-"])',
160
- 'button:not([disabled]):not([tabindex^="-"])',
161
- 'iframe:not([tabindex^="-"])',
162
- 'audio[controls]:not([tabindex^="-"])',
163
- 'video[controls]:not([tabindex^="-"])',
164
- '[contenteditable]:not([tabindex^="-"])',
165
- '[tabindex]:not([tabindex^="-"])',
135
+ const not = {
136
+ inert: ':not([inert]):not([inert] *)',
137
+ negTabIndex: ':not([tabindex^="-"])',
138
+ disabled: ':not(:disabled)',
139
+ };
140
+
141
+ var e = [
142
+ `a[href]${not.inert}${not.negTabIndex}`,
143
+ `area[href]${not.inert}${not.negTabIndex}`,
144
+ `input:not([type="hidden"]):not([type="radio"])${not.inert}${not.negTabIndex}${not.disabled}`,
145
+ `input[type="radio"]${not.inert}${not.negTabIndex}${not.disabled}`,
146
+ `select${not.inert}${not.negTabIndex}${not.disabled}`,
147
+ `textarea${not.inert}${not.negTabIndex}${not.disabled}`,
148
+ `button${not.inert}${not.negTabIndex}${not.disabled}`,
149
+ `details${not.inert} > summary:first-of-type${not.negTabIndex}`,
150
+ // Discard until Firefox supports `:has()`
151
+ // See: https://github.com/KittyGiraudel/focusable-selectors/issues/12
152
+ // `details:not(:has(> summary))${not.inert}${not.negTabIndex}`,
153
+ `iframe${not.inert}${not.negTabIndex}`,
154
+ `audio[controls]${not.inert}${not.negTabIndex}`,
155
+ `video[controls]${not.inert}${not.negTabIndex}`,
156
+ `[contenteditable]${not.inert}${not.negTabIndex}`,
157
+ `[tabindex]${not.inert}${not.negTabIndex}`,
166
158
  ];
167
159
 
168
160
  var _focusable = /*#__PURE__*/_classPrivateFieldLooseKey("focusable");
169
-
170
161
  var _handleFocusTrap = /*#__PURE__*/_classPrivateFieldLooseKey("handleFocusTrap");
171
-
172
162
  var _handleFocusLock = /*#__PURE__*/_classPrivateFieldLooseKey("handleFocusLock");
173
-
174
163
  class FocusTrap {
175
164
  constructor(el = null, selectorFocus = '[data-focus]') {
176
165
  Object.defineProperty(this, _focusable, {
@@ -190,15 +179,14 @@ class FocusTrap {
190
179
  _classPrivateFieldLooseBase(this, _handleFocusTrap)[_handleFocusTrap] = handleFocusTrap.bind(this);
191
180
  _classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock] = handleFocusLock.bind(this);
192
181
  }
193
-
194
182
  get focusable() {
195
183
  return _classPrivateFieldLooseBase(this, _focusable)[_focusable];
196
184
  }
197
-
198
185
  set focusable(value) {
199
186
  // Update the focusable value.
200
- _classPrivateFieldLooseBase(this, _focusable)[_focusable] = value; // Apply event listeners based on new focusable array length.
187
+ _classPrivateFieldLooseBase(this, _focusable)[_focusable] = value;
201
188
 
189
+ // Apply event listeners based on new focusable array length.
202
190
  if (_classPrivateFieldLooseBase(this, _focusable)[_focusable].length) {
203
191
  document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock]);
204
192
  document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusTrap)[_handleFocusTrap]);
@@ -207,74 +195,76 @@ class FocusTrap {
207
195
  document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock]);
208
196
  }
209
197
  }
210
-
211
198
  get focusableFirst() {
212
199
  return this.focusable[0];
213
200
  }
214
-
215
201
  get focusableLast() {
216
202
  return this.focusable[this.focusable.length - 1];
217
203
  }
218
-
219
204
  mount(el, selectorFocus) {
220
205
  // Update passed params.
221
206
  if (el) this.el = el;
222
- if (selectorFocus) this.selectorFocus = selectorFocus; // Get the focusable elements.
207
+ if (selectorFocus) this.selectorFocus = selectorFocus;
223
208
 
224
- this.focusable = this.getFocusable(); // Set the focus on the element.
209
+ // Get the focusable elements.
210
+ this.focusable = this.getFocusable();
225
211
 
212
+ // Set the focus on the element.
226
213
  this.focus();
227
214
  }
228
-
229
215
  unmount() {
230
216
  // Set element to null.
231
- this.el = null; // Apply empty array to focusable.
217
+ this.el = null;
232
218
 
233
- this.focusable = []; // Remove event listeners
219
+ // Apply empty array to focusable.
220
+ this.focusable = [];
234
221
 
222
+ // Remove event listeners
235
223
  document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusTrap)[_handleFocusTrap]);
236
224
  document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock]);
237
225
  }
238
-
239
226
  focus(el = this.el, selectorFocus = this.selectorFocus) {
240
227
  // Query for the focus selector, otherwise return this element.
241
- const result = el.querySelector(selectorFocus) || el; // Give the returned element focus.
242
-
228
+ const result = el.querySelector(selectorFocus) || el;
229
+ // Give the returned element focus.
243
230
  result.focus();
244
231
  }
245
-
246
232
  getFocusable(el = this.el) {
247
233
  // Initialize the focusable array.
248
- const focusable = []; // Store the initial focus and scroll position.
234
+ const focusable = [];
249
235
 
236
+ // Store the initial focus and scroll position.
250
237
  const initFocus = document.activeElement;
251
- const initScrollTop = el.scrollTop; // Query for all the focusable elements.
238
+ const initScrollTop = el.scrollTop;
252
239
 
253
- const els = el.querySelectorAll(focusableSelectors.join(',')); // Loop through all focusable elements.
240
+ // Query for all the focusable elements.
241
+ const els = el.querySelectorAll(e.join(','));
254
242
 
243
+ // Loop through all focusable elements.
255
244
  els.forEach(el => {
256
245
  // Set them to focus and check
257
- el.focus(); // Test that the element took focus.
258
-
246
+ el.focus();
247
+ // Test that the element took focus.
259
248
  if (document.activeElement === el) {
260
249
  // Add element to the focusable array.
261
250
  focusable.push(el);
262
251
  }
263
- }); // Restore the initial scroll position and focus.
252
+ });
264
253
 
254
+ // Restore the initial scroll position and focus.
265
255
  el.scrollTop = initScrollTop;
266
- initFocus.focus(); // Return the focusable array.
256
+ initFocus.focus();
267
257
 
258
+ // Return the focusable array.
268
259
  return focusable;
269
260
  }
270
-
271
261
  }
272
-
273
262
  function handleFocusTrap(event) {
274
263
  // Check if the click was a tab and return if not.
275
264
  const isTab = event.key === 'Tab' || event.keyCode === 9;
276
- if (!isTab) return; // If the shift key is pressed.
265
+ if (!isTab) return;
277
266
 
267
+ // If the shift key is pressed.
278
268
  if (event.shiftKey) {
279
269
  // If the active element is either the root el or first focusable.
280
270
  if (document.activeElement === this.focusableFirst || document.activeElement === this.el) {
@@ -291,7 +281,6 @@ function handleFocusTrap(event) {
291
281
  }
292
282
  }
293
283
  }
294
-
295
284
  function handleFocusLock(event) {
296
285
  // Ignore the tab key by preventing default.
297
286
  const isTab = event.key === 'Tab' || event.keyCode === 9;
@@ -315,18 +304,15 @@ function localStore(key, enable = true) {
315
304
  get(prop) {
316
305
  return prop ? store[prop] : store;
317
306
  },
318
-
319
307
  set(prop, value) {
320
308
  if (value) {
321
309
  store[prop] = value;
322
310
  } else {
323
311
  delete store[prop];
324
312
  }
325
-
326
313
  if (enable) localStorage.setItem(key, JSON.stringify(store));
327
314
  return store;
328
315
  }
329
-
330
316
  };
331
317
  }
332
318
 
@@ -344,31 +330,37 @@ function localStore(key, enable = true) {
344
330
  function teleport(what, where, how) {
345
331
  // Check if ref is either a comment or element node.
346
332
  const isComment = where.nodeType === Node.COMMENT_NODE;
347
- const isElement = where.nodeType === Node.ELEMENT_NODE; // Get the reference element.
333
+ const isElement = where.nodeType === Node.ELEMENT_NODE;
348
334
 
349
- where = isComment || isElement ? where : document.querySelector(where); // If ref is a comment, set teleport type to 'after'.
335
+ // Get the reference element.
336
+ where = isComment || isElement ? where : document.querySelector(where);
350
337
 
351
- if (isComment) how = 'after'; // Must be a valid reference element and method.
338
+ // If ref is a comment, set teleport type to 'after'.
339
+ if (isComment) how = 'after';
352
340
 
341
+ // Must be a valid reference element and method.
353
342
  if (!where) throw new Error(`Not a valid teleport reference: '${where}'`);
354
- if (typeof where[how] != 'function') throw new Error(`Not a valid teleport method: '${how}'`); // Initial return ref is null.
343
+ if (typeof where[how] != 'function') throw new Error(`Not a valid teleport method: '${how}'`);
355
344
 
356
- let returnRef = null; // If ref is not a comment, set a return reference comment.
345
+ // Initial return ref is null.
346
+ let returnRef = null;
357
347
 
348
+ // If ref is not a comment, set a return reference comment.
358
349
  if (!isComment) {
359
350
  returnRef = document.createComment('teleported #' + what.id);
360
351
  what.before(returnRef);
361
- } // Teleport the target node.
362
-
352
+ }
363
353
 
364
- where[how](what); // Delete the comment node if element was returned to a comment reference.
354
+ // Teleport the target node.
355
+ where[how](what);
365
356
 
357
+ // Delete the comment node if element was returned to a comment reference.
366
358
  if (isComment) {
367
359
  where.remove();
368
- } // Return the return reference if it was teleported else return null if it was
369
- // returned to a comment reference.
370
-
360
+ }
371
361
 
362
+ // Return the return reference if it was teleported else return null if it was
363
+ // returned to a comment reference.
372
364
  return returnRef;
373
365
  }
374
366
 
@@ -421,7 +413,6 @@ function setOverflowHidden(state, selector) {
421
413
  });
422
414
  }
423
415
  }
424
-
425
416
  function setInert(state, selector) {
426
417
  if (selector) {
427
418
  const els = document.querySelectorAll(selector);
@@ -436,11 +427,11 @@ function setInert(state, selector) {
436
427
  });
437
428
  }
438
429
  }
439
-
440
430
  function updateGlobalState(param, config) {
441
431
  // Set inert state based on if a modal is active.
442
- setInert(!!param, config.selectorInert); // Set overflow state based on if a modal is active.
432
+ setInert(!!param, config.selectorInert);
443
433
 
434
+ // Set overflow state based on if a modal is active.
444
435
  setOverflowHidden(!!param, config.selectorOverflow);
445
436
  }
446
437
 
@@ -471,7 +462,6 @@ class Checkbox {
471
462
  this.__handlerClick = this.handlerClick.bind(this);
472
463
  if (this.settings.autoInit) this.init();
473
464
  }
474
-
475
465
  init(options = null) {
476
466
  if (options) this.settings = _extends({}, this.settings, options);
477
467
  const selector = `[${this.settings.stateAttr}="${this.settings.stateValue}"]`;
@@ -479,11 +469,9 @@ class Checkbox {
479
469
  this.setIndeterminate(mixed);
480
470
  document.addEventListener('click', this.__handlerClick, false);
481
471
  }
482
-
483
472
  destroy() {
484
473
  document.removeEventListener('click', this.__handlerClick, false);
485
474
  }
486
-
487
475
  handlerClick(event) {
488
476
  const selector = `[${this.settings.stateAttr}="${this.settings.stateValue}"]`;
489
477
  const el = event.target.closest(selector);
@@ -491,21 +479,18 @@ class Checkbox {
491
479
  this.removeAriaState(el);
492
480
  this.setIndeterminate(el);
493
481
  }
494
-
495
482
  setAriaState(el, value = this.settings.stateValue) {
496
483
  el = el.forEach ? el : [el];
497
484
  el.forEach(el => {
498
485
  el.setAttribute(this.settings.stateAttr, value);
499
486
  });
500
487
  }
501
-
502
488
  removeAriaState(el) {
503
489
  el = el.forEach ? el : [el];
504
490
  el.forEach(el => {
505
491
  el.removeAttribute(this.settings.stateAttr);
506
492
  });
507
493
  }
508
-
509
494
  setIndeterminate(el) {
510
495
  el = el.forEach ? el : [el];
511
496
  el.forEach(el => {
@@ -516,7 +501,6 @@ class Checkbox {
516
501
  }
517
502
  });
518
503
  }
519
-
520
504
  }
521
505
 
522
506
  var defaults$2 = {
@@ -557,60 +541,59 @@ function handleClick$2(event) {
557
541
  [data-${this.settings.dataToggle}],
558
542
  [data-${this.settings.dataClose}]
559
543
  `);
560
-
561
544
  if (trigger) {
562
545
  // Prevent the default behavior of the trigger.
563
- event.preventDefault(); // If it's a toggle trigger...
546
+ event.preventDefault();
564
547
 
548
+ // If it's a toggle trigger...
565
549
  if (trigger.matches(`[data-${this.settings.dataToggle}]`)) {
566
550
  const selectors = trigger.getAttribute(`data-${this.settings.dataToggle}`).trim().split(' ');
567
551
  selectors.forEach(selector => {
568
552
  // Get the entry from collection using the attribute value.
569
- const entry = this.get(selector); // Store the trigger on the entry.
570
-
571
- entry.trigger = trigger; // Toggle the drawer
572
-
553
+ const entry = this.get(selector);
554
+ // Store the trigger on the entry.
555
+ entry.trigger = trigger;
556
+ // Toggle the drawer
573
557
  entry.toggle();
574
558
  });
575
- } // If it's a open trigger...
576
-
559
+ }
577
560
 
561
+ // If it's a open trigger...
578
562
  if (trigger.matches(`[data-${this.settings.dataOpen}]`)) {
579
563
  const selectors = trigger.getAttribute(`data-${this.settings.dataOpen}`).trim().split(' ');
580
564
  selectors.forEach(selector => {
581
565
  // Get the entry from collection using the attribute value.
582
- const entry = this.get(selector); // Store the trigger on the entry.
583
-
584
- entry.trigger = trigger; // Open the drawer.
585
-
566
+ const entry = this.get(selector);
567
+ // Store the trigger on the entry.
568
+ entry.trigger = trigger;
569
+ // Open the drawer.
586
570
  entry.open();
587
571
  });
588
- } // If it's a close trigger...
589
-
572
+ }
590
573
 
574
+ // If it's a close trigger...
591
575
  if (trigger.matches(`[data-${this.settings.dataClose}]`)) {
592
576
  const selectors = trigger.getAttribute(`data-${this.settings.dataClose}`).trim().split(' ');
593
577
  selectors.forEach(selector => {
594
578
  if (selector) {
595
579
  // Get the entry from collection using the attribute value.
596
- const entry = this.get(selector); // Store the trigger on the entry.
597
-
598
- entry.trigger = trigger; // Close the drawer.
599
-
580
+ const entry = this.get(selector);
581
+ // Store the trigger on the entry.
582
+ entry.trigger = trigger;
583
+ // Close the drawer.
600
584
  entry.close();
601
585
  } else {
602
586
  // If no value is set on close trigger, get the parent drawer.
603
- const parent = event.target.closest(this.settings.selectorDrawer); // If a parent drawer was found, close it.
604
-
587
+ const parent = event.target.closest(this.settings.selectorDrawer);
588
+ // If a parent drawer was found, close it.
605
589
  if (parent) this.close(parent);
606
590
  }
607
591
  });
608
592
  }
609
-
610
593
  return;
611
- } // If the modal drawer screen was clicked...
612
-
594
+ }
613
595
 
596
+ // If the modal drawer screen was clicked...
614
597
  if (event.target.matches(this.settings.selectorDrawer)) {
615
598
  // Close the modal drawer.
616
599
  this.close(event.target.id);
@@ -625,34 +608,38 @@ function handleKeydown$2(event) {
625
608
 
626
609
  async function deregister$2(obj, close = true) {
627
610
  // Return collection if nothing was passed.
628
- if (!obj) return this.collection; // Check if entry has been registered in the collection.
611
+ if (!obj) return this.collection;
629
612
 
613
+ // Check if entry has been registered in the collection.
630
614
  const index = this.collection.findIndex(entry => {
631
615
  return entry.id === obj.id;
632
616
  });
633
-
634
617
  if (index >= 0) {
635
618
  // Get the collection entry.
636
- const entry = this.collection[index]; // If entry is in the opened state.
619
+ const entry = this.collection[index];
637
620
 
621
+ // If entry is in the opened state.
638
622
  if (close && entry.state === 'opened') {
639
623
  // Close the drawer.
640
624
  await entry.close(false);
641
- } // Remove entry from local store.
642
-
625
+ }
643
626
 
644
- this.store.set(entry.id); // Unmount the MatchMedia functionality.
627
+ // Remove entry from local store.
628
+ this.store.set(entry.id);
645
629
 
646
- entry.unmountBreakpoint(); // Delete properties from collection entry.
630
+ // Unmount the MatchMedia functionality.
631
+ entry.unmountBreakpoint();
647
632
 
633
+ // Delete properties from collection entry.
648
634
  Object.getOwnPropertyNames(entry).forEach(prop => {
649
635
  delete entry[prop];
650
- }); // Remove entry from collection.
636
+ });
651
637
 
638
+ // Remove entry from collection.
652
639
  this.collection.splice(index, 1);
653
- } // Return the modified collection.
654
-
640
+ }
655
641
 
642
+ // Return the modified collection.
656
643
  return this.collection;
657
644
  }
658
645
 
@@ -663,7 +650,6 @@ function g() {
663
650
  function getBreakpoint(drawer) {
664
651
  const prefix = g();
665
652
  const bp = drawer.getAttribute(`data-${this.settings.dataBreakpoint}`);
666
-
667
653
  if (this.settings.breakpoints && this.settings.breakpoints[bp]) {
668
654
  return this.settings.breakpoints[bp];
669
655
  } else if (getComputedStyle(document.body).getPropertyValue(`--${prefix}breakpoint-${bp}`).trim()) {
@@ -675,8 +661,9 @@ function getBreakpoint(drawer) {
675
661
 
676
662
  function getDrawer(query) {
677
663
  // Get the entry from collection.
678
- const entry = typeof query === 'string' ? this.get(query) : this.get(query.id); // Return entry if it was resolved, otherwise throw error.
664
+ const entry = typeof query === 'string' ? this.get(query) : this.get(query.id);
679
665
 
666
+ // Return entry if it was resolved, otherwise throw error.
680
667
  if (entry) {
681
668
  return entry;
682
669
  } else {
@@ -688,37 +675,49 @@ function getDrawerID(obj) {
688
675
  // If it's a string, return the string.
689
676
  if (typeof obj === 'string') {
690
677
  return obj;
691
- } // If it's an HTML element.
678
+ }
679
+
680
+ // If it's an HTML element.
692
681
  else if (typeof obj.hasAttribute === 'function') {
693
682
  // If it's a drawer open trigger, return data value.
694
683
  if (obj.hasAttribute(`data-${this.settings.dataOpen}`)) {
695
684
  return obj.getAttribute(`data-${this.settings.dataOpen}`);
696
- } // If it's a drawer close trigger, return data value or false.
685
+ }
686
+
687
+ // If it's a drawer close trigger, return data value or false.
697
688
  else if (obj.hasAttribute(`data-${this.settings.dataClose}`)) {
698
689
  return obj.getAttribute(`data-${this.settings.dataClose}`) || false;
699
- } // If it's a drawer toggle trigger, return data value.
690
+ }
691
+
692
+ // If it's a drawer toggle trigger, return data value.
700
693
  else if (obj.hasAttribute(`data-${this.settings.dataToggle}`)) {
701
694
  return obj.getAttribute(`data-${this.settings.dataToggle}`);
702
- } // If it's a drawer element, return the id.
695
+ }
696
+
697
+ // If it's a drawer element, return the id.
703
698
  else if (obj.closest(this.settings.selectorDrawer)) {
704
699
  obj = obj.closest(this.settings.selectorDrawer);
705
700
  return obj.id || false;
706
- } // Return false if no id was found.
701
+ }
702
+
703
+ // Return false if no id was found.
707
704
  else return false;
708
- } // If it has an id property, return its value.
705
+ }
706
+
707
+ // If it has an id property, return its value.
709
708
  else if (obj.id) {
710
709
  return obj.id;
711
- } // Return false if no id was found.
710
+ }
711
+
712
+ // Return false if no id was found.
712
713
  else return false;
713
714
  }
714
715
 
715
716
  function getDrawerElements(query) {
716
717
  const id = getDrawerID.call(this, query);
717
-
718
718
  if (id) {
719
719
  const drawer = document.querySelector(`#${id}`);
720
720
  const dialog = drawer ? drawer.querySelector(this.settings.selectorDialog) : null;
721
-
722
721
  if (!drawer && !dialog) {
723
722
  return {
724
723
  error: new Error(`No drawer elements found using the ID: "${id}".`)
@@ -758,8 +757,8 @@ async function initialState(entry) {
758
757
  } else {
759
758
  // Remove transition state classes.
760
759
  entry.el.classList.remove(this.settings.stateOpening);
761
- entry.el.classList.remove(this.settings.stateClosing); // Add closed state class.
762
-
760
+ entry.el.classList.remove(this.settings.stateClosing);
761
+ // Add closed state class.
763
762
  entry.el.classList.add(this.settings.stateClosed);
764
763
  }
765
764
  }
@@ -779,85 +778,98 @@ function updateFocusState$1(entry) {
779
778
  entry.trigger.focus();
780
779
  entry.trigger = null;
781
780
  }
782
-
783
781
  this.focusTrap.unmount();
784
782
  }
785
783
  }
786
784
 
787
785
  async function open$2(query, transition, focus = true) {
788
786
  // Get the drawer from collection.
789
- const drawer = getDrawer.call(this, query); // Get the modal configuration.
790
-
791
- const config = _extends({}, this.settings, drawer.settings); // Add transition parameter to configuration.
787
+ const drawer = getDrawer.call(this, query);
792
788
 
789
+ // Get the modal configuration.
790
+ const config = _extends({}, this.settings, drawer.settings);
793
791
 
794
- if (transition !== undefined) config.transition = transition; // If drawer is closed.
792
+ // Add transition parameter to configuration.
793
+ if (transition !== undefined) config.transition = transition;
795
794
 
795
+ // If drawer is closed.
796
796
  if (drawer.state === 'closed') {
797
797
  // Update drawer state.
798
- drawer.state = 'opening'; // Run the open transition.
798
+ drawer.state = 'opening';
799
799
 
800
- await openTransition(drawer.el, config); // Update the global state if mode is modal.
800
+ // Run the open transition.
801
+ await openTransition(drawer.el, config);
801
802
 
802
- if (drawer.mode === 'modal') updateGlobalState(true, config); // Update drawer state.
803
+ // Update the global state if mode is modal.
804
+ if (drawer.mode === 'modal') updateGlobalState(true, config);
803
805
 
806
+ // Update drawer state.
804
807
  drawer.state = 'opened';
805
- } // Set focus to the drawer element if the focus param is true.
806
-
808
+ }
807
809
 
810
+ // Set focus to the drawer element if the focus param is true.
808
811
  if (focus) {
809
812
  updateFocusState$1.call(this, drawer);
810
- } // Dispatch custom opened event.
811
-
813
+ }
812
814
 
815
+ // Dispatch custom opened event.
813
816
  drawer.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'opened', {
814
817
  detail: this,
815
818
  bubbles: true
816
- })); // Return the drawer.
819
+ }));
817
820
 
821
+ // Return the drawer.
818
822
  return drawer;
819
823
  }
820
824
 
821
825
  async function close$2(query, transition, focus = true) {
822
826
  // Get the drawer from collection.
823
- const drawer = getDrawer.call(this, query); // Get the modal configuration.
827
+ const drawer = getDrawer.call(this, query);
824
828
 
825
- const config = _extends({}, this.settings, drawer.settings); // Add transition parameter to configuration.
829
+ // Get the modal configuration.
830
+ const config = _extends({}, this.settings, drawer.settings);
826
831
 
832
+ // Add transition parameter to configuration.
833
+ if (transition !== undefined) config.transition = transition;
827
834
 
828
- if (transition !== undefined) config.transition = transition; // If drawer is opened.
829
-
835
+ // If drawer is opened.
830
836
  if (drawer.state === 'opened') {
831
837
  // Update drawer state.
832
- drawer.state = 'closing'; // Remove focus from active element.
838
+ drawer.state = 'closing';
833
839
 
834
- document.activeElement.blur(); // Run the close transition.
840
+ // Remove focus from active element.
841
+ document.activeElement.blur();
835
842
 
836
- await closeTransition(drawer.el, config); // Update the global state if mode is modal.
843
+ // Run the close transition.
844
+ await closeTransition(drawer.el, config);
837
845
 
838
- if (drawer.mode === 'modal') updateGlobalState(false, config); // Set focus to the trigger element if the focus param is true.
846
+ // Update the global state if mode is modal.
847
+ if (drawer.mode === 'modal') updateGlobalState(false, config);
839
848
 
849
+ // Set focus to the trigger element if the focus param is true.
840
850
  if (focus) {
841
851
  updateFocusState$1.call(this, drawer);
842
- } // Update drawer state.
843
-
852
+ }
844
853
 
845
- drawer.state = 'closed'; // Dispatch custom closed event.
854
+ // Update drawer state.
855
+ drawer.state = 'closed';
846
856
 
857
+ // Dispatch custom closed event.
847
858
  drawer.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'closed', {
848
859
  detail: this,
849
860
  bubbles: true
850
861
  }));
851
- } // Return the drawer.
852
-
862
+ }
853
863
 
864
+ // Return the drawer.
854
865
  return drawer;
855
866
  }
856
867
 
857
868
  async function toggle(query, transition, focus) {
858
869
  // Get the drawer from collection.
859
- const drawer = getDrawer.call(this, query); // Open or close the drawer based on its current state.
870
+ const drawer = getDrawer.call(this, query);
860
871
 
872
+ // Open or close the drawer based on its current state.
861
873
  if (drawer.state === 'closed') {
862
874
  return open$2.call(this, drawer, transition, focus);
863
875
  } else {
@@ -869,179 +881,175 @@ function switchMode(entry) {
869
881
  switch (entry.mode) {
870
882
  case 'inline':
871
883
  return toInline.call(this, entry);
872
-
873
884
  case 'modal':
874
885
  return toModal.call(this, entry);
875
-
876
886
  default:
877
887
  throw new Error(`"${entry.mode}" is not a valid drawer mode.`);
878
888
  }
879
889
  }
880
-
881
890
  async function toInline(entry) {
882
891
  // Remove the modal class.
883
- entry.el.classList.remove(entry.getSetting('classModal')); // Remove the aria-modal attribute.
892
+ entry.el.classList.remove(entry.getSetting('classModal'));
884
893
 
885
- entry.dialog.removeAttribute('aria-modal'); // Update the global state.
894
+ // Remove the aria-modal attribute.
895
+ entry.dialog.removeAttribute('aria-modal');
886
896
 
887
- updateGlobalState(false, _extends({}, this.settings, entry.settings)); // Remove any focus traps.
897
+ // Update the global state.
898
+ updateGlobalState(false, _extends({}, this.settings, entry.settings));
888
899
 
889
- this.focusTrap.unmount(); // Setup initial state.
900
+ // Remove any focus traps.
901
+ this.focusTrap.unmount();
890
902
 
891
- await initialState.call(this, entry); // Dispatch custom switch event.
903
+ // Setup initial state.
904
+ await initialState.call(this, entry);
892
905
 
906
+ // Dispatch custom switch event.
893
907
  entry.el.dispatchEvent(new CustomEvent(entry.getSetting('customEventPrefix') + 'switchMode', {
894
908
  detail: this,
895
909
  bubbles: true
896
- })); // Return the entry.
910
+ }));
897
911
 
912
+ // Return the entry.
898
913
  return entry;
899
914
  }
900
-
901
915
  async function toModal(entry) {
902
916
  // Get the drawer configuration.
917
+
903
918
  // Add the modal class.
904
- entry.el.classList.add(entry.getSetting('classModal')); // Set aria-modal attribute to true.
919
+ entry.el.classList.add(entry.getSetting('classModal'));
905
920
 
906
- entry.dialog.setAttribute('aria-modal', 'true'); // If there isn't a stored state but also has the opened state class...
921
+ // Set aria-modal attribute to true.
922
+ entry.dialog.setAttribute('aria-modal', 'true');
907
923
 
924
+ // If there isn't a stored state but also has the opened state class...
908
925
  if (!this.store.get(entry.id) && entry.el.classList.contains(entry.getSetting('stateOpened'))) {
909
926
  // Save the opened state in local store.
910
927
  this.store.set(entry.id, 'opened');
911
- } // Modal drawer defaults to closed state.
912
-
928
+ }
913
929
 
914
- await close$2.call(this, entry, false, false); // Dispatch custom switch event.
930
+ // Modal drawer defaults to closed state.
931
+ await close$2.call(this, entry, false, false);
915
932
 
933
+ // Dispatch custom switch event.
916
934
  entry.el.dispatchEvent(new CustomEvent(entry.getSetting('customEventPrefix') + 'switchMode', {
917
935
  detail: this,
918
936
  bubbles: true
919
- })); // Return the entry.
937
+ }));
920
938
 
939
+ // Return the entry.
921
940
  return entry;
922
941
  }
923
942
 
924
943
  async function register$2(el, dialog) {
925
944
  // Deregister entry incase it has already been registered.
926
- await deregister$2.call(this, el, false); // Save root this for use inside methods API.
945
+ await deregister$2.call(this, el, false);
927
946
 
928
- const root = this; // Create an instance of the Breakpoint class.
947
+ // Save root this for use inside methods API.
948
+ const root = this;
929
949
 
930
- const breakpoint = new Breakpoint(); // Setup methods API.
950
+ // Create an instance of the Breakpoint class.
951
+ const breakpoint = new Breakpoint();
931
952
 
953
+ // Setup methods API.
932
954
  const methods = {
933
955
  open(transition, focus) {
934
956
  return open$2.call(root, this, transition, focus);
935
957
  },
936
-
937
958
  close(transition, focus) {
938
959
  return close$2.call(root, this, transition, focus);
939
960
  },
940
-
941
961
  toggle(transition, focus) {
942
962
  return toggle.call(root, this, transition, focus);
943
963
  },
944
-
945
964
  deregister() {
946
965
  return deregister$2.call(root, this);
947
966
  },
948
-
949
967
  mountBreakpoint() {
950
968
  const value = this.breakpoint;
951
969
  const handler = this.handleBreakpoint.bind(this);
952
970
  breakpoint.mount(value, handler);
953
971
  return this;
954
972
  },
955
-
956
973
  unmountBreakpoint() {
957
974
  breakpoint.unmount();
958
975
  return this;
959
976
  },
960
-
961
977
  handleBreakpoint(event) {
962
978
  this.mode = event.matches ? 'inline' : 'modal';
963
979
  return this;
964
980
  },
965
-
966
981
  getSetting(key) {
967
982
  return key in this.settings ? this.settings[key] : root.settings[key];
968
983
  }
984
+ };
969
985
 
970
- }; // Setup the drawer object.
971
-
986
+ // Setup the drawer object.
972
987
  const entry = _extends({
973
988
  id: el.id,
974
989
  el: el,
975
990
  dialog: dialog,
976
991
  trigger: null,
977
992
  settings: getConfig$1(el, this.settings.dataConfig),
978
-
979
993
  get breakpoint() {
980
994
  return getBreakpoint.call(root, el);
981
995
  },
982
-
983
996
  get state() {
984
997
  return __state;
985
998
  },
986
-
987
999
  set state(value) {
988
- __state = value; // Save 'opened' and 'closed' states to store if mode is inline.
989
-
1000
+ __state = value;
1001
+ // Save 'opened' and 'closed' states to store if mode is inline.
990
1002
  if (value === 'opened' || value === 'closed') {
991
1003
  if (this.mode === 'inline') root.store.set(this.id, this.state);
992
1004
  }
993
1005
  },
994
-
995
1006
  get mode() {
996
1007
  return __mode;
997
1008
  },
998
-
999
1009
  set mode(value) {
1000
1010
  __mode = value;
1001
1011
  switchMode.call(root, this);
1002
1012
  }
1013
+ }, methods);
1003
1014
 
1004
- }, methods); // Create the state var with the initial state.
1005
-
1006
-
1007
- let __state = el.classList.contains(entry.getSetting('stateOpened')) ? 'opened' : 'closed'; // Create the mode var with the initial mode.
1008
-
1009
-
1010
- let __mode = el.classList.contains(entry.getSetting('classModal')) ? 'modal' : 'inline'; // Setup mode specific attributes.
1015
+ // Create the state var with the initial state.
1016
+ let __state = el.classList.contains(entry.getSetting('stateOpened')) ? 'opened' : 'closed';
1011
1017
 
1018
+ // Create the mode var with the initial mode.
1019
+ let __mode = el.classList.contains(entry.getSetting('classModal')) ? 'modal' : 'inline';
1012
1020
 
1021
+ // Setup mode specific attributes.
1013
1022
  if (entry.mode === 'modal') {
1014
1023
  // Set aria-modal attribute to true.
1015
1024
  entry.dialog.setAttribute('aria-modal', 'true');
1016
1025
  } else {
1017
1026
  // Remove the aria-modal attribute.
1018
1027
  entry.dialog.removeAttribute('aria-modal');
1019
- } // Set tabindex="-1" so dialog is focusable via JS or click.
1020
-
1028
+ }
1021
1029
 
1030
+ // Set tabindex="-1" so dialog is focusable via JS or click.
1022
1031
  if (entry.getSetting('setTabindex')) {
1023
1032
  entry.dialog.setAttribute('tabindex', '-1');
1024
- } // Add entry to collection.
1025
-
1033
+ }
1026
1034
 
1027
- this.collection.push(entry); // If the entry has a breakpoint...
1035
+ // Add entry to collection.
1036
+ this.collection.push(entry);
1028
1037
 
1038
+ // If the entry has a breakpoint...
1029
1039
  if (entry.breakpoint) {
1030
1040
  // Mount media query breakpoint functionality.
1031
1041
  entry.mountBreakpoint();
1032
1042
  } else {
1033
1043
  // Else, Setup initial state.
1034
1044
  await initialState.call(this, entry);
1035
- } // Return the registered entry.
1036
-
1045
+ }
1037
1046
 
1047
+ // Return the registered entry.
1038
1048
  return entry;
1039
1049
  }
1040
1050
 
1041
1051
  var _handleClick$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
1042
-
1043
1052
  var _handleKeydown$2 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
1044
-
1045
1053
  class Drawer extends Collection {
1046
1054
  constructor(options) {
1047
1055
  super();
@@ -1055,81 +1063,71 @@ class Drawer extends Collection {
1055
1063
  });
1056
1064
  this.defaults = defaults$2;
1057
1065
  this.settings = _extends({}, this.defaults, options);
1058
- this.focusTrap = new FocusTrap(); // Setup local store for inline drawer state management.
1066
+ this.focusTrap = new FocusTrap();
1059
1067
 
1068
+ // Setup local store for inline drawer state management.
1060
1069
  this.store = localStore(this.settings.storeKey, this.settings.store);
1061
1070
  _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1] = handleClick$2.bind(this);
1062
1071
  _classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2] = handleKeydown$2.bind(this);
1063
1072
  if (this.settings.autoInit) this.init();
1064
1073
  }
1065
-
1066
1074
  get activeModal() {
1067
1075
  return this.collection.find(entry => {
1068
1076
  return entry.state === 'opened' && entry.mode === 'modal';
1069
1077
  });
1070
1078
  }
1071
-
1072
1079
  async init(options = null) {
1073
1080
  // Update settings with passed options.
1074
- if (options) this.settings = _extends({}, this.settings, options); // Get all the modals.
1081
+ if (options) this.settings = _extends({}, this.settings, options);
1075
1082
 
1076
- const drawers = document.querySelectorAll(this.settings.selectorDrawer); // Register the collections array with modal instances.
1083
+ // Get all the modals.
1084
+ const drawers = document.querySelectorAll(this.settings.selectorDrawer);
1077
1085
 
1078
- await this.registerCollection(drawers); // If eventListeners are enabled, init event listeners.
1086
+ // Register the collections array with modal instances.
1087
+ await this.registerCollection(drawers);
1079
1088
 
1089
+ // If eventListeners are enabled, init event listeners.
1080
1090
  if (this.settings.eventListeners) {
1081
1091
  this.initEventListeners();
1082
1092
  }
1083
-
1084
1093
  return this;
1085
1094
  }
1086
-
1087
1095
  async destroy() {
1088
1096
  // Remove all entries from the collection.
1089
- await this.deregisterCollection(); // If eventListeners are enabled, init event listeners.
1097
+ await this.deregisterCollection();
1090
1098
 
1099
+ // If eventListeners are enabled, init event listeners.
1091
1100
  if (this.settings.eventListeners) {
1092
1101
  this.destroyEventListeners();
1093
1102
  }
1094
-
1095
1103
  return this;
1096
1104
  }
1097
-
1098
1105
  initEventListeners() {
1099
1106
  document.addEventListener('click', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
1100
- document.addEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
1101
1107
  document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2], false);
1102
1108
  }
1103
-
1104
1109
  destroyEventListeners() {
1105
1110
  document.removeEventListener('click', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
1106
- document.removeEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
1107
1111
  document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2], false);
1108
1112
  }
1109
-
1110
1113
  register(query) {
1111
1114
  const els = getDrawerElements.call(this, query);
1112
1115
  if (els.error) return Promise.reject(els.error);
1113
1116
  return register$2.call(this, els.drawer, els.dialog);
1114
1117
  }
1115
-
1116
1118
  deregister(query) {
1117
1119
  const entry = this.get(getDrawerID.call(this, query));
1118
1120
  return deregister$2.call(this, entry);
1119
1121
  }
1120
-
1121
1122
  open(id, transition, focus) {
1122
1123
  return open$2.call(this, id, transition, focus);
1123
1124
  }
1124
-
1125
1125
  close(id, transition, focus) {
1126
1126
  return close$2.call(this, id, transition, focus);
1127
1127
  }
1128
-
1129
1128
  toggle(id, transition, focus) {
1130
1129
  return toggle.call(this, id, transition, focus);
1131
1130
  }
1132
-
1133
1131
  }
1134
1132
 
1135
1133
  var defaults$1 = {
@@ -1162,8 +1160,9 @@ var defaults$1 = {
1162
1160
 
1163
1161
  function getModal(query) {
1164
1162
  // Get the entry from collection.
1165
- const entry = typeof query === 'string' ? this.get(query) : this.get(query.id); // Return entry if it was resolved, otherwise throw error.
1163
+ const entry = typeof query === 'string' ? this.get(query) : this.get(query.id);
1166
1164
 
1165
+ // Return entry if it was resolved, otherwise throw error.
1167
1166
  if (entry) {
1168
1167
  return entry;
1169
1168
  } else {
@@ -1175,37 +1174,49 @@ function getModalID(obj) {
1175
1174
  // If it's a string, return the string.
1176
1175
  if (typeof obj === 'string') {
1177
1176
  return obj;
1178
- } // If it's an HTML element.
1177
+ }
1178
+
1179
+ // If it's an HTML element.
1179
1180
  else if (typeof obj.hasAttribute === 'function') {
1180
1181
  // If it's a modal open trigger, return data value.
1181
1182
  if (obj.hasAttribute(`data-${this.settings.dataOpen}`)) {
1182
1183
  return obj.getAttribute(`data-${this.settings.dataOpen}`);
1183
- } // If it's a modal close trigger, return data value or false.
1184
+ }
1185
+
1186
+ // If it's a modal close trigger, return data value or false.
1184
1187
  else if (obj.hasAttribute(`data-${this.settings.dataClose}`)) {
1185
1188
  return obj.getAttribute(`data-${this.settings.dataClose}`) || false;
1186
- } // If it's a modal replace trigger, return data value.
1189
+ }
1190
+
1191
+ // If it's a modal replace trigger, return data value.
1187
1192
  else if (obj.hasAttribute(`data-${this.settings.dataReplace}`)) {
1188
1193
  return obj.getAttribute(`data-${this.settings.dataReplace}`);
1189
- } // If it's a modal element, return the id.
1194
+ }
1195
+
1196
+ // If it's a modal element, return the id.
1190
1197
  else if (obj.closest(this.settings.selectorModal)) {
1191
1198
  obj = obj.closest(this.settings.selectorModal);
1192
1199
  return obj.id || false;
1193
- } // Return false if no id was found.
1200
+ }
1201
+
1202
+ // Return false if no id was found.
1194
1203
  else return false;
1195
- } // If it has an id property, return its value.
1204
+ }
1205
+
1206
+ // If it has an id property, return its value.
1196
1207
  else if (obj.id) {
1197
1208
  return obj.id;
1198
- } // Return false if no id was found.
1209
+ }
1210
+
1211
+ // Return false if no id was found.
1199
1212
  else return false;
1200
1213
  }
1201
1214
 
1202
1215
  function getModalElements(query) {
1203
1216
  const id = getModalID.call(this, query);
1204
-
1205
1217
  if (id) {
1206
1218
  const modal = document.querySelector(`#${id}`);
1207
1219
  const dialog = modal ? modal.querySelector(this.settings.selectorDialog) : null;
1208
-
1209
1220
  if (!modal && !dialog) {
1210
1221
  return {
1211
1222
  error: new Error(`No modal elements found using the ID: "${id}".`)
@@ -1238,7 +1249,6 @@ function updateFocusState() {
1238
1249
  this.trigger.focus();
1239
1250
  this.trigger = null;
1240
1251
  }
1241
-
1242
1252
  this.focusTrap.unmount();
1243
1253
  }
1244
1254
  }
@@ -1246,30 +1256,28 @@ function updateFocusState() {
1246
1256
  async function handleClick$1(event) {
1247
1257
  // If an open or replace button was clicked, open or replace the modal.
1248
1258
  let trigger = event.target.closest(`[data-${this.settings.dataOpen}], [data-${this.settings.dataReplace}]`);
1249
-
1250
1259
  if (trigger) {
1251
- event.preventDefault(); // Save the trigger if it's not coming from inside a modal.
1252
-
1260
+ event.preventDefault();
1261
+ // Save the trigger if it's not coming from inside a modal.
1253
1262
  const fromModal = event.target.closest(this.settings.selectorModal);
1254
- if (!fromModal) this.trigger = trigger; // Get the modal.
1255
-
1256
- const modal = this.get(getModalID.call(this, trigger)); // Depending on the button type, either open or replace the modal.
1257
-
1263
+ if (!fromModal) this.trigger = trigger;
1264
+ // Get the modal.
1265
+ const modal = this.get(getModalID.call(this, trigger));
1266
+ // Depending on the button type, either open or replace the modal.
1258
1267
  return trigger.matches(`[data-${this.settings.dataOpen}]`) ? modal.open() : modal.replace();
1259
- } // If a close button was clicked, close the modal.
1260
-
1268
+ }
1261
1269
 
1270
+ // If a close button was clicked, close the modal.
1262
1271
  trigger = event.target.closest(`[data-${this.settings.dataClose}]`);
1263
-
1264
1272
  if (trigger) {
1265
- event.preventDefault(); // Get the value of the data attribute.
1266
-
1267
- const value = trigger.getAttribute(`data-${this.settings.dataClose}`); // Close all if * wildcard is passed, otherwise close a single modal.
1268
-
1273
+ event.preventDefault();
1274
+ // Get the value of the data attribute.
1275
+ const value = trigger.getAttribute(`data-${this.settings.dataClose}`);
1276
+ // Close all if * wildcard is passed, otherwise close a single modal.
1269
1277
  return value === '*' ? this.closeAll() : this.close(value);
1270
- } // If the modal screen was clicked, close the modal.
1271
-
1278
+ }
1272
1279
 
1280
+ // If the modal screen was clicked, close the modal.
1273
1281
  if (event.target.matches(this.settings.selectorModal) && !event.target.querySelector(this.settings.selectorRequired)) {
1274
1282
  return this.close(getModalID.call(this, event.target));
1275
1283
  }
@@ -1286,109 +1294,125 @@ function handleKeydown$1(event) {
1286
1294
 
1287
1295
  async function deregister$1(obj, close = true) {
1288
1296
  // Return collection if nothing was passed.
1289
- if (!obj) return this.collection; // Check if entry has been registered in the collection.
1297
+ if (!obj) return this.collection;
1290
1298
 
1299
+ // Check if entry has been registered in the collection.
1291
1300
  const index = this.collection.findIndex(entry => {
1292
1301
  return entry.id === obj.id;
1293
1302
  });
1294
-
1295
1303
  if (index >= 0) {
1296
1304
  // Get the collection entry.
1297
- const entry = this.collection[index]; // If entry is in the opened state, close it.
1305
+ const entry = this.collection[index];
1298
1306
 
1307
+ // If entry is in the opened state, close it.
1299
1308
  if (close && entry.state === 'opened') {
1300
1309
  await entry.close(false);
1301
1310
  } else {
1302
1311
  // Remove modal from stack.
1303
1312
  this.stack.remove(entry);
1304
- } // Return teleported modal if a reference has been set.
1305
-
1313
+ }
1306
1314
 
1315
+ // Return teleported modal if a reference has been set.
1307
1316
  if (entry.getSetting('teleport')) {
1308
1317
  entry.teleportReturn();
1309
- } // Delete properties from collection entry.
1310
-
1318
+ }
1311
1319
 
1320
+ // Delete properties from collection entry.
1312
1321
  Object.getOwnPropertyNames(entry).forEach(prop => {
1313
1322
  delete entry[prop];
1314
- }); // Remove entry from collection.
1323
+ });
1315
1324
 
1325
+ // Remove entry from collection.
1316
1326
  this.collection.splice(index, 1);
1317
- } // Return the modified collection.
1318
-
1327
+ }
1319
1328
 
1329
+ // Return the modified collection.
1320
1330
  return this.collection;
1321
1331
  }
1322
1332
 
1323
1333
  async function open$1(query, transition, focus = true) {
1324
1334
  // Get the modal from collection.
1325
- const modal = getModal.call(this, query); // Get the modal configuration.
1326
-
1327
- const config = _extends({}, this.settings, modal.settings); // Add transition parameter to configuration.
1335
+ const modal = getModal.call(this, query);
1328
1336
 
1337
+ // Get the modal configuration.
1338
+ const config = _extends({}, this.settings, modal.settings);
1329
1339
 
1330
- if (transition !== undefined) config.transition = transition; // Maybe add modal to top of stack.
1340
+ // Add transition parameter to configuration.
1341
+ if (transition !== undefined) config.transition = transition;
1331
1342
 
1332
- this.stack.moveToTop(modal); // If modal is closed.
1343
+ // Maybe add modal to top of stack.
1344
+ this.stack.moveToTop(modal);
1333
1345
 
1346
+ // If modal is closed.
1334
1347
  if (modal.state === 'closed') {
1335
1348
  // Update modal state.
1336
- modal.state = 'opening'; // Add modal to stack.
1349
+ modal.state = 'opening';
1337
1350
 
1338
- this.stack.add(modal); // Run the open transition.
1351
+ // Add modal to stack.
1352
+ this.stack.add(modal);
1339
1353
 
1340
- await openTransition(modal.el, config); // Update modal state.
1354
+ // Run the open transition.
1355
+ await openTransition(modal.el, config);
1341
1356
 
1357
+ // Update modal state.
1342
1358
  modal.state = 'opened';
1343
- } // Update focus if the focus param is true.
1344
-
1359
+ }
1345
1360
 
1361
+ // Update focus if the focus param is true.
1346
1362
  if (focus) {
1347
1363
  updateFocusState.call(this);
1348
- } // Dispatch custom opened event.
1349
-
1364
+ }
1350
1365
 
1366
+ // Dispatch custom opened event.
1351
1367
  modal.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'opened', {
1352
1368
  detail: this,
1353
1369
  bubbles: true
1354
- })); // Return the modal.
1370
+ }));
1355
1371
 
1372
+ // Return the modal.
1356
1373
  return modal;
1357
1374
  }
1358
1375
 
1359
1376
  async function close$1(query, transition, focus = true) {
1360
1377
  // Get the modal from collection, or top modal in stack if no query is provided.
1361
- const modal = query ? getModal.call(this, query) : this.active; // If a modal exists and its state is opened.
1378
+ const modal = query ? getModal.call(this, query) : this.active;
1362
1379
 
1380
+ // If a modal exists and its state is opened.
1363
1381
  if (modal && modal.state === 'opened') {
1364
1382
  // Update modal state.
1365
- modal.state = 'closing'; // Get the modal configuration.
1383
+ modal.state = 'closing';
1366
1384
 
1367
- const config = _extends({}, this.settings, modal.settings); // Add transition parameter to configuration.
1385
+ // Get the modal configuration.
1386
+ const config = _extends({}, this.settings, modal.settings);
1368
1387
 
1388
+ // Add transition parameter to configuration.
1389
+ if (transition !== undefined) config.transition = transition;
1369
1390
 
1370
- if (transition !== undefined) config.transition = transition; // Remove focus from active element.
1391
+ // Remove focus from active element.
1392
+ document.activeElement.blur();
1371
1393
 
1372
- document.activeElement.blur(); // Run the close transition.
1394
+ // Run the close transition.
1395
+ await closeTransition(modal.el, config);
1373
1396
 
1374
- await closeTransition(modal.el, config); // Remove modal from stack.
1375
-
1376
- this.stack.remove(modal); // Update focus if the focus param is true.
1397
+ // Remove modal from stack.
1398
+ this.stack.remove(modal);
1377
1399
 
1400
+ // Update focus if the focus param is true.
1378
1401
  if (focus) {
1379
1402
  updateFocusState.call(this);
1380
- } // Update modal state.
1381
-
1403
+ }
1382
1404
 
1383
- modal.state = 'closed'; // Dispatch custom closed event.
1405
+ // Update modal state.
1406
+ modal.state = 'closed';
1384
1407
 
1408
+ // Dispatch custom closed event.
1385
1409
  modal.el.dispatchEvent(new CustomEvent(config.customEventPrefix + 'closed', {
1386
1410
  detail: this,
1387
1411
  bubbles: true
1388
1412
  }));
1389
- } // Return the modal.
1390
-
1413
+ }
1391
1414
 
1415
+ // Return the modal.
1392
1416
  return modal;
1393
1417
  }
1394
1418
 
@@ -1400,7 +1424,6 @@ async function closeAll$1(exclude, transition) {
1400
1424
  } else {
1401
1425
  result.push(await close$1.call(this, modal, transition, false));
1402
1426
  }
1403
-
1404
1427
  modal.trigger = null;
1405
1428
  }));
1406
1429
  return result;
@@ -1408,10 +1431,10 @@ async function closeAll$1(exclude, transition) {
1408
1431
 
1409
1432
  async function replace(query, transition, focus = true) {
1410
1433
  // Get the modal from collection.
1411
- const modal = getModal.call(this, query); // Setup results for return.
1434
+ const modal = getModal.call(this, query);
1412
1435
 
1436
+ // Setup results for return.
1413
1437
  let resultOpened, resultClosed;
1414
-
1415
1438
  if (modal.state === 'opened') {
1416
1439
  // If modal is open, close all modals except for replacement.
1417
1440
  resultOpened = modal;
@@ -1421,14 +1444,14 @@ async function replace(query, transition, focus = true) {
1421
1444
  resultOpened = open$1.call(this, modal, transition, false);
1422
1445
  resultClosed = closeAll$1.call(this, false, transition);
1423
1446
  await Promise.all([resultOpened, resultClosed]);
1424
- } // Update focus if the focus param is true.
1425
-
1447
+ }
1426
1448
 
1449
+ // Update focus if the focus param is true.
1427
1450
  if (focus) {
1428
1451
  updateFocusState.call(this);
1429
- } // Return the modals there were opened and closed.
1430
-
1452
+ }
1431
1453
 
1454
+ // Return the modals there were opened and closed.
1432
1455
  return {
1433
1456
  opened: resultOpened,
1434
1457
  closed: resultClosed
@@ -1437,27 +1460,25 @@ async function replace(query, transition, focus = true) {
1437
1460
 
1438
1461
  async function register$1(el, dialog) {
1439
1462
  // Deregister entry incase it has already been registered.
1440
- await deregister$1.call(this, el, false); // Save root this for use inside methods API.
1463
+ await deregister$1.call(this, el, false);
1441
1464
 
1442
- const root = this; // Setup methods API.
1465
+ // Save root this for use inside methods API.
1466
+ const root = this;
1443
1467
 
1468
+ // Setup methods API.
1444
1469
  const methods = {
1445
1470
  open(transition, focus) {
1446
1471
  return open$1.call(root, this, transition, focus);
1447
1472
  },
1448
-
1449
1473
  close(transition, focus) {
1450
1474
  return close$1.call(root, this, transition, focus);
1451
1475
  },
1452
-
1453
1476
  replace(transition, focus) {
1454
1477
  return replace.call(root, this, transition, focus);
1455
1478
  },
1456
-
1457
1479
  deregister() {
1458
1480
  return deregister$1.call(root, this);
1459
1481
  },
1460
-
1461
1482
  teleport(ref = this.getSetting('teleport'), method = this.getSetting('teleportMethod')) {
1462
1483
  if (!this.returnRef) {
1463
1484
  this.returnRef = teleport(this.el, ref, method);
@@ -1467,7 +1488,6 @@ async function register$1(el, dialog) {
1467
1488
  return false;
1468
1489
  }
1469
1490
  },
1470
-
1471
1491
  teleportReturn() {
1472
1492
  if (this.returnRef) {
1473
1493
  this.returnRef = teleport(this.el, this.returnRef);
@@ -1477,13 +1497,12 @@ async function register$1(el, dialog) {
1477
1497
  return false;
1478
1498
  }
1479
1499
  },
1480
-
1481
1500
  getSetting(key) {
1482
1501
  return key in this.settings ? this.settings[key] : root.settings[key];
1483
1502
  }
1503
+ };
1484
1504
 
1485
- }; // Setup the modal object.
1486
-
1505
+ // Setup the modal object.
1487
1506
  const entry = _extends({
1488
1507
  id: el.id,
1489
1508
  state: 'closed',
@@ -1491,40 +1510,42 @@ async function register$1(el, dialog) {
1491
1510
  dialog: dialog,
1492
1511
  returnRef: null,
1493
1512
  settings: getConfig$1(el, this.settings.dataConfig)
1494
- }, methods); // Set aria-modal attribute to true.
1513
+ }, methods);
1495
1514
 
1515
+ // Set aria-modal attribute to true.
1516
+ entry.dialog.setAttribute('aria-modal', 'true');
1496
1517
 
1497
- entry.dialog.setAttribute('aria-modal', 'true'); // If a role attribute is not set, set it to "dialog" as the default.
1498
-
1518
+ // If a role attribute is not set, set it to "dialog" as the default.
1499
1519
  if (!entry.dialog.hasAttribute('role')) {
1500
1520
  entry.dialog.setAttribute('role', 'dialog');
1501
- } // Set tabindex="-1" so dialog is focusable via JS or click.
1502
-
1521
+ }
1503
1522
 
1523
+ // Set tabindex="-1" so dialog is focusable via JS or click.
1504
1524
  if (entry.getSetting('setTabindex')) {
1505
1525
  entry.dialog.setAttribute('tabindex', '-1');
1506
- } // Teleport modal if a reference has been set.
1507
-
1526
+ }
1508
1527
 
1528
+ // Teleport modal if a reference has been set.
1509
1529
  if (entry.getSetting('teleport')) {
1510
1530
  entry.teleport();
1511
- } // Add entry to collection.
1512
-
1531
+ }
1513
1532
 
1514
- this.collection.push(entry); // Setup initial state.
1533
+ // Add entry to collection.
1534
+ this.collection.push(entry);
1515
1535
 
1536
+ // Setup initial state.
1516
1537
  if (entry.el.classList.contains(this.settings.stateOpened)) {
1517
1538
  // Open entry with transitions disabled.
1518
1539
  await entry.open(false);
1519
1540
  } else {
1520
1541
  // Remove transition state classes.
1521
1542
  entry.el.classList.remove(this.settings.stateOpening);
1522
- entry.el.classList.remove(this.settings.stateClosing); // Add closed state class.
1523
-
1543
+ entry.el.classList.remove(this.settings.stateClosing);
1544
+ // Add closed state class.
1524
1545
  entry.el.classList.add(this.settings.stateClosed);
1525
- } // Return the registered entry.
1526
-
1546
+ }
1527
1547
 
1548
+ // Return the registered entry.
1528
1549
  return entry;
1529
1550
  }
1530
1551
 
@@ -1534,11 +1555,9 @@ function stack(settings) {
1534
1555
  get value() {
1535
1556
  return [...stackArray];
1536
1557
  },
1537
-
1538
1558
  get top() {
1539
1559
  return stackArray[stackArray.length - 1];
1540
1560
  },
1541
-
1542
1561
  updateIndex() {
1543
1562
  stackArray.forEach((entry, index) => {
1544
1563
  entry.el.style.zIndex = null;
@@ -1546,60 +1565,60 @@ function stack(settings) {
1546
1565
  entry.el.style.zIndex = parseInt(value) + index + 1;
1547
1566
  });
1548
1567
  },
1549
-
1550
1568
  updateGlobalState() {
1551
1569
  updateGlobalState(this.top, settings);
1552
1570
  this.updateIndex();
1553
1571
  },
1554
-
1555
1572
  add(entry) {
1556
1573
  // Apply z-index styles based on stack length.
1557
1574
  entry.el.style.zIndex = null;
1558
1575
  const value = getComputedStyle(entry.el)['z-index'];
1559
- entry.el.style.zIndex = parseInt(value) + stackArray.length + 1; // Move back to end of stack.
1576
+ entry.el.style.zIndex = parseInt(value) + stackArray.length + 1;
1560
1577
 
1561
- stackArray.push(entry); // Update the global state.
1578
+ // Move back to end of stack.
1579
+ stackArray.push(entry);
1562
1580
 
1581
+ // Update the global state.
1563
1582
  this.updateGlobalState();
1564
1583
  },
1565
-
1566
1584
  remove(entry) {
1567
1585
  // Get the index of the entry.
1568
1586
  const index = stackArray.findIndex(item => {
1569
1587
  return item.id === entry.id;
1570
- }); // If entry is in stack...
1588
+ });
1571
1589
 
1590
+ // If entry is in stack...
1572
1591
  if (index >= 0) {
1573
1592
  // Remove z-index styles.
1574
- entry.el.style.zIndex = null; // Remove entry from stack array.
1593
+ entry.el.style.zIndex = null;
1575
1594
 
1576
- stackArray.splice(index, 1); // Update the global state.
1595
+ // Remove entry from stack array.
1596
+ stackArray.splice(index, 1);
1577
1597
 
1598
+ // Update the global state.
1578
1599
  this.updateGlobalState();
1579
1600
  }
1580
1601
  },
1581
-
1582
1602
  moveToTop(entry) {
1583
1603
  // Get the index of the entry.
1584
1604
  const index = stackArray.findIndex(item => {
1585
1605
  return item.id === entry.id;
1586
- }); // If entry is in stack...
1606
+ });
1587
1607
 
1608
+ // If entry is in stack...
1588
1609
  if (index >= 0) {
1589
1610
  // Remove entry from stack array.
1590
- stackArray.splice(index, 1); // Add entry back to top of stack.
1611
+ stackArray.splice(index, 1);
1591
1612
 
1613
+ // Add entry back to top of stack.
1592
1614
  this.add(entry);
1593
1615
  }
1594
1616
  }
1595
-
1596
1617
  };
1597
1618
  }
1598
1619
 
1599
1620
  var _handleClick = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
1600
-
1601
1621
  var _handleKeydown$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
1602
-
1603
1622
  class Modal extends Collection {
1604
1623
  constructor(options) {
1605
1624
  super();
@@ -1614,91 +1633,80 @@ class Modal extends Collection {
1614
1633
  this.defaults = defaults$1;
1615
1634
  this.settings = _extends({}, this.defaults, options);
1616
1635
  this.trigger = null;
1617
- this.focusTrap = new FocusTrap(); // Setup stack module.
1636
+ this.focusTrap = new FocusTrap();
1618
1637
 
1638
+ // Setup stack module.
1619
1639
  this.stack = stack(this.settings);
1620
1640
  _classPrivateFieldLooseBase(this, _handleClick)[_handleClick] = handleClick$1.bind(this);
1621
1641
  _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1] = handleKeydown$1.bind(this);
1622
1642
  if (this.settings.autoInit) this.init();
1623
1643
  }
1624
-
1625
1644
  get active() {
1626
1645
  return this.stack.top;
1627
1646
  }
1628
-
1629
1647
  async init(options) {
1630
1648
  // Update settings with passed options.
1631
- if (options) this.settings = _extends({}, this.settings, options); // Get all the modals.
1649
+ if (options) this.settings = _extends({}, this.settings, options);
1632
1650
 
1633
- const modals = document.querySelectorAll(this.settings.selectorModal); // Register the collections array with modal instances.
1651
+ // Get all the modals.
1652
+ const modals = document.querySelectorAll(this.settings.selectorModal);
1634
1653
 
1635
- await this.registerCollection(modals); // If eventListeners are enabled, init event listeners.
1654
+ // Register the collections array with modal instances.
1655
+ await this.registerCollection(modals);
1636
1656
 
1657
+ // If eventListeners are enabled, init event listeners.
1637
1658
  if (this.settings.eventListeners) {
1638
1659
  this.initEventListeners();
1639
1660
  }
1640
-
1641
1661
  return this;
1642
1662
  }
1643
-
1644
1663
  async destroy() {
1645
1664
  // Clear stored trigger.
1646
- this.trigger = null; // Remove all entries from the collection.
1665
+ this.trigger = null;
1647
1666
 
1648
- await this.deregisterCollection(); // If eventListeners are enabled, destroy event listeners.
1667
+ // Remove all entries from the collection.
1668
+ await this.deregisterCollection();
1649
1669
 
1670
+ // If eventListeners are enabled, destroy event listeners.
1650
1671
  if (this.settings.eventListeners) {
1651
1672
  this.destroyEventListeners();
1652
1673
  }
1653
-
1654
1674
  return this;
1655
1675
  }
1656
-
1657
1676
  initEventListeners() {
1658
1677
  document.addEventListener('click', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
1659
- document.addEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
1660
1678
  document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1], false);
1661
1679
  }
1662
-
1663
1680
  destroyEventListeners() {
1664
1681
  document.removeEventListener('click', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
1665
- document.removeEventListener('touchend', _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
1666
1682
  document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1], false);
1667
1683
  }
1668
-
1669
1684
  register(query) {
1670
1685
  const els = getModalElements.call(this, query);
1671
1686
  if (els.error) return Promise.reject(els.error);
1672
1687
  return register$1.call(this, els.modal, els.dialog);
1673
1688
  }
1674
-
1675
1689
  deregister(query) {
1676
1690
  const modal = this.get(getModalID.call(this, query));
1677
1691
  return deregister$1.call(this, modal);
1678
1692
  }
1679
-
1680
1693
  open(id, transition, focus) {
1681
1694
  return open$1.call(this, id, transition, focus);
1682
1695
  }
1683
-
1684
1696
  close(id, transition, focus) {
1685
1697
  return close$1.call(this, id, transition, focus);
1686
1698
  }
1687
-
1688
1699
  replace(id, transition, focus) {
1689
1700
  return replace.call(this, id, transition, focus);
1690
1701
  }
1691
-
1692
1702
  async closeAll(exclude = false, transition, focus = true) {
1693
- const result = await closeAll$1.call(this, exclude, transition); // Update focus if the focus param is true.
1694
-
1703
+ const result = await closeAll$1.call(this, exclude, transition);
1704
+ // Update focus if the focus param is true.
1695
1705
  if (focus) {
1696
1706
  updateFocusState.call(this);
1697
1707
  }
1698
-
1699
1708
  return result;
1700
1709
  }
1701
-
1702
1710
  }
1703
1711
 
1704
1712
  var defaults = {
@@ -1716,8 +1724,9 @@ var defaults = {
1716
1724
 
1717
1725
  function getConfig(el, settings) {
1718
1726
  // Get the computed styles of the element.
1719
- const styles = getComputedStyle(el); // Setup the config obj with default values.
1727
+ const styles = getComputedStyle(el);
1720
1728
 
1729
+ // Setup the config obj with default values.
1721
1730
  const config = {
1722
1731
  'placement': settings.placement,
1723
1732
  'event': settings.eventType,
@@ -1726,36 +1735,40 @@ function getConfig(el, settings) {
1726
1735
  'flip-padding': 0,
1727
1736
  'arrow-element': settings.selectorArrow,
1728
1737
  'arrow-padding': 0
1729
- }; // Loop through config obj.
1738
+ };
1730
1739
 
1740
+ // Loop through config obj.
1731
1741
  for (const prop in config) {
1732
1742
  // Get the CSS variable property values.
1733
1743
  const prefix = g();
1734
- const value = styles.getPropertyValue(`--${prefix}popover-${prop}`).trim(); // If a value was found, replace the default in config obj.
1744
+ const value = styles.getPropertyValue(`--${prefix}popover-${prop}`).trim();
1735
1745
 
1746
+ // If a value was found, replace the default in config obj.
1736
1747
  if (value) {
1737
1748
  config[prop] = value;
1738
1749
  }
1739
- } // Return the config obj.
1740
-
1750
+ }
1741
1751
 
1752
+ // Return the config obj.
1742
1753
  return config;
1743
1754
  }
1744
1755
 
1745
1756
  function getPadding(value) {
1746
- let padding; // Split the value by spaces if it's a string.
1757
+ let padding;
1747
1758
 
1748
- const array = typeof value === 'string' ? value.trim().split(' ') : [value]; // Convert individual values to integers.
1759
+ // Split the value by spaces if it's a string.
1760
+ const array = typeof value === 'string' ? value.trim().split(' ') : [value];
1749
1761
 
1762
+ // Convert individual values to integers.
1750
1763
  array.forEach(function (item, index) {
1751
1764
  array[index] = parseInt(item, 10);
1752
- }); // Build the padding object based on the number of values passed.
1765
+ });
1753
1766
 
1767
+ // Build the padding object based on the number of values passed.
1754
1768
  switch (array.length) {
1755
1769
  case 1:
1756
1770
  padding = array[0];
1757
1771
  break;
1758
-
1759
1772
  case 2:
1760
1773
  padding = {
1761
1774
  top: array[0],
@@ -1764,7 +1777,6 @@ function getPadding(value) {
1764
1777
  left: array[1]
1765
1778
  };
1766
1779
  break;
1767
-
1768
1780
  case 3:
1769
1781
  padding = {
1770
1782
  top: array[0],
@@ -1773,7 +1785,6 @@ function getPadding(value) {
1773
1785
  left: array[1]
1774
1786
  };
1775
1787
  break;
1776
-
1777
1788
  case 4:
1778
1789
  padding = {
1779
1790
  top: array[0],
@@ -1782,13 +1793,12 @@ function getPadding(value) {
1782
1793
  left: array[3]
1783
1794
  };
1784
1795
  break;
1785
-
1786
1796
  default:
1787
1797
  padding = false;
1788
1798
  break;
1789
- } // Return the padding object.
1790
-
1799
+ }
1791
1800
 
1801
+ // Return the padding object.
1792
1802
  return padding;
1793
1803
  }
1794
1804
 
@@ -1819,8 +1829,9 @@ function getModifiers(options) {
1819
1829
 
1820
1830
  function getPopover(query) {
1821
1831
  // Get the entry from collection.
1822
- const entry = typeof query === 'string' ? this.get(query) : this.get(query.id); // Return entry if it was resolved, otherwise throw error.
1832
+ const entry = typeof query === 'string' ? this.get(query) : this.get(query.id);
1823
1833
 
1834
+ // Return entry if it was resolved, otherwise throw error.
1824
1835
  if (entry) {
1825
1836
  return entry;
1826
1837
  } else {
@@ -1832,34 +1843,44 @@ function getPopoverID(obj) {
1832
1843
  // If it's a string, return the string.
1833
1844
  if (typeof obj === 'string') {
1834
1845
  return obj;
1835
- } // If it's an HTML element.
1846
+ }
1847
+
1848
+ // If it's an HTML element.
1836
1849
  else if (typeof obj.hasAttribute === 'function') {
1837
1850
  // If it's a popover element, return the id.
1838
1851
  if (obj.closest(this.settings.selectorPopover)) {
1839
1852
  obj = obj.closest(this.settings.selectorPopover);
1840
1853
  return obj.id;
1841
- } // If it's a popover trigger, return value of aria-controls.
1854
+ }
1855
+
1856
+ // If it's a popover trigger, return value of aria-controls.
1842
1857
  else if (obj.hasAttribute('aria-controls')) {
1843
1858
  return obj.getAttribute('aria-controls');
1844
- } // If it's a popover tooltip trigger, return the value of aria-describedby.
1859
+ }
1860
+
1861
+ // If it's a popover tooltip trigger, return the value of aria-describedby.
1845
1862
  else if (obj.hasAttribute('aria-describedby')) {
1846
1863
  return obj.getAttribute('aria-describedby');
1847
- } // Return false if no id was found.
1864
+ }
1865
+
1866
+ // Return false if no id was found.
1848
1867
  else return false;
1849
- } // If it has an id property, return its value.
1868
+ }
1869
+
1870
+ // If it has an id property, return its value.
1850
1871
  else if (obj.id) {
1851
1872
  return obj.id;
1852
- } // Return false if no id was found.
1873
+ }
1874
+
1875
+ // Return false if no id was found.
1853
1876
  else return false;
1854
1877
  }
1855
1878
 
1856
1879
  function getPopoverElements(query) {
1857
1880
  const id = getPopoverID.call(this, query);
1858
-
1859
1881
  if (id) {
1860
1882
  const popover = document.querySelector(`#${id}`);
1861
1883
  const trigger = document.querySelector(`[aria-controls="${id}"]`) || document.querySelector(`[aria-describedby="${id}"]`);
1862
-
1863
1884
  if (!trigger && !popover) {
1864
1885
  return {
1865
1886
  error: new Error(`No popover elements found using the ID: "${id}".`)
@@ -1887,32 +1908,36 @@ function getPopoverElements(query) {
1887
1908
 
1888
1909
  async function close(query) {
1889
1910
  // Get the popover from collection.
1890
- const popover = query ? getPopover.call(this, query) : await closeAll.call(this); // If a modal exists and its state is opened.
1911
+ const popover = query ? getPopover.call(this, query) : await closeAll.call(this);
1891
1912
 
1913
+ // If a modal exists and its state is opened.
1892
1914
  if (popover && popover.state === 'opened') {
1893
1915
  // Update state class.
1894
- popover.el.classList.remove(this.settings.stateActive); // Update accessibility attribute(s).
1916
+ popover.el.classList.remove(this.settings.stateActive);
1895
1917
 
1918
+ // Update accessibility attribute(s).
1896
1919
  if (popover.trigger.hasAttribute('aria-controls')) {
1897
1920
  popover.trigger.setAttribute('aria-expanded', 'false');
1898
- } // Disable popper event listeners.
1899
-
1921
+ }
1900
1922
 
1923
+ // Disable popper event listeners.
1901
1924
  popover.popper.setOptions({
1902
1925
  modifiers: [{
1903
1926
  name: 'eventListeners',
1904
1927
  enabled: false
1905
1928
  }]
1906
- }); // Update popover state.
1929
+ });
1907
1930
 
1908
- popover.state = 'closed'; // Clear root trigger if popover trigger matches.
1931
+ // Update popover state.
1932
+ popover.state = 'closed';
1909
1933
 
1934
+ // Clear root trigger if popover trigger matches.
1910
1935
  if (popover.trigger === this.trigger) {
1911
1936
  this.trigger = null;
1912
1937
  }
1913
- } // Return the popover.
1914
-
1938
+ }
1915
1939
 
1940
+ // Return the popover.
1916
1941
  return popover;
1917
1942
  }
1918
1943
  async function closeAll() {
@@ -1926,19 +1951,22 @@ async function closeAll() {
1926
1951
  }
1927
1952
  function closeCheck(popover) {
1928
1953
  // Only run closeCheck if provided popover is currently open.
1929
- if (popover.state != 'opened') return; // Needed to correctly check which element is currently being focused.
1954
+ if (popover.state != 'opened') return;
1930
1955
 
1956
+ // Needed to correctly check which element is currently being focused.
1931
1957
  setTimeout(() => {
1932
1958
  // Check if trigger or element are being hovered.
1933
- const isHovered = popover.el.closest(':hover') === popover.el || popover.trigger.closest(':hover') === popover.trigger; // Check if trigger or element are being focused.
1959
+ const isHovered = popover.el.closest(':hover') === popover.el || popover.trigger.closest(':hover') === popover.trigger;
1934
1960
 
1935
- const isFocused = document.activeElement.closest(`#${popover.id}, [aria-controls="${popover.id}"], [aria-describedby="${popover.id}"]`); // Close if the trigger and element are not currently hovered or focused.
1961
+ // Check if trigger or element are being focused.
1962
+ const isFocused = document.activeElement.closest(`#${popover.id}, [aria-controls="${popover.id}"], [aria-describedby="${popover.id}"]`);
1936
1963
 
1964
+ // Close if the trigger and element are not currently hovered or focused.
1937
1965
  if (!isHovered && !isFocused) {
1938
1966
  popover.close();
1939
- } // Return the popover.
1940
-
1967
+ }
1941
1968
 
1969
+ // Return the popover.
1942
1970
  return popover;
1943
1971
  }, 1);
1944
1972
  }
@@ -1958,16 +1986,13 @@ function handleKeydown(event) {
1958
1986
  if (this.trigger) {
1959
1987
  this.trigger.focus();
1960
1988
  }
1961
-
1962
1989
  closeAll.call(this);
1963
1990
  return;
1964
-
1965
1991
  case 'Tab':
1966
1992
  this.collection.forEach(popover => {
1967
1993
  closeCheck.call(this, popover);
1968
1994
  });
1969
1995
  return;
1970
-
1971
1996
  default:
1972
1997
  return;
1973
1998
  }
@@ -1976,8 +2001,9 @@ function handleDocumentClick(popover) {
1976
2001
  const root = this;
1977
2002
  document.addEventListener('click', function _f(event) {
1978
2003
  // Check if a popover or its trigger was clicked.
1979
- const wasClicked = event.target.closest(`#${popover.id}, [aria-controls="${popover.id}"], [aria-describedby="${popover.id}"]`); // If popover or popover trigger was clicked...
2004
+ const wasClicked = event.target.closest(`#${popover.id}, [aria-controls="${popover.id}"], [aria-describedby="${popover.id}"]`);
1980
2005
 
2006
+ // If popover or popover trigger was clicked...
1981
2007
  if (wasClicked) {
1982
2008
  // If popover element exists and is not active...
1983
2009
  if (popover.el && !popover.el.classList.contains(root.settings.stateActive)) {
@@ -1988,7 +2014,6 @@ function handleDocumentClick(popover) {
1988
2014
  if (popover.el && popover.el.classList.contains(root.settings.stateActive)) {
1989
2015
  popover.close();
1990
2016
  }
1991
-
1992
2017
  this.removeEventListener('click', _f);
1993
2018
  }
1994
2019
  });
@@ -2154,38 +2179,57 @@ var max = Math.max;
2154
2179
  var min = Math.min;
2155
2180
  var round = Math.round;
2156
2181
 
2157
- function getBoundingClientRect(element, includeScale) {
2182
+ function getUAString() {
2183
+ var uaData = navigator.userAgentData;
2184
+
2185
+ if (uaData != null && uaData.brands) {
2186
+ return uaData.brands.map(function (item) {
2187
+ return item.brand + "/" + item.version;
2188
+ }).join(' ');
2189
+ }
2190
+
2191
+ return navigator.userAgent;
2192
+ }
2193
+
2194
+ function isLayoutViewport() {
2195
+ return !/^((?!chrome|android).)*safari/i.test(getUAString());
2196
+ }
2197
+
2198
+ function getBoundingClientRect(element, includeScale, isFixedStrategy) {
2158
2199
  if (includeScale === void 0) {
2159
2200
  includeScale = false;
2160
2201
  }
2161
2202
 
2162
- var rect = element.getBoundingClientRect();
2203
+ if (isFixedStrategy === void 0) {
2204
+ isFixedStrategy = false;
2205
+ }
2206
+
2207
+ var clientRect = element.getBoundingClientRect();
2163
2208
  var scaleX = 1;
2164
2209
  var scaleY = 1;
2165
2210
 
2166
- if (isHTMLElement(element) && includeScale) {
2167
- var offsetHeight = element.offsetHeight;
2168
- var offsetWidth = element.offsetWidth; // Do not attempt to divide by 0, otherwise we get `Infinity` as scale
2169
- // Fallback to 1 in case both values are `0`
2170
-
2171
- if (offsetWidth > 0) {
2172
- scaleX = round(rect.width) / offsetWidth || 1;
2173
- }
2174
-
2175
- if (offsetHeight > 0) {
2176
- scaleY = round(rect.height) / offsetHeight || 1;
2177
- }
2211
+ if (includeScale && isHTMLElement(element)) {
2212
+ scaleX = element.offsetWidth > 0 ? round(clientRect.width) / element.offsetWidth || 1 : 1;
2213
+ scaleY = element.offsetHeight > 0 ? round(clientRect.height) / element.offsetHeight || 1 : 1;
2178
2214
  }
2179
2215
 
2216
+ var _ref = isElement(element) ? getWindow(element) : window,
2217
+ visualViewport = _ref.visualViewport;
2218
+
2219
+ var addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
2220
+ var x = (clientRect.left + (addVisualOffsets && visualViewport ? visualViewport.offsetLeft : 0)) / scaleX;
2221
+ var y = (clientRect.top + (addVisualOffsets && visualViewport ? visualViewport.offsetTop : 0)) / scaleY;
2222
+ var width = clientRect.width / scaleX;
2223
+ var height = clientRect.height / scaleY;
2180
2224
  return {
2181
- width: rect.width / scaleX,
2182
- height: rect.height / scaleY,
2183
- top: rect.top / scaleY,
2184
- right: rect.right / scaleX,
2185
- bottom: rect.bottom / scaleY,
2186
- left: rect.left / scaleX,
2187
- x: rect.left / scaleX,
2188
- y: rect.top / scaleY
2225
+ width: width,
2226
+ height: height,
2227
+ top: y,
2228
+ right: x + width,
2229
+ bottom: y + height,
2230
+ left: x,
2231
+ x: x,
2232
+ y: y
2189
2233
  };
2190
2234
  }
2191
2235
 
@@ -2280,8 +2324,8 @@ function getTrueOffsetParent(element) {
2280
2324
 
2281
2325
 
2282
2326
  function getContainingBlock(element) {
2283
- var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') !== -1;
2284
- var isIE = navigator.userAgent.indexOf('Trident') !== -1;
2327
+ var isFirefox = /firefox/i.test(getUAString());
2328
+ var isIE = /Trident/i.test(getUAString());
2285
2329
 
2286
2330
  if (isIE && isHTMLElement(element)) {
2287
2331
  // In IE 9, 10 and 11 fixed elements containing block is always established by the viewport
@@ -2702,31 +2746,21 @@ function getWindowScrollBarX(element) {
2702
2746
  return getBoundingClientRect(getDocumentElement(element)).left + getWindowScroll(element).scrollLeft;
2703
2747
  }
2704
2748
 
2705
- function getViewportRect(element) {
2749
+ function getViewportRect(element, strategy) {
2706
2750
  var win = getWindow(element);
2707
2751
  var html = getDocumentElement(element);
2708
2752
  var visualViewport = win.visualViewport;
2709
2753
  var width = html.clientWidth;
2710
2754
  var height = html.clientHeight;
2711
2755
  var x = 0;
2712
- var y = 0; // NB: This isn't supported on iOS <= 12. If the keyboard is open, the popper
2713
- // can be obscured underneath it.
2714
- // Also, `html.clientHeight` adds the bottom bar height in Safari iOS, even
2715
- // if it isn't open, so if this isn't available, the popper will be detected
2716
- // to overflow the bottom of the screen too early.
2756
+ var y = 0;
2717
2757
 
2718
2758
  if (visualViewport) {
2719
2759
  width = visualViewport.width;
2720
- height = visualViewport.height; // Uses Layout Viewport (like Chrome; Safari does not currently)
2721
- // In Chrome, it returns a value very close to 0 (+/-) but contains rounding
2722
- // errors due to floating point numbers, so we need to check precision.
2723
- // Safari returns a number <= 0, usually < -1 when pinch-zoomed
2724
- // Feature detection fails in mobile emulation mode in Chrome.
2725
- // Math.abs(win.innerWidth / visualViewport.scale - visualViewport.width) <
2726
- // 0.001
2727
- // Fallback here: "Not Safari" userAgent
2728
-
2729
- if (!/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
2760
+ height = visualViewport.height;
2761
+ var layoutViewport = isLayoutViewport();
2762
+
2763
+ if (layoutViewport || !layoutViewport && strategy === 'fixed') {
2730
2764
  x = visualViewport.offsetLeft;
2731
2765
  y = visualViewport.offsetTop;
2732
2766
  }
@@ -2820,8 +2854,8 @@ function rectToClientRect(rect) {
2820
2854
  });
2821
2855
  }
2822
2856
 
2823
- function getInnerBoundingClientRect(element) {
2824
- var rect = getBoundingClientRect(element);
2857
+ function getInnerBoundingClientRect(element, strategy) {
2858
+ var rect = getBoundingClientRect(element, false, strategy === 'fixed');
2825
2859
  rect.top = rect.top + element.clientTop;
2826
2860
  rect.left = rect.left + element.clientLeft;
2827
2861
  rect.bottom = rect.top + element.clientHeight;
@@ -2833,8 +2867,8 @@ function getInnerBoundingClientRect(element) {
2833
2867
  return rect;
2834
2868
  }
2835
2869
 
2836
- function getClientRectFromMixedType(element, clippingParent) {
2837
- return clippingParent === viewport ? rectToClientRect(getViewportRect(element)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
2870
+ function getClientRectFromMixedType(element, clippingParent, strategy) {
2871
+ return clippingParent === viewport ? rectToClientRect(getViewportRect(element, strategy)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent, strategy) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
2838
2872
  } // A "clipping parent" is an overflowable container with the characteristic of
2839
2873
  // clipping (or hiding) overflowing elements with a position different from
2840
2874
  // `initial`
@@ -2857,18 +2891,18 @@ function getClippingParents(element) {
2857
2891
  // clipping parents
2858
2892
 
2859
2893
 
2860
- function getClippingRect(element, boundary, rootBoundary) {
2894
+ function getClippingRect(element, boundary, rootBoundary, strategy) {
2861
2895
  var mainClippingParents = boundary === 'clippingParents' ? getClippingParents(element) : [].concat(boundary);
2862
2896
  var clippingParents = [].concat(mainClippingParents, [rootBoundary]);
2863
2897
  var firstClippingParent = clippingParents[0];
2864
2898
  var clippingRect = clippingParents.reduce(function (accRect, clippingParent) {
2865
- var rect = getClientRectFromMixedType(element, clippingParent);
2899
+ var rect = getClientRectFromMixedType(element, clippingParent, strategy);
2866
2900
  accRect.top = max(rect.top, accRect.top);
2867
2901
  accRect.right = min(rect.right, accRect.right);
2868
2902
  accRect.bottom = min(rect.bottom, accRect.bottom);
2869
2903
  accRect.left = max(rect.left, accRect.left);
2870
2904
  return accRect;
2871
- }, getClientRectFromMixedType(element, firstClippingParent));
2905
+ }, getClientRectFromMixedType(element, firstClippingParent, strategy));
2872
2906
  clippingRect.width = clippingRect.right - clippingRect.left;
2873
2907
  clippingRect.height = clippingRect.bottom - clippingRect.top;
2874
2908
  clippingRect.x = clippingRect.left;
@@ -2949,6 +2983,8 @@ function detectOverflow(state, options) {
2949
2983
  var _options = options,
2950
2984
  _options$placement = _options.placement,
2951
2985
  placement = _options$placement === void 0 ? state.placement : _options$placement,
2986
+ _options$strategy = _options.strategy,
2987
+ strategy = _options$strategy === void 0 ? state.strategy : _options$strategy,
2952
2988
  _options$boundary = _options.boundary,
2953
2989
  boundary = _options$boundary === void 0 ? clippingParents : _options$boundary,
2954
2990
  _options$rootBoundary = _options.rootBoundary,
@@ -2963,7 +2999,7 @@ function detectOverflow(state, options) {
2963
2999
  var altContext = elementContext === popper ? reference : popper;
2964
3000
  var popperRect = state.rects.popper;
2965
3001
  var element = state.elements[altBoundary ? altContext : elementContext];
2966
- var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary);
3002
+ var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary, strategy);
2967
3003
  var referenceClientRect = getBoundingClientRect(state.elements.reference);
2968
3004
  var popperOffsets = computeOffsets({
2969
3005
  reference: referenceClientRect,
@@ -3477,7 +3513,7 @@ function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
3477
3513
  var isOffsetParentAnElement = isHTMLElement(offsetParent);
3478
3514
  var offsetParentIsScaled = isHTMLElement(offsetParent) && isElementScaled(offsetParent);
3479
3515
  var documentElement = getDocumentElement(offsetParent);
3480
- var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled);
3516
+ var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled, isFixed);
3481
3517
  var scroll = {
3482
3518
  scrollLeft: 0,
3483
3519
  scrollTop: 0
@@ -3783,33 +3819,37 @@ var createPopper = /*#__PURE__*/popperGenerator({
3783
3819
 
3784
3820
  async function deregister(obj) {
3785
3821
  // Return collection if nothing was passed.
3786
- if (!obj) return this.collection; // Check if entry has been registered in the collection.
3822
+ if (!obj) return this.collection;
3787
3823
 
3824
+ // Check if entry has been registered in the collection.
3788
3825
  const index = this.collection.findIndex(entry => {
3789
3826
  return entry.id === obj.id;
3790
3827
  });
3791
-
3792
3828
  if (index >= 0) {
3793
3829
  // Get the collection entry.
3794
- const entry = this.collection[index]; // If entry is in the opened state, close it.
3830
+ const entry = this.collection[index];
3795
3831
 
3832
+ // If entry is in the opened state, close it.
3796
3833
  if (entry.state === 'opened') {
3797
3834
  entry.close();
3798
- } // Clean up the popper instance.
3799
-
3835
+ }
3800
3836
 
3801
- entry.popper.destroy(); // Remove event listeners.
3837
+ // Clean up the popper instance.
3838
+ entry.popper.destroy();
3802
3839
 
3803
- deregisterEventListeners(entry); // Delete properties from collection entry.
3840
+ // Remove event listeners.
3841
+ deregisterEventListeners(entry);
3804
3842
 
3843
+ // Delete properties from collection entry.
3805
3844
  Object.getOwnPropertyNames(entry).forEach(prop => {
3806
3845
  delete entry[prop];
3807
- }); // Remove entry from collection.
3846
+ });
3808
3847
 
3848
+ // Remove entry from collection.
3809
3849
  this.collection.splice(index, 1);
3810
- } // Return the modified collection.
3811
-
3850
+ }
3812
3851
 
3852
+ // Return the modified collection.
3813
3853
  return this.collection;
3814
3854
  }
3815
3855
  function deregisterEventListeners(entry) {
@@ -3822,65 +3862,71 @@ function deregisterEventListeners(entry) {
3822
3862
  entry[el].removeEventListener(type, evObj.listener, false);
3823
3863
  });
3824
3864
  });
3825
- }); // Remove eventListeners object from collection.
3826
-
3865
+ });
3827
3866
 
3867
+ // Remove eventListeners object from collection.
3828
3868
  delete entry.__eventListeners;
3829
- } // Return the entry object.
3830
-
3869
+ }
3831
3870
 
3871
+ // Return the entry object.
3832
3872
  return entry;
3833
3873
  }
3834
3874
 
3835
3875
  async function open(query) {
3836
3876
  // Get the popover from collection.
3837
- const popover = getPopover.call(this, query); // Update state class.
3877
+ const popover = getPopover.call(this, query);
3838
3878
 
3839
- popover.el.classList.add(this.settings.stateActive); // Update accessibility attribute(s).
3879
+ // Update state class.
3880
+ popover.el.classList.add(this.settings.stateActive);
3840
3881
 
3882
+ // Update accessibility attribute(s).
3841
3883
  if (popover.trigger.hasAttribute('aria-controls')) {
3842
3884
  popover.trigger.setAttribute('aria-expanded', 'true');
3843
- } // Update popover config.
3844
-
3885
+ }
3845
3886
 
3846
- popover.config = getConfig(popover.el, this.settings); // Enable popper event listeners and set placement/modifiers.
3887
+ // Update popover config.
3888
+ popover.config = getConfig(popover.el, this.settings);
3847
3889
 
3890
+ // Enable popper event listeners and set placement/modifiers.
3848
3891
  popover.popper.setOptions({
3849
3892
  placement: popover.config['placement'],
3850
3893
  modifiers: [{
3851
3894
  name: 'eventListeners',
3852
3895
  enabled: true
3853
3896
  }, ...getModifiers(popover.config)]
3854
- }); // Update popover position.
3897
+ });
3855
3898
 
3856
- popover.popper.update(); // Update popover state.
3899
+ // Update popover position.
3900
+ popover.popper.update();
3857
3901
 
3858
- popover.state = 'opened'; // Return the popover.
3902
+ // Update popover state.
3903
+ popover.state = 'opened';
3859
3904
 
3905
+ // Return the popover.
3860
3906
  return popover;
3861
3907
  }
3862
3908
 
3863
3909
  async function register(el, trigger) {
3864
3910
  // Deregister entry incase it has already been registered.
3865
- deregister.call(this, el); // Save root this for use inside methods API.
3911
+ deregister.call(this, el);
3866
3912
 
3867
- const root = this; // Setup methods API.
3913
+ // Save root this for use inside methods API.
3914
+ const root = this;
3868
3915
 
3916
+ // Setup methods API.
3869
3917
  const methods = {
3870
3918
  open() {
3871
3919
  return open.call(root, this);
3872
3920
  },
3873
-
3874
3921
  close() {
3875
3922
  return close.call(root, this);
3876
3923
  },
3877
-
3878
3924
  deregister() {
3879
3925
  return deregister.call(root, this);
3880
3926
  }
3927
+ };
3881
3928
 
3882
- }; // Setup the popover object.
3883
-
3929
+ // Setup the popover object.
3884
3930
  const entry = _extends({
3885
3931
  id: el.id,
3886
3932
  state: 'closed',
@@ -3888,32 +3934,35 @@ async function register(el, trigger) {
3888
3934
  trigger: trigger,
3889
3935
  popper: createPopper(trigger, el),
3890
3936
  config: getConfig(el, this.settings)
3891
- }, methods); // Set aria-expanded to false if trigger has aria-controls attribute.
3892
-
3937
+ }, methods);
3893
3938
 
3939
+ // Set aria-expanded to false if trigger has aria-controls attribute.
3894
3940
  if (entry.trigger.hasAttribute('aria-controls')) {
3895
3941
  entry.trigger.setAttribute('aria-expanded', 'false');
3896
- } // Setup event listeners.
3897
-
3942
+ }
3898
3943
 
3899
- registerEventListeners.call(this, entry); // Add entry to collection.
3944
+ // Setup event listeners.
3945
+ registerEventListeners.call(this, entry);
3900
3946
 
3901
- this.collection.push(entry); // Set initial state.
3947
+ // Add entry to collection.
3948
+ this.collection.push(entry);
3902
3949
 
3950
+ // Set initial state.
3903
3951
  if (entry.el.classList.contains(this.settings.stateActive)) {
3904
3952
  await entry.open();
3905
3953
  handleDocumentClick.call(this, entry);
3906
- } // Return the registered entry.
3907
-
3954
+ }
3908
3955
 
3956
+ // Return the registered entry.
3909
3957
  return entry;
3910
3958
  }
3911
3959
  function registerEventListeners(entry) {
3912
3960
  // If event listeners aren't already setup.
3913
3961
  if (!entry.__eventListeners) {
3914
3962
  // Add event listeners based on event type.
3915
- const eventType = entry.config['event']; // If the event type is hover.
3963
+ const eventType = entry.config['event'];
3916
3964
 
3965
+ // If the event type is hover.
3917
3966
  if (eventType === 'hover') {
3918
3967
  // Setup event listeners object for hover.
3919
3968
  entry.__eventListeners = [{
@@ -3924,8 +3973,9 @@ function registerEventListeners(entry) {
3924
3973
  el: ['el', 'trigger'],
3925
3974
  type: ['mouseleave', 'focusout'],
3926
3975
  listener: closeCheck.bind(this, entry)
3927
- }]; // Loop through listeners and apply to the appropriate elements.
3976
+ }];
3928
3977
 
3978
+ // Loop through listeners and apply to the appropriate elements.
3929
3979
  entry.__eventListeners.forEach(evObj => {
3930
3980
  evObj.el.forEach(el => {
3931
3981
  evObj.type.forEach(type => {
@@ -3933,15 +3983,18 @@ function registerEventListeners(entry) {
3933
3983
  });
3934
3984
  });
3935
3985
  });
3936
- } // Else the event type is click.
3986
+ }
3987
+
3988
+ // Else the event type is click.
3937
3989
  else {
3938
3990
  // Setup event listeners object for click.
3939
3991
  entry.__eventListeners = [{
3940
3992
  el: ['trigger'],
3941
3993
  type: ['click'],
3942
3994
  listener: handleClick.bind(this, entry)
3943
- }]; // Loop through listeners and apply to the appropriate elements.
3995
+ }];
3944
3996
 
3997
+ // Loop through listeners and apply to the appropriate elements.
3945
3998
  entry.__eventListeners.forEach(evObj => {
3946
3999
  evObj.el.forEach(el => {
3947
4000
  evObj.type.forEach(type => {
@@ -3950,14 +4003,13 @@ function registerEventListeners(entry) {
3950
4003
  });
3951
4004
  });
3952
4005
  }
3953
- } // Return the entry object.
3954
-
4006
+ }
3955
4007
 
4008
+ // Return the entry object.
3956
4009
  return entry;
3957
4010
  }
3958
4011
 
3959
4012
  var _handleKeydown = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
3960
-
3961
4013
  class Popover extends Collection {
3962
4014
  constructor(options) {
3963
4015
  super();
@@ -3971,82 +4023,76 @@ class Popover extends Collection {
3971
4023
  _classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown] = handleKeydown.bind(this);
3972
4024
  if (this.settings.autoInit) this.init();
3973
4025
  }
3974
-
3975
4026
  async init(options) {
3976
4027
  // Update settings with passed options.
3977
- if (options) this.settings = _extends({}, this.settings, options); // Get all the popovers.
4028
+ if (options) this.settings = _extends({}, this.settings, options);
3978
4029
 
3979
- const popovers = document.querySelectorAll(this.settings.selectorPopover); // Register the collections array with popover instances.
4030
+ // Get all the popovers.
4031
+ const popovers = document.querySelectorAll(this.settings.selectorPopover);
3980
4032
 
3981
- await this.registerCollection(popovers); // If eventListeners are enabled, init event listeners.
4033
+ // Register the collections array with popover instances.
4034
+ await this.registerCollection(popovers);
3982
4035
 
4036
+ // If eventListeners are enabled, init event listeners.
3983
4037
  if (this.settings.eventListeners) {
3984
4038
  // Pass false to initEventListeners() since registerCollection()
3985
4039
  // already adds event listeners to popovers.
3986
4040
  this.initEventListeners(false);
3987
4041
  }
3988
-
3989
4042
  return this;
3990
4043
  }
3991
-
3992
4044
  async destroy() {
3993
4045
  // Clear stored trigger.
3994
- this.trigger = null; // Remove all entries from the collection.
4046
+ this.trigger = null;
3995
4047
 
3996
- await this.deregisterCollection(); // If eventListeners are enabled, destroy event listeners.
4048
+ // Remove all entries from the collection.
4049
+ await this.deregisterCollection();
3997
4050
 
4051
+ // If eventListeners are enabled, destroy event listeners.
3998
4052
  if (this.settings.eventListeners) {
3999
4053
  // Pass false to destroyEventListeners() since deregisterCollection()
4000
4054
  // already removes event listeners from popovers.
4001
4055
  this.destroyEventListeners(false);
4002
4056
  }
4003
-
4004
4057
  return this;
4005
4058
  }
4006
-
4007
4059
  initEventListeners(processCollection = true) {
4008
4060
  if (processCollection) {
4009
4061
  // Loop through collection and setup event listeners.
4010
4062
  this.collection.forEach(popover => {
4011
4063
  registerEventListeners.call(this, popover);
4012
4064
  });
4013
- } // Add keydown global event listener.
4014
-
4065
+ }
4015
4066
 
4067
+ // Add keydown global event listener.
4016
4068
  document.addEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown], false);
4017
4069
  }
4018
-
4019
4070
  destroyEventListeners(processCollection = true) {
4020
4071
  if (processCollection) {
4021
4072
  // Loop through collection and remove event listeners.
4022
4073
  this.collection.forEach(popover => {
4023
4074
  deregisterEventListeners(popover);
4024
4075
  });
4025
- } // Remove keydown global event listener.
4026
-
4076
+ }
4027
4077
 
4078
+ // Remove keydown global event listener.
4028
4079
  document.removeEventListener('keydown', _classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown], false);
4029
4080
  }
4030
-
4031
4081
  register(query) {
4032
4082
  const els = getPopoverElements.call(this, query);
4033
4083
  if (els.error) return Promise.reject(els.error);
4034
4084
  return register.call(this, els.popover, els.trigger);
4035
4085
  }
4036
-
4037
4086
  deregister(query) {
4038
4087
  const popover = this.get(getPopoverID.call(this, query));
4039
4088
  return deregister.call(this, popover);
4040
4089
  }
4041
-
4042
4090
  open(id) {
4043
4091
  return open.call(this, id);
4044
4092
  }
4045
-
4046
4093
  close(id) {
4047
4094
  return close.call(this, id);
4048
4095
  }
4049
-
4050
4096
  }
4051
4097
 
4052
4098
  export { Checkbox, Drawer, Modal, Popover, index as core };