diff options
author | Minteck <contact@minteck.org> | 2022-02-09 17:58:07 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-02-09 17:58:07 +0100 |
commit | 22a25ded9f7d9c9a96cce8d1bc12475ca0434201 (patch) | |
tree | 0e33d0650fe58f41c00bbc4b8047956905766823 /node_modules/css-select/lib/pseudo-selectors/pseudos.js | |
parent | 8f54d903fb3470823a5e4d6ff4655de009836245 (diff) | |
download | youtoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.tar.gz youtoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.tar.bz2 youtoo-22a25ded9f7d9c9a96cce8d1bc12475ca0434201.zip |
Major update
Diffstat (limited to 'node_modules/css-select/lib/pseudo-selectors/pseudos.js')
-rw-r--r-- | node_modules/css-select/lib/pseudo-selectors/pseudos.js | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/node_modules/css-select/lib/pseudo-selectors/pseudos.js b/node_modules/css-select/lib/pseudo-selectors/pseudos.js new file mode 100644 index 0000000..c5da839 --- /dev/null +++ b/node_modules/css-select/lib/pseudo-selectors/pseudos.js @@ -0,0 +1,89 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.verifyPseudoArgs = exports.pseudos = void 0; +// While filters are precompiled, pseudos get called when they are needed +exports.pseudos = { + empty: function (elem, _a) { + var adapter = _a.adapter; + return !adapter.getChildren(elem).some(function (elem) { + // FIXME: `getText` call is potentially expensive. + return adapter.isTag(elem) || adapter.getText(elem) !== ""; + }); + }, + "first-child": function (elem, _a) { + var adapter = _a.adapter, equals = _a.equals; + var firstChild = adapter + .getSiblings(elem) + .find(function (elem) { return adapter.isTag(elem); }); + return firstChild != null && equals(elem, firstChild); + }, + "last-child": function (elem, _a) { + var adapter = _a.adapter, equals = _a.equals; + var siblings = adapter.getSiblings(elem); + for (var i = siblings.length - 1; i >= 0; i--) { + if (equals(elem, siblings[i])) + return true; + if (adapter.isTag(siblings[i])) + break; + } + return false; + }, + "first-of-type": function (elem, _a) { + var adapter = _a.adapter, equals = _a.equals; + var siblings = adapter.getSiblings(elem); + var elemName = adapter.getName(elem); + for (var i = 0; i < siblings.length; i++) { + var currentSibling = siblings[i]; + if (equals(elem, currentSibling)) + return true; + if (adapter.isTag(currentSibling) && + adapter.getName(currentSibling) === elemName) { + break; + } + } + return false; + }, + "last-of-type": function (elem, _a) { + var adapter = _a.adapter, equals = _a.equals; + var siblings = adapter.getSiblings(elem); + var elemName = adapter.getName(elem); + for (var i = siblings.length - 1; i >= 0; i--) { + var currentSibling = siblings[i]; + if (equals(elem, currentSibling)) + return true; + if (adapter.isTag(currentSibling) && + adapter.getName(currentSibling) === elemName) { + break; + } + } + return false; + }, + "only-of-type": function (elem, _a) { + var adapter = _a.adapter, equals = _a.equals; + var elemName = adapter.getName(elem); + return adapter + .getSiblings(elem) + .every(function (sibling) { + return equals(elem, sibling) || + !adapter.isTag(sibling) || + adapter.getName(sibling) !== elemName; + }); + }, + "only-child": function (elem, _a) { + var adapter = _a.adapter, equals = _a.equals; + return adapter + .getSiblings(elem) + .every(function (sibling) { return equals(elem, sibling) || !adapter.isTag(sibling); }); + }, +}; +function verifyPseudoArgs(func, name, subselect) { + if (subselect === null) { + if (func.length > 2) { + throw new Error("pseudo-selector :".concat(name, " requires an argument")); + } + } + else if (func.length === 2) { + throw new Error("pseudo-selector :".concat(name, " doesn't have any arguments")); + } +} +exports.verifyPseudoArgs = verifyPseudoArgs; |