vrembem 4.0.0-next.30 → 4.0.0-next.31

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.umd.cjs CHANGED
@@ -9,9 +9,73 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
9
9
  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);
10
10
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
11
 
12
- var _handler, _focusable, _handleFocusTrap, _handleFocusLock, _mode, _state, _breakpoint, _handleClick, _handleKeydown, _handleClick2, _handleKeydown2, _eventListeners, _isHovered, _handleKeydown3;
12
+ var _mode, _handleClick, _handleKeydown, _handleClick2, _handleKeydown2, _eventListeners, _isHovered, _handleKeydown3;
13
+ const notInert = ":not([inert])";
14
+ const notNegTabIndex = ':not([tabindex^="-"])';
15
+ const notDisabled = ":not(:disabled)";
16
+ const focusableSelectors = [
17
+ `a[href]${notInert}${notNegTabIndex}`,
18
+ `area[href]${notInert}${notNegTabIndex}`,
19
+ `input:not([type="hidden"]):not([type="radio"])${notInert}${notNegTabIndex}${notDisabled}`,
20
+ `input[type="radio"]${notInert}${notNegTabIndex}${notDisabled}`,
21
+ `select${notInert}${notNegTabIndex}${notDisabled}`,
22
+ `textarea${notInert}${notNegTabIndex}${notDisabled}`,
23
+ `button${notInert}${notNegTabIndex}${notDisabled}`,
24
+ `details${notInert} > summary:first-of-type${notNegTabIndex}`,
25
+ `iframe${notInert}${notNegTabIndex}`,
26
+ `audio[controls]${notInert}${notNegTabIndex}`,
27
+ `video[controls]${notInert}${notNegTabIndex}`,
28
+ `[contenteditable]${notInert}${notNegTabIndex}`,
29
+ `[tabindex]${notInert}${notNegTabIndex}`
30
+ ];
31
+ function getDataConfig(el, dataConfig = "config") {
32
+ const string = el.getAttribute(`data-${dataConfig}`) || "";
33
+ const json = string.replace(/'/g, '"');
34
+ return json ? JSON.parse(json) : {};
35
+ }
36
+ function getElement(query) {
37
+ if (typeof query === "string") {
38
+ return document.getElementById(query);
39
+ } else if (query instanceof HTMLElement) {
40
+ return query;
41
+ } else {
42
+ return null;
43
+ }
44
+ }
45
+ async function maybeRunMethod(obj, name, ...args) {
46
+ if (name in obj && typeof obj[name] === "function") {
47
+ await obj[name](...args);
48
+ }
49
+ }
50
+ function teleportElement(what, where, how) {
51
+ if (typeof where === "string") {
52
+ const whereEl = document.querySelector(where);
53
+ if (!whereEl) {
54
+ throw new Error(`No teleport reference found for selector: ${where}`);
55
+ }
56
+ where = whereEl;
57
+ } else if (!(where instanceof HTMLElement)) {
58
+ throw new Error(`Not a valid teleport reference: '${where}'`);
59
+ }
60
+ if (typeof where[how] != "function")
61
+ throw new Error(`Not a valid teleport method: '${how}'`);
62
+ let returnRef = document.createComment(
63
+ "teleported #" + what.id
64
+ );
65
+ what.before(returnRef);
66
+ where[how](what);
67
+ return () => {
68
+ if (returnRef) {
69
+ returnRef.after(what);
70
+ returnRef.remove();
71
+ returnRef = null;
72
+ }
73
+ };
74
+ }
13
75
  function toCamel(value) {
14
- return value.split("-").map((word, index2) => index2 === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1)).join("");
76
+ return value.split("-").map(
77
+ (word, index2) => index2 === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1)
78
+ ).join("");
15
79
  }
16
80
  function toKebab(value) {
17
81
  return value.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
@@ -27,16 +91,24 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
27
91
  }
28
92
  throw new Error(`Could not convert value to milliseconds: ${value}`);
29
93
  }
30
- function getPrefix() {
31
- return getComputedStyle(document.body).getPropertyValue("--vb-prefix").trim();
94
+ function transition(el, init, interim, final, duration = 0) {
95
+ return new Promise((resolve) => {
96
+ el.classList.remove(init);
97
+ el.classList.add(interim);
98
+ setTimeout(() => {
99
+ el.classList.add(final);
100
+ el.classList.remove(interim);
101
+ resolve(el);
102
+ }, toMilliseconds(duration));
103
+ });
32
104
  }
33
- function cssVar(property, options) {
105
+ function cssVar(property, options = {}) {
34
106
  const settings = {
35
107
  fallback: null,
36
108
  element: document.body,
37
109
  ...options
38
110
  };
39
- if (property.slice(0, 2) !== "--") {
111
+ if (!property.startsWith("--")) {
40
112
  const prefixValue = getPrefix();
41
113
  if (prefixValue) {
42
114
  property = `${prefixValue}${property}`;
@@ -54,10 +126,15 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
54
126
  }
55
127
  }
56
128
  }
57
- function getConfig(el, dataConfig = "config") {
58
- const string = el.getAttribute(`data-${dataConfig}`) || "";
59
- const json = string.replace(/'/g, '"');
60
- return json ? JSON.parse(json) : {};
129
+ async function dispatchLifecycleHook(name, parent2, entry) {
130
+ await maybeRunMethod(parent2, name, entry);
131
+ if (entry) {
132
+ await maybeRunMethod(entry, name);
133
+ }
134
+ for (const plugin of parent2.plugins) {
135
+ await maybeRunMethod(plugin, name, { plugin, parent: parent2, entry });
136
+ }
137
+ await parent2.emit(name, entry);
61
138
  }
62
139
  function getCustomProps(entry) {
63
140
  const styles = getComputedStyle(entry.el);
@@ -65,7 +142,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
65
142
  const keys = entry.getSetting("customProps");
66
143
  for (let i = 0; i < keys.length; i++) {
67
144
  const prefix = getPrefix();
68
- const module2 = entry.context.module.toLowerCase();
145
+ const module2 = entry.parent.module.toLowerCase();
69
146
  const key = toKebab(keys[i]);
70
147
  const value = styles.getPropertyValue(`--${prefix}${module2}-${key}`).trim();
71
148
  if (value) {
@@ -74,14 +151,8 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
74
151
  }
75
152
  return result;
76
153
  }
77
- function getElement(query) {
78
- if (typeof query === "string") {
79
- return document.getElementById(query);
80
- } else if (query instanceof HTMLElement) {
81
- return query;
82
- } else {
83
- return null;
84
- }
154
+ function getPrefix() {
155
+ return getComputedStyle(document.body).getPropertyValue("--vb-prefix").trim();
85
156
  }
86
157
  function maybeReturnSetting(prop, key, type = "camel") {
87
158
  key = type === "camel" ? toCamel(key) : toKebab(key);
@@ -90,7 +161,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
90
161
  function getSetting(key, options = {}) {
91
162
  const {
92
163
  fallback,
93
- props = ["dataConfig", "customProps", "settings", "context.settings"]
164
+ props = ["dataConfig", "customProps", "settings", "parent.settings"]
94
165
  } = options;
95
166
  for (const prop of props) {
96
167
  const type = prop !== "customProps" ? "camel" : "kebab";
@@ -102,23 +173,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
102
173
  if (fallback !== void 0) {
103
174
  return fallback;
104
175
  }
105
- throw new Error(`${this.context.module} setting does not exist: ${key}`);
106
- }
107
- async function lifecycleHook(name, ...args) {
108
- if (name in this && typeof this[name] === "function") {
109
- await this[name](...args);
110
- }
111
- }
112
- function transition(el, init, interim, final, duration = 0) {
113
- return new Promise((resolve) => {
114
- el.classList.remove(init);
115
- el.classList.add(interim);
116
- setTimeout(() => {
117
- el.classList.add(final);
118
- el.classList.remove(interim);
119
- resolve(el);
120
- }, toMilliseconds(duration));
121
- });
176
+ throw new Error(`${this.parent.module} setting does not exist: ${key}`);
122
177
  }
123
178
  function setOverflowHidden(state, selector) {
124
179
  if (selector) {
@@ -138,9 +193,9 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
138
193
  els.forEach((el) => {
139
194
  if (state) {
140
195
  el.inert = true;
141
- el.setAttribute("aria-hidden", true);
196
+ el.setAttribute("aria-hidden", "true");
142
197
  } else {
143
- el.inert = null;
198
+ el.inert = false;
144
199
  el.removeAttribute("aria-hidden");
145
200
  }
146
201
  });
@@ -150,308 +205,725 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
150
205
  setInert(!!state, selectorInert);
151
206
  setOverflowHidden(!!state, selectorOverflow);
152
207
  }
153
- class Breakpoint {
154
- constructor(value, handler) {
155
- __privateAdd(this, _handler);
156
- this.value = value;
157
- __privateSet(this, _handler, handler);
158
- this.mql = null;
159
- }
160
- get handler() {
161
- return __privateGet(this, _handler);
162
- }
163
- // Unmount existing handler before setting a new one.
164
- set handler(func) {
165
- if (this.mql) {
166
- this.mql.removeEventListener("change", __privateGet(this, _handler));
167
- }
168
- __privateSet(this, _handler, func);
169
- }
170
- mount(value, handler) {
171
- if (value) this.value = value;
172
- if (handler) __privateSet(this, _handler, handler);
173
- if (!this.value) return this;
174
- this.mql = window.matchMedia(`(min-width: ${this.value})`);
175
- this.mql.addEventListener("change", __privateGet(this, _handler));
176
- __privateGet(this, _handler).call(this, this.mql);
177
- return this;
208
+ const eventEmitter = {
209
+ on(event, listener, ...args) {
210
+ if (!this.events[event]) {
211
+ this.events[event] = [];
212
+ }
213
+ const listenerExists = this.events[event].some(
214
+ (entry) => entry.listener === listener
215
+ );
216
+ if (!listenerExists) {
217
+ this.events[event].push({ listener, args });
218
+ }
219
+ },
220
+ off(event, listenerRef) {
221
+ if (!this.events[event]) return;
222
+ this.events[event] = this.events[event].filter(
223
+ (entry) => entry.listener !== listenerRef
224
+ );
225
+ },
226
+ async emit(event, data) {
227
+ event = event.startsWith("on") ? event.slice(2, 3).toLowerCase() + event.slice(3) : event;
228
+ if (!this.events[event]) return;
229
+ for (const { listener, args } of this.events[event]) {
230
+ await listener(data, ...args);
231
+ }
178
232
  }
179
- unmount() {
180
- if (!this.mql) return this;
181
- this.mql.removeEventListener("change", __privateGet(this, _handler));
182
- this.value = null;
183
- __privateSet(this, _handler, null);
184
- this.mql = null;
185
- return this;
233
+ };
234
+ class FocusableArray extends Array {
235
+ constructor(el = null) {
236
+ super();
237
+ this.el = el;
238
+ if (this.el) this.set();
239
+ }
240
+ get first() {
241
+ return this[0];
242
+ }
243
+ get last() {
244
+ return this[this.length - 1];
245
+ }
246
+ set(el = this.el) {
247
+ this.length = 0;
248
+ this.push(...el.querySelectorAll(focusableSelectors.join(",")));
249
+ }
250
+ clear() {
251
+ this.length = 0;
186
252
  }
187
253
  }
188
- _handler = new WeakMap();
189
- class Collection {
190
- constructor(options = {}) {
191
- this.module = this.constructor.name;
192
- this.collection = [];
193
- this.settings = Object.assign({
194
- dataConfig: "config",
195
- customProps: [],
196
- teleport: null,
197
- teleportMethod: "append"
198
- }, options);
254
+ class FocusTrap {
255
+ constructor(el = null) {
256
+ this.el = el;
257
+ this.focusable = new FocusableArray();
258
+ this.handleFocusTrap = handleFocusTrap.bind(this);
199
259
  }
200
- get(value, key = "id") {
201
- return this.collection.find((entry) => entry[key] === value);
260
+ on(el = this.el) {
261
+ this.focusable.set(el);
262
+ this.focusable.length ? document.addEventListener("keydown", this.handleFocusTrap) : document.addEventListener("keydown", handleFocusLock);
202
263
  }
203
- applySettings(obj) {
204
- return Object.assign(this.settings, obj);
264
+ off() {
265
+ this.focusable.clear();
266
+ document.removeEventListener("keydown", this.handleFocusTrap);
267
+ document.removeEventListener("keydown", handleFocusLock);
205
268
  }
206
- async createEntry(query, config) {
207
- return new CollectionEntry(this, query, config);
269
+ }
270
+ function handleFocusLock(event) {
271
+ if (event.key === "Tab" || event.keyCode === 9) event.preventDefault();
272
+ }
273
+ function handleFocusTrap(event) {
274
+ if (event.key !== "Tab" && event.keyCode !== 9) return;
275
+ const { activeElement } = document;
276
+ const { el, focusable } = this;
277
+ const isShiftTab = event.shiftKey;
278
+ const isFirstOrRoot = activeElement === focusable.first || activeElement === el;
279
+ const isLastOrRoot = activeElement === focusable.last || activeElement === el;
280
+ if (isShiftTab && isFirstOrRoot || !isShiftTab && isLastOrRoot) {
281
+ event.preventDefault();
282
+ (isShiftTab ? focusable.last : focusable.first).focus();
208
283
  }
209
- async register(query, config = {}) {
210
- await this.deregister((query == null ? void 0 : query.id) || query, true);
211
- const entry = await this.createEntry(query, config);
212
- await entry.mount();
213
- await lifecycleHook.call(this, "beforeRegister", entry);
214
- await lifecycleHook.call(entry, "beforeRegister");
215
- this.collection.push(entry);
216
- await lifecycleHook.call(entry, "afterRegister");
217
- await lifecycleHook.call(this, "afterRegister", entry);
218
- return entry;
284
+ }
285
+ function localStore(key, enable = true) {
286
+ const local = localStorage.getItem(key);
287
+ const store = local ? JSON.parse(local) : {};
288
+ return {
289
+ get(prop, fallback = void 0) {
290
+ if (!prop) return store;
291
+ return prop in store ? store[prop] : fallback;
292
+ },
293
+ set(prop, value) {
294
+ if (value) {
295
+ store[prop] = value;
296
+ } else {
297
+ delete store[prop];
298
+ }
299
+ if (enable) localStorage.setItem(key, JSON.stringify(store));
300
+ return store;
301
+ }
302
+ };
303
+ }
304
+ class PluginsArray extends Array {
305
+ constructor(presets2 = {}) {
306
+ super();
307
+ this.presets = presets2;
308
+ }
309
+ applySettings(plugin) {
310
+ var _a;
311
+ const defaults2 = (plugin == null ? void 0 : plugin.defaults) || {};
312
+ const preset = ((_a = this.presets) == null ? void 0 : _a[plugin.name]) || {};
313
+ const options = (plugin == null ? void 0 : plugin.options) || {};
314
+ plugin.settings = { ...defaults2, ...preset, ...options };
315
+ }
316
+ validate(plugin) {
317
+ if (!("name" in plugin) || typeof plugin.name !== "string") {
318
+ console.error("Plugin requires a name!");
319
+ return false;
320
+ }
321
+ return true;
219
322
  }
220
- async deregister(id, reReg = false) {
221
- const index2 = this.collection.findIndex((entry) => entry.id === id);
222
- if (~index2) {
223
- const entry = this.collection[index2];
224
- await entry.unmount(reReg);
225
- await lifecycleHook.call(this, "beforeDeregister", entry);
226
- await lifecycleHook.call(entry, "beforeDeregister", reReg);
227
- Object.getOwnPropertyNames(entry).forEach((prop) => {
228
- if (prop != "beforeDeregister" && prop != "afterDeregister") {
229
- delete entry[prop];
323
+ get(name) {
324
+ return this.find((plugin) => plugin.name === name);
325
+ }
326
+ add(plugin) {
327
+ if (Array.isArray(plugin)) {
328
+ plugin.forEach((plugin2) => this.add(plugin2));
329
+ } else {
330
+ this.applySettings(plugin);
331
+ if (this.validate(plugin)) {
332
+ const index2 = this.findIndex((item) => item.name === plugin.name);
333
+ if (~index2) {
334
+ this[index2] = plugin;
335
+ } else {
336
+ this.push(plugin);
230
337
  }
338
+ }
339
+ }
340
+ }
341
+ remove(name) {
342
+ const index2 = this.findIndex((plugin) => plugin.name === name);
343
+ if (~index2) {
344
+ this.splice(index2, 1);
345
+ }
346
+ }
347
+ }
348
+ class StackArray extends Array {
349
+ constructor(settings = {}) {
350
+ super();
351
+ this.settings = settings;
352
+ }
353
+ get copy() {
354
+ return [...this];
355
+ }
356
+ get top() {
357
+ const result = this[this.length - 1];
358
+ return result ? result : null;
359
+ }
360
+ updateIndex() {
361
+ this.forEach((entry, index2) => {
362
+ entry.el.style.zIndex = null;
363
+ const value = getComputedStyle(entry.el)["z-index"];
364
+ entry.el.style.zIndex = parseInt(value) + index2 + 1;
365
+ });
366
+ }
367
+ onChange() {
368
+ this.updateIndex();
369
+ if (typeof this.settings.onChange === "function") {
370
+ this.settings.onChange();
371
+ }
372
+ }
373
+ add(entry) {
374
+ this.push(entry);
375
+ this.onChange();
376
+ }
377
+ remove(entry) {
378
+ const index2 = this.findIndex((item) => item.id === entry.id);
379
+ if (~index2) {
380
+ entry.el.style.zIndex = null;
381
+ this.splice(index2, 1);
382
+ this.onChange();
383
+ }
384
+ }
385
+ moveToTop(entry) {
386
+ const index2 = this.findIndex((item) => item.id === entry.id);
387
+ if (~index2) {
388
+ this.splice(index2, 1);
389
+ this.add(entry);
390
+ }
391
+ }
392
+ }
393
+ const defaults$8 = {
394
+ condition: true
395
+ };
396
+ const colors = {
397
+ primary: "hsl(152deg 60% 50%)",
398
+ secondary: "hsl(214deg 50% 50%)",
399
+ neutral: "hsl(214deg 20% 50%)",
400
+ important: "hsl(0deg 80% 50%)"
401
+ };
402
+ function debug(options = {}) {
403
+ const props = {
404
+ name: "debug",
405
+ defaults: defaults$8,
406
+ options
407
+ };
408
+ function log(name, args = [], colorKeys = ["primary", "secondary"]) {
409
+ const colorStyles = colorKeys.map((key) => `color: ${colors[key]}`);
410
+ console.log(`%c📡 DEBUG: %c${name}`, ...colorStyles, ...args);
411
+ }
412
+ function getValue(obj, ...args) {
413
+ return typeof obj === "function" ? obj(...args) : obj;
414
+ }
415
+ const refs = {
416
+ beforeMountRef: log.bind(null, "Event > beforeMount()"),
417
+ afterMountRef: log.bind(null, "Event > afterMount()"),
418
+ beforeUnmountRef: log.bind(
419
+ null,
420
+ "Event > beforeUnmount()",
421
+ [],
422
+ ["important", "neutral"]
423
+ ),
424
+ afterUnmountRef: log.bind(
425
+ null,
426
+ "Event > afterUnmount()",
427
+ [],
428
+ ["important", "neutral"]
429
+ ),
430
+ createEntryRef: (entry, { parent: parent2, plugin }) => {
431
+ if (getValue(plugin.settings.condition, entry)) {
432
+ const count = parent2.collection.length;
433
+ log(`Event > createEntry() > [${count}] #${entry.id}`);
434
+ }
435
+ },
436
+ registerEntryRef: (entry, { parent: parent2, plugin }) => {
437
+ if (getValue(plugin.settings.condition, entry)) {
438
+ const count = parent2.collection.length;
439
+ log(`Event > registerEntry() > [${count}] #${entry.id}`);
440
+ }
441
+ },
442
+ destroyEntryRef: (entry, { parent: parent2, plugin }) => {
443
+ if (getValue(plugin.settings.condition, entry)) {
444
+ const count = parent2.collection.length;
445
+ log(
446
+ `Event > destroyEntry() > [${count}] #${entry.id}`,
447
+ [],
448
+ ["important", "neutral"]
449
+ );
450
+ }
451
+ },
452
+ deregisterEntryRef: (entry, { parent: parent2, plugin }) => {
453
+ if (getValue(plugin.settings.condition, entry)) {
454
+ const count = parent2.collection.length;
455
+ log(
456
+ `Event > deregisterEntry() > [${count}] #${entry.id}`,
457
+ [],
458
+ ["important", "neutral"]
459
+ );
460
+ }
461
+ }
462
+ };
463
+ const methods = {
464
+ // Plugin setup/teardown methods
465
+ setup({ parent: parent2 }) {
466
+ log("Plugin > setup()", arguments, ["secondary", "neutral"]);
467
+ parent2.on("beforeMount", refs.beforeMountRef);
468
+ parent2.on("createEntry", refs.createEntryRef, { parent: parent2, plugin: this });
469
+ parent2.on("registerEntry", refs.registerEntryRef, {
470
+ parent: parent2,
471
+ plugin: this
231
472
  });
232
- this.collection.splice(index2, 1);
233
- await lifecycleHook.call(entry, "afterDeregister", reReg);
234
- await lifecycleHook.call(this, "afterDeregister", entry);
473
+ parent2.on("afterMount", refs.afterMountRef);
474
+ parent2.on("beforeUnmount", refs.beforeUnmountRef);
475
+ parent2.on("destroyEntry", refs.destroyEntryRef, { parent: parent2, plugin: this });
476
+ parent2.on("deregisterEntry", refs.deregisterEntryRef, {
477
+ parent: parent2,
478
+ plugin: this
479
+ });
480
+ parent2.on("afterUnmount", refs.afterUnmountRef);
481
+ },
482
+ teardown({ parent: parent2 }) {
483
+ log("Plugin > teardown()", arguments, ["secondary", "neutral"]);
484
+ parent2.off("beforeMount", refs.beforeMountRef);
485
+ parent2.off("createEntry", refs.createEntryRef);
486
+ parent2.off("registerEntry", refs.registerEntryRef);
487
+ parent2.off("afterMount", refs.afterMountRef);
488
+ parent2.off("beforeUnmount", refs.beforeUnmountRef);
489
+ parent2.off("destroyEntry", refs.destroyEntryRef);
490
+ parent2.off("deregisterEntry", refs.deregisterEntryRef);
491
+ parent2.off("afterUnmount", refs.afterUnmountRef);
492
+ },
493
+ // Mount lifecycle hooks
494
+ beforeMount() {
495
+ log("Hook > beforeMount()", arguments);
496
+ },
497
+ onCreateEntry({ parent: parent2, entry }) {
498
+ if (getValue(this.settings.condition, entry)) {
499
+ const count = parent2.collection.length;
500
+ log(`Hook > onCreateEntry() > [${count}] #${entry.id}`, arguments);
501
+ }
502
+ },
503
+ onRegisterEntry({ parent: parent2, entry }) {
504
+ if (getValue(this.settings.condition, entry)) {
505
+ const count = parent2.collection.length - 1;
506
+ log(`Hook > onRegisterEntry() > [${count}] #${entry.id}`, arguments);
507
+ }
508
+ },
509
+ afterMount() {
510
+ log("Hook > afterMount()", arguments);
511
+ },
512
+ // Unmount lifecycle hooks
513
+ beforeUnmount() {
514
+ log("Hook > beforeUnmount()", arguments, ["important", "neutral"]);
515
+ },
516
+ onDestroyEntry({ parent: parent2, entry }) {
517
+ if (getValue(this.settings.condition, entry)) {
518
+ const count = parent2.collection.length - 1;
519
+ log(`Hook > onDestroyEntry() > [${count}] #${entry.id}`, arguments, [
520
+ "important",
521
+ "neutral"
522
+ ]);
523
+ }
524
+ },
525
+ onDeregisterEntry({ parent: parent2, entry }) {
526
+ if (getValue(this.settings.condition, entry)) {
527
+ const count = parent2.collection.length;
528
+ log(`Hook > onDeregisterEntry() > [${count}] #${entry.id}`, arguments, [
529
+ "important",
530
+ "neutral"
531
+ ]);
532
+ }
533
+ },
534
+ afterUnmount() {
535
+ log("Hook > afterUnmount()", arguments, ["important", "neutral"]);
536
+ }
537
+ };
538
+ return { ...props, ...methods };
539
+ }
540
+ const defaults$7 = {
541
+ condition: true
542
+ };
543
+ function focusTrap(options = {}) {
544
+ const props = {
545
+ name: "focusTrap",
546
+ defaults: defaults$7,
547
+ options
548
+ };
549
+ const methods = {
550
+ setup({ parent: parent2 }) {
551
+ parent2.on("opened", enableFocusTrap, this);
552
+ parent2.on("closed", disableFocusTrap, this);
553
+ },
554
+ teardown({ parent: parent2 }) {
555
+ parent2.off("opened", enableFocusTrap);
556
+ parent2.off("closed", disableFocusTrap);
557
+ },
558
+ onCreateEntry({ entry }) {
559
+ entry.focusTrap = new FocusTrap();
235
560
  }
236
- return this.collection;
561
+ };
562
+ function getValue(obj, ...args) {
563
+ return typeof obj === "function" ? obj(...args) : obj;
564
+ }
565
+ function enableFocusTrap(entry, plugin) {
566
+ var _a;
567
+ const contextObj = { plugin, parent: entry.parent, entry };
568
+ if (getValue(plugin.settings.condition, contextObj)) {
569
+ (_a = entry.focusTrap) == null ? void 0 : _a.on(entry.dialog);
570
+ }
571
+ }
572
+ function disableFocusTrap(entry, plugin) {
573
+ var _a;
574
+ const contextObj = { plugin, parent: entry.parent, entry };
575
+ if (getValue(plugin.settings.condition, contextObj)) {
576
+ (_a = entry.focusTrap) == null ? void 0 : _a.off();
577
+ }
578
+ }
579
+ return { ...props, ...methods };
580
+ }
581
+ const defaults$6 = {
582
+ // The data attributes to get the breakpoint values from.
583
+ dataBreakpoint: "breakpoint",
584
+ // The data attributes to get the media query value from.
585
+ dataMediaQuery: "media-query",
586
+ // The string token to replace in the media query string.
587
+ token: "{{BP}}",
588
+ // Sets a global breakpoint. Can be overridden by setting a data attribute
589
+ // value. Notice: setting this option will enable a media query breakpoint on
590
+ // all entries.
591
+ breakpoint: null,
592
+ // The default media query string to use. Can be overridden by setting a data
593
+ // attribute value.
594
+ mediaQuery: "(min-width: {{BP}})",
595
+ // Maps entry ID or breakpoint key to breakpoint values. This is referenced
596
+ // when getting an entries breakpoint value.
597
+ breakpoints: {},
598
+ // Maps entry ID's to a media query strings. Media query may contain a token.
599
+ // This is referenced when getting an entries media query string.
600
+ mediaQueries: {},
601
+ // The function to run when the MediaQueryList triggers a "change" event.
602
+ // This is run once on initial mount.
603
+ onChange: () => {
237
604
  }
238
- async mount(options = {}) {
239
- this.applySettings(options);
240
- await lifecycleHook.call(this, "beforeMount");
241
- const els = document.querySelectorAll(this.settings.selector);
242
- for (const el of els) {
243
- await this.register(el);
605
+ };
606
+ function mediaQuery(options = {}) {
607
+ const props = {
608
+ name: "mediaQuery",
609
+ defaults: defaults$6,
610
+ options
611
+ };
612
+ const methods = {
613
+ onCreateEntry({ entry }) {
614
+ setupMediaQueryList.call(this, entry);
615
+ },
616
+ onDestroyEntry({ entry }) {
617
+ removeMediaQueryList(entry);
244
618
  }
245
- await lifecycleHook.call(this, "afterMount");
246
- return this;
619
+ };
620
+ function getMediaQuery(entry) {
621
+ const value = entry.el.getAttribute(`data-${this.settings.dataMediaQuery}`);
622
+ if (!value && entry.id in this.settings.mediaQueries) {
623
+ return this.settings.mediaQueries[entry.id];
624
+ }
625
+ return value;
247
626
  }
248
- async unmount() {
249
- await lifecycleHook.call(this, "beforeUnmount");
250
- while (this.collection.length > 0) {
251
- await this.deregister(this.collection[0].id);
627
+ function getBreakpointValue(entry) {
628
+ let value = entry.el.getAttribute(`data-${this.settings.dataBreakpoint}`);
629
+ if (!value && entry.id in this.settings.breakpoints) {
630
+ value = this.settings.breakpoints[entry.id];
252
631
  }
253
- await lifecycleHook.call(this, "afterUnmount");
254
- return this;
632
+ if (value && value in this.settings.breakpoints) {
633
+ value = this.settings.breakpoints[value];
634
+ }
635
+ if (value) {
636
+ const customProp = getComputedStyle(document.body).getPropertyValue(`--${getPrefix()}breakpoint-${value}`).trim();
637
+ value = customProp || value;
638
+ }
639
+ return value || this.settings.breakpoint;
640
+ }
641
+ function setupMediaQueryList(entry) {
642
+ let mq = getMediaQuery.call(this, entry);
643
+ const bp = getBreakpointValue.call(this, entry);
644
+ if (!bp && !mq) return;
645
+ if (bp && !mq) {
646
+ mq = this.settings.mediaQuery;
647
+ }
648
+ const mqs = mq.replace(new RegExp(`${this.settings.token}`, "g"), bp);
649
+ entry.mql = window.matchMedia(mqs);
650
+ entry.mql.onchange = (event) => {
651
+ this.settings.onChange(event, entry);
652
+ };
653
+ this.settings.onChange(entry.mql, entry);
654
+ }
655
+ function removeMediaQueryList(entry) {
656
+ if (!entry.mql) return;
657
+ entry.mql.onchange = null;
658
+ entry.mql = null;
659
+ }
660
+ return { ...props, ...methods };
661
+ }
662
+ const defaults$5 = {
663
+ // The property on entry objects to watch.
664
+ prop: "state",
665
+ // The default value or a function to compute the initial value.
666
+ value: null,
667
+ // The local storage key prefix.
668
+ keyPrefix: "VB:",
669
+ // The local storage key to use. If not provided, module name and prop value
670
+ // will be used e.g., "VB:ModalState".
671
+ key: null,
672
+ // Condition to determine whether or not to store the value in local storage.
673
+ condition: false,
674
+ // The function to run whenever the value changes.
675
+ onChange() {
676
+ }
677
+ };
678
+ function propStore(options = {}) {
679
+ const props = {
680
+ name: "propStore",
681
+ defaults: defaults$5,
682
+ options,
683
+ store: null
684
+ };
685
+ const methods = {
686
+ setup({ parent: parent2 }) {
687
+ this.store = localStore(getKey.call(this, parent2.module));
688
+ },
689
+ async onCreateEntry({ entry }) {
690
+ await setupPropStore.call(this, entry);
691
+ },
692
+ onDestroyEntry({ entry }) {
693
+ removePropStore.call(this, entry);
694
+ }
695
+ };
696
+ async function setupPropStore(entry) {
697
+ let _value = entry[this.settings.prop] || null;
698
+ const contextObj = { plugin: this, parent: entry.parent, entry };
699
+ Object.defineProperty(entry, this.settings.prop, {
700
+ configurable: true,
701
+ get() {
702
+ return _value;
703
+ },
704
+ set: async (newValue) => {
705
+ if (_value === newValue) return;
706
+ const oldValue = _value;
707
+ _value = newValue;
708
+ const condition = getValue(
709
+ this.settings.condition,
710
+ contextObj,
711
+ newValue,
712
+ oldValue
713
+ );
714
+ if (condition) {
715
+ this.store.set(entry.id, newValue);
716
+ }
717
+ await this.settings.onChange(contextObj, newValue, oldValue);
718
+ }
719
+ });
720
+ Object.defineProperty(entry, "store", {
721
+ configurable: true,
722
+ get: () => {
723
+ return this.store.get(entry.id);
724
+ },
725
+ set: (value) => {
726
+ entry[this.settings.prop] = value;
727
+ }
728
+ });
729
+ entry[this.settings.prop] = await getValue(this.settings.value, contextObj) || entry[this.settings.prop];
730
+ }
731
+ function getValue(obj, ...args) {
732
+ return typeof obj === "function" ? obj(...args) : obj;
733
+ }
734
+ async function removePropStore(entry) {
735
+ const currentValue = entry[this.settings.prop];
736
+ delete entry[this.settings.prop];
737
+ entry[this.settings.prop] = currentValue;
738
+ this.store.set(entry.id, null);
739
+ }
740
+ function getKey(moduleName) {
741
+ const prop = this.settings.prop.charAt(0).toUpperCase() + this.settings.prop.slice(1);
742
+ const key = this.settings.key || moduleName + prop;
743
+ return this.settings.keyPrefix + key;
744
+ }
745
+ return { ...props, ...methods };
746
+ }
747
+ const defaults$4 = {
748
+ where: null,
749
+ how: "append"
750
+ };
751
+ function teleport(options = {}) {
752
+ const props = {
753
+ name: "teleport",
754
+ defaults: defaults$4,
755
+ options
756
+ };
757
+ const methods = {
758
+ onCreateEntry({ plugin, entry }) {
759
+ teleport2(plugin, entry);
760
+ },
761
+ onDestroyEntry({ plugin, entry }) {
762
+ teleportReturn(plugin, entry);
763
+ }
764
+ };
765
+ function teleport2(plugin, entry) {
766
+ entry.teleport = () => {
767
+ if (typeof entry.teleportReturn === "function") {
768
+ entry.teleportReturn();
769
+ }
770
+ entry.teleportReturn = teleportElement(
771
+ entry.el,
772
+ entry.getSetting("teleport", { fallback: plugin.settings.where }),
773
+ entry.getSetting("teleportMethod", { fallback: plugin.settings.how })
774
+ );
775
+ };
776
+ entry.teleport();
777
+ entry.parent.emit("teleport", { plugin, parent, entry });
255
778
  }
779
+ function teleportReturn(plugin, entry) {
780
+ if (typeof entry.teleportReturn === "function") {
781
+ entry.teleportReturn();
782
+ }
783
+ entry.parent.emit("teleportReturn", { plugin, parent, entry });
784
+ }
785
+ return { ...props, ...methods };
256
786
  }
787
+ const defaults$3 = {
788
+ dataConfig: "config",
789
+ customProps: []
790
+ };
257
791
  class CollectionEntry {
258
- constructor(context, query, options = {}) {
259
- this.context = context;
792
+ constructor(parent2, query, options = {}) {
793
+ this.parent = parent2;
260
794
  this.id = (query == null ? void 0 : query.id) || query;
261
795
  this.el = getElement(query);
262
- this.settings = Object.assign({}, options);
796
+ this.settings = { ...options };
263
797
  this.dataConfig = {};
264
798
  this.customProps = {};
265
- this.returnRef = null;
266
799
  }
267
- applySettings(obj) {
268
- return Object.assign(this.settings, obj);
800
+ applySettings(options) {
801
+ return Object.assign(this.settings, options);
269
802
  }
270
- getDataConfig() {
271
- return Object.assign(this.dataConfig, getConfig(this.el, this.getSetting("dataConfig")));
803
+ getSetting(key, options) {
804
+ return getSetting.call(this, key, options);
272
805
  }
273
- getCustomProps() {
274
- return Object.assign(this.customProps, getCustomProps(this));
806
+ buildDataConfig() {
807
+ return Object.assign(
808
+ this.dataConfig,
809
+ getDataConfig(this.el, this.getSetting("dataConfig"))
810
+ );
275
811
  }
276
- getSetting(key, options = {}) {
277
- return getSetting.call(this, key, options);
812
+ buildCustomProps() {
813
+ return Object.assign(this.customProps, getCustomProps(this));
278
814
  }
279
- async mount(options = {}) {
815
+ async init(options = {}) {
280
816
  if (this.el === null) {
281
- throw new Error(`${this.context.module} element was not found with ID: "${this.id}"`);
817
+ throw new Error(
818
+ `${this.parent.module} element was not found with ID: "${this.id}"`
819
+ );
282
820
  }
283
821
  this.applySettings(options);
284
- this.getDataConfig();
285
- this.getCustomProps();
286
- await lifecycleHook.call(this, "beforeMount");
287
- if (this.getSetting("teleport")) {
288
- this.teleport();
822
+ this.buildDataConfig();
823
+ this.buildCustomProps();
824
+ }
825
+ async destroy() {
826
+ Object.getOwnPropertyNames(this).forEach((prop) => {
827
+ if (prop !== "id") {
828
+ delete this[prop];
829
+ }
830
+ });
831
+ }
832
+ }
833
+ class Collection {
834
+ constructor(options = {}) {
835
+ this.module = this.constructor.name;
836
+ this.collection = [];
837
+ this.entryClass = CollectionEntry;
838
+ this.settings = { ...defaults$3, ...options };
839
+ this.plugins = new PluginsArray(this.settings.presets);
840
+ this.events = {};
841
+ Object.assign(this, eventEmitter);
842
+ }
843
+ get(value, key = "id") {
844
+ return this.collection.find((entry) => entry[key] === value);
845
+ }
846
+ applySettings(options) {
847
+ return Object.assign(this.settings, options);
848
+ }
849
+ async createEntry(query, config) {
850
+ const entry = new this.entryClass(this, query, config);
851
+ await maybeRunMethod(entry, "init");
852
+ await dispatchLifecycleHook("onCreateEntry", this, entry);
853
+ return entry;
854
+ }
855
+ async destroyEntry(entry) {
856
+ await dispatchLifecycleHook("onDestroyEntry", this, entry);
857
+ await maybeRunMethod(entry, "destroy");
858
+ return entry;
859
+ }
860
+ async register(query, config = {}) {
861
+ const element = getElement(query);
862
+ if (element === null) {
863
+ throw new Error(
864
+ `${this.module} element was not found with ID: "${(query == null ? void 0 : query.id) || query}"`
865
+ );
866
+ }
867
+ const index2 = this.collection.findIndex((item) => item.id === element.id);
868
+ if (~index2) {
869
+ const entry = this.collection[index2];
870
+ entry.el = element;
871
+ if (typeof entry.init === "function") {
872
+ await entry.init(config);
873
+ }
874
+ return entry;
875
+ } else {
876
+ const entry = await this.createEntry(element, config);
877
+ this.collection.push(entry);
878
+ await dispatchLifecycleHook("onRegisterEntry", this, entry);
879
+ return entry;
289
880
  }
290
- await lifecycleHook.call(this, "afterMount");
291
881
  }
292
- async unmount(reMount = false) {
293
- await lifecycleHook.call(this, "beforeUnmount", reMount);
294
- if (this.getSetting("teleport")) {
295
- this.teleportReturn();
882
+ async deregister(id) {
883
+ const index2 = this.collection.findIndex((entry) => entry.id === id);
884
+ if (~index2) {
885
+ const entry = await this.destroyEntry(this.collection[index2]);
886
+ await dispatchLifecycleHook(
887
+ "onDeregisterEntry",
888
+ this,
889
+ this.collection[index2]
890
+ );
891
+ this.collection.splice(index2, 1);
892
+ return entry;
296
893
  }
297
- await lifecycleHook.call(this, "afterUnmount", reMount);
894
+ return null;
298
895
  }
299
- teleport(ref = this.getSetting("teleport"), method = this.getSetting("teleportMethod")) {
300
- if (!this.returnRef) {
301
- this.returnRef = teleport(this.el, ref, method);
302
- return this.el;
303
- } else {
304
- console.error("Element has already been teleported:", this.el);
305
- return false;
896
+ async mount(options = {}) {
897
+ var _a;
898
+ this.applySettings(options);
899
+ for (const plugin of ((_a = this.settings) == null ? void 0 : _a.plugins) || []) {
900
+ this.plugins.add(plugin);
306
901
  }
307
- }
308
- teleportReturn() {
309
- if (this.returnRef) {
310
- this.returnRef = teleport(this.el, this.returnRef);
311
- return this.el;
312
- } else {
313
- console.error("No return reference found:", this.el);
314
- return false;
902
+ for (const plugin of this.plugins) {
903
+ await maybeRunMethod(plugin, "setup", { plugin, parent: this });
315
904
  }
905
+ await dispatchLifecycleHook("beforeMount", this);
906
+ const els = document.querySelectorAll(this.settings.selector);
907
+ for (const el of els) {
908
+ await this.register(el);
909
+ }
910
+ await dispatchLifecycleHook("afterMount", this);
911
+ return this;
316
912
  }
317
- }
318
- class FocusTrap {
319
- constructor(el = null, selectorFocus = "[data-focus]") {
320
- __privateAdd(this, _focusable);
321
- __privateAdd(this, _handleFocusTrap);
322
- __privateAdd(this, _handleFocusLock);
323
- this.el = el;
324
- this.selectorFocus = selectorFocus;
325
- __privateSet(this, _handleFocusTrap, handleFocusTrap.bind(this));
326
- __privateSet(this, _handleFocusLock, handleFocusLock.bind(this));
327
- }
328
- get focusable() {
329
- return __privateGet(this, _focusable);
330
- }
331
- set focusable(value) {
332
- __privateSet(this, _focusable, value);
333
- if (__privateGet(this, _focusable).length) {
334
- document.removeEventListener("keydown", __privateGet(this, _handleFocusLock));
335
- document.addEventListener("keydown", __privateGet(this, _handleFocusTrap));
336
- } else {
337
- document.removeEventListener("keydown", __privateGet(this, _handleFocusTrap));
338
- document.addEventListener("keydown", __privateGet(this, _handleFocusLock));
339
- }
340
- }
341
- get focusableFirst() {
342
- return this.focusable[0];
343
- }
344
- get focusableLast() {
345
- return this.focusable[this.focusable.length - 1];
346
- }
347
- mount(el, selectorFocus) {
348
- if (el) this.el = el;
349
- if (selectorFocus) this.selectorFocus = selectorFocus;
350
- this.focusable = this.getFocusable();
351
- this.focus();
352
- }
353
- unmount() {
354
- this.el = null;
355
- this.focusable = [];
356
- document.removeEventListener("keydown", __privateGet(this, _handleFocusTrap));
357
- document.removeEventListener("keydown", __privateGet(this, _handleFocusLock));
358
- }
359
- focus(el = this.el, selectorFocus = this.selectorFocus) {
360
- const result = el.querySelector(selectorFocus) || el;
361
- result.focus();
362
- }
363
- getFocusable(el = this.el) {
364
- const focusable = [];
365
- const initFocus = document.activeElement;
366
- const initScrollTop = el.scrollTop;
367
- const selector = focusableSelectors.join(",");
368
- const els = el.querySelectorAll(selector);
369
- els.forEach((el2) => {
370
- el2.focus();
371
- if (document.activeElement === el2) {
372
- focusable.push(el2);
373
- }
374
- });
375
- el.scrollTop = initScrollTop;
376
- initFocus.focus();
377
- return focusable;
378
- }
379
- }
380
- _focusable = new WeakMap();
381
- _handleFocusTrap = new WeakMap();
382
- _handleFocusLock = new WeakMap();
383
- const notInert = ":not([inert])";
384
- const notNegTabIndex = ':not([tabindex^="-"])';
385
- const notDisabled = ":not(:disabled)";
386
- const focusableSelectors = [
387
- `a[href]${notInert}${notNegTabIndex}`,
388
- `area[href]${notInert}${notNegTabIndex}`,
389
- `input:not([type="hidden"]):not([type="radio"])${notInert}${notNegTabIndex}${notDisabled}`,
390
- `input[type="radio"]${notInert}${notNegTabIndex}${notDisabled}`,
391
- `select${notInert}${notNegTabIndex}${notDisabled}`,
392
- `textarea${notInert}${notNegTabIndex}${notDisabled}`,
393
- `button${notInert}${notNegTabIndex}${notDisabled}`,
394
- `details${notInert} > summary:first-of-type${notNegTabIndex}`,
395
- `iframe${notInert}${notNegTabIndex}`,
396
- `audio[controls]${notInert}${notNegTabIndex}`,
397
- `video[controls]${notInert}${notNegTabIndex}`,
398
- `[contenteditable]${notInert}${notNegTabIndex}`,
399
- `[tabindex]${notInert}${notNegTabIndex}`
400
- ];
401
- function handleFocusTrap(event) {
402
- const isTab = event.key === "Tab" || event.keyCode === 9;
403
- if (!isTab) return;
404
- if (event.shiftKey) {
405
- if (document.activeElement === this.focusableFirst || document.activeElement === this.el) {
406
- event.preventDefault();
407
- this.focusableLast.focus();
913
+ async unmount() {
914
+ await dispatchLifecycleHook("beforeUnmount", this);
915
+ while (this.collection.length > 0) {
916
+ await this.deregister(this.collection[0].id);
408
917
  }
409
- } else {
410
- if (document.activeElement === this.focusableLast || document.activeElement === this.el) {
411
- event.preventDefault();
412
- this.focusableFirst.focus();
918
+ await dispatchLifecycleHook("afterUnmount", this);
919
+ for (const plugin of this.plugins) {
920
+ await maybeRunMethod(plugin, "teardown", { plugin, parent: this });
413
921
  }
414
- }
415
- }
416
- function handleFocusLock(event) {
417
- const isTab = event.key === "Tab" || event.keyCode === 9;
418
- if (isTab) event.preventDefault();
419
- }
420
- function localStore(key, enable = true) {
421
- const local = localStorage.getItem(key);
422
- const store = local ? JSON.parse(local) : {};
423
- return {
424
- get(prop) {
425
- return prop ? store[prop] : store;
426
- },
427
- set(prop, value) {
428
- if (value) {
429
- store[prop] = value;
430
- } else {
431
- delete store[prop];
432
- }
433
- if (enable) localStorage.setItem(key, JSON.stringify(store));
434
- return store;
922
+ for (const plugin of [...this.plugins]) {
923
+ this.plugins.remove(plugin.name);
435
924
  }
436
- };
437
- }
438
- function teleport(what, where, how) {
439
- const isComment = where.nodeType === Node.COMMENT_NODE;
440
- const isElement2 = where.nodeType === Node.ELEMENT_NODE;
441
- where = isComment || isElement2 ? where : document.querySelector(where);
442
- if (isComment) how = "after";
443
- if (!where) throw new Error(`Not a valid teleport reference: '${where}'`);
444
- if (typeof where[how] != "function") throw new Error(`Not a valid teleport method: '${how}'`);
445
- let returnRef = null;
446
- if (!isComment) {
447
- returnRef = document.createComment("teleported #" + what.id);
448
- what.before(returnRef);
449
- }
450
- where[how](what);
451
- if (isComment) {
452
- where.remove();
925
+ return this;
453
926
  }
454
- return returnRef;
455
927
  }
456
928
  function themeStore(options) {
457
929
  const settings = {
@@ -477,9 +949,9 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
477
949
  }
478
950
  const profile = localStore(settings.storeKey);
479
951
  const api = {
480
- // Store our settings in the API.
952
+ // Store our settings in the API
481
953
  settings,
482
- // Actions.
954
+ // Actions
483
955
  add(value) {
484
956
  settings.themes.push(value);
485
957
  },
@@ -490,7 +962,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
490
962
  callback(name) {
491
963
  callbacks[name].call(this);
492
964
  },
493
- // Getters.
965
+ // Getters
494
966
  get class() {
495
967
  return `${settings.prefix}${this.theme}`;
496
968
  },
@@ -500,7 +972,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
500
972
  get themes() {
501
973
  return settings.themes;
502
974
  },
503
- // Setup the theme get and set methods.
975
+ // Setup the theme get and set methods
504
976
  get theme() {
505
977
  return profile.get("theme") || "root";
506
978
  },
@@ -522,32 +994,61 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
522
994
  }
523
995
  const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
524
996
  __proto__: null,
525
- Breakpoint,
526
997
  Collection,
527
998
  CollectionEntry,
528
999
  FocusTrap,
1000
+ FocusableArray,
1001
+ PluginsArray,
1002
+ StackArray,
529
1003
  cssVar,
530
- getConfig,
1004
+ debug,
1005
+ dispatchLifecycleHook,
1006
+ eventEmitter,
1007
+ focusTrap,
1008
+ focusableSelectors,
531
1009
  getCustomProps,
1010
+ getDataConfig,
532
1011
  getElement,
533
1012
  getPrefix,
534
1013
  getSetting,
535
- lifecycleHook,
536
1014
  localStore,
1015
+ maybeRunMethod,
1016
+ mediaQuery,
1017
+ propStore,
537
1018
  setGlobalState,
538
1019
  teleport,
1020
+ teleportElement,
539
1021
  themeStore,
540
1022
  toCamel,
541
1023
  toKebab,
542
1024
  toMilliseconds,
543
1025
  transition
544
1026
  }, Symbol.toStringTag, { value: "Module" }));
1027
+ const presets = {
1028
+ focusTrap: {
1029
+ condition: ({ entry }) => {
1030
+ return entry.state === "closed" || entry.state === "opened" && entry.mode === "modal";
1031
+ }
1032
+ },
1033
+ mediaQuery: {
1034
+ onChange(event, entry) {
1035
+ entry.mode = event.matches ? "inline" : "modal";
1036
+ }
1037
+ },
1038
+ propStore: {
1039
+ prop: "inlineState",
1040
+ value: ({ entry }) => entry.store,
1041
+ condition: ({ entry }) => ["opened", "closed", "indeterminate"].includes(entry.state),
1042
+ onChange: ({ entry }) => entry.applyState()
1043
+ }
1044
+ };
545
1045
  const defaults$2 = {
1046
+ // Plugin presets
1047
+ presets,
546
1048
  // Data attributes
547
1049
  dataOpen: "drawer-open",
548
1050
  dataClose: "drawer-close",
549
1051
  dataToggle: "drawer-toggle",
550
- dataBreakpoint: "drawer-breakpoint",
551
1052
  // Selectors
552
1053
  selector: ".drawer",
553
1054
  selectorDialog: ".drawer__dialog",
@@ -563,90 +1064,13 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
563
1064
  // Classes
564
1065
  classModal: "drawer_modal",
565
1066
  // Feature toggles
566
- customProps: [
567
- "transition-duration"
568
- ],
1067
+ customProps: ["transition-duration"],
569
1068
  breakpoints: null,
570
1069
  customEventPrefix: "drawer:",
571
- store: true,
572
- storeKey: "VB:DrawerState",
573
1070
  setTabindex: true,
574
- teleport: null,
575
- teleportMethod: "prepend",
576
1071
  transition: true,
577
1072
  transitionDuration: 300
578
1073
  };
579
- function applyInitialState(entry) {
580
- if (entry.store === "opened") {
581
- entry.open(false, false);
582
- } else if (entry.store === "closed") {
583
- entry.close(false, false);
584
- } else if (entry.store === "indeterminate") {
585
- entry.state = "indeterminate";
586
- } else {
587
- if (entry.el.classList.contains(entry.getSetting("stateOpened"))) {
588
- entry.open(false, false);
589
- } else if (entry.el.classList.contains(entry.getSetting("stateClosed"))) {
590
- entry.close(false, false);
591
- } else {
592
- entry.state = "indeterminate";
593
- }
594
- }
595
- }
596
- async function applyInlineState(entry) {
597
- if (entry.store === "opened") {
598
- await entry.open(false, false);
599
- } else if (entry.store === "closed") {
600
- await entry.close(false, false);
601
- } else if (entry.store === "indeterminate") {
602
- if (entry.state != "indeterminate") {
603
- entry.state = "indeterminate";
604
- }
605
- } else {
606
- if (entry.state != entry.inlineState) {
607
- entry.state = entry.inlineState;
608
- }
609
- if (entry.inlineState === "opened") {
610
- await entry.open(false, false);
611
- } else if (entry.inlineState === "closed") {
612
- await entry.close(false, false);
613
- }
614
- }
615
- }
616
- function getBreakpoint(drawer) {
617
- const prefix = getPrefix();
618
- const bp = drawer.getAttribute(`data-${this.settings.dataBreakpoint}`);
619
- if (this.settings.breakpoints && this.settings.breakpoints[bp]) {
620
- return this.settings.breakpoints[bp];
621
- } else if (getComputedStyle(document.body).getPropertyValue(`--${prefix}breakpoint-${bp}`).trim()) {
622
- return getComputedStyle(document.body).getPropertyValue(`--${prefix}breakpoint-${bp}`).trim();
623
- } else {
624
- return bp;
625
- }
626
- }
627
- function getDrawer(query) {
628
- const entry = typeof query === "string" ? this.get(query) : query;
629
- if (entry) {
630
- return entry;
631
- } else {
632
- throw new Error(`Drawer not found in collection with id of "${query.id || query}".`);
633
- }
634
- }
635
- function updateFocusState$1(entry) {
636
- if (entry.state === "opened") {
637
- if (entry.mode === "modal") {
638
- this.focusTrap.mount(entry.dialog, this.settings.selectorFocus);
639
- } else {
640
- this.focusTrap.focus(entry.dialog, this.settings.selectorFocus);
641
- }
642
- } else {
643
- if (entry.trigger) {
644
- entry.trigger.focus();
645
- entry.trigger = null;
646
- }
647
- this.focusTrap.unmount();
648
- }
649
- }
650
1074
  function switchMode(entry) {
651
1075
  switch (entry.mode) {
652
1076
  case "inline":
@@ -660,61 +1084,57 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
660
1084
  async function toInline(entry) {
661
1085
  entry.el.classList.remove(entry.getSetting("classModal"));
662
1086
  entry.dialog.removeAttribute("aria-modal");
663
- setGlobalState(false, entry.getSetting("selectorInert"), entry.getSetting("selectorOverflow"));
664
- this.focusTrap.unmount();
665
- await applyInlineState(entry);
666
- entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "switchMode", {
667
- detail: this,
668
- bubbles: true
669
- }));
1087
+ setGlobalState(
1088
+ false,
1089
+ entry.getSetting("selectorInert"),
1090
+ entry.getSetting("selectorOverflow")
1091
+ );
1092
+ entry.applyState();
1093
+ entry.el.dispatchEvent(
1094
+ new CustomEvent(entry.getSetting("customEventPrefix") + "switchMode", {
1095
+ detail: this,
1096
+ bubbles: true
1097
+ })
1098
+ );
1099
+ await entry.parent.emit("switchMode", entry);
670
1100
  return entry;
671
1101
  }
672
1102
  async function toModal(entry) {
673
1103
  entry.el.classList.add(entry.getSetting("classModal"));
674
1104
  entry.dialog.setAttribute("aria-modal", "true");
675
1105
  await entry.close(false, false);
676
- entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "switchMode", {
677
- detail: this,
678
- bubbles: true
679
- }));
1106
+ entry.el.dispatchEvent(
1107
+ new CustomEvent(entry.getSetting("customEventPrefix") + "switchMode", {
1108
+ detail: this,
1109
+ bubbles: true
1110
+ })
1111
+ );
1112
+ await entry.parent.emit("switchMode", entry);
680
1113
  return entry;
681
1114
  }
682
1115
  class DrawerEntry extends CollectionEntry {
683
- constructor(context, query, options = {}) {
684
- super(context, query, options);
1116
+ constructor(parent2, query, options = {}) {
1117
+ super(parent2, query, options);
685
1118
  __privateAdd(this, _mode);
686
- __privateAdd(this, _state);
687
- __privateAdd(this, _breakpoint);
688
1119
  this.dialog = null;
689
1120
  this.trigger = null;
690
- __privateSet(this, _breakpoint, new Breakpoint());
1121
+ this.state = null;
1122
+ this.inlineState = null;
691
1123
  __privateSet(this, _mode, "indeterminate");
692
- __privateSet(this, _state, "indeterminate");
693
- this.inlineState = "indeterminate";
694
- }
695
- get breakpoint() {
696
- return getBreakpoint.call(this.context, this.el);
697
- }
698
- get store() {
699
- return this.context.store.get(this.id);
700
1124
  }
701
1125
  get mode() {
702
1126
  return __privateGet(this, _mode);
703
1127
  }
704
1128
  set mode(value) {
1129
+ if (__privateGet(this, _mode) === value) return;
705
1130
  __privateSet(this, _mode, value);
706
- switchMode.call(this.context, this);
1131
+ switchMode.call(this.parent, this);
707
1132
  }
708
- get state() {
709
- return __privateGet(this, _state);
710
- }
711
- set state(value) {
712
- __privateSet(this, _state, value);
713
- if (this.mode === "inline" && value != "opening" && value != "closing") {
1133
+ setState(value) {
1134
+ this.state = value;
1135
+ const ignoreStates = ["opening", "closing"];
1136
+ if (this.mode === "inline" && !ignoreStates.includes(value)) {
714
1137
  this.inlineState = value;
715
- if (this.getSetting("store")) {
716
- this.context.store.set(this.id, value);
717
- }
718
1138
  }
719
1139
  if (value === "indeterminate") {
720
1140
  this.el.classList.remove(this.getSetting("stateOpened"));
@@ -723,56 +1143,63 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
723
1143
  this.el.classList.remove(this.getSetting("stateClosing"));
724
1144
  }
725
1145
  }
1146
+ async applyState() {
1147
+ if (this.mode === "modal") return;
1148
+ if (this.inlineState === "opened") {
1149
+ return await this.open(false, false);
1150
+ }
1151
+ if (this.inlineState === "closed") {
1152
+ return await this.close(false, false);
1153
+ }
1154
+ if (this.state === null) {
1155
+ if (this.el.classList.contains(this.getSetting("stateOpened"))) {
1156
+ return await this.open(false, false);
1157
+ }
1158
+ if (this.el.classList.contains(this.getSetting("stateClosed"))) {
1159
+ return await this.close(false, false);
1160
+ }
1161
+ }
1162
+ return this.setState("indeterminate");
1163
+ }
726
1164
  async open(transition2, focus) {
727
- return this.context.open(this, transition2, focus);
1165
+ return this.parent.open(this, transition2, focus);
728
1166
  }
729
1167
  async close(transition2, focus) {
730
- return this.context.close(this, transition2, focus);
1168
+ return this.parent.close(this, transition2, focus);
731
1169
  }
732
1170
  async toggle(transition2, focus) {
733
- return this.context.toggle(this, transition2, focus);
1171
+ return this.parent.toggle(this, transition2, focus);
734
1172
  }
735
1173
  async deregister() {
736
- return this.context.deregister(this.id);
737
- }
738
- mountBreakpoint() {
739
- const value = this.breakpoint;
740
- const handler = this.handleBreakpoint.bind(this);
741
- __privateGet(this, _breakpoint).mount(value, handler);
742
- }
743
- unmountBreakpoint() {
744
- __privateGet(this, _breakpoint).unmount();
745
- }
746
- handleBreakpoint(event) {
747
- const bpMode = event.matches ? "inline" : "modal";
748
- if (this.mode != bpMode) {
749
- this.mode = bpMode;
750
- }
1174
+ return this.parent.deregister(this.id);
751
1175
  }
752
- async beforeMount() {
1176
+ async onCreateEntry() {
753
1177
  const dialog = this.el.querySelector(this.getSetting("selectorDialog"));
754
1178
  this.dialog = dialog ? dialog : this.el;
755
1179
  if (this.getSetting("setTabindex")) {
756
1180
  this.dialog.setAttribute("tabindex", "-1");
757
1181
  }
758
- applyInitialState(this);
1182
+ await this.applyState();
759
1183
  this.inlineState = this.state;
760
1184
  this.mode = this.el.classList.contains(this.getSetting("classModal")) ? "modal" : "inline";
761
- if (this.breakpoint) {
762
- this.mountBreakpoint();
763
- }
764
1185
  }
765
- async beforeUnmount(close2 = true) {
766
- if (close2 && this.state === "opened") {
1186
+ async onDestroyEntry() {
1187
+ if (this.mode === "modal" && this.state === "opened") {
767
1188
  await this.close(false);
768
1189
  }
769
- this.context.store.set(this.id);
770
- this.unmountBreakpoint();
771
1190
  }
772
1191
  }
773
1192
  _mode = new WeakMap();
774
- _state = new WeakMap();
775
- _breakpoint = new WeakMap();
1193
+ function getDrawer(query) {
1194
+ const entry = typeof query === "string" ? this.get(query) : query;
1195
+ if (entry) {
1196
+ return entry;
1197
+ } else {
1198
+ throw new Error(
1199
+ `Drawer not found in collection with id of "${query.id || query}".`
1200
+ );
1201
+ }
1202
+ }
776
1203
  async function handleClick$2(event) {
777
1204
  const trigger = event.target.closest(`
778
1205
  [data-${this.settings.dataOpen}],
@@ -805,8 +1232,8 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
805
1232
  entry.trigger = trigger;
806
1233
  return entry.close();
807
1234
  } else {
808
- const parent = event.target.closest(this.settings.selector);
809
- if (parent) return this.close(parent.id);
1235
+ const parent2 = event.target.closest(this.settings.selector);
1236
+ if (parent2) return this.close(parent2.id);
810
1237
  }
811
1238
  });
812
1239
  }
@@ -821,10 +1248,20 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
821
1248
  if (this.activeModal) return this.close(this.activeModal.id);
822
1249
  }
823
1250
  }
1251
+ function updateFocusState$1(entry) {
1252
+ if (entry.state === "opened") {
1253
+ (entry.dialog.querySelector(this.settings.selectorFocus) || entry.dialog).focus();
1254
+ } else {
1255
+ if (entry.trigger) {
1256
+ entry.trigger.focus();
1257
+ entry.trigger = null;
1258
+ }
1259
+ }
1260
+ }
824
1261
  async function open$2(query, transitionOverride, focus = true) {
825
1262
  const entry = getDrawer.call(this, query);
826
- if (entry.state === "closed" || entry.state === "indeterminate") {
827
- entry.state = "opening";
1263
+ if (entry.state === "closed" || entry.state === "indeterminate" || entry.state === null) {
1264
+ entry.setState("opening");
828
1265
  if (transitionOverride != void 0 ? transitionOverride : entry.getSetting("transition")) {
829
1266
  await transition(
830
1267
  entry.el,
@@ -837,22 +1274,30 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
837
1274
  entry.el.classList.add(entry.getSetting("stateOpened"));
838
1275
  entry.el.classList.remove(entry.getSetting("stateClosed"));
839
1276
  }
840
- entry.state = "opened";
841
- if (entry.mode === "modal") setGlobalState(true, entry.getSetting("selectorInert"), entry.getSetting("selectorOverflow"));
1277
+ entry.setState("opened");
1278
+ if (entry.mode === "modal")
1279
+ setGlobalState(
1280
+ true,
1281
+ entry.getSetting("selectorInert"),
1282
+ entry.getSetting("selectorOverflow")
1283
+ );
842
1284
  if (focus) {
843
1285
  updateFocusState$1.call(this, entry);
844
1286
  }
845
- entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "opened", {
846
- detail: this,
847
- bubbles: true
848
- }));
1287
+ entry.el.dispatchEvent(
1288
+ new CustomEvent(entry.getSetting("customEventPrefix") + "opened", {
1289
+ detail: this,
1290
+ bubbles: true
1291
+ })
1292
+ );
1293
+ await entry.parent.emit("opened", entry);
849
1294
  }
850
1295
  return entry;
851
1296
  }
852
1297
  async function close$2(query, transitionOverride, focus = true) {
853
1298
  const entry = getDrawer.call(this, query);
854
- if (entry.state === "opened" || entry.state === "indeterminate") {
855
- entry.state = "closing";
1299
+ if (entry.state === "opened" || entry.state === "indeterminate" || entry.state === null) {
1300
+ entry.setState("closing");
856
1301
  document.activeElement.blur();
857
1302
  if (transitionOverride != void 0 ? transitionOverride : entry.getSetting("transition")) {
858
1303
  await transition(
@@ -866,15 +1311,23 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
866
1311
  entry.el.classList.add(entry.getSetting("stateClosed"));
867
1312
  entry.el.classList.remove(entry.getSetting("stateOpened"));
868
1313
  }
869
- entry.state = "closed";
870
- if (entry.mode === "modal") setGlobalState(false, entry.getSetting("selectorInert"), entry.getSetting("selectorOverflow"));
1314
+ entry.setState("closed");
1315
+ if (entry.mode === "modal")
1316
+ setGlobalState(
1317
+ false,
1318
+ entry.getSetting("selectorInert"),
1319
+ entry.getSetting("selectorOverflow")
1320
+ );
871
1321
  if (focus) {
872
1322
  updateFocusState$1.call(this, entry);
873
1323
  }
874
- entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "closed", {
875
- detail: this,
876
- bubbles: true
877
- }));
1324
+ entry.el.dispatchEvent(
1325
+ new CustomEvent(entry.getSetting("customEventPrefix") + "closed", {
1326
+ detail: this,
1327
+ bubbles: true
1328
+ })
1329
+ );
1330
+ await entry.parent.emit("closed", entry);
878
1331
  }
879
1332
  return entry;
880
1333
  }
@@ -891,19 +1344,16 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
891
1344
  super({ ...defaults$2, ...options });
892
1345
  __privateAdd(this, _handleClick);
893
1346
  __privateAdd(this, _handleKeydown);
894
- this.focusTrap = new FocusTrap();
1347
+ this.module = "Drawer";
1348
+ this.entryClass = DrawerEntry;
895
1349
  __privateSet(this, _handleClick, handleClick$2.bind(this));
896
1350
  __privateSet(this, _handleKeydown, handleKeydown$2.bind(this));
897
- this.store = localStore(this.settings.storeKey, this.settings.store);
898
1351
  }
899
1352
  get activeModal() {
900
1353
  return this.collection.find((entry) => {
901
1354
  return entry.state === "opened" && entry.mode === "modal";
902
1355
  });
903
1356
  }
904
- async createEntry(query, config) {
905
- return new DrawerEntry(this, query, config);
906
- }
907
1357
  async open(id, transition2, focus) {
908
1358
  return open$2.call(this, id, transition2, focus);
909
1359
  }
@@ -946,19 +1396,15 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
946
1396
  stateClosing: "is-closing",
947
1397
  stateClosed: "is-closed",
948
1398
  // Feature settings
949
- customProps: [
950
- "transition-duration"
951
- ],
1399
+ customProps: ["transition-duration"],
952
1400
  customEventPrefix: "modal:",
953
1401
  setTabindex: true,
954
- teleport: null,
955
- teleportMethod: "append",
956
1402
  transition: true,
957
1403
  transitionDuration: 300
958
1404
  };
959
1405
  class ModalEntry extends CollectionEntry {
960
- constructor(context, query, options = {}) {
961
- super(context, query, options);
1406
+ constructor(parent2, query, options = {}) {
1407
+ super(parent2, query, options);
962
1408
  this.state = "closed";
963
1409
  this.dialog = null;
964
1410
  }
@@ -966,18 +1412,18 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
966
1412
  return this.dialog.matches(this.getSetting("selectorRequired"));
967
1413
  }
968
1414
  async open(transition2, focus) {
969
- return this.context.open(this, transition2, focus);
1415
+ return this.parent.open(this, transition2, focus);
970
1416
  }
971
1417
  async close(transition2, focus) {
972
- return this.context.close(this, transition2, focus);
1418
+ return this.parent.close(this, transition2, focus);
973
1419
  }
974
1420
  async replace(transition2, focus) {
975
- return this.context.replace(this, transition2, focus);
1421
+ return this.parent.replace(this, transition2, focus);
976
1422
  }
977
1423
  async deregister() {
978
- return this.context.deregister(this.id);
1424
+ return this.parent.deregister(this.id);
979
1425
  }
980
- async beforeMount() {
1426
+ async onCreateEntry() {
981
1427
  const dialog = this.el.querySelector(this.getSetting("selectorDialog"));
982
1428
  this.dialog = dialog ? dialog : this.el;
983
1429
  this.dialog.setAttribute("aria-modal", "true");
@@ -988,7 +1434,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
988
1434
  this.dialog.setAttribute("tabindex", "-1");
989
1435
  }
990
1436
  }
991
- async afterRegister() {
1437
+ async onRegisterEntry() {
992
1438
  if (this.el.classList.contains(this.getSetting("stateOpened"))) {
993
1439
  await this.open(false);
994
1440
  } else {
@@ -997,11 +1443,9 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
997
1443
  this.el.classList.add(this.getSetting("stateClosed"));
998
1444
  }
999
1445
  }
1000
- async beforeUnmount(reMount = false) {
1001
- if (!reMount && this.state === "opened") {
1446
+ async onDestroyEntry() {
1447
+ if (this.state === "opened") {
1002
1448
  await this.close(false);
1003
- } else {
1004
- this.context.stack.remove(this);
1005
1449
  }
1006
1450
  }
1007
1451
  }
@@ -1010,18 +1454,9 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1010
1454
  if (entry) {
1011
1455
  return entry;
1012
1456
  } else {
1013
- throw new Error(`Modal not found in collection with id of "${query.id || query}".`);
1014
- }
1015
- }
1016
- function updateFocusState() {
1017
- if (this.active) {
1018
- this.focusTrap.mount(this.active.dialog, this.settings.selectorFocus);
1019
- } else {
1020
- if (this.trigger) {
1021
- this.trigger.focus();
1022
- this.trigger = null;
1023
- }
1024
- this.focusTrap.unmount();
1457
+ throw new Error(
1458
+ `Modal not found in collection with id of "${query.id || query}".`
1459
+ );
1025
1460
  }
1026
1461
  }
1027
1462
  async function handleClick$1(event) {
@@ -1062,6 +1497,16 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1062
1497
  }
1063
1498
  }
1064
1499
  }
1500
+ function updateFocusState() {
1501
+ if (this.active) {
1502
+ (this.active.dialog.querySelector(this.settings.selectorFocus) || this.active.dialog).focus();
1503
+ } else {
1504
+ if (this.trigger) {
1505
+ this.trigger.focus();
1506
+ this.trigger = null;
1507
+ }
1508
+ }
1509
+ }
1065
1510
  async function open$1(query, transitionOverride = void 0, focus = true) {
1066
1511
  const entry = getModal.call(this, query);
1067
1512
  this.stack.moveToTop(entry);
@@ -1085,10 +1530,13 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1085
1530
  if (focus) {
1086
1531
  updateFocusState.call(this);
1087
1532
  }
1088
- entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "opened", {
1089
- detail: this,
1090
- bubbles: true
1091
- }));
1533
+ entry.el.dispatchEvent(
1534
+ new CustomEvent(entry.getSetting("customEventPrefix") + "opened", {
1535
+ detail: entry,
1536
+ bubbles: true
1537
+ })
1538
+ );
1539
+ await entry.parent.emit("opened", entry);
1092
1540
  return entry;
1093
1541
  }
1094
1542
  async function close$1(query, transitionOverride, focus = true) {
@@ -1113,23 +1561,25 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1113
1561
  if (focus) {
1114
1562
  updateFocusState.call(this);
1115
1563
  }
1116
- entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "closed", {
1117
- detail: this,
1118
- bubbles: true
1119
- }));
1564
+ entry.el.dispatchEvent(
1565
+ new CustomEvent(entry.getSetting("customEventPrefix") + "closed", {
1566
+ detail: entry,
1567
+ bubbles: true
1568
+ })
1569
+ );
1570
+ await entry.parent.emit("closed", entry);
1120
1571
  }
1121
1572
  return entry;
1122
1573
  }
1123
1574
  async function closeAll$1(exclude, transition2) {
1124
1575
  const result = [];
1125
- await Promise.all(this.stack.value.map(async (modal) => {
1126
- if (exclude && exclude === modal.id) {
1127
- Promise.resolve();
1128
- } else {
1129
- result.push(await close$1.call(this, modal, transition2, false));
1130
- }
1131
- modal.trigger = null;
1132
- }));
1576
+ await Promise.all(
1577
+ this.stack.copy.map(async (entry) => {
1578
+ if (exclude && exclude === entry.id) return;
1579
+ result.push(await close$1.call(this, entry, transition2, false));
1580
+ entry.trigger = null;
1581
+ })
1582
+ );
1133
1583
  return result;
1134
1584
  }
1135
1585
  async function replace(query, transition2, focus = true) {
@@ -1148,72 +1598,29 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1148
1598
  }
1149
1599
  return { opened: resultOpened, closed: resultClosed };
1150
1600
  }
1151
- function stack(settings) {
1152
- const stackArray = [];
1153
- return {
1154
- get value() {
1155
- return [...stackArray];
1156
- },
1157
- get top() {
1158
- const result = stackArray[stackArray.length - 1];
1159
- return result ? result : null;
1160
- },
1161
- updateIndex() {
1162
- stackArray.forEach((entry, index2) => {
1163
- entry.el.style.zIndex = null;
1164
- const value = getComputedStyle(entry.el)["z-index"];
1165
- entry.el.style.zIndex = parseInt(value) + index2 + 1;
1166
- });
1167
- },
1168
- setGlobalState() {
1169
- setGlobalState(this.top, settings.selectorInert, settings.selectorOverflow);
1170
- this.updateIndex();
1171
- },
1172
- add(entry) {
1173
- entry.el.style.zIndex = null;
1174
- const value = getComputedStyle(entry.el)["z-index"];
1175
- entry.el.style.zIndex = parseInt(value) + stackArray.length + 1;
1176
- stackArray.push(entry);
1177
- this.setGlobalState();
1178
- },
1179
- remove(entry) {
1180
- const index2 = stackArray.findIndex((item) => {
1181
- return item.id === entry.id;
1182
- });
1183
- if (index2 >= 0) {
1184
- entry.el.style.zIndex = null;
1185
- stackArray.splice(index2, 1);
1186
- this.setGlobalState();
1187
- }
1188
- },
1189
- moveToTop(entry) {
1190
- const index2 = stackArray.findIndex((item) => {
1191
- return item.id === entry.id;
1192
- });
1193
- if (index2 >= 0) {
1194
- stackArray.splice(index2, 1);
1195
- this.add(entry);
1196
- }
1197
- }
1198
- };
1199
- }
1200
1601
  class Modal extends Collection {
1201
1602
  constructor(options) {
1202
1603
  super({ ...defaults$1, ...options });
1203
1604
  __privateAdd(this, _handleClick2);
1204
1605
  __privateAdd(this, _handleKeydown2);
1606
+ this.module = "Modal";
1607
+ this.entryClass = ModalEntry;
1205
1608
  this.trigger = null;
1206
- this.focusTrap = new FocusTrap();
1207
1609
  __privateSet(this, _handleClick2, handleClick$1.bind(this));
1208
1610
  __privateSet(this, _handleKeydown2, handleKeydown$1.bind(this));
1209
- this.stack = stack(this.settings);
1611
+ this.stack = new StackArray({
1612
+ onChange: () => {
1613
+ setGlobalState(
1614
+ this.stack.top,
1615
+ this.settings.selectorInert,
1616
+ this.settings.selectorOverflow
1617
+ );
1618
+ }
1619
+ });
1210
1620
  }
1211
1621
  get active() {
1212
1622
  return this.stack.top;
1213
1623
  }
1214
- async createEntry(query, config) {
1215
- return new ModalEntry(this, query, config);
1216
- }
1217
1624
  async open(id, transition2, focus) {
1218
1625
  return open$1.call(this, id, transition2, focus);
1219
1626
  }
@@ -1261,16 +1668,14 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1261
1668
  "arrow-padding",
1262
1669
  "toggle-delay"
1263
1670
  ],
1671
+ customEventPrefix: "popover:",
1264
1672
  placement: "bottom",
1265
1673
  event: "click",
1266
1674
  offset: 0,
1267
1675
  flipPadding: 0,
1268
1676
  shiftPadding: 0,
1269
1677
  arrowPadding: 0,
1270
- toggleDelay: 0,
1271
- // Feature settings
1272
- teleport: null,
1273
- teleportMethod: "append"
1678
+ toggleDelay: 0
1274
1679
  };
1275
1680
  function applyPositionStyle(el, x, y) {
1276
1681
  Object.assign(el.style, {
@@ -1374,16 +1779,25 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1374
1779
  if (popover.trigger === this.trigger) {
1375
1780
  this.trigger = null;
1376
1781
  }
1782
+ popover.el.dispatchEvent(
1783
+ new CustomEvent(popover.getSetting("customEventPrefix") + "closed", {
1784
+ detail: this,
1785
+ bubbles: true
1786
+ })
1787
+ );
1788
+ await popover.parent.emit("closed", popover);
1377
1789
  }
1378
1790
  return popover;
1379
1791
  }
1380
1792
  async function closeAll() {
1381
1793
  const result = [];
1382
- await Promise.all(this.collection.map(async (popover) => {
1383
- if (popover.state === "opened") {
1384
- result.push(await close.call(this, popover));
1385
- }
1386
- }));
1794
+ await Promise.all(
1795
+ this.collection.map(async (popover) => {
1796
+ if (popover.state === "opened") {
1797
+ result.push(await close.call(this, popover));
1798
+ }
1799
+ })
1800
+ );
1387
1801
  return result;
1388
1802
  }
1389
1803
  function closeCheck(popover) {
@@ -1393,7 +1807,6 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1393
1807
  let isFocused = document.activeElement.closest(
1394
1808
  `#${popover.id}, [aria-controls="${popover.id}"], [aria-describedby="${popover.id}"]`
1395
1809
  );
1396
- isFocused = isFocused ? isFocused.matches(":focus-visible") : false;
1397
1810
  if (!isHovered && !isFocused) {
1398
1811
  popover.close();
1399
1812
  }
@@ -1439,9 +1852,12 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1439
1852
  if (popover.toggleDelayId) {
1440
1853
  clearTimeout(popover.toggleDelayId);
1441
1854
  }
1442
- popover.toggleDelayId = setTimeout(() => {
1443
- closeCheck.call(this, popover);
1444
- }, getDelay(popover, 1));
1855
+ popover.toggleDelayId = setTimeout(
1856
+ () => {
1857
+ closeCheck.call(this, popover);
1858
+ },
1859
+ getDelay(popover, 1)
1860
+ );
1445
1861
  }, 1);
1446
1862
  }
1447
1863
  function handleKeydown(event) {
@@ -1480,8 +1896,8 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1480
1896
  });
1481
1897
  }
1482
1898
  class PopoverEntry extends CollectionEntry {
1483
- constructor(context, query, options = {}) {
1484
- super(context, query, options);
1899
+ constructor(parent2, query, options = {}) {
1900
+ super(parent2, query, options);
1485
1901
  __privateAdd(this, _eventListeners);
1486
1902
  __privateAdd(this, _isHovered);
1487
1903
  this.state = "closed";
@@ -1514,31 +1930,35 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1514
1930
  }
1515
1931
  }
1516
1932
  async open() {
1517
- return this.context.open(this);
1933
+ return this.parent.open(this);
1518
1934
  }
1519
1935
  async close() {
1520
- return this.context.close(this);
1936
+ return this.parent.close(this);
1521
1937
  }
1522
1938
  async deregister() {
1523
- return this.context.deregister(this.id);
1939
+ return this.parent.deregister(this.id);
1524
1940
  }
1525
1941
  registerEventListeners() {
1526
1942
  if (!__privateGet(this, _eventListeners)) {
1527
1943
  const eventType = this.getSetting("event");
1528
1944
  if (eventType === "hover") {
1529
- __privateSet(this, _eventListeners, [{
1530
- el: ["el", "trigger"],
1531
- type: ["mouseenter", "focus"],
1532
- listener: handleMouseEnter.bind(this.context, this)
1533
- }, {
1534
- el: ["el", "trigger"],
1535
- type: ["mouseleave", "focusout"],
1536
- listener: handleMouseLeave.bind(this.context, this)
1537
- }, {
1538
- el: ["trigger"],
1539
- type: ["click"],
1540
- listener: handleTooltipClick.bind(this.context, this)
1541
- }]);
1945
+ __privateSet(this, _eventListeners, [
1946
+ {
1947
+ el: ["el", "trigger"],
1948
+ type: ["mouseenter", "focus"],
1949
+ listener: handleMouseEnter.bind(this.parent, this)
1950
+ },
1951
+ {
1952
+ el: ["el", "trigger"],
1953
+ type: ["mouseleave", "focusout"],
1954
+ listener: handleMouseLeave.bind(this.parent, this)
1955
+ },
1956
+ {
1957
+ el: ["trigger"],
1958
+ type: ["click"],
1959
+ listener: handleTooltipClick.bind(this.parent, this)
1960
+ }
1961
+ ]);
1542
1962
  __privateGet(this, _eventListeners).forEach((evObj) => {
1543
1963
  evObj.el.forEach((el) => {
1544
1964
  evObj.type.forEach((type) => {
@@ -1547,11 +1967,13 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1547
1967
  });
1548
1968
  });
1549
1969
  } else {
1550
- __privateSet(this, _eventListeners, [{
1551
- el: ["trigger"],
1552
- type: ["click"],
1553
- listener: handleClick.bind(this.context, this)
1554
- }]);
1970
+ __privateSet(this, _eventListeners, [
1971
+ {
1972
+ el: ["trigger"],
1973
+ type: ["click"],
1974
+ listener: handleClick.bind(this.parent, this)
1975
+ }
1976
+ ]);
1555
1977
  __privateGet(this, _eventListeners).forEach((evObj) => {
1556
1978
  evObj.el.forEach((el) => {
1557
1979
  evObj.type.forEach((type) => {
@@ -1574,7 +1996,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1574
1996
  __privateSet(this, _eventListeners, null);
1575
1997
  }
1576
1998
  }
1577
- async beforeMount() {
1999
+ async onCreateEntry() {
1578
2000
  this.trigger = document.querySelector(
1579
2001
  `[aria-controls="${this.id}"], [aria-describedby="${this.id}"]`
1580
2002
  );
@@ -1586,14 +2008,14 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
1586
2008
  }
1587
2009
  this.registerEventListeners();
1588
2010
  }
1589
- async afterRegister() {
2011
+ async onRegisterEntry() {
1590
2012
  if (this.el.classList.contains(this.getSetting("stateActive"))) {
1591
2013
  await this.open();
1592
2014
  } else {
1593
2015
  this.el.inert = true;
1594
2016
  }
1595
2017
  }
1596
- async beforeUnmount() {
2018
+ async onDestroyEntry() {
1597
2019
  if (this.state === "opened") {
1598
2020
  await this.close();
1599
2021
  }
@@ -2045,15 +2467,20 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
2045
2467
  const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
2046
2468
  const nextPlacement = placements[nextIndex];
2047
2469
  if (nextPlacement) {
2048
- return {
2049
- data: {
2050
- index: nextIndex,
2051
- overflows: overflowsData
2052
- },
2053
- reset: {
2054
- placement: nextPlacement
2055
- }
2056
- };
2470
+ var _overflowsData$;
2471
+ const ignoreCrossAxisOverflow = checkCrossAxis === "alignment" ? initialSideAxis !== getSideAxis(nextPlacement) : false;
2472
+ const hasInitialMainAxisOverflow = ((_overflowsData$ = overflowsData[0]) == null ? void 0 : _overflowsData$.overflows[0]) > 0;
2473
+ if (!ignoreCrossAxisOverflow || hasInitialMainAxisOverflow) {
2474
+ return {
2475
+ data: {
2476
+ index: nextIndex,
2477
+ overflows: overflowsData
2478
+ },
2479
+ reset: {
2480
+ placement: nextPlacement
2481
+ }
2482
+ };
2483
+ }
2057
2484
  }
2058
2485
  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;
2059
2486
  if (!resetPlacement) {
@@ -2360,7 +2787,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
2360
2787
  function isContainingBlock(elementOrCss) {
2361
2788
  const webkit = isWebKit();
2362
2789
  const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
2363
- 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));
2790
+ return ["transform", "translate", "scale", "rotate", "perspective"].some((value) => css[value] ? css[value] !== "none" : false) || (css.containerType ? css.containerType !== "normal" : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== "none" : false) || !webkit && (css.filter ? css.filter !== "none" : false) || ["transform", "translate", "scale", "rotate", "perspective", "filter"].some((value) => (css.willChange || "").includes(value)) || ["paint", "layout", "strict", "content"].some((value) => (css.contain || "").includes(value));
2364
2791
  }
2365
2792
  function getContainingBlock(element) {
2366
2793
  let currentNode = getParentNode(element);
@@ -2556,6 +2983,28 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
2556
2983
  y
2557
2984
  });
2558
2985
  }
2986
+ function getWindowScrollBarX(element, rect) {
2987
+ const leftScroll = getNodeScroll(element).scrollLeft;
2988
+ if (!rect) {
2989
+ return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
2990
+ }
2991
+ return rect.left + leftScroll;
2992
+ }
2993
+ function getHTMLOffset(documentElement, scroll, ignoreScrollbarX) {
2994
+ if (ignoreScrollbarX === void 0) {
2995
+ ignoreScrollbarX = false;
2996
+ }
2997
+ const htmlRect = documentElement.getBoundingClientRect();
2998
+ const x = htmlRect.left + scroll.scrollLeft - (ignoreScrollbarX ? 0 : (
2999
+ // RTL <body> scrollbar.
3000
+ getWindowScrollBarX(documentElement, htmlRect)
3001
+ ));
3002
+ const y = htmlRect.top + scroll.scrollTop;
3003
+ return {
3004
+ x,
3005
+ y
3006
+ };
3007
+ }
2559
3008
  function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
2560
3009
  let {
2561
3010
  elements,
@@ -2587,23 +3036,17 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
2587
3036
  offsets.y = offsetRect.y + offsetParent.clientTop;
2588
3037
  }
2589
3038
  }
3039
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll, true) : createCoords(0);
2590
3040
  return {
2591
3041
  width: rect.width * scale.x,
2592
3042
  height: rect.height * scale.y,
2593
- x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
2594
- y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
3043
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
3044
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
2595
3045
  };
2596
3046
  }
2597
3047
  function getClientRects(element) {
2598
3048
  return Array.from(element.getClientRects());
2599
3049
  }
2600
- function getWindowScrollBarX(element, rect) {
2601
- const leftScroll = getNodeScroll(element).scrollLeft;
2602
- if (!rect) {
2603
- return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
2604
- }
2605
- return rect.left + leftScroll;
2606
- }
2607
3050
  function getDocumentRect(element) {
2608
3051
  const html = getDocumentElement(element);
2609
3052
  const scroll = getNodeScroll(element);
@@ -2673,9 +3116,10 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
2673
3116
  } else {
2674
3117
  const visualOffsets = getVisualOffsets(element);
2675
3118
  rect = {
2676
- ...clippingAncestor,
2677
3119
  x: clippingAncestor.x - visualOffsets.x,
2678
- y: clippingAncestor.y - visualOffsets.y
3120
+ y: clippingAncestor.y - visualOffsets.y,
3121
+ width: clippingAncestor.width,
3122
+ height: clippingAncestor.height
2679
3123
  };
2680
3124
  }
2681
3125
  return rectToClientRect(rect);
@@ -2758,6 +3202,9 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
2758
3202
  scrollTop: 0
2759
3203
  };
2760
3204
  const offsets = createCoords(0);
3205
+ function setLeftRTLScrollbarOffset() {
3206
+ offsets.x = getWindowScrollBarX(documentElement);
3207
+ }
2761
3208
  if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
2762
3209
  if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
2763
3210
  scroll = getNodeScroll(offsetParent);
@@ -2767,19 +3214,15 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
2767
3214
  offsets.x = offsetRect.x + offsetParent.clientLeft;
2768
3215
  offsets.y = offsetRect.y + offsetParent.clientTop;
2769
3216
  } else if (documentElement) {
2770
- offsets.x = getWindowScrollBarX(documentElement);
3217
+ setLeftRTLScrollbarOffset();
2771
3218
  }
2772
3219
  }
2773
- let htmlX = 0;
2774
- let htmlY = 0;
2775
- if (documentElement && !isOffsetParentAnElement && !isFixed) {
2776
- const htmlRect = documentElement.getBoundingClientRect();
2777
- htmlY = htmlRect.top + scroll.scrollTop;
2778
- htmlX = htmlRect.left + scroll.scrollLeft - // RTL <body> scrollbar.
2779
- getWindowScrollBarX(documentElement, htmlRect);
3220
+ if (isFixed && !isOffsetParentAnElement && documentElement) {
3221
+ setLeftRTLScrollbarOffset();
2780
3222
  }
2781
- const x = rect.left + scroll.scrollLeft - offsets.x - htmlX;
2782
- const y = rect.top + scroll.scrollTop - offsets.y - htmlY;
3223
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
3224
+ const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
3225
+ const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
2783
3226
  return {
2784
3227
  x,
2785
3228
  y,
@@ -2856,6 +3299,9 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
2856
3299
  isElement,
2857
3300
  isRTL
2858
3301
  };
3302
+ function rectsAreEqual(a, b) {
3303
+ return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
3304
+ }
2859
3305
  function observeMove(element, onMove) {
2860
3306
  let io = null;
2861
3307
  let timeoutId;
@@ -2874,12 +3320,13 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
2874
3320
  threshold = 1;
2875
3321
  }
2876
3322
  cleanup();
3323
+ const elementRectForRootMargin = element.getBoundingClientRect();
2877
3324
  const {
2878
3325
  left,
2879
3326
  top,
2880
3327
  width,
2881
3328
  height
2882
- } = element.getBoundingClientRect();
3329
+ } = elementRectForRootMargin;
2883
3330
  if (!skip) {
2884
3331
  onMove();
2885
3332
  }
@@ -2910,6 +3357,9 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
2910
3357
  refresh(false, ratio);
2911
3358
  }
2912
3359
  }
3360
+ if (ratio === 1 && !rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) {
3361
+ refresh();
3362
+ }
2913
3363
  isFirstUpdate = false;
2914
3364
  }
2915
3365
  try {
@@ -2918,7 +3368,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
2918
3368
  // Handle <iframe>s
2919
3369
  root: root.ownerDocument
2920
3370
  });
2921
- } catch (e) {
3371
+ } catch (_e) {
2922
3372
  io = new IntersectionObserver(handleObserve, options);
2923
3373
  }
2924
3374
  io.observe(element);
@@ -2973,7 +3423,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
2973
3423
  }
2974
3424
  function frameLoop() {
2975
3425
  const nextRefRect = getBoundingClientRect(reference);
2976
- if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
3426
+ if (prevRefRect && !rectsAreEqual(prevRefRect, nextRefRect)) {
2977
3427
  update();
2978
3428
  }
2979
3429
  prevRefRect = nextRefRect;
@@ -3021,7 +3471,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
3021
3471
  if (!popover.isTooltip) {
3022
3472
  popover.trigger.setAttribute("aria-expanded", "true");
3023
3473
  }
3024
- popover.getCustomProps();
3474
+ popover.buildCustomProps();
3025
3475
  const middlewareOptions = getMiddlewareOptions(popover);
3026
3476
  const arrowEl = popover.el.querySelector(middlewareOptions.arrow.element);
3027
3477
  middlewareOptions.arrow.element = arrowEl ? arrowEl : void 0;
@@ -3050,12 +3500,21 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
3050
3500
  if (popover.getSetting("event") === "click") {
3051
3501
  handleDocumentClick.call(this, popover);
3052
3502
  }
3503
+ popover.el.dispatchEvent(
3504
+ new CustomEvent(popover.getSetting("customEventPrefix") + "opened", {
3505
+ detail: this,
3506
+ bubbles: true
3507
+ })
3508
+ );
3509
+ await popover.parent.emit("opened", popover);
3053
3510
  return popover;
3054
3511
  }
3055
3512
  class Popover extends Collection {
3056
3513
  constructor(options = {}) {
3057
3514
  super({ ...defaults, ...options });
3058
3515
  __privateAdd(this, _handleKeydown3);
3516
+ this.module = "Popover";
3517
+ this.entryClass = PopoverEntry;
3059
3518
  this.trigger = null;
3060
3519
  __privateSet(this, _handleKeydown3, handleKeydown.bind(this));
3061
3520
  }
@@ -3067,9 +3526,6 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
3067
3526
  return popover.state == "opened" && popover.getSetting("event") == "hover";
3068
3527
  });
3069
3528
  }
3070
- async createEntry(query, config) {
3071
- return new PopoverEntry(this, query, config);
3072
- }
3073
3529
  async open(id) {
3074
3530
  return open.call(this, id);
3075
3531
  }