inclusive-elements 0.4.0 → 0.4.1

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.
@@ -1,534 +1,20 @@
1
- var T = Object.defineProperty;
2
- var D = (r, a, t) => a in r ? T(r, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[a] = t;
3
- var s = (r, a, t) => (D(r, typeof a != "symbol" ? a + "" : a, t), t);
4
- import { move as A, hello as h, goodbye as c, cancel as v } from "hello-goodbye";
5
- import { isFocusable as H, focusable as k } from "tabbable";
6
- import { createFocusTrap as K } from "focus-trap";
7
- import { autoUpdate as M, computePosition as E, shift as L, flip as x, size as O } from "@floating-ui/dom";
8
- class F extends HTMLElement {
9
- constructor() {
10
- super(...arguments);
11
- s(this, "onToggle", (t) => {
12
- const e = t.target;
13
- e.open && this.querySelectorAll(
14
- ":scope > :is(ui-disclosure, details)"
15
- ).forEach((i) => {
16
- i.toggleAttribute("open", i === e), this.required && i.toggleAttribute("disabled", i === e);
17
- });
18
- });
19
- }
20
- connectedCallback() {
21
- this.addEventListener("toggle", this.onToggle, { capture: !0 });
22
- }
23
- disconnectedCallback() {
24
- this.removeEventListener("toggle", this.onToggle, { capture: !0 });
25
- }
26
- get required() {
27
- return this.hasAttribute("required");
28
- }
29
- }
30
- const w = class extends HTMLElement {
31
- constructor() {
32
- super();
33
- s(this, "timeouts", /* @__PURE__ */ new Map());
34
- s(this, "index", 0);
35
- new MutationObserver((e) => {
36
- e.forEach((i) => {
37
- i.addedNodes.forEach((n) => {
38
- n instanceof HTMLElement && this.show(n);
39
- });
40
- });
41
- }).observe(this, { childList: !0 });
42
- }
43
- connectedCallback() {
44
- this.hasAttribute("role") || this.setAttribute("role", "status"), this.hasAttribute("aria-live") || this.setAttribute("aria-live", "polite"), this.hasAttribute("aria-relevant") || this.setAttribute("aria-relevant", "additions");
45
- for (const t of this.children)
46
- this.show(t, { animate: !1 });
47
- }
48
- show(t, e = {}) {
49
- const i = e.key || t.dataset.key || String(this.index++);
50
- t.dataset.key = i, this.contains(t) ? h(t) : e.animate === !1 ? this.append(t) : A(this.children, () => {
51
- this.append(t), h(t);
52
- });
53
- const n = Number(
54
- e.duration !== void 0 ? e.duration : t.dataset.duration || w.duration
55
- );
56
- return n > 0 && (this.startTimeout(t, n), t.addEventListener("mouseenter", this.clearTimeout.bind(this, t)), t.addEventListener("focusin", this.clearTimeout.bind(this, t)), t.addEventListener(
57
- "mouseleave",
58
- this.startTimeout.bind(this, t, n)
59
- ), t.addEventListener(
60
- "focusout",
61
- this.startTimeout.bind(this, t, n)
62
- )), i;
63
- }
64
- dismiss(t) {
65
- if (typeof t == "string") {
66
- this.querySelectorAll(
67
- `[data-key="${t}"]`
68
- ).forEach((e) => {
69
- this.dismiss(e);
70
- });
71
- return;
72
- }
73
- A(this.children, () => {
74
- c(t).then(() => this.removeChild(t));
75
- }), this.clearTimeout(t);
76
- }
77
- clear() {
78
- Array.from(this.children).forEach((t) => {
79
- this.dismiss(t);
80
- });
81
- }
82
- speak(t) {
83
- const e = document.createElement("div");
84
- Object.assign(e.style, {
85
- clip: "rect(0 0 0 0)",
86
- clipPath: "inset(50%)",
87
- height: "1px",
88
- overflow: "hidden",
89
- position: "absolute",
90
- whiteSpace: "nowrap",
91
- width: "1px"
92
- }), e.textContent = t, this.show(e);
93
- }
94
- startTimeout(t, e) {
95
- this.clearTimeout(t), this.timeouts.set(
96
- t,
97
- window.setTimeout(() => {
98
- this.dismiss(t);
99
- }, e)
100
- );
101
- }
102
- clearTimeout(t) {
103
- this.timeouts.has(t) && clearTimeout(this.timeouts.get(t));
104
- }
105
- };
106
- let p = w;
107
- s(p, "duration", 1e4);
108
- function C(r) {
109
- return r.altKey || r.ctrlKey || r.metaKey || r.shiftKey || r.button !== void 0 && r.button !== 0;
110
- }
111
- class $ extends HTMLElement {
112
- constructor() {
113
- super(...arguments);
114
- s(this, "onButtonClick", (t) => {
115
- !C(t) && !this.disabled && (this.open = !this.open, t.preventDefault());
116
- });
117
- }
118
- static get observedAttributes() {
119
- return ["open"];
120
- }
121
- connectedCallback() {
122
- this.content.hidden = !this.open, this.button.setAttribute("aria-expanded", String(this.open)), this.button.addEventListener("click", this.onButtonClick);
123
- }
124
- disconnectedCallback() {
125
- v(this.content), this.button.removeAttribute("aria-expanded"), this.button.removeEventListener("click", this.onButtonClick);
126
- }
127
- get open() {
128
- return this.hasAttribute("open");
129
- }
130
- set open(t) {
131
- t ? this.setAttribute("open", "") : this.removeAttribute("open");
132
- }
133
- get disabled() {
134
- return this.hasAttribute("disabled");
135
- }
136
- attributeChangedCallback(t, e, i) {
137
- t === "open" && (i !== null ? this.wasOpened() : this.wasClosed());
138
- }
139
- wasOpened() {
140
- this.content.hidden && (this.content.hidden = !1, h(this.content)), this.button.setAttribute("aria-expanded", "true"), this.dispatchEvent(new Event("toggle"));
141
- }
142
- wasClosed() {
143
- this.content.hidden || c(this.content).then(() => this.content.hidden = !0), this.button.setAttribute("aria-expanded", "false"), this.dispatchEvent(new Event("toggle"));
144
- }
145
- get button() {
146
- return this.querySelector("button, [role=button]");
147
- }
148
- get content() {
149
- return this.children[1];
150
- }
151
- }
152
- const g = class extends HTMLElement {
153
- constructor() {
154
- super(...arguments);
155
- s(this, "search", "");
156
- s(this, "searchTimeout");
157
- s(this, "onKeyDown", (t) => {
158
- if (!this.hidden) {
159
- if (t.key === "ArrowUp") {
160
- this.navigate(-1), t.preventDefault();
161
- return;
162
- }
163
- if (t.key === "ArrowDown") {
164
- this.navigate(1), t.preventDefault();
165
- return;
166
- }
167
- t.key.length > 1 || t.ctrlKey || t.metaKey || t.altKey || (this.search += t.key.toLowerCase(), t.preventDefault(), clearTimeout(this.searchTimeout), this.searchTimeout = window.setTimeout(() => {
168
- this.search = "";
169
- }, g.searchDelay), this.items.some((e) => {
170
- var i;
171
- return ((i = e.textContent) == null ? void 0 : i.trim().toLowerCase().indexOf(this.search)) === 0 ? (e.focus(), !0) : !1;
172
- }));
173
- }
174
- });
175
- }
176
- connectedCallback() {
177
- this.hasAttribute("role") || this.setAttribute("role", "menu"), this.hasAttribute("tabindex") || this.setAttribute("tabindex", "-1"), this.items.forEach((t) => {
178
- t.hasAttribute("tabindex") || t.setAttribute("tabindex", "-1");
179
- }), this.addEventListener("keydown", this.onKeyDown);
180
- }
181
- disconnectedCallback() {
182
- this.removeEventListener("keydown", this.onKeyDown);
183
- }
184
- get items() {
185
- return Array.from(
186
- this.querySelectorAll("[role^=menuitem]")
187
- ).filter((t) => H(t));
188
- }
189
- navigate(t) {
190
- var n;
191
- const e = this.items;
192
- let i = (document.activeElement instanceof HTMLElement ? e.indexOf(document.activeElement) : -1) + t;
193
- i < 0 && (i = e.length - 1), i >= e.length && (i = 0), (n = e[i]) == null || n.focus();
194
- }
195
- };
196
- let f = g;
197
- s(f, "searchDelay", 800);
198
- const l = class extends HTMLElement {
199
- constructor() {
200
- super();
201
- s(this, "focusTrap");
202
- s(this, "connected", !1);
203
- const t = document.createElement("template");
204
- t.innerHTML = `
205
- <div part="backdrop" style="position: fixed; top: 0; left: 0; right: 0; bottom: 0"></div>
206
- <div part="content" style="z-index: 1"><slot></slot></div>
207
- `;
208
- const e = this.attachShadow({ mode: "open" });
209
- e.appendChild(t.content.cloneNode(!0)), this.backdrop.addEventListener("click", () => {
210
- var i;
211
- this.hasAttribute("static") ? (i = l.attention) == null || i.call(l, e.children[1]) : this.close();
212
- }), this.focusTrap = K(this, {
213
- escapeDeactivates: !1,
214
- allowOutsideClick: !0,
215
- preventScroll: !0
216
- });
217
- }
218
- static get observedAttributes() {
219
- return ["open"];
220
- }
221
- connectedCallback() {
222
- var t, e, i, n, o, y;
223
- this.connected = !0, (t = this.content) != null && t.hasAttribute("role") || (e = this.content) == null || e.setAttribute("role", "dialog"), (i = this.content) != null && i.hasAttribute("aria-modal") || (n = this.content) == null || n.setAttribute("aria-modal", "true"), (o = this.content) != null && o.hasAttribute("tabindex") || (y = this.content) == null || y.setAttribute("tabindex", "-1"), this.addEventListener("keydown", (b) => {
224
- b.key === "Escape" && this.open && (b.preventDefault(), b.stopPropagation(), this.close());
225
- }), this.open && this.wasOpened();
226
- }
227
- disconnectedCallback() {
228
- this.connected = !1;
229
- }
230
- get open() {
231
- return this.hasAttribute("open");
232
- }
233
- set open(t) {
234
- t ? this.setAttribute("open", "") : this.removeAttribute("open");
235
- }
236
- close() {
237
- if (!this.open)
238
- return;
239
- const t = new Event("beforeclose", { cancelable: !0 });
240
- this.dispatchEvent(t) && (this.open = !1);
241
- }
242
- attributeChangedCallback(t, e, i) {
243
- t !== "open" || !this.connected || (i !== null ? this.wasOpened() : this.wasClosed());
244
- }
245
- wasOpened() {
246
- var t, e;
247
- this.hidden = !1, h(this), (t = this.focusTrap) == null || t.activate(), (e = this.querySelector("[autofocus]")) == null || e.focus(), this.dispatchEvent(new Event("open"));
248
- }
249
- wasClosed() {
250
- var t;
251
- (t = this.focusTrap) == null || t.deactivate(), c(this).then(() => this.hidden = !0), this.dispatchEvent(new Event("close"));
252
- }
253
- get backdrop() {
254
- var t;
255
- return (t = this.shadowRoot) == null ? void 0 : t.firstElementChild;
256
- }
257
- get content() {
258
- return this.firstElementChild;
259
- }
260
- };
261
- let m = l;
262
- s(m, "attention", (t) => t.animate(
263
- [
264
- { transform: "scale(1)" },
265
- { transform: "scale(1.1)" },
266
- { transform: "scale(1)" }
267
- ],
268
- 300
269
- ));
270
- class U extends HTMLElement {
271
- constructor() {
272
- super();
273
- s(this, "cleanup");
274
- s(this, "onButtonClick", (t) => {
275
- !C(t) && !this.disabled && (this.open = !this.open, t.preventDefault());
276
- });
277
- s(this, "onButtonKeyDown", (t) => {
278
- var e;
279
- t.key === "ArrowDown" && !this.disabled && (t.preventDefault(), this.open = !0, (e = k(this.content)[0]) == null || e.focus());
280
- });
281
- s(this, "onKeyDown", (t) => {
282
- t.key === "Escape" && this.open && (t.preventDefault(), t.stopPropagation(), this.open = !1, this.button.focus());
283
- });
284
- s(this, "onFocusOut", (t) => {
285
- (!(t.relatedTarget instanceof Node) || !this.contains(t.relatedTarget)) && (this.open = !1);
286
- });
287
- s(this, "onContentClick", (t) => {
288
- t.target instanceof Element && t.target.closest("[role=menuitem], [role=menuitemradio]") && (this.open = !1, this.button.focus());
289
- });
290
- const t = document.createElement("template");
291
- t.innerHTML = `
292
- <div part="backdrop" hidden style="position: fixed; top: 0; left: 0; right: 0; bottom: 0"></div>
293
- <slot></slot>
294
- `, this.attachShadow({ mode: "open" }).appendChild(t.content.cloneNode(!0)), this.backdrop.onclick = () => this.open = !1;
295
- }
296
- static get observedAttributes() {
297
- return ["open"];
298
- }
299
- connectedCallback() {
300
- this.backdrop.hidden = !0, this.content.hidden = !0, this.open = !1, this.button.setAttribute("aria-expanded", "false"), setTimeout(() => {
301
- this.content.getAttribute("role") === "menu" && this.button.setAttribute("aria-haspopup", "true");
302
- }), this.button.addEventListener("click", this.onButtonClick), this.button.addEventListener("keydown", this.onButtonKeyDown), this.addEventListener("keydown", this.onKeyDown), this.addEventListener("focusout", this.onFocusOut), this.content.addEventListener("click", this.onContentClick);
303
- }
304
- disconnectedCallback() {
305
- v(this.backdrop), v(this.content), this.button.removeAttribute("aria-expanded"), this.button.removeAttribute("aria-haspopup"), this.button.removeEventListener("click", this.onButtonClick), this.button.removeEventListener("keydown", this.onButtonKeyDown), this.removeEventListener("keydown", this.onKeyDown), this.removeEventListener("focusout", this.onFocusOut), this.content.removeEventListener("click", this.onContentClick);
306
- }
307
- get open() {
308
- return this.hasAttribute("open");
309
- }
310
- set open(t) {
311
- t ? this.setAttribute("open", "") : this.removeAttribute("open");
312
- }
313
- get disabled() {
314
- return this.hasAttribute("disabled");
315
- }
316
- attributeChangedCallback(t, e, i) {
317
- t === "open" && (i !== null ? this.wasOpened() : this.wasClosed());
318
- }
319
- wasOpened() {
320
- if (!this.content.hidden)
321
- return;
322
- this.content.hidden = !1, this.content.style.position = "absolute", this.backdrop.hidden = !1, h(this.content), h(this.backdrop), this.button.setAttribute("aria-expanded", "true"), this.cleanup = M(
323
- this.button,
324
- this.content,
325
- () => {
326
- E(this.button, this.content, {
327
- placement: this.getAttribute("placement") || "bottom",
328
- middleware: [
329
- L(),
330
- x(),
331
- O({
332
- apply: ({ availableWidth: e, availableHeight: i }) => {
333
- Object.assign(this.content.style, {
334
- maxWidth: "",
335
- maxHeight: ""
336
- });
337
- const n = getComputedStyle(this.content);
338
- (n.maxWidth === "none" || e < parseInt(n.maxWidth)) && (this.content.style.maxWidth = `${e}px`), (n.maxHeight === "none" || i < parseInt(n.maxHeight)) && (this.content.style.maxHeight = `${i}px`);
339
- }
340
- })
341
- ]
342
- }).then(({ x: e, y: i, placement: n }) => {
343
- Object.assign(this.content.style, {
344
- left: `${e}px`,
345
- top: `${i}px`
346
- }), this.content.dataset.placement = n;
347
- });
348
- },
349
- { ancestorScroll: !1 }
350
- );
351
- const t = this.content.querySelector("[autofocus]");
352
- t ? t.focus() : this.content.focus(), this.dispatchEvent(new Event("open"));
353
- }
354
- wasClosed() {
355
- var t;
356
- this.content.hidden || (this.button.setAttribute("aria-expanded", "false"), (t = this.cleanup) == null || t.call(this), c(this.backdrop).then(() => this.backdrop.hidden = !0), c(this.content).then(() => this.content.hidden = !0), this.dispatchEvent(new Event("close")));
357
- }
358
- get backdrop() {
359
- var t;
360
- return (t = this.shadowRoot) == null ? void 0 : t.firstElementChild;
361
- }
362
- get button() {
363
- return this.querySelector("button, [role=button]");
364
- }
365
- get content() {
366
- return this.children[1];
367
- }
368
- }
369
- let S = 0;
370
- class R extends HTMLElement {
371
- constructor() {
372
- super(...arguments);
373
- s(this, "idPrefix", "tabs" + ++S);
374
- s(this, "onKeyDown", (t) => {
375
- const e = t.target, i = this.tabs.indexOf(e), n = this.tablist.getAttribute("aria-orientation") === "vertical";
376
- let o = !1;
377
- switch (t.key) {
378
- case (n ? "ArrowUp" : "ArrowLeft"):
379
- this.selectTab(i - 1), o = !0;
380
- break;
381
- case (n ? "ArrowDown" : "ArrowRight"):
382
- this.selectTab(i + 1), o = !0;
383
- break;
384
- case "Home":
385
- this.selectTab(0), o = !0;
386
- break;
387
- case "End":
388
- this.selectTab(this.tabs.length - 1), o = !0;
389
- }
390
- o && (t.stopPropagation(), t.preventDefault());
391
- });
392
- s(this, "onClick", (t) => {
393
- const i = t.target.closest("[role=tab]");
394
- i && this.selectTab(this.tabs.indexOf(i));
395
- });
396
- }
397
- connectedCallback() {
398
- this.tablist.addEventListener("keydown", this.onKeyDown), this.tablist.addEventListener("click", this.onClick), this.selectTab(0, !1), this.tabs.forEach((t, e) => {
399
- const i = this.tabpanels[e], n = t.getAttribute("id") || this.idPrefix + "_tab_" + e, o = i.getAttribute("id") || this.idPrefix + "_panel_" + e;
400
- t.setAttribute("id", n), t.setAttribute("aria-controls", o), i.setAttribute("id", o), i.setAttribute("aria-labelledby", n), i.setAttribute("tabindex", "0");
401
- });
402
- }
403
- disconnectedCallback() {
404
- this.tablist.removeEventListener("keydown", this.onKeyDown), this.tablist.removeEventListener("click", this.onClick);
405
- }
406
- selectTab(t, e = !0) {
407
- t < 0 ? t += this.tabs.length : t >= this.tabs.length && (t -= this.tabs.length), this.tabs.forEach((i, n) => {
408
- n === t ? (i.setAttribute("aria-selected", "true"), i.removeAttribute("tabindex"), this.tabpanels[n].hidden = !1, e && i.focus()) : (i.setAttribute("aria-selected", "false"), i.setAttribute("tabindex", "-1"), this.tabpanels[n].hidden = !0);
409
- });
410
- }
411
- get tablist() {
412
- return this.querySelector("[role=tablist]");
413
- }
414
- get tabs() {
415
- return Array.from(this.querySelectorAll("[role=tab]"));
416
- }
417
- get tabpanels() {
418
- return Array.from(this.querySelectorAll("[role=tabpanel]"));
419
- }
420
- }
421
- class j extends HTMLElement {
422
- constructor() {
423
- super(...arguments);
424
- s(this, "onInitialFocus", () => {
425
- this.removeAttribute("tabindex"), this.focusControlAtIndex(0);
426
- });
427
- s(this, "onKeyDown", (t) => {
428
- if (t.key !== "ArrowRight" && t.key !== "ArrowLeft" && t.key !== "Home" && t.key !== "End")
429
- return;
430
- const e = this.controls, i = this.controls.length, n = e.indexOf(t.target);
431
- if (n === -1)
432
- return;
433
- let o = 0;
434
- t.key === "ArrowLeft" && (o = n - 1), t.key === "ArrowRight" && (o = n + 1), t.key === "End" && (o = i - 1), o < 0 && (o = i - 1), o > i - 1 && (o = 0), this.focusControlAtIndex(o), t.preventDefault();
435
- });
436
- }
437
- connectedCallback() {
438
- this.hasAttribute("role") || this.setAttribute("role", "toolbar"), this.setAttribute("tabindex", "0"), this.addEventListener("focus", this.onInitialFocus, { once: !0 }), this.addEventListener("keydown", this.onKeyDown);
439
- }
440
- disconnectedCallback() {
441
- this.removeEventListener("keydown", this.onKeyDown);
442
- }
443
- focusControlAtIndex(t) {
444
- this.controls.forEach((e, i) => {
445
- i === t ? (e.setAttribute("tabindex", "0"), e.focus()) : e.setAttribute("tabindex", "-1");
446
- });
447
- }
448
- get controls() {
449
- return k(this);
450
- }
451
- }
452
- const u = class extends HTMLElement {
453
- constructor() {
454
- super(...arguments);
455
- s(this, "parent");
456
- s(this, "tooltip");
457
- s(this, "timeout");
458
- s(this, "observer");
459
- s(this, "showing", !1);
460
- s(this, "onMouseEnter", this.afterDelay.bind(this, this.show));
461
- s(this, "onFocus", this.show.bind(this));
462
- s(this, "onMouseLeave", this.afterDelay.bind(this, this.hide));
463
- s(this, "onBlur", this.hide.bind(this));
464
- s(this, "onPointerUp", (t) => {
465
- t.pointerType === "mouse" ? this.hide() : this.show();
466
- });
467
- s(this, "onKeyDown", (t) => {
468
- t.key === "Escape" && this.hide();
469
- });
470
- }
471
- connectedCallback() {
472
- this.parent = this.parentNode, this.parent && (this.parent.addEventListener("mouseenter", this.onMouseEnter), this.parent.addEventListener("focus", this.onFocus), this.parent.addEventListener("mouseleave", this.onMouseLeave), this.parent.addEventListener("blur", this.onBlur), this.parent.addEventListener("pointerup", this.onPointerUp), this.observer = new MutationObserver((t) => {
473
- t.forEach((e) => {
474
- e.attributeName === "disabled" && this.hide();
475
- });
476
- }), this.observer.observe(this.parent, { attributes: !0 })), document.addEventListener("keydown", this.onKeyDown), document.addEventListener("scroll", this.onBlur);
477
- }
478
- disconnectedCallback() {
479
- var t;
480
- this.tooltip && (this.tooltip.remove(), this.tooltip = void 0), this.parent && (this.parent.removeEventListener("mouseenter", this.onMouseEnter), this.parent.removeEventListener("focus", this.onFocus), this.parent.removeEventListener("mouseleave", this.onMouseLeave), this.parent.removeEventListener("blur", this.onBlur), this.parent.removeEventListener("pointerup", this.onPointerUp), this.parent = void 0), document.removeEventListener("keydown", this.onKeyDown), document.removeEventListener("scroll", this.onBlur), (t = this.observer) == null || t.disconnect(), clearTimeout(this.timeout);
481
- }
482
- get disabled() {
483
- return this.hasAttribute("disabled");
484
- }
485
- set disabled(t) {
486
- t ? this.setAttribute("disabled", "") : this.removeAttribute("disabled");
487
- }
488
- show() {
489
- if (this.disabled)
490
- return;
491
- const t = this.createTooltip();
492
- clearTimeout(this.timeout), this.showing || (t.hidden = !1, h(t), this.showing = !0), t.innerHTML !== this.innerHTML && (t.innerHTML = this.innerHTML), t.style.position = "absolute", E(this.parent, t, {
493
- placement: this.getAttribute("placement") || u.placement,
494
- middleware: [L(), x()]
495
- }).then(({ x: e, y: i, placement: n }) => {
496
- Object.assign(t.style, {
497
- left: `${e}px`,
498
- top: `${i}px`
499
- }), t.dataset.placement = n;
500
- });
501
- }
502
- hide() {
503
- clearTimeout(this.timeout), this.showing && (this.showing = !1, c(this.tooltip).then(() => {
504
- this.tooltip && (this.tooltip.hidden = !0);
505
- }));
506
- }
507
- afterDelay(t) {
508
- clearTimeout(this.timeout);
509
- const e = parseInt(this.getAttribute("delay") || "");
510
- this.timeout = window.setTimeout(
511
- t.bind(this),
512
- isNaN(e) ? u.delay : e
513
- );
514
- }
515
- createTooltip() {
516
- return this.tooltip || (this.tooltip = document.createElement("div"), this.tooltip.className = this.getAttribute("tooltip-class") || u.tooltipClass, this.tooltip.hidden = !0, this.tooltip.addEventListener("mouseenter", this.show.bind(this)), this.tooltip.addEventListener(
517
- "mouseleave",
518
- this.afterDelay.bind(this, this.hide)
519
- ), document.body.appendChild(this.tooltip)), this.tooltip;
520
- }
521
- };
522
- let d = u;
523
- s(d, "delay", 100), s(d, "placement", "top"), s(d, "tooltipClass", "tooltip");
1
+ import { default as o } from "./inclusive-elements2.js";
2
+ import { default as r } from "./inclusive-elements3.js";
3
+ import { default as f } from "./inclusive-elements4.js";
4
+ import { default as s } from "./inclusive-elements5.js";
5
+ import { default as u } from "./inclusive-elements6.js";
6
+ import { default as n } from "./inclusive-elements7.js";
7
+ import { default as E } from "./inclusive-elements8.js";
8
+ import { default as i } from "./inclusive-elements9.js";
9
+ import { default as b } from "./inclusive-elements10.js";
524
10
  export {
525
- F as AccordionElement,
526
- p as AlertsElement,
527
- $ as DisclosureElement,
528
- f as MenuElement,
529
- m as ModalElement,
530
- U as PopupElement,
531
- R as TabsElement,
532
- j as ToolbarElement,
533
- d as TooltipElement
11
+ o as AccordionElement,
12
+ r as AlertsElement,
13
+ f as DisclosureElement,
14
+ s as MenuElement,
15
+ u as ModalElement,
16
+ n as PopupElement,
17
+ E as TabsElement,
18
+ i as ToolbarElement,
19
+ b as TooltipElement
534
20
  };
@@ -0,0 +1,80 @@
1
+ var d = Object.defineProperty;
2
+ var l = (o, i, t) => i in o ? d(o, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[i] = t;
3
+ var e = (o, i, t) => (l(o, typeof i != "symbol" ? i + "" : i, t), t);
4
+ import { computePosition as p, shift as u, flip as c } from "@floating-ui/dom";
5
+ import { hello as m, goodbye as v } from "hello-goodbye";
6
+ const r = class extends HTMLElement {
7
+ constructor() {
8
+ super(...arguments);
9
+ e(this, "parent");
10
+ e(this, "tooltip");
11
+ e(this, "timeout");
12
+ e(this, "observer");
13
+ e(this, "showing", !1);
14
+ e(this, "onMouseEnter", this.afterDelay.bind(this, this.show));
15
+ e(this, "onFocus", this.show.bind(this));
16
+ e(this, "onMouseLeave", this.afterDelay.bind(this, this.hide));
17
+ e(this, "onBlur", this.hide.bind(this));
18
+ e(this, "onPointerUp", (t) => {
19
+ t.pointerType === "mouse" ? this.hide() : this.show();
20
+ });
21
+ e(this, "onKeyDown", (t) => {
22
+ t.key === "Escape" && this.hide();
23
+ });
24
+ }
25
+ connectedCallback() {
26
+ this.parent = this.parentNode, this.parent && (this.parent.addEventListener("mouseenter", this.onMouseEnter), this.parent.addEventListener("focus", this.onFocus), this.parent.addEventListener("mouseleave", this.onMouseLeave), this.parent.addEventListener("blur", this.onBlur), this.parent.addEventListener("pointerup", this.onPointerUp), this.observer = new MutationObserver((t) => {
27
+ t.forEach((s) => {
28
+ s.attributeName === "disabled" && this.hide();
29
+ });
30
+ }), this.observer.observe(this.parent, { attributes: !0 })), document.addEventListener("keydown", this.onKeyDown), document.addEventListener("scroll", this.onBlur);
31
+ }
32
+ disconnectedCallback() {
33
+ var t;
34
+ this.tooltip && (this.tooltip.remove(), this.tooltip = void 0), this.parent && (this.parent.removeEventListener("mouseenter", this.onMouseEnter), this.parent.removeEventListener("focus", this.onFocus), this.parent.removeEventListener("mouseleave", this.onMouseLeave), this.parent.removeEventListener("blur", this.onBlur), this.parent.removeEventListener("pointerup", this.onPointerUp), this.parent = void 0), document.removeEventListener("keydown", this.onKeyDown), document.removeEventListener("scroll", this.onBlur), (t = this.observer) == null || t.disconnect(), clearTimeout(this.timeout);
35
+ }
36
+ get disabled() {
37
+ return this.hasAttribute("disabled");
38
+ }
39
+ set disabled(t) {
40
+ t ? this.setAttribute("disabled", "") : this.removeAttribute("disabled");
41
+ }
42
+ show() {
43
+ if (this.disabled)
44
+ return;
45
+ const t = this.createTooltip();
46
+ clearTimeout(this.timeout), this.showing || (t.hidden = !1, m(t), this.showing = !0), t.innerHTML !== this.innerHTML && (t.innerHTML = this.innerHTML), t.style.position = "absolute", p(this.parent, t, {
47
+ placement: this.getAttribute("placement") || r.placement,
48
+ middleware: [u(), c()]
49
+ }).then(({ x: s, y: h, placement: a }) => {
50
+ Object.assign(t.style, {
51
+ left: `${s}px`,
52
+ top: `${h}px`
53
+ }), t.dataset.placement = a;
54
+ });
55
+ }
56
+ hide() {
57
+ clearTimeout(this.timeout), this.showing && (this.showing = !1, v(this.tooltip).then(() => {
58
+ this.tooltip && (this.tooltip.hidden = !0);
59
+ }));
60
+ }
61
+ afterDelay(t) {
62
+ clearTimeout(this.timeout);
63
+ const s = parseInt(this.getAttribute("delay") || "");
64
+ this.timeout = window.setTimeout(
65
+ t.bind(this),
66
+ isNaN(s) ? r.delay : s
67
+ );
68
+ }
69
+ createTooltip() {
70
+ return this.tooltip || (this.tooltip = document.createElement("div"), this.tooltip.className = this.getAttribute("tooltip-class") || r.tooltipClass, this.tooltip.hidden = !0, this.tooltip.addEventListener("mouseenter", this.show.bind(this)), this.tooltip.addEventListener(
71
+ "mouseleave",
72
+ this.afterDelay.bind(this, this.hide)
73
+ ), document.body.appendChild(this.tooltip)), this.tooltip;
74
+ }
75
+ };
76
+ let n = r;
77
+ e(n, "delay", 100), e(n, "placement", "top"), e(n, "tooltipClass", "tooltip");
78
+ export {
79
+ n as default
80
+ };
@@ -0,0 +1,6 @@
1
+ function n(t) {
2
+ return t.altKey || t.ctrlKey || t.metaKey || t.shiftKey || t.button !== void 0 && t.button !== 0;
3
+ }
4
+ export {
5
+ n as shouldOpenInNewTab
6
+ };
@@ -0,0 +1,28 @@
1
+ var n = Object.defineProperty;
2
+ var l = (r, e, t) => e in r ? n(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var s = (r, e, t) => (l(r, typeof e != "symbol" ? e + "" : e, t), t);
4
+ class a extends HTMLElement {
5
+ constructor() {
6
+ super(...arguments);
7
+ s(this, "onToggle", (t) => {
8
+ const o = t.target;
9
+ o.open && this.querySelectorAll(
10
+ ":scope > :is(ui-disclosure, details)"
11
+ ).forEach((i) => {
12
+ i.toggleAttribute("open", i === o), this.required && i.toggleAttribute("disabled", i === o);
13
+ });
14
+ });
15
+ }
16
+ connectedCallback() {
17
+ this.addEventListener("toggle", this.onToggle, { capture: !0 });
18
+ }
19
+ disconnectedCallback() {
20
+ this.removeEventListener("toggle", this.onToggle, { capture: !0 });
21
+ }
22
+ get required() {
23
+ return this.hasAttribute("required");
24
+ }
25
+ }
26
+ export {
27
+ a as default
28
+ };
@@ -0,0 +1,85 @@
1
+ var c = Object.defineProperty;
2
+ var m = (a, s, t) => s in a ? c(a, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[s] = t;
3
+ var o = (a, s, t) => (m(a, typeof s != "symbol" ? s + "" : s, t), t);
4
+ import { move as d, hello as u, goodbye as f } from "hello-goodbye";
5
+ const n = class extends HTMLElement {
6
+ constructor() {
7
+ super();
8
+ o(this, "timeouts", /* @__PURE__ */ new Map());
9
+ o(this, "index", 0);
10
+ new MutationObserver((i) => {
11
+ i.forEach((r) => {
12
+ r.addedNodes.forEach((e) => {
13
+ e instanceof HTMLElement && this.show(e);
14
+ });
15
+ });
16
+ }).observe(this, { childList: !0 });
17
+ }
18
+ connectedCallback() {
19
+ this.hasAttribute("role") || this.setAttribute("role", "status"), this.hasAttribute("aria-live") || this.setAttribute("aria-live", "polite"), this.hasAttribute("aria-relevant") || this.setAttribute("aria-relevant", "additions");
20
+ for (const t of this.children)
21
+ this.show(t, { animate: !1 });
22
+ }
23
+ show(t, i = {}) {
24
+ const r = i.key || t.dataset.key || String(this.index++);
25
+ t.dataset.key = r, this.contains(t) ? u(t) : i.animate === !1 ? this.append(t) : d(this.children, () => {
26
+ this.append(t), u(t);
27
+ });
28
+ const e = Number(
29
+ i.duration !== void 0 ? i.duration : t.dataset.duration || n.duration
30
+ );
31
+ return e > 0 && (this.startTimeout(t, e), t.addEventListener("mouseenter", this.clearTimeout.bind(this, t)), t.addEventListener("focusin", this.clearTimeout.bind(this, t)), t.addEventListener(
32
+ "mouseleave",
33
+ this.startTimeout.bind(this, t, e)
34
+ ), t.addEventListener(
35
+ "focusout",
36
+ this.startTimeout.bind(this, t, e)
37
+ )), r;
38
+ }
39
+ dismiss(t) {
40
+ if (typeof t == "string") {
41
+ this.querySelectorAll(
42
+ `[data-key="${t}"]`
43
+ ).forEach((i) => {
44
+ this.dismiss(i);
45
+ });
46
+ return;
47
+ }
48
+ d(this.children, () => {
49
+ f(t).then(() => this.removeChild(t));
50
+ }), this.clearTimeout(t);
51
+ }
52
+ clear() {
53
+ Array.from(this.children).forEach((t) => {
54
+ this.dismiss(t);
55
+ });
56
+ }
57
+ speak(t) {
58
+ const i = document.createElement("div");
59
+ Object.assign(i.style, {
60
+ clip: "rect(0 0 0 0)",
61
+ clipPath: "inset(50%)",
62
+ height: "1px",
63
+ overflow: "hidden",
64
+ position: "absolute",
65
+ whiteSpace: "nowrap",
66
+ width: "1px"
67
+ }), i.textContent = t, this.show(i);
68
+ }
69
+ startTimeout(t, i) {
70
+ this.clearTimeout(t), this.timeouts.set(
71
+ t,
72
+ window.setTimeout(() => {
73
+ this.dismiss(t);
74
+ }, i)
75
+ );
76
+ }
77
+ clearTimeout(t) {
78
+ this.timeouts.has(t) && clearTimeout(this.timeouts.get(t));
79
+ }
80
+ };
81
+ let h = n;
82
+ o(h, "duration", 1e4);
83
+ export {
84
+ h as default
85
+ };
@@ -0,0 +1,49 @@
1
+ var o = Object.defineProperty;
2
+ var r = (n, e, t) => e in n ? o(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var i = (n, e, t) => (r(n, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { cancel as h, hello as d, goodbye as a } from "hello-goodbye";
5
+ import { shouldOpenInNewTab as l } from "./inclusive-elements11.js";
6
+ class f extends HTMLElement {
7
+ constructor() {
8
+ super(...arguments);
9
+ i(this, "onButtonClick", (t) => {
10
+ !l(t) && !this.disabled && (this.open = !this.open, t.preventDefault());
11
+ });
12
+ }
13
+ static get observedAttributes() {
14
+ return ["open"];
15
+ }
16
+ connectedCallback() {
17
+ this.content.hidden = !this.open, this.button.setAttribute("aria-expanded", String(this.open)), this.button.addEventListener("click", this.onButtonClick);
18
+ }
19
+ disconnectedCallback() {
20
+ h(this.content), this.button.removeAttribute("aria-expanded"), this.button.removeEventListener("click", this.onButtonClick);
21
+ }
22
+ get open() {
23
+ return this.hasAttribute("open");
24
+ }
25
+ set open(t) {
26
+ t ? this.setAttribute("open", "") : this.removeAttribute("open");
27
+ }
28
+ get disabled() {
29
+ return this.hasAttribute("disabled");
30
+ }
31
+ attributeChangedCallback(t, u, s) {
32
+ t === "open" && (s !== null ? this.wasOpened() : this.wasClosed());
33
+ }
34
+ wasOpened() {
35
+ this.content.hidden && (this.content.hidden = !1, d(this.content)), this.button.setAttribute("aria-expanded", "true"), this.dispatchEvent(new Event("toggle"));
36
+ }
37
+ wasClosed() {
38
+ this.content.hidden || a(this.content).then(() => this.content.hidden = !0), this.button.setAttribute("aria-expanded", "false"), this.dispatchEvent(new Event("toggle"));
39
+ }
40
+ get button() {
41
+ return this.querySelector("button, [role=button]");
42
+ }
43
+ get content() {
44
+ return this.children[1];
45
+ }
46
+ }
47
+ export {
48
+ f as default
49
+ };
@@ -0,0 +1,53 @@
1
+ var c = Object.defineProperty;
2
+ var u = (r, e, t) => e in r ? c(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var n = (r, e, t) => (u(r, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { isFocusable as l } from "tabbable";
5
+ const o = class extends HTMLElement {
6
+ constructor() {
7
+ super(...arguments);
8
+ n(this, "search", "");
9
+ n(this, "searchTimeout");
10
+ n(this, "onKeyDown", (t) => {
11
+ if (!this.hidden) {
12
+ if (t.key === "ArrowUp") {
13
+ this.navigate(-1), t.preventDefault();
14
+ return;
15
+ }
16
+ if (t.key === "ArrowDown") {
17
+ this.navigate(1), t.preventDefault();
18
+ return;
19
+ }
20
+ t.key.length > 1 || t.ctrlKey || t.metaKey || t.altKey || (this.search += t.key.toLowerCase(), t.preventDefault(), clearTimeout(this.searchTimeout), this.searchTimeout = window.setTimeout(() => {
21
+ this.search = "";
22
+ }, o.searchDelay), this.items.some((s) => {
23
+ var i;
24
+ return ((i = s.textContent) == null ? void 0 : i.trim().toLowerCase().indexOf(this.search)) === 0 ? (s.focus(), !0) : !1;
25
+ }));
26
+ }
27
+ });
28
+ }
29
+ connectedCallback() {
30
+ this.hasAttribute("role") || this.setAttribute("role", "menu"), this.hasAttribute("tabindex") || this.setAttribute("tabindex", "-1"), this.items.forEach((t) => {
31
+ t.hasAttribute("tabindex") || t.setAttribute("tabindex", "-1");
32
+ }), this.addEventListener("keydown", this.onKeyDown);
33
+ }
34
+ disconnectedCallback() {
35
+ this.removeEventListener("keydown", this.onKeyDown);
36
+ }
37
+ get items() {
38
+ return Array.from(
39
+ this.querySelectorAll("[role^=menuitem]")
40
+ ).filter((t) => l(t));
41
+ }
42
+ navigate(t) {
43
+ var h;
44
+ const s = this.items;
45
+ let i = (document.activeElement instanceof HTMLElement ? s.indexOf(document.activeElement) : -1) + t;
46
+ i < 0 && (i = s.length - 1), i >= s.length && (i = 0), (h = s[i]) == null || h.focus();
47
+ }
48
+ };
49
+ let a = o;
50
+ n(a, "searchDelay", 800);
51
+ export {
52
+ a as default
53
+ };
@@ -0,0 +1,80 @@
1
+ var p = Object.defineProperty;
2
+ var u = (n, s, t) => s in n ? p(n, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[s] = t;
3
+ var a = (n, s, t) => (u(n, typeof s != "symbol" ? s + "" : s, t), t);
4
+ import { createFocusTrap as f } from "focus-trap";
5
+ import { hello as b, goodbye as v } from "hello-goodbye";
6
+ const o = class extends HTMLElement {
7
+ constructor() {
8
+ super();
9
+ a(this, "focusTrap");
10
+ a(this, "connected", !1);
11
+ const t = document.createElement("template");
12
+ t.innerHTML = `
13
+ <div part="backdrop" style="position: fixed; top: 0; left: 0; right: 0; bottom: 0"></div>
14
+ <div part="content" style="z-index: 1"><slot></slot></div>
15
+ `;
16
+ const e = this.attachShadow({ mode: "open" });
17
+ e.appendChild(t.content.cloneNode(!0)), this.backdrop.addEventListener("click", () => {
18
+ var i;
19
+ this.hasAttribute("static") ? (i = o.attention) == null || i.call(o, e.children[1]) : this.close();
20
+ }), this.focusTrap = f(this, {
21
+ escapeDeactivates: !1,
22
+ allowOutsideClick: !0,
23
+ preventScroll: !0
24
+ });
25
+ }
26
+ static get observedAttributes() {
27
+ return ["open"];
28
+ }
29
+ connectedCallback() {
30
+ var t, e, i, h, l, d;
31
+ this.connected = !0, (t = this.content) != null && t.hasAttribute("role") || (e = this.content) == null || e.setAttribute("role", "dialog"), (i = this.content) != null && i.hasAttribute("aria-modal") || (h = this.content) == null || h.setAttribute("aria-modal", "true"), (l = this.content) != null && l.hasAttribute("tabindex") || (d = this.content) == null || d.setAttribute("tabindex", "-1"), this.addEventListener("keydown", (r) => {
32
+ r.key === "Escape" && this.open && (r.preventDefault(), r.stopPropagation(), this.close());
33
+ }), this.open && this.wasOpened();
34
+ }
35
+ disconnectedCallback() {
36
+ this.connected = !1;
37
+ }
38
+ get open() {
39
+ return this.hasAttribute("open");
40
+ }
41
+ set open(t) {
42
+ t ? this.setAttribute("open", "") : this.removeAttribute("open");
43
+ }
44
+ close() {
45
+ if (!this.open)
46
+ return;
47
+ const t = new Event("beforeclose", { cancelable: !0 });
48
+ this.dispatchEvent(t) && (this.open = !1);
49
+ }
50
+ attributeChangedCallback(t, e, i) {
51
+ t !== "open" || !this.connected || (i !== null ? this.wasOpened() : this.wasClosed());
52
+ }
53
+ wasOpened() {
54
+ var t, e;
55
+ this.hidden = !1, b(this), (t = this.focusTrap) == null || t.activate(), (e = this.querySelector("[autofocus]")) == null || e.focus(), this.dispatchEvent(new Event("open"));
56
+ }
57
+ wasClosed() {
58
+ var t;
59
+ (t = this.focusTrap) == null || t.deactivate(), v(this).then(() => this.hidden = !0), this.dispatchEvent(new Event("close"));
60
+ }
61
+ get backdrop() {
62
+ var t;
63
+ return (t = this.shadowRoot) == null ? void 0 : t.firstElementChild;
64
+ }
65
+ get content() {
66
+ return this.firstElementChild;
67
+ }
68
+ };
69
+ let c = o;
70
+ a(c, "attention", (t) => t.animate(
71
+ [
72
+ { transform: "scale(1)" },
73
+ { transform: "scale(1.1)" },
74
+ { transform: "scale(1)" }
75
+ ],
76
+ 300
77
+ ));
78
+ export {
79
+ c as default
80
+ };
@@ -0,0 +1,109 @@
1
+ var u = Object.defineProperty;
2
+ var d = (i, n, t) => n in i ? u(i, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[n] = t;
3
+ var o = (i, n, t) => (d(i, typeof n != "symbol" ? n + "" : n, t), t);
4
+ import { autoUpdate as l, computePosition as p, shift as b, flip as f, size as m } from "@floating-ui/dom";
5
+ import { cancel as r, hello as a, goodbye as c } from "hello-goodbye";
6
+ import { focusable as k } from "tabbable";
7
+ import { shouldOpenInNewTab as v } from "./inclusive-elements11.js";
8
+ class C extends HTMLElement {
9
+ constructor() {
10
+ super();
11
+ o(this, "cleanup");
12
+ o(this, "onButtonClick", (t) => {
13
+ !v(t) && !this.disabled && (this.open = !this.open, t.preventDefault());
14
+ });
15
+ o(this, "onButtonKeyDown", (t) => {
16
+ var e;
17
+ t.key === "ArrowDown" && !this.disabled && (t.preventDefault(), this.open = !0, (e = k(this.content)[0]) == null || e.focus());
18
+ });
19
+ o(this, "onKeyDown", (t) => {
20
+ t.key === "Escape" && this.open && (t.preventDefault(), t.stopPropagation(), this.open = !1, this.button.focus());
21
+ });
22
+ o(this, "onFocusOut", (t) => {
23
+ (!(t.relatedTarget instanceof Node) || !this.contains(t.relatedTarget)) && (this.open = !1);
24
+ });
25
+ o(this, "onContentClick", (t) => {
26
+ t.target instanceof Element && t.target.closest("[role=menuitem], [role=menuitemradio]") && (this.open = !1, this.button.focus());
27
+ });
28
+ const t = document.createElement("template");
29
+ t.innerHTML = `
30
+ <div part="backdrop" hidden style="position: fixed; top: 0; left: 0; right: 0; bottom: 0"></div>
31
+ <slot></slot>
32
+ `, this.attachShadow({ mode: "open" }).appendChild(t.content.cloneNode(!0)), this.backdrop.onclick = () => this.open = !1;
33
+ }
34
+ static get observedAttributes() {
35
+ return ["open"];
36
+ }
37
+ connectedCallback() {
38
+ this.backdrop.hidden = !0, this.content.hidden = !0, this.open = !1, this.button.setAttribute("aria-expanded", "false"), setTimeout(() => {
39
+ this.content.getAttribute("role") === "menu" && this.button.setAttribute("aria-haspopup", "true");
40
+ }), this.button.addEventListener("click", this.onButtonClick), this.button.addEventListener("keydown", this.onButtonKeyDown), this.addEventListener("keydown", this.onKeyDown), this.addEventListener("focusout", this.onFocusOut), this.content.addEventListener("click", this.onContentClick);
41
+ }
42
+ disconnectedCallback() {
43
+ r(this.backdrop), r(this.content), this.button.removeAttribute("aria-expanded"), this.button.removeAttribute("aria-haspopup"), this.button.removeEventListener("click", this.onButtonClick), this.button.removeEventListener("keydown", this.onButtonKeyDown), this.removeEventListener("keydown", this.onKeyDown), this.removeEventListener("focusout", this.onFocusOut), this.content.removeEventListener("click", this.onContentClick);
44
+ }
45
+ get open() {
46
+ return this.hasAttribute("open");
47
+ }
48
+ set open(t) {
49
+ t ? this.setAttribute("open", "") : this.removeAttribute("open");
50
+ }
51
+ get disabled() {
52
+ return this.hasAttribute("disabled");
53
+ }
54
+ attributeChangedCallback(t, e, s) {
55
+ t === "open" && (s !== null ? this.wasOpened() : this.wasClosed());
56
+ }
57
+ wasOpened() {
58
+ if (!this.content.hidden)
59
+ return;
60
+ this.content.hidden = !1, this.content.style.position = "absolute", this.backdrop.hidden = !1, a(this.content), a(this.backdrop), this.button.setAttribute("aria-expanded", "true"), this.cleanup = l(
61
+ this.button,
62
+ this.content,
63
+ () => {
64
+ p(this.button, this.content, {
65
+ placement: this.getAttribute("placement") || "bottom",
66
+ middleware: [
67
+ b(),
68
+ f(),
69
+ m({
70
+ apply: ({ availableWidth: e, availableHeight: s }) => {
71
+ Object.assign(this.content.style, {
72
+ maxWidth: "",
73
+ maxHeight: ""
74
+ });
75
+ const h = getComputedStyle(this.content);
76
+ (h.maxWidth === "none" || e < parseInt(h.maxWidth)) && (this.content.style.maxWidth = `${e}px`), (h.maxHeight === "none" || s < parseInt(h.maxHeight)) && (this.content.style.maxHeight = `${s}px`);
77
+ }
78
+ })
79
+ ]
80
+ }).then(({ x: e, y: s, placement: h }) => {
81
+ Object.assign(this.content.style, {
82
+ left: `${e}px`,
83
+ top: `${s}px`
84
+ }), this.content.dataset.placement = h;
85
+ });
86
+ },
87
+ { ancestorScroll: !1 }
88
+ );
89
+ const t = this.content.querySelector("[autofocus]");
90
+ t ? t.focus() : this.content.focus(), this.dispatchEvent(new Event("open"));
91
+ }
92
+ wasClosed() {
93
+ var t;
94
+ this.content.hidden || (this.button.setAttribute("aria-expanded", "false"), (t = this.cleanup) == null || t.call(this), c(this.backdrop).then(() => this.backdrop.hidden = !0), c(this.content).then(() => this.content.hidden = !0), this.dispatchEvent(new Event("close")));
95
+ }
96
+ get backdrop() {
97
+ var t;
98
+ return (t = this.shadowRoot) == null ? void 0 : t.firstElementChild;
99
+ }
100
+ get button() {
101
+ return this.querySelector("button, [role=button]");
102
+ }
103
+ get content() {
104
+ return this.children[1];
105
+ }
106
+ }
107
+ export {
108
+ C as default
109
+ };
@@ -0,0 +1,58 @@
1
+ var o = Object.defineProperty;
2
+ var b = (l, i, t) => i in l ? o(l, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[i] = t;
3
+ var n = (l, i, t) => (b(l, typeof i != "symbol" ? i + "" : i, t), t);
4
+ let c = 0;
5
+ class d extends HTMLElement {
6
+ constructor() {
7
+ super(...arguments);
8
+ n(this, "idPrefix", "tabs" + ++c);
9
+ n(this, "onKeyDown", (t) => {
10
+ const a = t.target, e = this.tabs.indexOf(a), s = this.tablist.getAttribute("aria-orientation") === "vertical";
11
+ let r = !1;
12
+ switch (t.key) {
13
+ case (s ? "ArrowUp" : "ArrowLeft"):
14
+ this.selectTab(e - 1), r = !0;
15
+ break;
16
+ case (s ? "ArrowDown" : "ArrowRight"):
17
+ this.selectTab(e + 1), r = !0;
18
+ break;
19
+ case "Home":
20
+ this.selectTab(0), r = !0;
21
+ break;
22
+ case "End":
23
+ this.selectTab(this.tabs.length - 1), r = !0;
24
+ }
25
+ r && (t.stopPropagation(), t.preventDefault());
26
+ });
27
+ n(this, "onClick", (t) => {
28
+ const e = t.target.closest("[role=tab]");
29
+ e && this.selectTab(this.tabs.indexOf(e));
30
+ });
31
+ }
32
+ connectedCallback() {
33
+ this.tablist.addEventListener("keydown", this.onKeyDown), this.tablist.addEventListener("click", this.onClick), this.selectTab(0, !1), this.tabs.forEach((t, a) => {
34
+ const e = this.tabpanels[a], s = t.getAttribute("id") || this.idPrefix + "_tab_" + a, r = e.getAttribute("id") || this.idPrefix + "_panel_" + a;
35
+ t.setAttribute("id", s), t.setAttribute("aria-controls", r), e.setAttribute("id", r), e.setAttribute("aria-labelledby", s), e.setAttribute("tabindex", "0");
36
+ });
37
+ }
38
+ disconnectedCallback() {
39
+ this.tablist.removeEventListener("keydown", this.onKeyDown), this.tablist.removeEventListener("click", this.onClick);
40
+ }
41
+ selectTab(t, a = !0) {
42
+ t < 0 ? t += this.tabs.length : t >= this.tabs.length && (t -= this.tabs.length), this.tabs.forEach((e, s) => {
43
+ s === t ? (e.setAttribute("aria-selected", "true"), e.removeAttribute("tabindex"), this.tabpanels[s].hidden = !1, a && e.focus()) : (e.setAttribute("aria-selected", "false"), e.setAttribute("tabindex", "-1"), this.tabpanels[s].hidden = !0);
44
+ });
45
+ }
46
+ get tablist() {
47
+ return this.querySelector("[role=tablist]");
48
+ }
49
+ get tabs() {
50
+ return Array.from(this.querySelectorAll("[role=tab]"));
51
+ }
52
+ get tabpanels() {
53
+ return Array.from(this.querySelectorAll("[role=tabpanel]"));
54
+ }
55
+ }
56
+ export {
57
+ d as default
58
+ };
@@ -0,0 +1,38 @@
1
+ var c = Object.defineProperty;
2
+ var a = (o, e, t) => e in o ? c(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var l = (o, e, t) => (a(o, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { focusable as d } from "tabbable";
5
+ class u extends HTMLElement {
6
+ constructor() {
7
+ super(...arguments);
8
+ l(this, "onInitialFocus", () => {
9
+ this.removeAttribute("tabindex"), this.focusControlAtIndex(0);
10
+ });
11
+ l(this, "onKeyDown", (t) => {
12
+ if (t.key !== "ArrowRight" && t.key !== "ArrowLeft" && t.key !== "Home" && t.key !== "End")
13
+ return;
14
+ const i = this.controls, s = this.controls.length, r = i.indexOf(t.target);
15
+ if (r === -1)
16
+ return;
17
+ let n = 0;
18
+ t.key === "ArrowLeft" && (n = r - 1), t.key === "ArrowRight" && (n = r + 1), t.key === "End" && (n = s - 1), n < 0 && (n = s - 1), n > s - 1 && (n = 0), this.focusControlAtIndex(n), t.preventDefault();
19
+ });
20
+ }
21
+ connectedCallback() {
22
+ this.hasAttribute("role") || this.setAttribute("role", "toolbar"), this.setAttribute("tabindex", "0"), this.addEventListener("focus", this.onInitialFocus, { once: !0 }), this.addEventListener("keydown", this.onKeyDown);
23
+ }
24
+ disconnectedCallback() {
25
+ this.removeEventListener("keydown", this.onKeyDown);
26
+ }
27
+ focusControlAtIndex(t) {
28
+ this.controls.forEach((i, s) => {
29
+ s === t ? (i.setAttribute("tabindex", "0"), i.focus()) : i.setAttribute("tabindex", "-1");
30
+ });
31
+ }
32
+ get controls() {
33
+ return d(this);
34
+ }
35
+ }
36
+ export {
37
+ u as default
38
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inclusive-elements",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Accessible, lightweight, unstyled implementations of common UI controls.",
5
5
  "module": "dist/inclusive-elements.js",
6
6
  "type": "module",