/** * jsdom lacks parts of the CSSOM. Reka's Presence uses `CSS.escape` when it * resolves exiting children, so tests that dispatch real `animationend` events * need the same capability a browser provides. Only fills the gap; never * overrides an existing implementation. */ type CssEscapeHost = { escape?: (value: string) => string }; 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. 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 = 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; } return output; }; cssGlobal.CSS.escape = escapeIdentifier; }