import { COMMENT as e, DECLARATION as t, RULESET as n } from "./Enum.js";
import { abs as r, append as i, charat as a, from as o, replace as s, sizeof as c, strlen as l, substr as u, trim as d } from "./Utility.js";
import { alloc as f, caret as p, char as m, commenter as h, dealloc as g, delimit as _, escaping as v, identifier as y, next as b, node as x, peek as S, prev as C, token as w, whitespace as T } from "./Tokenizer.js";
//#region ../../node_modules/stylis/src/Parser.js
function E(e) {
	return g(D("", null, null, null, [""], e = f(e), 0, [0], e));
}
function D(e, t, n, r, c, d, f, m, g) {
	for (var x = 0, E = 0, j = f, M = 0, N = 0, P = 0, F = 1, I = 1, L = 1, R = 0, z = 0, B = "", V = c, H = d, U = r, W = B; I;) switch (P = z, z = b()) {
		case 40:
			P != 108 && a(W, j - 1) == 58 ? (R++, W += "(") : W += _(z);
			break;
		case 41:
			R--, W += ")";
			break;
		case 34:
		case 39:
		case 91:
			W += _(z);
			break;
		case 9:
		case 10:
		case 13:
		case 32:
			if (R > 0) {
				W += o(z);
				break;
			}
			W += T(P);
			break;
		case 92:
			W += v(p() - 1, 7);
			continue;
		case 47:
			switch (S()) {
				case 42:
				case 47:
					i(k(h(b(), p()), t, n, g), g), (w(P || 1) == 5 || w(S() || 1) == 5) && l(W) && u(W, -1, void 0) !== " " && (W += " ");
					break;
				default: W += "/";
			}
			break;
		case 123 * F: m[x++] = l(W) * L;
		case 125 * F:
		case 59:
		case 0:
			if (R > 0 && z) {
				W += o(z);
				break;
			}
			switch (z) {
				case 0:
				case 125: I = 0;
				case 59 + E:
					L == -1 && (W = s(W, /\f/g, "")), N > 0 && (l(W) - j || F === 0) && i(N > 32 ? A(W + ";", r, n, j - 1, g) : A(s(W, " ", "") + ";", r, n, j - 2, g), g);
					break;
				case 59: W += ";";
				default: if (i(U = O(W, t, n, x, E, c, m, B, V = [], H = [], j, d), d), z === 123) if (E === 0) D(W, t, U, U, V, d, j, m, H);
				else {
					switch (M) {
						case 99: if (a(W, 3) === 110) break;
						case 108: if (a(W, 2) === 97) break;
						default: E = 0;
						case 100:
						case 109:
						case 115:
					}
					E ? D(e, U, U, r && i(O(e, U, U, 0, 0, c, m, B, c, V = [], j, H), H), c, H, j, m, r ? V : H) : D(W, U, U, U, [""], H, 0, m, H);
				}
			}
			x = E = N = 0, F = L = 1, B = W = "", j = f;
			break;
		case 58: j = 1 + l(W), N = P;
		default:
			if (F < 1) {
				if (z == 123) --F;
				else if (z == 125 && F++ == 0 && C() == 125) continue;
			}
			switch (W += o(z), z * F) {
				case 38:
					L = E > 0 ? 1 : (W += "\f", -1);
					break;
				case 44:
					if (R > 0) break;
					m[x++] = (l(W) - 1) * L, L = 1;
					break;
				case 64:
					S() === 45 && (W += _(b())), M = S(), E = j = l(B = W += y(p())), z++;
					break;
				case 45: P === 45 && l(W) == 2 && (F = 0);
			}
	}
	return d;
}
function O(e, t, i, a, o, l, f, p, m, h, g, _) {
	for (var v = o - 1, y = o === 0 ? l : [""], b = c(y), S = 0, C = 0, w = 0; S < a; ++S) for (var T = 0, E = u(e, v + 1, v = r(C = f[S])), D = e; T < b; ++T) (D = d(C > 0 ? y[T] + " " + E : s(E, /&\f/g, y[T]))) && (m[w++] = D);
	return x(e, t, i, o === 0 ? n : p, m, h, g, _);
}
function k(t, n, r, i) {
	return x(t, n, r, e, o(m()), u(t, 2, -2), 0, i);
}
function A(e, n, r, i, a) {
	return x(e, n, r, t, u(e, 0, i), u(e, i + 1, -1), i, a);
}
//#endregion
export { E as compile };

//# sourceMappingURL=Parser.js.map