diff options
Diffstat (limited to 'node_modules/css-what/lib')
-rw-r--r-- | node_modules/css-what/lib/index.d.ts | 4 | ||||
-rw-r--r-- | node_modules/css-what/lib/index.d.ts.map | 1 | ||||
-rw-r--r-- | node_modules/css-what/lib/index.js | 21 | ||||
-rw-r--r-- | node_modules/css-what/lib/parse.d.ts | 71 | ||||
-rw-r--r-- | node_modules/css-what/lib/parse.d.ts.map | 1 | ||||
-rw-r--r-- | node_modules/css-what/lib/parse.js | 432 | ||||
-rw-r--r-- | node_modules/css-what/lib/stringify.d.ts | 8 | ||||
-rw-r--r-- | node_modules/css-what/lib/stringify.d.ts.map | 1 | ||||
-rw-r--r-- | node_modules/css-what/lib/stringify.js | 105 |
9 files changed, 644 insertions, 0 deletions
diff --git a/node_modules/css-what/lib/index.d.ts b/node_modules/css-what/lib/index.d.ts new file mode 100644 index 0000000..d474fa1 --- /dev/null +++ b/node_modules/css-what/lib/index.d.ts @@ -0,0 +1,4 @@ +export * from "./parse"; +export { default as parse } from "./parse"; +export { default as stringify } from "./stringify"; +//# sourceMappingURL=index.d.ts.map
\ No newline at end of file diff --git a/node_modules/css-what/lib/index.d.ts.map b/node_modules/css-what/lib/index.d.ts.map new file mode 100644 index 0000000..4191999 --- /dev/null +++ b/node_modules/css-what/lib/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC"}
\ No newline at end of file diff --git a/node_modules/css-what/lib/index.js b/node_modules/css-what/lib/index.js new file mode 100644 index 0000000..5095250 --- /dev/null +++ b/node_modules/css-what/lib/index.js @@ -0,0 +1,21 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.stringify = exports.parse = void 0; +__exportStar(require("./parse"), exports); +var parse_1 = require("./parse"); +Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return __importDefault(parse_1).default; } }); +var stringify_1 = require("./stringify"); +Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return __importDefault(stringify_1).default; } }); diff --git a/node_modules/css-what/lib/parse.d.ts b/node_modules/css-what/lib/parse.d.ts new file mode 100644 index 0000000..59e81e3 --- /dev/null +++ b/node_modules/css-what/lib/parse.d.ts @@ -0,0 +1,71 @@ +export interface Options { + /** + * When false, tag names will not be lowercased. + * @default true + */ + lowerCaseAttributeNames?: boolean; + /** + * When false, attribute names will not be lowercased. + * @default true + */ + lowerCaseTags?: boolean; + /** + * When `true`, `xmlMode` implies both `lowerCaseTags` and `lowerCaseAttributeNames` are set to `false`. + * Also, `ignoreCase` on attributes will not be inferred based on HTML rules anymore. + * @default false + */ + xmlMode?: boolean; +} +export declare type Selector = PseudoSelector | PseudoElement | AttributeSelector | TagSelector | UniversalSelector | Traversal; +export interface AttributeSelector { + type: "attribute"; + name: string; + action: AttributeAction; + value: string; + ignoreCase: boolean | null; + namespace: string | null; +} +declare type DataType = Selector[][] | null | string; +export interface PseudoSelector { + type: "pseudo"; + name: string; + data: DataType; +} +export interface PseudoElement { + type: "pseudo-element"; + name: string; +} +export interface TagSelector { + type: "tag"; + name: string; + namespace: string | null; +} +export interface UniversalSelector { + type: "universal"; + namespace: string | null; +} +export interface Traversal { + type: TraversalType; +} +export declare type AttributeAction = "any" | "element" | "end" | "equals" | "exists" | "hyphen" | "not" | "start"; +export declare type TraversalType = "adjacent" | "child" | "descendant" | "parent" | "sibling"; +/** + * Checks whether a specific selector is a traversal. + * This is useful eg. in swapping the order of elements that + * are not traversals. + * + * @param selector Selector to check. + */ +export declare function isTraversal(selector: Selector): selector is Traversal; +/** + * Parses `selector`, optionally with the passed `options`. + * + * @param selector Selector to parse. + * @param options Options for parsing. + * @returns Returns a two-dimensional array. + * The first dimension represents selectors separated by commas (eg. `sub1, sub2`), + * the second contains the relevant tokens for that selector. + */ +export default function parse(selector: string, options?: Options): Selector[][]; +export {}; +//# sourceMappingURL=parse.d.ts.map
\ No newline at end of file diff --git a/node_modules/css-what/lib/parse.d.ts.map b/node_modules/css-what/lib/parse.d.ts.map new file mode 100644 index 0000000..df5d1a3 --- /dev/null +++ b/node_modules/css-what/lib/parse.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACpB;;;OAGG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,oBAAY,QAAQ,GACd,cAAc,GACd,aAAa,GACb,iBAAiB,GACjB,WAAW,GACX,iBAAiB,GACjB,SAAS,CAAC;AAEhB,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,aAAK,QAAQ,GAAG,QAAQ,EAAE,EAAE,GAAG,IAAI,GAAG,MAAM,CAAC;AAE7C,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,gBAAgB,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,aAAa,CAAC;CACvB;AAED,oBAAY,eAAe,GACrB,KAAK,GACL,SAAS,GACT,KAAK,GACL,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,KAAK,GACL,OAAO,CAAC;AAEd,oBAAY,aAAa,GACnB,UAAU,GACV,OAAO,GACP,YAAY,GACZ,QAAQ,GACR,SAAS,CAAC;AAiGhB;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,IAAI,SAAS,CAErE;AA4BD;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,KAAK,CACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,OAAO,GAClB,QAAQ,EAAE,EAAE,CAUd"}
\ No newline at end of file diff --git a/node_modules/css-what/lib/parse.js b/node_modules/css-what/lib/parse.js new file mode 100644 index 0000000..786b13e --- /dev/null +++ b/node_modules/css-what/lib/parse.js @@ -0,0 +1,432 @@ +"use strict"; +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.isTraversal = void 0; +var reName = /^[^\\#]?(?:\\(?:[\da-f]{1,6}\s?|.)|[\w\-\u00b0-\uFFFF])+/; +var reEscape = /\\([\da-f]{1,6}\s?|(\s)|.)/gi; +var actionTypes = new Map([ + ["~", "element"], + ["^", "start"], + ["$", "end"], + ["*", "any"], + ["!", "not"], + ["|", "hyphen"], +]); +var Traversals = { + ">": "child", + "<": "parent", + "~": "sibling", + "+": "adjacent", +}; +var attribSelectors = { + "#": ["id", "equals"], + ".": ["class", "element"], +}; +// Pseudos, whose data property is parsed as well. +var unpackPseudos = new Set([ + "has", + "not", + "matches", + "is", + "where", + "host", + "host-context", +]); +var traversalNames = new Set(__spreadArray([ + "descendant" +], Object.keys(Traversals).map(function (k) { return Traversals[k]; }), true)); +/** + * Attributes that are case-insensitive in HTML. + * + * @private + * @see https://html.spec.whatwg.org/multipage/semantics-other.html#case-sensitivity-of-selectors + */ +var caseInsensitiveAttributes = new Set([ + "accept", + "accept-charset", + "align", + "alink", + "axis", + "bgcolor", + "charset", + "checked", + "clear", + "codetype", + "color", + "compact", + "declare", + "defer", + "dir", + "direction", + "disabled", + "enctype", + "face", + "frame", + "hreflang", + "http-equiv", + "lang", + "language", + "link", + "media", + "method", + "multiple", + "nohref", + "noresize", + "noshade", + "nowrap", + "readonly", + "rel", + "rev", + "rules", + "scope", + "scrolling", + "selected", + "shape", + "target", + "text", + "type", + "valign", + "valuetype", + "vlink", +]); +/** + * Checks whether a specific selector is a traversal. + * This is useful eg. in swapping the order of elements that + * are not traversals. + * + * @param selector Selector to check. + */ +function isTraversal(selector) { + return traversalNames.has(selector.type); +} +exports.isTraversal = isTraversal; +var stripQuotesFromPseudos = new Set(["contains", "icontains"]); +var quotes = new Set(['"', "'"]); +// Unescape function taken from https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L152 +function funescape(_, escaped, escapedWhitespace) { + var high = parseInt(escaped, 16) - 0x10000; + // NaN means non-codepoint + return high !== high || escapedWhitespace + ? escaped + : high < 0 + ? // BMP codepoint + String.fromCharCode(high + 0x10000) + : // Supplemental Plane codepoint (surrogate pair) + String.fromCharCode((high >> 10) | 0xd800, (high & 0x3ff) | 0xdc00); +} +function unescapeCSS(str) { + return str.replace(reEscape, funescape); +} +function isWhitespace(c) { + return c === " " || c === "\n" || c === "\t" || c === "\f" || c === "\r"; +} +/** + * Parses `selector`, optionally with the passed `options`. + * + * @param selector Selector to parse. + * @param options Options for parsing. + * @returns Returns a two-dimensional array. + * The first dimension represents selectors separated by commas (eg. `sub1, sub2`), + * the second contains the relevant tokens for that selector. + */ +function parse(selector, options) { + var subselects = []; + var endIndex = parseSelector(subselects, "" + selector, options, 0); + if (endIndex < selector.length) { + throw new Error("Unmatched selector: " + selector.slice(endIndex)); + } + return subselects; +} +exports.default = parse; +function parseSelector(subselects, selector, options, selectorIndex) { + var _a, _b; + if (options === void 0) { options = {}; } + var tokens = []; + var sawWS = false; + function getName(offset) { + var match = selector.slice(selectorIndex + offset).match(reName); + if (!match) { + throw new Error("Expected name, found " + selector.slice(selectorIndex)); + } + var name = match[0]; + selectorIndex += offset + name.length; + return unescapeCSS(name); + } + function stripWhitespace(offset) { + while (isWhitespace(selector.charAt(selectorIndex + offset))) + offset++; + selectorIndex += offset; + } + function isEscaped(pos) { + var slashCount = 0; + while (selector.charAt(--pos) === "\\") + slashCount++; + return (slashCount & 1) === 1; + } + function ensureNotTraversal() { + if (tokens.length > 0 && isTraversal(tokens[tokens.length - 1])) { + throw new Error("Did not expect successive traversals."); + } + } + stripWhitespace(0); + while (selector !== "") { + var firstChar = selector.charAt(selectorIndex); + if (isWhitespace(firstChar)) { + sawWS = true; + stripWhitespace(1); + } + else if (firstChar in Traversals) { + ensureNotTraversal(); + tokens.push({ type: Traversals[firstChar] }); + sawWS = false; + stripWhitespace(1); + } + else if (firstChar === ",") { + if (tokens.length === 0) { + throw new Error("Empty sub-selector"); + } + subselects.push(tokens); + tokens = []; + sawWS = false; + stripWhitespace(1); + } + else if (selector.startsWith("/*", selectorIndex)) { + var endIndex = selector.indexOf("*/", selectorIndex + 2); + if (endIndex < 0) { + throw new Error("Comment was not terminated"); + } + selectorIndex = endIndex + 2; + } + else { + if (sawWS) { + ensureNotTraversal(); + tokens.push({ type: "descendant" }); + sawWS = false; + } + if (firstChar in attribSelectors) { + var _c = attribSelectors[firstChar], name_1 = _c[0], action = _c[1]; + tokens.push({ + type: "attribute", + name: name_1, + action: action, + value: getName(1), + namespace: null, + // TODO: Add quirksMode option, which makes `ignoreCase` `true` for HTML. + ignoreCase: options.xmlMode ? null : false, + }); + } + else if (firstChar === "[") { + stripWhitespace(1); + // Determine attribute name and namespace + var namespace = null; + if (selector.charAt(selectorIndex) === "|") { + namespace = ""; + selectorIndex += 1; + } + if (selector.startsWith("*|", selectorIndex)) { + namespace = "*"; + selectorIndex += 2; + } + var name_2 = getName(0); + if (namespace === null && + selector.charAt(selectorIndex) === "|" && + selector.charAt(selectorIndex + 1) !== "=") { + namespace = name_2; + name_2 = getName(1); + } + if ((_a = options.lowerCaseAttributeNames) !== null && _a !== void 0 ? _a : !options.xmlMode) { + name_2 = name_2.toLowerCase(); + } + stripWhitespace(0); + // Determine comparison operation + var action = "exists"; + var possibleAction = actionTypes.get(selector.charAt(selectorIndex)); + if (possibleAction) { + action = possibleAction; + if (selector.charAt(selectorIndex + 1) !== "=") { + throw new Error("Expected `=`"); + } + stripWhitespace(2); + } + else if (selector.charAt(selectorIndex) === "=") { + action = "equals"; + stripWhitespace(1); + } + // Determine value + var value = ""; + var ignoreCase = null; + if (action !== "exists") { + if (quotes.has(selector.charAt(selectorIndex))) { + var quote = selector.charAt(selectorIndex); + var sectionEnd = selectorIndex + 1; + while (sectionEnd < selector.length && + (selector.charAt(sectionEnd) !== quote || + isEscaped(sectionEnd))) { + sectionEnd += 1; + } + if (selector.charAt(sectionEnd) !== quote) { + throw new Error("Attribute value didn't end"); + } + value = unescapeCSS(selector.slice(selectorIndex + 1, sectionEnd)); + selectorIndex = sectionEnd + 1; + } + else { + var valueStart = selectorIndex; + while (selectorIndex < selector.length && + ((!isWhitespace(selector.charAt(selectorIndex)) && + selector.charAt(selectorIndex) !== "]") || + isEscaped(selectorIndex))) { + selectorIndex += 1; + } + value = unescapeCSS(selector.slice(valueStart, selectorIndex)); + } + stripWhitespace(0); + // See if we have a force ignore flag + var forceIgnore = selector.charAt(selectorIndex); + // If the forceIgnore flag is set (either `i` or `s`), use that value + if (forceIgnore === "s" || forceIgnore === "S") { + ignoreCase = false; + stripWhitespace(1); + } + else if (forceIgnore === "i" || forceIgnore === "I") { + ignoreCase = true; + stripWhitespace(1); + } + } + // If `xmlMode` is set, there are no rules; otherwise, use the `caseInsensitiveAttributes` list. + if (!options.xmlMode) { + // TODO: Skip this for `exists`, as there is no value to compare to. + ignoreCase !== null && ignoreCase !== void 0 ? ignoreCase : (ignoreCase = caseInsensitiveAttributes.has(name_2)); + } + if (selector.charAt(selectorIndex) !== "]") { + throw new Error("Attribute selector didn't terminate"); + } + selectorIndex += 1; + var attributeSelector = { + type: "attribute", + name: name_2, + action: action, + value: value, + namespace: namespace, + ignoreCase: ignoreCase, + }; + tokens.push(attributeSelector); + } + else if (firstChar === ":") { + if (selector.charAt(selectorIndex + 1) === ":") { + tokens.push({ + type: "pseudo-element", + name: getName(2).toLowerCase(), + }); + continue; + } + var name_3 = getName(1).toLowerCase(); + var data = null; + if (selector.charAt(selectorIndex) === "(") { + if (unpackPseudos.has(name_3)) { + if (quotes.has(selector.charAt(selectorIndex + 1))) { + throw new Error("Pseudo-selector " + name_3 + " cannot be quoted"); + } + data = []; + selectorIndex = parseSelector(data, selector, options, selectorIndex + 1); + if (selector.charAt(selectorIndex) !== ")") { + throw new Error("Missing closing parenthesis in :" + name_3 + " (" + selector + ")"); + } + selectorIndex += 1; + } + else { + selectorIndex += 1; + var start = selectorIndex; + var counter = 1; + for (; counter > 0 && selectorIndex < selector.length; selectorIndex++) { + if (selector.charAt(selectorIndex) === "(" && + !isEscaped(selectorIndex)) { + counter++; + } + else if (selector.charAt(selectorIndex) === ")" && + !isEscaped(selectorIndex)) { + counter--; + } + } + if (counter) { + throw new Error("Parenthesis not matched"); + } + data = selector.slice(start, selectorIndex - 1); + if (stripQuotesFromPseudos.has(name_3)) { + var quot = data.charAt(0); + if (quot === data.slice(-1) && quotes.has(quot)) { + data = data.slice(1, -1); + } + data = unescapeCSS(data); + } + } + } + tokens.push({ type: "pseudo", name: name_3, data: data }); + } + else { + var namespace = null; + var name_4 = void 0; + if (firstChar === "*") { + selectorIndex += 1; + name_4 = "*"; + } + else if (reName.test(selector.slice(selectorIndex))) { + if (selector.charAt(selectorIndex) === "|") { + namespace = ""; + selectorIndex += 1; + } + name_4 = getName(0); + } + else { + /* + * We have finished parsing the selector. + * Remove descendant tokens at the end if they exist, + * and return the last index, so that parsing can be + * picked up from here. + */ + if (tokens.length && + tokens[tokens.length - 1].type === "descendant") { + tokens.pop(); + } + addToken(subselects, tokens); + return selectorIndex; + } + if (selector.charAt(selectorIndex) === "|") { + namespace = name_4; + if (selector.charAt(selectorIndex + 1) === "*") { + name_4 = "*"; + selectorIndex += 2; + } + else { + name_4 = getName(1); + } + } + if (name_4 === "*") { + tokens.push({ type: "universal", namespace: namespace }); + } + else { + if ((_b = options.lowerCaseTags) !== null && _b !== void 0 ? _b : !options.xmlMode) { + name_4 = name_4.toLowerCase(); + } + tokens.push({ type: "tag", name: name_4, namespace: namespace }); + } + } + } + } + addToken(subselects, tokens); + return selectorIndex; +} +function addToken(subselects, tokens) { + if (subselects.length > 0 && tokens.length === 0) { + throw new Error("Empty sub-selector"); + } + subselects.push(tokens); +} diff --git a/node_modules/css-what/lib/stringify.d.ts b/node_modules/css-what/lib/stringify.d.ts new file mode 100644 index 0000000..407050e --- /dev/null +++ b/node_modules/css-what/lib/stringify.d.ts @@ -0,0 +1,8 @@ +import { Selector } from "./parse"; +/** + * Turns `selector` back into a string. + * + * @param selector Selector to stringify. + */ +export default function stringify(selector: Selector[][]): string; +//# sourceMappingURL=stringify.d.ts.map
\ No newline at end of file diff --git a/node_modules/css-what/lib/stringify.d.ts.map b/node_modules/css-what/lib/stringify.d.ts.map new file mode 100644 index 0000000..06eb2f0 --- /dev/null +++ b/node_modules/css-what/lib/stringify.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"stringify.d.ts","sourceRoot":"","sources":["../src/stringify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AA0BnC;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,GAAG,MAAM,CAEhE"}
\ No newline at end of file diff --git a/node_modules/css-what/lib/stringify.js b/node_modules/css-what/lib/stringify.js new file mode 100644 index 0000000..ccd3d6c --- /dev/null +++ b/node_modules/css-what/lib/stringify.js @@ -0,0 +1,105 @@ +"use strict"; +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var actionTypes = { + equals: "", + element: "~", + start: "^", + end: "$", + any: "*", + not: "!", + hyphen: "|", +}; +var charsToEscape = new Set(__spreadArray(__spreadArray([], Object.keys(actionTypes) + .map(function (typeKey) { return actionTypes[typeKey]; }) + .filter(Boolean), true), [ + ":", + "[", + "]", + " ", + "\\", + "(", + ")", + "'", +], false)); +/** + * Turns `selector` back into a string. + * + * @param selector Selector to stringify. + */ +function stringify(selector) { + return selector.map(stringifySubselector).join(", "); +} +exports.default = stringify; +function stringifySubselector(token) { + return token.map(stringifyToken).join(""); +} +function stringifyToken(token) { + switch (token.type) { + // Simple types + case "child": + return " > "; + case "parent": + return " < "; + case "sibling": + return " ~ "; + case "adjacent": + return " + "; + case "descendant": + return " "; + case "universal": + return getNamespace(token.namespace) + "*"; + case "tag": + return getNamespacedName(token); + case "pseudo-element": + return "::" + escapeName(token.name); + case "pseudo": + if (token.data === null) + return ":" + escapeName(token.name); + if (typeof token.data === "string") { + return ":" + escapeName(token.name) + "(" + escapeName(token.data) + ")"; + } + return ":" + escapeName(token.name) + "(" + stringify(token.data) + ")"; + case "attribute": { + if (token.name === "id" && + token.action === "equals" && + !token.ignoreCase && + !token.namespace) { + return "#" + escapeName(token.value); + } + if (token.name === "class" && + token.action === "element" && + !token.ignoreCase && + !token.namespace) { + return "." + escapeName(token.value); + } + var name_1 = getNamespacedName(token); + if (token.action === "exists") { + return "[" + name_1 + "]"; + } + return "[" + name_1 + actionTypes[token.action] + "='" + escapeName(token.value) + "'" + (token.ignoreCase ? "i" : token.ignoreCase === false ? "s" : "") + "]"; + } + } +} +function getNamespacedName(token) { + return "" + getNamespace(token.namespace) + escapeName(token.name); +} +function getNamespace(namespace) { + return namespace !== null + ? (namespace === "*" ? "*" : escapeName(namespace)) + "|" + : ""; +} +function escapeName(str) { + return str + .split("") + .map(function (c) { return (charsToEscape.has(c) ? "\\" + c : c); }) + .join(""); +} |