vrembem 4.0.0-next.25 → 4.0.0-next.27

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.
package/dev/index.js CHANGED
@@ -5,7 +5,126 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
5
5
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
6
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
7
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
- var _handler, _focusable, _handleFocusTrap, _handleFocusLock, _handleClick, _handleKeydown, _handleClick2, _handleKeydown2, _handleKeydown3;
8
+ var _handler, _focusable, _handleFocusTrap, _handleFocusLock, _mode, _state, _breakpoint, _handleClick, _handleKeydown, _handleClick2, _handleKeydown2, _eventListeners, _isHovered, _handleKeydown3;
9
+ function toCamel(value) {
10
+ return value.split("-").map((word, index2) => index2 === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1)).join("");
11
+ }
12
+ function toKebab(value) {
13
+ return value.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
14
+ }
15
+ function toMilliseconds(value) {
16
+ if (typeof value === "number") {
17
+ return value;
18
+ }
19
+ const parsed = parseFloat(value);
20
+ if (!Number.isNaN(parsed)) {
21
+ const isMilliseconds = value.includes("ms");
22
+ return parsed * (isMilliseconds ? 1 : 1e3);
23
+ }
24
+ throw new Error(`Could not convert value to milliseconds: ${value}`);
25
+ }
26
+ function getPrefix() {
27
+ return getComputedStyle(document.body).getPropertyValue("--vb-prefix").trim();
28
+ }
29
+ function cssVar(property, options) {
30
+ const settings = {
31
+ fallback: null,
32
+ element: document.body,
33
+ ...options
34
+ };
35
+ if (property.slice(0, 2) !== "--") {
36
+ const prefixValue = getPrefix();
37
+ if (prefixValue) {
38
+ property = `${prefixValue}${property}`;
39
+ }
40
+ property = `--${property}`;
41
+ }
42
+ const cssValue = getComputedStyle(settings.element).getPropertyValue(property).trim();
43
+ if (cssValue) {
44
+ return cssValue;
45
+ } else {
46
+ if (settings.fallback) {
47
+ return settings.fallback;
48
+ } else {
49
+ throw new Error(`CSS variable "${property}" was not found!`);
50
+ }
51
+ }
52
+ }
53
+ function getConfig(el, dataConfig = "config") {
54
+ const string = el.getAttribute(`data-${dataConfig}`) || "";
55
+ const json = string.replace(/'/g, '"');
56
+ return json ? JSON.parse(json) : {};
57
+ }
58
+ function getCustomProps(entry) {
59
+ const styles = getComputedStyle(entry.el);
60
+ const result = {};
61
+ const keys = Object.keys(entry.context.settings);
62
+ for (let i = 0; i < keys.length; i++) {
63
+ const prefix = getPrefix();
64
+ const module = entry.context.module.toLowerCase();
65
+ const key = toKebab(keys[i]);
66
+ const value = styles.getPropertyValue(`--${prefix}${module}-${key}`).trim();
67
+ if (value) {
68
+ result[key] = value;
69
+ }
70
+ }
71
+ return result;
72
+ }
73
+ function getElement(query) {
74
+ if (typeof query === "string") {
75
+ return document.getElementById(query);
76
+ } else if (query instanceof HTMLElement) {
77
+ return query;
78
+ } else {
79
+ return null;
80
+ }
81
+ }
82
+ async function lifecycleHook(name, ...args) {
83
+ if (name in this && typeof this[name] === "function") {
84
+ await this[name](...args);
85
+ }
86
+ }
87
+ function transition(el, init, interim, final, duration = 0) {
88
+ return new Promise((resolve) => {
89
+ el.classList.remove(init);
90
+ el.classList.add(interim);
91
+ setTimeout(() => {
92
+ el.classList.add(final);
93
+ el.classList.remove(interim);
94
+ resolve(el);
95
+ }, toMilliseconds(duration));
96
+ });
97
+ }
98
+ function setOverflowHidden(state, selector) {
99
+ if (selector) {
100
+ const els = document.querySelectorAll(selector);
101
+ els.forEach((el) => {
102
+ if (state) {
103
+ el.style.overflow = "hidden";
104
+ } else {
105
+ el.style.removeProperty("overflow");
106
+ }
107
+ });
108
+ }
109
+ }
110
+ function setInert(state, selector) {
111
+ if (selector) {
112
+ const els = document.querySelectorAll(selector);
113
+ els.forEach((el) => {
114
+ if (state) {
115
+ el.inert = true;
116
+ el.setAttribute("aria-hidden", true);
117
+ } else {
118
+ el.inert = null;
119
+ el.removeAttribute("aria-hidden");
120
+ }
121
+ });
122
+ }
123
+ }
124
+ function setGlobalState(state, selectorInert, selectorOverflow) {
125
+ setInert(!!state, selectorInert);
126
+ setOverflowHidden(!!state, selectorOverflow);
127
+ }
9
128
  class Breakpoint {
10
129
  constructor(value, handler) {
11
130
  __privateAdd(this, _handler);
@@ -43,43 +162,145 @@ class Breakpoint {
43
162
  }
44
163
  _handler = new WeakMap();
45
164
  class Collection {
46
- constructor() {
165
+ constructor(options = {}) {
166
+ this.module = this.constructor.name;
47
167
  this.collection = [];
168
+ this.settings = Object.assign({
169
+ dataConfig: "config",
170
+ teleport: null,
171
+ teleportMethod: "append"
172
+ }, options);
48
173
  }
49
- async register(item) {
50
- await this.deregister(item);
51
- this.collection.push(item);
52
- return this.collection;
174
+ get(value, key = "id") {
175
+ return this.collection.find((entry) => entry[key] === value);
176
+ }
177
+ applySettings(obj) {
178
+ return Object.assign(this.settings, obj);
179
+ }
180
+ async createEntry(query, config) {
181
+ return new CollectionEntry(this, query, config);
182
+ }
183
+ async register(query, config = {}) {
184
+ await this.deregister((query == null ? void 0 : query.id) || query, true);
185
+ const entry = await this.createEntry(query, config);
186
+ await entry.mount();
187
+ await lifecycleHook.call(this, "beforeRegister", entry);
188
+ await lifecycleHook.call(entry, "beforeRegister");
189
+ this.collection.push(entry);
190
+ await lifecycleHook.call(entry, "afterRegister");
191
+ await lifecycleHook.call(this, "afterRegister", entry);
192
+ return entry;
53
193
  }
54
- async deregister(ref) {
55
- const index2 = this.collection.findIndex((entry) => {
56
- return entry === ref;
57
- });
58
- if (index2 >= 0) {
194
+ async deregister(id, reReg = false) {
195
+ const index2 = this.collection.findIndex((entry) => entry.id === id);
196
+ if (~index2) {
59
197
  const entry = this.collection[index2];
198
+ await entry.unmount(reReg);
199
+ await lifecycleHook.call(this, "beforeDeregister", entry);
200
+ await lifecycleHook.call(entry, "beforeDeregister", reReg);
60
201
  Object.getOwnPropertyNames(entry).forEach((prop) => {
61
- delete entry[prop];
202
+ if (prop != "beforeDeregister" && prop != "afterDeregister") {
203
+ delete entry[prop];
204
+ }
62
205
  });
63
206
  this.collection.splice(index2, 1);
207
+ await lifecycleHook.call(entry, "afterDeregister", reReg);
208
+ await lifecycleHook.call(this, "afterDeregister", entry);
64
209
  }
65
210
  return this.collection;
66
211
  }
67
- async registerCollection(items) {
68
- await Promise.all(Array.from(items, (item) => {
69
- this.register(item);
70
- }));
71
- return this.collection;
212
+ async mount(options = {}) {
213
+ this.applySettings(options);
214
+ await lifecycleHook.call(this, "beforeMount");
215
+ const els = document.querySelectorAll(this.settings.selector);
216
+ for (const el of els) {
217
+ await this.register(el);
218
+ }
219
+ await lifecycleHook.call(this, "afterMount");
220
+ return this;
72
221
  }
73
- async deregisterCollection() {
222
+ async unmount() {
223
+ await lifecycleHook.call(this, "beforeUnmount");
74
224
  while (this.collection.length > 0) {
75
- await this.deregister(this.collection[0]);
225
+ await this.deregister(this.collection[0].id);
76
226
  }
77
- return this.collection;
227
+ await lifecycleHook.call(this, "afterUnmount");
228
+ return this;
78
229
  }
79
- get(value, key = "id") {
80
- return this.collection.find((item) => {
81
- return item[key] === value;
82
- });
230
+ }
231
+ class CollectionEntry {
232
+ constructor(context, query, options = {}) {
233
+ this.context = context;
234
+ this.id = (query == null ? void 0 : query.id) || query;
235
+ this.el = getElement(query);
236
+ this.settings = Object.assign({}, options);
237
+ this.dataConfig = {};
238
+ this.customProps = {};
239
+ this.returnRef = null;
240
+ }
241
+ applySettings(obj) {
242
+ return Object.assign(this.settings, obj);
243
+ }
244
+ getDataConfig() {
245
+ return Object.assign(this.dataConfig, getConfig(this.el, this.getSetting("dataConfig")));
246
+ }
247
+ getCustomProps() {
248
+ return Object.assign(this.customProps, getCustomProps(this));
249
+ }
250
+ getSetting(key) {
251
+ const camel = toCamel(key);
252
+ const kebab = toKebab(key);
253
+ if ("dataConfig" in this && camel in this.dataConfig) {
254
+ return this.dataConfig[camel];
255
+ }
256
+ if ("customProps" in this && kebab in this.customProps) {
257
+ return this.customProps[kebab];
258
+ }
259
+ if ("settings" in this && camel in this.settings) {
260
+ return this.settings[camel];
261
+ }
262
+ if ("settings" in this.context && camel in this.context.settings) {
263
+ return this.context.settings[camel];
264
+ }
265
+ throw new Error(`${this.context.module} setting does not exist: ${key}`);
266
+ }
267
+ async mount(options = {}) {
268
+ if (this.el === null) {
269
+ throw new Error(`${this.context.module} element was not found with ID: "${this.id}"`);
270
+ }
271
+ this.applySettings(options);
272
+ this.getDataConfig();
273
+ this.getCustomProps();
274
+ await lifecycleHook.call(this, "beforeMount");
275
+ if (this.getSetting("teleport")) {
276
+ this.teleport();
277
+ }
278
+ await lifecycleHook.call(this, "afterMount");
279
+ }
280
+ async unmount(reMount = false) {
281
+ await lifecycleHook.call(this, "beforeUnmount", reMount);
282
+ if (this.getSetting("teleport")) {
283
+ this.teleportReturn();
284
+ }
285
+ await lifecycleHook.call(this, "afterUnmount", reMount);
286
+ }
287
+ teleport(ref = this.getSetting("teleport"), method = this.getSetting("teleportMethod")) {
288
+ if (!this.returnRef) {
289
+ this.returnRef = teleport(this.el, ref, method);
290
+ return this.el;
291
+ } else {
292
+ console.error("Element has already been teleported:", this.el);
293
+ return false;
294
+ }
295
+ }
296
+ teleportReturn() {
297
+ if (this.returnRef) {
298
+ this.returnRef = teleport(this.el, this.returnRef);
299
+ return this.el;
300
+ } else {
301
+ console.error("No return reference found:", this.el);
302
+ return false;
303
+ }
83
304
  }
84
305
  }
85
306
  class FocusTrap {
@@ -184,38 +405,6 @@ function handleFocusLock(event) {
184
405
  const isTab = event.key === "Tab" || event.keyCode === 9;
185
406
  if (isTab) event.preventDefault();
186
407
  }
187
- function getPrefix() {
188
- return getComputedStyle(document.body).getPropertyValue("--vb-prefix").trim();
189
- }
190
- function cssVar(property, options) {
191
- const settings = {
192
- fallback: null,
193
- element: document.body,
194
- ...options
195
- };
196
- if (property.slice(0, 2) !== "--") {
197
- const prefixValue = getPrefix();
198
- if (prefixValue) {
199
- property = `${prefixValue}${property}`;
200
- }
201
- property = `--${property}`;
202
- }
203
- const cssValue = getComputedStyle(settings.element).getPropertyValue(property).trim();
204
- if (cssValue) {
205
- return cssValue;
206
- } else {
207
- if (settings.fallback) {
208
- return settings.fallback;
209
- } else {
210
- throw new Error(`CSS variable "${property}" was not found!`);
211
- }
212
- }
213
- }
214
- function getConfig$1(el, dataConfig) {
215
- const string = el.getAttribute(`data-${dataConfig}`) || "";
216
- const json = string.replace(/'/g, '"');
217
- return json ? JSON.parse(json) : {};
218
- }
219
408
  function localStore(key, enable = true) {
220
409
  const local = localStorage.getItem(key);
221
410
  const store = local ? JSON.parse(local) : {};
@@ -319,76 +508,35 @@ function themeStore(options) {
319
508
  api.callback("onInit");
320
509
  return api;
321
510
  }
322
- function transition(el, from, to, duration = "transition-duration") {
323
- return new Promise((resolve) => {
324
- if (typeof duration === "string") {
325
- const cssValue = cssVar(duration, { element: el });
326
- const ms = cssValue.includes("ms") ? true : false;
327
- duration = parseFloat(cssValue) * (ms ? 1 : 1e3);
328
- }
329
- el.classList.remove(from.finish);
330
- el.classList.add(to.start);
331
- setTimeout(() => {
332
- el.classList.add(to.finish);
333
- el.classList.remove(to.start);
334
- resolve(el);
335
- }, duration);
336
- });
337
- }
338
- function setOverflowHidden(state, selector) {
339
- if (selector) {
340
- const els = document.querySelectorAll(selector);
341
- els.forEach((el) => {
342
- if (state) {
343
- el.style.overflow = "hidden";
344
- } else {
345
- el.style.removeProperty("overflow");
346
- }
347
- });
348
- }
349
- }
350
- function setInert(state, selector) {
351
- if (selector) {
352
- const els = document.querySelectorAll(selector);
353
- els.forEach((el) => {
354
- if (state) {
355
- el.inert = true;
356
- el.setAttribute("aria-hidden", true);
357
- } else {
358
- el.inert = null;
359
- el.removeAttribute("aria-hidden");
360
- }
361
- });
362
- }
363
- }
364
- function updateGlobalState(state, config) {
365
- setInert(!!state, config.selectorInert);
366
- setOverflowHidden(!!state, config.selectorOverflow);
367
- }
368
511
  const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
369
512
  __proto__: null,
370
513
  Breakpoint,
371
514
  Collection,
515
+ CollectionEntry,
372
516
  FocusTrap,
373
517
  cssVar,
374
- getConfig: getConfig$1,
518
+ getConfig,
519
+ getCustomProps,
520
+ getElement,
375
521
  getPrefix,
522
+ lifecycleHook,
376
523
  localStore,
524
+ setGlobalState,
377
525
  teleport,
378
526
  themeStore,
379
- transition,
380
- updateGlobalState
527
+ toCamel,
528
+ toKebab,
529
+ toMilliseconds,
530
+ transition
381
531
  }, Symbol.toStringTag, { value: "Module" }));
382
532
  const defaults$2 = {
383
- autoMount: false,
384
533
  // Data attributes
385
534
  dataOpen: "drawer-open",
386
535
  dataClose: "drawer-close",
387
536
  dataToggle: "drawer-toggle",
388
537
  dataBreakpoint: "drawer-breakpoint",
389
- dataConfig: "drawer-config",
390
538
  // Selectors
391
- selectorDrawer: ".drawer",
539
+ selector: ".drawer",
392
540
  selectorDialog: ".drawer__dialog",
393
541
  selectorScreen: ".drawer",
394
542
  selectorFocus: "[data-focus]",
@@ -404,10 +552,11 @@ const defaults$2 = {
404
552
  // Feature toggles
405
553
  breakpoints: null,
406
554
  customEventPrefix: "drawer:",
407
- eventListeners: true,
408
555
  store: true,
409
556
  storeKey: "VB:DrawerState",
410
557
  setTabindex: true,
558
+ teleport: null,
559
+ teleportMethod: "prepend",
411
560
  transition: true,
412
561
  transitionDuration: "drawer-transition-duration"
413
562
  };
@@ -460,7 +609,7 @@ function getBreakpoint(drawer) {
460
609
  }
461
610
  }
462
611
  function getDrawer(query) {
463
- const entry = typeof query === "string" ? this.get(query) : this.get(query.id);
612
+ const entry = typeof query === "string" ? this.get(query) : query;
464
613
  if (entry) {
465
614
  return entry;
466
615
  } else {
@@ -482,6 +631,132 @@ function updateFocusState$1(entry) {
482
631
  this.focusTrap.unmount();
483
632
  }
484
633
  }
634
+ function switchMode(entry) {
635
+ switch (entry.mode) {
636
+ case "inline":
637
+ return toInline.call(this, entry);
638
+ case "modal":
639
+ return toModal.call(this, entry);
640
+ default:
641
+ throw new Error(`"${entry.mode}" is not a valid drawer mode.`);
642
+ }
643
+ }
644
+ async function toInline(entry) {
645
+ entry.el.classList.remove(entry.getSetting("classModal"));
646
+ entry.dialog.removeAttribute("aria-modal");
647
+ setGlobalState(false, entry.getSetting("selectorInert"), entry.getSetting("selectorOverflow"));
648
+ this.focusTrap.unmount();
649
+ await applyInlineState(entry);
650
+ entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "switchMode", {
651
+ detail: this,
652
+ bubbles: true
653
+ }));
654
+ return entry;
655
+ }
656
+ async function toModal(entry) {
657
+ entry.el.classList.add(entry.getSetting("classModal"));
658
+ entry.dialog.setAttribute("aria-modal", "true");
659
+ await entry.close(false, false);
660
+ entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "switchMode", {
661
+ detail: this,
662
+ bubbles: true
663
+ }));
664
+ return entry;
665
+ }
666
+ class DrawerEntry extends CollectionEntry {
667
+ constructor(context, query, options = {}) {
668
+ super(context, query, options);
669
+ __privateAdd(this, _mode);
670
+ __privateAdd(this, _state);
671
+ __privateAdd(this, _breakpoint);
672
+ this.dialog = null;
673
+ this.trigger = null;
674
+ __privateSet(this, _breakpoint, new Breakpoint());
675
+ __privateSet(this, _mode, "indeterminate");
676
+ __privateSet(this, _state, "indeterminate");
677
+ this.inlineState = "indeterminate";
678
+ }
679
+ get breakpoint() {
680
+ return getBreakpoint.call(this.context, this.el);
681
+ }
682
+ get store() {
683
+ return this.context.store.get(this.id);
684
+ }
685
+ get mode() {
686
+ return __privateGet(this, _mode);
687
+ }
688
+ set mode(value) {
689
+ __privateSet(this, _mode, value);
690
+ switchMode.call(this.context, this);
691
+ }
692
+ get state() {
693
+ return __privateGet(this, _state);
694
+ }
695
+ set state(value) {
696
+ __privateSet(this, _state, value);
697
+ if (this.mode === "inline" && value != "opening" && value != "closing") {
698
+ this.inlineState = value;
699
+ if (this.getSetting("store")) {
700
+ this.context.store.set(this.id, value);
701
+ }
702
+ }
703
+ if (value === "indeterminate") {
704
+ this.el.classList.remove(this.getSetting("stateOpened"));
705
+ this.el.classList.remove(this.getSetting("stateOpening"));
706
+ this.el.classList.remove(this.getSetting("stateClosed"));
707
+ this.el.classList.remove(this.getSetting("stateClosing"));
708
+ }
709
+ }
710
+ async open(transition2, focus) {
711
+ return this.context.open(this, transition2, focus);
712
+ }
713
+ async close(transition2, focus) {
714
+ return this.context.close(this, transition2, focus);
715
+ }
716
+ async toggle(transition2, focus) {
717
+ return this.context.toggle(this, transition2, focus);
718
+ }
719
+ async deregister() {
720
+ return this.context.deregister(this.id);
721
+ }
722
+ mountBreakpoint() {
723
+ const value = this.breakpoint;
724
+ const handler = this.handleBreakpoint.bind(this);
725
+ __privateGet(this, _breakpoint).mount(value, handler);
726
+ }
727
+ unmountBreakpoint() {
728
+ __privateGet(this, _breakpoint).unmount();
729
+ }
730
+ handleBreakpoint(event) {
731
+ const bpMode = event.matches ? "inline" : "modal";
732
+ if (this.mode != bpMode) {
733
+ this.mode = bpMode;
734
+ }
735
+ }
736
+ async beforeMount() {
737
+ const dialog = this.el.querySelector(this.getSetting("selectorDialog"));
738
+ this.dialog = dialog ? dialog : this.el;
739
+ if (this.getSetting("setTabindex")) {
740
+ this.dialog.setAttribute("tabindex", "-1");
741
+ }
742
+ applyInitialState(this);
743
+ this.inlineState = this.state;
744
+ this.mode = this.el.classList.contains(this.getSetting("classModal")) ? "modal" : "inline";
745
+ if (this.breakpoint) {
746
+ this.mountBreakpoint();
747
+ }
748
+ }
749
+ async beforeUnmount(close2 = true) {
750
+ if (close2 && this.state === "opened") {
751
+ await this.close(false);
752
+ }
753
+ this.context.store.set(this.id);
754
+ this.unmountBreakpoint();
755
+ }
756
+ }
757
+ _mode = new WeakMap();
758
+ _state = new WeakMap();
759
+ _breakpoint = new WeakMap();
485
760
  async function handleClick$2(event) {
486
761
  const trigger = event.target.closest(`
487
762
  [data-${this.settings.dataOpen}],
@@ -514,8 +789,8 @@ async function handleClick$2(event) {
514
789
  entry.trigger = trigger;
515
790
  return entry.close();
516
791
  } else {
517
- const parent = event.target.closest(this.settings.selectorDrawer);
518
- if (parent) return this.close(parent);
792
+ const parent = event.target.closest(this.settings.selector);
793
+ if (parent) return this.close(parent.id);
519
794
  }
520
795
  });
521
796
  }
@@ -527,82 +802,60 @@ async function handleClick$2(event) {
527
802
  }
528
803
  function handleKeydown$2(event) {
529
804
  if (event.key === "Escape") {
530
- if (this.activeModal) return this.close(this.activeModal);
531
- }
532
- }
533
- async function deregister$2(obj, close2 = true) {
534
- const index2 = this.collection.findIndex((entry) => {
535
- return entry.id === obj.id;
536
- });
537
- if (index2 >= 0) {
538
- const entry = this.collection[index2];
539
- if (close2 && entry.state === "opened") {
540
- await entry.close(false);
541
- }
542
- this.store.set(entry.id);
543
- entry.unmountBreakpoint();
544
- Object.getOwnPropertyNames(entry).forEach((prop) => {
545
- delete entry[prop];
546
- });
547
- this.collection.splice(index2, 1);
805
+ if (this.activeModal) return this.close(this.activeModal.id);
548
806
  }
549
- return this.collection;
550
807
  }
551
- async function open$2(query, enableTransition, focus = true) {
808
+ async function open$2(query, transitionOverride, focus = true) {
552
809
  const entry = getDrawer.call(this, query);
553
- const config = { ...this.settings, ...entry.settings };
554
- if (enableTransition !== void 0) config.transition = enableTransition;
555
810
  if (entry.state === "closed" || entry.state === "indeterminate") {
556
811
  entry.state = "opening";
557
- if (config.transition) {
558
- await transition(entry.el, {
559
- start: config.stateClosing,
560
- finish: config.stateClosed
561
- }, {
562
- start: config.stateOpening,
563
- finish: config.stateOpened
564
- }, config.transitionDuration);
812
+ if (transitionOverride != void 0 ? transitionOverride : entry.getSetting("transition")) {
813
+ await transition(
814
+ entry.el,
815
+ entry.getSetting("stateClosed"),
816
+ entry.getSetting("stateOpening"),
817
+ entry.getSetting("stateOpened"),
818
+ entry.getSetting("transitionDuration")
819
+ );
565
820
  } else {
566
- entry.el.classList.add(config.stateOpened);
567
- entry.el.classList.remove(config.stateClosed);
821
+ entry.el.classList.add(entry.getSetting("stateOpened"));
822
+ entry.el.classList.remove(entry.getSetting("stateClosed"));
568
823
  }
569
824
  entry.state = "opened";
570
- if (entry.mode === "modal") updateGlobalState(true, config);
825
+ if (entry.mode === "modal") setGlobalState(true, entry.getSetting("selectorInert"), entry.getSetting("selectorOverflow"));
571
826
  if (focus) {
572
827
  updateFocusState$1.call(this, entry);
573
828
  }
574
- entry.el.dispatchEvent(new CustomEvent(config.customEventPrefix + "opened", {
829
+ entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "opened", {
575
830
  detail: this,
576
831
  bubbles: true
577
832
  }));
578
833
  }
579
834
  return entry;
580
835
  }
581
- async function close$2(query, enableTransition, focus = true) {
836
+ async function close$2(query, transitionOverride, focus = true) {
582
837
  const entry = getDrawer.call(this, query);
583
- const config = { ...this.settings, ...entry.settings };
584
- if (enableTransition !== void 0) config.transition = enableTransition;
585
838
  if (entry.state === "opened" || entry.state === "indeterminate") {
586
839
  entry.state = "closing";
587
840
  document.activeElement.blur();
588
- if (config.transition) {
589
- await transition(entry.el, {
590
- start: config.stateOpening,
591
- finish: config.stateOpened
592
- }, {
593
- start: config.stateClosing,
594
- finish: config.stateClosed
595
- }, config.transitionDuration);
841
+ if (transitionOverride != void 0 ? transitionOverride : entry.getSetting("transition")) {
842
+ await transition(
843
+ entry.el,
844
+ entry.getSetting("stateOpened"),
845
+ entry.getSetting("stateClosing"),
846
+ entry.getSetting("stateClosed"),
847
+ entry.getSetting("transitionDuration")
848
+ );
596
849
  } else {
597
- entry.el.classList.add(config.stateClosed);
598
- entry.el.classList.remove(config.stateOpened);
850
+ entry.el.classList.add(entry.getSetting("stateClosed"));
851
+ entry.el.classList.remove(entry.getSetting("stateOpened"));
599
852
  }
600
853
  entry.state = "closed";
601
- if (entry.mode === "modal") updateGlobalState(false, config);
854
+ if (entry.mode === "modal") setGlobalState(false, entry.getSetting("selectorInert"), entry.getSetting("selectorOverflow"));
602
855
  if (focus) {
603
856
  updateFocusState$1.call(this, entry);
604
857
  }
605
- entry.el.dispatchEvent(new CustomEvent(config.customEventPrefix + "closed", {
858
+ entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "closed", {
606
859
  detail: this,
607
860
  bubbles: true
608
861
  }));
@@ -617,199 +870,54 @@ async function toggle(query, transition2, focus) {
617
870
  return close$2.call(this, entry, transition2, focus);
618
871
  }
619
872
  }
620
- function switchMode(entry) {
621
- switch (entry.mode) {
622
- case "inline":
623
- return toInline.call(this, entry);
624
- case "modal":
625
- return toModal.call(this, entry);
626
- default:
627
- throw new Error(`"${entry.mode}" is not a valid drawer mode.`);
628
- }
629
- }
630
- async function toInline(entry) {
631
- entry.el.classList.remove(entry.getSetting("classModal"));
632
- entry.dialog.removeAttribute("aria-modal");
633
- updateGlobalState(false, { ...this.settings, ...entry.settings });
634
- this.focusTrap.unmount();
635
- await applyInlineState(entry);
636
- entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "switchMode", {
637
- detail: this,
638
- bubbles: true
639
- }));
640
- return entry;
641
- }
642
- async function toModal(entry) {
643
- entry.el.classList.add(entry.getSetting("classModal"));
644
- entry.dialog.setAttribute("aria-modal", "true");
645
- await close$2.call(this, entry, false, false);
646
- entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "switchMode", {
647
- detail: this,
648
- bubbles: true
649
- }));
650
- return entry;
651
- }
652
- async function register$2(el, config = {}) {
653
- await deregister$2.call(this, el, false);
654
- const root = this;
655
- const breakpoint = new Breakpoint();
656
- let _mode, _state = "indeterminate";
657
- const entry = {
658
- id: el.id,
659
- el,
660
- dialog: null,
661
- trigger: null,
662
- settings: { ...getConfig$1(el, this.settings.dataConfig), ...config },
663
- inlineState: "indeterminate",
664
- get breakpoint() {
665
- return getBreakpoint.call(root, el);
666
- },
667
- get store() {
668
- return root.store.get(this.id);
669
- },
670
- get mode() {
671
- return _mode;
672
- },
673
- set mode(value) {
674
- _mode = value;
675
- switchMode.call(root, this);
676
- },
677
- get state() {
678
- return _state;
679
- },
680
- set state(value) {
681
- _state = value;
682
- if (this.mode === "inline" && value != "opening" && value != "closing") {
683
- this.inlineState = value;
684
- if (this.getSetting("store")) {
685
- root.store.set(this.id, value);
686
- }
687
- }
688
- if (value === "indeterminate") {
689
- this.el.classList.remove(this.getSetting("stateOpened"));
690
- this.el.classList.remove(this.getSetting("stateOpening"));
691
- this.el.classList.remove(this.getSetting("stateClosed"));
692
- this.el.classList.remove(this.getSetting("stateClosing"));
693
- }
694
- },
695
- open(transition2, focus) {
696
- return open$2.call(root, this, transition2, focus);
697
- },
698
- close(transition2, focus) {
699
- return close$2.call(root, this, transition2, focus);
700
- },
701
- toggle(transition2, focus) {
702
- return toggle.call(root, this, transition2, focus);
703
- },
704
- deregister() {
705
- return deregister$2.call(root, this);
706
- },
707
- mountBreakpoint() {
708
- const value = this.breakpoint;
709
- const handler = this.handleBreakpoint.bind(this);
710
- breakpoint.mount(value, handler);
711
- return this;
712
- },
713
- unmountBreakpoint() {
714
- breakpoint.unmount();
715
- return this;
716
- },
717
- handleBreakpoint(event) {
718
- const bpMode = event.matches ? "inline" : "modal";
719
- if (this.mode != bpMode) {
720
- this.mode = bpMode;
721
- }
722
- return this;
723
- },
724
- getSetting(key) {
725
- return key in this.settings ? this.settings[key] : root.settings[key];
726
- }
727
- };
728
- this.collection.push(entry);
729
- const dialog = el.querySelector(entry.getSetting("selectorDialog"));
730
- entry.dialog = dialog ? dialog : el;
731
- if (entry.getSetting("setTabindex")) {
732
- entry.dialog.setAttribute("tabindex", "-1");
733
- }
734
- await applyInitialState(entry);
735
- entry.inlineState = entry.state;
736
- entry.mode = el.classList.contains(entry.getSetting("classModal")) ? "modal" : "inline";
737
- if (entry.breakpoint) {
738
- entry.mountBreakpoint();
739
- }
740
- return entry;
741
- }
742
873
  class Drawer extends Collection {
743
874
  constructor(options) {
744
- super();
875
+ super({ ...defaults$2, ...options });
745
876
  __privateAdd(this, _handleClick);
746
877
  __privateAdd(this, _handleKeydown);
747
- this.defaults = defaults$2;
748
- this.settings = { ...this.defaults, ...options };
749
878
  this.focusTrap = new FocusTrap();
750
- this.store = localStore(this.settings.storeKey, this.settings.store);
751
879
  __privateSet(this, _handleClick, handleClick$2.bind(this));
752
880
  __privateSet(this, _handleKeydown, handleKeydown$2.bind(this));
753
- if (this.settings.autoMount) this.mount();
881
+ this.store = localStore(this.settings.storeKey, this.settings.store);
754
882
  }
755
883
  get activeModal() {
756
884
  return this.collection.find((entry) => {
757
885
  return entry.state === "opened" && entry.mode === "modal";
758
886
  });
759
887
  }
760
- async mount(options = null) {
761
- if (options) this.settings = { ...this.settings, ...options };
762
- const drawers = document.querySelectorAll(this.settings.selectorDrawer);
763
- await this.registerCollection(drawers);
764
- if (this.settings.eventListeners) {
765
- this.mountEventListeners();
766
- }
767
- return this;
888
+ async createEntry(query, config) {
889
+ return new DrawerEntry(this, query, config);
768
890
  }
769
- async unmount() {
770
- await this.deregisterCollection();
771
- if (this.settings.eventListeners) {
772
- this.unmountEventListeners();
773
- }
774
- return this;
891
+ async open(id, transition2, focus) {
892
+ return open$2.call(this, id, transition2, focus);
893
+ }
894
+ async close(id, transition2, focus) {
895
+ return close$2.call(this, id, transition2, focus);
775
896
  }
776
- mountEventListeners() {
897
+ async toggle(id, transition2, focus) {
898
+ return toggle.call(this, id, transition2, focus);
899
+ }
900
+ async afterMount() {
777
901
  document.addEventListener("click", __privateGet(this, _handleClick), false);
778
902
  document.addEventListener("keydown", __privateGet(this, _handleKeydown), false);
779
903
  }
780
- unmountEventListeners() {
904
+ async beforeUnmount() {
905
+ this.trigger = null;
906
+ }
907
+ async afterUnmount() {
781
908
  document.removeEventListener("click", __privateGet(this, _handleClick), false);
782
909
  document.removeEventListener("keydown", __privateGet(this, _handleKeydown), false);
783
910
  }
784
- register(query, config = {}) {
785
- let el = typeof query == "string" ? document.getElementById(query) : query;
786
- return el ? register$2.call(this, el, config) : Promise.reject(new Error(`Failed to register; drawer not found with ID of: "${query.id || query}".`));
787
- }
788
- deregister(query) {
789
- let obj = this.get(query.id || query);
790
- return obj ? deregister$2.call(this, obj) : Promise.reject(new Error(`Failed to deregister; drawer does not exist in collection with ID of: "${query.id || query}".`));
791
- }
792
- open(id, transition2, focus) {
793
- return open$2.call(this, id, transition2, focus);
794
- }
795
- close(id, transition2, focus) {
796
- return close$2.call(this, id, transition2, focus);
797
- }
798
- toggle(id, transition2, focus) {
799
- return toggle.call(this, id, transition2, focus);
800
- }
801
911
  }
802
912
  _handleClick = new WeakMap();
803
913
  _handleKeydown = new WeakMap();
804
914
  const defaults$1 = {
805
- autoMount: false,
806
915
  // Data attributes
807
916
  dataOpen: "modal-open",
808
917
  dataClose: "modal-close",
809
918
  dataReplace: "modal-replace",
810
- dataConfig: "modal-config",
811
919
  // Selectors
812
- selectorModal: ".modal",
920
+ selector: ".modal",
813
921
  selectorDialog: ".modal__dialog",
814
922
  selectorScreen: ".modal",
815
923
  selectorRequired: '[role="alertdialog"]',
@@ -823,13 +931,61 @@ const defaults$1 = {
823
931
  stateClosed: "is-closed",
824
932
  // Feature settings
825
933
  customEventPrefix: "modal:",
826
- eventListeners: true,
934
+ setTabindex: true,
827
935
  teleport: null,
828
936
  teleportMethod: "append",
829
- setTabindex: true,
830
937
  transition: true,
831
938
  transitionDuration: "modal-transition-duration"
832
939
  };
940
+ class ModalEntry extends CollectionEntry {
941
+ constructor(context, query, options = {}) {
942
+ super(context, query, options);
943
+ this.state = "closed";
944
+ this.dialog = null;
945
+ }
946
+ get isRequired() {
947
+ return this.dialog.matches(this.getSetting("selectorRequired"));
948
+ }
949
+ async open(transition2, focus) {
950
+ return this.context.open(this, transition2, focus);
951
+ }
952
+ async close(transition2, focus) {
953
+ return this.context.close(this, transition2, focus);
954
+ }
955
+ async replace(transition2, focus) {
956
+ return this.context.replace(this, transition2, focus);
957
+ }
958
+ async deregister() {
959
+ return this.context.deregister(this.id);
960
+ }
961
+ async beforeMount() {
962
+ const dialog = this.el.querySelector(this.getSetting("selectorDialog"));
963
+ this.dialog = dialog ? dialog : this.el;
964
+ this.dialog.setAttribute("aria-modal", "true");
965
+ if (!this.dialog.hasAttribute("role")) {
966
+ this.dialog.setAttribute("role", "dialog");
967
+ }
968
+ if (this.getSetting("setTabindex")) {
969
+ this.dialog.setAttribute("tabindex", "-1");
970
+ }
971
+ }
972
+ async afterRegister() {
973
+ if (this.el.classList.contains(this.getSetting("stateOpened"))) {
974
+ await this.open(false);
975
+ } else {
976
+ this.el.classList.remove(this.getSetting("stateOpening"));
977
+ this.el.classList.remove(this.getSetting("stateClosing"));
978
+ this.el.classList.add(this.getSetting("stateClosed"));
979
+ }
980
+ }
981
+ async beforeUnmount(reMount = false) {
982
+ if (!reMount && this.state === "opened") {
983
+ await this.close(false);
984
+ } else {
985
+ this.context.stack.remove(this);
986
+ }
987
+ }
988
+ }
833
989
  function getModal(query) {
834
990
  const entry = typeof query === "string" ? this.get(query) : this.get(query.id);
835
991
  if (entry) {
@@ -860,14 +1016,14 @@ async function handleClick$1(event) {
860
1016
  if (trigger.matches(`[data-${this.settings.dataOpen}]`)) {
861
1017
  const selector = trigger.getAttribute(`data-${this.settings.dataOpen}`).trim();
862
1018
  const entry = getModal.call(this, selector);
863
- const fromModal = event.target.closest(this.settings.selectorModal);
1019
+ const fromModal = event.target.closest(this.settings.selector);
864
1020
  if (!fromModal) this.trigger = trigger;
865
1021
  return entry.open();
866
1022
  }
867
1023
  if (trigger.matches(`[data-${this.settings.dataReplace}]`)) {
868
1024
  const selector = trigger.getAttribute(`data-${this.settings.dataReplace}`).trim();
869
1025
  const entry = getModal.call(this, selector);
870
- const fromModal = event.target.closest(this.settings.selectorModal);
1026
+ const fromModal = event.target.closest(this.settings.selector);
871
1027
  if (!fromModal) this.trigger = trigger;
872
1028
  return entry.replace();
873
1029
  }
@@ -876,7 +1032,7 @@ async function handleClick$1(event) {
876
1032
  return selector === "*" ? this.closeAll() : this.close(selector);
877
1033
  }
878
1034
  }
879
- if (this.active && event.target.matches(this.settings.selectorScreen) && !this.active.required) {
1035
+ if (this.active && event.target.matches(this.settings.selectorScreen) && !this.active.isRequired) {
880
1036
  return this.close(this.active.id);
881
1037
  }
882
1038
  }
@@ -887,83 +1043,58 @@ function handleKeydown$1(event) {
887
1043
  }
888
1044
  }
889
1045
  }
890
- async function deregister$1(obj, close2 = true) {
891
- const index2 = this.collection.findIndex((entry) => {
892
- return entry.id === obj.id;
893
- });
894
- if (index2 >= 0) {
895
- const entry = this.collection[index2];
896
- if (close2 && entry.state === "opened") {
897
- await entry.close(false);
898
- } else {
899
- this.stack.remove(entry);
900
- }
901
- if (entry.getSetting("teleport")) {
902
- entry.teleportReturn();
903
- }
904
- Object.getOwnPropertyNames(entry).forEach((prop) => {
905
- delete entry[prop];
906
- });
907
- this.collection.splice(index2, 1);
908
- }
909
- return this.collection;
910
- }
911
- async function open$1(query, enableTransition, focus = true) {
1046
+ async function open$1(query, transitionOverride = void 0, focus = true) {
912
1047
  const entry = getModal.call(this, query);
913
- const config = { ...this.settings, ...entry.settings };
914
- if (enableTransition !== void 0) config.transition = enableTransition;
915
1048
  this.stack.moveToTop(entry);
916
1049
  if (entry.state === "closed") {
917
1050
  entry.state = "opening";
918
1051
  this.stack.add(entry);
919
- if (config.transition) {
920
- await transition(entry.el, {
921
- start: config.stateClosing,
922
- finish: config.stateClosed
923
- }, {
924
- start: config.stateOpening,
925
- finish: config.stateOpened
926
- }, config.transitionDuration);
1052
+ if (transitionOverride != void 0 ? transitionOverride : entry.getSetting("transition")) {
1053
+ await transition(
1054
+ entry.el,
1055
+ entry.getSetting("stateClosed"),
1056
+ entry.getSetting("stateOpening"),
1057
+ entry.getSetting("stateOpened"),
1058
+ entry.getSetting("transitionDuration")
1059
+ );
927
1060
  } else {
928
- entry.el.classList.add(config.stateOpened);
929
- entry.el.classList.remove(config.stateClosed);
1061
+ entry.el.classList.add(entry.getSetting("stateOpened"));
1062
+ entry.el.classList.remove(entry.getSetting("stateClosed"));
930
1063
  }
931
1064
  entry.state = "opened";
932
1065
  }
933
1066
  if (focus) {
934
1067
  updateFocusState.call(this);
935
1068
  }
936
- entry.el.dispatchEvent(new CustomEvent(config.customEventPrefix + "opened", {
1069
+ entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "opened", {
937
1070
  detail: this,
938
1071
  bubbles: true
939
1072
  }));
940
1073
  return entry;
941
1074
  }
942
- async function close$1(query, enableTransition, focus = true) {
1075
+ async function close$1(query, transitionOverride, focus = true) {
943
1076
  const entry = query ? getModal.call(this, query) : this.active;
944
1077
  if (entry && entry.state === "opened") {
945
1078
  entry.state = "closing";
946
- const config = { ...this.settings, ...entry.settings };
947
- if (enableTransition !== void 0) config.transition = enableTransition;
948
1079
  document.activeElement.blur();
949
- if (config.transition) {
950
- await transition(entry.el, {
951
- start: config.stateOpening,
952
- finish: config.stateOpened
953
- }, {
954
- start: config.stateClosing,
955
- finish: config.stateClosed
956
- }, config.transitionDuration);
1080
+ if (transitionOverride != void 0 ? transitionOverride : entry.getSetting("transition")) {
1081
+ await transition(
1082
+ entry.el,
1083
+ entry.getSetting("stateOpened"),
1084
+ entry.getSetting("stateClosing"),
1085
+ entry.getSetting("stateClosed"),
1086
+ entry.getSetting("transitionDuration")
1087
+ );
957
1088
  } else {
958
- entry.el.classList.add(config.stateClosed);
959
- entry.el.classList.remove(config.stateOpened);
1089
+ entry.el.classList.add(entry.getSetting("stateClosed"));
1090
+ entry.el.classList.remove(entry.getSetting("stateOpened"));
960
1091
  }
961
1092
  this.stack.remove(entry);
962
1093
  entry.state = "closed";
963
1094
  if (focus) {
964
1095
  updateFocusState.call(this);
965
1096
  }
966
- entry.el.dispatchEvent(new CustomEvent(config.customEventPrefix + "closed", {
1097
+ entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "closed", {
967
1098
  detail: this,
968
1099
  bubbles: true
969
1100
  }));
@@ -998,75 +1129,6 @@ async function replace(query, transition2, focus = true) {
998
1129
  }
999
1130
  return { opened: resultOpened, closed: resultClosed };
1000
1131
  }
1001
- async function register$1(el, config = {}) {
1002
- await deregister$1.call(this, el, false);
1003
- const root = this;
1004
- const entry = {
1005
- id: el.id,
1006
- state: "closed",
1007
- el,
1008
- dialog: null,
1009
- get required() {
1010
- return this.dialog.matches(this.getSetting("selectorRequired"));
1011
- },
1012
- returnRef: null,
1013
- settings: { ...getConfig$1(el, this.settings.dataConfig), ...config },
1014
- open(transition2, focus) {
1015
- return open$1.call(root, this, transition2, focus);
1016
- },
1017
- close(transition2, focus) {
1018
- return close$1.call(root, this, transition2, focus);
1019
- },
1020
- replace(transition2, focus) {
1021
- return replace.call(root, this, transition2, focus);
1022
- },
1023
- deregister() {
1024
- return deregister$1.call(root, this);
1025
- },
1026
- teleport(ref = this.getSetting("teleport"), method = this.getSetting("teleportMethod")) {
1027
- if (!this.returnRef) {
1028
- this.returnRef = teleport(this.el, ref, method);
1029
- return this.el;
1030
- } else {
1031
- console.error("Element has already been teleported:", this.el);
1032
- return false;
1033
- }
1034
- },
1035
- teleportReturn() {
1036
- if (this.returnRef) {
1037
- this.returnRef = teleport(this.el, this.returnRef);
1038
- return this.el;
1039
- } else {
1040
- console.error("No return reference found:", this.el);
1041
- return false;
1042
- }
1043
- },
1044
- getSetting(key) {
1045
- return key in this.settings ? this.settings[key] : root.settings[key];
1046
- }
1047
- };
1048
- const dialog = el.querySelector(entry.getSetting("selectorDialog"));
1049
- entry.dialog = dialog ? dialog : el;
1050
- entry.dialog.setAttribute("aria-modal", "true");
1051
- if (!entry.dialog.hasAttribute("role")) {
1052
- entry.dialog.setAttribute("role", "dialog");
1053
- }
1054
- if (entry.getSetting("setTabindex")) {
1055
- entry.dialog.setAttribute("tabindex", "-1");
1056
- }
1057
- if (entry.getSetting("teleport")) {
1058
- entry.teleport();
1059
- }
1060
- this.collection.push(entry);
1061
- if (entry.el.classList.contains(this.settings.stateOpened)) {
1062
- await entry.open(false);
1063
- } else {
1064
- entry.el.classList.remove(this.settings.stateOpening);
1065
- entry.el.classList.remove(this.settings.stateClosing);
1066
- entry.el.classList.add(this.settings.stateClosed);
1067
- }
1068
- return entry;
1069
- }
1070
1132
  function stack(settings) {
1071
1133
  const stackArray = [];
1072
1134
  return {
@@ -1074,7 +1136,8 @@ function stack(settings) {
1074
1136
  return [...stackArray];
1075
1137
  },
1076
1138
  get top() {
1077
- return stackArray[stackArray.length - 1];
1139
+ const result = stackArray[stackArray.length - 1];
1140
+ return result ? result : null;
1078
1141
  },
1079
1142
  updateIndex() {
1080
1143
  stackArray.forEach((entry, index2) => {
@@ -1083,8 +1146,8 @@ function stack(settings) {
1083
1146
  entry.el.style.zIndex = parseInt(value) + index2 + 1;
1084
1147
  });
1085
1148
  },
1086
- updateGlobalState() {
1087
- updateGlobalState(this.top, settings);
1149
+ setGlobalState() {
1150
+ setGlobalState(this.top, settings.selectorInert, settings.selectorOverflow);
1088
1151
  this.updateIndex();
1089
1152
  },
1090
1153
  add(entry) {
@@ -1092,7 +1155,7 @@ function stack(settings) {
1092
1155
  const value = getComputedStyle(entry.el)["z-index"];
1093
1156
  entry.el.style.zIndex = parseInt(value) + stackArray.length + 1;
1094
1157
  stackArray.push(entry);
1095
- this.updateGlobalState();
1158
+ this.setGlobalState();
1096
1159
  },
1097
1160
  remove(entry) {
1098
1161
  const index2 = stackArray.findIndex((item) => {
@@ -1101,7 +1164,7 @@ function stack(settings) {
1101
1164
  if (index2 >= 0) {
1102
1165
  entry.el.style.zIndex = null;
1103
1166
  stackArray.splice(index2, 1);
1104
- this.updateGlobalState();
1167
+ this.setGlobalState();
1105
1168
  }
1106
1169
  },
1107
1170
  moveToTop(entry) {
@@ -1117,61 +1180,28 @@ function stack(settings) {
1117
1180
  }
1118
1181
  class Modal extends Collection {
1119
1182
  constructor(options) {
1120
- super();
1183
+ super({ ...defaults$1, ...options });
1121
1184
  __privateAdd(this, _handleClick2);
1122
1185
  __privateAdd(this, _handleKeydown2);
1123
- this.defaults = defaults$1;
1124
- this.settings = { ...this.defaults, ...options };
1125
1186
  this.trigger = null;
1126
1187
  this.focusTrap = new FocusTrap();
1127
- this.stack = stack(this.settings);
1128
1188
  __privateSet(this, _handleClick2, handleClick$1.bind(this));
1129
1189
  __privateSet(this, _handleKeydown2, handleKeydown$1.bind(this));
1130
- if (this.settings.autoMount) this.mount();
1190
+ this.stack = stack(this.settings);
1131
1191
  }
1132
1192
  get active() {
1133
1193
  return this.stack.top;
1134
1194
  }
1135
- async mount(options) {
1136
- if (options) this.settings = { ...this.settings, ...options };
1137
- const modals = document.querySelectorAll(this.settings.selectorModal);
1138
- await this.registerCollection(modals);
1139
- if (this.settings.eventListeners) {
1140
- this.mountEventListeners();
1141
- }
1142
- return this;
1143
- }
1144
- async unmount() {
1145
- this.trigger = null;
1146
- await this.deregisterCollection();
1147
- if (this.settings.eventListeners) {
1148
- this.unmountEventListeners();
1149
- }
1150
- return this;
1151
- }
1152
- mountEventListeners() {
1153
- document.addEventListener("click", __privateGet(this, _handleClick2), false);
1154
- document.addEventListener("keydown", __privateGet(this, _handleKeydown2), false);
1155
- }
1156
- unmountEventListeners() {
1157
- document.removeEventListener("click", __privateGet(this, _handleClick2), false);
1158
- document.removeEventListener("keydown", __privateGet(this, _handleKeydown2), false);
1159
- }
1160
- register(query, config = {}) {
1161
- let el = typeof query == "string" ? document.getElementById(query) : query;
1162
- return el ? register$1.call(this, el, config) : Promise.reject(new Error(`Failed to register; modal not found with ID of: "${query.id || query}".`));
1163
- }
1164
- deregister(query) {
1165
- let obj = this.get(query.id || query);
1166
- return obj ? deregister$1.call(this, obj) : Promise.reject(new Error(`Failed to deregister; modal does not exist in collection with ID of: "${query.id || query}".`));
1195
+ async createEntry(query, config) {
1196
+ return new ModalEntry(this, query, config);
1167
1197
  }
1168
- open(id, transition2, focus) {
1198
+ async open(id, transition2, focus) {
1169
1199
  return open$1.call(this, id, transition2, focus);
1170
1200
  }
1171
- close(id, transition2, focus) {
1201
+ async close(id, transition2, focus) {
1172
1202
  return close$1.call(this, id, transition2, focus);
1173
1203
  }
1174
- replace(id, transition2, focus) {
1204
+ async replace(id, transition2, focus) {
1175
1205
  return replace.call(this, id, transition2, focus);
1176
1206
  }
1177
1207
  async closeAll(exclude = false, transition2, focus = true) {
@@ -1181,50 +1211,71 @@ class Modal extends Collection {
1181
1211
  }
1182
1212
  return result;
1183
1213
  }
1214
+ async afterMount() {
1215
+ document.addEventListener("click", __privateGet(this, _handleClick2), false);
1216
+ document.addEventListener("keydown", __privateGet(this, _handleKeydown2), false);
1217
+ }
1218
+ async beforeUnmount() {
1219
+ this.trigger = null;
1220
+ }
1221
+ async afterUnmount() {
1222
+ document.removeEventListener("click", __privateGet(this, _handleClick2), false);
1223
+ document.removeEventListener("keydown", __privateGet(this, _handleKeydown2), false);
1224
+ }
1184
1225
  }
1185
1226
  _handleClick2 = new WeakMap();
1186
1227
  _handleKeydown2 = new WeakMap();
1187
1228
  const defaults = {
1188
- autoMount: false,
1189
1229
  // Selectors
1190
- selectorPopover: ".popover",
1230
+ selector: ".popover",
1191
1231
  selectorTooltip: ".popover_tooltip",
1192
1232
  selectorArrow: ".popover__arrow",
1193
1233
  // State classes
1194
1234
  stateActive: "is-active",
1195
- // Feature settings
1196
- eventListeners: true,
1197
- eventType: "click",
1235
+ // Custom properties and their defaults
1198
1236
  placement: "bottom",
1199
- hoverToggleDelay: 0
1237
+ event: "click",
1238
+ offset: 0,
1239
+ flipPadding: 0,
1240
+ shiftPadding: 0,
1241
+ arrowPadding: 0,
1242
+ toggleDelay: 0,
1243
+ // Feature settings
1244
+ teleport: null,
1245
+ teleportMethod: "append"
1200
1246
  };
1201
- function getConfig(el, settings) {
1202
- const styles = getComputedStyle(el);
1203
- const config = {
1204
- "placement": settings.placement,
1205
- "event": settings.eventType,
1206
- "offset": 0,
1207
- "overflow-padding": 0,
1208
- "flip-padding": 0,
1209
- "arrow-element": settings.selectorArrow,
1210
- "arrow-padding": 0,
1211
- "toggle-delay": settings.hoverToggleDelay
1212
- };
1213
- for (const prop in config) {
1214
- const prefix = getPrefix();
1215
- const value = styles.getPropertyValue(`--${prefix}popover-${prop}`).trim();
1216
- if (value) {
1217
- config[prop] = value;
1247
+ function applyPositionStyle(el, x, y) {
1248
+ Object.assign(el.style, {
1249
+ left: x != null ? `${x}px` : "",
1250
+ top: y != null ? `${y}px` : ""
1251
+ });
1252
+ }
1253
+ function getDelay(popover, index2) {
1254
+ let value = popover.getSetting("toggle-delay");
1255
+ if (typeof value == "string") {
1256
+ if (value.indexOf(",") > -1) {
1257
+ value = value.split(",");
1218
1258
  }
1259
+ if (value.indexOf(" ") > -1) {
1260
+ value = value.split(" ");
1261
+ }
1262
+ }
1263
+ if (Array.isArray(value)) {
1264
+ value = value[index2];
1265
+ }
1266
+ const number = Number(value);
1267
+ if (!Number.isNaN(number)) {
1268
+ return number;
1269
+ } else {
1270
+ throw new Error(`Provided delay value is not a number: "${value}"`);
1219
1271
  }
1220
- return config;
1221
1272
  }
1222
1273
  function getPadding(value) {
1223
1274
  let padding;
1224
1275
  const array = typeof value === "string" ? value.trim().split(" ") : [value];
1225
- array.forEach(function(item, index2) {
1226
- array[index2] = parseInt(item, 10);
1227
- });
1276
+ for (let index2 = 0; index2 < array.length; index2++) {
1277
+ array[index2] = Number(array[index2]);
1278
+ }
1228
1279
  switch (array.length) {
1229
1280
  case 1:
1230
1281
  padding = array[0];
@@ -1259,29 +1310,20 @@ function getPadding(value) {
1259
1310
  }
1260
1311
  return padding;
1261
1312
  }
1262
- function getModifiers(options) {
1263
- return [{
1264
- name: "offset",
1265
- options: {
1266
- offset: [0, parseInt(options["offset"], 10)]
1267
- }
1268
- }, {
1269
- name: "preventOverflow",
1270
- options: {
1271
- padding: getPadding(options["overflow-padding"])
1272
- }
1273
- }, {
1274
- name: "flip",
1275
- options: {
1276
- padding: getPadding(options["flip-padding"])
1277
- }
1278
- }, {
1279
- name: "arrow",
1280
- options: {
1281
- element: options["arrow-element"],
1282
- padding: getPadding(options["arrow-padding"])
1313
+ function getMiddlewareOptions(popover) {
1314
+ return {
1315
+ offset: Number(popover.getSetting("offset")),
1316
+ flip: {
1317
+ padding: getPadding(popover.getSetting("flip-padding"))
1318
+ },
1319
+ shift: {
1320
+ padding: getPadding(popover.getSetting("shift-padding"))
1321
+ },
1322
+ arrow: {
1323
+ element: popover.getSetting("selectorArrow"),
1324
+ padding: getPadding(popover.getSetting("arrow-padding"))
1283
1325
  }
1284
- }];
1326
+ };
1285
1327
  }
1286
1328
  function getPopover(query) {
1287
1329
  const entry = typeof query === "string" ? this.get(query) : this.get(query.id);
@@ -1291,38 +1333,6 @@ function getPopover(query) {
1291
1333
  throw new Error(`Popover not found in collection with id of "${query}".`);
1292
1334
  }
1293
1335
  }
1294
- function getPopoverID(obj) {
1295
- if (typeof obj === "string") {
1296
- return obj;
1297
- } else if (typeof obj.hasAttribute === "function") {
1298
- if (obj.closest(this.settings.selectorPopover)) {
1299
- obj = obj.closest(this.settings.selectorPopover);
1300
- return obj.id;
1301
- } else if (obj.hasAttribute("aria-controls")) {
1302
- return obj.getAttribute("aria-controls");
1303
- } else if (obj.hasAttribute("aria-describedby")) {
1304
- return obj.getAttribute("aria-describedby");
1305
- } else return false;
1306
- } else return false;
1307
- }
1308
- function getPopoverElements(query) {
1309
- const id = getPopoverID.call(this, query);
1310
- if (id) {
1311
- const popover = document.querySelector(`#${id}`);
1312
- const trigger = document.querySelector(`[aria-controls="${id}"]`) || document.querySelector(`[aria-describedby="${id}"]`);
1313
- if (!trigger && !popover) {
1314
- return { error: new Error(`No popover elements found using the ID: "${id}".`) };
1315
- } else if (!trigger) {
1316
- return { error: new Error(`No popover trigger associated with the provided popover: "${id}".`) };
1317
- } else if (!popover) {
1318
- return { error: new Error(`No popover associated with the provided popover trigger: "${id}".`) };
1319
- } else {
1320
- return { popover, trigger };
1321
- }
1322
- } else {
1323
- return { error: new Error("Could not resolve the popover ID.") };
1324
- }
1325
- }
1326
1336
  async function close(query) {
1327
1337
  const popover = query ? getPopover.call(this, query) : await closeAll.call(this);
1328
1338
  if (popover && popover.state === "opened") {
@@ -1331,13 +1341,7 @@ async function close(query) {
1331
1341
  if (!popover.isTooltip) {
1332
1342
  popover.trigger.setAttribute("aria-expanded", "false");
1333
1343
  }
1334
- popover.popper.setOptions({
1335
- placement: popover.config["placement"],
1336
- modifiers: [
1337
- { name: "eventListeners", enabled: false },
1338
- ...getModifiers(popover.config)
1339
- ]
1340
- });
1344
+ popover.floatingCleanup();
1341
1345
  popover.state = "closed";
1342
1346
  if (popover.trigger === this.trigger) {
1343
1347
  this.trigger = null;
@@ -1369,48 +1373,48 @@ function closeCheck(popover) {
1369
1373
  }, 1);
1370
1374
  }
1371
1375
  function handleClick(popover) {
1372
- const tooltipId = popover.trigger.getAttribute("aria-describedby");
1373
- if (tooltipId) {
1374
- const entry = this.get(tooltipId);
1375
- if (entry.isTooltip) {
1376
- if (entry.toggleDelayId) {
1377
- clearTimeout(entry.toggleDelayId);
1378
- }
1379
- entry.close();
1380
- }
1381
- }
1382
1376
  if (popover.state === "opened") {
1383
1377
  popover.close();
1384
1378
  } else {
1385
1379
  this.trigger = popover.trigger;
1386
1380
  popover.open();
1387
- handleDocumentClick.call(this, popover);
1381
+ }
1382
+ }
1383
+ function handleTooltipClick(popover) {
1384
+ if (popover.isTooltip) {
1385
+ if (popover.toggleDelayId) {
1386
+ clearTimeout(popover.toggleDelayId);
1387
+ }
1388
+ popover.close();
1388
1389
  }
1389
1390
  }
1390
1391
  function handleMouseEnter(popover, event) {
1392
+ popover.isHovered = event;
1391
1393
  if (event.type == "focus" && !popover.trigger.matches(":focus-visible")) {
1392
1394
  return;
1393
1395
  }
1394
- const isExpanded = popover.trigger.getAttribute("aria-expanded");
1395
- if (isExpanded && isExpanded == "true") {
1396
- return;
1397
- }
1398
1396
  if (popover.toggleDelayId) {
1399
1397
  clearTimeout(popover.toggleDelayId);
1400
1398
  }
1401
- const delay = this.activeTooltip ? 0 : popover.config["toggle-delay"];
1402
- if (this.activeTooltip) this.activeTooltip.close();
1399
+ const isExpanded = popover.trigger.getAttribute("aria-expanded");
1400
+ if (isExpanded && isExpanded == "true") return;
1401
+ const delay = this.activeHover ? 0 : getDelay(popover, 0);
1402
+ if (this.activeHover) this.activeHover.close();
1403
1403
  popover.toggleDelayId = setTimeout(() => {
1404
1404
  if (popover.id) popover.open();
1405
1405
  }, delay);
1406
1406
  }
1407
- function handleMouseLeave(popover) {
1408
- if (popover.toggleDelayId) {
1409
- clearTimeout(popover.toggleDelayId);
1410
- }
1411
- popover.toggleDelayId = setTimeout(() => {
1412
- closeCheck.call(this, popover);
1413
- }, popover.config["toggle-delay"]);
1407
+ function handleMouseLeave(popover, event) {
1408
+ setTimeout(() => {
1409
+ popover.isHovered = event;
1410
+ if (popover.isHovered) return;
1411
+ if (popover.toggleDelayId) {
1412
+ clearTimeout(popover.toggleDelayId);
1413
+ }
1414
+ popover.toggleDelayId = setTimeout(() => {
1415
+ closeCheck.call(this, popover);
1416
+ }, getDelay(popover, 1));
1417
+ }, 1);
1414
1418
  }
1415
1419
  function handleKeydown(event) {
1416
1420
  switch (event.key) {
@@ -1447,567 +1451,1162 @@ function handleDocumentClick(popover) {
1447
1451
  }
1448
1452
  });
1449
1453
  }
1450
- var top = "top";
1451
- var bottom = "bottom";
1452
- var right = "right";
1453
- var left = "left";
1454
- var auto = "auto";
1455
- var basePlacements = [top, bottom, right, left];
1456
- var start = "start";
1457
- var end = "end";
1458
- var clippingParents = "clippingParents";
1459
- var viewport = "viewport";
1460
- var popper = "popper";
1461
- var reference = "reference";
1462
- var variationPlacements = /* @__PURE__ */ basePlacements.reduce(function(acc, placement) {
1463
- return acc.concat([placement + "-" + start, placement + "-" + end]);
1464
- }, []);
1465
- var placements = /* @__PURE__ */ [].concat(basePlacements, [auto]).reduce(function(acc, placement) {
1466
- return acc.concat([placement, placement + "-" + start, placement + "-" + end]);
1467
- }, []);
1468
- var beforeRead = "beforeRead";
1469
- var read = "read";
1470
- var afterRead = "afterRead";
1471
- var beforeMain = "beforeMain";
1472
- var main = "main";
1473
- var afterMain = "afterMain";
1474
- var beforeWrite = "beforeWrite";
1475
- var write = "write";
1476
- var afterWrite = "afterWrite";
1477
- var modifierPhases = [beforeRead, read, afterRead, beforeMain, main, afterMain, beforeWrite, write, afterWrite];
1478
- function getNodeName(element) {
1479
- return element ? (element.nodeName || "").toLowerCase() : null;
1480
- }
1481
- function getWindow(node) {
1482
- if (node == null) {
1483
- return window;
1454
+ class PopoverEntry extends CollectionEntry {
1455
+ constructor(context, query, options = {}) {
1456
+ super(context, query, options);
1457
+ __privateAdd(this, _eventListeners);
1458
+ __privateAdd(this, _isHovered);
1459
+ this.state = "closed";
1460
+ this.toggleDelayId = null;
1461
+ this.trigger = null;
1462
+ __privateSet(this, _eventListeners, null);
1463
+ __privateSet(this, _isHovered, {
1464
+ el: false,
1465
+ trigger: false
1466
+ });
1467
+ this.floatingCleanup = () => {
1468
+ };
1484
1469
  }
1485
- if (node.toString() !== "[object Window]") {
1486
- var ownerDocument = node.ownerDocument;
1487
- return ownerDocument ? ownerDocument.defaultView || window : window;
1470
+ get isTooltip() {
1471
+ return !!this.el.closest(this.getSetting("selectorTooltip")) || this.el.getAttribute("role") == "tooltip";
1488
1472
  }
1489
- return node;
1490
- }
1491
- function isElement(node) {
1492
- var OwnElement = getWindow(node).Element;
1493
- return node instanceof OwnElement || node instanceof Element;
1494
- }
1495
- function isHTMLElement(node) {
1496
- var OwnElement = getWindow(node).HTMLElement;
1497
- return node instanceof OwnElement || node instanceof HTMLElement;
1498
- }
1499
- function isShadowRoot(node) {
1500
- if (typeof ShadowRoot === "undefined") {
1501
- return false;
1473
+ get isHovered() {
1474
+ return __privateGet(this, _isHovered).el || __privateGet(this, _isHovered).trigger;
1502
1475
  }
1503
- var OwnElement = getWindow(node).ShadowRoot;
1504
- return node instanceof OwnElement || node instanceof ShadowRoot;
1505
- }
1506
- function applyStyles(_ref) {
1507
- var state = _ref.state;
1508
- Object.keys(state.elements).forEach(function(name) {
1509
- var style = state.styles[name] || {};
1510
- var attributes = state.attributes[name] || {};
1511
- var element = state.elements[name];
1512
- if (!isHTMLElement(element) || !getNodeName(element)) {
1513
- return;
1476
+ set isHovered(event) {
1477
+ const state = event.type == "mouseenter" ? true : event.type == "mouseleave" ? false : void 0;
1478
+ if (state == void 0) return;
1479
+ switch (event.target) {
1480
+ case this.el:
1481
+ __privateGet(this, _isHovered).el = state;
1482
+ break;
1483
+ case this.trigger:
1484
+ __privateGet(this, _isHovered).trigger = state;
1485
+ break;
1514
1486
  }
1515
- Object.assign(element.style, style);
1516
- Object.keys(attributes).forEach(function(name2) {
1517
- var value = attributes[name2];
1518
- if (value === false) {
1519
- element.removeAttribute(name2);
1487
+ }
1488
+ async open() {
1489
+ return this.context.open(this);
1490
+ }
1491
+ async close() {
1492
+ return this.context.close(this);
1493
+ }
1494
+ async deregister() {
1495
+ return this.context.deregister(this.id);
1496
+ }
1497
+ registerEventListeners() {
1498
+ if (!__privateGet(this, _eventListeners)) {
1499
+ const eventType = this.getSetting("event");
1500
+ if (eventType === "hover") {
1501
+ __privateSet(this, _eventListeners, [{
1502
+ el: ["el", "trigger"],
1503
+ type: ["mouseenter", "focus"],
1504
+ listener: handleMouseEnter.bind(this.context, this)
1505
+ }, {
1506
+ el: ["el", "trigger"],
1507
+ type: ["mouseleave", "focusout"],
1508
+ listener: handleMouseLeave.bind(this.context, this)
1509
+ }, {
1510
+ el: ["trigger"],
1511
+ type: ["click"],
1512
+ listener: handleTooltipClick.bind(this.context, this)
1513
+ }]);
1514
+ __privateGet(this, _eventListeners).forEach((evObj) => {
1515
+ evObj.el.forEach((el) => {
1516
+ evObj.type.forEach((type) => {
1517
+ this[el].addEventListener(type, evObj.listener, false);
1518
+ });
1519
+ });
1520
+ });
1520
1521
  } else {
1521
- element.setAttribute(name2, value === true ? "" : value);
1522
- }
1523
- });
1524
- });
1525
- }
1526
- function effect$2(_ref2) {
1527
- var state = _ref2.state;
1528
- var initialStyles = {
1529
- popper: {
1530
- position: state.options.strategy,
1531
- left: "0",
1532
- top: "0",
1533
- margin: "0"
1534
- },
1535
- arrow: {
1536
- position: "absolute"
1537
- },
1538
- reference: {}
1539
- };
1540
- Object.assign(state.elements.popper.style, initialStyles.popper);
1541
- state.styles = initialStyles;
1542
- if (state.elements.arrow) {
1543
- Object.assign(state.elements.arrow.style, initialStyles.arrow);
1544
- }
1545
- return function() {
1546
- Object.keys(state.elements).forEach(function(name) {
1547
- var element = state.elements[name];
1548
- var attributes = state.attributes[name] || {};
1549
- var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? state.styles[name] : initialStyles[name]);
1550
- var style = styleProperties.reduce(function(style2, property) {
1551
- style2[property] = "";
1552
- return style2;
1553
- }, {});
1554
- if (!isHTMLElement(element) || !getNodeName(element)) {
1555
- return;
1522
+ __privateSet(this, _eventListeners, [{
1523
+ el: ["trigger"],
1524
+ type: ["click"],
1525
+ listener: handleClick.bind(this.context, this)
1526
+ }]);
1527
+ __privateGet(this, _eventListeners).forEach((evObj) => {
1528
+ evObj.el.forEach((el) => {
1529
+ evObj.type.forEach((type) => {
1530
+ this[el].addEventListener(type, evObj.listener, false);
1531
+ });
1532
+ });
1533
+ });
1556
1534
  }
1557
- Object.assign(element.style, style);
1558
- Object.keys(attributes).forEach(function(attribute) {
1559
- element.removeAttribute(attribute);
1535
+ }
1536
+ }
1537
+ deregisterEventListeners() {
1538
+ if (__privateGet(this, _eventListeners)) {
1539
+ __privateGet(this, _eventListeners).forEach((evObj) => {
1540
+ evObj.el.forEach((el) => {
1541
+ evObj.type.forEach((type) => {
1542
+ this[el].removeEventListener(type, evObj.listener, false);
1543
+ });
1544
+ });
1560
1545
  });
1561
- });
1562
- };
1546
+ __privateSet(this, _eventListeners, null);
1547
+ }
1548
+ }
1549
+ async beforeMount() {
1550
+ this.trigger = document.querySelector(
1551
+ `[aria-controls="${this.id}"], [aria-describedby="${this.id}"]`
1552
+ );
1553
+ if (this.isTooltip) {
1554
+ this.settings.event = "hover";
1555
+ this.el.setAttribute("role", "tooltip");
1556
+ } else {
1557
+ this.trigger.setAttribute("aria-expanded", "false");
1558
+ }
1559
+ this.registerEventListeners();
1560
+ }
1561
+ async afterRegister() {
1562
+ if (this.el.classList.contains(this.getSetting("stateActive"))) {
1563
+ await this.open();
1564
+ } else {
1565
+ this.el.inert = true;
1566
+ }
1567
+ }
1568
+ async beforeUnmount() {
1569
+ if (this.state === "opened") {
1570
+ await this.close();
1571
+ }
1572
+ this.floatingCleanup();
1573
+ this.deregisterEventListeners();
1574
+ }
1563
1575
  }
1564
- const applyStyles$1 = {
1565
- name: "applyStyles",
1566
- enabled: true,
1567
- phase: "write",
1568
- fn: applyStyles,
1569
- effect: effect$2,
1570
- requires: ["computeStyles"]
1576
+ _eventListeners = new WeakMap();
1577
+ _isHovered = new WeakMap();
1578
+ const min = Math.min;
1579
+ const max = Math.max;
1580
+ const round = Math.round;
1581
+ const floor = Math.floor;
1582
+ const createCoords = (v) => ({
1583
+ x: v,
1584
+ y: v
1585
+ });
1586
+ const oppositeSideMap = {
1587
+ left: "right",
1588
+ right: "left",
1589
+ bottom: "top",
1590
+ top: "bottom"
1591
+ };
1592
+ const oppositeAlignmentMap = {
1593
+ start: "end",
1594
+ end: "start"
1571
1595
  };
1572
- function getBasePlacement(placement) {
1596
+ function clamp(start, value, end) {
1597
+ return max(start, min(value, end));
1598
+ }
1599
+ function evaluate(value, param) {
1600
+ return typeof value === "function" ? value(param) : value;
1601
+ }
1602
+ function getSide(placement) {
1573
1603
  return placement.split("-")[0];
1574
1604
  }
1575
- var max = Math.max;
1576
- var min = Math.min;
1577
- var round = Math.round;
1578
- function getUAString() {
1579
- var uaData = navigator.userAgentData;
1580
- if (uaData != null && uaData.brands && Array.isArray(uaData.brands)) {
1581
- return uaData.brands.map(function(item) {
1582
- return item.brand + "/" + item.version;
1583
- }).join(" ");
1584
- }
1585
- return navigator.userAgent;
1605
+ function getAlignment(placement) {
1606
+ return placement.split("-")[1];
1586
1607
  }
1587
- function isLayoutViewport() {
1588
- return !/^((?!chrome|android).)*safari/i.test(getUAString());
1608
+ function getOppositeAxis(axis) {
1609
+ return axis === "x" ? "y" : "x";
1589
1610
  }
1590
- function getBoundingClientRect(element, includeScale, isFixedStrategy) {
1591
- if (includeScale === void 0) {
1592
- includeScale = false;
1611
+ function getAxisLength(axis) {
1612
+ return axis === "y" ? "height" : "width";
1613
+ }
1614
+ function getSideAxis(placement) {
1615
+ return ["top", "bottom"].includes(getSide(placement)) ? "y" : "x";
1616
+ }
1617
+ function getAlignmentAxis(placement) {
1618
+ return getOppositeAxis(getSideAxis(placement));
1619
+ }
1620
+ function getAlignmentSides(placement, rects, rtl) {
1621
+ if (rtl === void 0) {
1622
+ rtl = false;
1623
+ }
1624
+ const alignment = getAlignment(placement);
1625
+ const alignmentAxis = getAlignmentAxis(placement);
1626
+ const length = getAxisLength(alignmentAxis);
1627
+ let mainAlignmentSide = alignmentAxis === "x" ? alignment === (rtl ? "end" : "start") ? "right" : "left" : alignment === "start" ? "bottom" : "top";
1628
+ if (rects.reference[length] > rects.floating[length]) {
1629
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
1630
+ }
1631
+ return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
1632
+ }
1633
+ function getExpandedPlacements(placement) {
1634
+ const oppositePlacement = getOppositePlacement(placement);
1635
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
1636
+ }
1637
+ function getOppositeAlignmentPlacement(placement) {
1638
+ return placement.replace(/start|end/g, (alignment) => oppositeAlignmentMap[alignment]);
1639
+ }
1640
+ function getSideList(side, isStart, rtl) {
1641
+ const lr = ["left", "right"];
1642
+ const rl = ["right", "left"];
1643
+ const tb = ["top", "bottom"];
1644
+ const bt = ["bottom", "top"];
1645
+ switch (side) {
1646
+ case "top":
1647
+ case "bottom":
1648
+ if (rtl) return isStart ? rl : lr;
1649
+ return isStart ? lr : rl;
1650
+ case "left":
1651
+ case "right":
1652
+ return isStart ? tb : bt;
1653
+ default:
1654
+ return [];
1593
1655
  }
1594
- if (isFixedStrategy === void 0) {
1595
- isFixedStrategy = false;
1656
+ }
1657
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
1658
+ const alignment = getAlignment(placement);
1659
+ let list = getSideList(getSide(placement), direction === "start", rtl);
1660
+ if (alignment) {
1661
+ list = list.map((side) => side + "-" + alignment);
1662
+ if (flipAlignment) {
1663
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
1664
+ }
1596
1665
  }
1597
- var clientRect = element.getBoundingClientRect();
1598
- var scaleX = 1;
1599
- var scaleY = 1;
1600
- if (includeScale && isHTMLElement(element)) {
1601
- scaleX = element.offsetWidth > 0 ? round(clientRect.width) / element.offsetWidth || 1 : 1;
1602
- scaleY = element.offsetHeight > 0 ? round(clientRect.height) / element.offsetHeight || 1 : 1;
1603
- }
1604
- var _ref = isElement(element) ? getWindow(element) : window, visualViewport = _ref.visualViewport;
1605
- var addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
1606
- var x = (clientRect.left + (addVisualOffsets && visualViewport ? visualViewport.offsetLeft : 0)) / scaleX;
1607
- var y = (clientRect.top + (addVisualOffsets && visualViewport ? visualViewport.offsetTop : 0)) / scaleY;
1608
- var width = clientRect.width / scaleX;
1609
- var height = clientRect.height / scaleY;
1666
+ return list;
1667
+ }
1668
+ function getOppositePlacement(placement) {
1669
+ return placement.replace(/left|right|bottom|top/g, (side) => oppositeSideMap[side]);
1670
+ }
1671
+ function expandPaddingObject(padding) {
1610
1672
  return {
1611
- width,
1612
- height,
1613
- top: y,
1614
- right: x + width,
1615
- bottom: y + height,
1673
+ top: 0,
1674
+ right: 0,
1675
+ bottom: 0,
1676
+ left: 0,
1677
+ ...padding
1678
+ };
1679
+ }
1680
+ function getPaddingObject(padding) {
1681
+ return typeof padding !== "number" ? expandPaddingObject(padding) : {
1682
+ top: padding,
1683
+ right: padding,
1684
+ bottom: padding,
1685
+ left: padding
1686
+ };
1687
+ }
1688
+ function rectToClientRect(rect) {
1689
+ const {
1690
+ x,
1691
+ y,
1692
+ width,
1693
+ height
1694
+ } = rect;
1695
+ return {
1696
+ width,
1697
+ height,
1698
+ top: y,
1616
1699
  left: x,
1700
+ right: x + width,
1701
+ bottom: y + height,
1617
1702
  x,
1618
1703
  y
1619
1704
  };
1620
1705
  }
1621
- function getLayoutRect(element) {
1622
- var clientRect = getBoundingClientRect(element);
1623
- var width = element.offsetWidth;
1624
- var height = element.offsetHeight;
1625
- if (Math.abs(clientRect.width - width) <= 1) {
1626
- width = clientRect.width;
1706
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
1707
+ let {
1708
+ reference,
1709
+ floating
1710
+ } = _ref;
1711
+ const sideAxis = getSideAxis(placement);
1712
+ const alignmentAxis = getAlignmentAxis(placement);
1713
+ const alignLength = getAxisLength(alignmentAxis);
1714
+ const side = getSide(placement);
1715
+ const isVertical = sideAxis === "y";
1716
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
1717
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
1718
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
1719
+ let coords;
1720
+ switch (side) {
1721
+ case "top":
1722
+ coords = {
1723
+ x: commonX,
1724
+ y: reference.y - floating.height
1725
+ };
1726
+ break;
1727
+ case "bottom":
1728
+ coords = {
1729
+ x: commonX,
1730
+ y: reference.y + reference.height
1731
+ };
1732
+ break;
1733
+ case "right":
1734
+ coords = {
1735
+ x: reference.x + reference.width,
1736
+ y: commonY
1737
+ };
1738
+ break;
1739
+ case "left":
1740
+ coords = {
1741
+ x: reference.x - floating.width,
1742
+ y: commonY
1743
+ };
1744
+ break;
1745
+ default:
1746
+ coords = {
1747
+ x: reference.x,
1748
+ y: reference.y
1749
+ };
1627
1750
  }
1628
- if (Math.abs(clientRect.height - height) <= 1) {
1629
- height = clientRect.height;
1751
+ switch (getAlignment(placement)) {
1752
+ case "start":
1753
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
1754
+ break;
1755
+ case "end":
1756
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
1757
+ break;
1758
+ }
1759
+ return coords;
1760
+ }
1761
+ const computePosition$1 = async (reference, floating, config) => {
1762
+ const {
1763
+ placement = "bottom",
1764
+ strategy = "absolute",
1765
+ middleware = [],
1766
+ platform: platform2
1767
+ } = config;
1768
+ const validMiddleware = middleware.filter(Boolean);
1769
+ const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(floating));
1770
+ let rects = await platform2.getElementRects({
1771
+ reference,
1772
+ floating,
1773
+ strategy
1774
+ });
1775
+ let {
1776
+ x,
1777
+ y
1778
+ } = computeCoordsFromPlacement(rects, placement, rtl);
1779
+ let statefulPlacement = placement;
1780
+ let middlewareData = {};
1781
+ let resetCount = 0;
1782
+ for (let i = 0; i < validMiddleware.length; i++) {
1783
+ const {
1784
+ name,
1785
+ fn
1786
+ } = validMiddleware[i];
1787
+ const {
1788
+ x: nextX,
1789
+ y: nextY,
1790
+ data,
1791
+ reset
1792
+ } = await fn({
1793
+ x,
1794
+ y,
1795
+ initialPlacement: placement,
1796
+ placement: statefulPlacement,
1797
+ strategy,
1798
+ middlewareData,
1799
+ rects,
1800
+ platform: platform2,
1801
+ elements: {
1802
+ reference,
1803
+ floating
1804
+ }
1805
+ });
1806
+ x = nextX != null ? nextX : x;
1807
+ y = nextY != null ? nextY : y;
1808
+ middlewareData = {
1809
+ ...middlewareData,
1810
+ [name]: {
1811
+ ...middlewareData[name],
1812
+ ...data
1813
+ }
1814
+ };
1815
+ if (reset && resetCount <= 50) {
1816
+ resetCount++;
1817
+ if (typeof reset === "object") {
1818
+ if (reset.placement) {
1819
+ statefulPlacement = reset.placement;
1820
+ }
1821
+ if (reset.rects) {
1822
+ rects = reset.rects === true ? await platform2.getElementRects({
1823
+ reference,
1824
+ floating,
1825
+ strategy
1826
+ }) : reset.rects;
1827
+ }
1828
+ ({
1829
+ x,
1830
+ y
1831
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
1832
+ }
1833
+ i = -1;
1834
+ }
1630
1835
  }
1631
1836
  return {
1632
- x: element.offsetLeft,
1633
- y: element.offsetTop,
1634
- width,
1635
- height
1837
+ x,
1838
+ y,
1839
+ placement: statefulPlacement,
1840
+ strategy,
1841
+ middlewareData
1842
+ };
1843
+ };
1844
+ async function detectOverflow(state, options) {
1845
+ var _await$platform$isEle;
1846
+ if (options === void 0) {
1847
+ options = {};
1848
+ }
1849
+ const {
1850
+ x,
1851
+ y,
1852
+ platform: platform2,
1853
+ rects,
1854
+ elements,
1855
+ strategy
1856
+ } = state;
1857
+ const {
1858
+ boundary = "clippingAncestors",
1859
+ rootBoundary = "viewport",
1860
+ elementContext = "floating",
1861
+ altBoundary = false,
1862
+ padding = 0
1863
+ } = evaluate(options, state);
1864
+ const paddingObject = getPaddingObject(padding);
1865
+ const altContext = elementContext === "floating" ? "reference" : "floating";
1866
+ const element = elements[altBoundary ? altContext : elementContext];
1867
+ const clippingClientRect = rectToClientRect(await platform2.getClippingRect({
1868
+ element: ((_await$platform$isEle = await (platform2.isElement == null ? void 0 : platform2.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || await (platform2.getDocumentElement == null ? void 0 : platform2.getDocumentElement(elements.floating)),
1869
+ boundary,
1870
+ rootBoundary,
1871
+ strategy
1872
+ }));
1873
+ const rect = elementContext === "floating" ? {
1874
+ x,
1875
+ y,
1876
+ width: rects.floating.width,
1877
+ height: rects.floating.height
1878
+ } : rects.reference;
1879
+ const offsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(elements.floating));
1880
+ const offsetScale = await (platform2.isElement == null ? void 0 : platform2.isElement(offsetParent)) ? await (platform2.getScale == null ? void 0 : platform2.getScale(offsetParent)) || {
1881
+ x: 1,
1882
+ y: 1
1883
+ } : {
1884
+ x: 1,
1885
+ y: 1
1886
+ };
1887
+ const elementClientRect = rectToClientRect(platform2.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform2.convertOffsetParentRelativeRectToViewportRelativeRect({
1888
+ elements,
1889
+ rect,
1890
+ offsetParent,
1891
+ strategy
1892
+ }) : rect);
1893
+ return {
1894
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
1895
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
1896
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
1897
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
1636
1898
  };
1637
1899
  }
1638
- function contains(parent, child) {
1639
- var rootNode = child.getRootNode && child.getRootNode();
1640
- if (parent.contains(child)) {
1641
- return true;
1642
- } else if (rootNode && isShadowRoot(rootNode)) {
1643
- var next = child;
1644
- do {
1645
- if (next && parent.isSameNode(next)) {
1646
- return true;
1900
+ const arrow$1 = (options) => ({
1901
+ name: "arrow",
1902
+ options,
1903
+ async fn(state) {
1904
+ const {
1905
+ x,
1906
+ y,
1907
+ placement,
1908
+ rects,
1909
+ platform: platform2,
1910
+ elements,
1911
+ middlewareData
1912
+ } = state;
1913
+ const {
1914
+ element,
1915
+ padding = 0
1916
+ } = evaluate(options, state) || {};
1917
+ if (element == null) {
1918
+ return {};
1919
+ }
1920
+ const paddingObject = getPaddingObject(padding);
1921
+ const coords = {
1922
+ x,
1923
+ y
1924
+ };
1925
+ const axis = getAlignmentAxis(placement);
1926
+ const length = getAxisLength(axis);
1927
+ const arrowDimensions = await platform2.getDimensions(element);
1928
+ const isYAxis = axis === "y";
1929
+ const minProp = isYAxis ? "top" : "left";
1930
+ const maxProp = isYAxis ? "bottom" : "right";
1931
+ const clientProp = isYAxis ? "clientHeight" : "clientWidth";
1932
+ const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
1933
+ const startDiff = coords[axis] - rects.reference[axis];
1934
+ const arrowOffsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(element));
1935
+ let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
1936
+ if (!clientSize || !await (platform2.isElement == null ? void 0 : platform2.isElement(arrowOffsetParent))) {
1937
+ clientSize = elements.floating[clientProp] || rects.floating[length];
1938
+ }
1939
+ const centerToReference = endDiff / 2 - startDiff / 2;
1940
+ const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
1941
+ const minPadding = min(paddingObject[minProp], largestPossiblePadding);
1942
+ const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
1943
+ const min$1 = minPadding;
1944
+ const max2 = clientSize - arrowDimensions[length] - maxPadding;
1945
+ const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
1946
+ const offset2 = clamp(min$1, center, max2);
1947
+ const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset2 && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
1948
+ const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max2 : 0;
1949
+ return {
1950
+ [axis]: coords[axis] + alignmentOffset,
1951
+ data: {
1952
+ [axis]: offset2,
1953
+ centerOffset: center - offset2 - alignmentOffset,
1954
+ ...shouldAddOffset && {
1955
+ alignmentOffset
1956
+ }
1957
+ },
1958
+ reset: shouldAddOffset
1959
+ };
1960
+ }
1961
+ });
1962
+ const flip$1 = function(options) {
1963
+ if (options === void 0) {
1964
+ options = {};
1965
+ }
1966
+ return {
1967
+ name: "flip",
1968
+ options,
1969
+ async fn(state) {
1970
+ var _middlewareData$arrow, _middlewareData$flip;
1971
+ const {
1972
+ placement,
1973
+ middlewareData,
1974
+ rects,
1975
+ initialPlacement,
1976
+ platform: platform2,
1977
+ elements
1978
+ } = state;
1979
+ const {
1980
+ mainAxis: checkMainAxis = true,
1981
+ crossAxis: checkCrossAxis = true,
1982
+ fallbackPlacements: specifiedFallbackPlacements,
1983
+ fallbackStrategy = "bestFit",
1984
+ fallbackAxisSideDirection = "none",
1985
+ flipAlignment = true,
1986
+ ...detectOverflowOptions
1987
+ } = evaluate(options, state);
1988
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
1989
+ return {};
1647
1990
  }
1648
- next = next.parentNode || next.host;
1649
- } while (next);
1991
+ const side = getSide(placement);
1992
+ const initialSideAxis = getSideAxis(initialPlacement);
1993
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
1994
+ const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
1995
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
1996
+ const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== "none";
1997
+ if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
1998
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
1999
+ }
2000
+ const placements = [initialPlacement, ...fallbackPlacements];
2001
+ const overflow = await detectOverflow(state, detectOverflowOptions);
2002
+ const overflows = [];
2003
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
2004
+ if (checkMainAxis) {
2005
+ overflows.push(overflow[side]);
2006
+ }
2007
+ if (checkCrossAxis) {
2008
+ const sides = getAlignmentSides(placement, rects, rtl);
2009
+ overflows.push(overflow[sides[0]], overflow[sides[1]]);
2010
+ }
2011
+ overflowsData = [...overflowsData, {
2012
+ placement,
2013
+ overflows
2014
+ }];
2015
+ if (!overflows.every((side2) => side2 <= 0)) {
2016
+ var _middlewareData$flip2, _overflowsData$filter;
2017
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
2018
+ const nextPlacement = placements[nextIndex];
2019
+ if (nextPlacement) {
2020
+ return {
2021
+ data: {
2022
+ index: nextIndex,
2023
+ overflows: overflowsData
2024
+ },
2025
+ reset: {
2026
+ placement: nextPlacement
2027
+ }
2028
+ };
2029
+ }
2030
+ let resetPlacement = (_overflowsData$filter = overflowsData.filter((d) => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
2031
+ if (!resetPlacement) {
2032
+ switch (fallbackStrategy) {
2033
+ case "bestFit": {
2034
+ var _overflowsData$filter2;
2035
+ const placement2 = (_overflowsData$filter2 = overflowsData.filter((d) => {
2036
+ if (hasFallbackAxisSideDirection) {
2037
+ const currentSideAxis = getSideAxis(d.placement);
2038
+ return currentSideAxis === initialSideAxis || // Create a bias to the `y` side axis due to horizontal
2039
+ // reading directions favoring greater width.
2040
+ currentSideAxis === "y";
2041
+ }
2042
+ return true;
2043
+ }).map((d) => [d.placement, d.overflows.filter((overflow2) => overflow2 > 0).reduce((acc, overflow2) => acc + overflow2, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0];
2044
+ if (placement2) {
2045
+ resetPlacement = placement2;
2046
+ }
2047
+ break;
2048
+ }
2049
+ case "initialPlacement":
2050
+ resetPlacement = initialPlacement;
2051
+ break;
2052
+ }
2053
+ }
2054
+ if (placement !== resetPlacement) {
2055
+ return {
2056
+ reset: {
2057
+ placement: resetPlacement
2058
+ }
2059
+ };
2060
+ }
2061
+ }
2062
+ return {};
2063
+ }
2064
+ };
2065
+ };
2066
+ async function convertValueToCoords(state, options) {
2067
+ const {
2068
+ placement,
2069
+ platform: platform2,
2070
+ elements
2071
+ } = state;
2072
+ const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
2073
+ const side = getSide(placement);
2074
+ const alignment = getAlignment(placement);
2075
+ const isVertical = getSideAxis(placement) === "y";
2076
+ const mainAxisMulti = ["left", "top"].includes(side) ? -1 : 1;
2077
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
2078
+ const rawValue = evaluate(options, state);
2079
+ let {
2080
+ mainAxis,
2081
+ crossAxis,
2082
+ alignmentAxis
2083
+ } = typeof rawValue === "number" ? {
2084
+ mainAxis: rawValue,
2085
+ crossAxis: 0,
2086
+ alignmentAxis: null
2087
+ } : {
2088
+ mainAxis: rawValue.mainAxis || 0,
2089
+ crossAxis: rawValue.crossAxis || 0,
2090
+ alignmentAxis: rawValue.alignmentAxis
2091
+ };
2092
+ if (alignment && typeof alignmentAxis === "number") {
2093
+ crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
1650
2094
  }
1651
- return false;
2095
+ return isVertical ? {
2096
+ x: crossAxis * crossAxisMulti,
2097
+ y: mainAxis * mainAxisMulti
2098
+ } : {
2099
+ x: mainAxis * mainAxisMulti,
2100
+ y: crossAxis * crossAxisMulti
2101
+ };
1652
2102
  }
1653
- function getComputedStyle$1(element) {
1654
- return getWindow(element).getComputedStyle(element);
2103
+ const offset$1 = function(options) {
2104
+ if (options === void 0) {
2105
+ options = 0;
2106
+ }
2107
+ return {
2108
+ name: "offset",
2109
+ options,
2110
+ async fn(state) {
2111
+ var _middlewareData$offse, _middlewareData$arrow;
2112
+ const {
2113
+ x,
2114
+ y,
2115
+ placement,
2116
+ middlewareData
2117
+ } = state;
2118
+ const diffCoords = await convertValueToCoords(state, options);
2119
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
2120
+ return {};
2121
+ }
2122
+ return {
2123
+ x: x + diffCoords.x,
2124
+ y: y + diffCoords.y,
2125
+ data: {
2126
+ ...diffCoords,
2127
+ placement
2128
+ }
2129
+ };
2130
+ }
2131
+ };
2132
+ };
2133
+ const shift$1 = function(options) {
2134
+ if (options === void 0) {
2135
+ options = {};
2136
+ }
2137
+ return {
2138
+ name: "shift",
2139
+ options,
2140
+ async fn(state) {
2141
+ const {
2142
+ x,
2143
+ y,
2144
+ placement
2145
+ } = state;
2146
+ const {
2147
+ mainAxis: checkMainAxis = true,
2148
+ crossAxis: checkCrossAxis = false,
2149
+ limiter = {
2150
+ fn: (_ref) => {
2151
+ let {
2152
+ x: x2,
2153
+ y: y2
2154
+ } = _ref;
2155
+ return {
2156
+ x: x2,
2157
+ y: y2
2158
+ };
2159
+ }
2160
+ },
2161
+ ...detectOverflowOptions
2162
+ } = evaluate(options, state);
2163
+ const coords = {
2164
+ x,
2165
+ y
2166
+ };
2167
+ const overflow = await detectOverflow(state, detectOverflowOptions);
2168
+ const crossAxis = getSideAxis(getSide(placement));
2169
+ const mainAxis = getOppositeAxis(crossAxis);
2170
+ let mainAxisCoord = coords[mainAxis];
2171
+ let crossAxisCoord = coords[crossAxis];
2172
+ if (checkMainAxis) {
2173
+ const minSide = mainAxis === "y" ? "top" : "left";
2174
+ const maxSide = mainAxis === "y" ? "bottom" : "right";
2175
+ const min2 = mainAxisCoord + overflow[minSide];
2176
+ const max2 = mainAxisCoord - overflow[maxSide];
2177
+ mainAxisCoord = clamp(min2, mainAxisCoord, max2);
2178
+ }
2179
+ if (checkCrossAxis) {
2180
+ const minSide = crossAxis === "y" ? "top" : "left";
2181
+ const maxSide = crossAxis === "y" ? "bottom" : "right";
2182
+ const min2 = crossAxisCoord + overflow[minSide];
2183
+ const max2 = crossAxisCoord - overflow[maxSide];
2184
+ crossAxisCoord = clamp(min2, crossAxisCoord, max2);
2185
+ }
2186
+ const limitedCoords = limiter.fn({
2187
+ ...state,
2188
+ [mainAxis]: mainAxisCoord,
2189
+ [crossAxis]: crossAxisCoord
2190
+ });
2191
+ return {
2192
+ ...limitedCoords,
2193
+ data: {
2194
+ x: limitedCoords.x - x,
2195
+ y: limitedCoords.y - y,
2196
+ enabled: {
2197
+ [mainAxis]: checkMainAxis,
2198
+ [crossAxis]: checkCrossAxis
2199
+ }
2200
+ }
2201
+ };
2202
+ }
2203
+ };
2204
+ };
2205
+ const limitShift$1 = function(options) {
2206
+ if (options === void 0) {
2207
+ options = {};
2208
+ }
2209
+ return {
2210
+ options,
2211
+ fn(state) {
2212
+ const {
2213
+ x,
2214
+ y,
2215
+ placement,
2216
+ rects,
2217
+ middlewareData
2218
+ } = state;
2219
+ const {
2220
+ offset: offset2 = 0,
2221
+ mainAxis: checkMainAxis = true,
2222
+ crossAxis: checkCrossAxis = true
2223
+ } = evaluate(options, state);
2224
+ const coords = {
2225
+ x,
2226
+ y
2227
+ };
2228
+ const crossAxis = getSideAxis(placement);
2229
+ const mainAxis = getOppositeAxis(crossAxis);
2230
+ let mainAxisCoord = coords[mainAxis];
2231
+ let crossAxisCoord = coords[crossAxis];
2232
+ const rawOffset = evaluate(offset2, state);
2233
+ const computedOffset = typeof rawOffset === "number" ? {
2234
+ mainAxis: rawOffset,
2235
+ crossAxis: 0
2236
+ } : {
2237
+ mainAxis: 0,
2238
+ crossAxis: 0,
2239
+ ...rawOffset
2240
+ };
2241
+ if (checkMainAxis) {
2242
+ const len = mainAxis === "y" ? "height" : "width";
2243
+ const limitMin = rects.reference[mainAxis] - rects.floating[len] + computedOffset.mainAxis;
2244
+ const limitMax = rects.reference[mainAxis] + rects.reference[len] - computedOffset.mainAxis;
2245
+ if (mainAxisCoord < limitMin) {
2246
+ mainAxisCoord = limitMin;
2247
+ } else if (mainAxisCoord > limitMax) {
2248
+ mainAxisCoord = limitMax;
2249
+ }
2250
+ }
2251
+ if (checkCrossAxis) {
2252
+ var _middlewareData$offse, _middlewareData$offse2;
2253
+ const len = mainAxis === "y" ? "width" : "height";
2254
+ const isOriginSide = ["top", "left"].includes(getSide(placement));
2255
+ const limitMin = rects.reference[crossAxis] - rects.floating[len] + (isOriginSide ? ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse[crossAxis]) || 0 : 0) + (isOriginSide ? 0 : computedOffset.crossAxis);
2256
+ const limitMax = rects.reference[crossAxis] + rects.reference[len] + (isOriginSide ? 0 : ((_middlewareData$offse2 = middlewareData.offset) == null ? void 0 : _middlewareData$offse2[crossAxis]) || 0) - (isOriginSide ? computedOffset.crossAxis : 0);
2257
+ if (crossAxisCoord < limitMin) {
2258
+ crossAxisCoord = limitMin;
2259
+ } else if (crossAxisCoord > limitMax) {
2260
+ crossAxisCoord = limitMax;
2261
+ }
2262
+ }
2263
+ return {
2264
+ [mainAxis]: mainAxisCoord,
2265
+ [crossAxis]: crossAxisCoord
2266
+ };
2267
+ }
2268
+ };
2269
+ };
2270
+ function hasWindow() {
2271
+ return typeof window !== "undefined";
1655
2272
  }
1656
- function isTableElement(element) {
1657
- return ["table", "td", "th"].indexOf(getNodeName(element)) >= 0;
1658
- }
1659
- function getDocumentElement(element) {
1660
- return ((isElement(element) ? element.ownerDocument : (
1661
- // $FlowFixMe[prop-missing]
1662
- element.document
1663
- )) || window.document).documentElement;
1664
- }
1665
- function getParentNode(element) {
1666
- if (getNodeName(element) === "html") {
1667
- return element;
1668
- }
1669
- return (
1670
- // this is a quicker (but less type safe) way to save quite some bytes from the bundle
1671
- // $FlowFixMe[incompatible-return]
1672
- // $FlowFixMe[prop-missing]
1673
- element.assignedSlot || // step into the shadow DOM of the parent of a slotted node
1674
- element.parentNode || // DOM Element detected
1675
- (isShadowRoot(element) ? element.host : null) || // ShadowRoot detected
1676
- // $FlowFixMe[incompatible-call]: HTMLElement is a Node
1677
- getDocumentElement(element)
1678
- );
2273
+ function getNodeName(node) {
2274
+ if (isNode(node)) {
2275
+ return (node.nodeName || "").toLowerCase();
2276
+ }
2277
+ return "#document";
1679
2278
  }
1680
- function getTrueOffsetParent(element) {
1681
- if (!isHTMLElement(element) || // https://github.com/popperjs/popper-core/issues/837
1682
- getComputedStyle$1(element).position === "fixed") {
1683
- return null;
2279
+ function getWindow(node) {
2280
+ var _node$ownerDocument;
2281
+ return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
2282
+ }
2283
+ function getDocumentElement(node) {
2284
+ var _ref;
2285
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
2286
+ }
2287
+ function isNode(value) {
2288
+ if (!hasWindow()) {
2289
+ return false;
1684
2290
  }
1685
- return element.offsetParent;
2291
+ return value instanceof Node || value instanceof getWindow(value).Node;
1686
2292
  }
1687
- function getContainingBlock(element) {
1688
- var isFirefox = /firefox/i.test(getUAString());
1689
- var isIE = /Trident/i.test(getUAString());
1690
- if (isIE && isHTMLElement(element)) {
1691
- var elementCss = getComputedStyle$1(element);
1692
- if (elementCss.position === "fixed") {
1693
- return null;
1694
- }
2293
+ function isElement(value) {
2294
+ if (!hasWindow()) {
2295
+ return false;
2296
+ }
2297
+ return value instanceof Element || value instanceof getWindow(value).Element;
2298
+ }
2299
+ function isHTMLElement(value) {
2300
+ if (!hasWindow()) {
2301
+ return false;
1695
2302
  }
1696
- var currentNode = getParentNode(element);
1697
- if (isShadowRoot(currentNode)) {
1698
- currentNode = currentNode.host;
2303
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
2304
+ }
2305
+ function isShadowRoot(value) {
2306
+ if (!hasWindow() || typeof ShadowRoot === "undefined") {
2307
+ return false;
1699
2308
  }
1700
- while (isHTMLElement(currentNode) && ["html", "body"].indexOf(getNodeName(currentNode)) < 0) {
1701
- var css = getComputedStyle$1(currentNode);
1702
- 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") {
2309
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
2310
+ }
2311
+ function isOverflowElement(element) {
2312
+ const {
2313
+ overflow,
2314
+ overflowX,
2315
+ overflowY,
2316
+ display
2317
+ } = getComputedStyle$1(element);
2318
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !["inline", "contents"].includes(display);
2319
+ }
2320
+ function isTableElement(element) {
2321
+ return ["table", "td", "th"].includes(getNodeName(element));
2322
+ }
2323
+ function isTopLayer(element) {
2324
+ return [":popover-open", ":modal"].some((selector) => {
2325
+ try {
2326
+ return element.matches(selector);
2327
+ } catch (e) {
2328
+ return false;
2329
+ }
2330
+ });
2331
+ }
2332
+ function isContainingBlock(elementOrCss) {
2333
+ const webkit = isWebKit();
2334
+ const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
2335
+ return css.transform !== "none" || css.perspective !== "none" || (css.containerType ? css.containerType !== "normal" : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== "none" : false) || !webkit && (css.filter ? css.filter !== "none" : false) || ["transform", "perspective", "filter"].some((value) => (css.willChange || "").includes(value)) || ["paint", "layout", "strict", "content"].some((value) => (css.contain || "").includes(value));
2336
+ }
2337
+ function getContainingBlock(element) {
2338
+ let currentNode = getParentNode(element);
2339
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
2340
+ if (isContainingBlock(currentNode)) {
1703
2341
  return currentNode;
1704
- } else {
1705
- currentNode = currentNode.parentNode;
2342
+ } else if (isTopLayer(currentNode)) {
2343
+ return null;
1706
2344
  }
2345
+ currentNode = getParentNode(currentNode);
1707
2346
  }
1708
2347
  return null;
1709
2348
  }
1710
- function getOffsetParent(element) {
1711
- var window2 = getWindow(element);
1712
- var offsetParent = getTrueOffsetParent(element);
1713
- while (offsetParent && isTableElement(offsetParent) && getComputedStyle$1(offsetParent).position === "static") {
1714
- offsetParent = getTrueOffsetParent(offsetParent);
1715
- }
1716
- if (offsetParent && (getNodeName(offsetParent) === "html" || getNodeName(offsetParent) === "body" && getComputedStyle$1(offsetParent).position === "static")) {
1717
- return window2;
1718
- }
1719
- return offsetParent || getContainingBlock(element) || window2;
2349
+ function isWebKit() {
2350
+ if (typeof CSS === "undefined" || !CSS.supports) return false;
2351
+ return CSS.supports("-webkit-backdrop-filter", "none");
1720
2352
  }
1721
- function getMainAxisFromPlacement(placement) {
1722
- return ["top", "bottom"].indexOf(placement) >= 0 ? "x" : "y";
2353
+ function isLastTraversableNode(node) {
2354
+ return ["html", "body", "#document"].includes(getNodeName(node));
1723
2355
  }
1724
- function within(min$1, value, max$1) {
1725
- return max(min$1, min(value, max$1));
1726
- }
1727
- function withinMaxClamp(min2, value, max2) {
1728
- var v = within(min2, value, max2);
1729
- return v > max2 ? max2 : v;
2356
+ function getComputedStyle$1(element) {
2357
+ return getWindow(element).getComputedStyle(element);
1730
2358
  }
1731
- function getFreshSideObject() {
2359
+ function getNodeScroll(element) {
2360
+ if (isElement(element)) {
2361
+ return {
2362
+ scrollLeft: element.scrollLeft,
2363
+ scrollTop: element.scrollTop
2364
+ };
2365
+ }
1732
2366
  return {
1733
- top: 0,
1734
- right: 0,
1735
- bottom: 0,
1736
- left: 0
2367
+ scrollLeft: element.scrollX,
2368
+ scrollTop: element.scrollY
1737
2369
  };
1738
2370
  }
1739
- function mergePaddingObject(paddingObject) {
1740
- return Object.assign({}, getFreshSideObject(), paddingObject);
1741
- }
1742
- function expandToHashMap(value, keys) {
1743
- return keys.reduce(function(hashMap, key) {
1744
- hashMap[key] = value;
1745
- return hashMap;
1746
- }, {});
2371
+ function getParentNode(node) {
2372
+ if (getNodeName(node) === "html") {
2373
+ return node;
2374
+ }
2375
+ const result = (
2376
+ // Step into the shadow DOM of the parent of a slotted node.
2377
+ node.assignedSlot || // DOM Element detected.
2378
+ node.parentNode || // ShadowRoot detected.
2379
+ isShadowRoot(node) && node.host || // Fallback.
2380
+ getDocumentElement(node)
2381
+ );
2382
+ return isShadowRoot(result) ? result.host : result;
1747
2383
  }
1748
- var toPaddingObject = function toPaddingObject2(padding, state) {
1749
- padding = typeof padding === "function" ? padding(Object.assign({}, state.rects, {
1750
- placement: state.placement
1751
- })) : padding;
1752
- return mergePaddingObject(typeof padding !== "number" ? padding : expandToHashMap(padding, basePlacements));
1753
- };
1754
- function arrow(_ref) {
1755
- var _state$modifiersData$;
1756
- var state = _ref.state, name = _ref.name, options = _ref.options;
1757
- var arrowElement = state.elements.arrow;
1758
- var popperOffsets2 = state.modifiersData.popperOffsets;
1759
- var basePlacement = getBasePlacement(state.placement);
1760
- var axis = getMainAxisFromPlacement(basePlacement);
1761
- var isVertical = [left, right].indexOf(basePlacement) >= 0;
1762
- var len = isVertical ? "height" : "width";
1763
- if (!arrowElement || !popperOffsets2) {
1764
- return;
2384
+ function getNearestOverflowAncestor(node) {
2385
+ const parentNode = getParentNode(node);
2386
+ if (isLastTraversableNode(parentNode)) {
2387
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
1765
2388
  }
1766
- var paddingObject = toPaddingObject(options.padding, state);
1767
- var arrowRect = getLayoutRect(arrowElement);
1768
- var minProp = axis === "y" ? top : left;
1769
- var maxProp = axis === "y" ? bottom : right;
1770
- var endDiff = state.rects.reference[len] + state.rects.reference[axis] - popperOffsets2[axis] - state.rects.popper[len];
1771
- var startDiff = popperOffsets2[axis] - state.rects.reference[axis];
1772
- var arrowOffsetParent = getOffsetParent(arrowElement);
1773
- var clientSize = arrowOffsetParent ? axis === "y" ? arrowOffsetParent.clientHeight || 0 : arrowOffsetParent.clientWidth || 0 : 0;
1774
- var centerToReference = endDiff / 2 - startDiff / 2;
1775
- var min2 = paddingObject[minProp];
1776
- var max2 = clientSize - arrowRect[len] - paddingObject[maxProp];
1777
- var center = clientSize / 2 - arrowRect[len] / 2 + centerToReference;
1778
- var offset2 = within(min2, center, max2);
1779
- var axisProp = axis;
1780
- state.modifiersData[name] = (_state$modifiersData$ = {}, _state$modifiersData$[axisProp] = offset2, _state$modifiersData$.centerOffset = offset2 - center, _state$modifiersData$);
1781
- }
1782
- function effect$1(_ref2) {
1783
- var state = _ref2.state, options = _ref2.options;
1784
- var _options$element = options.element, arrowElement = _options$element === void 0 ? "[data-popper-arrow]" : _options$element;
1785
- if (arrowElement == null) {
1786
- return;
2389
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
2390
+ return parentNode;
1787
2391
  }
1788
- if (typeof arrowElement === "string") {
1789
- arrowElement = state.elements.popper.querySelector(arrowElement);
1790
- if (!arrowElement) {
1791
- return;
1792
- }
2392
+ return getNearestOverflowAncestor(parentNode);
2393
+ }
2394
+ function getOverflowAncestors(node, list, traverseIframes) {
2395
+ var _node$ownerDocument2;
2396
+ if (list === void 0) {
2397
+ list = [];
1793
2398
  }
1794
- if (!contains(state.elements.popper, arrowElement)) {
1795
- return;
2399
+ if (traverseIframes === void 0) {
2400
+ traverseIframes = true;
2401
+ }
2402
+ const scrollableAncestor = getNearestOverflowAncestor(node);
2403
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
2404
+ const win = getWindow(scrollableAncestor);
2405
+ if (isBody) {
2406
+ const frameElement = getFrameElement(win);
2407
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
2408
+ }
2409
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
2410
+ }
2411
+ function getFrameElement(win) {
2412
+ return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
2413
+ }
2414
+ function getCssDimensions(element) {
2415
+ const css = getComputedStyle$1(element);
2416
+ let width = parseFloat(css.width) || 0;
2417
+ let height = parseFloat(css.height) || 0;
2418
+ const hasOffset = isHTMLElement(element);
2419
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
2420
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
2421
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
2422
+ if (shouldFallback) {
2423
+ width = offsetWidth;
2424
+ height = offsetHeight;
1796
2425
  }
1797
- state.elements.arrow = arrowElement;
1798
- }
1799
- const arrow$1 = {
1800
- name: "arrow",
1801
- enabled: true,
1802
- phase: "main",
1803
- fn: arrow,
1804
- effect: effect$1,
1805
- requires: ["popperOffsets"],
1806
- requiresIfExists: ["preventOverflow"]
1807
- };
1808
- function getVariation(placement) {
1809
- return placement.split("-")[1];
1810
- }
1811
- var unsetSides = {
1812
- top: "auto",
1813
- right: "auto",
1814
- bottom: "auto",
1815
- left: "auto"
1816
- };
1817
- function roundOffsetsByDPR(_ref, win) {
1818
- var x = _ref.x, y = _ref.y;
1819
- var dpr = win.devicePixelRatio || 1;
1820
2426
  return {
1821
- x: round(x * dpr) / dpr || 0,
1822
- y: round(y * dpr) / dpr || 0
2427
+ width,
2428
+ height,
2429
+ $: shouldFallback
1823
2430
  };
1824
2431
  }
1825
- function mapToStyles(_ref2) {
1826
- var _Object$assign2;
1827
- var popper2 = _ref2.popper, popperRect = _ref2.popperRect, placement = _ref2.placement, variation = _ref2.variation, offsets = _ref2.offsets, position = _ref2.position, gpuAcceleration = _ref2.gpuAcceleration, adaptive = _ref2.adaptive, roundOffsets = _ref2.roundOffsets, isFixed = _ref2.isFixed;
1828
- var _offsets$x = offsets.x, x = _offsets$x === void 0 ? 0 : _offsets$x, _offsets$y = offsets.y, y = _offsets$y === void 0 ? 0 : _offsets$y;
1829
- var _ref3 = typeof roundOffsets === "function" ? roundOffsets({
1830
- x,
1831
- y
1832
- }) : {
1833
- x,
1834
- y
1835
- };
1836
- x = _ref3.x;
1837
- y = _ref3.y;
1838
- var hasX = offsets.hasOwnProperty("x");
1839
- var hasY = offsets.hasOwnProperty("y");
1840
- var sideX = left;
1841
- var sideY = top;
1842
- var win = window;
1843
- if (adaptive) {
1844
- var offsetParent = getOffsetParent(popper2);
1845
- var heightProp = "clientHeight";
1846
- var widthProp = "clientWidth";
1847
- if (offsetParent === getWindow(popper2)) {
1848
- offsetParent = getDocumentElement(popper2);
1849
- if (getComputedStyle$1(offsetParent).position !== "static" && position === "absolute") {
1850
- heightProp = "scrollHeight";
1851
- widthProp = "scrollWidth";
1852
- }
1853
- }
1854
- offsetParent = offsetParent;
1855
- if (placement === top || (placement === left || placement === right) && variation === end) {
1856
- sideY = bottom;
1857
- var offsetY = isFixed && offsetParent === win && win.visualViewport ? win.visualViewport.height : (
1858
- // $FlowFixMe[prop-missing]
1859
- offsetParent[heightProp]
1860
- );
1861
- y -= offsetY - popperRect.height;
1862
- y *= gpuAcceleration ? 1 : -1;
1863
- }
1864
- if (placement === left || (placement === top || placement === bottom) && variation === end) {
1865
- sideX = right;
1866
- var offsetX = isFixed && offsetParent === win && win.visualViewport ? win.visualViewport.width : (
1867
- // $FlowFixMe[prop-missing]
1868
- offsetParent[widthProp]
1869
- );
1870
- x -= offsetX - popperRect.width;
1871
- x *= gpuAcceleration ? 1 : -1;
1872
- }
2432
+ function unwrapElement(element) {
2433
+ return !isElement(element) ? element.contextElement : element;
2434
+ }
2435
+ function getScale(element) {
2436
+ const domElement = unwrapElement(element);
2437
+ if (!isHTMLElement(domElement)) {
2438
+ return createCoords(1);
1873
2439
  }
1874
- var commonStyles = Object.assign({
1875
- position
1876
- }, adaptive && unsetSides);
1877
- var _ref4 = roundOffsets === true ? roundOffsetsByDPR({
1878
- x,
1879
- y
1880
- }, getWindow(popper2)) : {
2440
+ const rect = domElement.getBoundingClientRect();
2441
+ const {
2442
+ width,
2443
+ height,
2444
+ $
2445
+ } = getCssDimensions(domElement);
2446
+ let x = ($ ? round(rect.width) : rect.width) / width;
2447
+ let y = ($ ? round(rect.height) : rect.height) / height;
2448
+ if (!x || !Number.isFinite(x)) {
2449
+ x = 1;
2450
+ }
2451
+ if (!y || !Number.isFinite(y)) {
2452
+ y = 1;
2453
+ }
2454
+ return {
1881
2455
  x,
1882
2456
  y
1883
2457
  };
1884
- x = _ref4.x;
1885
- y = _ref4.y;
1886
- if (gpuAcceleration) {
1887
- var _Object$assign;
1888
- 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));
1889
- }
1890
- return Object.assign({}, commonStyles, (_Object$assign2 = {}, _Object$assign2[sideY] = hasY ? y + "px" : "", _Object$assign2[sideX] = hasX ? x + "px" : "", _Object$assign2.transform = "", _Object$assign2));
1891
- }
1892
- function computeStyles(_ref5) {
1893
- var state = _ref5.state, options = _ref5.options;
1894
- var _options$gpuAccelerat = options.gpuAcceleration, gpuAcceleration = _options$gpuAccelerat === void 0 ? true : _options$gpuAccelerat, _options$adaptive = options.adaptive, adaptive = _options$adaptive === void 0 ? true : _options$adaptive, _options$roundOffsets = options.roundOffsets, roundOffsets = _options$roundOffsets === void 0 ? true : _options$roundOffsets;
1895
- var commonStyles = {
1896
- placement: getBasePlacement(state.placement),
1897
- variation: getVariation(state.placement),
1898
- popper: state.elements.popper,
1899
- popperRect: state.rects.popper,
1900
- gpuAcceleration,
1901
- isFixed: state.options.strategy === "fixed"
2458
+ }
2459
+ const noOffsets = /* @__PURE__ */ createCoords(0);
2460
+ function getVisualOffsets(element) {
2461
+ const win = getWindow(element);
2462
+ if (!isWebKit() || !win.visualViewport) {
2463
+ return noOffsets;
2464
+ }
2465
+ return {
2466
+ x: win.visualViewport.offsetLeft,
2467
+ y: win.visualViewport.offsetTop
1902
2468
  };
1903
- if (state.modifiersData.popperOffsets != null) {
1904
- state.styles.popper = Object.assign({}, state.styles.popper, mapToStyles(Object.assign({}, commonStyles, {
1905
- offsets: state.modifiersData.popperOffsets,
1906
- position: state.options.strategy,
1907
- adaptive,
1908
- roundOffsets
1909
- })));
1910
- }
1911
- if (state.modifiersData.arrow != null) {
1912
- state.styles.arrow = Object.assign({}, state.styles.arrow, mapToStyles(Object.assign({}, commonStyles, {
1913
- offsets: state.modifiersData.arrow,
1914
- position: "absolute",
1915
- adaptive: false,
1916
- roundOffsets
1917
- })));
1918
- }
1919
- state.attributes.popper = Object.assign({}, state.attributes.popper, {
1920
- "data-popper-placement": state.placement
1921
- });
1922
2469
  }
1923
- const computeStyles$1 = {
1924
- name: "computeStyles",
1925
- enabled: true,
1926
- phase: "beforeWrite",
1927
- fn: computeStyles,
1928
- data: {}
1929
- };
1930
- var passive = {
1931
- passive: true
1932
- };
1933
- function effect(_ref) {
1934
- var state = _ref.state, instance = _ref.instance, options = _ref.options;
1935
- var _options$scroll = options.scroll, scroll = _options$scroll === void 0 ? true : _options$scroll, _options$resize = options.resize, resize = _options$resize === void 0 ? true : _options$resize;
1936
- var window2 = getWindow(state.elements.popper);
1937
- var scrollParents = [].concat(state.scrollParents.reference, state.scrollParents.popper);
1938
- if (scroll) {
1939
- scrollParents.forEach(function(scrollParent) {
1940
- scrollParent.addEventListener("scroll", instance.update, passive);
1941
- });
2470
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
2471
+ if (isFixed === void 0) {
2472
+ isFixed = false;
1942
2473
  }
1943
- if (resize) {
1944
- window2.addEventListener("resize", instance.update, passive);
2474
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
2475
+ return false;
1945
2476
  }
1946
- return function() {
1947
- if (scroll) {
1948
- scrollParents.forEach(function(scrollParent) {
1949
- scrollParent.removeEventListener("scroll", instance.update, passive);
1950
- });
2477
+ return isFixed;
2478
+ }
2479
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
2480
+ if (includeScale === void 0) {
2481
+ includeScale = false;
2482
+ }
2483
+ if (isFixedStrategy === void 0) {
2484
+ isFixedStrategy = false;
2485
+ }
2486
+ const clientRect = element.getBoundingClientRect();
2487
+ const domElement = unwrapElement(element);
2488
+ let scale = createCoords(1);
2489
+ if (includeScale) {
2490
+ if (offsetParent) {
2491
+ if (isElement(offsetParent)) {
2492
+ scale = getScale(offsetParent);
2493
+ }
2494
+ } else {
2495
+ scale = getScale(element);
2496
+ }
2497
+ }
2498
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
2499
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
2500
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
2501
+ let width = clientRect.width / scale.x;
2502
+ let height = clientRect.height / scale.y;
2503
+ if (domElement) {
2504
+ const win = getWindow(domElement);
2505
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
2506
+ let currentWin = win;
2507
+ let currentIFrame = getFrameElement(currentWin);
2508
+ while (currentIFrame && offsetParent && offsetWin !== currentWin) {
2509
+ const iframeScale = getScale(currentIFrame);
2510
+ const iframeRect = currentIFrame.getBoundingClientRect();
2511
+ const css = getComputedStyle$1(currentIFrame);
2512
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
2513
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
2514
+ x *= iframeScale.x;
2515
+ y *= iframeScale.y;
2516
+ width *= iframeScale.x;
2517
+ height *= iframeScale.y;
2518
+ x += left;
2519
+ y += top;
2520
+ currentWin = getWindow(currentIFrame);
2521
+ currentIFrame = getFrameElement(currentWin);
2522
+ }
2523
+ }
2524
+ return rectToClientRect({
2525
+ width,
2526
+ height,
2527
+ x,
2528
+ y
2529
+ });
2530
+ }
2531
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
2532
+ let {
2533
+ elements,
2534
+ rect,
2535
+ offsetParent,
2536
+ strategy
2537
+ } = _ref;
2538
+ const isFixed = strategy === "fixed";
2539
+ const documentElement = getDocumentElement(offsetParent);
2540
+ const topLayer = elements ? isTopLayer(elements.floating) : false;
2541
+ if (offsetParent === documentElement || topLayer && isFixed) {
2542
+ return rect;
2543
+ }
2544
+ let scroll = {
2545
+ scrollLeft: 0,
2546
+ scrollTop: 0
2547
+ };
2548
+ let scale = createCoords(1);
2549
+ const offsets = createCoords(0);
2550
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
2551
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
2552
+ if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
2553
+ scroll = getNodeScroll(offsetParent);
1951
2554
  }
1952
- if (resize) {
1953
- window2.removeEventListener("resize", instance.update, passive);
2555
+ if (isHTMLElement(offsetParent)) {
2556
+ const offsetRect = getBoundingClientRect(offsetParent);
2557
+ scale = getScale(offsetParent);
2558
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
2559
+ offsets.y = offsetRect.y + offsetParent.clientTop;
1954
2560
  }
2561
+ }
2562
+ return {
2563
+ width: rect.width * scale.x,
2564
+ height: rect.height * scale.y,
2565
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
2566
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
1955
2567
  };
1956
2568
  }
1957
- const eventListeners = {
1958
- name: "eventListeners",
1959
- enabled: true,
1960
- phase: "write",
1961
- fn: function fn() {
1962
- },
1963
- effect,
1964
- data: {}
1965
- };
1966
- var hash$1 = {
1967
- left: "right",
1968
- right: "left",
1969
- bottom: "top",
1970
- top: "bottom"
1971
- };
1972
- function getOppositePlacement(placement) {
1973
- return placement.replace(/left|right|bottom|top/g, function(matched) {
1974
- return hash$1[matched];
1975
- });
2569
+ function getClientRects(element) {
2570
+ return Array.from(element.getClientRects());
1976
2571
  }
1977
- var hash = {
1978
- start: "end",
1979
- end: "start"
1980
- };
1981
- function getOppositeVariationPlacement(placement) {
1982
- return placement.replace(/start|end/g, function(matched) {
1983
- return hash[matched];
1984
- });
2572
+ function getWindowScrollBarX(element, rect) {
2573
+ const leftScroll = getNodeScroll(element).scrollLeft;
2574
+ if (!rect) {
2575
+ return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
2576
+ }
2577
+ return rect.left + leftScroll;
1985
2578
  }
1986
- function getWindowScroll(node) {
1987
- var win = getWindow(node);
1988
- var scrollLeft = win.pageXOffset;
1989
- var scrollTop = win.pageYOffset;
2579
+ function getDocumentRect(element) {
2580
+ const html = getDocumentElement(element);
2581
+ const scroll = getNodeScroll(element);
2582
+ const body = element.ownerDocument.body;
2583
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
2584
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
2585
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
2586
+ const y = -scroll.scrollTop;
2587
+ if (getComputedStyle$1(body).direction === "rtl") {
2588
+ x += max(html.clientWidth, body.clientWidth) - width;
2589
+ }
1990
2590
  return {
1991
- scrollLeft,
1992
- scrollTop
2591
+ width,
2592
+ height,
2593
+ x,
2594
+ y
1993
2595
  };
1994
2596
  }
1995
- function getWindowScrollBarX(element) {
1996
- return getBoundingClientRect(getDocumentElement(element)).left + getWindowScroll(element).scrollLeft;
1997
- }
1998
2597
  function getViewportRect(element, strategy) {
1999
- var win = getWindow(element);
2000
- var html = getDocumentElement(element);
2001
- var visualViewport = win.visualViewport;
2002
- var width = html.clientWidth;
2003
- var height = html.clientHeight;
2004
- var x = 0;
2005
- var y = 0;
2598
+ const win = getWindow(element);
2599
+ const html = getDocumentElement(element);
2600
+ const visualViewport = win.visualViewport;
2601
+ let width = html.clientWidth;
2602
+ let height = html.clientHeight;
2603
+ let x = 0;
2604
+ let y = 0;
2006
2605
  if (visualViewport) {
2007
2606
  width = visualViewport.width;
2008
2607
  height = visualViewport.height;
2009
- var layoutViewport = isLayoutViewport();
2010
- if (layoutViewport || !layoutViewport && strategy === "fixed") {
2608
+ const visualViewportBased = isWebKit();
2609
+ if (!visualViewportBased || visualViewportBased && strategy === "fixed") {
2011
2610
  x = visualViewport.offsetLeft;
2012
2611
  y = visualViewport.offsetTop;
2013
2612
  }
@@ -2015,22 +2614,19 @@ function getViewportRect(element, strategy) {
2015
2614
  return {
2016
2615
  width,
2017
2616
  height,
2018
- x: x + getWindowScrollBarX(element),
2617
+ x,
2019
2618
  y
2020
2619
  };
2021
2620
  }
2022
- function getDocumentRect(element) {
2023
- var _element$ownerDocumen;
2024
- var html = getDocumentElement(element);
2025
- var winScroll = getWindowScroll(element);
2026
- var body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
2027
- var width = max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
2028
- var height = max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
2029
- var x = -winScroll.scrollLeft + getWindowScrollBarX(element);
2030
- var y = -winScroll.scrollTop;
2031
- if (getComputedStyle$1(body || html).direction === "rtl") {
2032
- x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
2033
- }
2621
+ function getInnerBoundingClientRect(element, strategy) {
2622
+ const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
2623
+ const top = clientRect.top + element.clientTop;
2624
+ const left = clientRect.left + element.clientLeft;
2625
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
2626
+ const width = element.clientWidth * scale.x;
2627
+ const height = element.clientHeight * scale.y;
2628
+ const x = left * scale.x;
2629
+ const y = top * scale.y;
2034
2630
  return {
2035
2631
  width,
2036
2632
  height,
@@ -2038,794 +2634,358 @@ function getDocumentRect(element) {
2038
2634
  y
2039
2635
  };
2040
2636
  }
2041
- function isScrollParent(element) {
2042
- var _getComputedStyle = getComputedStyle$1(element), overflow = _getComputedStyle.overflow, overflowX = _getComputedStyle.overflowX, overflowY = _getComputedStyle.overflowY;
2043
- return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
2044
- }
2045
- function getScrollParent(node) {
2046
- if (["html", "body", "#document"].indexOf(getNodeName(node)) >= 0) {
2047
- return node.ownerDocument.body;
2048
- }
2049
- if (isHTMLElement(node) && isScrollParent(node)) {
2050
- return node;
2637
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
2638
+ let rect;
2639
+ if (clippingAncestor === "viewport") {
2640
+ rect = getViewportRect(element, strategy);
2641
+ } else if (clippingAncestor === "document") {
2642
+ rect = getDocumentRect(getDocumentElement(element));
2643
+ } else if (isElement(clippingAncestor)) {
2644
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
2645
+ } else {
2646
+ const visualOffsets = getVisualOffsets(element);
2647
+ rect = {
2648
+ ...clippingAncestor,
2649
+ x: clippingAncestor.x - visualOffsets.x,
2650
+ y: clippingAncestor.y - visualOffsets.y
2651
+ };
2051
2652
  }
2052
- return getScrollParent(getParentNode(node));
2653
+ return rectToClientRect(rect);
2053
2654
  }
2054
- function listScrollParents(element, list) {
2055
- var _element$ownerDocumen;
2056
- if (list === void 0) {
2057
- list = [];
2655
+ function hasFixedPositionAncestor(element, stopNode) {
2656
+ const parentNode = getParentNode(element);
2657
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
2658
+ return false;
2058
2659
  }
2059
- var scrollParent = getScrollParent(element);
2060
- var isBody = scrollParent === ((_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body);
2061
- var win = getWindow(scrollParent);
2062
- var target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
2063
- var updatedList = list.concat(target);
2064
- return isBody ? updatedList : (
2065
- // $FlowFixMe[incompatible-call]: isBody tells us target will be an HTMLElement here
2066
- updatedList.concat(listScrollParents(getParentNode(target)))
2067
- );
2068
- }
2069
- function rectToClientRect(rect) {
2070
- return Object.assign({}, rect, {
2071
- left: rect.x,
2072
- top: rect.y,
2073
- right: rect.x + rect.width,
2074
- bottom: rect.y + rect.height
2075
- });
2076
- }
2077
- function getInnerBoundingClientRect(element, strategy) {
2078
- var rect = getBoundingClientRect(element, false, strategy === "fixed");
2079
- rect.top = rect.top + element.clientTop;
2080
- rect.left = rect.left + element.clientLeft;
2081
- rect.bottom = rect.top + element.clientHeight;
2082
- rect.right = rect.left + element.clientWidth;
2083
- rect.width = element.clientWidth;
2084
- rect.height = element.clientHeight;
2085
- rect.x = rect.left;
2086
- rect.y = rect.top;
2087
- return rect;
2088
- }
2089
- function getClientRectFromMixedType(element, clippingParent, strategy) {
2090
- return clippingParent === viewport ? rectToClientRect(getViewportRect(element, strategy)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent, strategy) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
2091
- }
2092
- function getClippingParents(element) {
2093
- var clippingParents2 = listScrollParents(getParentNode(element));
2094
- var canEscapeClipping = ["absolute", "fixed"].indexOf(getComputedStyle$1(element).position) >= 0;
2095
- var clipperElement = canEscapeClipping && isHTMLElement(element) ? getOffsetParent(element) : element;
2096
- if (!isElement(clipperElement)) {
2097
- return [];
2098
- }
2099
- return clippingParents2.filter(function(clippingParent) {
2100
- return isElement(clippingParent) && contains(clippingParent, clipperElement) && getNodeName(clippingParent) !== "body";
2101
- });
2660
+ return getComputedStyle$1(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
2661
+ }
2662
+ function getClippingElementAncestors(element, cache) {
2663
+ const cachedResult = cache.get(element);
2664
+ if (cachedResult) {
2665
+ return cachedResult;
2666
+ }
2667
+ let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
2668
+ let currentContainingBlockComputedStyle = null;
2669
+ const elementIsFixed = getComputedStyle$1(element).position === "fixed";
2670
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
2671
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
2672
+ const computedStyle = getComputedStyle$1(currentNode);
2673
+ const currentNodeIsContaining = isContainingBlock(currentNode);
2674
+ if (!currentNodeIsContaining && computedStyle.position === "fixed") {
2675
+ currentContainingBlockComputedStyle = null;
2676
+ }
2677
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && ["absolute", "fixed"].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
2678
+ if (shouldDropCurrentNode) {
2679
+ result = result.filter((ancestor) => ancestor !== currentNode);
2680
+ } else {
2681
+ currentContainingBlockComputedStyle = computedStyle;
2682
+ }
2683
+ currentNode = getParentNode(currentNode);
2684
+ }
2685
+ cache.set(element, result);
2686
+ return result;
2102
2687
  }
2103
- function getClippingRect(element, boundary, rootBoundary, strategy) {
2104
- var mainClippingParents = boundary === "clippingParents" ? getClippingParents(element) : [].concat(boundary);
2105
- var clippingParents2 = [].concat(mainClippingParents, [rootBoundary]);
2106
- var firstClippingParent = clippingParents2[0];
2107
- var clippingRect = clippingParents2.reduce(function(accRect, clippingParent) {
2108
- var rect = getClientRectFromMixedType(element, clippingParent, strategy);
2688
+ function getClippingRect(_ref) {
2689
+ let {
2690
+ element,
2691
+ boundary,
2692
+ rootBoundary,
2693
+ strategy
2694
+ } = _ref;
2695
+ const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
2696
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
2697
+ const firstClippingAncestor = clippingAncestors[0];
2698
+ const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
2699
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
2109
2700
  accRect.top = max(rect.top, accRect.top);
2110
2701
  accRect.right = min(rect.right, accRect.right);
2111
2702
  accRect.bottom = min(rect.bottom, accRect.bottom);
2112
2703
  accRect.left = max(rect.left, accRect.left);
2113
2704
  return accRect;
2114
- }, getClientRectFromMixedType(element, firstClippingParent, strategy));
2115
- clippingRect.width = clippingRect.right - clippingRect.left;
2116
- clippingRect.height = clippingRect.bottom - clippingRect.top;
2117
- clippingRect.x = clippingRect.left;
2118
- clippingRect.y = clippingRect.top;
2119
- return clippingRect;
2120
- }
2121
- function computeOffsets(_ref) {
2122
- var reference2 = _ref.reference, element = _ref.element, placement = _ref.placement;
2123
- var basePlacement = placement ? getBasePlacement(placement) : null;
2124
- var variation = placement ? getVariation(placement) : null;
2125
- var commonX = reference2.x + reference2.width / 2 - element.width / 2;
2126
- var commonY = reference2.y + reference2.height / 2 - element.height / 2;
2127
- var offsets;
2128
- switch (basePlacement) {
2129
- case top:
2130
- offsets = {
2131
- x: commonX,
2132
- y: reference2.y - element.height
2133
- };
2134
- break;
2135
- case bottom:
2136
- offsets = {
2137
- x: commonX,
2138
- y: reference2.y + reference2.height
2139
- };
2140
- break;
2141
- case right:
2142
- offsets = {
2143
- x: reference2.x + reference2.width,
2144
- y: commonY
2145
- };
2146
- break;
2147
- case left:
2148
- offsets = {
2149
- x: reference2.x - element.width,
2150
- y: commonY
2151
- };
2152
- break;
2153
- default:
2154
- offsets = {
2155
- x: reference2.x,
2156
- y: reference2.y
2157
- };
2158
- }
2159
- var mainAxis = basePlacement ? getMainAxisFromPlacement(basePlacement) : null;
2160
- if (mainAxis != null) {
2161
- var len = mainAxis === "y" ? "height" : "width";
2162
- switch (variation) {
2163
- case start:
2164
- offsets[mainAxis] = offsets[mainAxis] - (reference2[len] / 2 - element[len] / 2);
2165
- break;
2166
- case end:
2167
- offsets[mainAxis] = offsets[mainAxis] + (reference2[len] / 2 - element[len] / 2);
2168
- break;
2169
- }
2170
- }
2171
- return offsets;
2172
- }
2173
- function detectOverflow(state, options) {
2174
- if (options === void 0) {
2175
- options = {};
2176
- }
2177
- var _options = options, _options$placement = _options.placement, placement = _options$placement === void 0 ? state.placement : _options$placement, _options$strategy = _options.strategy, strategy = _options$strategy === void 0 ? state.strategy : _options$strategy, _options$boundary = _options.boundary, boundary = _options$boundary === void 0 ? clippingParents : _options$boundary, _options$rootBoundary = _options.rootBoundary, rootBoundary = _options$rootBoundary === void 0 ? viewport : _options$rootBoundary, _options$elementConte = _options.elementContext, elementContext = _options$elementConte === void 0 ? popper : _options$elementConte, _options$altBoundary = _options.altBoundary, altBoundary = _options$altBoundary === void 0 ? false : _options$altBoundary, _options$padding = _options.padding, padding = _options$padding === void 0 ? 0 : _options$padding;
2178
- var paddingObject = mergePaddingObject(typeof padding !== "number" ? padding : expandToHashMap(padding, basePlacements));
2179
- var altContext = elementContext === popper ? reference : popper;
2180
- var popperRect = state.rects.popper;
2181
- var element = state.elements[altBoundary ? altContext : elementContext];
2182
- var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary, strategy);
2183
- var referenceClientRect = getBoundingClientRect(state.elements.reference);
2184
- var popperOffsets2 = computeOffsets({
2185
- reference: referenceClientRect,
2186
- element: popperRect,
2187
- strategy: "absolute",
2188
- placement
2189
- });
2190
- var popperClientRect = rectToClientRect(Object.assign({}, popperRect, popperOffsets2));
2191
- var elementClientRect = elementContext === popper ? popperClientRect : referenceClientRect;
2192
- var overflowOffsets = {
2193
- top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
2194
- bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
2195
- left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
2196
- right: elementClientRect.right - clippingClientRect.right + paddingObject.right
2197
- };
2198
- var offsetData = state.modifiersData.offset;
2199
- if (elementContext === popper && offsetData) {
2200
- var offset2 = offsetData[placement];
2201
- Object.keys(overflowOffsets).forEach(function(key) {
2202
- var multiply = [right, bottom].indexOf(key) >= 0 ? 1 : -1;
2203
- var axis = [top, bottom].indexOf(key) >= 0 ? "y" : "x";
2204
- overflowOffsets[key] += offset2[axis] * multiply;
2205
- });
2206
- }
2207
- return overflowOffsets;
2208
- }
2209
- function computeAutoPlacement(state, options) {
2210
- if (options === void 0) {
2211
- options = {};
2212
- }
2213
- var _options = options, placement = _options.placement, boundary = _options.boundary, rootBoundary = _options.rootBoundary, padding = _options.padding, flipVariations = _options.flipVariations, _options$allowedAutoP = _options.allowedAutoPlacements, allowedAutoPlacements = _options$allowedAutoP === void 0 ? placements : _options$allowedAutoP;
2214
- var variation = getVariation(placement);
2215
- var placements$1 = variation ? flipVariations ? variationPlacements : variationPlacements.filter(function(placement2) {
2216
- return getVariation(placement2) === variation;
2217
- }) : basePlacements;
2218
- var allowedPlacements = placements$1.filter(function(placement2) {
2219
- return allowedAutoPlacements.indexOf(placement2) >= 0;
2220
- });
2221
- if (allowedPlacements.length === 0) {
2222
- allowedPlacements = placements$1;
2223
- }
2224
- var overflows = allowedPlacements.reduce(function(acc, placement2) {
2225
- acc[placement2] = detectOverflow(state, {
2226
- placement: placement2,
2227
- boundary,
2228
- rootBoundary,
2229
- padding
2230
- })[getBasePlacement(placement2)];
2231
- return acc;
2232
- }, {});
2233
- return Object.keys(overflows).sort(function(a, b) {
2234
- return overflows[a] - overflows[b];
2235
- });
2236
- }
2237
- function getExpandedFallbackPlacements(placement) {
2238
- if (getBasePlacement(placement) === auto) {
2239
- return [];
2240
- }
2241
- var oppositePlacement = getOppositePlacement(placement);
2242
- return [getOppositeVariationPlacement(placement), oppositePlacement, getOppositeVariationPlacement(oppositePlacement)];
2243
- }
2244
- function flip(_ref) {
2245
- var state = _ref.state, options = _ref.options, name = _ref.name;
2246
- if (state.modifiersData[name]._skip) {
2247
- return;
2248
- }
2249
- var _options$mainAxis = options.mainAxis, checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis, _options$altAxis = options.altAxis, checkAltAxis = _options$altAxis === void 0 ? true : _options$altAxis, specifiedFallbackPlacements = options.fallbackPlacements, padding = options.padding, boundary = options.boundary, rootBoundary = options.rootBoundary, altBoundary = options.altBoundary, _options$flipVariatio = options.flipVariations, flipVariations = _options$flipVariatio === void 0 ? true : _options$flipVariatio, allowedAutoPlacements = options.allowedAutoPlacements;
2250
- var preferredPlacement = state.options.placement;
2251
- var basePlacement = getBasePlacement(preferredPlacement);
2252
- var isBasePlacement = basePlacement === preferredPlacement;
2253
- var fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipVariations ? [getOppositePlacement(preferredPlacement)] : getExpandedFallbackPlacements(preferredPlacement));
2254
- var placements2 = [preferredPlacement].concat(fallbackPlacements).reduce(function(acc, placement2) {
2255
- return acc.concat(getBasePlacement(placement2) === auto ? computeAutoPlacement(state, {
2256
- placement: placement2,
2257
- boundary,
2258
- rootBoundary,
2259
- padding,
2260
- flipVariations,
2261
- allowedAutoPlacements
2262
- }) : placement2);
2263
- }, []);
2264
- var referenceRect = state.rects.reference;
2265
- var popperRect = state.rects.popper;
2266
- var checksMap = /* @__PURE__ */ new Map();
2267
- var makeFallbackChecks = true;
2268
- var firstFittingPlacement = placements2[0];
2269
- for (var i = 0; i < placements2.length; i++) {
2270
- var placement = placements2[i];
2271
- var _basePlacement = getBasePlacement(placement);
2272
- var isStartVariation = getVariation(placement) === start;
2273
- var isVertical = [top, bottom].indexOf(_basePlacement) >= 0;
2274
- var len = isVertical ? "width" : "height";
2275
- var overflow = detectOverflow(state, {
2276
- placement,
2277
- boundary,
2278
- rootBoundary,
2279
- altBoundary,
2280
- padding
2281
- });
2282
- var mainVariationSide = isVertical ? isStartVariation ? right : left : isStartVariation ? bottom : top;
2283
- if (referenceRect[len] > popperRect[len]) {
2284
- mainVariationSide = getOppositePlacement(mainVariationSide);
2285
- }
2286
- var altVariationSide = getOppositePlacement(mainVariationSide);
2287
- var checks = [];
2288
- if (checkMainAxis) {
2289
- checks.push(overflow[_basePlacement] <= 0);
2290
- }
2291
- if (checkAltAxis) {
2292
- checks.push(overflow[mainVariationSide] <= 0, overflow[altVariationSide] <= 0);
2293
- }
2294
- if (checks.every(function(check) {
2295
- return check;
2296
- })) {
2297
- firstFittingPlacement = placement;
2298
- makeFallbackChecks = false;
2299
- break;
2300
- }
2301
- checksMap.set(placement, checks);
2302
- }
2303
- if (makeFallbackChecks) {
2304
- var numberOfChecks = flipVariations ? 3 : 1;
2305
- var _loop = function _loop2(_i2) {
2306
- var fittingPlacement = placements2.find(function(placement2) {
2307
- var checks2 = checksMap.get(placement2);
2308
- if (checks2) {
2309
- return checks2.slice(0, _i2).every(function(check) {
2310
- return check;
2311
- });
2312
- }
2313
- });
2314
- if (fittingPlacement) {
2315
- firstFittingPlacement = fittingPlacement;
2316
- return "break";
2317
- }
2318
- };
2319
- for (var _i = numberOfChecks; _i > 0; _i--) {
2320
- var _ret = _loop(_i);
2321
- if (_ret === "break") break;
2322
- }
2323
- }
2324
- if (state.placement !== firstFittingPlacement) {
2325
- state.modifiersData[name]._skip = true;
2326
- state.placement = firstFittingPlacement;
2327
- state.reset = true;
2328
- }
2329
- }
2330
- const flip$1 = {
2331
- name: "flip",
2332
- enabled: true,
2333
- phase: "main",
2334
- fn: flip,
2335
- requiresIfExists: ["offset"],
2336
- data: {
2337
- _skip: false
2338
- }
2339
- };
2340
- function getSideOffsets(overflow, rect, preventedOffsets) {
2341
- if (preventedOffsets === void 0) {
2342
- preventedOffsets = {
2343
- x: 0,
2344
- y: 0
2345
- };
2346
- }
2705
+ }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
2347
2706
  return {
2348
- top: overflow.top - rect.height - preventedOffsets.y,
2349
- right: overflow.right - rect.width + preventedOffsets.x,
2350
- bottom: overflow.bottom - rect.height + preventedOffsets.y,
2351
- left: overflow.left - rect.width - preventedOffsets.x
2352
- };
2353
- }
2354
- function isAnySideFullyClipped(overflow) {
2355
- return [top, right, bottom, left].some(function(side) {
2356
- return overflow[side] >= 0;
2357
- });
2358
- }
2359
- function hide(_ref) {
2360
- var state = _ref.state, name = _ref.name;
2361
- var referenceRect = state.rects.reference;
2362
- var popperRect = state.rects.popper;
2363
- var preventedOffsets = state.modifiersData.preventOverflow;
2364
- var referenceOverflow = detectOverflow(state, {
2365
- elementContext: "reference"
2366
- });
2367
- var popperAltOverflow = detectOverflow(state, {
2368
- altBoundary: true
2369
- });
2370
- var referenceClippingOffsets = getSideOffsets(referenceOverflow, referenceRect);
2371
- var popperEscapeOffsets = getSideOffsets(popperAltOverflow, popperRect, preventedOffsets);
2372
- var isReferenceHidden = isAnySideFullyClipped(referenceClippingOffsets);
2373
- var hasPopperEscaped = isAnySideFullyClipped(popperEscapeOffsets);
2374
- state.modifiersData[name] = {
2375
- referenceClippingOffsets,
2376
- popperEscapeOffsets,
2377
- isReferenceHidden,
2378
- hasPopperEscaped
2707
+ width: clippingRect.right - clippingRect.left,
2708
+ height: clippingRect.bottom - clippingRect.top,
2709
+ x: clippingRect.left,
2710
+ y: clippingRect.top
2379
2711
  };
2380
- state.attributes.popper = Object.assign({}, state.attributes.popper, {
2381
- "data-popper-reference-hidden": isReferenceHidden,
2382
- "data-popper-escaped": hasPopperEscaped
2383
- });
2384
- }
2385
- const hide$1 = {
2386
- name: "hide",
2387
- enabled: true,
2388
- phase: "main",
2389
- requiresIfExists: ["preventOverflow"],
2390
- fn: hide
2391
- };
2392
- function distanceAndSkiddingToXY(placement, rects, offset2) {
2393
- var basePlacement = getBasePlacement(placement);
2394
- var invertDistance = [left, top].indexOf(basePlacement) >= 0 ? -1 : 1;
2395
- var _ref = typeof offset2 === "function" ? offset2(Object.assign({}, rects, {
2396
- placement
2397
- })) : offset2, skidding = _ref[0], distance = _ref[1];
2398
- skidding = skidding || 0;
2399
- distance = (distance || 0) * invertDistance;
2400
- return [left, right].indexOf(basePlacement) >= 0 ? {
2401
- x: distance,
2402
- y: skidding
2403
- } : {
2404
- x: skidding,
2405
- y: distance
2406
- };
2407
- }
2408
- function offset(_ref2) {
2409
- var state = _ref2.state, options = _ref2.options, name = _ref2.name;
2410
- var _options$offset = options.offset, offset2 = _options$offset === void 0 ? [0, 0] : _options$offset;
2411
- var data = placements.reduce(function(acc, placement) {
2412
- acc[placement] = distanceAndSkiddingToXY(placement, state.rects, offset2);
2413
- return acc;
2414
- }, {});
2415
- var _data$state$placement = data[state.placement], x = _data$state$placement.x, y = _data$state$placement.y;
2416
- if (state.modifiersData.popperOffsets != null) {
2417
- state.modifiersData.popperOffsets.x += x;
2418
- state.modifiersData.popperOffsets.y += y;
2419
- }
2420
- state.modifiersData[name] = data;
2421
- }
2422
- const offset$1 = {
2423
- name: "offset",
2424
- enabled: true,
2425
- phase: "main",
2426
- requires: ["popperOffsets"],
2427
- fn: offset
2428
- };
2429
- function popperOffsets(_ref) {
2430
- var state = _ref.state, name = _ref.name;
2431
- state.modifiersData[name] = computeOffsets({
2432
- reference: state.rects.reference,
2433
- element: state.rects.popper,
2434
- strategy: "absolute",
2435
- placement: state.placement
2436
- });
2437
2712
  }
2438
- const popperOffsets$1 = {
2439
- name: "popperOffsets",
2440
- enabled: true,
2441
- phase: "read",
2442
- fn: popperOffsets,
2443
- data: {}
2444
- };
2445
- function getAltAxis(axis) {
2446
- return axis === "x" ? "y" : "x";
2447
- }
2448
- function preventOverflow(_ref) {
2449
- var state = _ref.state, options = _ref.options, name = _ref.name;
2450
- var _options$mainAxis = options.mainAxis, checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis, _options$altAxis = options.altAxis, checkAltAxis = _options$altAxis === void 0 ? false : _options$altAxis, boundary = options.boundary, rootBoundary = options.rootBoundary, altBoundary = options.altBoundary, padding = options.padding, _options$tether = options.tether, tether = _options$tether === void 0 ? true : _options$tether, _options$tetherOffset = options.tetherOffset, tetherOffset = _options$tetherOffset === void 0 ? 0 : _options$tetherOffset;
2451
- var overflow = detectOverflow(state, {
2452
- boundary,
2453
- rootBoundary,
2454
- padding,
2455
- altBoundary
2456
- });
2457
- var basePlacement = getBasePlacement(state.placement);
2458
- var variation = getVariation(state.placement);
2459
- var isBasePlacement = !variation;
2460
- var mainAxis = getMainAxisFromPlacement(basePlacement);
2461
- var altAxis = getAltAxis(mainAxis);
2462
- var popperOffsets2 = state.modifiersData.popperOffsets;
2463
- var referenceRect = state.rects.reference;
2464
- var popperRect = state.rects.popper;
2465
- var tetherOffsetValue = typeof tetherOffset === "function" ? tetherOffset(Object.assign({}, state.rects, {
2466
- placement: state.placement
2467
- })) : tetherOffset;
2468
- var normalizedTetherOffsetValue = typeof tetherOffsetValue === "number" ? {
2469
- mainAxis: tetherOffsetValue,
2470
- altAxis: tetherOffsetValue
2471
- } : Object.assign({
2472
- mainAxis: 0,
2473
- altAxis: 0
2474
- }, tetherOffsetValue);
2475
- var offsetModifierState = state.modifiersData.offset ? state.modifiersData.offset[state.placement] : null;
2476
- var data = {
2477
- x: 0,
2478
- y: 0
2479
- };
2480
- if (!popperOffsets2) {
2481
- return;
2482
- }
2483
- if (checkMainAxis) {
2484
- var _offsetModifierState$;
2485
- var mainSide = mainAxis === "y" ? top : left;
2486
- var altSide = mainAxis === "y" ? bottom : right;
2487
- var len = mainAxis === "y" ? "height" : "width";
2488
- var offset2 = popperOffsets2[mainAxis];
2489
- var min$1 = offset2 + overflow[mainSide];
2490
- var max$1 = offset2 - overflow[altSide];
2491
- var additive = tether ? -popperRect[len] / 2 : 0;
2492
- var minLen = variation === start ? referenceRect[len] : popperRect[len];
2493
- var maxLen = variation === start ? -popperRect[len] : -referenceRect[len];
2494
- var arrowElement = state.elements.arrow;
2495
- var arrowRect = tether && arrowElement ? getLayoutRect(arrowElement) : {
2496
- width: 0,
2497
- height: 0
2498
- };
2499
- var arrowPaddingObject = state.modifiersData["arrow#persistent"] ? state.modifiersData["arrow#persistent"].padding : getFreshSideObject();
2500
- var arrowPaddingMin = arrowPaddingObject[mainSide];
2501
- var arrowPaddingMax = arrowPaddingObject[altSide];
2502
- var arrowLen = within(0, referenceRect[len], arrowRect[len]);
2503
- var minOffset = isBasePlacement ? referenceRect[len] / 2 - additive - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis : minLen - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis;
2504
- var maxOffset = isBasePlacement ? -referenceRect[len] / 2 + additive + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis : maxLen + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis;
2505
- var arrowOffsetParent = state.elements.arrow && getOffsetParent(state.elements.arrow);
2506
- var clientOffset = arrowOffsetParent ? mainAxis === "y" ? arrowOffsetParent.clientTop || 0 : arrowOffsetParent.clientLeft || 0 : 0;
2507
- var offsetModifierValue = (_offsetModifierState$ = offsetModifierState == null ? void 0 : offsetModifierState[mainAxis]) != null ? _offsetModifierState$ : 0;
2508
- var tetherMin = offset2 + minOffset - offsetModifierValue - clientOffset;
2509
- var tetherMax = offset2 + maxOffset - offsetModifierValue;
2510
- var preventedOffset = within(tether ? min(min$1, tetherMin) : min$1, offset2, tether ? max(max$1, tetherMax) : max$1);
2511
- popperOffsets2[mainAxis] = preventedOffset;
2512
- data[mainAxis] = preventedOffset - offset2;
2513
- }
2514
- if (checkAltAxis) {
2515
- var _offsetModifierState$2;
2516
- var _mainSide = mainAxis === "x" ? top : left;
2517
- var _altSide = mainAxis === "x" ? bottom : right;
2518
- var _offset = popperOffsets2[altAxis];
2519
- var _len = altAxis === "y" ? "height" : "width";
2520
- var _min = _offset + overflow[_mainSide];
2521
- var _max = _offset - overflow[_altSide];
2522
- var isOriginSide = [top, left].indexOf(basePlacement) !== -1;
2523
- var _offsetModifierValue = (_offsetModifierState$2 = offsetModifierState == null ? void 0 : offsetModifierState[altAxis]) != null ? _offsetModifierState$2 : 0;
2524
- var _tetherMin = isOriginSide ? _min : _offset - referenceRect[_len] - popperRect[_len] - _offsetModifierValue + normalizedTetherOffsetValue.altAxis;
2525
- var _tetherMax = isOriginSide ? _offset + referenceRect[_len] + popperRect[_len] - _offsetModifierValue - normalizedTetherOffsetValue.altAxis : _max;
2526
- var _preventedOffset = tether && isOriginSide ? withinMaxClamp(_tetherMin, _offset, _tetherMax) : within(tether ? _tetherMin : _min, _offset, tether ? _tetherMax : _max);
2527
- popperOffsets2[altAxis] = _preventedOffset;
2528
- data[altAxis] = _preventedOffset - _offset;
2529
- }
2530
- state.modifiersData[name] = data;
2531
- }
2532
- const preventOverflow$1 = {
2533
- name: "preventOverflow",
2534
- enabled: true,
2535
- phase: "main",
2536
- fn: preventOverflow,
2537
- requiresIfExists: ["offset"]
2538
- };
2539
- function getHTMLElementScroll(element) {
2713
+ function getDimensions(element) {
2714
+ const {
2715
+ width,
2716
+ height
2717
+ } = getCssDimensions(element);
2540
2718
  return {
2541
- scrollLeft: element.scrollLeft,
2542
- scrollTop: element.scrollTop
2719
+ width,
2720
+ height
2543
2721
  };
2544
2722
  }
2545
- function getNodeScroll(node) {
2546
- if (node === getWindow(node) || !isHTMLElement(node)) {
2547
- return getWindowScroll(node);
2548
- } else {
2549
- return getHTMLElementScroll(node);
2550
- }
2551
- }
2552
- function isElementScaled(element) {
2553
- var rect = element.getBoundingClientRect();
2554
- var scaleX = round(rect.width) / element.offsetWidth || 1;
2555
- var scaleY = round(rect.height) / element.offsetHeight || 1;
2556
- return scaleX !== 1 || scaleY !== 1;
2557
- }
2558
- function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
2559
- if (isFixed === void 0) {
2560
- isFixed = false;
2561
- }
2562
- var isOffsetParentAnElement = isHTMLElement(offsetParent);
2563
- var offsetParentIsScaled = isHTMLElement(offsetParent) && isElementScaled(offsetParent);
2564
- var documentElement = getDocumentElement(offsetParent);
2565
- var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled, isFixed);
2566
- var scroll = {
2723
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
2724
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
2725
+ const documentElement = getDocumentElement(offsetParent);
2726
+ const isFixed = strategy === "fixed";
2727
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
2728
+ let scroll = {
2567
2729
  scrollLeft: 0,
2568
2730
  scrollTop: 0
2569
2731
  };
2570
- var offsets = {
2571
- x: 0,
2572
- y: 0
2573
- };
2732
+ const offsets = createCoords(0);
2574
2733
  if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
2575
- if (getNodeName(offsetParent) !== "body" || // https://github.com/popperjs/popper-core/issues/1078
2576
- isScrollParent(documentElement)) {
2734
+ if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
2577
2735
  scroll = getNodeScroll(offsetParent);
2578
2736
  }
2579
- if (isHTMLElement(offsetParent)) {
2580
- offsets = getBoundingClientRect(offsetParent, true);
2581
- offsets.x += offsetParent.clientLeft;
2582
- offsets.y += offsetParent.clientTop;
2737
+ if (isOffsetParentAnElement) {
2738
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
2739
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
2740
+ offsets.y = offsetRect.y + offsetParent.clientTop;
2583
2741
  } else if (documentElement) {
2584
2742
  offsets.x = getWindowScrollBarX(documentElement);
2585
2743
  }
2586
2744
  }
2745
+ let htmlX = 0;
2746
+ let htmlY = 0;
2747
+ if (documentElement && !isOffsetParentAnElement && !isFixed) {
2748
+ const htmlRect = documentElement.getBoundingClientRect();
2749
+ htmlY = htmlRect.top + scroll.scrollTop;
2750
+ htmlX = htmlRect.left + scroll.scrollLeft - // RTL <body> scrollbar.
2751
+ getWindowScrollBarX(documentElement, htmlRect);
2752
+ }
2753
+ const x = rect.left + scroll.scrollLeft - offsets.x - htmlX;
2754
+ const y = rect.top + scroll.scrollTop - offsets.y - htmlY;
2587
2755
  return {
2588
- x: rect.left + scroll.scrollLeft - offsets.x,
2589
- y: rect.top + scroll.scrollTop - offsets.y,
2756
+ x,
2757
+ y,
2590
2758
  width: rect.width,
2591
2759
  height: rect.height
2592
2760
  };
2593
2761
  }
2594
- function order(modifiers) {
2595
- var map = /* @__PURE__ */ new Map();
2596
- var visited = /* @__PURE__ */ new Set();
2597
- var result = [];
2598
- modifiers.forEach(function(modifier) {
2599
- map.set(modifier.name, modifier);
2600
- });
2601
- function sort(modifier) {
2602
- visited.add(modifier.name);
2603
- var requires = [].concat(modifier.requires || [], modifier.requiresIfExists || []);
2604
- requires.forEach(function(dep) {
2605
- if (!visited.has(dep)) {
2606
- var depModifier = map.get(dep);
2607
- if (depModifier) {
2608
- sort(depModifier);
2609
- }
2610
- }
2611
- });
2612
- result.push(modifier);
2762
+ function isStaticPositioned(element) {
2763
+ return getComputedStyle$1(element).position === "static";
2764
+ }
2765
+ function getTrueOffsetParent(element, polyfill) {
2766
+ if (!isHTMLElement(element) || getComputedStyle$1(element).position === "fixed") {
2767
+ return null;
2613
2768
  }
2614
- modifiers.forEach(function(modifier) {
2615
- if (!visited.has(modifier.name)) {
2616
- sort(modifier);
2769
+ if (polyfill) {
2770
+ return polyfill(element);
2771
+ }
2772
+ let rawOffsetParent = element.offsetParent;
2773
+ if (getDocumentElement(element) === rawOffsetParent) {
2774
+ rawOffsetParent = rawOffsetParent.ownerDocument.body;
2775
+ }
2776
+ return rawOffsetParent;
2777
+ }
2778
+ function getOffsetParent(element, polyfill) {
2779
+ const win = getWindow(element);
2780
+ if (isTopLayer(element)) {
2781
+ return win;
2782
+ }
2783
+ if (!isHTMLElement(element)) {
2784
+ let svgOffsetParent = getParentNode(element);
2785
+ while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
2786
+ if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
2787
+ return svgOffsetParent;
2788
+ }
2789
+ svgOffsetParent = getParentNode(svgOffsetParent);
2617
2790
  }
2618
- });
2619
- return result;
2791
+ return win;
2792
+ }
2793
+ let offsetParent = getTrueOffsetParent(element, polyfill);
2794
+ while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
2795
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
2796
+ }
2797
+ if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
2798
+ return win;
2799
+ }
2800
+ return offsetParent || getContainingBlock(element) || win;
2620
2801
  }
2621
- function orderModifiers(modifiers) {
2622
- var orderedModifiers = order(modifiers);
2623
- return modifierPhases.reduce(function(acc, phase) {
2624
- return acc.concat(orderedModifiers.filter(function(modifier) {
2625
- return modifier.phase === phase;
2626
- }));
2627
- }, []);
2628
- }
2629
- function debounce(fn2) {
2630
- var pending;
2631
- return function() {
2632
- if (!pending) {
2633
- pending = new Promise(function(resolve) {
2634
- Promise.resolve().then(function() {
2635
- pending = void 0;
2636
- resolve(fn2());
2637
- });
2638
- });
2802
+ const getElementRects = async function(data) {
2803
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
2804
+ const getDimensionsFn = this.getDimensions;
2805
+ const floatingDimensions = await getDimensionsFn(data.floating);
2806
+ return {
2807
+ reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
2808
+ floating: {
2809
+ x: 0,
2810
+ y: 0,
2811
+ width: floatingDimensions.width,
2812
+ height: floatingDimensions.height
2639
2813
  }
2640
- return pending;
2641
2814
  };
2642
- }
2643
- function mergeByName(modifiers) {
2644
- var merged = modifiers.reduce(function(merged2, current) {
2645
- var existing = merged2[current.name];
2646
- merged2[current.name] = existing ? Object.assign({}, existing, current, {
2647
- options: Object.assign({}, existing.options, current.options),
2648
- data: Object.assign({}, existing.data, current.data)
2649
- }) : current;
2650
- return merged2;
2651
- }, {});
2652
- return Object.keys(merged).map(function(key) {
2653
- return merged[key];
2654
- });
2655
- }
2656
- var DEFAULT_OPTIONS = {
2657
- placement: "bottom",
2658
- modifiers: [],
2659
- strategy: "absolute"
2660
2815
  };
2661
- function areValidElements() {
2662
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2663
- args[_key] = arguments[_key];
2664
- }
2665
- return !args.some(function(element) {
2666
- return !(element && typeof element.getBoundingClientRect === "function");
2667
- });
2668
- }
2669
- function popperGenerator(generatorOptions) {
2670
- if (generatorOptions === void 0) {
2671
- generatorOptions = {};
2672
- }
2673
- var _generatorOptions = generatorOptions, _generatorOptions$def = _generatorOptions.defaultModifiers, defaultModifiers2 = _generatorOptions$def === void 0 ? [] : _generatorOptions$def, _generatorOptions$def2 = _generatorOptions.defaultOptions, defaultOptions = _generatorOptions$def2 === void 0 ? DEFAULT_OPTIONS : _generatorOptions$def2;
2674
- return function createPopper2(reference2, popper2, options) {
2675
- if (options === void 0) {
2676
- options = defaultOptions;
2816
+ function isRTL(element) {
2817
+ return getComputedStyle$1(element).direction === "rtl";
2818
+ }
2819
+ const platform = {
2820
+ convertOffsetParentRelativeRectToViewportRelativeRect,
2821
+ getDocumentElement,
2822
+ getClippingRect,
2823
+ getOffsetParent,
2824
+ getElementRects,
2825
+ getClientRects,
2826
+ getDimensions,
2827
+ getScale,
2828
+ isElement,
2829
+ isRTL
2830
+ };
2831
+ function observeMove(element, onMove) {
2832
+ let io = null;
2833
+ let timeoutId;
2834
+ const root = getDocumentElement(element);
2835
+ function cleanup() {
2836
+ var _io;
2837
+ clearTimeout(timeoutId);
2838
+ (_io = io) == null || _io.disconnect();
2839
+ io = null;
2840
+ }
2841
+ function refresh(skip, threshold) {
2842
+ if (skip === void 0) {
2843
+ skip = false;
2844
+ }
2845
+ if (threshold === void 0) {
2846
+ threshold = 1;
2847
+ }
2848
+ cleanup();
2849
+ const {
2850
+ left,
2851
+ top,
2852
+ width,
2853
+ height
2854
+ } = element.getBoundingClientRect();
2855
+ if (!skip) {
2856
+ onMove();
2857
+ }
2858
+ if (!width || !height) {
2859
+ return;
2677
2860
  }
2678
- var state = {
2679
- placement: "bottom",
2680
- orderedModifiers: [],
2681
- options: Object.assign({}, DEFAULT_OPTIONS, defaultOptions),
2682
- modifiersData: {},
2683
- elements: {
2684
- reference: reference2,
2685
- popper: popper2
2686
- },
2687
- attributes: {},
2688
- styles: {}
2861
+ const insetTop = floor(top);
2862
+ const insetRight = floor(root.clientWidth - (left + width));
2863
+ const insetBottom = floor(root.clientHeight - (top + height));
2864
+ const insetLeft = floor(left);
2865
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
2866
+ const options = {
2867
+ rootMargin,
2868
+ threshold: max(0, min(1, threshold)) || 1
2689
2869
  };
2690
- var effectCleanupFns = [];
2691
- var isDestroyed = false;
2692
- var instance = {
2693
- state,
2694
- setOptions: function setOptions(setOptionsAction) {
2695
- var options2 = typeof setOptionsAction === "function" ? setOptionsAction(state.options) : setOptionsAction;
2696
- cleanupModifierEffects();
2697
- state.options = Object.assign({}, defaultOptions, state.options, options2);
2698
- state.scrollParents = {
2699
- reference: isElement(reference2) ? listScrollParents(reference2) : reference2.contextElement ? listScrollParents(reference2.contextElement) : [],
2700
- popper: listScrollParents(popper2)
2701
- };
2702
- var orderedModifiers = orderModifiers(mergeByName([].concat(defaultModifiers2, state.options.modifiers)));
2703
- state.orderedModifiers = orderedModifiers.filter(function(m) {
2704
- return m.enabled;
2705
- });
2706
- runModifierEffects();
2707
- return instance.update();
2708
- },
2709
- // Sync update – it will always be executed, even if not necessary. This
2710
- // is useful for low frequency updates where sync behavior simplifies the
2711
- // logic.
2712
- // For high frequency updates (e.g. `resize` and `scroll` events), always
2713
- // prefer the async Popper#update method
2714
- forceUpdate: function forceUpdate() {
2715
- if (isDestroyed) {
2716
- return;
2717
- }
2718
- var _state$elements = state.elements, reference3 = _state$elements.reference, popper3 = _state$elements.popper;
2719
- if (!areValidElements(reference3, popper3)) {
2720
- return;
2870
+ let isFirstUpdate = true;
2871
+ function handleObserve(entries) {
2872
+ const ratio = entries[0].intersectionRatio;
2873
+ if (ratio !== threshold) {
2874
+ if (!isFirstUpdate) {
2875
+ return refresh();
2721
2876
  }
2722
- state.rects = {
2723
- reference: getCompositeRect(reference3, getOffsetParent(popper3), state.options.strategy === "fixed"),
2724
- popper: getLayoutRect(popper3)
2725
- };
2726
- state.reset = false;
2727
- state.placement = state.options.placement;
2728
- state.orderedModifiers.forEach(function(modifier) {
2729
- return state.modifiersData[modifier.name] = Object.assign({}, modifier.data);
2730
- });
2731
- for (var index2 = 0; index2 < state.orderedModifiers.length; index2++) {
2732
- if (state.reset === true) {
2733
- state.reset = false;
2734
- index2 = -1;
2735
- continue;
2736
- }
2737
- var _state$orderedModifie = state.orderedModifiers[index2], fn2 = _state$orderedModifie.fn, _state$orderedModifie2 = _state$orderedModifie.options, _options = _state$orderedModifie2 === void 0 ? {} : _state$orderedModifie2, name = _state$orderedModifie.name;
2738
- if (typeof fn2 === "function") {
2739
- state = fn2({
2740
- state,
2741
- options: _options,
2742
- name,
2743
- instance
2744
- }) || state;
2745
- }
2877
+ if (!ratio) {
2878
+ timeoutId = setTimeout(() => {
2879
+ refresh(false, 1e-7);
2880
+ }, 1e3);
2881
+ } else {
2882
+ refresh(false, ratio);
2746
2883
  }
2747
- },
2748
- // Async and optimistically optimized update – it will not be executed if
2749
- // not necessary (debounced to run at most once-per-tick)
2750
- update: debounce(function() {
2751
- return new Promise(function(resolve) {
2752
- instance.forceUpdate();
2753
- resolve(state);
2754
- });
2755
- }),
2756
- destroy: function destroy() {
2757
- cleanupModifierEffects();
2758
- isDestroyed = true;
2759
2884
  }
2760
- };
2761
- if (!areValidElements(reference2, popper2)) {
2762
- return instance;
2763
- }
2764
- instance.setOptions(options).then(function(state2) {
2765
- if (!isDestroyed && options.onFirstUpdate) {
2766
- options.onFirstUpdate(state2);
2767
- }
2768
- });
2769
- function runModifierEffects() {
2770
- state.orderedModifiers.forEach(function(_ref) {
2771
- var name = _ref.name, _ref$options = _ref.options, options2 = _ref$options === void 0 ? {} : _ref$options, effect2 = _ref.effect;
2772
- if (typeof effect2 === "function") {
2773
- var cleanupFn = effect2({
2774
- state,
2775
- name,
2776
- instance,
2777
- options: options2
2778
- });
2779
- var noopFn = function noopFn2() {
2780
- };
2781
- effectCleanupFns.push(cleanupFn || noopFn);
2782
- }
2783
- });
2885
+ isFirstUpdate = false;
2784
2886
  }
2785
- function cleanupModifierEffects() {
2786
- effectCleanupFns.forEach(function(fn2) {
2787
- return fn2();
2887
+ try {
2888
+ io = new IntersectionObserver(handleObserve, {
2889
+ ...options,
2890
+ // Handle <iframe>s
2891
+ root: root.ownerDocument
2788
2892
  });
2789
- effectCleanupFns = [];
2893
+ } catch (e) {
2894
+ io = new IntersectionObserver(handleObserve, options);
2790
2895
  }
2791
- return instance;
2792
- };
2793
- }
2794
- var defaultModifiers = [eventListeners, popperOffsets$1, computeStyles$1, applyStyles$1, offset$1, flip$1, preventOverflow$1, arrow$1, hide$1];
2795
- var createPopper = /* @__PURE__ */ popperGenerator({
2796
- defaultModifiers
2797
- });
2798
- async function deregister(obj) {
2799
- const index2 = this.collection.findIndex((entry) => {
2800
- return entry.id === obj.id;
2801
- });
2802
- if (index2 >= 0) {
2803
- const entry = this.collection[index2];
2804
- if (entry.state === "opened") {
2805
- entry.close();
2806
- }
2807
- entry.popper.destroy();
2808
- deregisterEventListeners(entry);
2809
- Object.getOwnPropertyNames(entry).forEach((prop) => {
2810
- delete entry[prop];
2811
- });
2812
- this.collection.splice(index2, 1);
2896
+ io.observe(element);
2813
2897
  }
2814
- return this.collection;
2898
+ refresh(true);
2899
+ return cleanup;
2815
2900
  }
2816
- function deregisterEventListeners(entry) {
2817
- if (entry.__eventListeners) {
2818
- entry.__eventListeners.forEach((evObj) => {
2819
- evObj.el.forEach((el) => {
2820
- evObj.type.forEach((type) => {
2821
- entry[el].removeEventListener(type, evObj.listener, false);
2901
+ function autoUpdate(reference, floating, update, options) {
2902
+ if (options === void 0) {
2903
+ options = {};
2904
+ }
2905
+ const {
2906
+ ancestorScroll = true,
2907
+ ancestorResize = true,
2908
+ elementResize = typeof ResizeObserver === "function",
2909
+ layoutShift = typeof IntersectionObserver === "function",
2910
+ animationFrame = false
2911
+ } = options;
2912
+ const referenceEl = unwrapElement(reference);
2913
+ const ancestors = ancestorScroll || ancestorResize ? [...referenceEl ? getOverflowAncestors(referenceEl) : [], ...getOverflowAncestors(floating)] : [];
2914
+ ancestors.forEach((ancestor) => {
2915
+ ancestorScroll && ancestor.addEventListener("scroll", update, {
2916
+ passive: true
2917
+ });
2918
+ ancestorResize && ancestor.addEventListener("resize", update);
2919
+ });
2920
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
2921
+ let reobserveFrame = -1;
2922
+ let resizeObserver = null;
2923
+ if (elementResize) {
2924
+ resizeObserver = new ResizeObserver((_ref) => {
2925
+ let [firstEntry] = _ref;
2926
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
2927
+ resizeObserver.unobserve(floating);
2928
+ cancelAnimationFrame(reobserveFrame);
2929
+ reobserveFrame = requestAnimationFrame(() => {
2930
+ var _resizeObserver;
2931
+ (_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
2822
2932
  });
2823
- });
2933
+ }
2934
+ update();
2824
2935
  });
2825
- delete entry.__eventListeners;
2826
- }
2827
- return entry;
2936
+ if (referenceEl && !animationFrame) {
2937
+ resizeObserver.observe(referenceEl);
2938
+ }
2939
+ resizeObserver.observe(floating);
2940
+ }
2941
+ let frameId;
2942
+ let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
2943
+ if (animationFrame) {
2944
+ frameLoop();
2945
+ }
2946
+ function frameLoop() {
2947
+ const nextRefRect = getBoundingClientRect(reference);
2948
+ if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
2949
+ update();
2950
+ }
2951
+ prevRefRect = nextRefRect;
2952
+ frameId = requestAnimationFrame(frameLoop);
2953
+ }
2954
+ update();
2955
+ return () => {
2956
+ var _resizeObserver2;
2957
+ ancestors.forEach((ancestor) => {
2958
+ ancestorScroll && ancestor.removeEventListener("scroll", update);
2959
+ ancestorResize && ancestor.removeEventListener("resize", update);
2960
+ });
2961
+ cleanupIo == null || cleanupIo();
2962
+ (_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
2963
+ resizeObserver = null;
2964
+ if (animationFrame) {
2965
+ cancelAnimationFrame(frameId);
2966
+ }
2967
+ };
2828
2968
  }
2969
+ const offset = offset$1;
2970
+ const shift = shift$1;
2971
+ const flip = flip$1;
2972
+ const arrow = arrow$1;
2973
+ const limitShift = limitShift$1;
2974
+ const computePosition = (reference, floating, options) => {
2975
+ const cache = /* @__PURE__ */ new Map();
2976
+ const mergedOptions = {
2977
+ platform,
2978
+ ...options
2979
+ };
2980
+ const platformWithCache = {
2981
+ ...mergedOptions.platform,
2982
+ _c: cache
2983
+ };
2984
+ return computePosition$1(reference, floating, {
2985
+ ...mergedOptions,
2986
+ platform: platformWithCache
2987
+ });
2988
+ };
2829
2989
  async function open(query) {
2830
2990
  const popover = getPopover.call(this, query);
2831
2991
  popover.el.inert = false;
@@ -2833,161 +2993,69 @@ async function open(query) {
2833
2993
  if (!popover.isTooltip) {
2834
2994
  popover.trigger.setAttribute("aria-expanded", "true");
2835
2995
  }
2836
- popover.config = getConfig(popover.el, this.settings);
2837
- popover.popper.setOptions({
2838
- placement: popover.config["placement"],
2839
- modifiers: [
2840
- { name: "eventListeners", enabled: true },
2841
- ...getModifiers(popover.config)
2842
- ]
2996
+ popover.getCustomProps();
2997
+ const middlewareOptions = getMiddlewareOptions(popover);
2998
+ const arrowEl = popover.el.querySelector(middlewareOptions.arrow.element);
2999
+ middlewareOptions.arrow.element = arrowEl ? arrowEl : void 0;
3000
+ popover.floatingCleanup = autoUpdate(popover.trigger, popover.el, () => {
3001
+ computePosition(popover.trigger, popover.el, {
3002
+ placement: popover.getSetting("placement"),
3003
+ middleware: [
3004
+ flip(middlewareOptions.flip),
3005
+ shift({ ...middlewareOptions.shift, limiter: limitShift() }),
3006
+ offset(middlewareOptions.offset),
3007
+ arrow(middlewareOptions.arrow)
3008
+ ]
3009
+ }).then(({ x, y, placement, middlewareData }) => {
3010
+ if (!popover.el) {
3011
+ return;
3012
+ }
3013
+ applyPositionStyle(popover.el, x, y);
3014
+ if (middlewareOptions.arrow.element && middlewareData.arrow) {
3015
+ const { x: x2, y: y2 } = middlewareData.arrow;
3016
+ applyPositionStyle(middlewareOptions.arrow.element, x2, y2);
3017
+ }
3018
+ popover.el.setAttribute("data-floating-placement", placement);
3019
+ });
2843
3020
  });
2844
- popover.popper.update();
2845
3021
  popover.state = "opened";
2846
- return popover;
2847
- }
2848
- async function register(el, trigger) {
2849
- deregister.call(this, el);
2850
- const root = this;
2851
- const entry = {
2852
- id: el.id,
2853
- state: "closed",
2854
- el,
2855
- trigger,
2856
- toggleDelayId: null,
2857
- popper: createPopper(trigger, el),
2858
- config: getConfig(el, this.settings),
2859
- get isTooltip() {
2860
- return !!el.closest(root.settings.selectorTooltip) || el.getAttribute("role") == "tooltip";
2861
- },
2862
- open() {
2863
- return open.call(root, this);
2864
- },
2865
- close() {
2866
- return close.call(root, this);
2867
- },
2868
- deregister() {
2869
- return deregister.call(root, this);
2870
- }
2871
- };
2872
- if (entry.isTooltip) {
2873
- entry.el.setAttribute("role", "tooltip");
2874
- }
2875
- if (!entry.isTooltip) {
2876
- entry.trigger.setAttribute("aria-expanded", "false");
2877
- }
2878
- registerEventListeners.call(this, entry);
2879
- this.collection.push(entry);
2880
- if (entry.el.classList.contains(this.settings.stateActive)) {
2881
- await entry.open();
2882
- handleDocumentClick.call(this, entry);
2883
- } else {
2884
- entry.el.inert = true;
2885
- }
2886
- entry.popper.setOptions({
2887
- placement: entry.config["placement"]
2888
- });
2889
- return entry;
2890
- }
2891
- function registerEventListeners(entry) {
2892
- if (!entry.__eventListeners) {
2893
- const eventType = entry.isTooltip ? "hover" : entry.config["event"];
2894
- if (eventType === "hover") {
2895
- entry.__eventListeners = [{
2896
- el: ["trigger"],
2897
- type: ["mouseenter", "focus"],
2898
- listener: handleMouseEnter.bind(this, entry)
2899
- }, {
2900
- el: ["el", "trigger"],
2901
- type: ["mouseleave", "focusout"],
2902
- listener: handleMouseLeave.bind(this, entry)
2903
- }];
2904
- entry.__eventListeners.forEach((evObj) => {
2905
- evObj.el.forEach((el) => {
2906
- evObj.type.forEach((type) => {
2907
- entry[el].addEventListener(type, evObj.listener, false);
2908
- });
2909
- });
2910
- });
2911
- } else {
2912
- entry.__eventListeners = [{
2913
- el: ["trigger"],
2914
- type: ["click"],
2915
- listener: handleClick.bind(this, entry)
2916
- }];
2917
- entry.__eventListeners.forEach((evObj) => {
2918
- evObj.el.forEach((el) => {
2919
- evObj.type.forEach((type) => {
2920
- entry[el].addEventListener(type, evObj.listener, false);
2921
- });
2922
- });
2923
- });
2924
- }
3022
+ if (popover.getSetting("event") === "click") {
3023
+ handleDocumentClick.call(this, popover);
2925
3024
  }
2926
- return entry;
3025
+ return popover;
2927
3026
  }
2928
3027
  class Popover extends Collection {
2929
- constructor(options) {
2930
- super();
3028
+ constructor(options = {}) {
3029
+ super({ ...defaults, ...options });
2931
3030
  __privateAdd(this, _handleKeydown3);
2932
- this.defaults = defaults;
2933
- this.settings = { ...this.defaults, ...options };
2934
3031
  this.trigger = null;
2935
3032
  __privateSet(this, _handleKeydown3, handleKeydown.bind(this));
2936
- if (this.settings.autoMount) this.mount();
2937
3033
  }
2938
3034
  get active() {
2939
- return this.collection.find((popover) => popover.state == "opened");
3035
+ return this.get("opened", "state");
2940
3036
  }
2941
- get activeTooltip() {
2942
- return this.collection.find((popover) => popover.state == "opened" && popover.isTooltip);
2943
- }
2944
- async mount(options) {
2945
- if (options) this.settings = { ...this.settings, ...options };
2946
- const popovers = document.querySelectorAll(this.settings.selectorPopover);
2947
- await this.registerCollection(popovers);
2948
- if (this.settings.eventListeners) {
2949
- this.mountEventListeners(false);
2950
- }
2951
- return this;
2952
- }
2953
- async unmount() {
2954
- this.trigger = null;
2955
- await this.deregisterCollection();
2956
- if (this.settings.eventListeners) {
2957
- this.unmountEventListeners(false);
2958
- }
2959
- return this;
3037
+ get activeHover() {
3038
+ return this.collection.find((popover) => {
3039
+ return popover.state == "opened" && popover.getSetting("event") == "hover";
3040
+ });
2960
3041
  }
2961
- mountEventListeners(processCollection = true) {
2962
- if (processCollection) {
2963
- this.collection.forEach((popover) => {
2964
- registerEventListeners.call(this, popover);
2965
- });
2966
- }
2967
- document.addEventListener("keydown", __privateGet(this, _handleKeydown3), false);
3042
+ async createEntry(query, config) {
3043
+ return new PopoverEntry(this, query, config);
2968
3044
  }
2969
- unmountEventListeners(processCollection = true) {
2970
- if (processCollection) {
2971
- this.collection.forEach((popover) => {
2972
- deregisterEventListeners(popover);
2973
- });
2974
- }
2975
- document.removeEventListener("keydown", __privateGet(this, _handleKeydown3), false);
3045
+ async open(id) {
3046
+ return open.call(this, id);
2976
3047
  }
2977
- register(query) {
2978
- const els = getPopoverElements.call(this, query);
2979
- if (els.error) return Promise.reject(els.error);
2980
- return register.call(this, els.popover, els.trigger);
3048
+ async close(id) {
3049
+ return close.call(this, id);
2981
3050
  }
2982
- deregister(query) {
2983
- let obj = this.get(query.id || query);
2984
- return obj ? deregister.call(this, obj) : Promise.reject(new Error(`Failed to deregister; popover does not exist in collection with ID of: "${query.id || query}".`));
3051
+ async afterMount() {
3052
+ document.addEventListener("keydown", __privateGet(this, _handleKeydown3), false);
2985
3053
  }
2986
- open(id) {
2987
- return open.call(this, id);
3054
+ async beforeUnmount() {
3055
+ this.trigger = null;
2988
3056
  }
2989
- close(id) {
2990
- return close.call(this, id);
3057
+ async afterUnmount() {
3058
+ document.removeEventListener("keydown", __privateGet(this, _handleKeydown3), false);
2991
3059
  }
2992
3060
  }
2993
3061
  _handleKeydown3 = new WeakMap();