vrembem 3.0.18 → 3.0.20

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