vrembem 3.0.18 → 3.0.19

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