vrembem 3.0.18 → 3.0.20

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.
@@ -0,0 +1,4090 @@
1
+ function _classPrivateFieldLooseBase(e, t) {
2
+ if (!{}.hasOwnProperty.call(e, t)) throw new TypeError("attempted to use private field on non-instance");
3
+ return e;
4
+ }
5
+ var id = 0;
6
+ function _classPrivateFieldLooseKey(e) {
7
+ return "__private_" + id++ + "_" + e;
8
+ }
9
+ function _extends() {
10
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
11
+ for (var e = 1; e < arguments.length; e++) {
12
+ var t = arguments[e];
13
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
14
+ }
15
+ return n;
16
+ }, _extends.apply(null, arguments);
17
+ }
18
+
19
+ var _handler = /*#__PURE__*/_classPrivateFieldLooseKey("handler");
20
+ class Breakpoint {
21
+ constructor(value, handler) {
22
+ Object.defineProperty(this, _handler, {
23
+ writable: true,
24
+ value: void 0
25
+ });
26
+ this.value = value;
27
+ _classPrivateFieldLooseBase(this, _handler)[_handler] = handler;
28
+ this.mql = null;
29
+ }
30
+ get handler() {
31
+ return _classPrivateFieldLooseBase(this, _handler)[_handler];
32
+ }
33
+
34
+ // Unmount existing handler before setting a new one.
35
+ set handler(func) {
36
+ if (this.mql) {
37
+ // Conditionally use removeListener() for IE11 support.
38
+ if (typeof this.mql.removeEventListener === "function") {
39
+ this.mql.removeEventListener("change", _classPrivateFieldLooseBase(this, _handler)[_handler]);
40
+ } else {
41
+ this.mql.removeListener(_classPrivateFieldLooseBase(this, _handler)[_handler]);
42
+ }
43
+ }
44
+ _classPrivateFieldLooseBase(this, _handler)[_handler] = func;
45
+ }
46
+ mount(value, handler) {
47
+ // Update passed params.
48
+ if (value) this.value = value;
49
+ if (handler) _classPrivateFieldLooseBase(this, _handler)[_handler] = handler;
50
+
51
+ // Guard if no breakpoint was set.
52
+ if (!this.value) return this;
53
+
54
+ // Setup and store the MediaQueryList instance.
55
+ this.mql = window.matchMedia(`(min-width: ${this.value})`);
56
+
57
+ // Conditionally use addListener() for IE11 support.
58
+ if (typeof this.mql.addEventListener === "function") {
59
+ this.mql.addEventListener("change", _classPrivateFieldLooseBase(this, _handler)[_handler]);
60
+ } else {
61
+ this.mql.addListener(_classPrivateFieldLooseBase(this, _handler)[_handler]);
62
+ }
63
+
64
+ // Run the handler.
65
+ _classPrivateFieldLooseBase(this, _handler)[_handler](this.mql);
66
+ return this;
67
+ }
68
+ unmount() {
69
+ // Guard if no MediaQueryList instance exists.
70
+ if (!this.mql) return this;
71
+
72
+ // Conditionally use removeListener() for IE11 support.
73
+ if (typeof this.mql.removeEventListener === "function") {
74
+ this.mql.removeEventListener("change", _classPrivateFieldLooseBase(this, _handler)[_handler]);
75
+ } else {
76
+ this.mql.removeListener(_classPrivateFieldLooseBase(this, _handler)[_handler]);
77
+ }
78
+
79
+ // Set value, handler and MediaQueryList to null.
80
+ this.value = null;
81
+ _classPrivateFieldLooseBase(this, _handler)[_handler] = null;
82
+ this.mql = null;
83
+ return this;
84
+ }
85
+ }
86
+
87
+ class Collection {
88
+ constructor() {
89
+ this.collection = [];
90
+ }
91
+ async register(item) {
92
+ await this.deregister(item);
93
+ this.collection.push(item);
94
+ return this.collection;
95
+ }
96
+ async deregister(ref) {
97
+ const index = this.collection.findIndex(entry => {
98
+ return entry === ref;
99
+ });
100
+ if (index >= 0) {
101
+ const entry = this.collection[index];
102
+ Object.getOwnPropertyNames(entry).forEach(prop => {
103
+ delete entry[prop];
104
+ });
105
+ this.collection.splice(index, 1);
106
+ }
107
+ return this.collection;
108
+ }
109
+ async registerCollection(items) {
110
+ await Promise.all(Array.from(items, item => {
111
+ this.register(item);
112
+ }));
113
+ return this.collection;
114
+ }
115
+ async deregisterCollection() {
116
+ while (this.collection.length > 0) {
117
+ await this.deregister(this.collection[0]);
118
+ }
119
+ return this.collection;
120
+ }
121
+ get(value, key = "id") {
122
+ return this.collection.find(item => {
123
+ return item[key] === value;
124
+ });
125
+ }
126
+ }
127
+
128
+ var _focusable = /*#__PURE__*/_classPrivateFieldLooseKey("focusable");
129
+ var _handleFocusTrap = /*#__PURE__*/_classPrivateFieldLooseKey("handleFocusTrap");
130
+ var _handleFocusLock = /*#__PURE__*/_classPrivateFieldLooseKey("handleFocusLock");
131
+ class FocusTrap {
132
+ constructor(el = null, selectorFocus = "[data-focus]") {
133
+ Object.defineProperty(this, _focusable, {
134
+ writable: true,
135
+ value: void 0
136
+ });
137
+ Object.defineProperty(this, _handleFocusTrap, {
138
+ writable: true,
139
+ value: void 0
140
+ });
141
+ Object.defineProperty(this, _handleFocusLock, {
142
+ writable: true,
143
+ value: void 0
144
+ });
145
+ this.el = el;
146
+ this.selectorFocus = selectorFocus;
147
+ _classPrivateFieldLooseBase(this, _handleFocusTrap)[_handleFocusTrap] = handleFocusTrap.bind(this);
148
+ _classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock] = handleFocusLock.bind(this);
149
+ }
150
+ get focusable() {
151
+ return _classPrivateFieldLooseBase(this, _focusable)[_focusable];
152
+ }
153
+ set focusable(value) {
154
+ // Update the focusable value.
155
+ _classPrivateFieldLooseBase(this, _focusable)[_focusable] = value;
156
+
157
+ // Apply event listeners based on new focusable array length.
158
+ if (_classPrivateFieldLooseBase(this, _focusable)[_focusable].length) {
159
+ document.removeEventListener("keydown", _classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock]);
160
+ document.addEventListener("keydown", _classPrivateFieldLooseBase(this, _handleFocusTrap)[_handleFocusTrap]);
161
+ } else {
162
+ document.removeEventListener("keydown", _classPrivateFieldLooseBase(this, _handleFocusTrap)[_handleFocusTrap]);
163
+ document.addEventListener("keydown", _classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock]);
164
+ }
165
+ }
166
+ get focusableFirst() {
167
+ return this.focusable[0];
168
+ }
169
+ get focusableLast() {
170
+ return this.focusable[this.focusable.length - 1];
171
+ }
172
+ mount(el, selectorFocus) {
173
+ // Update passed params.
174
+ if (el) this.el = el;
175
+ if (selectorFocus) this.selectorFocus = selectorFocus;
176
+
177
+ // Get the focusable elements.
178
+ this.focusable = this.getFocusable();
179
+
180
+ // Set the focus on the element.
181
+ this.focus();
182
+ }
183
+ unmount() {
184
+ // Set element to null.
185
+ this.el = null;
186
+
187
+ // Apply empty array to focusable.
188
+ this.focusable = [];
189
+
190
+ // Remove event listeners
191
+ document.removeEventListener("keydown", _classPrivateFieldLooseBase(this, _handleFocusTrap)[_handleFocusTrap]);
192
+ document.removeEventListener("keydown", _classPrivateFieldLooseBase(this, _handleFocusLock)[_handleFocusLock]);
193
+ }
194
+ focus(el = this.el, selectorFocus = this.selectorFocus) {
195
+ // Query for the focus selector, otherwise return this element.
196
+ const result = el.querySelector(selectorFocus) || el;
197
+ // Give the returned element focus.
198
+ result.focus();
199
+ }
200
+ getFocusable(el = this.el) {
201
+ // Initialize the focusable array.
202
+ const focusable = [];
203
+
204
+ // Store the initial focus and scroll position.
205
+ const initFocus = document.activeElement;
206
+ const initScrollTop = el.scrollTop;
207
+
208
+ // Query for all the focusable elements.
209
+ const selector = focusableSelectors.join(",");
210
+ const els = el.querySelectorAll(selector);
211
+
212
+ // Loop through all focusable elements.
213
+ els.forEach(el => {
214
+ // Set them to focus and check
215
+ el.focus();
216
+ // Test that the element took focus.
217
+ if (document.activeElement === el) {
218
+ // Add element to the focusable array.
219
+ focusable.push(el);
220
+ }
221
+ });
222
+
223
+ // Restore the initial scroll position and focus.
224
+ el.scrollTop = initScrollTop;
225
+ initFocus.focus();
226
+
227
+ // Return the focusable array.
228
+ return focusable;
229
+ }
230
+ }
231
+
232
+ // This has been copied over from focusable-selectors package and modified.
233
+ // https://github.com/KittyGiraudel/focusable-selectors
234
+ const notInert = ":not([inert])"; // Previously `:not([inert]):not([inert] *)`
235
+ const notNegTabIndex = ":not([tabindex^=\"-\"])";
236
+ const notDisabled = ":not(:disabled)";
237
+ const focusableSelectors = [`a[href]${notInert}${notNegTabIndex}`, `area[href]${notInert}${notNegTabIndex}`, `input:not([type="hidden"]):not([type="radio"])${notInert}${notNegTabIndex}${notDisabled}`, `input[type="radio"]${notInert}${notNegTabIndex}${notDisabled}`, `select${notInert}${notNegTabIndex}${notDisabled}`, `textarea${notInert}${notNegTabIndex}${notDisabled}`, `button${notInert}${notNegTabIndex}${notDisabled}`, `details${notInert} > summary:first-of-type${notNegTabIndex}`, `iframe${notInert}${notNegTabIndex}`, `audio[controls]${notInert}${notNegTabIndex}`, `video[controls]${notInert}${notNegTabIndex}`, `[contenteditable]${notInert}${notNegTabIndex}`, `[tabindex]${notInert}${notNegTabIndex}`];
238
+ function handleFocusTrap(event) {
239
+ // Check if the click was a tab and return if not.
240
+ const isTab = event.key === "Tab" || event.keyCode === 9;
241
+ if (!isTab) return;
242
+
243
+ // If the shift key is pressed.
244
+ if (event.shiftKey) {
245
+ // If the active element is either the root el or first focusable.
246
+ if (document.activeElement === this.focusableFirst || document.activeElement === this.el) {
247
+ // Prevent default and focus the last focusable element instead.
248
+ event.preventDefault();
249
+ this.focusableLast.focus();
250
+ }
251
+ } else {
252
+ // If the active element is either the root el or last focusable.
253
+ if (document.activeElement === this.focusableLast || document.activeElement === this.el) {
254
+ // Prevent default and focus the first focusable element instead.
255
+ event.preventDefault();
256
+ this.focusableFirst.focus();
257
+ }
258
+ }
259
+ }
260
+ function handleFocusLock(event) {
261
+ // Ignore the tab key by preventing default.
262
+ const isTab = event.key === "Tab" || event.keyCode === 9;
263
+ if (isTab) event.preventDefault();
264
+ }
265
+
266
+ function getConfig$1(el, dataConfig) {
267
+ const string = el.getAttribute(`data-${dataConfig}`) || "";
268
+ const json = string.replace(/'/g, "\"");
269
+ return json ? JSON.parse(json) : {};
270
+ }
271
+
272
+ function getPrefix() {
273
+ return getComputedStyle(document.body).getPropertyValue("--vrembem-variable-prefix").trim();
274
+ }
275
+
276
+ function localStore(key, enable = true) {
277
+ const local = localStorage.getItem(key);
278
+ const store = local ? JSON.parse(local) : {};
279
+ return {
280
+ get(prop) {
281
+ return prop ? store[prop] : store;
282
+ },
283
+ set(prop, value) {
284
+ if (value) {
285
+ store[prop] = value;
286
+ } else {
287
+ delete store[prop];
288
+ }
289
+ if (enable) localStorage.setItem(key, JSON.stringify(store));
290
+ return store;
291
+ }
292
+ };
293
+ }
294
+
295
+ /**
296
+ * Teleports an element in the DOM based on a reference and teleport method.
297
+ * Provide the comment node as the reference to teleport the element back to its
298
+ * previous location.
299
+ * @param {Node} what - What element to teleport.
300
+ * @param {String || Node} where - Where to teleport the element.
301
+ * @param {String} how - How (method) to teleport the element, e.g: 'after',
302
+ * 'before', 'append' or 'prepend'.
303
+ * @return {Node} Return the return reference if it was teleported else return
304
+ * null if it was returned to a comment reference.
305
+ */
306
+ function teleport(what, where, how) {
307
+ // Check if ref is either a comment or element node.
308
+ const isComment = where.nodeType === Node.COMMENT_NODE;
309
+ const isElement = where.nodeType === Node.ELEMENT_NODE;
310
+
311
+ // Get the reference element.
312
+ where = isComment || isElement ? where : document.querySelector(where);
313
+
314
+ // If ref is a comment, set teleport type to 'after'.
315
+ if (isComment) how = "after";
316
+
317
+ // Must be a valid reference element and method.
318
+ if (!where) throw new Error(`Not a valid teleport reference: '${where}'`);
319
+ if (typeof where[how] != "function") throw new Error(`Not a valid teleport method: '${how}'`);
320
+
321
+ // Initial return ref is null.
322
+ let returnRef = null;
323
+
324
+ // If ref is not a comment, set a return reference comment.
325
+ if (!isComment) {
326
+ returnRef = document.createComment("teleported #" + what.id);
327
+ what.before(returnRef);
328
+ }
329
+
330
+ // Teleport the target node.
331
+ where[how](what);
332
+
333
+ // Delete the comment node if element was returned to a comment reference.
334
+ if (isComment) {
335
+ where.remove();
336
+ }
337
+
338
+ // Return the return reference if it was teleported else return null if it was
339
+ // returned to a comment reference.
340
+ return returnRef;
341
+ }
342
+
343
+ const openTransition = (el, settings) => {
344
+ return new Promise(resolve => {
345
+ // Check if transitions are enabled.
346
+ if (settings.transition) {
347
+ // Toggle classes for opening transition.
348
+ el.classList.remove(settings.stateClosed);
349
+ el.classList.add(settings.stateOpening);
350
+
351
+ // Add event listener for when the transition is finished.
352
+ el.addEventListener("transitionend", function _f(event) {
353
+ // Prevent child transition bubbling from firing this event.
354
+ if (event.target != el) return;
355
+
356
+ // Toggle final opened state classes.
357
+ el.classList.add(settings.stateOpened);
358
+ el.classList.remove(settings.stateOpening);
359
+
360
+ // Resolve the promise and remove the event listener.
361
+ resolve(el);
362
+ this.removeEventListener("transitionend", _f);
363
+ });
364
+ } else {
365
+ // Toggle final opened state classes and resolve the promise.
366
+ el.classList.add(settings.stateOpened);
367
+ el.classList.remove(settings.stateClosed);
368
+ resolve(el);
369
+ }
370
+ });
371
+ };
372
+ const closeTransition = (el, settings) => {
373
+ return new Promise(resolve => {
374
+ // Check if transitions are enabled.
375
+ if (settings.transition) {
376
+ // Toggle classes for closing transition.
377
+ el.classList.add(settings.stateClosing);
378
+ el.classList.remove(settings.stateOpened);
379
+
380
+ // Add event listener for when the transition is finished.
381
+ el.addEventListener("transitionend", function _f(event) {
382
+ // Prevent child transition bubbling from firing this event.
383
+ if (event.target != el) return;
384
+
385
+ // Toggle final closed state classes.
386
+ el.classList.remove(settings.stateClosing);
387
+ el.classList.add(settings.stateClosed);
388
+
389
+ // Resolve the promise and remove the event listener.
390
+ resolve(el);
391
+ this.removeEventListener("transitionend", _f);
392
+ });
393
+ } else {
394
+ // Toggle final closed state classes and resolve the promise.
395
+ el.classList.add(settings.stateClosed);
396
+ el.classList.remove(settings.stateOpened);
397
+ resolve(el);
398
+ }
399
+ });
400
+ };
401
+
402
+ function setOverflowHidden(state, selector) {
403
+ if (selector) {
404
+ const els = document.querySelectorAll(selector);
405
+ els.forEach(el => {
406
+ if (state) {
407
+ el.style.overflow = "hidden";
408
+ } else {
409
+ el.style.removeProperty("overflow");
410
+ }
411
+ });
412
+ }
413
+ }
414
+ function setInert(state, selector) {
415
+ if (selector) {
416
+ const els = document.querySelectorAll(selector);
417
+ els.forEach(el => {
418
+ if (state) {
419
+ el.inert = true;
420
+ el.setAttribute("aria-hidden", true);
421
+ } else {
422
+ el.inert = null;
423
+ el.removeAttribute("aria-hidden");
424
+ }
425
+ });
426
+ }
427
+ }
428
+ function updateGlobalState(param, config) {
429
+ // Set inert state based on if a modal is active.
430
+ setInert(!!param, config.selectorInert);
431
+
432
+ // Set overflow state based on if a modal is active.
433
+ setOverflowHidden(!!param, config.selectorOverflow);
434
+ }
435
+
436
+ var index = {
437
+ __proto__: null,
438
+ Breakpoint: Breakpoint,
439
+ Collection: Collection,
440
+ FocusTrap: FocusTrap,
441
+ getConfig: getConfig$1,
442
+ getPrefix: getPrefix,
443
+ localStore: localStore,
444
+ teleport: teleport,
445
+ openTransition: openTransition,
446
+ closeTransition: closeTransition,
447
+ updateGlobalState: updateGlobalState
448
+ };
449
+
450
+ var defaults$3 = {
451
+ autoInit: false,
452
+ stateAttr: "aria-checked",
453
+ stateValue: "mixed"
454
+ };
455
+
456
+ class Checkbox {
457
+ constructor(options) {
458
+ this.defaults = defaults$3;
459
+ this.settings = _extends({}, this.defaults, options);
460
+ this.__handlerClick = this.handlerClick.bind(this);
461
+ if (this.settings.autoInit) this.init();
462
+ }
463
+ init(options = null) {
464
+ if (options) this.settings = _extends({}, this.settings, options);
465
+ const selector = `[${this.settings.stateAttr}="${this.settings.stateValue}"]`;
466
+ const mixed = document.querySelectorAll(selector);
467
+ this.setIndeterminate(mixed);
468
+ document.addEventListener("click", this.__handlerClick, false);
469
+ }
470
+ destroy() {
471
+ document.removeEventListener("click", this.__handlerClick, false);
472
+ }
473
+ handlerClick(event) {
474
+ const selector = `[${this.settings.stateAttr}="${this.settings.stateValue}"]`;
475
+ const el = event.target.closest(selector);
476
+ if (!el) return;
477
+ this.removeAriaState(el);
478
+ this.setIndeterminate(el);
479
+ }
480
+ setAriaState(el, value = this.settings.stateValue) {
481
+ el = el.forEach ? el : [el];
482
+ el.forEach(el => {
483
+ el.setAttribute(this.settings.stateAttr, value);
484
+ });
485
+ }
486
+ removeAriaState(el) {
487
+ el = el.forEach ? el : [el];
488
+ el.forEach(el => {
489
+ el.removeAttribute(this.settings.stateAttr);
490
+ });
491
+ }
492
+ setIndeterminate(el) {
493
+ el = el.forEach ? el : [el];
494
+ el.forEach(el => {
495
+ if (el.hasAttribute(this.settings.stateAttr)) {
496
+ el.indeterminate = true;
497
+ } else {
498
+ el.indeterminate = false;
499
+ }
500
+ });
501
+ }
502
+ }
503
+
504
+ var defaults$2 = {
505
+ autoInit: false,
506
+ // Data attributes
507
+ dataOpen: "drawer-open",
508
+ dataClose: "drawer-close",
509
+ dataToggle: "drawer-toggle",
510
+ dataBreakpoint: "drawer-breakpoint",
511
+ dataConfig: "drawer-config",
512
+ // Selectors
513
+ selectorDrawer: ".drawer",
514
+ selectorDialog: ".drawer__dialog",
515
+ selectorFocus: "[data-focus]",
516
+ selectorInert: null,
517
+ selectorOverflow: "body",
518
+ // State classes
519
+ stateOpened: "is-opened",
520
+ stateOpening: "is-opening",
521
+ stateClosing: "is-closing",
522
+ stateClosed: "is-closed",
523
+ // Classes
524
+ classModal: "drawer_modal",
525
+ // Feature toggles
526
+ breakpoints: null,
527
+ customEventPrefix: "drawer:",
528
+ eventListeners: true,
529
+ store: true,
530
+ storeKey: "VB:DrawerState",
531
+ setTabindex: true,
532
+ transition: true
533
+ };
534
+
535
+ function handleClick$2(event) {
536
+ // If an open, close or toggle button was clicked, handle the click event.
537
+ const trigger = event.target.closest(`
538
+ [data-${this.settings.dataOpen}],
539
+ [data-${this.settings.dataToggle}],
540
+ [data-${this.settings.dataClose}]
541
+ `);
542
+ if (trigger) {
543
+ // Prevent the default behavior of the trigger.
544
+ event.preventDefault();
545
+
546
+ // If it's a toggle trigger...
547
+ if (trigger.matches(`[data-${this.settings.dataToggle}]`)) {
548
+ const selectors = trigger.getAttribute(`data-${this.settings.dataToggle}`).trim().split(" ");
549
+ selectors.forEach(selector => {
550
+ // Get the entry from collection using the attribute value.
551
+ const entry = this.get(selector);
552
+ // Store the trigger on the entry.
553
+ entry.trigger = trigger;
554
+ // Toggle the drawer
555
+ entry.toggle();
556
+ });
557
+ }
558
+
559
+ // If it's a open trigger...
560
+ if (trigger.matches(`[data-${this.settings.dataOpen}]`)) {
561
+ const selectors = trigger.getAttribute(`data-${this.settings.dataOpen}`).trim().split(" ");
562
+ selectors.forEach(selector => {
563
+ // Get the entry from collection using the attribute value.
564
+ const entry = this.get(selector);
565
+ // Store the trigger on the entry.
566
+ entry.trigger = trigger;
567
+ // Open the drawer.
568
+ entry.open();
569
+ });
570
+ }
571
+
572
+ // If it's a close trigger...
573
+ if (trigger.matches(`[data-${this.settings.dataClose}]`)) {
574
+ const selectors = trigger.getAttribute(`data-${this.settings.dataClose}`).trim().split(" ");
575
+ selectors.forEach(selector => {
576
+ if (selector) {
577
+ // Get the entry from collection using the attribute value.
578
+ const entry = this.get(selector);
579
+ // Store the trigger on the entry.
580
+ entry.trigger = trigger;
581
+ // Close the drawer.
582
+ entry.close();
583
+ } else {
584
+ // If no value is set on close trigger, get the parent drawer.
585
+ const parent = event.target.closest(this.settings.selectorDrawer);
586
+ // If a parent drawer was found, close it.
587
+ if (parent) this.close(parent);
588
+ }
589
+ });
590
+ }
591
+ return;
592
+ }
593
+
594
+ // If the modal drawer screen was clicked...
595
+ if (event.target.matches(this.settings.selectorDrawer)) {
596
+ // Close the modal drawer.
597
+ this.close(event.target.id);
598
+ }
599
+ }
600
+ function handleKeydown$2(event) {
601
+ if (event.key === "Escape") {
602
+ const modal = this.activeModal;
603
+ if (modal) this.close(modal);
604
+ }
605
+ }
606
+
607
+ async function deregister$2(obj, close = true) {
608
+ // Return collection if nothing was passed.
609
+ if (!obj) return this.collection;
610
+
611
+ // Check if entry has been registered in the collection.
612
+ const index = this.collection.findIndex(entry => {
613
+ return entry.id === obj.id;
614
+ });
615
+ if (index >= 0) {
616
+ // Get the collection entry.
617
+ const entry = this.collection[index];
618
+
619
+ // If entry is in the opened state.
620
+ if (close && entry.state === "opened") {
621
+ // Close the drawer.
622
+ await entry.close(false);
623
+ }
624
+
625
+ // Remove entry from local store.
626
+ this.store.set(entry.id);
627
+
628
+ // Unmount the MatchMedia functionality.
629
+ entry.unmountBreakpoint();
630
+
631
+ // Delete properties from collection entry.
632
+ Object.getOwnPropertyNames(entry).forEach(prop => {
633
+ delete entry[prop];
634
+ });
635
+
636
+ // Remove entry from collection.
637
+ this.collection.splice(index, 1);
638
+ }
639
+
640
+ // Return the modified collection.
641
+ return this.collection;
642
+ }
643
+
644
+ function P() {
645
+ return getComputedStyle(document.body).getPropertyValue("--vrembem-variable-prefix").trim();
646
+ }
647
+
648
+ function getBreakpoint(drawer) {
649
+ const prefix = P();
650
+ const bp = drawer.getAttribute(`data-${this.settings.dataBreakpoint}`);
651
+ if (this.settings.breakpoints && this.settings.breakpoints[bp]) {
652
+ return this.settings.breakpoints[bp];
653
+ } else if (getComputedStyle(document.body).getPropertyValue(`--${prefix}breakpoint-${bp}`).trim()) {
654
+ return getComputedStyle(document.body).getPropertyValue(`--${prefix}breakpoint-${bp}`).trim();
655
+ } else {
656
+ return bp;
657
+ }
658
+ }
659
+
660
+ function getDrawer(query) {
661
+ // Get the entry from collection.
662
+ const entry = typeof query === "string" ? this.get(query) : this.get(query.id);
663
+
664
+ // Return entry if it was resolved, otherwise throw error.
665
+ if (entry) {
666
+ return entry;
667
+ } else {
668
+ throw new Error(`Drawer not found in collection with id of "${query.id || query}".`);
669
+ }
670
+ }
671
+
672
+ function getDrawerID(obj) {
673
+ // If it's a string, return the string.
674
+ if (typeof obj === "string") {
675
+ return obj;
676
+ }
677
+
678
+ // If it's an HTML element.
679
+ else if (typeof obj.hasAttribute === "function") {
680
+ // If it's a drawer open trigger, return data value.
681
+ if (obj.hasAttribute(`data-${this.settings.dataOpen}`)) {
682
+ return obj.getAttribute(`data-${this.settings.dataOpen}`);
683
+ }
684
+
685
+ // If it's a drawer close trigger, return data value or false.
686
+ else if (obj.hasAttribute(`data-${this.settings.dataClose}`)) {
687
+ return obj.getAttribute(`data-${this.settings.dataClose}`) || false;
688
+ }
689
+
690
+ // If it's a drawer toggle trigger, return data value.
691
+ else if (obj.hasAttribute(`data-${this.settings.dataToggle}`)) {
692
+ return obj.getAttribute(`data-${this.settings.dataToggle}`);
693
+ }
694
+
695
+ // If it's a drawer element, return the id.
696
+ else if (obj.closest(this.settings.selectorDrawer)) {
697
+ obj = obj.closest(this.settings.selectorDrawer);
698
+ return obj.id || false;
699
+ }
700
+
701
+ // Return false if no id was found.
702
+ else return false;
703
+ }
704
+
705
+ // If it has an id property, return its value.
706
+ else if (obj.id) {
707
+ return obj.id;
708
+ }
709
+
710
+ // Return false if no id was found.
711
+ else return false;
712
+ }
713
+
714
+ function getDrawerElements(query) {
715
+ const id = getDrawerID.call(this, query);
716
+ if (id) {
717
+ const drawer = document.querySelector(`#${id}`);
718
+ const dialog = drawer ? drawer.querySelector(this.settings.selectorDialog) : null;
719
+ if (!drawer && !dialog) {
720
+ return {
721
+ error: new Error(`No drawer elements found using the ID: "${id}".`)
722
+ };
723
+ } else if (!dialog) {
724
+ return {
725
+ error: new Error("Drawer is missing dialog element.")
726
+ };
727
+ } else {
728
+ return {
729
+ drawer,
730
+ dialog
731
+ };
732
+ }
733
+ } else {
734
+ return {
735
+ error: new Error("Could not resolve the drawer ID.")
736
+ };
737
+ }
738
+ }
739
+
740
+ async function initialState(entry) {
741
+ // Setup initial state using the following priority:
742
+ // 1. If a store state is available, restore from local store.
743
+ // 2. If opened state class is set, set state to opened.
744
+ // 3. Else, initialize default state.
745
+ if (this.store.get(entry.id)) {
746
+ // Restore drawers to saved inline state.
747
+ if (this.store.get(entry.id) === "opened") {
748
+ await entry.open(false, false);
749
+ } else {
750
+ await entry.close(false, false);
751
+ }
752
+ } else if (entry.el.classList.contains(this.settings.stateOpened)) {
753
+ // Update drawer state.
754
+ entry.state = "opened";
755
+ } else {
756
+ // Remove transition state classes.
757
+ entry.el.classList.remove(this.settings.stateOpening);
758
+ entry.el.classList.remove(this.settings.stateClosing);
759
+ // Add closed state class.
760
+ entry.el.classList.add(this.settings.stateClosed);
761
+ }
762
+ }
763
+
764
+ function updateFocusState$1(entry) {
765
+ // Check if there's an active modal
766
+ if (entry.state === "opened") {
767
+ // Mount the focus trap on the opened drawer.
768
+ if (entry.mode === "modal") {
769
+ this.focusTrap.mount(entry.dialog, this.settings.selectorFocus);
770
+ } else {
771
+ this.focusTrap.focus(entry.dialog, this.settings.selectorFocus);
772
+ }
773
+ } else {
774
+ // Set focus to root trigger and unmount the focus trap.
775
+ if (entry.trigger) {
776
+ entry.trigger.focus();
777
+ entry.trigger = null;
778
+ }
779
+ this.focusTrap.unmount();
780
+ }
781
+ }
782
+
783
+ async function open$2(query, transition, focus = true) {
784
+ // Get the drawer from collection.
785
+ const drawer = getDrawer.call(this, query);
786
+
787
+ // Get the modal configuration.
788
+ const config = _extends({}, this.settings, drawer.settings);
789
+
790
+ // Add transition parameter to configuration.
791
+ if (transition !== undefined) config.transition = transition;
792
+
793
+ // If drawer is closed.
794
+ if (drawer.state === "closed") {
795
+ // Update drawer state.
796
+ drawer.state = "opening";
797
+
798
+ // Run the open transition.
799
+ await openTransition(drawer.el, config);
800
+
801
+ // Update the global state if mode is modal.
802
+ if (drawer.mode === "modal") updateGlobalState(true, config);
803
+
804
+ // Update drawer state.
805
+ drawer.state = "opened";
806
+ }
807
+
808
+ // Set focus to the drawer element if the focus param is true.
809
+ if (focus) {
810
+ updateFocusState$1.call(this, drawer);
811
+ }
812
+
813
+ // Dispatch custom opened event.
814
+ drawer.el.dispatchEvent(new CustomEvent(config.customEventPrefix + "opened", {
815
+ detail: this,
816
+ bubbles: true
817
+ }));
818
+
819
+ // Return the drawer.
820
+ return drawer;
821
+ }
822
+
823
+ async function close$2(query, transition, focus = true) {
824
+ // Get the drawer from collection.
825
+ const drawer = getDrawer.call(this, query);
826
+
827
+ // Get the modal configuration.
828
+ const config = _extends({}, this.settings, drawer.settings);
829
+
830
+ // Add transition parameter to configuration.
831
+ if (transition !== undefined) config.transition = transition;
832
+
833
+ // If drawer is opened.
834
+ if (drawer.state === "opened") {
835
+ // Update drawer state.
836
+ drawer.state = "closing";
837
+
838
+ // Remove focus from active element.
839
+ document.activeElement.blur();
840
+
841
+ // Run the close transition.
842
+ await closeTransition(drawer.el, config);
843
+
844
+ // Update the global state if mode is modal.
845
+ if (drawer.mode === "modal") updateGlobalState(false, config);
846
+
847
+ // Set focus to the trigger element if the focus param is true.
848
+ if (focus) {
849
+ updateFocusState$1.call(this, drawer);
850
+ }
851
+
852
+ // Update drawer state.
853
+ drawer.state = "closed";
854
+
855
+ // Dispatch custom closed event.
856
+ drawer.el.dispatchEvent(new CustomEvent(config.customEventPrefix + "closed", {
857
+ detail: this,
858
+ bubbles: true
859
+ }));
860
+ }
861
+
862
+ // Return the drawer.
863
+ return drawer;
864
+ }
865
+
866
+ async function toggle(query, transition, focus) {
867
+ // Get the drawer from collection.
868
+ const drawer = getDrawer.call(this, query);
869
+
870
+ // Open or close the drawer based on its current state.
871
+ if (drawer.state === "closed") {
872
+ return open$2.call(this, drawer, transition, focus);
873
+ } else {
874
+ return close$2.call(this, drawer, transition, focus);
875
+ }
876
+ }
877
+
878
+ function switchMode(entry) {
879
+ switch (entry.mode) {
880
+ case "inline":
881
+ return toInline.call(this, entry);
882
+ case "modal":
883
+ return toModal.call(this, entry);
884
+ default:
885
+ throw new Error(`"${entry.mode}" is not a valid drawer mode.`);
886
+ }
887
+ }
888
+ async function toInline(entry) {
889
+ // Remove the modal class.
890
+ entry.el.classList.remove(entry.getSetting("classModal"));
891
+
892
+ // Remove the aria-modal attribute.
893
+ entry.dialog.removeAttribute("aria-modal");
894
+
895
+ // Update the global state.
896
+ updateGlobalState(false, _extends({}, this.settings, entry.settings));
897
+
898
+ // Remove any focus traps.
899
+ this.focusTrap.unmount();
900
+
901
+ // Setup initial state.
902
+ await initialState.call(this, entry);
903
+
904
+ // Dispatch custom switch event.
905
+ entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "switchMode", {
906
+ detail: this,
907
+ bubbles: true
908
+ }));
909
+
910
+ // Return the entry.
911
+ return entry;
912
+ }
913
+ async function toModal(entry) {
914
+ // Get the drawer configuration.
915
+
916
+ // Add the modal class.
917
+ entry.el.classList.add(entry.getSetting("classModal"));
918
+
919
+ // Set aria-modal attribute to true.
920
+ entry.dialog.setAttribute("aria-modal", "true");
921
+
922
+ // If there isn't a stored state but also has the opened state class...
923
+ if (!this.store.get(entry.id) && entry.el.classList.contains(entry.getSetting("stateOpened"))) {
924
+ // Save the opened state in local store.
925
+ this.store.set(entry.id, "opened");
926
+ }
927
+
928
+ // Modal drawer defaults to closed state.
929
+ await close$2.call(this, entry, false, false);
930
+
931
+ // Dispatch custom switch event.
932
+ entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "switchMode", {
933
+ detail: this,
934
+ bubbles: true
935
+ }));
936
+
937
+ // Return the entry.
938
+ return entry;
939
+ }
940
+
941
+ async function register$2(el, dialog) {
942
+ // Deregister entry incase it has already been registered.
943
+ await deregister$2.call(this, el, false);
944
+
945
+ // Save root this for use inside methods API.
946
+ const root = this;
947
+
948
+ // Create an instance of the Breakpoint class.
949
+ const breakpoint = new Breakpoint();
950
+
951
+ // Setup methods API.
952
+ const methods = {
953
+ open(transition, focus) {
954
+ return open$2.call(root, this, transition, focus);
955
+ },
956
+ close(transition, focus) {
957
+ return close$2.call(root, this, transition, focus);
958
+ },
959
+ toggle(transition, focus) {
960
+ return toggle.call(root, this, transition, focus);
961
+ },
962
+ deregister() {
963
+ return deregister$2.call(root, this);
964
+ },
965
+ mountBreakpoint() {
966
+ const value = this.breakpoint;
967
+ const handler = this.handleBreakpoint.bind(this);
968
+ breakpoint.mount(value, handler);
969
+ return this;
970
+ },
971
+ unmountBreakpoint() {
972
+ breakpoint.unmount();
973
+ return this;
974
+ },
975
+ handleBreakpoint(event) {
976
+ this.mode = event.matches ? "inline" : "modal";
977
+ return this;
978
+ },
979
+ getSetting(key) {
980
+ return key in this.settings ? this.settings[key] : root.settings[key];
981
+ }
982
+ };
983
+
984
+ // Setup the drawer object.
985
+ const entry = _extends({
986
+ id: el.id,
987
+ el: el,
988
+ dialog: dialog,
989
+ trigger: null,
990
+ settings: getConfig$1(el, this.settings.dataConfig),
991
+ get breakpoint() {
992
+ return getBreakpoint.call(root, el);
993
+ },
994
+ get state() {
995
+ return __state;
996
+ },
997
+ set state(value) {
998
+ __state = value;
999
+ // Save 'opened' and 'closed' states to store if mode is inline.
1000
+ if (value === "opened" || value === "closed") {
1001
+ if (this.mode === "inline") root.store.set(this.id, this.state);
1002
+ }
1003
+ },
1004
+ get mode() {
1005
+ return __mode;
1006
+ },
1007
+ set mode(value) {
1008
+ __mode = value;
1009
+ switchMode.call(root, this);
1010
+ }
1011
+ }, methods);
1012
+
1013
+ // Create the state var with the initial state.
1014
+ let __state = el.classList.contains(entry.getSetting("stateOpened")) ? "opened" : "closed";
1015
+
1016
+ // Create the mode var with the initial mode.
1017
+ let __mode = el.classList.contains(entry.getSetting("classModal")) ? "modal" : "inline";
1018
+
1019
+ // Setup mode specific attributes.
1020
+ if (entry.mode === "modal") {
1021
+ // Set aria-modal attribute to true.
1022
+ entry.dialog.setAttribute("aria-modal", "true");
1023
+ } else {
1024
+ // Remove the aria-modal attribute.
1025
+ entry.dialog.removeAttribute("aria-modal");
1026
+ }
1027
+
1028
+ // Set tabindex="-1" so dialog is focusable via JS or click.
1029
+ if (entry.getSetting("setTabindex")) {
1030
+ entry.dialog.setAttribute("tabindex", "-1");
1031
+ }
1032
+
1033
+ // Add entry to collection.
1034
+ this.collection.push(entry);
1035
+
1036
+ // If the entry has a breakpoint...
1037
+ if (entry.breakpoint) {
1038
+ // Mount media query breakpoint functionality.
1039
+ entry.mountBreakpoint();
1040
+ } else {
1041
+ // Else, Setup initial state.
1042
+ await initialState.call(this, entry);
1043
+ }
1044
+
1045
+ // Return the registered entry.
1046
+ return entry;
1047
+ }
1048
+
1049
+ var _handleClick$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
1050
+ var _handleKeydown$2 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
1051
+ class Drawer extends Collection {
1052
+ constructor(options) {
1053
+ super();
1054
+ Object.defineProperty(this, _handleClick$1, {
1055
+ writable: true,
1056
+ value: void 0
1057
+ });
1058
+ Object.defineProperty(this, _handleKeydown$2, {
1059
+ writable: true,
1060
+ value: void 0
1061
+ });
1062
+ this.defaults = defaults$2;
1063
+ this.settings = _extends({}, this.defaults, options);
1064
+ this.focusTrap = new FocusTrap();
1065
+
1066
+ // Setup local store for inline drawer state management.
1067
+ this.store = localStore(this.settings.storeKey, this.settings.store);
1068
+ _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1] = handleClick$2.bind(this);
1069
+ _classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2] = handleKeydown$2.bind(this);
1070
+ if (this.settings.autoInit) this.init();
1071
+ }
1072
+ get activeModal() {
1073
+ return this.collection.find(entry => {
1074
+ return entry.state === "opened" && entry.mode === "modal";
1075
+ });
1076
+ }
1077
+ async init(options = null) {
1078
+ // Update settings with passed options.
1079
+ if (options) this.settings = _extends({}, this.settings, options);
1080
+
1081
+ // Get all the modals.
1082
+ const drawers = document.querySelectorAll(this.settings.selectorDrawer);
1083
+
1084
+ // Register the collections array with modal instances.
1085
+ await this.registerCollection(drawers);
1086
+
1087
+ // If eventListeners are enabled, init event listeners.
1088
+ if (this.settings.eventListeners) {
1089
+ this.initEventListeners();
1090
+ }
1091
+ return this;
1092
+ }
1093
+ async destroy() {
1094
+ // Remove all entries from the collection.
1095
+ await this.deregisterCollection();
1096
+
1097
+ // If eventListeners are enabled, init event listeners.
1098
+ if (this.settings.eventListeners) {
1099
+ this.destroyEventListeners();
1100
+ }
1101
+ return this;
1102
+ }
1103
+ initEventListeners() {
1104
+ document.addEventListener("click", _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
1105
+ document.addEventListener("keydown", _classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2], false);
1106
+ }
1107
+ destroyEventListeners() {
1108
+ document.removeEventListener("click", _classPrivateFieldLooseBase(this, _handleClick$1)[_handleClick$1], false);
1109
+ document.removeEventListener("keydown", _classPrivateFieldLooseBase(this, _handleKeydown$2)[_handleKeydown$2], false);
1110
+ }
1111
+ register(query) {
1112
+ const els = getDrawerElements.call(this, query);
1113
+ if (els.error) return Promise.reject(els.error);
1114
+ return register$2.call(this, els.drawer, els.dialog);
1115
+ }
1116
+ deregister(query) {
1117
+ const entry = this.get(getDrawerID.call(this, query));
1118
+ return deregister$2.call(this, entry);
1119
+ }
1120
+ open(id, transition, focus) {
1121
+ return open$2.call(this, id, transition, focus);
1122
+ }
1123
+ close(id, transition, focus) {
1124
+ return close$2.call(this, id, transition, focus);
1125
+ }
1126
+ toggle(id, transition, focus) {
1127
+ return toggle.call(this, id, transition, focus);
1128
+ }
1129
+ }
1130
+
1131
+ var defaults$1 = {
1132
+ autoInit: false,
1133
+ // Data attributes
1134
+ dataOpen: "modal-open",
1135
+ dataClose: "modal-close",
1136
+ dataReplace: "modal-replace",
1137
+ dataConfig: "modal-config",
1138
+ // Selectors
1139
+ selectorModal: ".modal",
1140
+ selectorDialog: ".modal__dialog",
1141
+ selectorRequired: "[role=\"alertdialog\"]",
1142
+ selectorFocus: "[data-focus]",
1143
+ selectorInert: null,
1144
+ selectorOverflow: "body",
1145
+ // State classes
1146
+ stateOpened: "is-opened",
1147
+ stateOpening: "is-opening",
1148
+ stateClosing: "is-closing",
1149
+ stateClosed: "is-closed",
1150
+ // Feature settings
1151
+ customEventPrefix: "modal:",
1152
+ eventListeners: true,
1153
+ teleport: null,
1154
+ teleportMethod: "append",
1155
+ setTabindex: true,
1156
+ transition: true
1157
+ };
1158
+
1159
+ function getModal(query) {
1160
+ // Get the entry from collection.
1161
+ const entry = typeof query === "string" ? this.get(query) : this.get(query.id);
1162
+
1163
+ // Return entry if it was resolved, otherwise throw error.
1164
+ if (entry) {
1165
+ return entry;
1166
+ } else {
1167
+ throw new Error(`Modal not found in collection with id of "${query.id || query}".`);
1168
+ }
1169
+ }
1170
+
1171
+ function getModalID(obj) {
1172
+ // If it's a string, return the string.
1173
+ if (typeof obj === "string") {
1174
+ return obj;
1175
+ }
1176
+
1177
+ // If it's an HTML element.
1178
+ else if (typeof obj.hasAttribute === "function") {
1179
+ // If it's a modal open trigger, return data value.
1180
+ if (obj.hasAttribute(`data-${this.settings.dataOpen}`)) {
1181
+ return obj.getAttribute(`data-${this.settings.dataOpen}`);
1182
+ }
1183
+
1184
+ // If it's a modal close trigger, return data value or false.
1185
+ else if (obj.hasAttribute(`data-${this.settings.dataClose}`)) {
1186
+ return obj.getAttribute(`data-${this.settings.dataClose}`) || false;
1187
+ }
1188
+
1189
+ // If it's a modal replace trigger, return data value.
1190
+ else if (obj.hasAttribute(`data-${this.settings.dataReplace}`)) {
1191
+ return obj.getAttribute(`data-${this.settings.dataReplace}`);
1192
+ }
1193
+
1194
+ // If it's a modal element, return the id.
1195
+ else if (obj.closest(this.settings.selectorModal)) {
1196
+ obj = obj.closest(this.settings.selectorModal);
1197
+ return obj.id || false;
1198
+ }
1199
+
1200
+ // Return false if no id was found.
1201
+ else return false;
1202
+ }
1203
+
1204
+ // If it has an id property, return its value.
1205
+ else if (obj.id) {
1206
+ return obj.id;
1207
+ }
1208
+
1209
+ // Return false if no id was found.
1210
+ else return false;
1211
+ }
1212
+
1213
+ function getModalElements(query) {
1214
+ const id = getModalID.call(this, query);
1215
+ if (id) {
1216
+ const modal = document.querySelector(`#${id}`);
1217
+ const dialog = modal ? modal.querySelector(this.settings.selectorDialog) : null;
1218
+ if (!modal && !dialog) {
1219
+ return {
1220
+ error: new Error(`No modal elements found using the ID: "${id}".`)
1221
+ };
1222
+ } else if (!dialog) {
1223
+ return {
1224
+ error: new Error("Modal is missing dialog element.")
1225
+ };
1226
+ } else {
1227
+ return {
1228
+ modal,
1229
+ dialog
1230
+ };
1231
+ }
1232
+ } else {
1233
+ return {
1234
+ error: new Error("Could not resolve the modal ID.")
1235
+ };
1236
+ }
1237
+ }
1238
+
1239
+ function updateFocusState() {
1240
+ // Check if there's an active modal
1241
+ if (this.active) {
1242
+ // Mount the focus trap on the active modal.
1243
+ this.focusTrap.mount(this.active.dialog, this.settings.selectorFocus);
1244
+ } else {
1245
+ // Set focus to root trigger and unmount the focus trap.
1246
+ if (this.trigger) {
1247
+ this.trigger.focus();
1248
+ this.trigger = null;
1249
+ }
1250
+ this.focusTrap.unmount();
1251
+ }
1252
+ }
1253
+
1254
+ async function handleClick$1(event) {
1255
+ // If an open or replace button was clicked, open or replace the modal.
1256
+ let trigger = event.target.closest(`[data-${this.settings.dataOpen}], [data-${this.settings.dataReplace}]`);
1257
+ if (trigger) {
1258
+ event.preventDefault();
1259
+ // Save the trigger if it's not coming from inside a modal.
1260
+ const fromModal = event.target.closest(this.settings.selectorModal);
1261
+ if (!fromModal) this.trigger = trigger;
1262
+ // Get the modal.
1263
+ const modal = this.get(getModalID.call(this, trigger));
1264
+ // Depending on the button type, either open or replace the modal.
1265
+ return trigger.matches(`[data-${this.settings.dataOpen}]`) ? modal.open() : modal.replace();
1266
+ }
1267
+
1268
+ // If a close button was clicked, close the modal.
1269
+ trigger = event.target.closest(`[data-${this.settings.dataClose}]`);
1270
+ if (trigger) {
1271
+ event.preventDefault();
1272
+ // Get the value of the data attribute.
1273
+ const value = trigger.getAttribute(`data-${this.settings.dataClose}`);
1274
+ // Close all if * wildcard is passed, otherwise close a single modal.
1275
+ return value === "*" ? this.closeAll() : this.close(value);
1276
+ }
1277
+
1278
+ // If the modal screen was clicked, close the modal.
1279
+ if (event.target.matches(this.settings.selectorModal) && !event.target.querySelector(this.settings.selectorRequired)) {
1280
+ return this.close(getModalID.call(this, event.target));
1281
+ }
1282
+ }
1283
+ function handleKeydown$1(event) {
1284
+ // If escape key was pressed.
1285
+ if (event.key === "Escape") {
1286
+ // If a modal is opened and not required, close the modal.
1287
+ if (this.active && !this.active.dialog.matches(this.settings.selectorRequired)) {
1288
+ return this.close();
1289
+ }
1290
+ }
1291
+ }
1292
+
1293
+ async function deregister$1(obj, close = true) {
1294
+ // Return collection if nothing was passed.
1295
+ if (!obj) return this.collection;
1296
+
1297
+ // Check if entry has been registered in the collection.
1298
+ const index = this.collection.findIndex(entry => {
1299
+ return entry.id === obj.id;
1300
+ });
1301
+ if (index >= 0) {
1302
+ // Get the collection entry.
1303
+ const entry = this.collection[index];
1304
+
1305
+ // If entry is in the opened state, close it.
1306
+ if (close && entry.state === "opened") {
1307
+ await entry.close(false);
1308
+ } else {
1309
+ // Remove modal from stack.
1310
+ this.stack.remove(entry);
1311
+ }
1312
+
1313
+ // Return teleported modal if a reference has been set.
1314
+ if (entry.getSetting("teleport")) {
1315
+ entry.teleportReturn();
1316
+ }
1317
+
1318
+ // Delete properties from collection entry.
1319
+ Object.getOwnPropertyNames(entry).forEach(prop => {
1320
+ delete entry[prop];
1321
+ });
1322
+
1323
+ // Remove entry from collection.
1324
+ this.collection.splice(index, 1);
1325
+ }
1326
+
1327
+ // Return the modified collection.
1328
+ return this.collection;
1329
+ }
1330
+
1331
+ async function open$1(query, transition, focus = true) {
1332
+ // Get the modal from collection.
1333
+ const modal = getModal.call(this, query);
1334
+
1335
+ // Get the modal configuration.
1336
+ const config = _extends({}, this.settings, modal.settings);
1337
+
1338
+ // Add transition parameter to configuration.
1339
+ if (transition !== undefined) config.transition = transition;
1340
+
1341
+ // Maybe add modal to top of stack.
1342
+ this.stack.moveToTop(modal);
1343
+
1344
+ // If modal is closed.
1345
+ if (modal.state === "closed") {
1346
+ // Update modal state.
1347
+ modal.state = "opening";
1348
+
1349
+ // Add modal to stack.
1350
+ this.stack.add(modal);
1351
+
1352
+ // Run the open transition.
1353
+ await openTransition(modal.el, config);
1354
+
1355
+ // Update modal state.
1356
+ modal.state = "opened";
1357
+ }
1358
+
1359
+ // Update focus if the focus param is true.
1360
+ if (focus) {
1361
+ updateFocusState.call(this);
1362
+ }
1363
+
1364
+ // Dispatch custom opened event.
1365
+ modal.el.dispatchEvent(new CustomEvent(config.customEventPrefix + "opened", {
1366
+ detail: this,
1367
+ bubbles: true
1368
+ }));
1369
+
1370
+ // Return the modal.
1371
+ return modal;
1372
+ }
1373
+
1374
+ async function close$1(query, transition, focus = true) {
1375
+ // Get the modal from collection, or top modal in stack if no query is provided.
1376
+ const modal = query ? getModal.call(this, query) : this.active;
1377
+
1378
+ // If a modal exists and its state is opened.
1379
+ if (modal && modal.state === "opened") {
1380
+ // Update modal state.
1381
+ modal.state = "closing";
1382
+
1383
+ // Get the modal configuration.
1384
+ const config = _extends({}, this.settings, modal.settings);
1385
+
1386
+ // Add transition parameter to configuration.
1387
+ if (transition !== undefined) config.transition = transition;
1388
+
1389
+ // Remove focus from active element.
1390
+ document.activeElement.blur();
1391
+
1392
+ // Run the close transition.
1393
+ await closeTransition(modal.el, config);
1394
+
1395
+ // Remove modal from stack.
1396
+ this.stack.remove(modal);
1397
+
1398
+ // Update focus if the focus param is true.
1399
+ if (focus) {
1400
+ updateFocusState.call(this);
1401
+ }
1402
+
1403
+ // Update modal state.
1404
+ modal.state = "closed";
1405
+
1406
+ // Dispatch custom closed event.
1407
+ modal.el.dispatchEvent(new CustomEvent(config.customEventPrefix + "closed", {
1408
+ detail: this,
1409
+ bubbles: true
1410
+ }));
1411
+ }
1412
+
1413
+ // Return the modal.
1414
+ return modal;
1415
+ }
1416
+
1417
+ async function closeAll$1(exclude, transition) {
1418
+ const result = [];
1419
+ await Promise.all(this.stack.value.map(async modal => {
1420
+ if (exclude && exclude === modal.id) {
1421
+ Promise.resolve();
1422
+ } else {
1423
+ result.push(await close$1.call(this, modal, transition, false));
1424
+ }
1425
+ modal.trigger = null;
1426
+ }));
1427
+ return result;
1428
+ }
1429
+
1430
+ async function replace(query, transition, focus = true) {
1431
+ // Get the modal from collection.
1432
+ const modal = getModal.call(this, query);
1433
+
1434
+ // Setup results for return.
1435
+ let resultOpened, resultClosed;
1436
+ if (modal.state === "opened") {
1437
+ // If modal is open, close all modals except for replacement.
1438
+ resultOpened = modal;
1439
+ resultClosed = await closeAll$1.call(this, modal.id, transition);
1440
+ } else {
1441
+ // If modal is closed, close all and open replacement at the same time.
1442
+ resultOpened = open$1.call(this, modal, transition, false);
1443
+ resultClosed = closeAll$1.call(this, false, transition);
1444
+ await Promise.all([resultOpened, resultClosed]);
1445
+ }
1446
+
1447
+ // Update focus if the focus param is true.
1448
+ if (focus) {
1449
+ updateFocusState.call(this);
1450
+ }
1451
+
1452
+ // Return the modals there were opened and closed.
1453
+ return {
1454
+ opened: resultOpened,
1455
+ closed: resultClosed
1456
+ };
1457
+ }
1458
+
1459
+ async function register$1(el, dialog) {
1460
+ // Deregister entry incase it has already been registered.
1461
+ await deregister$1.call(this, el, false);
1462
+
1463
+ // Save root this for use inside methods API.
1464
+ const root = this;
1465
+
1466
+ // Setup methods API.
1467
+ const methods = {
1468
+ open(transition, focus) {
1469
+ return open$1.call(root, this, transition, focus);
1470
+ },
1471
+ close(transition, focus) {
1472
+ return close$1.call(root, this, transition, focus);
1473
+ },
1474
+ replace(transition, focus) {
1475
+ return replace.call(root, this, transition, focus);
1476
+ },
1477
+ deregister() {
1478
+ return deregister$1.call(root, this);
1479
+ },
1480
+ teleport(ref = this.getSetting("teleport"), method = this.getSetting("teleportMethod")) {
1481
+ if (!this.returnRef) {
1482
+ this.returnRef = teleport(this.el, ref, method);
1483
+ return this.el;
1484
+ } else {
1485
+ console.error("Element has already been teleported:", this.el);
1486
+ return false;
1487
+ }
1488
+ },
1489
+ teleportReturn() {
1490
+ if (this.returnRef) {
1491
+ this.returnRef = teleport(this.el, this.returnRef);
1492
+ return this.el;
1493
+ } else {
1494
+ console.error("No return reference found:", this.el);
1495
+ return false;
1496
+ }
1497
+ },
1498
+ getSetting(key) {
1499
+ return key in this.settings ? this.settings[key] : root.settings[key];
1500
+ }
1501
+ };
1502
+
1503
+ // Setup the modal object.
1504
+ const entry = _extends({
1505
+ id: el.id,
1506
+ state: "closed",
1507
+ el: el,
1508
+ dialog: dialog,
1509
+ returnRef: null,
1510
+ settings: getConfig$1(el, this.settings.dataConfig)
1511
+ }, methods);
1512
+
1513
+ // Set aria-modal attribute to true.
1514
+ entry.dialog.setAttribute("aria-modal", "true");
1515
+
1516
+ // If a role attribute is not set, set it to "dialog" as the default.
1517
+ if (!entry.dialog.hasAttribute("role")) {
1518
+ entry.dialog.setAttribute("role", "dialog");
1519
+ }
1520
+
1521
+ // Set tabindex="-1" so dialog is focusable via JS or click.
1522
+ if (entry.getSetting("setTabindex")) {
1523
+ entry.dialog.setAttribute("tabindex", "-1");
1524
+ }
1525
+
1526
+ // Teleport modal if a reference has been set.
1527
+ if (entry.getSetting("teleport")) {
1528
+ entry.teleport();
1529
+ }
1530
+
1531
+ // Add entry to collection.
1532
+ this.collection.push(entry);
1533
+
1534
+ // Setup initial state.
1535
+ if (entry.el.classList.contains(this.settings.stateOpened)) {
1536
+ // Open entry with transitions disabled.
1537
+ await entry.open(false);
1538
+ } else {
1539
+ // Remove transition state classes.
1540
+ entry.el.classList.remove(this.settings.stateOpening);
1541
+ entry.el.classList.remove(this.settings.stateClosing);
1542
+ // Add closed state class.
1543
+ entry.el.classList.add(this.settings.stateClosed);
1544
+ }
1545
+
1546
+ // Return the registered entry.
1547
+ return entry;
1548
+ }
1549
+
1550
+ function stack(settings) {
1551
+ const stackArray = [];
1552
+ return {
1553
+ get value() {
1554
+ return [...stackArray];
1555
+ },
1556
+ get top() {
1557
+ return stackArray[stackArray.length - 1];
1558
+ },
1559
+ updateIndex() {
1560
+ stackArray.forEach((entry, index) => {
1561
+ entry.el.style.zIndex = null;
1562
+ const value = getComputedStyle(entry.el)["z-index"];
1563
+ entry.el.style.zIndex = parseInt(value) + index + 1;
1564
+ });
1565
+ },
1566
+ updateGlobalState() {
1567
+ updateGlobalState(this.top, settings);
1568
+ this.updateIndex();
1569
+ },
1570
+ add(entry) {
1571
+ // Apply z-index styles based on stack length.
1572
+ entry.el.style.zIndex = null;
1573
+ const value = getComputedStyle(entry.el)["z-index"];
1574
+ entry.el.style.zIndex = parseInt(value) + stackArray.length + 1;
1575
+
1576
+ // Move back to end of stack.
1577
+ stackArray.push(entry);
1578
+
1579
+ // Update the global state.
1580
+ this.updateGlobalState();
1581
+ },
1582
+ remove(entry) {
1583
+ // Get the index of the entry.
1584
+ const index = stackArray.findIndex(item => {
1585
+ return item.id === entry.id;
1586
+ });
1587
+
1588
+ // If entry is in stack...
1589
+ if (index >= 0) {
1590
+ // Remove z-index styles.
1591
+ entry.el.style.zIndex = null;
1592
+
1593
+ // Remove entry from stack array.
1594
+ stackArray.splice(index, 1);
1595
+
1596
+ // Update the global state.
1597
+ this.updateGlobalState();
1598
+ }
1599
+ },
1600
+ moveToTop(entry) {
1601
+ // Get the index of the entry.
1602
+ const index = stackArray.findIndex(item => {
1603
+ return item.id === entry.id;
1604
+ });
1605
+
1606
+ // If entry is in stack...
1607
+ if (index >= 0) {
1608
+ // Remove entry from stack array.
1609
+ stackArray.splice(index, 1);
1610
+
1611
+ // Add entry back to top of stack.
1612
+ this.add(entry);
1613
+ }
1614
+ }
1615
+ };
1616
+ }
1617
+
1618
+ var _handleClick = /*#__PURE__*/_classPrivateFieldLooseKey("handleClick");
1619
+ var _handleKeydown$1 = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
1620
+ class Modal extends Collection {
1621
+ constructor(options) {
1622
+ super();
1623
+ Object.defineProperty(this, _handleClick, {
1624
+ writable: true,
1625
+ value: void 0
1626
+ });
1627
+ Object.defineProperty(this, _handleKeydown$1, {
1628
+ writable: true,
1629
+ value: void 0
1630
+ });
1631
+ this.defaults = defaults$1;
1632
+ this.settings = _extends({}, this.defaults, options);
1633
+ this.trigger = null;
1634
+ this.focusTrap = new FocusTrap();
1635
+
1636
+ // Setup stack module.
1637
+ this.stack = stack(this.settings);
1638
+ _classPrivateFieldLooseBase(this, _handleClick)[_handleClick] = handleClick$1.bind(this);
1639
+ _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1] = handleKeydown$1.bind(this);
1640
+ if (this.settings.autoInit) this.init();
1641
+ }
1642
+ get active() {
1643
+ return this.stack.top;
1644
+ }
1645
+ async init(options) {
1646
+ // Update settings with passed options.
1647
+ if (options) this.settings = _extends({}, this.settings, options);
1648
+
1649
+ // Get all the modals.
1650
+ const modals = document.querySelectorAll(this.settings.selectorModal);
1651
+
1652
+ // Register the collections array with modal instances.
1653
+ await this.registerCollection(modals);
1654
+
1655
+ // If eventListeners are enabled, init event listeners.
1656
+ if (this.settings.eventListeners) {
1657
+ this.initEventListeners();
1658
+ }
1659
+ return this;
1660
+ }
1661
+ async destroy() {
1662
+ // Clear stored trigger.
1663
+ this.trigger = null;
1664
+
1665
+ // Remove all entries from the collection.
1666
+ await this.deregisterCollection();
1667
+
1668
+ // If eventListeners are enabled, destroy event listeners.
1669
+ if (this.settings.eventListeners) {
1670
+ this.destroyEventListeners();
1671
+ }
1672
+ return this;
1673
+ }
1674
+ initEventListeners() {
1675
+ document.addEventListener("click", _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
1676
+ document.addEventListener("keydown", _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1], false);
1677
+ }
1678
+ destroyEventListeners() {
1679
+ document.removeEventListener("click", _classPrivateFieldLooseBase(this, _handleClick)[_handleClick], false);
1680
+ document.removeEventListener("keydown", _classPrivateFieldLooseBase(this, _handleKeydown$1)[_handleKeydown$1], false);
1681
+ }
1682
+ register(query) {
1683
+ const els = getModalElements.call(this, query);
1684
+ if (els.error) return Promise.reject(els.error);
1685
+ return register$1.call(this, els.modal, els.dialog);
1686
+ }
1687
+ deregister(query) {
1688
+ const modal = this.get(getModalID.call(this, query));
1689
+ return deregister$1.call(this, modal);
1690
+ }
1691
+ open(id, transition, focus) {
1692
+ return open$1.call(this, id, transition, focus);
1693
+ }
1694
+ close(id, transition, focus) {
1695
+ return close$1.call(this, id, transition, focus);
1696
+ }
1697
+ replace(id, transition, focus) {
1698
+ return replace.call(this, id, transition, focus);
1699
+ }
1700
+ async closeAll(exclude = false, transition, focus = true) {
1701
+ const result = await closeAll$1.call(this, exclude, transition);
1702
+ // Update focus if the focus param is true.
1703
+ if (focus) {
1704
+ updateFocusState.call(this);
1705
+ }
1706
+ return result;
1707
+ }
1708
+ }
1709
+
1710
+ var defaults = {
1711
+ autoInit: false,
1712
+ // Selectors
1713
+ selectorPopover: ".popover",
1714
+ selectorArrow: ".popover__arrow",
1715
+ // State classes
1716
+ stateActive: "is-active",
1717
+ // Feature settings
1718
+ eventListeners: true,
1719
+ eventType: "click",
1720
+ placement: "bottom"
1721
+ };
1722
+
1723
+ function getConfig(el, settings) {
1724
+ // Get the computed styles of the element.
1725
+ const styles = getComputedStyle(el);
1726
+
1727
+ // Setup the config obj with default values.
1728
+ const config = {
1729
+ "placement": settings.placement,
1730
+ "event": settings.eventType,
1731
+ "offset": 0,
1732
+ "overflow-padding": 0,
1733
+ "flip-padding": 0,
1734
+ "arrow-element": settings.selectorArrow,
1735
+ "arrow-padding": 0
1736
+ };
1737
+
1738
+ // Loop through config obj.
1739
+ for (const prop in config) {
1740
+ // Get the CSS variable property values.
1741
+ const prefix = P();
1742
+ const value = styles.getPropertyValue(`--${prefix}popover-${prop}`).trim();
1743
+
1744
+ // If a value was found, replace the default in config obj.
1745
+ if (value) {
1746
+ config[prop] = value;
1747
+ }
1748
+ }
1749
+
1750
+ // Return the config obj.
1751
+ return config;
1752
+ }
1753
+
1754
+ function getPadding(value) {
1755
+ let padding;
1756
+
1757
+ // Split the value by spaces if it's a string.
1758
+ const array = typeof value === "string" ? value.trim().split(" ") : [value];
1759
+
1760
+ // Convert individual values to integers.
1761
+ array.forEach(function (item, index) {
1762
+ array[index] = parseInt(item, 10);
1763
+ });
1764
+
1765
+ // Build the padding object based on the number of values passed.
1766
+ switch (array.length) {
1767
+ case 1:
1768
+ padding = array[0];
1769
+ break;
1770
+ case 2:
1771
+ padding = {
1772
+ top: array[0],
1773
+ right: array[1],
1774
+ bottom: array[0],
1775
+ left: array[1]
1776
+ };
1777
+ break;
1778
+ case 3:
1779
+ padding = {
1780
+ top: array[0],
1781
+ right: array[1],
1782
+ bottom: array[2],
1783
+ left: array[1]
1784
+ };
1785
+ break;
1786
+ case 4:
1787
+ padding = {
1788
+ top: array[0],
1789
+ right: array[1],
1790
+ bottom: array[2],
1791
+ left: array[3]
1792
+ };
1793
+ break;
1794
+ default:
1795
+ padding = false;
1796
+ break;
1797
+ }
1798
+
1799
+ // Return the padding object.
1800
+ return padding;
1801
+ }
1802
+
1803
+ function getModifiers(options) {
1804
+ return [{
1805
+ name: "offset",
1806
+ options: {
1807
+ offset: [0, parseInt(options["offset"], 10)]
1808
+ }
1809
+ }, {
1810
+ name: "preventOverflow",
1811
+ options: {
1812
+ padding: getPadding(options["overflow-padding"])
1813
+ }
1814
+ }, {
1815
+ name: "flip",
1816
+ options: {
1817
+ padding: getPadding(options["flip-padding"])
1818
+ }
1819
+ }, {
1820
+ name: "arrow",
1821
+ options: {
1822
+ element: options["arrow-element"],
1823
+ padding: getPadding(options["arrow-padding"])
1824
+ }
1825
+ }];
1826
+ }
1827
+
1828
+ function getPopover(query) {
1829
+ // Get the entry from collection.
1830
+ const entry = typeof query === "string" ? this.get(query) : this.get(query.id);
1831
+
1832
+ // Return entry if it was resolved, otherwise throw error.
1833
+ if (entry) {
1834
+ return entry;
1835
+ } else {
1836
+ throw new Error(`Popover not found in collection with id of "${query}".`);
1837
+ }
1838
+ }
1839
+
1840
+ function getPopoverID(obj) {
1841
+ // If it's a string, return the string.
1842
+ if (typeof obj === "string") {
1843
+ return obj;
1844
+ }
1845
+
1846
+ // If it's an HTML element.
1847
+ else if (typeof obj.hasAttribute === "function") {
1848
+ // If it's a popover element, return the id.
1849
+ if (obj.closest(this.settings.selectorPopover)) {
1850
+ obj = obj.closest(this.settings.selectorPopover);
1851
+ return obj.id;
1852
+ }
1853
+
1854
+ // If it's a popover trigger, return value of aria-controls.
1855
+ else if (obj.hasAttribute("aria-controls")) {
1856
+ return obj.getAttribute("aria-controls");
1857
+ }
1858
+
1859
+ // If it's a popover tooltip trigger, return the value of aria-describedby.
1860
+ else if (obj.hasAttribute("aria-describedby")) {
1861
+ return obj.getAttribute("aria-describedby");
1862
+ }
1863
+
1864
+ // Return false if no id was found.
1865
+ else return false;
1866
+ }
1867
+
1868
+ // If it has an id property, return its value.
1869
+ else if (obj.id) {
1870
+ return obj.id;
1871
+ }
1872
+
1873
+ // Return false if no id was found.
1874
+ else return false;
1875
+ }
1876
+
1877
+ function getPopoverElements(query) {
1878
+ const id = getPopoverID.call(this, query);
1879
+ if (id) {
1880
+ const popover = document.querySelector(`#${id}`);
1881
+ const trigger = document.querySelector(`[aria-controls="${id}"]`) || document.querySelector(`[aria-describedby="${id}"]`);
1882
+ if (!trigger && !popover) {
1883
+ return {
1884
+ error: new Error(`No popover elements found using the ID: "${id}".`)
1885
+ };
1886
+ } else if (!trigger) {
1887
+ return {
1888
+ error: new Error("No popover trigger associated with the provided popover.")
1889
+ };
1890
+ } else if (!popover) {
1891
+ return {
1892
+ error: new Error("No popover associated with the provided popover trigger.")
1893
+ };
1894
+ } else {
1895
+ return {
1896
+ popover,
1897
+ trigger
1898
+ };
1899
+ }
1900
+ } else {
1901
+ return {
1902
+ error: new Error("Could not resolve the popover ID.")
1903
+ };
1904
+ }
1905
+ }
1906
+
1907
+ async function close(query) {
1908
+ // Get the popover from collection.
1909
+ const popover = query ? getPopover.call(this, query) : await closeAll.call(this);
1910
+
1911
+ // If a modal exists and its state is opened.
1912
+ if (popover && popover.state === "opened") {
1913
+ // Update state class.
1914
+ popover.el.classList.remove(this.settings.stateActive);
1915
+
1916
+ // Update accessibility attribute(s).
1917
+ if (popover.trigger.hasAttribute("aria-controls")) {
1918
+ popover.trigger.setAttribute("aria-expanded", "false");
1919
+ }
1920
+
1921
+ // Disable popper event listeners.
1922
+ popover.popper.setOptions({
1923
+ modifiers: [{
1924
+ name: "eventListeners",
1925
+ enabled: false
1926
+ }]
1927
+ });
1928
+
1929
+ // Update popover state.
1930
+ popover.state = "closed";
1931
+
1932
+ // Clear root trigger if popover trigger matches.
1933
+ if (popover.trigger === this.trigger) {
1934
+ this.trigger = null;
1935
+ }
1936
+ }
1937
+
1938
+ // Return the popover.
1939
+ return popover;
1940
+ }
1941
+ async function closeAll() {
1942
+ const result = [];
1943
+ await Promise.all(this.collection.map(async popover => {
1944
+ if (popover.state === "opened") {
1945
+ result.push(await close.call(this, popover));
1946
+ }
1947
+ }));
1948
+ return result;
1949
+ }
1950
+ function closeCheck(popover) {
1951
+ // Only run closeCheck if provided popover is currently open.
1952
+ if (popover.state != "opened") return;
1953
+
1954
+ // Needed to correctly check which element is currently being focused.
1955
+ setTimeout(() => {
1956
+ // Check if trigger or element are being hovered.
1957
+ const isHovered = popover.el.closest(":hover") === popover.el || popover.trigger.closest(":hover") === popover.trigger;
1958
+
1959
+ // Check if trigger or element are being focused.
1960
+ const isFocused = document.activeElement.closest(`#${popover.id}, [aria-controls="${popover.id}"], [aria-describedby="${popover.id}"]`);
1961
+
1962
+ // Close if the trigger and element are not currently hovered or focused.
1963
+ if (!isHovered && !isFocused) {
1964
+ popover.close();
1965
+ }
1966
+
1967
+ // Return the popover.
1968
+ return popover;
1969
+ }, 1);
1970
+ }
1971
+
1972
+ function handleClick(popover) {
1973
+ if (popover.state === "opened") {
1974
+ popover.close();
1975
+ } else {
1976
+ this.trigger = popover.trigger;
1977
+ popover.open();
1978
+ handleDocumentClick.call(this, popover);
1979
+ }
1980
+ }
1981
+ function handleKeydown(event) {
1982
+ switch (event.key) {
1983
+ case "Escape":
1984
+ if (this.trigger) {
1985
+ this.trigger.focus();
1986
+ }
1987
+ closeAll.call(this);
1988
+ return;
1989
+ case "Tab":
1990
+ this.collection.forEach(popover => {
1991
+ closeCheck.call(this, popover);
1992
+ });
1993
+ return;
1994
+ default:
1995
+ return;
1996
+ }
1997
+ }
1998
+ function handleDocumentClick(popover) {
1999
+ const root = this;
2000
+ document.addEventListener("click", function _f(event) {
2001
+ // Check if a popover or its trigger was clicked.
2002
+ const wasClicked = event.target.closest(`#${popover.id}, [aria-controls="${popover.id}"], [aria-describedby="${popover.id}"]`);
2003
+
2004
+ // If popover or popover trigger was clicked...
2005
+ if (wasClicked) {
2006
+ // If popover element exists and is not active...
2007
+ if (popover.el && !popover.el.classList.contains(root.settings.stateActive)) {
2008
+ this.removeEventListener("click", _f);
2009
+ }
2010
+ } else {
2011
+ // If popover element exists and is active...
2012
+ if (popover.el && popover.el.classList.contains(root.settings.stateActive)) {
2013
+ popover.close();
2014
+ }
2015
+ this.removeEventListener("click", _f);
2016
+ }
2017
+ });
2018
+ }
2019
+
2020
+ var top = 'top';
2021
+ var bottom = 'bottom';
2022
+ var right = 'right';
2023
+ var left = 'left';
2024
+ var auto = 'auto';
2025
+ var basePlacements = [top, bottom, right, left];
2026
+ var start = 'start';
2027
+ var end = 'end';
2028
+ var clippingParents = 'clippingParents';
2029
+ var viewport = 'viewport';
2030
+ var popper = 'popper';
2031
+ var reference = 'reference';
2032
+ var variationPlacements = /*#__PURE__*/basePlacements.reduce(function (acc, placement) {
2033
+ return acc.concat([placement + "-" + start, placement + "-" + end]);
2034
+ }, []);
2035
+ var placements = /*#__PURE__*/[].concat(basePlacements, [auto]).reduce(function (acc, placement) {
2036
+ return acc.concat([placement, placement + "-" + start, placement + "-" + end]);
2037
+ }, []); // modifiers that need to read the DOM
2038
+
2039
+ var beforeRead = 'beforeRead';
2040
+ var read = 'read';
2041
+ var afterRead = 'afterRead'; // pure-logic modifiers
2042
+
2043
+ var beforeMain = 'beforeMain';
2044
+ var main = 'main';
2045
+ var afterMain = 'afterMain'; // modifier with the purpose to write to the DOM (or write into a framework state)
2046
+
2047
+ var beforeWrite = 'beforeWrite';
2048
+ var write = 'write';
2049
+ var afterWrite = 'afterWrite';
2050
+ var modifierPhases = [beforeRead, read, afterRead, beforeMain, main, afterMain, beforeWrite, write, afterWrite];
2051
+
2052
+ function getNodeName(element) {
2053
+ return element ? (element.nodeName || '').toLowerCase() : null;
2054
+ }
2055
+
2056
+ function getWindow(node) {
2057
+ if (node == null) {
2058
+ return window;
2059
+ }
2060
+
2061
+ if (node.toString() !== '[object Window]') {
2062
+ var ownerDocument = node.ownerDocument;
2063
+ return ownerDocument ? ownerDocument.defaultView || window : window;
2064
+ }
2065
+
2066
+ return node;
2067
+ }
2068
+
2069
+ function isElement(node) {
2070
+ var OwnElement = getWindow(node).Element;
2071
+ return node instanceof OwnElement || node instanceof Element;
2072
+ }
2073
+
2074
+ function isHTMLElement(node) {
2075
+ var OwnElement = getWindow(node).HTMLElement;
2076
+ return node instanceof OwnElement || node instanceof HTMLElement;
2077
+ }
2078
+
2079
+ function isShadowRoot(node) {
2080
+ // IE 11 has no ShadowRoot
2081
+ if (typeof ShadowRoot === 'undefined') {
2082
+ return false;
2083
+ }
2084
+
2085
+ var OwnElement = getWindow(node).ShadowRoot;
2086
+ return node instanceof OwnElement || node instanceof ShadowRoot;
2087
+ }
2088
+
2089
+ // and applies them to the HTMLElements such as popper and arrow
2090
+
2091
+ function applyStyles(_ref) {
2092
+ var state = _ref.state;
2093
+ Object.keys(state.elements).forEach(function (name) {
2094
+ var style = state.styles[name] || {};
2095
+ var attributes = state.attributes[name] || {};
2096
+ var element = state.elements[name]; // arrow is optional + virtual elements
2097
+
2098
+ if (!isHTMLElement(element) || !getNodeName(element)) {
2099
+ return;
2100
+ } // Flow doesn't support to extend this property, but it's the most
2101
+ // effective way to apply styles to an HTMLElement
2102
+ // $FlowFixMe[cannot-write]
2103
+
2104
+
2105
+ Object.assign(element.style, style);
2106
+ Object.keys(attributes).forEach(function (name) {
2107
+ var value = attributes[name];
2108
+
2109
+ if (value === false) {
2110
+ element.removeAttribute(name);
2111
+ } else {
2112
+ element.setAttribute(name, value === true ? '' : value);
2113
+ }
2114
+ });
2115
+ });
2116
+ }
2117
+
2118
+ function effect$2(_ref2) {
2119
+ var state = _ref2.state;
2120
+ var initialStyles = {
2121
+ popper: {
2122
+ position: state.options.strategy,
2123
+ left: '0',
2124
+ top: '0',
2125
+ margin: '0'
2126
+ },
2127
+ arrow: {
2128
+ position: 'absolute'
2129
+ },
2130
+ reference: {}
2131
+ };
2132
+ Object.assign(state.elements.popper.style, initialStyles.popper);
2133
+ state.styles = initialStyles;
2134
+
2135
+ if (state.elements.arrow) {
2136
+ Object.assign(state.elements.arrow.style, initialStyles.arrow);
2137
+ }
2138
+
2139
+ return function () {
2140
+ Object.keys(state.elements).forEach(function (name) {
2141
+ var element = state.elements[name];
2142
+ var attributes = state.attributes[name] || {};
2143
+ var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? state.styles[name] : initialStyles[name]); // Set all values to an empty string to unset them
2144
+
2145
+ var style = styleProperties.reduce(function (style, property) {
2146
+ style[property] = '';
2147
+ return style;
2148
+ }, {}); // arrow is optional + virtual elements
2149
+
2150
+ if (!isHTMLElement(element) || !getNodeName(element)) {
2151
+ return;
2152
+ }
2153
+
2154
+ Object.assign(element.style, style);
2155
+ Object.keys(attributes).forEach(function (attribute) {
2156
+ element.removeAttribute(attribute);
2157
+ });
2158
+ });
2159
+ };
2160
+ } // eslint-disable-next-line import/no-unused-modules
2161
+
2162
+
2163
+ var applyStyles$1 = {
2164
+ name: 'applyStyles',
2165
+ enabled: true,
2166
+ phase: 'write',
2167
+ fn: applyStyles,
2168
+ effect: effect$2,
2169
+ requires: ['computeStyles']
2170
+ };
2171
+
2172
+ function getBasePlacement(placement) {
2173
+ return placement.split('-')[0];
2174
+ }
2175
+
2176
+ var max = Math.max;
2177
+ var min = Math.min;
2178
+ var round = Math.round;
2179
+
2180
+ function getUAString() {
2181
+ var uaData = navigator.userAgentData;
2182
+
2183
+ if (uaData != null && uaData.brands && Array.isArray(uaData.brands)) {
2184
+ return uaData.brands.map(function (item) {
2185
+ return item.brand + "/" + item.version;
2186
+ }).join(' ');
2187
+ }
2188
+
2189
+ return navigator.userAgent;
2190
+ }
2191
+
2192
+ function isLayoutViewport() {
2193
+ return !/^((?!chrome|android).)*safari/i.test(getUAString());
2194
+ }
2195
+
2196
+ function getBoundingClientRect(element, includeScale, isFixedStrategy) {
2197
+ if (includeScale === void 0) {
2198
+ includeScale = false;
2199
+ }
2200
+
2201
+ if (isFixedStrategy === void 0) {
2202
+ isFixedStrategy = false;
2203
+ }
2204
+
2205
+ var clientRect = element.getBoundingClientRect();
2206
+ var scaleX = 1;
2207
+ var scaleY = 1;
2208
+
2209
+ if (includeScale && isHTMLElement(element)) {
2210
+ scaleX = element.offsetWidth > 0 ? round(clientRect.width) / element.offsetWidth || 1 : 1;
2211
+ scaleY = element.offsetHeight > 0 ? round(clientRect.height) / element.offsetHeight || 1 : 1;
2212
+ }
2213
+
2214
+ var _ref = isElement(element) ? getWindow(element) : window,
2215
+ visualViewport = _ref.visualViewport;
2216
+
2217
+ var addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
2218
+ var x = (clientRect.left + (addVisualOffsets && visualViewport ? visualViewport.offsetLeft : 0)) / scaleX;
2219
+ var y = (clientRect.top + (addVisualOffsets && visualViewport ? visualViewport.offsetTop : 0)) / scaleY;
2220
+ var width = clientRect.width / scaleX;
2221
+ var height = clientRect.height / scaleY;
2222
+ return {
2223
+ width: width,
2224
+ height: height,
2225
+ top: y,
2226
+ right: x + width,
2227
+ bottom: y + height,
2228
+ left: x,
2229
+ x: x,
2230
+ y: y
2231
+ };
2232
+ }
2233
+
2234
+ // means it doesn't take into account transforms.
2235
+
2236
+ function getLayoutRect(element) {
2237
+ var clientRect = getBoundingClientRect(element); // Use the clientRect sizes if it's not been transformed.
2238
+ // Fixes https://github.com/popperjs/popper-core/issues/1223
2239
+
2240
+ var width = element.offsetWidth;
2241
+ var height = element.offsetHeight;
2242
+
2243
+ if (Math.abs(clientRect.width - width) <= 1) {
2244
+ width = clientRect.width;
2245
+ }
2246
+
2247
+ if (Math.abs(clientRect.height - height) <= 1) {
2248
+ height = clientRect.height;
2249
+ }
2250
+
2251
+ return {
2252
+ x: element.offsetLeft,
2253
+ y: element.offsetTop,
2254
+ width: width,
2255
+ height: height
2256
+ };
2257
+ }
2258
+
2259
+ function contains(parent, child) {
2260
+ var rootNode = child.getRootNode && child.getRootNode(); // First, attempt with faster native method
2261
+
2262
+ if (parent.contains(child)) {
2263
+ return true;
2264
+ } // then fallback to custom implementation with Shadow DOM support
2265
+ else if (rootNode && isShadowRoot(rootNode)) {
2266
+ var next = child;
2267
+
2268
+ do {
2269
+ if (next && parent.isSameNode(next)) {
2270
+ return true;
2271
+ } // $FlowFixMe[prop-missing]: need a better way to handle this...
2272
+
2273
+
2274
+ next = next.parentNode || next.host;
2275
+ } while (next);
2276
+ } // Give up, the result is false
2277
+
2278
+
2279
+ return false;
2280
+ }
2281
+
2282
+ function getComputedStyle$1(element) {
2283
+ return getWindow(element).getComputedStyle(element);
2284
+ }
2285
+
2286
+ function isTableElement(element) {
2287
+ return ['table', 'td', 'th'].indexOf(getNodeName(element)) >= 0;
2288
+ }
2289
+
2290
+ function getDocumentElement(element) {
2291
+ // $FlowFixMe[incompatible-return]: assume body is always available
2292
+ return ((isElement(element) ? element.ownerDocument : // $FlowFixMe[prop-missing]
2293
+ element.document) || window.document).documentElement;
2294
+ }
2295
+
2296
+ function getParentNode(element) {
2297
+ if (getNodeName(element) === 'html') {
2298
+ return element;
2299
+ }
2300
+
2301
+ return (// this is a quicker (but less type safe) way to save quite some bytes from the bundle
2302
+ // $FlowFixMe[incompatible-return]
2303
+ // $FlowFixMe[prop-missing]
2304
+ element.assignedSlot || // step into the shadow DOM of the parent of a slotted node
2305
+ element.parentNode || ( // DOM Element detected
2306
+ isShadowRoot(element) ? element.host : null) || // ShadowRoot detected
2307
+ // $FlowFixMe[incompatible-call]: HTMLElement is a Node
2308
+ getDocumentElement(element) // fallback
2309
+
2310
+ );
2311
+ }
2312
+
2313
+ function getTrueOffsetParent(element) {
2314
+ if (!isHTMLElement(element) || // https://github.com/popperjs/popper-core/issues/837
2315
+ getComputedStyle$1(element).position === 'fixed') {
2316
+ return null;
2317
+ }
2318
+
2319
+ return element.offsetParent;
2320
+ } // `.offsetParent` reports `null` for fixed elements, while absolute elements
2321
+ // return the containing block
2322
+
2323
+
2324
+ function getContainingBlock(element) {
2325
+ var isFirefox = /firefox/i.test(getUAString());
2326
+ var isIE = /Trident/i.test(getUAString());
2327
+
2328
+ if (isIE && isHTMLElement(element)) {
2329
+ // In IE 9, 10 and 11 fixed elements containing block is always established by the viewport
2330
+ var elementCss = getComputedStyle$1(element);
2331
+
2332
+ if (elementCss.position === 'fixed') {
2333
+ return null;
2334
+ }
2335
+ }
2336
+
2337
+ var currentNode = getParentNode(element);
2338
+
2339
+ if (isShadowRoot(currentNode)) {
2340
+ currentNode = currentNode.host;
2341
+ }
2342
+
2343
+ while (isHTMLElement(currentNode) && ['html', 'body'].indexOf(getNodeName(currentNode)) < 0) {
2344
+ var css = getComputedStyle$1(currentNode); // This is non-exhaustive but covers the most common CSS properties that
2345
+ // create a containing block.
2346
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
2347
+
2348
+ if (css.transform !== 'none' || css.perspective !== 'none' || css.contain === 'paint' || ['transform', 'perspective'].indexOf(css.willChange) !== -1 || isFirefox && css.willChange === 'filter' || isFirefox && css.filter && css.filter !== 'none') {
2349
+ return currentNode;
2350
+ } else {
2351
+ currentNode = currentNode.parentNode;
2352
+ }
2353
+ }
2354
+
2355
+ return null;
2356
+ } // Gets the closest ancestor positioned element. Handles some edge cases,
2357
+ // such as table ancestors and cross browser bugs.
2358
+
2359
+
2360
+ function getOffsetParent(element) {
2361
+ var window = getWindow(element);
2362
+ var offsetParent = getTrueOffsetParent(element);
2363
+
2364
+ while (offsetParent && isTableElement(offsetParent) && getComputedStyle$1(offsetParent).position === 'static') {
2365
+ offsetParent = getTrueOffsetParent(offsetParent);
2366
+ }
2367
+
2368
+ if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle$1(offsetParent).position === 'static')) {
2369
+ return window;
2370
+ }
2371
+
2372
+ return offsetParent || getContainingBlock(element) || window;
2373
+ }
2374
+
2375
+ function getMainAxisFromPlacement(placement) {
2376
+ return ['top', 'bottom'].indexOf(placement) >= 0 ? 'x' : 'y';
2377
+ }
2378
+
2379
+ function within(min$1, value, max$1) {
2380
+ return max(min$1, min(value, max$1));
2381
+ }
2382
+ function withinMaxClamp(min, value, max) {
2383
+ var v = within(min, value, max);
2384
+ return v > max ? max : v;
2385
+ }
2386
+
2387
+ function getFreshSideObject() {
2388
+ return {
2389
+ top: 0,
2390
+ right: 0,
2391
+ bottom: 0,
2392
+ left: 0
2393
+ };
2394
+ }
2395
+
2396
+ function mergePaddingObject(paddingObject) {
2397
+ return Object.assign({}, getFreshSideObject(), paddingObject);
2398
+ }
2399
+
2400
+ function expandToHashMap(value, keys) {
2401
+ return keys.reduce(function (hashMap, key) {
2402
+ hashMap[key] = value;
2403
+ return hashMap;
2404
+ }, {});
2405
+ }
2406
+
2407
+ var toPaddingObject = function toPaddingObject(padding, state) {
2408
+ padding = typeof padding === 'function' ? padding(Object.assign({}, state.rects, {
2409
+ placement: state.placement
2410
+ })) : padding;
2411
+ return mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
2412
+ };
2413
+
2414
+ function arrow(_ref) {
2415
+ var _state$modifiersData$;
2416
+
2417
+ var state = _ref.state,
2418
+ name = _ref.name,
2419
+ options = _ref.options;
2420
+ var arrowElement = state.elements.arrow;
2421
+ var popperOffsets = state.modifiersData.popperOffsets;
2422
+ var basePlacement = getBasePlacement(state.placement);
2423
+ var axis = getMainAxisFromPlacement(basePlacement);
2424
+ var isVertical = [left, right].indexOf(basePlacement) >= 0;
2425
+ var len = isVertical ? 'height' : 'width';
2426
+
2427
+ if (!arrowElement || !popperOffsets) {
2428
+ return;
2429
+ }
2430
+
2431
+ var paddingObject = toPaddingObject(options.padding, state);
2432
+ var arrowRect = getLayoutRect(arrowElement);
2433
+ var minProp = axis === 'y' ? top : left;
2434
+ var maxProp = axis === 'y' ? bottom : right;
2435
+ var endDiff = state.rects.reference[len] + state.rects.reference[axis] - popperOffsets[axis] - state.rects.popper[len];
2436
+ var startDiff = popperOffsets[axis] - state.rects.reference[axis];
2437
+ var arrowOffsetParent = getOffsetParent(arrowElement);
2438
+ var clientSize = arrowOffsetParent ? axis === 'y' ? arrowOffsetParent.clientHeight || 0 : arrowOffsetParent.clientWidth || 0 : 0;
2439
+ var centerToReference = endDiff / 2 - startDiff / 2; // Make sure the arrow doesn't overflow the popper if the center point is
2440
+ // outside of the popper bounds
2441
+
2442
+ var min = paddingObject[minProp];
2443
+ var max = clientSize - arrowRect[len] - paddingObject[maxProp];
2444
+ var center = clientSize / 2 - arrowRect[len] / 2 + centerToReference;
2445
+ var offset = within(min, center, max); // Prevents breaking syntax highlighting...
2446
+
2447
+ var axisProp = axis;
2448
+ state.modifiersData[name] = (_state$modifiersData$ = {}, _state$modifiersData$[axisProp] = offset, _state$modifiersData$.centerOffset = offset - center, _state$modifiersData$);
2449
+ }
2450
+
2451
+ function effect$1(_ref2) {
2452
+ var state = _ref2.state,
2453
+ options = _ref2.options;
2454
+ var _options$element = options.element,
2455
+ arrowElement = _options$element === void 0 ? '[data-popper-arrow]' : _options$element;
2456
+
2457
+ if (arrowElement == null) {
2458
+ return;
2459
+ } // CSS selector
2460
+
2461
+
2462
+ if (typeof arrowElement === 'string') {
2463
+ arrowElement = state.elements.popper.querySelector(arrowElement);
2464
+
2465
+ if (!arrowElement) {
2466
+ return;
2467
+ }
2468
+ }
2469
+
2470
+ if (!contains(state.elements.popper, arrowElement)) {
2471
+ return;
2472
+ }
2473
+
2474
+ state.elements.arrow = arrowElement;
2475
+ } // eslint-disable-next-line import/no-unused-modules
2476
+
2477
+
2478
+ var arrow$1 = {
2479
+ name: 'arrow',
2480
+ enabled: true,
2481
+ phase: 'main',
2482
+ fn: arrow,
2483
+ effect: effect$1,
2484
+ requires: ['popperOffsets'],
2485
+ requiresIfExists: ['preventOverflow']
2486
+ };
2487
+
2488
+ function getVariation(placement) {
2489
+ return placement.split('-')[1];
2490
+ }
2491
+
2492
+ var unsetSides = {
2493
+ top: 'auto',
2494
+ right: 'auto',
2495
+ bottom: 'auto',
2496
+ left: 'auto'
2497
+ }; // Round the offsets to the nearest suitable subpixel based on the DPR.
2498
+ // Zooming can change the DPR, but it seems to report a value that will
2499
+ // cleanly divide the values into the appropriate subpixels.
2500
+
2501
+ function roundOffsetsByDPR(_ref, win) {
2502
+ var x = _ref.x,
2503
+ y = _ref.y;
2504
+ var dpr = win.devicePixelRatio || 1;
2505
+ return {
2506
+ x: round(x * dpr) / dpr || 0,
2507
+ y: round(y * dpr) / dpr || 0
2508
+ };
2509
+ }
2510
+
2511
+ function mapToStyles(_ref2) {
2512
+ var _Object$assign2;
2513
+
2514
+ var popper = _ref2.popper,
2515
+ popperRect = _ref2.popperRect,
2516
+ placement = _ref2.placement,
2517
+ variation = _ref2.variation,
2518
+ offsets = _ref2.offsets,
2519
+ position = _ref2.position,
2520
+ gpuAcceleration = _ref2.gpuAcceleration,
2521
+ adaptive = _ref2.adaptive,
2522
+ roundOffsets = _ref2.roundOffsets,
2523
+ isFixed = _ref2.isFixed;
2524
+ var _offsets$x = offsets.x,
2525
+ x = _offsets$x === void 0 ? 0 : _offsets$x,
2526
+ _offsets$y = offsets.y,
2527
+ y = _offsets$y === void 0 ? 0 : _offsets$y;
2528
+
2529
+ var _ref3 = typeof roundOffsets === 'function' ? roundOffsets({
2530
+ x: x,
2531
+ y: y
2532
+ }) : {
2533
+ x: x,
2534
+ y: y
2535
+ };
2536
+
2537
+ x = _ref3.x;
2538
+ y = _ref3.y;
2539
+ var hasX = offsets.hasOwnProperty('x');
2540
+ var hasY = offsets.hasOwnProperty('y');
2541
+ var sideX = left;
2542
+ var sideY = top;
2543
+ var win = window;
2544
+
2545
+ if (adaptive) {
2546
+ var offsetParent = getOffsetParent(popper);
2547
+ var heightProp = 'clientHeight';
2548
+ var widthProp = 'clientWidth';
2549
+
2550
+ if (offsetParent === getWindow(popper)) {
2551
+ offsetParent = getDocumentElement(popper);
2552
+
2553
+ if (getComputedStyle$1(offsetParent).position !== 'static' && position === 'absolute') {
2554
+ heightProp = 'scrollHeight';
2555
+ widthProp = 'scrollWidth';
2556
+ }
2557
+ } // $FlowFixMe[incompatible-cast]: force type refinement, we compare offsetParent with window above, but Flow doesn't detect it
2558
+
2559
+
2560
+ offsetParent = offsetParent;
2561
+
2562
+ if (placement === top || (placement === left || placement === right) && variation === end) {
2563
+ sideY = bottom;
2564
+ var offsetY = isFixed && offsetParent === win && win.visualViewport ? win.visualViewport.height : // $FlowFixMe[prop-missing]
2565
+ offsetParent[heightProp];
2566
+ y -= offsetY - popperRect.height;
2567
+ y *= gpuAcceleration ? 1 : -1;
2568
+ }
2569
+
2570
+ if (placement === left || (placement === top || placement === bottom) && variation === end) {
2571
+ sideX = right;
2572
+ var offsetX = isFixed && offsetParent === win && win.visualViewport ? win.visualViewport.width : // $FlowFixMe[prop-missing]
2573
+ offsetParent[widthProp];
2574
+ x -= offsetX - popperRect.width;
2575
+ x *= gpuAcceleration ? 1 : -1;
2576
+ }
2577
+ }
2578
+
2579
+ var commonStyles = Object.assign({
2580
+ position: position
2581
+ }, adaptive && unsetSides);
2582
+
2583
+ var _ref4 = roundOffsets === true ? roundOffsetsByDPR({
2584
+ x: x,
2585
+ y: y
2586
+ }, getWindow(popper)) : {
2587
+ x: x,
2588
+ y: y
2589
+ };
2590
+
2591
+ x = _ref4.x;
2592
+ y = _ref4.y;
2593
+
2594
+ if (gpuAcceleration) {
2595
+ var _Object$assign;
2596
+
2597
+ return Object.assign({}, commonStyles, (_Object$assign = {}, _Object$assign[sideY] = hasY ? '0' : '', _Object$assign[sideX] = hasX ? '0' : '', _Object$assign.transform = (win.devicePixelRatio || 1) <= 1 ? "translate(" + x + "px, " + y + "px)" : "translate3d(" + x + "px, " + y + "px, 0)", _Object$assign));
2598
+ }
2599
+
2600
+ return Object.assign({}, commonStyles, (_Object$assign2 = {}, _Object$assign2[sideY] = hasY ? y + "px" : '', _Object$assign2[sideX] = hasX ? x + "px" : '', _Object$assign2.transform = '', _Object$assign2));
2601
+ }
2602
+
2603
+ function computeStyles(_ref5) {
2604
+ var state = _ref5.state,
2605
+ options = _ref5.options;
2606
+ var _options$gpuAccelerat = options.gpuAcceleration,
2607
+ gpuAcceleration = _options$gpuAccelerat === void 0 ? true : _options$gpuAccelerat,
2608
+ _options$adaptive = options.adaptive,
2609
+ adaptive = _options$adaptive === void 0 ? true : _options$adaptive,
2610
+ _options$roundOffsets = options.roundOffsets,
2611
+ roundOffsets = _options$roundOffsets === void 0 ? true : _options$roundOffsets;
2612
+ var commonStyles = {
2613
+ placement: getBasePlacement(state.placement),
2614
+ variation: getVariation(state.placement),
2615
+ popper: state.elements.popper,
2616
+ popperRect: state.rects.popper,
2617
+ gpuAcceleration: gpuAcceleration,
2618
+ isFixed: state.options.strategy === 'fixed'
2619
+ };
2620
+
2621
+ if (state.modifiersData.popperOffsets != null) {
2622
+ state.styles.popper = Object.assign({}, state.styles.popper, mapToStyles(Object.assign({}, commonStyles, {
2623
+ offsets: state.modifiersData.popperOffsets,
2624
+ position: state.options.strategy,
2625
+ adaptive: adaptive,
2626
+ roundOffsets: roundOffsets
2627
+ })));
2628
+ }
2629
+
2630
+ if (state.modifiersData.arrow != null) {
2631
+ state.styles.arrow = Object.assign({}, state.styles.arrow, mapToStyles(Object.assign({}, commonStyles, {
2632
+ offsets: state.modifiersData.arrow,
2633
+ position: 'absolute',
2634
+ adaptive: false,
2635
+ roundOffsets: roundOffsets
2636
+ })));
2637
+ }
2638
+
2639
+ state.attributes.popper = Object.assign({}, state.attributes.popper, {
2640
+ 'data-popper-placement': state.placement
2641
+ });
2642
+ } // eslint-disable-next-line import/no-unused-modules
2643
+
2644
+
2645
+ var computeStyles$1 = {
2646
+ name: 'computeStyles',
2647
+ enabled: true,
2648
+ phase: 'beforeWrite',
2649
+ fn: computeStyles,
2650
+ data: {}
2651
+ };
2652
+
2653
+ var passive = {
2654
+ passive: true
2655
+ };
2656
+
2657
+ function effect(_ref) {
2658
+ var state = _ref.state,
2659
+ instance = _ref.instance,
2660
+ options = _ref.options;
2661
+ var _options$scroll = options.scroll,
2662
+ scroll = _options$scroll === void 0 ? true : _options$scroll,
2663
+ _options$resize = options.resize,
2664
+ resize = _options$resize === void 0 ? true : _options$resize;
2665
+ var window = getWindow(state.elements.popper);
2666
+ var scrollParents = [].concat(state.scrollParents.reference, state.scrollParents.popper);
2667
+
2668
+ if (scroll) {
2669
+ scrollParents.forEach(function (scrollParent) {
2670
+ scrollParent.addEventListener('scroll', instance.update, passive);
2671
+ });
2672
+ }
2673
+
2674
+ if (resize) {
2675
+ window.addEventListener('resize', instance.update, passive);
2676
+ }
2677
+
2678
+ return function () {
2679
+ if (scroll) {
2680
+ scrollParents.forEach(function (scrollParent) {
2681
+ scrollParent.removeEventListener('scroll', instance.update, passive);
2682
+ });
2683
+ }
2684
+
2685
+ if (resize) {
2686
+ window.removeEventListener('resize', instance.update, passive);
2687
+ }
2688
+ };
2689
+ } // eslint-disable-next-line import/no-unused-modules
2690
+
2691
+
2692
+ var eventListeners = {
2693
+ name: 'eventListeners',
2694
+ enabled: true,
2695
+ phase: 'write',
2696
+ fn: function fn() {},
2697
+ effect: effect,
2698
+ data: {}
2699
+ };
2700
+
2701
+ var hash$1 = {
2702
+ left: 'right',
2703
+ right: 'left',
2704
+ bottom: 'top',
2705
+ top: 'bottom'
2706
+ };
2707
+ function getOppositePlacement(placement) {
2708
+ return placement.replace(/left|right|bottom|top/g, function (matched) {
2709
+ return hash$1[matched];
2710
+ });
2711
+ }
2712
+
2713
+ var hash = {
2714
+ start: 'end',
2715
+ end: 'start'
2716
+ };
2717
+ function getOppositeVariationPlacement(placement) {
2718
+ return placement.replace(/start|end/g, function (matched) {
2719
+ return hash[matched];
2720
+ });
2721
+ }
2722
+
2723
+ function getWindowScroll(node) {
2724
+ var win = getWindow(node);
2725
+ var scrollLeft = win.pageXOffset;
2726
+ var scrollTop = win.pageYOffset;
2727
+ return {
2728
+ scrollLeft: scrollLeft,
2729
+ scrollTop: scrollTop
2730
+ };
2731
+ }
2732
+
2733
+ function getWindowScrollBarX(element) {
2734
+ // If <html> has a CSS width greater than the viewport, then this will be
2735
+ // incorrect for RTL.
2736
+ // Popper 1 is broken in this case and never had a bug report so let's assume
2737
+ // it's not an issue. I don't think anyone ever specifies width on <html>
2738
+ // anyway.
2739
+ // Browsers where the left scrollbar doesn't cause an issue report `0` for
2740
+ // this (e.g. Edge 2019, IE11, Safari)
2741
+ return getBoundingClientRect(getDocumentElement(element)).left + getWindowScroll(element).scrollLeft;
2742
+ }
2743
+
2744
+ function getViewportRect(element, strategy) {
2745
+ var win = getWindow(element);
2746
+ var html = getDocumentElement(element);
2747
+ var visualViewport = win.visualViewport;
2748
+ var width = html.clientWidth;
2749
+ var height = html.clientHeight;
2750
+ var x = 0;
2751
+ var y = 0;
2752
+
2753
+ if (visualViewport) {
2754
+ width = visualViewport.width;
2755
+ height = visualViewport.height;
2756
+ var layoutViewport = isLayoutViewport();
2757
+
2758
+ if (layoutViewport || !layoutViewport && strategy === 'fixed') {
2759
+ x = visualViewport.offsetLeft;
2760
+ y = visualViewport.offsetTop;
2761
+ }
2762
+ }
2763
+
2764
+ return {
2765
+ width: width,
2766
+ height: height,
2767
+ x: x + getWindowScrollBarX(element),
2768
+ y: y
2769
+ };
2770
+ }
2771
+
2772
+ // of the `<html>` and `<body>` rect bounds if horizontally scrollable
2773
+
2774
+ function getDocumentRect(element) {
2775
+ var _element$ownerDocumen;
2776
+
2777
+ var html = getDocumentElement(element);
2778
+ var winScroll = getWindowScroll(element);
2779
+ var body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
2780
+ var width = max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
2781
+ var height = max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
2782
+ var x = -winScroll.scrollLeft + getWindowScrollBarX(element);
2783
+ var y = -winScroll.scrollTop;
2784
+
2785
+ if (getComputedStyle$1(body || html).direction === 'rtl') {
2786
+ x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
2787
+ }
2788
+
2789
+ return {
2790
+ width: width,
2791
+ height: height,
2792
+ x: x,
2793
+ y: y
2794
+ };
2795
+ }
2796
+
2797
+ function isScrollParent(element) {
2798
+ // Firefox wants us to check `-x` and `-y` variations as well
2799
+ var _getComputedStyle = getComputedStyle$1(element),
2800
+ overflow = _getComputedStyle.overflow,
2801
+ overflowX = _getComputedStyle.overflowX,
2802
+ overflowY = _getComputedStyle.overflowY;
2803
+
2804
+ return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
2805
+ }
2806
+
2807
+ function getScrollParent(node) {
2808
+ if (['html', 'body', '#document'].indexOf(getNodeName(node)) >= 0) {
2809
+ // $FlowFixMe[incompatible-return]: assume body is always available
2810
+ return node.ownerDocument.body;
2811
+ }
2812
+
2813
+ if (isHTMLElement(node) && isScrollParent(node)) {
2814
+ return node;
2815
+ }
2816
+
2817
+ return getScrollParent(getParentNode(node));
2818
+ }
2819
+
2820
+ /*
2821
+ given a DOM element, return the list of all scroll parents, up the list of ancesors
2822
+ until we get to the top window object. This list is what we attach scroll listeners
2823
+ to, because if any of these parent elements scroll, we'll need to re-calculate the
2824
+ reference element's position.
2825
+ */
2826
+
2827
+ function listScrollParents(element, list) {
2828
+ var _element$ownerDocumen;
2829
+
2830
+ if (list === void 0) {
2831
+ list = [];
2832
+ }
2833
+
2834
+ var scrollParent = getScrollParent(element);
2835
+ var isBody = scrollParent === ((_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body);
2836
+ var win = getWindow(scrollParent);
2837
+ var target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
2838
+ var updatedList = list.concat(target);
2839
+ return isBody ? updatedList : // $FlowFixMe[incompatible-call]: isBody tells us target will be an HTMLElement here
2840
+ updatedList.concat(listScrollParents(getParentNode(target)));
2841
+ }
2842
+
2843
+ function rectToClientRect(rect) {
2844
+ return Object.assign({}, rect, {
2845
+ left: rect.x,
2846
+ top: rect.y,
2847
+ right: rect.x + rect.width,
2848
+ bottom: rect.y + rect.height
2849
+ });
2850
+ }
2851
+
2852
+ function getInnerBoundingClientRect(element, strategy) {
2853
+ var rect = getBoundingClientRect(element, false, strategy === 'fixed');
2854
+ rect.top = rect.top + element.clientTop;
2855
+ rect.left = rect.left + element.clientLeft;
2856
+ rect.bottom = rect.top + element.clientHeight;
2857
+ rect.right = rect.left + element.clientWidth;
2858
+ rect.width = element.clientWidth;
2859
+ rect.height = element.clientHeight;
2860
+ rect.x = rect.left;
2861
+ rect.y = rect.top;
2862
+ return rect;
2863
+ }
2864
+
2865
+ function getClientRectFromMixedType(element, clippingParent, strategy) {
2866
+ return clippingParent === viewport ? rectToClientRect(getViewportRect(element, strategy)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent, strategy) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
2867
+ } // A "clipping parent" is an overflowable container with the characteristic of
2868
+ // clipping (or hiding) overflowing elements with a position different from
2869
+ // `initial`
2870
+
2871
+
2872
+ function getClippingParents(element) {
2873
+ var clippingParents = listScrollParents(getParentNode(element));
2874
+ var canEscapeClipping = ['absolute', 'fixed'].indexOf(getComputedStyle$1(element).position) >= 0;
2875
+ var clipperElement = canEscapeClipping && isHTMLElement(element) ? getOffsetParent(element) : element;
2876
+
2877
+ if (!isElement(clipperElement)) {
2878
+ return [];
2879
+ } // $FlowFixMe[incompatible-return]: https://github.com/facebook/flow/issues/1414
2880
+
2881
+
2882
+ return clippingParents.filter(function (clippingParent) {
2883
+ return isElement(clippingParent) && contains(clippingParent, clipperElement) && getNodeName(clippingParent) !== 'body';
2884
+ });
2885
+ } // Gets the maximum area that the element is visible in due to any number of
2886
+ // clipping parents
2887
+
2888
+
2889
+ function getClippingRect(element, boundary, rootBoundary, strategy) {
2890
+ var mainClippingParents = boundary === 'clippingParents' ? getClippingParents(element) : [].concat(boundary);
2891
+ var clippingParents = [].concat(mainClippingParents, [rootBoundary]);
2892
+ var firstClippingParent = clippingParents[0];
2893
+ var clippingRect = clippingParents.reduce(function (accRect, clippingParent) {
2894
+ var rect = getClientRectFromMixedType(element, clippingParent, strategy);
2895
+ accRect.top = max(rect.top, accRect.top);
2896
+ accRect.right = min(rect.right, accRect.right);
2897
+ accRect.bottom = min(rect.bottom, accRect.bottom);
2898
+ accRect.left = max(rect.left, accRect.left);
2899
+ return accRect;
2900
+ }, getClientRectFromMixedType(element, firstClippingParent, strategy));
2901
+ clippingRect.width = clippingRect.right - clippingRect.left;
2902
+ clippingRect.height = clippingRect.bottom - clippingRect.top;
2903
+ clippingRect.x = clippingRect.left;
2904
+ clippingRect.y = clippingRect.top;
2905
+ return clippingRect;
2906
+ }
2907
+
2908
+ function computeOffsets(_ref) {
2909
+ var reference = _ref.reference,
2910
+ element = _ref.element,
2911
+ placement = _ref.placement;
2912
+ var basePlacement = placement ? getBasePlacement(placement) : null;
2913
+ var variation = placement ? getVariation(placement) : null;
2914
+ var commonX = reference.x + reference.width / 2 - element.width / 2;
2915
+ var commonY = reference.y + reference.height / 2 - element.height / 2;
2916
+ var offsets;
2917
+
2918
+ switch (basePlacement) {
2919
+ case top:
2920
+ offsets = {
2921
+ x: commonX,
2922
+ y: reference.y - element.height
2923
+ };
2924
+ break;
2925
+
2926
+ case bottom:
2927
+ offsets = {
2928
+ x: commonX,
2929
+ y: reference.y + reference.height
2930
+ };
2931
+ break;
2932
+
2933
+ case right:
2934
+ offsets = {
2935
+ x: reference.x + reference.width,
2936
+ y: commonY
2937
+ };
2938
+ break;
2939
+
2940
+ case left:
2941
+ offsets = {
2942
+ x: reference.x - element.width,
2943
+ y: commonY
2944
+ };
2945
+ break;
2946
+
2947
+ default:
2948
+ offsets = {
2949
+ x: reference.x,
2950
+ y: reference.y
2951
+ };
2952
+ }
2953
+
2954
+ var mainAxis = basePlacement ? getMainAxisFromPlacement(basePlacement) : null;
2955
+
2956
+ if (mainAxis != null) {
2957
+ var len = mainAxis === 'y' ? 'height' : 'width';
2958
+
2959
+ switch (variation) {
2960
+ case start:
2961
+ offsets[mainAxis] = offsets[mainAxis] - (reference[len] / 2 - element[len] / 2);
2962
+ break;
2963
+
2964
+ case end:
2965
+ offsets[mainAxis] = offsets[mainAxis] + (reference[len] / 2 - element[len] / 2);
2966
+ break;
2967
+ }
2968
+ }
2969
+
2970
+ return offsets;
2971
+ }
2972
+
2973
+ function detectOverflow(state, options) {
2974
+ if (options === void 0) {
2975
+ options = {};
2976
+ }
2977
+
2978
+ var _options = options,
2979
+ _options$placement = _options.placement,
2980
+ placement = _options$placement === void 0 ? state.placement : _options$placement,
2981
+ _options$strategy = _options.strategy,
2982
+ strategy = _options$strategy === void 0 ? state.strategy : _options$strategy,
2983
+ _options$boundary = _options.boundary,
2984
+ boundary = _options$boundary === void 0 ? clippingParents : _options$boundary,
2985
+ _options$rootBoundary = _options.rootBoundary,
2986
+ rootBoundary = _options$rootBoundary === void 0 ? viewport : _options$rootBoundary,
2987
+ _options$elementConte = _options.elementContext,
2988
+ elementContext = _options$elementConte === void 0 ? popper : _options$elementConte,
2989
+ _options$altBoundary = _options.altBoundary,
2990
+ altBoundary = _options$altBoundary === void 0 ? false : _options$altBoundary,
2991
+ _options$padding = _options.padding,
2992
+ padding = _options$padding === void 0 ? 0 : _options$padding;
2993
+ var paddingObject = mergePaddingObject(typeof padding !== 'number' ? padding : expandToHashMap(padding, basePlacements));
2994
+ var altContext = elementContext === popper ? reference : popper;
2995
+ var popperRect = state.rects.popper;
2996
+ var element = state.elements[altBoundary ? altContext : elementContext];
2997
+ var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary, strategy);
2998
+ var referenceClientRect = getBoundingClientRect(state.elements.reference);
2999
+ var popperOffsets = computeOffsets({
3000
+ reference: referenceClientRect,
3001
+ element: popperRect,
3002
+ strategy: 'absolute',
3003
+ placement: placement
3004
+ });
3005
+ var popperClientRect = rectToClientRect(Object.assign({}, popperRect, popperOffsets));
3006
+ var elementClientRect = elementContext === popper ? popperClientRect : referenceClientRect; // positive = overflowing the clipping rect
3007
+ // 0 or negative = within the clipping rect
3008
+
3009
+ var overflowOffsets = {
3010
+ top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
3011
+ bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
3012
+ left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
3013
+ right: elementClientRect.right - clippingClientRect.right + paddingObject.right
3014
+ };
3015
+ var offsetData = state.modifiersData.offset; // Offsets can be applied only to the popper element
3016
+
3017
+ if (elementContext === popper && offsetData) {
3018
+ var offset = offsetData[placement];
3019
+ Object.keys(overflowOffsets).forEach(function (key) {
3020
+ var multiply = [right, bottom].indexOf(key) >= 0 ? 1 : -1;
3021
+ var axis = [top, bottom].indexOf(key) >= 0 ? 'y' : 'x';
3022
+ overflowOffsets[key] += offset[axis] * multiply;
3023
+ });
3024
+ }
3025
+
3026
+ return overflowOffsets;
3027
+ }
3028
+
3029
+ function computeAutoPlacement(state, options) {
3030
+ if (options === void 0) {
3031
+ options = {};
3032
+ }
3033
+
3034
+ var _options = options,
3035
+ placement = _options.placement,
3036
+ boundary = _options.boundary,
3037
+ rootBoundary = _options.rootBoundary,
3038
+ padding = _options.padding,
3039
+ flipVariations = _options.flipVariations,
3040
+ _options$allowedAutoP = _options.allowedAutoPlacements,
3041
+ allowedAutoPlacements = _options$allowedAutoP === void 0 ? placements : _options$allowedAutoP;
3042
+ var variation = getVariation(placement);
3043
+ var placements$1 = variation ? flipVariations ? variationPlacements : variationPlacements.filter(function (placement) {
3044
+ return getVariation(placement) === variation;
3045
+ }) : basePlacements;
3046
+ var allowedPlacements = placements$1.filter(function (placement) {
3047
+ return allowedAutoPlacements.indexOf(placement) >= 0;
3048
+ });
3049
+
3050
+ if (allowedPlacements.length === 0) {
3051
+ allowedPlacements = placements$1;
3052
+ } // $FlowFixMe[incompatible-type]: Flow seems to have problems with two array unions...
3053
+
3054
+
3055
+ var overflows = allowedPlacements.reduce(function (acc, placement) {
3056
+ acc[placement] = detectOverflow(state, {
3057
+ placement: placement,
3058
+ boundary: boundary,
3059
+ rootBoundary: rootBoundary,
3060
+ padding: padding
3061
+ })[getBasePlacement(placement)];
3062
+ return acc;
3063
+ }, {});
3064
+ return Object.keys(overflows).sort(function (a, b) {
3065
+ return overflows[a] - overflows[b];
3066
+ });
3067
+ }
3068
+
3069
+ function getExpandedFallbackPlacements(placement) {
3070
+ if (getBasePlacement(placement) === auto) {
3071
+ return [];
3072
+ }
3073
+
3074
+ var oppositePlacement = getOppositePlacement(placement);
3075
+ return [getOppositeVariationPlacement(placement), oppositePlacement, getOppositeVariationPlacement(oppositePlacement)];
3076
+ }
3077
+
3078
+ function flip(_ref) {
3079
+ var state = _ref.state,
3080
+ options = _ref.options,
3081
+ name = _ref.name;
3082
+
3083
+ if (state.modifiersData[name]._skip) {
3084
+ return;
3085
+ }
3086
+
3087
+ var _options$mainAxis = options.mainAxis,
3088
+ checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis,
3089
+ _options$altAxis = options.altAxis,
3090
+ checkAltAxis = _options$altAxis === void 0 ? true : _options$altAxis,
3091
+ specifiedFallbackPlacements = options.fallbackPlacements,
3092
+ padding = options.padding,
3093
+ boundary = options.boundary,
3094
+ rootBoundary = options.rootBoundary,
3095
+ altBoundary = options.altBoundary,
3096
+ _options$flipVariatio = options.flipVariations,
3097
+ flipVariations = _options$flipVariatio === void 0 ? true : _options$flipVariatio,
3098
+ allowedAutoPlacements = options.allowedAutoPlacements;
3099
+ var preferredPlacement = state.options.placement;
3100
+ var basePlacement = getBasePlacement(preferredPlacement);
3101
+ var isBasePlacement = basePlacement === preferredPlacement;
3102
+ var fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipVariations ? [getOppositePlacement(preferredPlacement)] : getExpandedFallbackPlacements(preferredPlacement));
3103
+ var placements = [preferredPlacement].concat(fallbackPlacements).reduce(function (acc, placement) {
3104
+ return acc.concat(getBasePlacement(placement) === auto ? computeAutoPlacement(state, {
3105
+ placement: placement,
3106
+ boundary: boundary,
3107
+ rootBoundary: rootBoundary,
3108
+ padding: padding,
3109
+ flipVariations: flipVariations,
3110
+ allowedAutoPlacements: allowedAutoPlacements
3111
+ }) : placement);
3112
+ }, []);
3113
+ var referenceRect = state.rects.reference;
3114
+ var popperRect = state.rects.popper;
3115
+ var checksMap = new Map();
3116
+ var makeFallbackChecks = true;
3117
+ var firstFittingPlacement = placements[0];
3118
+
3119
+ for (var i = 0; i < placements.length; i++) {
3120
+ var placement = placements[i];
3121
+
3122
+ var _basePlacement = getBasePlacement(placement);
3123
+
3124
+ var isStartVariation = getVariation(placement) === start;
3125
+ var isVertical = [top, bottom].indexOf(_basePlacement) >= 0;
3126
+ var len = isVertical ? 'width' : 'height';
3127
+ var overflow = detectOverflow(state, {
3128
+ placement: placement,
3129
+ boundary: boundary,
3130
+ rootBoundary: rootBoundary,
3131
+ altBoundary: altBoundary,
3132
+ padding: padding
3133
+ });
3134
+ var mainVariationSide = isVertical ? isStartVariation ? right : left : isStartVariation ? bottom : top;
3135
+
3136
+ if (referenceRect[len] > popperRect[len]) {
3137
+ mainVariationSide = getOppositePlacement(mainVariationSide);
3138
+ }
3139
+
3140
+ var altVariationSide = getOppositePlacement(mainVariationSide);
3141
+ var checks = [];
3142
+
3143
+ if (checkMainAxis) {
3144
+ checks.push(overflow[_basePlacement] <= 0);
3145
+ }
3146
+
3147
+ if (checkAltAxis) {
3148
+ checks.push(overflow[mainVariationSide] <= 0, overflow[altVariationSide] <= 0);
3149
+ }
3150
+
3151
+ if (checks.every(function (check) {
3152
+ return check;
3153
+ })) {
3154
+ firstFittingPlacement = placement;
3155
+ makeFallbackChecks = false;
3156
+ break;
3157
+ }
3158
+
3159
+ checksMap.set(placement, checks);
3160
+ }
3161
+
3162
+ if (makeFallbackChecks) {
3163
+ // `2` may be desired in some cases – research later
3164
+ var numberOfChecks = flipVariations ? 3 : 1;
3165
+
3166
+ var _loop = function _loop(_i) {
3167
+ var fittingPlacement = placements.find(function (placement) {
3168
+ var checks = checksMap.get(placement);
3169
+
3170
+ if (checks) {
3171
+ return checks.slice(0, _i).every(function (check) {
3172
+ return check;
3173
+ });
3174
+ }
3175
+ });
3176
+
3177
+ if (fittingPlacement) {
3178
+ firstFittingPlacement = fittingPlacement;
3179
+ return "break";
3180
+ }
3181
+ };
3182
+
3183
+ for (var _i = numberOfChecks; _i > 0; _i--) {
3184
+ var _ret = _loop(_i);
3185
+
3186
+ if (_ret === "break") break;
3187
+ }
3188
+ }
3189
+
3190
+ if (state.placement !== firstFittingPlacement) {
3191
+ state.modifiersData[name]._skip = true;
3192
+ state.placement = firstFittingPlacement;
3193
+ state.reset = true;
3194
+ }
3195
+ } // eslint-disable-next-line import/no-unused-modules
3196
+
3197
+
3198
+ var flip$1 = {
3199
+ name: 'flip',
3200
+ enabled: true,
3201
+ phase: 'main',
3202
+ fn: flip,
3203
+ requiresIfExists: ['offset'],
3204
+ data: {
3205
+ _skip: false
3206
+ }
3207
+ };
3208
+
3209
+ function getSideOffsets(overflow, rect, preventedOffsets) {
3210
+ if (preventedOffsets === void 0) {
3211
+ preventedOffsets = {
3212
+ x: 0,
3213
+ y: 0
3214
+ };
3215
+ }
3216
+
3217
+ return {
3218
+ top: overflow.top - rect.height - preventedOffsets.y,
3219
+ right: overflow.right - rect.width + preventedOffsets.x,
3220
+ bottom: overflow.bottom - rect.height + preventedOffsets.y,
3221
+ left: overflow.left - rect.width - preventedOffsets.x
3222
+ };
3223
+ }
3224
+
3225
+ function isAnySideFullyClipped(overflow) {
3226
+ return [top, right, bottom, left].some(function (side) {
3227
+ return overflow[side] >= 0;
3228
+ });
3229
+ }
3230
+
3231
+ function hide(_ref) {
3232
+ var state = _ref.state,
3233
+ name = _ref.name;
3234
+ var referenceRect = state.rects.reference;
3235
+ var popperRect = state.rects.popper;
3236
+ var preventedOffsets = state.modifiersData.preventOverflow;
3237
+ var referenceOverflow = detectOverflow(state, {
3238
+ elementContext: 'reference'
3239
+ });
3240
+ var popperAltOverflow = detectOverflow(state, {
3241
+ altBoundary: true
3242
+ });
3243
+ var referenceClippingOffsets = getSideOffsets(referenceOverflow, referenceRect);
3244
+ var popperEscapeOffsets = getSideOffsets(popperAltOverflow, popperRect, preventedOffsets);
3245
+ var isReferenceHidden = isAnySideFullyClipped(referenceClippingOffsets);
3246
+ var hasPopperEscaped = isAnySideFullyClipped(popperEscapeOffsets);
3247
+ state.modifiersData[name] = {
3248
+ referenceClippingOffsets: referenceClippingOffsets,
3249
+ popperEscapeOffsets: popperEscapeOffsets,
3250
+ isReferenceHidden: isReferenceHidden,
3251
+ hasPopperEscaped: hasPopperEscaped
3252
+ };
3253
+ state.attributes.popper = Object.assign({}, state.attributes.popper, {
3254
+ 'data-popper-reference-hidden': isReferenceHidden,
3255
+ 'data-popper-escaped': hasPopperEscaped
3256
+ });
3257
+ } // eslint-disable-next-line import/no-unused-modules
3258
+
3259
+
3260
+ var hide$1 = {
3261
+ name: 'hide',
3262
+ enabled: true,
3263
+ phase: 'main',
3264
+ requiresIfExists: ['preventOverflow'],
3265
+ fn: hide
3266
+ };
3267
+
3268
+ function distanceAndSkiddingToXY(placement, rects, offset) {
3269
+ var basePlacement = getBasePlacement(placement);
3270
+ var invertDistance = [left, top].indexOf(basePlacement) >= 0 ? -1 : 1;
3271
+
3272
+ var _ref = typeof offset === 'function' ? offset(Object.assign({}, rects, {
3273
+ placement: placement
3274
+ })) : offset,
3275
+ skidding = _ref[0],
3276
+ distance = _ref[1];
3277
+
3278
+ skidding = skidding || 0;
3279
+ distance = (distance || 0) * invertDistance;
3280
+ return [left, right].indexOf(basePlacement) >= 0 ? {
3281
+ x: distance,
3282
+ y: skidding
3283
+ } : {
3284
+ x: skidding,
3285
+ y: distance
3286
+ };
3287
+ }
3288
+
3289
+ function offset(_ref2) {
3290
+ var state = _ref2.state,
3291
+ options = _ref2.options,
3292
+ name = _ref2.name;
3293
+ var _options$offset = options.offset,
3294
+ offset = _options$offset === void 0 ? [0, 0] : _options$offset;
3295
+ var data = placements.reduce(function (acc, placement) {
3296
+ acc[placement] = distanceAndSkiddingToXY(placement, state.rects, offset);
3297
+ return acc;
3298
+ }, {});
3299
+ var _data$state$placement = data[state.placement],
3300
+ x = _data$state$placement.x,
3301
+ y = _data$state$placement.y;
3302
+
3303
+ if (state.modifiersData.popperOffsets != null) {
3304
+ state.modifiersData.popperOffsets.x += x;
3305
+ state.modifiersData.popperOffsets.y += y;
3306
+ }
3307
+
3308
+ state.modifiersData[name] = data;
3309
+ } // eslint-disable-next-line import/no-unused-modules
3310
+
3311
+
3312
+ var offset$1 = {
3313
+ name: 'offset',
3314
+ enabled: true,
3315
+ phase: 'main',
3316
+ requires: ['popperOffsets'],
3317
+ fn: offset
3318
+ };
3319
+
3320
+ function popperOffsets(_ref) {
3321
+ var state = _ref.state,
3322
+ name = _ref.name;
3323
+ // Offsets are the actual position the popper needs to have to be
3324
+ // properly positioned near its reference element
3325
+ // This is the most basic placement, and will be adjusted by
3326
+ // the modifiers in the next step
3327
+ state.modifiersData[name] = computeOffsets({
3328
+ reference: state.rects.reference,
3329
+ element: state.rects.popper,
3330
+ strategy: 'absolute',
3331
+ placement: state.placement
3332
+ });
3333
+ } // eslint-disable-next-line import/no-unused-modules
3334
+
3335
+
3336
+ var popperOffsets$1 = {
3337
+ name: 'popperOffsets',
3338
+ enabled: true,
3339
+ phase: 'read',
3340
+ fn: popperOffsets,
3341
+ data: {}
3342
+ };
3343
+
3344
+ function getAltAxis(axis) {
3345
+ return axis === 'x' ? 'y' : 'x';
3346
+ }
3347
+
3348
+ function preventOverflow(_ref) {
3349
+ var state = _ref.state,
3350
+ options = _ref.options,
3351
+ name = _ref.name;
3352
+ var _options$mainAxis = options.mainAxis,
3353
+ checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis,
3354
+ _options$altAxis = options.altAxis,
3355
+ checkAltAxis = _options$altAxis === void 0 ? false : _options$altAxis,
3356
+ boundary = options.boundary,
3357
+ rootBoundary = options.rootBoundary,
3358
+ altBoundary = options.altBoundary,
3359
+ padding = options.padding,
3360
+ _options$tether = options.tether,
3361
+ tether = _options$tether === void 0 ? true : _options$tether,
3362
+ _options$tetherOffset = options.tetherOffset,
3363
+ tetherOffset = _options$tetherOffset === void 0 ? 0 : _options$tetherOffset;
3364
+ var overflow = detectOverflow(state, {
3365
+ boundary: boundary,
3366
+ rootBoundary: rootBoundary,
3367
+ padding: padding,
3368
+ altBoundary: altBoundary
3369
+ });
3370
+ var basePlacement = getBasePlacement(state.placement);
3371
+ var variation = getVariation(state.placement);
3372
+ var isBasePlacement = !variation;
3373
+ var mainAxis = getMainAxisFromPlacement(basePlacement);
3374
+ var altAxis = getAltAxis(mainAxis);
3375
+ var popperOffsets = state.modifiersData.popperOffsets;
3376
+ var referenceRect = state.rects.reference;
3377
+ var popperRect = state.rects.popper;
3378
+ var tetherOffsetValue = typeof tetherOffset === 'function' ? tetherOffset(Object.assign({}, state.rects, {
3379
+ placement: state.placement
3380
+ })) : tetherOffset;
3381
+ var normalizedTetherOffsetValue = typeof tetherOffsetValue === 'number' ? {
3382
+ mainAxis: tetherOffsetValue,
3383
+ altAxis: tetherOffsetValue
3384
+ } : Object.assign({
3385
+ mainAxis: 0,
3386
+ altAxis: 0
3387
+ }, tetherOffsetValue);
3388
+ var offsetModifierState = state.modifiersData.offset ? state.modifiersData.offset[state.placement] : null;
3389
+ var data = {
3390
+ x: 0,
3391
+ y: 0
3392
+ };
3393
+
3394
+ if (!popperOffsets) {
3395
+ return;
3396
+ }
3397
+
3398
+ if (checkMainAxis) {
3399
+ var _offsetModifierState$;
3400
+
3401
+ var mainSide = mainAxis === 'y' ? top : left;
3402
+ var altSide = mainAxis === 'y' ? bottom : right;
3403
+ var len = mainAxis === 'y' ? 'height' : 'width';
3404
+ var offset = popperOffsets[mainAxis];
3405
+ var min$1 = offset + overflow[mainSide];
3406
+ var max$1 = offset - overflow[altSide];
3407
+ var additive = tether ? -popperRect[len] / 2 : 0;
3408
+ var minLen = variation === start ? referenceRect[len] : popperRect[len];
3409
+ var maxLen = variation === start ? -popperRect[len] : -referenceRect[len]; // We need to include the arrow in the calculation so the arrow doesn't go
3410
+ // outside the reference bounds
3411
+
3412
+ var arrowElement = state.elements.arrow;
3413
+ var arrowRect = tether && arrowElement ? getLayoutRect(arrowElement) : {
3414
+ width: 0,
3415
+ height: 0
3416
+ };
3417
+ var arrowPaddingObject = state.modifiersData['arrow#persistent'] ? state.modifiersData['arrow#persistent'].padding : getFreshSideObject();
3418
+ var arrowPaddingMin = arrowPaddingObject[mainSide];
3419
+ var arrowPaddingMax = arrowPaddingObject[altSide]; // If the reference length is smaller than the arrow length, we don't want
3420
+ // to include its full size in the calculation. If the reference is small
3421
+ // and near the edge of a boundary, the popper can overflow even if the
3422
+ // reference is not overflowing as well (e.g. virtual elements with no
3423
+ // width or height)
3424
+
3425
+ var arrowLen = within(0, referenceRect[len], arrowRect[len]);
3426
+ var minOffset = isBasePlacement ? referenceRect[len] / 2 - additive - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis : minLen - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis;
3427
+ var maxOffset = isBasePlacement ? -referenceRect[len] / 2 + additive + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis : maxLen + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis;
3428
+ var arrowOffsetParent = state.elements.arrow && getOffsetParent(state.elements.arrow);
3429
+ var clientOffset = arrowOffsetParent ? mainAxis === 'y' ? arrowOffsetParent.clientTop || 0 : arrowOffsetParent.clientLeft || 0 : 0;
3430
+ var offsetModifierValue = (_offsetModifierState$ = offsetModifierState == null ? void 0 : offsetModifierState[mainAxis]) != null ? _offsetModifierState$ : 0;
3431
+ var tetherMin = offset + minOffset - offsetModifierValue - clientOffset;
3432
+ var tetherMax = offset + maxOffset - offsetModifierValue;
3433
+ var preventedOffset = within(tether ? min(min$1, tetherMin) : min$1, offset, tether ? max(max$1, tetherMax) : max$1);
3434
+ popperOffsets[mainAxis] = preventedOffset;
3435
+ data[mainAxis] = preventedOffset - offset;
3436
+ }
3437
+
3438
+ if (checkAltAxis) {
3439
+ var _offsetModifierState$2;
3440
+
3441
+ var _mainSide = mainAxis === 'x' ? top : left;
3442
+
3443
+ var _altSide = mainAxis === 'x' ? bottom : right;
3444
+
3445
+ var _offset = popperOffsets[altAxis];
3446
+
3447
+ var _len = altAxis === 'y' ? 'height' : 'width';
3448
+
3449
+ var _min = _offset + overflow[_mainSide];
3450
+
3451
+ var _max = _offset - overflow[_altSide];
3452
+
3453
+ var isOriginSide = [top, left].indexOf(basePlacement) !== -1;
3454
+
3455
+ var _offsetModifierValue = (_offsetModifierState$2 = offsetModifierState == null ? void 0 : offsetModifierState[altAxis]) != null ? _offsetModifierState$2 : 0;
3456
+
3457
+ var _tetherMin = isOriginSide ? _min : _offset - referenceRect[_len] - popperRect[_len] - _offsetModifierValue + normalizedTetherOffsetValue.altAxis;
3458
+
3459
+ var _tetherMax = isOriginSide ? _offset + referenceRect[_len] + popperRect[_len] - _offsetModifierValue - normalizedTetherOffsetValue.altAxis : _max;
3460
+
3461
+ var _preventedOffset = tether && isOriginSide ? withinMaxClamp(_tetherMin, _offset, _tetherMax) : within(tether ? _tetherMin : _min, _offset, tether ? _tetherMax : _max);
3462
+
3463
+ popperOffsets[altAxis] = _preventedOffset;
3464
+ data[altAxis] = _preventedOffset - _offset;
3465
+ }
3466
+
3467
+ state.modifiersData[name] = data;
3468
+ } // eslint-disable-next-line import/no-unused-modules
3469
+
3470
+
3471
+ var preventOverflow$1 = {
3472
+ name: 'preventOverflow',
3473
+ enabled: true,
3474
+ phase: 'main',
3475
+ fn: preventOverflow,
3476
+ requiresIfExists: ['offset']
3477
+ };
3478
+
3479
+ function getHTMLElementScroll(element) {
3480
+ return {
3481
+ scrollLeft: element.scrollLeft,
3482
+ scrollTop: element.scrollTop
3483
+ };
3484
+ }
3485
+
3486
+ function getNodeScroll(node) {
3487
+ if (node === getWindow(node) || !isHTMLElement(node)) {
3488
+ return getWindowScroll(node);
3489
+ } else {
3490
+ return getHTMLElementScroll(node);
3491
+ }
3492
+ }
3493
+
3494
+ function isElementScaled(element) {
3495
+ var rect = element.getBoundingClientRect();
3496
+ var scaleX = round(rect.width) / element.offsetWidth || 1;
3497
+ var scaleY = round(rect.height) / element.offsetHeight || 1;
3498
+ return scaleX !== 1 || scaleY !== 1;
3499
+ } // Returns the composite rect of an element relative to its offsetParent.
3500
+ // Composite means it takes into account transforms as well as layout.
3501
+
3502
+
3503
+ function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
3504
+ if (isFixed === void 0) {
3505
+ isFixed = false;
3506
+ }
3507
+
3508
+ var isOffsetParentAnElement = isHTMLElement(offsetParent);
3509
+ var offsetParentIsScaled = isHTMLElement(offsetParent) && isElementScaled(offsetParent);
3510
+ var documentElement = getDocumentElement(offsetParent);
3511
+ var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled, isFixed);
3512
+ var scroll = {
3513
+ scrollLeft: 0,
3514
+ scrollTop: 0
3515
+ };
3516
+ var offsets = {
3517
+ x: 0,
3518
+ y: 0
3519
+ };
3520
+
3521
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
3522
+ if (getNodeName(offsetParent) !== 'body' || // https://github.com/popperjs/popper-core/issues/1078
3523
+ isScrollParent(documentElement)) {
3524
+ scroll = getNodeScroll(offsetParent);
3525
+ }
3526
+
3527
+ if (isHTMLElement(offsetParent)) {
3528
+ offsets = getBoundingClientRect(offsetParent, true);
3529
+ offsets.x += offsetParent.clientLeft;
3530
+ offsets.y += offsetParent.clientTop;
3531
+ } else if (documentElement) {
3532
+ offsets.x = getWindowScrollBarX(documentElement);
3533
+ }
3534
+ }
3535
+
3536
+ return {
3537
+ x: rect.left + scroll.scrollLeft - offsets.x,
3538
+ y: rect.top + scroll.scrollTop - offsets.y,
3539
+ width: rect.width,
3540
+ height: rect.height
3541
+ };
3542
+ }
3543
+
3544
+ function order(modifiers) {
3545
+ var map = new Map();
3546
+ var visited = new Set();
3547
+ var result = [];
3548
+ modifiers.forEach(function (modifier) {
3549
+ map.set(modifier.name, modifier);
3550
+ }); // On visiting object, check for its dependencies and visit them recursively
3551
+
3552
+ function sort(modifier) {
3553
+ visited.add(modifier.name);
3554
+ var requires = [].concat(modifier.requires || [], modifier.requiresIfExists || []);
3555
+ requires.forEach(function (dep) {
3556
+ if (!visited.has(dep)) {
3557
+ var depModifier = map.get(dep);
3558
+
3559
+ if (depModifier) {
3560
+ sort(depModifier);
3561
+ }
3562
+ }
3563
+ });
3564
+ result.push(modifier);
3565
+ }
3566
+
3567
+ modifiers.forEach(function (modifier) {
3568
+ if (!visited.has(modifier.name)) {
3569
+ // check for visited object
3570
+ sort(modifier);
3571
+ }
3572
+ });
3573
+ return result;
3574
+ }
3575
+
3576
+ function orderModifiers(modifiers) {
3577
+ // order based on dependencies
3578
+ var orderedModifiers = order(modifiers); // order based on phase
3579
+
3580
+ return modifierPhases.reduce(function (acc, phase) {
3581
+ return acc.concat(orderedModifiers.filter(function (modifier) {
3582
+ return modifier.phase === phase;
3583
+ }));
3584
+ }, []);
3585
+ }
3586
+
3587
+ function debounce(fn) {
3588
+ var pending;
3589
+ return function () {
3590
+ if (!pending) {
3591
+ pending = new Promise(function (resolve) {
3592
+ Promise.resolve().then(function () {
3593
+ pending = undefined;
3594
+ resolve(fn());
3595
+ });
3596
+ });
3597
+ }
3598
+
3599
+ return pending;
3600
+ };
3601
+ }
3602
+
3603
+ function mergeByName(modifiers) {
3604
+ var merged = modifiers.reduce(function (merged, current) {
3605
+ var existing = merged[current.name];
3606
+ merged[current.name] = existing ? Object.assign({}, existing, current, {
3607
+ options: Object.assign({}, existing.options, current.options),
3608
+ data: Object.assign({}, existing.data, current.data)
3609
+ }) : current;
3610
+ return merged;
3611
+ }, {}); // IE11 does not support Object.values
3612
+
3613
+ return Object.keys(merged).map(function (key) {
3614
+ return merged[key];
3615
+ });
3616
+ }
3617
+
3618
+ var DEFAULT_OPTIONS = {
3619
+ placement: 'bottom',
3620
+ modifiers: [],
3621
+ strategy: 'absolute'
3622
+ };
3623
+
3624
+ function areValidElements() {
3625
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3626
+ args[_key] = arguments[_key];
3627
+ }
3628
+
3629
+ return !args.some(function (element) {
3630
+ return !(element && typeof element.getBoundingClientRect === 'function');
3631
+ });
3632
+ }
3633
+
3634
+ function popperGenerator(generatorOptions) {
3635
+ if (generatorOptions === void 0) {
3636
+ generatorOptions = {};
3637
+ }
3638
+
3639
+ var _generatorOptions = generatorOptions,
3640
+ _generatorOptions$def = _generatorOptions.defaultModifiers,
3641
+ defaultModifiers = _generatorOptions$def === void 0 ? [] : _generatorOptions$def,
3642
+ _generatorOptions$def2 = _generatorOptions.defaultOptions,
3643
+ defaultOptions = _generatorOptions$def2 === void 0 ? DEFAULT_OPTIONS : _generatorOptions$def2;
3644
+ return function createPopper(reference, popper, options) {
3645
+ if (options === void 0) {
3646
+ options = defaultOptions;
3647
+ }
3648
+
3649
+ var state = {
3650
+ placement: 'bottom',
3651
+ orderedModifiers: [],
3652
+ options: Object.assign({}, DEFAULT_OPTIONS, defaultOptions),
3653
+ modifiersData: {},
3654
+ elements: {
3655
+ reference: reference,
3656
+ popper: popper
3657
+ },
3658
+ attributes: {},
3659
+ styles: {}
3660
+ };
3661
+ var effectCleanupFns = [];
3662
+ var isDestroyed = false;
3663
+ var instance = {
3664
+ state: state,
3665
+ setOptions: function setOptions(setOptionsAction) {
3666
+ var options = typeof setOptionsAction === 'function' ? setOptionsAction(state.options) : setOptionsAction;
3667
+ cleanupModifierEffects();
3668
+ state.options = Object.assign({}, defaultOptions, state.options, options);
3669
+ state.scrollParents = {
3670
+ reference: isElement(reference) ? listScrollParents(reference) : reference.contextElement ? listScrollParents(reference.contextElement) : [],
3671
+ popper: listScrollParents(popper)
3672
+ }; // Orders the modifiers based on their dependencies and `phase`
3673
+ // properties
3674
+
3675
+ var orderedModifiers = orderModifiers(mergeByName([].concat(defaultModifiers, state.options.modifiers))); // Strip out disabled modifiers
3676
+
3677
+ state.orderedModifiers = orderedModifiers.filter(function (m) {
3678
+ return m.enabled;
3679
+ });
3680
+ runModifierEffects();
3681
+ return instance.update();
3682
+ },
3683
+ // Sync update – it will always be executed, even if not necessary. This
3684
+ // is useful for low frequency updates where sync behavior simplifies the
3685
+ // logic.
3686
+ // For high frequency updates (e.g. `resize` and `scroll` events), always
3687
+ // prefer the async Popper#update method
3688
+ forceUpdate: function forceUpdate() {
3689
+ if (isDestroyed) {
3690
+ return;
3691
+ }
3692
+
3693
+ var _state$elements = state.elements,
3694
+ reference = _state$elements.reference,
3695
+ popper = _state$elements.popper; // Don't proceed if `reference` or `popper` are not valid elements
3696
+ // anymore
3697
+
3698
+ if (!areValidElements(reference, popper)) {
3699
+ return;
3700
+ } // Store the reference and popper rects to be read by modifiers
3701
+
3702
+
3703
+ state.rects = {
3704
+ reference: getCompositeRect(reference, getOffsetParent(popper), state.options.strategy === 'fixed'),
3705
+ popper: getLayoutRect(popper)
3706
+ }; // Modifiers have the ability to reset the current update cycle. The
3707
+ // most common use case for this is the `flip` modifier changing the
3708
+ // placement, which then needs to re-run all the modifiers, because the
3709
+ // logic was previously ran for the previous placement and is therefore
3710
+ // stale/incorrect
3711
+
3712
+ state.reset = false;
3713
+ state.placement = state.options.placement; // On each update cycle, the `modifiersData` property for each modifier
3714
+ // is filled with the initial data specified by the modifier. This means
3715
+ // it doesn't persist and is fresh on each update.
3716
+ // To ensure persistent data, use `${name}#persistent`
3717
+
3718
+ state.orderedModifiers.forEach(function (modifier) {
3719
+ return state.modifiersData[modifier.name] = Object.assign({}, modifier.data);
3720
+ });
3721
+
3722
+ for (var index = 0; index < state.orderedModifiers.length; index++) {
3723
+ if (state.reset === true) {
3724
+ state.reset = false;
3725
+ index = -1;
3726
+ continue;
3727
+ }
3728
+
3729
+ var _state$orderedModifie = state.orderedModifiers[index],
3730
+ fn = _state$orderedModifie.fn,
3731
+ _state$orderedModifie2 = _state$orderedModifie.options,
3732
+ _options = _state$orderedModifie2 === void 0 ? {} : _state$orderedModifie2,
3733
+ name = _state$orderedModifie.name;
3734
+
3735
+ if (typeof fn === 'function') {
3736
+ state = fn({
3737
+ state: state,
3738
+ options: _options,
3739
+ name: name,
3740
+ instance: instance
3741
+ }) || state;
3742
+ }
3743
+ }
3744
+ },
3745
+ // Async and optimistically optimized update – it will not be executed if
3746
+ // not necessary (debounced to run at most once-per-tick)
3747
+ update: debounce(function () {
3748
+ return new Promise(function (resolve) {
3749
+ instance.forceUpdate();
3750
+ resolve(state);
3751
+ });
3752
+ }),
3753
+ destroy: function destroy() {
3754
+ cleanupModifierEffects();
3755
+ isDestroyed = true;
3756
+ }
3757
+ };
3758
+
3759
+ if (!areValidElements(reference, popper)) {
3760
+ return instance;
3761
+ }
3762
+
3763
+ instance.setOptions(options).then(function (state) {
3764
+ if (!isDestroyed && options.onFirstUpdate) {
3765
+ options.onFirstUpdate(state);
3766
+ }
3767
+ }); // Modifiers have the ability to execute arbitrary code before the first
3768
+ // update cycle runs. They will be executed in the same order as the update
3769
+ // cycle. This is useful when a modifier adds some persistent data that
3770
+ // other modifiers need to use, but the modifier is run after the dependent
3771
+ // one.
3772
+
3773
+ function runModifierEffects() {
3774
+ state.orderedModifiers.forEach(function (_ref) {
3775
+ var name = _ref.name,
3776
+ _ref$options = _ref.options,
3777
+ options = _ref$options === void 0 ? {} : _ref$options,
3778
+ effect = _ref.effect;
3779
+
3780
+ if (typeof effect === 'function') {
3781
+ var cleanupFn = effect({
3782
+ state: state,
3783
+ name: name,
3784
+ instance: instance,
3785
+ options: options
3786
+ });
3787
+
3788
+ var noopFn = function noopFn() {};
3789
+
3790
+ effectCleanupFns.push(cleanupFn || noopFn);
3791
+ }
3792
+ });
3793
+ }
3794
+
3795
+ function cleanupModifierEffects() {
3796
+ effectCleanupFns.forEach(function (fn) {
3797
+ return fn();
3798
+ });
3799
+ effectCleanupFns = [];
3800
+ }
3801
+
3802
+ return instance;
3803
+ };
3804
+ }
3805
+
3806
+ var defaultModifiers = [eventListeners, popperOffsets$1, computeStyles$1, applyStyles$1, offset$1, flip$1, preventOverflow$1, arrow$1, hide$1];
3807
+ var createPopper = /*#__PURE__*/popperGenerator({
3808
+ defaultModifiers: defaultModifiers
3809
+ }); // eslint-disable-next-line import/no-unused-modules
3810
+
3811
+ async function deregister(obj) {
3812
+ // Return collection if nothing was passed.
3813
+ if (!obj) return this.collection;
3814
+
3815
+ // Check if entry has been registered in the collection.
3816
+ const index = this.collection.findIndex(entry => {
3817
+ return entry.id === obj.id;
3818
+ });
3819
+ if (index >= 0) {
3820
+ // Get the collection entry.
3821
+ const entry = this.collection[index];
3822
+
3823
+ // If entry is in the opened state, close it.
3824
+ if (entry.state === "opened") {
3825
+ entry.close();
3826
+ }
3827
+
3828
+ // Clean up the popper instance.
3829
+ entry.popper.destroy();
3830
+
3831
+ // Remove event listeners.
3832
+ deregisterEventListeners(entry);
3833
+
3834
+ // Delete properties from collection entry.
3835
+ Object.getOwnPropertyNames(entry).forEach(prop => {
3836
+ delete entry[prop];
3837
+ });
3838
+
3839
+ // Remove entry from collection.
3840
+ this.collection.splice(index, 1);
3841
+ }
3842
+
3843
+ // Return the modified collection.
3844
+ return this.collection;
3845
+ }
3846
+ function deregisterEventListeners(entry) {
3847
+ // If event listeners have been setup.
3848
+ if (entry.__eventListeners) {
3849
+ // Loop through listeners and remove from the appropriate elements.
3850
+ entry.__eventListeners.forEach(evObj => {
3851
+ evObj.el.forEach(el => {
3852
+ evObj.type.forEach(type => {
3853
+ entry[el].removeEventListener(type, evObj.listener, false);
3854
+ });
3855
+ });
3856
+ });
3857
+
3858
+ // Remove eventListeners object from collection.
3859
+ delete entry.__eventListeners;
3860
+ }
3861
+
3862
+ // Return the entry object.
3863
+ return entry;
3864
+ }
3865
+
3866
+ async function open(query) {
3867
+ // Get the popover from collection.
3868
+ const popover = getPopover.call(this, query);
3869
+
3870
+ // Update state class.
3871
+ popover.el.classList.add(this.settings.stateActive);
3872
+
3873
+ // Update accessibility attribute(s).
3874
+ if (popover.trigger.hasAttribute("aria-controls")) {
3875
+ popover.trigger.setAttribute("aria-expanded", "true");
3876
+ }
3877
+
3878
+ // Update popover config.
3879
+ popover.config = getConfig(popover.el, this.settings);
3880
+
3881
+ // Enable popper event listeners and set placement/modifiers.
3882
+ popover.popper.setOptions({
3883
+ placement: popover.config["placement"],
3884
+ modifiers: [{
3885
+ name: "eventListeners",
3886
+ enabled: true
3887
+ }, ...getModifiers(popover.config)]
3888
+ });
3889
+
3890
+ // Update popover position.
3891
+ popover.popper.update();
3892
+
3893
+ // Update popover state.
3894
+ popover.state = "opened";
3895
+
3896
+ // Return the popover.
3897
+ return popover;
3898
+ }
3899
+
3900
+ async function register(el, trigger) {
3901
+ // Deregister entry incase it has already been registered.
3902
+ deregister.call(this, el);
3903
+
3904
+ // Save root this for use inside methods API.
3905
+ const root = this;
3906
+
3907
+ // Setup methods API.
3908
+ const methods = {
3909
+ open() {
3910
+ return open.call(root, this);
3911
+ },
3912
+ close() {
3913
+ return close.call(root, this);
3914
+ },
3915
+ deregister() {
3916
+ return deregister.call(root, this);
3917
+ }
3918
+ };
3919
+
3920
+ // Setup the popover object.
3921
+ const entry = _extends({
3922
+ id: el.id,
3923
+ state: "closed",
3924
+ el: el,
3925
+ trigger: trigger,
3926
+ popper: createPopper(trigger, el),
3927
+ config: getConfig(el, this.settings)
3928
+ }, methods);
3929
+
3930
+ // Set aria-expanded to false if trigger has aria-controls attribute.
3931
+ if (entry.trigger.hasAttribute("aria-controls")) {
3932
+ entry.trigger.setAttribute("aria-expanded", "false");
3933
+ }
3934
+
3935
+ // Setup event listeners.
3936
+ registerEventListeners.call(this, entry);
3937
+
3938
+ // Add entry to collection.
3939
+ this.collection.push(entry);
3940
+
3941
+ // Set initial state.
3942
+ if (entry.el.classList.contains(this.settings.stateActive)) {
3943
+ await entry.open();
3944
+ handleDocumentClick.call(this, entry);
3945
+ }
3946
+
3947
+ // Return the registered entry.
3948
+ return entry;
3949
+ }
3950
+ function registerEventListeners(entry) {
3951
+ // If event listeners aren't already setup.
3952
+ if (!entry.__eventListeners) {
3953
+ // Add event listeners based on event type.
3954
+ const eventType = entry.config["event"];
3955
+
3956
+ // If the event type is hover.
3957
+ if (eventType === "hover") {
3958
+ // Setup event listeners object for hover.
3959
+ entry.__eventListeners = [{
3960
+ el: ["trigger"],
3961
+ type: ["mouseenter", "focus"],
3962
+ listener: open.bind(this, entry)
3963
+ }, {
3964
+ el: ["el", "trigger"],
3965
+ type: ["mouseleave", "focusout"],
3966
+ listener: closeCheck.bind(this, entry)
3967
+ }];
3968
+
3969
+ // Loop through listeners and apply to the appropriate elements.
3970
+ entry.__eventListeners.forEach(evObj => {
3971
+ evObj.el.forEach(el => {
3972
+ evObj.type.forEach(type => {
3973
+ entry[el].addEventListener(type, evObj.listener, false);
3974
+ });
3975
+ });
3976
+ });
3977
+ }
3978
+
3979
+ // Else the event type is click.
3980
+ else {
3981
+ // Setup event listeners object for click.
3982
+ entry.__eventListeners = [{
3983
+ el: ["trigger"],
3984
+ type: ["click"],
3985
+ listener: handleClick.bind(this, entry)
3986
+ }];
3987
+
3988
+ // Loop through listeners and apply to the appropriate elements.
3989
+ entry.__eventListeners.forEach(evObj => {
3990
+ evObj.el.forEach(el => {
3991
+ evObj.type.forEach(type => {
3992
+ entry[el].addEventListener(type, evObj.listener, false);
3993
+ });
3994
+ });
3995
+ });
3996
+ }
3997
+ }
3998
+
3999
+ // Return the entry object.
4000
+ return entry;
4001
+ }
4002
+
4003
+ var _handleKeydown = /*#__PURE__*/_classPrivateFieldLooseKey("handleKeydown");
4004
+ class Popover extends Collection {
4005
+ constructor(options) {
4006
+ super();
4007
+ Object.defineProperty(this, _handleKeydown, {
4008
+ writable: true,
4009
+ value: void 0
4010
+ });
4011
+ this.defaults = defaults;
4012
+ this.settings = _extends({}, this.defaults, options);
4013
+ this.trigger = null;
4014
+ _classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown] = handleKeydown.bind(this);
4015
+ if (this.settings.autoInit) this.init();
4016
+ }
4017
+ async init(options) {
4018
+ // Update settings with passed options.
4019
+ if (options) this.settings = _extends({}, this.settings, options);
4020
+
4021
+ // Get all the popovers.
4022
+ const popovers = document.querySelectorAll(this.settings.selectorPopover);
4023
+
4024
+ // Register the collections array with popover instances.
4025
+ await this.registerCollection(popovers);
4026
+
4027
+ // If eventListeners are enabled, init event listeners.
4028
+ if (this.settings.eventListeners) {
4029
+ // Pass false to initEventListeners() since registerCollection()
4030
+ // already adds event listeners to popovers.
4031
+ this.initEventListeners(false);
4032
+ }
4033
+ return this;
4034
+ }
4035
+ async destroy() {
4036
+ // Clear stored trigger.
4037
+ this.trigger = null;
4038
+
4039
+ // Remove all entries from the collection.
4040
+ await this.deregisterCollection();
4041
+
4042
+ // If eventListeners are enabled, destroy event listeners.
4043
+ if (this.settings.eventListeners) {
4044
+ // Pass false to destroyEventListeners() since deregisterCollection()
4045
+ // already removes event listeners from popovers.
4046
+ this.destroyEventListeners(false);
4047
+ }
4048
+ return this;
4049
+ }
4050
+ initEventListeners(processCollection = true) {
4051
+ if (processCollection) {
4052
+ // Loop through collection and setup event listeners.
4053
+ this.collection.forEach(popover => {
4054
+ registerEventListeners.call(this, popover);
4055
+ });
4056
+ }
4057
+
4058
+ // Add keydown global event listener.
4059
+ document.addEventListener("keydown", _classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown], false);
4060
+ }
4061
+ destroyEventListeners(processCollection = true) {
4062
+ if (processCollection) {
4063
+ // Loop through collection and remove event listeners.
4064
+ this.collection.forEach(popover => {
4065
+ deregisterEventListeners(popover);
4066
+ });
4067
+ }
4068
+
4069
+ // Remove keydown global event listener.
4070
+ document.removeEventListener("keydown", _classPrivateFieldLooseBase(this, _handleKeydown)[_handleKeydown], false);
4071
+ }
4072
+ register(query) {
4073
+ const els = getPopoverElements.call(this, query);
4074
+ if (els.error) return Promise.reject(els.error);
4075
+ return register.call(this, els.popover, els.trigger);
4076
+ }
4077
+ deregister(query) {
4078
+ const popover = this.get(getPopoverID.call(this, query));
4079
+ return deregister.call(this, popover);
4080
+ }
4081
+ open(id) {
4082
+ return open.call(this, id);
4083
+ }
4084
+ close(id) {
4085
+ return close.call(this, id);
4086
+ }
4087
+ }
4088
+
4089
+ export { Checkbox, Drawer, Modal, Popover, index as core };
4090
+ //# sourceMappingURL=scripts.modern.mjs.map