Deployed the page to Github Pages.
This commit is contained in:
parent
1d79754e93
commit
2c89899458
62797 changed files with 6551425 additions and 15279 deletions
142
node_modules/domutils/lib/helpers.js
generated
vendored
Normal file
142
node_modules/domutils/lib/helpers.js
generated
vendored
Normal file
|
@ -0,0 +1,142 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniqueSort = exports.compareDocumentPosition = exports.DocumentPosition = exports.removeSubsets = void 0;
|
||||
var domhandler_1 = require("domhandler");
|
||||
/**
|
||||
* Given an array of nodes, remove any member that is contained by another
|
||||
* member.
|
||||
*
|
||||
* @category Helpers
|
||||
* @param nodes Nodes to filter.
|
||||
* @returns Remaining nodes that aren't contained by other nodes.
|
||||
*/
|
||||
function removeSubsets(nodes) {
|
||||
var idx = nodes.length;
|
||||
/*
|
||||
* Check if each node (or one of its ancestors) is already contained in the
|
||||
* array.
|
||||
*/
|
||||
while (--idx >= 0) {
|
||||
var node = nodes[idx];
|
||||
/*
|
||||
* Remove the node if it is not unique.
|
||||
* We are going through the array from the end, so we only
|
||||
* have to check nodes that preceed the node under consideration in the array.
|
||||
*/
|
||||
if (idx > 0 && nodes.lastIndexOf(node, idx - 1) >= 0) {
|
||||
nodes.splice(idx, 1);
|
||||
continue;
|
||||
}
|
||||
for (var ancestor = node.parent; ancestor; ancestor = ancestor.parent) {
|
||||
if (nodes.includes(ancestor)) {
|
||||
nodes.splice(idx, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
exports.removeSubsets = removeSubsets;
|
||||
/**
|
||||
* @category Helpers
|
||||
* @see {@link http://dom.spec.whatwg.org/#dom-node-comparedocumentposition}
|
||||
*/
|
||||
var DocumentPosition;
|
||||
(function (DocumentPosition) {
|
||||
DocumentPosition[DocumentPosition["DISCONNECTED"] = 1] = "DISCONNECTED";
|
||||
DocumentPosition[DocumentPosition["PRECEDING"] = 2] = "PRECEDING";
|
||||
DocumentPosition[DocumentPosition["FOLLOWING"] = 4] = "FOLLOWING";
|
||||
DocumentPosition[DocumentPosition["CONTAINS"] = 8] = "CONTAINS";
|
||||
DocumentPosition[DocumentPosition["CONTAINED_BY"] = 16] = "CONTAINED_BY";
|
||||
})(DocumentPosition = exports.DocumentPosition || (exports.DocumentPosition = {}));
|
||||
/**
|
||||
* Compare the position of one node against another node in any other document,
|
||||
* returning a bitmask with the values from {@link DocumentPosition}.
|
||||
*
|
||||
* Document order:
|
||||
* > There is an ordering, document order, defined on all the nodes in the
|
||||
* > document corresponding to the order in which the first character of the
|
||||
* > XML representation of each node occurs in the XML representation of the
|
||||
* > document after expansion of general entities. Thus, the document element
|
||||
* > node will be the first node. Element nodes occur before their children.
|
||||
* > Thus, document order orders element nodes in order of the occurrence of
|
||||
* > their start-tag in the XML (after expansion of entities). The attribute
|
||||
* > nodes of an element occur after the element and before its children. The
|
||||
* > relative order of attribute nodes is implementation-dependent.
|
||||
*
|
||||
* Source:
|
||||
* http://www.w3.org/TR/DOM-Level-3-Core/glossary.html#dt-document-order
|
||||
*
|
||||
* @category Helpers
|
||||
* @param nodeA The first node to use in the comparison
|
||||
* @param nodeB The second node to use in the comparison
|
||||
* @returns A bitmask describing the input nodes' relative position.
|
||||
*
|
||||
* See http://dom.spec.whatwg.org/#dom-node-comparedocumentposition for
|
||||
* a description of these values.
|
||||
*/
|
||||
function compareDocumentPosition(nodeA, nodeB) {
|
||||
var aParents = [];
|
||||
var bParents = [];
|
||||
if (nodeA === nodeB) {
|
||||
return 0;
|
||||
}
|
||||
var current = (0, domhandler_1.hasChildren)(nodeA) ? nodeA : nodeA.parent;
|
||||
while (current) {
|
||||
aParents.unshift(current);
|
||||
current = current.parent;
|
||||
}
|
||||
current = (0, domhandler_1.hasChildren)(nodeB) ? nodeB : nodeB.parent;
|
||||
while (current) {
|
||||
bParents.unshift(current);
|
||||
current = current.parent;
|
||||
}
|
||||
var maxIdx = Math.min(aParents.length, bParents.length);
|
||||
var idx = 0;
|
||||
while (idx < maxIdx && aParents[idx] === bParents[idx]) {
|
||||
idx++;
|
||||
}
|
||||
if (idx === 0) {
|
||||
return DocumentPosition.DISCONNECTED;
|
||||
}
|
||||
var sharedParent = aParents[idx - 1];
|
||||
var siblings = sharedParent.children;
|
||||
var aSibling = aParents[idx];
|
||||
var bSibling = bParents[idx];
|
||||
if (siblings.indexOf(aSibling) > siblings.indexOf(bSibling)) {
|
||||
if (sharedParent === nodeB) {
|
||||
return DocumentPosition.FOLLOWING | DocumentPosition.CONTAINED_BY;
|
||||
}
|
||||
return DocumentPosition.FOLLOWING;
|
||||
}
|
||||
if (sharedParent === nodeA) {
|
||||
return DocumentPosition.PRECEDING | DocumentPosition.CONTAINS;
|
||||
}
|
||||
return DocumentPosition.PRECEDING;
|
||||
}
|
||||
exports.compareDocumentPosition = compareDocumentPosition;
|
||||
/**
|
||||
* Sort an array of nodes based on their relative position in the document,
|
||||
* removing any duplicate nodes. If the array contains nodes that do not belong
|
||||
* to the same document, sort order is unspecified.
|
||||
*
|
||||
* @category Helpers
|
||||
* @param nodes Array of DOM nodes.
|
||||
* @returns Collection of unique nodes, sorted in document order.
|
||||
*/
|
||||
function uniqueSort(nodes) {
|
||||
nodes = nodes.filter(function (node, i, arr) { return !arr.includes(node, i + 1); });
|
||||
nodes.sort(function (a, b) {
|
||||
var relative = compareDocumentPosition(a, b);
|
||||
if (relative & DocumentPosition.PRECEDING) {
|
||||
return -1;
|
||||
}
|
||||
else if (relative & DocumentPosition.FOLLOWING) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
return nodes;
|
||||
}
|
||||
exports.uniqueSort = uniqueSort;
|
||||
//# sourceMappingURL=helpers.js.map
|
153
node_modules/domutils/lib/legacy.js
generated
vendored
Normal file
153
node_modules/domutils/lib/legacy.js
generated
vendored
Normal file
|
@ -0,0 +1,153 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getElementsByTagType = exports.getElementsByTagName = exports.getElementById = exports.getElements = exports.testElement = void 0;
|
||||
var domhandler_1 = require("domhandler");
|
||||
var querying_js_1 = require("./querying.js");
|
||||
/**
|
||||
* A map of functions to check nodes against.
|
||||
*/
|
||||
var Checks = {
|
||||
tag_name: function (name) {
|
||||
if (typeof name === "function") {
|
||||
return function (elem) { return (0, domhandler_1.isTag)(elem) && name(elem.name); };
|
||||
}
|
||||
else if (name === "*") {
|
||||
return domhandler_1.isTag;
|
||||
}
|
||||
return function (elem) { return (0, domhandler_1.isTag)(elem) && elem.name === name; };
|
||||
},
|
||||
tag_type: function (type) {
|
||||
if (typeof type === "function") {
|
||||
return function (elem) { return type(elem.type); };
|
||||
}
|
||||
return function (elem) { return elem.type === type; };
|
||||
},
|
||||
tag_contains: function (data) {
|
||||
if (typeof data === "function") {
|
||||
return function (elem) { return (0, domhandler_1.isText)(elem) && data(elem.data); };
|
||||
}
|
||||
return function (elem) { return (0, domhandler_1.isText)(elem) && elem.data === data; };
|
||||
},
|
||||
};
|
||||
/**
|
||||
* Returns a function to check whether a node has an attribute with a particular
|
||||
* value.
|
||||
*
|
||||
* @param attrib Attribute to check.
|
||||
* @param value Attribute value to look for.
|
||||
* @returns A function to check whether the a node has an attribute with a
|
||||
* particular value.
|
||||
*/
|
||||
function getAttribCheck(attrib, value) {
|
||||
if (typeof value === "function") {
|
||||
return function (elem) { return (0, domhandler_1.isTag)(elem) && value(elem.attribs[attrib]); };
|
||||
}
|
||||
return function (elem) { return (0, domhandler_1.isTag)(elem) && elem.attribs[attrib] === value; };
|
||||
}
|
||||
/**
|
||||
* Returns a function that returns `true` if either of the input functions
|
||||
* returns `true` for a node.
|
||||
*
|
||||
* @param a First function to combine.
|
||||
* @param b Second function to combine.
|
||||
* @returns A function taking a node and returning `true` if either of the input
|
||||
* functions returns `true` for the node.
|
||||
*/
|
||||
function combineFuncs(a, b) {
|
||||
return function (elem) { return a(elem) || b(elem); };
|
||||
}
|
||||
/**
|
||||
* Returns a function that executes all checks in `options` and returns `true`
|
||||
* if any of them match a node.
|
||||
*
|
||||
* @param options An object describing nodes to look for.
|
||||
* @returns A function that executes all checks in `options` and returns `true`
|
||||
* if any of them match a node.
|
||||
*/
|
||||
function compileTest(options) {
|
||||
var funcs = Object.keys(options).map(function (key) {
|
||||
var value = options[key];
|
||||
return Object.prototype.hasOwnProperty.call(Checks, key)
|
||||
? Checks[key](value)
|
||||
: getAttribCheck(key, value);
|
||||
});
|
||||
return funcs.length === 0 ? null : funcs.reduce(combineFuncs);
|
||||
}
|
||||
/**
|
||||
* Checks whether a node matches the description in `options`.
|
||||
*
|
||||
* @category Legacy Query Functions
|
||||
* @param options An object describing nodes to look for.
|
||||
* @param node The element to test.
|
||||
* @returns Whether the element matches the description in `options`.
|
||||
*/
|
||||
function testElement(options, node) {
|
||||
var test = compileTest(options);
|
||||
return test ? test(node) : true;
|
||||
}
|
||||
exports.testElement = testElement;
|
||||
/**
|
||||
* Returns all nodes that match `options`.
|
||||
*
|
||||
* @category Legacy Query Functions
|
||||
* @param options An object describing nodes to look for.
|
||||
* @param nodes Nodes to search through.
|
||||
* @param recurse Also consider child nodes.
|
||||
* @param limit Maximum number of nodes to return.
|
||||
* @returns All nodes that match `options`.
|
||||
*/
|
||||
function getElements(options, nodes, recurse, limit) {
|
||||
if (limit === void 0) { limit = Infinity; }
|
||||
var test = compileTest(options);
|
||||
return test ? (0, querying_js_1.filter)(test, nodes, recurse, limit) : [];
|
||||
}
|
||||
exports.getElements = getElements;
|
||||
/**
|
||||
* Returns the node with the supplied ID.
|
||||
*
|
||||
* @category Legacy Query Functions
|
||||
* @param id The unique ID attribute value to look for.
|
||||
* @param nodes Nodes to search through.
|
||||
* @param recurse Also consider child nodes.
|
||||
* @returns The node with the supplied ID.
|
||||
*/
|
||||
function getElementById(id, nodes, recurse) {
|
||||
if (recurse === void 0) { recurse = true; }
|
||||
if (!Array.isArray(nodes))
|
||||
nodes = [nodes];
|
||||
return (0, querying_js_1.findOne)(getAttribCheck("id", id), nodes, recurse);
|
||||
}
|
||||
exports.getElementById = getElementById;
|
||||
/**
|
||||
* Returns all nodes with the supplied `tagName`.
|
||||
*
|
||||
* @category Legacy Query Functions
|
||||
* @param tagName Tag name to search for.
|
||||
* @param nodes Nodes to search through.
|
||||
* @param recurse Also consider child nodes.
|
||||
* @param limit Maximum number of nodes to return.
|
||||
* @returns All nodes with the supplied `tagName`.
|
||||
*/
|
||||
function getElementsByTagName(tagName, nodes, recurse, limit) {
|
||||
if (recurse === void 0) { recurse = true; }
|
||||
if (limit === void 0) { limit = Infinity; }
|
||||
return (0, querying_js_1.filter)(Checks["tag_name"](tagName), nodes, recurse, limit);
|
||||
}
|
||||
exports.getElementsByTagName = getElementsByTagName;
|
||||
/**
|
||||
* Returns all nodes with the supplied `type`.
|
||||
*
|
||||
* @category Legacy Query Functions
|
||||
* @param type Element type to look for.
|
||||
* @param nodes Nodes to search through.
|
||||
* @param recurse Also consider child nodes.
|
||||
* @param limit Maximum number of nodes to return.
|
||||
* @returns All nodes with the supplied `type`.
|
||||
*/
|
||||
function getElementsByTagType(type, nodes, recurse, limit) {
|
||||
if (recurse === void 0) { recurse = true; }
|
||||
if (limit === void 0) { limit = Infinity; }
|
||||
return (0, querying_js_1.filter)(Checks["tag_type"](type), nodes, recurse, limit);
|
||||
}
|
||||
exports.getElementsByTagType = getElementsByTagType;
|
||||
//# sourceMappingURL=legacy.js.map
|
143
node_modules/domutils/lib/manipulation.js
generated
vendored
Normal file
143
node_modules/domutils/lib/manipulation.js
generated
vendored
Normal file
|
@ -0,0 +1,143 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.prepend = exports.prependChild = exports.append = exports.appendChild = exports.replaceElement = exports.removeElement = void 0;
|
||||
/**
|
||||
* Remove an element from the dom
|
||||
*
|
||||
* @category Manipulation
|
||||
* @param elem The element to be removed
|
||||
*/
|
||||
function removeElement(elem) {
|
||||
if (elem.prev)
|
||||
elem.prev.next = elem.next;
|
||||
if (elem.next)
|
||||
elem.next.prev = elem.prev;
|
||||
if (elem.parent) {
|
||||
var childs = elem.parent.children;
|
||||
var childsIndex = childs.lastIndexOf(elem);
|
||||
if (childsIndex >= 0) {
|
||||
childs.splice(childsIndex, 1);
|
||||
}
|
||||
}
|
||||
elem.next = null;
|
||||
elem.prev = null;
|
||||
elem.parent = null;
|
||||
}
|
||||
exports.removeElement = removeElement;
|
||||
/**
|
||||
* Replace an element in the dom
|
||||
*
|
||||
* @category Manipulation
|
||||
* @param elem The element to be replaced
|
||||
* @param replacement The element to be added
|
||||
*/
|
||||
function replaceElement(elem, replacement) {
|
||||
var prev = (replacement.prev = elem.prev);
|
||||
if (prev) {
|
||||
prev.next = replacement;
|
||||
}
|
||||
var next = (replacement.next = elem.next);
|
||||
if (next) {
|
||||
next.prev = replacement;
|
||||
}
|
||||
var parent = (replacement.parent = elem.parent);
|
||||
if (parent) {
|
||||
var childs = parent.children;
|
||||
childs[childs.lastIndexOf(elem)] = replacement;
|
||||
elem.parent = null;
|
||||
}
|
||||
}
|
||||
exports.replaceElement = replaceElement;
|
||||
/**
|
||||
* Append a child to an element.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @param parent The element to append to.
|
||||
* @param child The element to be added as a child.
|
||||
*/
|
||||
function appendChild(parent, child) {
|
||||
removeElement(child);
|
||||
child.next = null;
|
||||
child.parent = parent;
|
||||
if (parent.children.push(child) > 1) {
|
||||
var sibling = parent.children[parent.children.length - 2];
|
||||
sibling.next = child;
|
||||
child.prev = sibling;
|
||||
}
|
||||
else {
|
||||
child.prev = null;
|
||||
}
|
||||
}
|
||||
exports.appendChild = appendChild;
|
||||
/**
|
||||
* Append an element after another.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @param elem The element to append after.
|
||||
* @param next The element be added.
|
||||
*/
|
||||
function append(elem, next) {
|
||||
removeElement(next);
|
||||
var parent = elem.parent;
|
||||
var currNext = elem.next;
|
||||
next.next = currNext;
|
||||
next.prev = elem;
|
||||
elem.next = next;
|
||||
next.parent = parent;
|
||||
if (currNext) {
|
||||
currNext.prev = next;
|
||||
if (parent) {
|
||||
var childs = parent.children;
|
||||
childs.splice(childs.lastIndexOf(currNext), 0, next);
|
||||
}
|
||||
}
|
||||
else if (parent) {
|
||||
parent.children.push(next);
|
||||
}
|
||||
}
|
||||
exports.append = append;
|
||||
/**
|
||||
* Prepend a child to an element.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @param parent The element to prepend before.
|
||||
* @param child The element to be added as a child.
|
||||
*/
|
||||
function prependChild(parent, child) {
|
||||
removeElement(child);
|
||||
child.parent = parent;
|
||||
child.prev = null;
|
||||
if (parent.children.unshift(child) !== 1) {
|
||||
var sibling = parent.children[1];
|
||||
sibling.prev = child;
|
||||
child.next = sibling;
|
||||
}
|
||||
else {
|
||||
child.next = null;
|
||||
}
|
||||
}
|
||||
exports.prependChild = prependChild;
|
||||
/**
|
||||
* Prepend an element before another.
|
||||
*
|
||||
* @category Manipulation
|
||||
* @param elem The element to prepend before.
|
||||
* @param prev The element be added.
|
||||
*/
|
||||
function prepend(elem, prev) {
|
||||
removeElement(prev);
|
||||
var parent = elem.parent;
|
||||
if (parent) {
|
||||
var childs = parent.children;
|
||||
childs.splice(childs.indexOf(elem), 0, prev);
|
||||
}
|
||||
if (elem.prev) {
|
||||
elem.prev.next = prev;
|
||||
}
|
||||
prev.parent = parent;
|
||||
prev.prev = elem.prev;
|
||||
prev.next = elem;
|
||||
elem.prev = prev;
|
||||
}
|
||||
exports.prepend = prepend;
|
||||
//# sourceMappingURL=manipulation.js.map
|
159
node_modules/domutils/lib/querying.js
generated
vendored
Normal file
159
node_modules/domutils/lib/querying.js
generated
vendored
Normal file
|
@ -0,0 +1,159 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.findAll = exports.existsOne = exports.findOne = exports.findOneChild = exports.find = exports.filter = void 0;
|
||||
var domhandler_1 = require("domhandler");
|
||||
/**
|
||||
* Search a node and its children for nodes passing a test function. If `node` is not an array, it will be wrapped in one.
|
||||
*
|
||||
* @category Querying
|
||||
* @param test Function to test nodes on.
|
||||
* @param node Node to search. Will be included in the result set if it matches.
|
||||
* @param recurse Also consider child nodes.
|
||||
* @param limit Maximum number of nodes to return.
|
||||
* @returns All nodes passing `test`.
|
||||
*/
|
||||
function filter(test, node, recurse, limit) {
|
||||
if (recurse === void 0) { recurse = true; }
|
||||
if (limit === void 0) { limit = Infinity; }
|
||||
return find(test, Array.isArray(node) ? node : [node], recurse, limit);
|
||||
}
|
||||
exports.filter = filter;
|
||||
/**
|
||||
* Search an array of nodes and their children for nodes passing a test function.
|
||||
*
|
||||
* @category Querying
|
||||
* @param test Function to test nodes on.
|
||||
* @param nodes Array of nodes to search.
|
||||
* @param recurse Also consider child nodes.
|
||||
* @param limit Maximum number of nodes to return.
|
||||
* @returns All nodes passing `test`.
|
||||
*/
|
||||
function find(test, nodes, recurse, limit) {
|
||||
var result = [];
|
||||
/** Stack of the arrays we are looking at. */
|
||||
var nodeStack = [nodes];
|
||||
/** Stack of the indices within the arrays. */
|
||||
var indexStack = [0];
|
||||
for (;;) {
|
||||
// First, check if the current array has any more elements to look at.
|
||||
if (indexStack[0] >= nodeStack[0].length) {
|
||||
// If we have no more arrays to look at, we are done.
|
||||
if (indexStack.length === 1) {
|
||||
return result;
|
||||
}
|
||||
// Otherwise, remove the current array from the stack.
|
||||
nodeStack.shift();
|
||||
indexStack.shift();
|
||||
// Loop back to the start to continue with the next array.
|
||||
continue;
|
||||
}
|
||||
var elem = nodeStack[0][indexStack[0]++];
|
||||
if (test(elem)) {
|
||||
result.push(elem);
|
||||
if (--limit <= 0)
|
||||
return result;
|
||||
}
|
||||
if (recurse && (0, domhandler_1.hasChildren)(elem) && elem.children.length > 0) {
|
||||
/*
|
||||
* Add the children to the stack. We are depth-first, so this is
|
||||
* the next array we look at.
|
||||
*/
|
||||
indexStack.unshift(0);
|
||||
nodeStack.unshift(elem.children);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.find = find;
|
||||
/**
|
||||
* Finds the first element inside of an array that matches a test function. This is an alias for `Array.prototype.find`.
|
||||
*
|
||||
* @category Querying
|
||||
* @param test Function to test nodes on.
|
||||
* @param nodes Array of nodes to search.
|
||||
* @returns The first node in the array that passes `test`.
|
||||
* @deprecated Use `Array.prototype.find` directly.
|
||||
*/
|
||||
function findOneChild(test, nodes) {
|
||||
return nodes.find(test);
|
||||
}
|
||||
exports.findOneChild = findOneChild;
|
||||
/**
|
||||
* Finds one element in a tree that passes a test.
|
||||
*
|
||||
* @category Querying
|
||||
* @param test Function to test nodes on.
|
||||
* @param nodes Node or array of nodes to search.
|
||||
* @param recurse Also consider child nodes.
|
||||
* @returns The first node that passes `test`.
|
||||
*/
|
||||
function findOne(test, nodes, recurse) {
|
||||
if (recurse === void 0) { recurse = true; }
|
||||
var elem = null;
|
||||
for (var i = 0; i < nodes.length && !elem; i++) {
|
||||
var node = nodes[i];
|
||||
if (!(0, domhandler_1.isTag)(node)) {
|
||||
continue;
|
||||
}
|
||||
else if (test(node)) {
|
||||
elem = node;
|
||||
}
|
||||
else if (recurse && node.children.length > 0) {
|
||||
elem = findOne(test, node.children, true);
|
||||
}
|
||||
}
|
||||
return elem;
|
||||
}
|
||||
exports.findOne = findOne;
|
||||
/**
|
||||
* Checks if a tree of nodes contains at least one node passing a test.
|
||||
*
|
||||
* @category Querying
|
||||
* @param test Function to test nodes on.
|
||||
* @param nodes Array of nodes to search.
|
||||
* @returns Whether a tree of nodes contains at least one node passing the test.
|
||||
*/
|
||||
function existsOne(test, nodes) {
|
||||
return nodes.some(function (checked) {
|
||||
return (0, domhandler_1.isTag)(checked) &&
|
||||
(test(checked) || existsOne(test, checked.children));
|
||||
});
|
||||
}
|
||||
exports.existsOne = existsOne;
|
||||
/**
|
||||
* Search an array of nodes and their children for elements passing a test function.
|
||||
*
|
||||
* Same as `find`, but limited to elements and with less options, leading to reduced complexity.
|
||||
*
|
||||
* @category Querying
|
||||
* @param test Function to test nodes on.
|
||||
* @param nodes Array of nodes to search.
|
||||
* @returns All nodes passing `test`.
|
||||
*/
|
||||
function findAll(test, nodes) {
|
||||
var result = [];
|
||||
var nodeStack = [nodes];
|
||||
var indexStack = [0];
|
||||
for (;;) {
|
||||
if (indexStack[0] >= nodeStack[0].length) {
|
||||
if (nodeStack.length === 1) {
|
||||
return result;
|
||||
}
|
||||
// Otherwise, remove the current array from the stack.
|
||||
nodeStack.shift();
|
||||
indexStack.shift();
|
||||
// Loop back to the start to continue with the next array.
|
||||
continue;
|
||||
}
|
||||
var elem = nodeStack[0][indexStack[0]++];
|
||||
if (!(0, domhandler_1.isTag)(elem))
|
||||
continue;
|
||||
if (test(elem))
|
||||
result.push(elem);
|
||||
if (elem.children.length > 0) {
|
||||
indexStack.unshift(0);
|
||||
nodeStack.unshift(elem.children);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.findAll = findAll;
|
||||
//# sourceMappingURL=querying.js.map
|
92
node_modules/domutils/lib/stringify.js
generated
vendored
Normal file
92
node_modules/domutils/lib/stringify.js
generated
vendored
Normal file
|
@ -0,0 +1,92 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.innerText = exports.textContent = exports.getText = exports.getInnerHTML = exports.getOuterHTML = void 0;
|
||||
var domhandler_1 = require("domhandler");
|
||||
var dom_serializer_1 = __importDefault(require("dom-serializer"));
|
||||
var domelementtype_1 = require("domelementtype");
|
||||
/**
|
||||
* @category Stringify
|
||||
* @deprecated Use the `dom-serializer` module directly.
|
||||
* @param node Node to get the outer HTML of.
|
||||
* @param options Options for serialization.
|
||||
* @returns `node`'s outer HTML.
|
||||
*/
|
||||
function getOuterHTML(node, options) {
|
||||
return (0, dom_serializer_1.default)(node, options);
|
||||
}
|
||||
exports.getOuterHTML = getOuterHTML;
|
||||
/**
|
||||
* @category Stringify
|
||||
* @deprecated Use the `dom-serializer` module directly.
|
||||
* @param node Node to get the inner HTML of.
|
||||
* @param options Options for serialization.
|
||||
* @returns `node`'s inner HTML.
|
||||
*/
|
||||
function getInnerHTML(node, options) {
|
||||
return (0, domhandler_1.hasChildren)(node)
|
||||
? node.children.map(function (node) { return getOuterHTML(node, options); }).join("")
|
||||
: "";
|
||||
}
|
||||
exports.getInnerHTML = getInnerHTML;
|
||||
/**
|
||||
* Get a node's inner text. Same as `textContent`, but inserts newlines for `<br>` tags. Ignores comments.
|
||||
*
|
||||
* @category Stringify
|
||||
* @deprecated Use `textContent` instead.
|
||||
* @param node Node to get the inner text of.
|
||||
* @returns `node`'s inner text.
|
||||
*/
|
||||
function getText(node) {
|
||||
if (Array.isArray(node))
|
||||
return node.map(getText).join("");
|
||||
if ((0, domhandler_1.isTag)(node))
|
||||
return node.name === "br" ? "\n" : getText(node.children);
|
||||
if ((0, domhandler_1.isCDATA)(node))
|
||||
return getText(node.children);
|
||||
if ((0, domhandler_1.isText)(node))
|
||||
return node.data;
|
||||
return "";
|
||||
}
|
||||
exports.getText = getText;
|
||||
/**
|
||||
* Get a node's text content. Ignores comments.
|
||||
*
|
||||
* @category Stringify
|
||||
* @param node Node to get the text content of.
|
||||
* @returns `node`'s text content.
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent}
|
||||
*/
|
||||
function textContent(node) {
|
||||
if (Array.isArray(node))
|
||||
return node.map(textContent).join("");
|
||||
if ((0, domhandler_1.hasChildren)(node) && !(0, domhandler_1.isComment)(node)) {
|
||||
return textContent(node.children);
|
||||
}
|
||||
if ((0, domhandler_1.isText)(node))
|
||||
return node.data;
|
||||
return "";
|
||||
}
|
||||
exports.textContent = textContent;
|
||||
/**
|
||||
* Get a node's inner text, ignoring `<script>` and `<style>` tags. Ignores comments.
|
||||
*
|
||||
* @category Stringify
|
||||
* @param node Node to get the inner text of.
|
||||
* @returns `node`'s inner text.
|
||||
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Node/innerText}
|
||||
*/
|
||||
function innerText(node) {
|
||||
if (Array.isArray(node))
|
||||
return node.map(innerText).join("");
|
||||
if ((0, domhandler_1.hasChildren)(node) && (node.type === domelementtype_1.ElementType.Tag || (0, domhandler_1.isCDATA)(node))) {
|
||||
return innerText(node.children);
|
||||
}
|
||||
if ((0, domhandler_1.isText)(node))
|
||||
return node.data;
|
||||
return "";
|
||||
}
|
||||
exports.innerText = innerText;
|
||||
//# sourceMappingURL=stringify.js.map
|
126
node_modules/domutils/lib/traversal.js
generated
vendored
Normal file
126
node_modules/domutils/lib/traversal.js
generated
vendored
Normal file
|
@ -0,0 +1,126 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.prevElementSibling = exports.nextElementSibling = exports.getName = exports.hasAttrib = exports.getAttributeValue = exports.getSiblings = exports.getParent = exports.getChildren = void 0;
|
||||
var domhandler_1 = require("domhandler");
|
||||
/**
|
||||
* Get a node's children.
|
||||
*
|
||||
* @category Traversal
|
||||
* @param elem Node to get the children of.
|
||||
* @returns `elem`'s children, or an empty array.
|
||||
*/
|
||||
function getChildren(elem) {
|
||||
return (0, domhandler_1.hasChildren)(elem) ? elem.children : [];
|
||||
}
|
||||
exports.getChildren = getChildren;
|
||||
/**
|
||||
* Get a node's parent.
|
||||
*
|
||||
* @category Traversal
|
||||
* @param elem Node to get the parent of.
|
||||
* @returns `elem`'s parent node, or `null` if `elem` is a root node.
|
||||
*/
|
||||
function getParent(elem) {
|
||||
return elem.parent || null;
|
||||
}
|
||||
exports.getParent = getParent;
|
||||
/**
|
||||
* Gets an elements siblings, including the element itself.
|
||||
*
|
||||
* Attempts to get the children through the element's parent first. If we don't
|
||||
* have a parent (the element is a root node), we walk the element's `prev` &
|
||||
* `next` to get all remaining nodes.
|
||||
*
|
||||
* @category Traversal
|
||||
* @param elem Element to get the siblings of.
|
||||
* @returns `elem`'s siblings, including `elem`.
|
||||
*/
|
||||
function getSiblings(elem) {
|
||||
var _a, _b;
|
||||
var parent = getParent(elem);
|
||||
if (parent != null)
|
||||
return getChildren(parent);
|
||||
var siblings = [elem];
|
||||
var prev = elem.prev, next = elem.next;
|
||||
while (prev != null) {
|
||||
siblings.unshift(prev);
|
||||
(_a = prev, prev = _a.prev);
|
||||
}
|
||||
while (next != null) {
|
||||
siblings.push(next);
|
||||
(_b = next, next = _b.next);
|
||||
}
|
||||
return siblings;
|
||||
}
|
||||
exports.getSiblings = getSiblings;
|
||||
/**
|
||||
* Gets an attribute from an element.
|
||||
*
|
||||
* @category Traversal
|
||||
* @param elem Element to check.
|
||||
* @param name Attribute name to retrieve.
|
||||
* @returns The element's attribute value, or `undefined`.
|
||||
*/
|
||||
function getAttributeValue(elem, name) {
|
||||
var _a;
|
||||
return (_a = elem.attribs) === null || _a === void 0 ? void 0 : _a[name];
|
||||
}
|
||||
exports.getAttributeValue = getAttributeValue;
|
||||
/**
|
||||
* Checks whether an element has an attribute.
|
||||
*
|
||||
* @category Traversal
|
||||
* @param elem Element to check.
|
||||
* @param name Attribute name to look for.
|
||||
* @returns Returns whether `elem` has the attribute `name`.
|
||||
*/
|
||||
function hasAttrib(elem, name) {
|
||||
return (elem.attribs != null &&
|
||||
Object.prototype.hasOwnProperty.call(elem.attribs, name) &&
|
||||
elem.attribs[name] != null);
|
||||
}
|
||||
exports.hasAttrib = hasAttrib;
|
||||
/**
|
||||
* Get the tag name of an element.
|
||||
*
|
||||
* @category Traversal
|
||||
* @param elem The element to get the name for.
|
||||
* @returns The tag name of `elem`.
|
||||
*/
|
||||
function getName(elem) {
|
||||
return elem.name;
|
||||
}
|
||||
exports.getName = getName;
|
||||
/**
|
||||
* Returns the next element sibling of a node.
|
||||
*
|
||||
* @category Traversal
|
||||
* @param elem The element to get the next sibling of.
|
||||
* @returns `elem`'s next sibling that is a tag, or `null` if there is no next
|
||||
* sibling.
|
||||
*/
|
||||
function nextElementSibling(elem) {
|
||||
var _a;
|
||||
var next = elem.next;
|
||||
while (next !== null && !(0, domhandler_1.isTag)(next))
|
||||
(_a = next, next = _a.next);
|
||||
return next;
|
||||
}
|
||||
exports.nextElementSibling = nextElementSibling;
|
||||
/**
|
||||
* Returns the previous element sibling of a node.
|
||||
*
|
||||
* @category Traversal
|
||||
* @param elem The element to get the previous sibling of.
|
||||
* @returns `elem`'s previous sibling that is a tag, or `null` if there is no
|
||||
* previous sibling.
|
||||
*/
|
||||
function prevElementSibling(elem) {
|
||||
var _a;
|
||||
var prev = elem.prev;
|
||||
while (prev !== null && !(0, domhandler_1.isTag)(prev))
|
||||
(_a = prev, prev = _a.prev);
|
||||
return prev;
|
||||
}
|
||||
exports.prevElementSibling = prevElementSibling;
|
||||
//# sourceMappingURL=traversal.js.map
|
Loading…
Add table
Add a link
Reference in a new issue