vrembem 4.0.0-next.3 → 4.0.0-next.30

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