inclusive-elements 0.5.4 → 0.6.0

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,83 +0,0 @@
1
- var u = Object.defineProperty;
2
- var p = (o, e, t) => e in o ? u(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
- var a = (o, e, t) => (p(o, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { createFocusTrap as f } from "focus-trap";
5
- import { hello as b, goodbye as m } from "hello-goodbye";
6
- const n = class n 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 i = this.attachShadow({ mode: "open" });
17
- i.appendChild(t.content.cloneNode(!0)), this.backdrop.addEventListener("click", () => {
18
- var s;
19
- this.hasAttribute("static") ? (s = n.attention) == null || s.call(n, i.children[1]) : this.close();
20
- }), this.focusTrap = f(this, {
21
- escapeDeactivates: !1,
22
- allowOutsideClick: !0,
23
- preventScroll: !0,
24
- initialFocus: () => this.querySelector("[autofocus]") || void 0
25
- });
26
- }
27
- static get observedAttributes() {
28
- return ["open"];
29
- }
30
- connectedCallback() {
31
- var t, i, s, c, h, l;
32
- this.connected = !0, (t = this.content) != null && t.hasAttribute("role") || (i = this.content) == null || i.setAttribute("role", "dialog"), (s = this.content) != null && s.hasAttribute("aria-modal") || (c = this.content) == null || c.setAttribute("aria-modal", "true"), (h = this.content) != null && h.hasAttribute("tabindex") || (l = this.content) == null || l.setAttribute("tabindex", "-1"), this.addEventListener("keydown", (r) => {
33
- r.key === "Escape" && this.open && (r.preventDefault(), r.stopPropagation(), this.close());
34
- }), this.open && this.wasOpened();
35
- }
36
- disconnectedCallback() {
37
- this.connected = !1;
38
- }
39
- get open() {
40
- return this.hasAttribute("open");
41
- }
42
- set open(t) {
43
- t ? this.setAttribute("open", "") : this.removeAttribute("open");
44
- }
45
- close() {
46
- if (!this.open)
47
- return;
48
- const t = new Event("beforeclose", { cancelable: !0 });
49
- this.dispatchEvent(t) && (this.open = !1);
50
- }
51
- attributeChangedCallback(t, i, s) {
52
- t !== "open" || !this.connected || (s !== null ? this.wasOpened() : this.wasClosed());
53
- }
54
- async wasOpened() {
55
- document.documentElement.style.overflow = "hidden", this.hidden = !1, b(this), requestAnimationFrame(() => {
56
- var t;
57
- return (t = this.focusTrap) == null ? void 0 : t.activate();
58
- }), this.dispatchEvent(new Event("open"));
59
- }
60
- wasClosed() {
61
- var t;
62
- document.documentElement.style.overflow = "", (t = this.focusTrap) == null || t.deactivate(), m(this).then(() => this.hidden = !0), this.dispatchEvent(new Event("close"));
63
- }
64
- get backdrop() {
65
- var t;
66
- return (t = this.shadowRoot) == null ? void 0 : t.firstElementChild;
67
- }
68
- get content() {
69
- return this.firstElementChild;
70
- }
71
- };
72
- a(n, "attention", (t) => t.animate(
73
- [
74
- { transform: "scale(1)" },
75
- { transform: "scale(1.1)" },
76
- { transform: "scale(1)" }
77
- ],
78
- 300
79
- ));
80
- let d = n;
81
- export {
82
- d as default
83
- };
@@ -1,127 +0,0 @@
1
- var l = Object.defineProperty;
2
- var f = (a, s, t) => s in a ? l(a, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[s] = t;
3
- var h = (a, s, t) => (f(a, typeof s != "symbol" ? s + "" : s, t), t);
4
- import { autoUpdate as b, computePosition as m, shift as k, flip as g, size as v } from "@floating-ui/dom";
5
- import { cancel as u, hello as d, goodbye as p } from "hello-goodbye";
6
- import { focusable as w } from "tabbable";
7
- import { shouldOpenInNewTab as y } from "./inclusive-elements11.js";
8
- class D extends HTMLElement {
9
- constructor() {
10
- super();
11
- h(this, "cleanup");
12
- h(this, "onButtonClick", (t) => {
13
- !y(t) && !this.disabled && (this.open = !this.open, t.preventDefault());
14
- });
15
- h(this, "onButtonKeyDown", (t) => {
16
- var e;
17
- t.key === "ArrowDown" && !this.disabled && (t.preventDefault(), this.open = !0, this.content && ((e = w(this.content)[0]) == null || e.focus()));
18
- });
19
- h(this, "onKeyDown", (t) => {
20
- var e;
21
- t.key === "Escape" && this.open && (t.preventDefault(), t.stopPropagation(), this.open = !1, (e = this.button) == null || e.focus());
22
- });
23
- h(this, "onFocusOut", (t) => {
24
- t.relatedTarget instanceof Node && !this.contains(t.relatedTarget) && (this.open = !1);
25
- });
26
- h(this, "onContentClick", (t) => {
27
- var e;
28
- t.target instanceof Element && t.target.closest("[role=menuitem], [role=menuitemradio]") && (this.open = !1, (e = this.button) == null || e.focus());
29
- });
30
- const t = document.createElement("template");
31
- t.innerHTML = `
32
- <div part="backdrop" hidden style="position: fixed; top: 0; left: 0; right: 0; bottom: 0"></div>
33
- <slot></slot>
34
- `, this.attachShadow({ mode: "open" }).appendChild(t.content.cloneNode(!0)), this.backdrop.onclick = () => this.open = !1;
35
- }
36
- static get observedAttributes() {
37
- return ["open"];
38
- }
39
- connectedCallback() {
40
- var t, e, n, o;
41
- this.backdrop.hidden = !this.open, this.content && (this.content.hidden = !this.open), (t = this.button) == null || t.setAttribute(
42
- "aria-expanded",
43
- this.open ? "true" : "false"
44
- ), setTimeout(() => {
45
- var i, c;
46
- ((i = this.content) == null ? void 0 : i.getAttribute("role")) === "menu" && ((c = this.button) == null || c.setAttribute("aria-haspopup", "true"));
47
- }), (e = this.button) == null || e.addEventListener("click", this.onButtonClick), (n = this.button) == null || n.addEventListener("keydown", this.onButtonKeyDown), this.addEventListener("keydown", this.onKeyDown), this.addEventListener("focusout", this.onFocusOut), (o = this.content) == null || o.addEventListener("click", this.onContentClick);
48
- }
49
- disconnectedCallback() {
50
- var t, e, n, o, i;
51
- u(this.backdrop), this.content && u(this.content), (t = this.button) == null || t.removeAttribute("aria-expanded"), (e = this.button) == null || e.removeAttribute("aria-haspopup"), (n = this.button) == null || n.removeEventListener("click", this.onButtonClick), (o = this.button) == null || o.removeEventListener("keydown", this.onButtonKeyDown), this.removeEventListener("keydown", this.onKeyDown), this.removeEventListener("focusout", this.onFocusOut), (i = this.content) == null || i.removeEventListener("click", this.onContentClick);
52
- }
53
- get open() {
54
- return this.hasAttribute("open");
55
- }
56
- set open(t) {
57
- t ? this.setAttribute("open", "") : this.removeAttribute("open");
58
- }
59
- get disabled() {
60
- return this.hasAttribute("disabled");
61
- }
62
- attributeChangedCallback(t, e, n) {
63
- t === "open" && (n !== null ? this.wasOpened() : this.wasClosed());
64
- }
65
- wasOpened() {
66
- var e, n;
67
- if (!((e = this.content) != null && e.hidden))
68
- return;
69
- this.content.hidden = !1, this.content.style.position = "fixed", this.backdrop.hidden = !1, d(this.content), d(this.backdrop), (n = this.button) == null || n.setAttribute("aria-expanded", "true"), this.button && (this.cleanup = b(
70
- this.button,
71
- this.content,
72
- () => {
73
- !this.button || !this.content || m(this.button, this.content, {
74
- strategy: "fixed",
75
- placement: this.getAttribute("placement") || "bottom",
76
- middleware: [
77
- k(),
78
- g(),
79
- v({
80
- apply: ({
81
- availableWidth: o,
82
- availableHeight: i,
83
- placement: c
84
- }) => {
85
- if (!this.content)
86
- return;
87
- this.content.dataset.placement = c, Object.assign(this.content.style, {
88
- maxWidth: "",
89
- maxHeight: ""
90
- });
91
- const r = getComputedStyle(
92
- this.content
93
- );
94
- o -= parseInt(r.marginLeft) + parseInt(r.marginRight), (r.maxWidth === "none" || o < parseInt(r.maxWidth)) && (this.content.style.maxWidth = `${o}px`), i -= parseInt(r.marginTop) + parseInt(r.marginBottom), (r.maxHeight === "none" || i < parseInt(r.maxHeight)) && (this.content.style.maxHeight = `${i}px`);
95
- }
96
- })
97
- ]
98
- }).then(({ x: o, y: i }) => {
99
- this.content && Object.assign(this.content.style, {
100
- left: `${o}px`,
101
- top: `${i}px`
102
- });
103
- });
104
- },
105
- { ancestorScroll: !1 }
106
- ));
107
- const t = this.content.querySelector("[autofocus]");
108
- t ? t.focus() : this.content.focus(), this.dispatchEvent(new Event("open"));
109
- }
110
- wasClosed() {
111
- var t, e, n;
112
- (t = this.content) != null && t.hidden || ((e = this.button) == null || e.setAttribute("aria-expanded", "false"), (n = this.cleanup) == null || n.call(this), p(this.backdrop).then(() => this.backdrop.hidden = !0), this.content && p(this.content).then(() => this.content.hidden = !0), this.dispatchEvent(new Event("close")));
113
- }
114
- get backdrop() {
115
- var t;
116
- return (t = this.shadowRoot) == null ? void 0 : t.firstElementChild;
117
- }
118
- get button() {
119
- return this.querySelector("button, [role=button]");
120
- }
121
- get content() {
122
- return this.children[1];
123
- }
124
- }
125
- export {
126
- D as default
127
- };
@@ -1,77 +0,0 @@
1
- var h = Object.defineProperty;
2
- var f = (l, r, t) => r in l ? h(l, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[r] = t;
3
- var c = (l, r, t) => (f(l, typeof r != "symbol" ? r + "" : r, t), t);
4
- let g = 0;
5
- class x extends HTMLElement {
6
- constructor() {
7
- super(...arguments);
8
- c(this, "idPrefix", "tabs" + ++g);
9
- c(this, "onKeyDown", (t) => {
10
- const e = this.tabs;
11
- if (e.length === 0)
12
- return;
13
- let i = e.indexOf(t.target);
14
- i === -1 && (i = e.findIndex(
15
- (o) => o.getAttribute("aria-selected") === "true"
16
- ), i === -1 && (i = 0));
17
- const a = this.tablist.getAttribute("aria-orientation") === "vertical";
18
- let s;
19
- switch (t.key) {
20
- case (a ? "ArrowUp" : "ArrowLeft"):
21
- s = (i - 1 + e.length) % e.length;
22
- break;
23
- case (a ? "ArrowDown" : "ArrowRight"):
24
- s = (i + 1) % e.length;
25
- break;
26
- case "Home":
27
- s = 0;
28
- break;
29
- case "End":
30
- s = e.length - 1;
31
- }
32
- s !== void 0 && (this.selectTab(s, { focus: !0 }), t.stopPropagation(), t.preventDefault());
33
- });
34
- c(this, "onClick", (t) => {
35
- const i = t.target.closest("[role=tab]");
36
- i && this.selectTab(this.tabs.indexOf(i), { focus: !0 });
37
- });
38
- }
39
- connectedCallback() {
40
- this.tablist.addEventListener("keydown", this.onKeyDown), this.tablist.addEventListener("click", this.onClick), this.selectTab(this.initialTabIndex, { emit: !1 }), this.tabs.forEach((t, e) => {
41
- const i = this.tabpanels[e], a = t.getAttribute("id") || this.idPrefix + "_tab_" + e, s = i.getAttribute("id") || this.idPrefix + "_panel_" + e;
42
- t.setAttribute("id", a), t.setAttribute("aria-controls", s), i.setAttribute("id", s), i.setAttribute("aria-labelledby", a), i.setAttribute("tabindex", "0");
43
- });
44
- }
45
- disconnectedCallback() {
46
- this.tablist.removeEventListener("keydown", this.onKeyDown), this.tablist.removeEventListener("click", this.onClick);
47
- }
48
- selectTab(t, e = {}) {
49
- const { focus: i = !1, emit: a = !0 } = e, s = this.tabs, o = this.tabpanels, u = s.length;
50
- if (t < 0 || t >= u)
51
- return !1;
52
- const d = s.findIndex(
53
- (n) => n.getAttribute("aria-selected") === "true"
54
- );
55
- return s.forEach((n, b) => {
56
- b === t ? (n.setAttribute("aria-selected", "true"), n.removeAttribute("tabindex"), o[b].hidden = !1, i && n.focus()) : (n.setAttribute("aria-selected", "false"), n.setAttribute("tabindex", "-1"), o[b].hidden = !0);
57
- }), a && d !== t && this.dispatchEvent(new Event("change")), d !== t;
58
- }
59
- get initialTabIndex() {
60
- const t = this.tabs.findIndex(
61
- (e) => e.getAttribute("aria-selected") === "true"
62
- );
63
- return t !== -1 ? t : 0;
64
- }
65
- get tablist() {
66
- return this.querySelector("[role=tablist]");
67
- }
68
- get tabs() {
69
- return Array.from(this.querySelectorAll("[role=tab]"));
70
- }
71
- get tabpanels() {
72
- return Array.from(this.querySelectorAll("[role=tabpanel]"));
73
- }
74
- }
75
- export {
76
- x as default
77
- };
@@ -1,38 +0,0 @@
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
- };
@@ -1,6 +0,0 @@
1
- export default class AccordionElement extends HTMLElement {
2
- connectedCallback(): void;
3
- disconnectedCallback(): void;
4
- private onToggle;
5
- get required(): boolean;
6
- }
@@ -1,14 +0,0 @@
1
- export default class DisclosureElement extends HTMLElement {
2
- static get observedAttributes(): string[];
3
- connectedCallback(): void;
4
- disconnectedCallback(): void;
5
- private onButtonClick;
6
- get open(): boolean;
7
- set open(val: boolean);
8
- get disabled(): boolean;
9
- attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
10
- private wasOpened;
11
- private wasClosed;
12
- private get button();
13
- private get content();
14
- }
@@ -1,17 +0,0 @@
1
- export default class ModalElement extends HTMLElement {
2
- static attention: (el: Element) => void;
3
- static get observedAttributes(): string[];
4
- private focusTrap?;
5
- private connected;
6
- constructor();
7
- connectedCallback(): void;
8
- disconnectedCallback(): void;
9
- get open(): boolean;
10
- set open(val: boolean);
11
- close(): void;
12
- attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
13
- private wasOpened;
14
- private wasClosed;
15
- private get backdrop();
16
- private get content();
17
- }
@@ -1,21 +0,0 @@
1
- export default class PopupElement extends HTMLElement {
2
- cleanup?: () => void;
3
- static get observedAttributes(): string[];
4
- constructor();
5
- connectedCallback(): void;
6
- disconnectedCallback(): void;
7
- private onButtonClick;
8
- private onButtonKeyDown;
9
- private onKeyDown;
10
- private onFocusOut;
11
- private onContentClick;
12
- get open(): boolean;
13
- set open(val: boolean);
14
- get disabled(): boolean;
15
- attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
16
- private wasOpened;
17
- private wasClosed;
18
- private get backdrop();
19
- private get button();
20
- private get content();
21
- }