//#region src/utils/a11y.ts
var e = [
	"a[href]",
	"button:not([disabled])",
	"input:not([disabled])",
	"select:not([disabled])",
	"textarea:not([disabled])",
	"[tabindex]:not([tabindex=\"-1\"])",
	"[contenteditable=\"true\"]"
].join(", ");
function t(t) {
	return Array.from(t.querySelectorAll(e)).filter((e) => !(e.offsetParent === null && e.getAttribute("aria-hidden") !== "false" || e.getAttribute("aria-hidden") === "true"));
}
function n(e) {
	let n = [], r = !1, i = null, a = (e) => {
		if (e.key !== "Tab" || n.length === 0) return;
		let t = n[0], r = n[n.length - 1];
		t === void 0 || r === void 0 || (e.shiftKey ? document.activeElement === t && (e.preventDefault(), r.focus()) : document.activeElement === r && (e.preventDefault(), t.focus()));
	}, o = () => {
		n = t(e);
	};
	return {
		activate: () => {
			r || (r = !0, i = document.activeElement, o(), document.addEventListener("keydown", a), n.length > 0 && n[0] !== void 0 ? n[0].focus() : e.focus());
		},
		deactivate: () => {
			r && (r = !1, document.removeEventListener("keydown", a), i !== null && document.body.contains(i) && i.focus());
		},
		update: o,
		isActive: () => r
	};
}
var r = null, i = null;
function a(e) {
	let t = e === "polite" ? r : i;
	if (t !== null && document.body.contains(t)) return t;
	let n = document.createElement("div");
	return n.setAttribute("role", "status"), n.setAttribute("aria-live", e), n.setAttribute("aria-atomic", "true"), n.className = "cmm-sr-only cmm-live-region", n.style.cssText = "\n    position: absolute;\n    width: 1px;\n    height: 1px;\n    padding: 0;\n    margin: -1px;\n    overflow: hidden;\n    clip: rect(0, 0, 0, 0);\n    white-space: nowrap;\n    border: 0;\n  ", document.body.appendChild(n), e === "polite" ? r = n : i = n, n;
}
function o(e, t = "polite") {
	let n = a(t);
	n.textContent = "", requestAnimationFrame(() => {
		n.textContent = e;
	});
}
function s(e = "polite") {
	let t = document.createElement("div");
	return t.setAttribute("role", "status"), t.setAttribute("aria-live", e), t.setAttribute("aria-atomic", "true"), t.className = "cmm-sr-only cmm-live-region", t.style.cssText = "\n    position: absolute;\n    width: 1px;\n    height: 1px;\n    padding: 0;\n    margin: -1px;\n    overflow: hidden;\n    clip: rect(0, 0, 0, 0);\n    white-space: nowrap;\n    border: 0;\n  ", {
		announce: (e) => {
			document.body.contains(t) || document.body.appendChild(t), t.textContent = "", requestAnimationFrame(() => {
				t.textContent = e;
			});
		},
		clear: () => {
			t.textContent = "";
		},
		destroy: () => {
			t.remove();
		}
	};
}
function c(e, t, n) {
	let r = [], i = n?.initialIndex ?? 0, a = n?.wrap ?? !0, o = n?.orientation ?? "vertical", s = n?.onFocusChange, c = () => {
		r = Array.from(e.querySelectorAll(t));
		for (let e of r) e.setAttribute("tabindex", "-1");
		let n = r[i];
		if (n !== void 0) n.setAttribute("tabindex", "0");
		else if (r.length > 0) {
			let e = r[0];
			e !== void 0 && (i = 0, e.setAttribute("tabindex", "0"));
		}
	}, l = (e) => {
		if (r[e] === void 0) return;
		let t = r[i];
		t !== void 0 && t.setAttribute("tabindex", "-1"), i = e;
		let n = r[i];
		n !== void 0 && (n.setAttribute("tabindex", "0"), n.focus(), s?.(i, n));
	}, u = () => {
		if (r.length === 0) return;
		let e = i + 1;
		e >= r.length && (e = a ? 0 : r.length - 1), l(e);
	}, d = () => {
		if (r.length === 0) return;
		let e = i - 1;
		e < 0 && (e = a ? r.length - 1 : 0), l(e);
	}, f = () => {
		l(0);
	}, p = () => {
		l(r.length - 1);
	}, m = (e) => {
		let t = e.target;
		if (!r.includes(t)) return;
		let n = !1;
		switch (e.key) {
			case "ArrowDown":
				(o === "vertical" || o === "both") && (u(), n = !0);
				break;
			case "ArrowUp":
				(o === "vertical" || o === "both") && (d(), n = !0);
				break;
			case "ArrowRight":
				(o === "horizontal" || o === "both") && (u(), n = !0);
				break;
			case "ArrowLeft":
				(o === "horizontal" || o === "both") && (d(), n = !0);
				break;
			case "Home":
				f(), n = !0;
				break;
			case "End":
				p(), n = !0;
				break;
		}
		n && e.preventDefault();
	};
	return c(), e.addEventListener("keydown", m), {
		next: u,
		prev: d,
		first: f,
		last: p,
		getCurrentIndex: () => i,
		setIndex: (e) => {
			l(e);
		},
		update: c,
		destroy: () => {
			e.removeEventListener("keydown", m);
		}
	};
}
function l(e, t) {
	let n = e.getAttribute("aria-describedby");
	n === null ? e.setAttribute("aria-describedby", t) : n.split(" ").includes(t) || e.setAttribute("aria-describedby", `${n} ${t}`);
}
function u(e, t) {
	let n = e.getAttribute("aria-labelledby");
	n === null ? e.setAttribute("aria-labelledby", t) : n.split(" ").includes(t) || e.setAttribute("aria-labelledby", `${n} ${t}`);
}
function d(e, t) {
	e.setAttribute("aria-controls", t);
}
function f(e, t) {
	e.setAttribute("aria-owns", t.join(" "));
}
function p(e) {
	let t = document.createElement("span");
	return t.className = "cmm-sr-only", t.style.cssText = "\n    position: absolute;\n    width: 1px;\n    height: 1px;\n    padding: 0;\n    margin: -1px;\n    overflow: hidden;\n    clip: rect(0, 0, 0, 0);\n    white-space: nowrap;\n    border: 0;\n  ", t.textContent = e, t;
}
function m() {
	try {
		return document.querySelector(":focus-visible"), !0;
	} catch {
		return !1;
	}
}
function h(e) {
	let t = !1, n = () => {
		t = !0;
	}, r = () => {
		t = !1;
	}, i = () => {
		t && e.classList.add("focus-visible");
	}, a = () => {
		e.classList.remove("focus-visible"), t = !1;
	};
	return document.addEventListener("keydown", n), document.addEventListener("pointerdown", r), e.addEventListener("focus", i), e.addEventListener("blur", a), () => {
		document.removeEventListener("keydown", n), document.removeEventListener("pointerdown", r), e.removeEventListener("focus", i), e.removeEventListener("blur", a);
	};
}
//#endregion
export { p as a, d as c, f as d, h as f, c as i, l, n, t as o, s as r, m as s, o as t, u };

//# sourceMappingURL=a11y-CuHKgVSx.js.map