summaryrefslogtreecommitdiff
path: root/includes/external/addressbook/node_modules/css-what/lib/es/stringify.js
diff options
context:
space:
mode:
authorRaindropsSys <raindrops@equestria.dev>2023-11-17 23:25:29 +0100
committerRaindropsSys <raindrops@equestria.dev>2023-11-17 23:25:29 +0100
commit953ddd82e48dd206cef5ac94456549aed13b3ad5 (patch)
tree8f003106ee2e7f422e5a22d2ee04d0db302e66c0 /includes/external/addressbook/node_modules/css-what/lib/es/stringify.js
parent62a9199846b0c07c03218703b33e8385764f42d9 (diff)
downloadpluralconnect-953ddd82e48dd206cef5ac94456549aed13b3ad5.tar.gz
pluralconnect-953ddd82e48dd206cef5ac94456549aed13b3ad5.tar.bz2
pluralconnect-953ddd82e48dd206cef5ac94456549aed13b3ad5.zip
Updated 30 files and deleted 2976 files (automated)
Diffstat (limited to 'includes/external/addressbook/node_modules/css-what/lib/es/stringify.js')
-rw-r--r--includes/external/addressbook/node_modules/css-what/lib/es/stringify.js126
1 files changed, 0 insertions, 126 deletions
diff --git a/includes/external/addressbook/node_modules/css-what/lib/es/stringify.js b/includes/external/addressbook/node_modules/css-what/lib/es/stringify.js
deleted file mode 100644
index 5f3b8ef..0000000
--- a/includes/external/addressbook/node_modules/css-what/lib/es/stringify.js
+++ /dev/null
@@ -1,126 +0,0 @@
-import { SelectorType, AttributeAction } from "./types";
-const attribValChars = ["\\", '"'];
-const pseudoValChars = [...attribValChars, "(", ")"];
-const charsToEscapeInAttributeValue = new Set(attribValChars.map((c) => c.charCodeAt(0)));
-const charsToEscapeInPseudoValue = new Set(pseudoValChars.map((c) => c.charCodeAt(0)));
-const charsToEscapeInName = new Set([
- ...pseudoValChars,
- "~",
- "^",
- "$",
- "*",
- "+",
- "!",
- "|",
- ":",
- "[",
- "]",
- " ",
- ".",
-].map((c) => c.charCodeAt(0)));
-/**
- * Turns `selector` back into a string.
- *
- * @param selector Selector to stringify.
- */
-export function stringify(selector) {
- return selector
- .map((token) => token.map(stringifyToken).join(""))
- .join(", ");
-}
-function stringifyToken(token, index, arr) {
- switch (token.type) {
- // Simple types
- case SelectorType.Child:
- return index === 0 ? "> " : " > ";
- case SelectorType.Parent:
- return index === 0 ? "< " : " < ";
- case SelectorType.Sibling:
- return index === 0 ? "~ " : " ~ ";
- case SelectorType.Adjacent:
- return index === 0 ? "+ " : " + ";
- case SelectorType.Descendant:
- return " ";
- case SelectorType.ColumnCombinator:
- return index === 0 ? "|| " : " || ";
- case SelectorType.Universal:
- // Return an empty string if the selector isn't needed.
- return token.namespace === "*" &&
- index + 1 < arr.length &&
- "name" in arr[index + 1]
- ? ""
- : `${getNamespace(token.namespace)}*`;
- case SelectorType.Tag:
- return getNamespacedName(token);
- case SelectorType.PseudoElement:
- return `::${escapeName(token.name, charsToEscapeInName)}${token.data === null
- ? ""
- : `(${escapeName(token.data, charsToEscapeInPseudoValue)})`}`;
- case SelectorType.Pseudo:
- return `:${escapeName(token.name, charsToEscapeInName)}${token.data === null
- ? ""
- : `(${typeof token.data === "string"
- ? escapeName(token.data, charsToEscapeInPseudoValue)
- : stringify(token.data)})`}`;
- case SelectorType.Attribute: {
- if (token.name === "id" &&
- token.action === AttributeAction.Equals &&
- token.ignoreCase === "quirks" &&
- !token.namespace) {
- return `#${escapeName(token.value, charsToEscapeInName)}`;
- }
- if (token.name === "class" &&
- token.action === AttributeAction.Element &&
- token.ignoreCase === "quirks" &&
- !token.namespace) {
- return `.${escapeName(token.value, charsToEscapeInName)}`;
- }
- const name = getNamespacedName(token);
- if (token.action === AttributeAction.Exists) {
- return `[${name}]`;
- }
- return `[${name}${getActionValue(token.action)}="${escapeName(token.value, charsToEscapeInAttributeValue)}"${token.ignoreCase === null ? "" : token.ignoreCase ? " i" : " s"}]`;
- }
- }
-}
-function getActionValue(action) {
- switch (action) {
- case AttributeAction.Equals:
- return "";
- case AttributeAction.Element:
- return "~";
- case AttributeAction.Start:
- return "^";
- case AttributeAction.End:
- return "$";
- case AttributeAction.Any:
- return "*";
- case AttributeAction.Not:
- return "!";
- case AttributeAction.Hyphen:
- return "|";
- case AttributeAction.Exists:
- throw new Error("Shouldn't be here");
- }
-}
-function getNamespacedName(token) {
- return `${getNamespace(token.namespace)}${escapeName(token.name, charsToEscapeInName)}`;
-}
-function getNamespace(namespace) {
- return namespace !== null
- ? `${namespace === "*"
- ? "*"
- : escapeName(namespace, charsToEscapeInName)}|`
- : "";
-}
-function escapeName(str, charsToEscape) {
- let lastIdx = 0;
- let ret = "";
- for (let i = 0; i < str.length; i++) {
- if (charsToEscape.has(str.charCodeAt(i))) {
- ret += `${str.slice(lastIdx, i)}\\${str.charAt(i)}`;
- lastIdx = i + 1;
- }
- }
- return ret.length > 0 ? ret + str.slice(lastIdx) : str;
-}