import { GlobalStateService as e } from "../services/global.service.js";
import { isFocusable as t } from "./focus.js";
//#region src/internal/utils/dom.ts
function n(e) {
	if (e instanceof Document && e.documentElement) return Array.from(e.documentElement.children);
	if (e instanceof HTMLElement && e.shadowRoot) return Array.from(e.shadowRoot.children);
	if (e instanceof HTMLSlotElement && e.assignedElements) {
		let t = e.assignedElements();
		return t.length ? t : Array.from(e.children);
	} else return Array.from(e.children);
}
function r() {
	return `_${self.crypto.getRandomValues(new Uint32Array(1))[0].toString(16)}`;
}
function i(e, t, n) {
	n(e.getAttribute(t));
	let r = new MutationObserver((e) => {
		e.forEach((e) => {
			e.attributeName === t && n(e.target.getAttribute(t));
		});
	});
	return r.observe(e, {
		attributes: !0,
		subtree: !0
	}), r;
}
function a(e, t, n) {
	let r = new MutationObserver((e) => {
		e.forEach((e) => {
			e.attributeName && t.includes(e.attributeName) && n(e);
		});
	});
	return r.observe(e, {
		attributes: !0,
		subtree: !0
	}), r;
}
function o(e, t) {
	let n = new CSSStyleSheet();
	n.replaceSync(t);
	let r = e.getRootNode();
	return r.adoptedStyleSheets && (r.adoptedStyleSheets.map((e) => s(e)).find((e) => e === s(n)) || (r.adoptedStyleSheets = [...Array.from(r.adoptedStyleSheets), n])), n;
}
function s(e) {
	return e.cssRules ? Array.from(e.cssRules).map((e) => e.cssText || "").join("\n") : "";
}
function c(e, t, n) {
	let r = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e), t);
	if (!r) return;
	let i = Object.getOwnPropertyDescriptor(e, t);
	i && i.configurable === !1 || Object.defineProperty(e, t, {
		configurable: !0,
		get: r.get,
		set: (t) => {
			r.set.call(e, t), n(t);
		}
	});
}
function l(e, t, n) {
	return e.hasAttribute(t) ? n(e.getAttribute(t)) : e[t] !== void 0 && n(e[t]), c(e, t, n), i(e, t, (e) => n(e));
}
function u(e, t) {
	let { left: n, right: r, top: i, bottom: a } = t.getBoundingClientRect();
	return e.clientX < n || e.clientX > r || e.clientY < i || e.clientY > a;
}
function d(e) {
	return parseInt(e.includes("calc") ? e.split("*")[1].replace("px)", "").trim() : e, 10) || 0;
}
var f = globalThis.CustomElementRegistry && "initialize" in CustomElementRegistry.prototype;
function p(t, n) {
	Object.entries(t.elementDefinitions ?? {}).filter(([e, t]) => !n.get(t.metadata.tag)).forEach(([e, t]) => {
		p(t, n);
	}), n.get(t.metadata.tag) || (n.define(t.metadata.tag, t), n === customElements && e.dispatch("NVE_ELEMENT_DEFINE", { elementRegistry: { [t.metadata.tag]: t.metadata.version } }));
}
function m(t) {
	let { version: n } = t.metadata;
	f && !customElements.get(t.metadata.tag) ? (customElements.define(t.metadata.tag, t), e.dispatch("NVE_ELEMENT_DEFINE", { elementRegistry: { [t.metadata.tag]: t.metadata.version } })) : p(t, customElements), e.state.elementRegistry[t.metadata.tag] !== n && globalThis?.location?.hostname === "localhost" && import("./audit-logs.js").then((e) => console.warn(e.getDuplicatePackageVersionWarning(t.metadata.tag, n)));
}
function h(e) {
	return e.buttons === 2 && !e.ctrlKey || e.buttons === 1 && e.ctrlKey;
}
function g(e, n = 10) {
	return _(e, n).filter((e) => t(e));
}
function _(e, t = 10) {
	return Array.from(n(e)).reduce((e, r) => [...e, [r, [...Array.from(n(r)).map((e) => [e, _(e, t)])]]], []).flat(t);
}
function v(e) {
	return b.has(e.code);
}
var y = /* @__PURE__ */ function(e) {
	return e.End = "End", e.Home = "Home", e.PageUp = "PageUp", e.PageDown = "PageDown", e.ArrowUp = "ArrowUp", e.ArrowDown = "ArrowDown", e.ArrowLeft = "ArrowLeft", e.ArrowRight = "ArrowRight", e;
}({}), b = new Set(Object.values(y));
function x(e) {
	return e.some((t) => t.children.length !== e[0].children.length);
}
function S(e) {
	e?.wholeText?.trim() === "" && e.remove();
}
function C() {
	let e = globalThis.document.createElement("div");
	e.style.setProperty("width", "100px"), e.style.setProperty("height", "100px"), e.style.setProperty("overflow", "scroll"), e.style.setProperty("position", "absolute"), e.style.setProperty("top", "-9999px"), globalThis.document.body.appendChild(e);
	let t = e.offsetWidth - e.clientWidth;
	return globalThis.document.body.removeChild(e), t;
}
function w(e) {
	return e.scrollHeight > e.clientHeight;
}
function T(e) {
	return e.scrollWidth > e.clientWidth;
}
function E(e, t = 0) {
	return e.scrollTop + e.offsetHeight + t >= e.scrollHeight;
}
async function D() {
	return await new globalThis.EyeDropper().open().then((e) => e.sRGBHex);
}
function O(e = globalThis.document.querySelector(":root")) {
	let t = getComputedStyle(e), n = [];
	try {
		n = Array.from(globalThis.parent.document.styleSheets);
	} catch {}
	return [...n, ...Array.from(globalThis.document.styleSheets)].reduce((e, t) => {
		let n = [];
		try {
			n = [...t.cssRules];
		} catch {}
		return e.concat(n.filter((e) => e.type === 1).reduce((e, t) => {
			let n = [...t.style].filter((e) => e.trim().includes("--nve")).map((e) => [e.trim(), t.style.getPropertyValue(e).trim()]);
			return [...e, ...n];
		}, []));
	}, []).reduce((e, n) => ({
		...e,
		[n[0]]: t.getPropertyValue(n[0])
	}), {});
}
function k(e) {
	A(e) && e.assignedNodes().forEach((e) => e.parentNode?.removeChild(e));
}
function A(e) {
	let t = !e.assignedNodes().find((e) => e.nodeType !== Node.TEXT_NODE), n = !e.assignedNodes().find((e) => e.nodeType === Node.TEXT_NODE && (e.textContent ?? "").trim() !== "");
	return t && n;
}
function j(e, t) {
	let n = e.assignedNodes(), r = e.name ?? "slot";
	n.length ? t._internals.states.add(`has-${r}`) : t._internals.states.delete(`has-${r}`);
}
function M(e) {
	return e?.label || e?.value || "";
}
function N(e, t) {
	return e.localName === t.metadata.tag;
}
function P(e) {
	let t = globalThis.document.createElement("div"), { width: n } = e.getBoundingClientRect();
	return t.setAttribute("nve-ghost", ""), t.style.minWidth = `${n}px`, t.style.maxWidth = `${n}px`, t.style.height = "1px", t.slot = e.slot, t;
}
function F(e, t) {
	let n = e.getRootNode(), r = t.getRootNode(), i = n instanceof ShadowRoot && r instanceof ShadowRoot && n === r, a = n === globalThis.document && r === globalThis.document;
	return i || a || n === r;
}
function I(e) {
	return e.style.anchorName?.split(",")?.map((e) => e.trim())?.filter((e) => e !== "none" && e !== "") ?? [];
}
function L(e, t) {
	let n = I(e);
	e.style.anchorName = n.filter((e) => e !== t).join(",");
}
function R(e, t) {
	e.style.anchorName = Array.from(new Set([...I(e), t])).join(",");
}
function z(e, t) {
	return e.length === t.length && e.every((e, n) => e === t[n]);
}
function B(e) {
	return Array.from(new Set(Array.from(e).filter((e) => typeof e == "string" && e.length > 0)));
}
//#endregion
export { y as KeynavCode, R as appendAnchorName, o as appendRootNodeStyle, j as applySlotContentStates, u as clickOutsideElementBounds, P as createGhostElement, m as define, p as defineElement, E as endOfScrollBox, r as generateId, I as getAnchorNames, i as getAttributeChanges, a as getAttributeListChanges, n as getChildren, M as getDisplayValue, l as getElementUpdate, _ as getFlattenedDOMTree, g as getFlattenedFocusableItems, c as getPropertyChanges, O as getThemeTokens, T as hasHorizontalScrollBar, x as hasInvalidDOMGrid, w as hasScrollBar, h as isContextMenuClick, N as matchesElementName, D as openEyeDropper, d as parseTokenNumber, L as removeAnchorName, k as removeEmptySlotWhitespace, S as removeEmptyTextNode, z as sameOrderedStringArray, F as sameRenderRoot, C as scrollBarWidth, A as slotContainsOnlyWhitespace, s as styleSheetToString, f as supportsScopedRegistry, B as uniqueNonEmptyStrings, v as validKeyNavigationCode };

//# sourceMappingURL=dom.js.map