import { GlobalStateService as e } from "../services/global.service.js";
import { LogService as t } from "../services/log.service.js";
import { isFocusable as n } from "./focus.js";
//#region src/internal/utils/dom.ts
function r(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 i() {
	return `_${self.crypto.getRandomValues(new Uint32Array(1))[0].toString(16)}`;
}
function a(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 o(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 s(e, t) {
	let n = new CSSStyleSheet();
	n.replaceSync(t);
	let r = e.getRootNode();
	return r.adoptedStyleSheets && (r.adoptedStyleSheets.map((e) => c(e)).find((e) => e === c(n)) || (r.adoptedStyleSheets = [...Array.from(r.adoptedStyleSheets), n])), n;
}
function c(e) {
	return e.cssRules ? Array.from(e.cssRules).map((e) => e.cssText || "").join("\n") : "";
}
function l(e, t, n) {
	let r = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(e), t);
	if (!r) return;
	let i = Object.getOwnPropertyDescriptor(e, t);
	if (!(i && i.configurable === !1)) return Object.defineProperty(e, t, {
		configurable: !0,
		get: r.get,
		set: (t) => {
			r.set.call(e, t), n(t);
		}
	}), () => {
		if (i) {
			Object.defineProperty(e, t, i);
			return;
		}
		Reflect.deleteProperty(e, t);
	};
}
function u(e, t, n) {
	e.hasAttribute(t) ? n(e.getAttribute(t)) : e[t] !== void 0 && n(e[t]);
	let r = l(e, t, n), i = a(e, t, (e) => n(e)), o = i.disconnect.bind(i);
	return i.disconnect = () => {
		r?.(), o();
	}, i;
}
function d(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 f(e) {
	return parseInt(e.includes("calc") ? e.split("*")[1].replace("px)", "").trim() : e, 10) || 0;
}
var p = globalThis.CustomElementRegistry && "initialize" in CustomElementRegistry.prototype;
function m(t, n) {
	Object.entries(t.elementDefinitions ?? {}).filter(([e, t]) => !n.get(t.metadata.tag)).forEach(([e, t]) => {
		m(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 h(t) {
	let { version: n } = t.metadata;
	p && !customElements.get(t.metadata.tag) ? (customElements.define(t.metadata.tag, t), e.dispatch("NVE_ELEMENT_DEFINE", { elementRegistry: { [t.metadata.tag]: t.metadata.version } })) : m(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 g(e) {
	return e.buttons === 2 && !e.ctrlKey || e.buttons === 1 && e.ctrlKey;
}
function _(e, t = 10) {
	return v(e, t).filter((e) => n(e));
}
function v(e, t = 10) {
	return Array.from(r(e)).reduce((e, n) => [...e, [n, [...Array.from(r(n)).map((e) => [e, v(e, t)])]]], []).flat(t);
}
function y(e) {
	return x.has(e.code);
}
var b = /* @__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;
}({}), x = new Set(Object.values(b));
function S(e) {
	return e.some((t) => t.children.length !== e[0].children.length);
}
function C(e) {
	e?.wholeText?.trim() === "" && e.remove();
}
function w() {
	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 T(e) {
	return e.scrollHeight > e.clientHeight;
}
function E(e) {
	return e.scrollWidth > e.clientWidth;
}
function D(e, t = 0) {
	return e.scrollTop + e.offsetHeight + t >= e.scrollHeight;
}
async function O() {
	let e = globalThis.EyeDropper;
	if (!e) return t.warn("EyeDropper API is unavailable"), "";
	try {
		return (await new e().open()).sRGBHex;
	} catch (e) {
		return t.warn(`EyeDropper selection failed: ${e.message}`), "";
	}
}
function k(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 A(e) {
	j(e) && e.assignedNodes().forEach((e) => e.parentNode?.removeChild(e));
}
function j(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 M(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 N(e) {
	return e?.label || e?.value || "";
}
function P(e, t) {
	return e.localName === t.metadata.tag;
}
function F(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 I(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 L(e) {
	return e.style.anchorName?.split(",")?.map((e) => e.trim())?.filter((e) => e !== "none" && e !== "") ?? [];
}
function R(e, t) {
	let n = L(e);
	e.style.anchorName = n.filter((e) => e !== t).join(",");
}
function z(e, t) {
	e.style.anchorName = Array.from(new Set([...L(e), t])).join(",");
}
function B(e, t) {
	return e.length === t.length && e.every((e, n) => e === t[n]);
}
function V(e) {
	return Array.from(new Set(Array.from(e).filter((e) => typeof e == "string" && e.length > 0)));
}
//#endregion
export { b as KeynavCode, z as appendAnchorName, s as appendRootNodeStyle, M as applySlotContentStates, d as clickOutsideElementBounds, F as createGhostElement, h as define, m as defineElement, D as endOfScrollBox, i as generateId, L as getAnchorNames, a as getAttributeChanges, o as getAttributeListChanges, r as getChildren, N as getDisplayValue, u as getElementUpdate, v as getFlattenedDOMTree, _ as getFlattenedFocusableItems, l as getPropertyChanges, k as getThemeTokens, E as hasHorizontalScrollBar, S as hasInvalidDOMGrid, T as hasScrollBar, g as isContextMenuClick, P as matchesElementName, O as openEyeDropper, f as parseTokenNumber, R as removeAnchorName, A as removeEmptySlotWhitespace, C as removeEmptyTextNode, B as sameOrderedStringArray, I as sameRenderRoot, w as scrollBarWidth, j as slotContainsOnlyWhitespace, c as styleSheetToString, p as supportsScopedRegistry, V as uniqueNonEmptyStrings, y as validKeyNavigationCode };

//# sourceMappingURL=dom.js.map