UNPKG

jquery

Version:

JavaScript library for DOM operations

39 lines (32 loc) • 1.24 kB
// CSS escapes // https://www.w3.org/TR/CSS21/syndata.html#escaped-characters import { whitespace } from "../var/whitespace.js"; var runescape = new RegExp( "\\\\[\\da-fA-F]{1,6}" + whitespace + "?|\\\\([^\\da-fA-F\\r\\n\\f])", "g" ), funescape = function( escape, nonHex ) { var codePoint = "0x" + escape.slice( 1 ) - 0; if ( nonHex ) { // Strip the backslash prefix from a non-hex escape sequence return nonHex; } // Per the CSS spec, a NULL, surrogate, or out-of-range code point is // replaced with the REPLACEMENT CHARACTER (U+FFFD). // https://www.w3.org/TR/css-syntax-3/#consume-escaped-code-point if ( !codePoint || codePoint > 0x10FFFF || ( codePoint >= 0xD800 && codePoint < 0xE000 ) ) { return "\uFFFD"; } // Replace a hexadecimal escape sequence with the encoded Unicode code point // Support: IE <=11+ // For values outside the Basic Multilingual Plane (BMP), manually construct a // surrogate pair return codePoint < 0x10000 ? String.fromCharCode( codePoint ) : String.fromCharCode( ( codePoint - 0x10000 ) >> 10 | 0xD800, ( codePoint - 0x10000 ) & 0x3FF | 0xDC00 ); }; export function unescapeSelector( sel ) { return sel.replace( runescape, funescape ); }