test: finalize Menu and Dropdown acceptance with CSSOM coverage
This commit is contained in:
+22
-11
@@ -10,27 +10,38 @@ const cssGlobal = globalThis as unknown as { CSS?: CssEscapeHost };
|
||||
if (!cssGlobal.CSS) cssGlobal.CSS = {};
|
||||
|
||||
if (typeof cssGlobal.CSS.escape !== "function") {
|
||||
// Approximation of CSS.escape for selector fragments: hex-escape leading
|
||||
// digits and any character outside the identifier set.
|
||||
// CSSOM identifier serialization, including leading digits after a minus,
|
||||
// control characters and the otherwise-invalid single minus identifier.
|
||||
const escapeIdentifier = (value: string) => {
|
||||
const input = String(value);
|
||||
let output = "";
|
||||
for (let index = 0; index < input.length; index += 1) {
|
||||
const char = input[index];
|
||||
const code = char.codePointAt(0) ?? 0;
|
||||
const isFirst = index === 0;
|
||||
const digits = code >= 0x30 && code <= 0x39;
|
||||
const safe =
|
||||
const code = input.charCodeAt(index);
|
||||
if (code === 0) {
|
||||
output += "\uFFFD";
|
||||
} else if (
|
||||
(code >= 1 && code <= 0x1f) ||
|
||||
code === 0x7f ||
|
||||
(code >= 0x30 &&
|
||||
code <= 0x39 &&
|
||||
(index === 0 || (index === 1 && input[0] === "-")))
|
||||
) {
|
||||
output += `\\${code.toString(16)} `;
|
||||
} else if (index === 0 && code === 0x2d && input.length === 1) {
|
||||
output += "\\-";
|
||||
} else if (
|
||||
code >= 0x80 ||
|
||||
code === 0x2d ||
|
||||
code === 0x5f ||
|
||||
(code >= 0x30 && code <= 0x39) ||
|
||||
(code >= 0x41 && code <= 0x5a) ||
|
||||
(code >= 0x61 && code <= 0x7a);
|
||||
if (code === 0) output += "\uFFFD";
|
||||
else if ((isFirst && digits) || !safe)
|
||||
output += `\\${code.toString(16)} `;
|
||||
else output += char;
|
||||
(code >= 0x61 && code <= 0x7a)
|
||||
) {
|
||||
output += char;
|
||||
} else {
|
||||
output += `\\${char}`;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user