source: trip-planner-front/node_modules/css-what/lib/stringify.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.0 KB
Line 
1"use strict";
2var __spreadArray = (this && this.__spreadArray) || function (to, from) {
3 for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
4 to[j] = from[i];
5 return to;
6};
7Object.defineProperty(exports, "__esModule", { value: true });
8var actionTypes = {
9 equals: "",
10 element: "~",
11 start: "^",
12 end: "$",
13 any: "*",
14 not: "!",
15 hyphen: "|",
16};
17var charsToEscape = new Set(__spreadArray(__spreadArray([], Object.keys(actionTypes)
18 .map(function (typeKey) { return actionTypes[typeKey]; })
19 .filter(Boolean)), [
20 ":",
21 "[",
22 "]",
23 " ",
24 "\\",
25 "(",
26 ")",
27 "'",
28]));
29/**
30 * Turns `selector` back into a string.
31 *
32 * @param selector Selector to stringify.
33 */
34function stringify(selector) {
35 return selector.map(stringifySubselector).join(", ");
36}
37exports.default = stringify;
38function stringifySubselector(token) {
39 return token.map(stringifyToken).join("");
40}
41function stringifyToken(token) {
42 switch (token.type) {
43 // Simple types
44 case "child":
45 return " > ";
46 case "parent":
47 return " < ";
48 case "sibling":
49 return " ~ ";
50 case "adjacent":
51 return " + ";
52 case "descendant":
53 return " ";
54 case "universal":
55 return getNamespace(token.namespace) + "*";
56 case "tag":
57 return getNamespacedName(token);
58 case "pseudo-element":
59 return "::" + escapeName(token.name);
60 case "pseudo":
61 if (token.data === null)
62 return ":" + escapeName(token.name);
63 if (typeof token.data === "string") {
64 return ":" + escapeName(token.name) + "(" + escapeName(token.data) + ")";
65 }
66 return ":" + escapeName(token.name) + "(" + stringify(token.data) + ")";
67 case "attribute": {
68 if (token.name === "id" &&
69 token.action === "equals" &&
70 !token.ignoreCase &&
71 !token.namespace) {
72 return "#" + escapeName(token.value);
73 }
74 if (token.name === "class" &&
75 token.action === "element" &&
76 !token.ignoreCase &&
77 !token.namespace) {
78 return "." + escapeName(token.value);
79 }
80 var name_1 = getNamespacedName(token);
81 if (token.action === "exists") {
82 return "[" + name_1 + "]";
83 }
84 return "[" + name_1 + actionTypes[token.action] + "='" + escapeName(token.value) + "'" + (token.ignoreCase ? "i" : token.ignoreCase === false ? "s" : "") + "]";
85 }
86 }
87}
88function getNamespacedName(token) {
89 return "" + getNamespace(token.namespace) + escapeName(token.name);
90}
91function getNamespace(namespace) {
92 return namespace !== null
93 ? (namespace === "*" ? "*" : escapeName(namespace)) + "|"
94 : "";
95}
96function escapeName(str) {
97 return str
98 .split("")
99 .map(function (c) { return (charsToEscape.has(c) ? "\\" + c : c); })
100 .join("");
101}
Note: See TracBrowser for help on using the repository browser.