first commit
This commit is contained in:
33
node_modules/@selderee/plugin-htmlparser2/CHANGELOG.md
generated
vendored
Normal file
33
node_modules/@selderee/plugin-htmlparser2/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# Changelog
|
||||
|
||||
## Version 0.11.0
|
||||
|
||||
* (`selderee`) Escape sequences in selectors.
|
||||
|
||||
## Version 0.10.0
|
||||
|
||||
* Targeting Node.js version 14 and ES2020;
|
||||
* Bump dependencies.
|
||||
|
||||
## Version 0.9.0
|
||||
|
||||
* Bump dependencies - fix "./core module cannot be found" issue.
|
||||
|
||||
## Version 0.8.1
|
||||
|
||||
* Sync with `selderee` package version. Now all dependencies are TypeScript, dual CommonJS/ES module packages;
|
||||
* Use `rollup-plugin-cleanup` to condition published files.
|
||||
|
||||
## Version 0.7.0
|
||||
|
||||
* Drop Node.js version 10 support. At least 12.22.x is required.
|
||||
|
||||
## Version 0.6.0
|
||||
|
||||
* `selderee` 0.6.0 - [changelog](https://github.com/mxxii/selderee/blob/main/packages/selderee/CHANGELOG.md).
|
||||
|
||||
## Version 0.5.0
|
||||
|
||||
Initial release.
|
||||
|
||||
Aiming at Node.js version 10 and up.
|
21
node_modules/@selderee/plugin-htmlparser2/LICENSE
generated
vendored
Normal file
21
node_modules/@selderee/plugin-htmlparser2/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021-2022 KillyMXI <killy@mxii.eu.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
15
node_modules/@selderee/plugin-htmlparser2/README.md
generated
vendored
Normal file
15
node_modules/@selderee/plugin-htmlparser2/README.md
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# selderee
|
||||
|
||||

|
||||

|
||||
[](https://github.com/mxxii/selderee/blob/main/LICENSE)
|
||||
|
||||
[selderee](https://github.com/mxxii/selderee) plugin - selectors decision tree builder for [htmlparser2](https://github.com/fb55/htmlparser2) DOM AST.
|
||||
|
||||
(Technically, the package depends not on `htmlparser2` but on [domhandler](https://github.com/fb55/domhandler), underlying package of `htmlparser2`.)
|
||||
|
||||
----
|
||||
|
||||
[Changelog](https://github.com/mxxii/selderee/blob/main/packages/plugin-htmlparser2/CHANGELOG.md).
|
||||
|
||||
See [main README file](https://github.com/mxxii/selderee/blob/main/README.md) for more info.
|
94
node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.cjs
generated
vendored
Normal file
94
node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.cjs
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var domhandler = require('domhandler');
|
||||
var selderee = require('selderee');
|
||||
|
||||
function hp2Builder(nodes) {
|
||||
return new selderee.Picker(handleArray(nodes));
|
||||
}
|
||||
function handleArray(nodes) {
|
||||
const matchers = nodes.map(handleNode);
|
||||
return (el, ...tail) => matchers.flatMap(m => m(el, ...tail));
|
||||
}
|
||||
function handleNode(node) {
|
||||
switch (node.type) {
|
||||
case 'terminal': {
|
||||
const result = [node.valueContainer];
|
||||
return (el, ...tail) => result;
|
||||
}
|
||||
case 'tagName':
|
||||
return handleTagName(node);
|
||||
case 'attrValue':
|
||||
return handleAttrValueName(node);
|
||||
case 'attrPresence':
|
||||
return handleAttrPresenceName(node);
|
||||
case 'pushElement':
|
||||
return handlePushElementNode(node);
|
||||
case 'popElement':
|
||||
return handlePopElementNode(node);
|
||||
}
|
||||
}
|
||||
function handleTagName(node) {
|
||||
const variants = {};
|
||||
for (const variant of node.variants) {
|
||||
variants[variant.value] = handleArray(variant.cont);
|
||||
}
|
||||
return (el, ...tail) => {
|
||||
const continuation = variants[el.name];
|
||||
return (continuation) ? continuation(el, ...tail) : [];
|
||||
};
|
||||
}
|
||||
function handleAttrPresenceName(node) {
|
||||
const attrName = node.name;
|
||||
const continuation = handleArray(node.cont);
|
||||
return (el, ...tail) => (Object.prototype.hasOwnProperty.call(el.attribs, attrName))
|
||||
? continuation(el, ...tail)
|
||||
: [];
|
||||
}
|
||||
function handleAttrValueName(node) {
|
||||
const callbacks = [];
|
||||
for (const matcher of node.matchers) {
|
||||
const predicate = matcher.predicate;
|
||||
const continuation = handleArray(matcher.cont);
|
||||
callbacks.push((attr, el, ...tail) => (predicate(attr) ? continuation(el, ...tail) : []));
|
||||
}
|
||||
const attrName = node.name;
|
||||
return (el, ...tail) => {
|
||||
const attr = el.attribs[attrName];
|
||||
return (attr || attr === '')
|
||||
? callbacks.flatMap(cb => cb(attr, el, ...tail))
|
||||
: [];
|
||||
};
|
||||
}
|
||||
function handlePushElementNode(node) {
|
||||
const continuation = handleArray(node.cont);
|
||||
const leftElementGetter = (node.combinator === '+')
|
||||
? getPrecedingElement
|
||||
: getParentElement;
|
||||
return (el, ...tail) => {
|
||||
const next = leftElementGetter(el);
|
||||
if (next === null) {
|
||||
return [];
|
||||
}
|
||||
return continuation(next, el, ...tail);
|
||||
};
|
||||
}
|
||||
const getPrecedingElement = (el) => {
|
||||
const prev = el.prev;
|
||||
if (prev === null) {
|
||||
return null;
|
||||
}
|
||||
return (domhandler.isTag(prev)) ? prev : getPrecedingElement(prev);
|
||||
};
|
||||
const getParentElement = (el) => {
|
||||
const parent = el.parent;
|
||||
return (parent && domhandler.isTag(parent)) ? parent : null;
|
||||
};
|
||||
function handlePopElementNode(node) {
|
||||
const continuation = handleArray(node.cont);
|
||||
return (el, next, ...tail) => continuation(next, ...tail);
|
||||
}
|
||||
|
||||
exports.hp2Builder = hp2Builder;
|
16
node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.d.ts
generated
vendored
Normal file
16
node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Element } from 'domhandler';
|
||||
import { Picker, Ast } from 'selderee';
|
||||
/**
|
||||
* A {@link BuilderFunction} implementation.
|
||||
*
|
||||
* Creates a function (in a {@link Picker} wrapper) that can run
|
||||
* the decision tree against `htmlparser2` `Element` nodes.
|
||||
*
|
||||
* @typeParam V - the type of values associated with selectors.
|
||||
*
|
||||
* @param nodes - nodes ({@link DecisionTreeNode})
|
||||
* from the root level of the decision tree.
|
||||
*
|
||||
* @returns a {@link Picker} object.
|
||||
*/
|
||||
export declare function hp2Builder<V>(nodes: Ast.DecisionTreeNode<V>[]): Picker<Element, V>;
|
90
node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.mjs
generated
vendored
Normal file
90
node_modules/@selderee/plugin-htmlparser2/lib/hp2-builder.mjs
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
import { isTag } from 'domhandler';
|
||||
import { Picker } from 'selderee';
|
||||
|
||||
function hp2Builder(nodes) {
|
||||
return new Picker(handleArray(nodes));
|
||||
}
|
||||
function handleArray(nodes) {
|
||||
const matchers = nodes.map(handleNode);
|
||||
return (el, ...tail) => matchers.flatMap(m => m(el, ...tail));
|
||||
}
|
||||
function handleNode(node) {
|
||||
switch (node.type) {
|
||||
case 'terminal': {
|
||||
const result = [node.valueContainer];
|
||||
return (el, ...tail) => result;
|
||||
}
|
||||
case 'tagName':
|
||||
return handleTagName(node);
|
||||
case 'attrValue':
|
||||
return handleAttrValueName(node);
|
||||
case 'attrPresence':
|
||||
return handleAttrPresenceName(node);
|
||||
case 'pushElement':
|
||||
return handlePushElementNode(node);
|
||||
case 'popElement':
|
||||
return handlePopElementNode(node);
|
||||
}
|
||||
}
|
||||
function handleTagName(node) {
|
||||
const variants = {};
|
||||
for (const variant of node.variants) {
|
||||
variants[variant.value] = handleArray(variant.cont);
|
||||
}
|
||||
return (el, ...tail) => {
|
||||
const continuation = variants[el.name];
|
||||
return (continuation) ? continuation(el, ...tail) : [];
|
||||
};
|
||||
}
|
||||
function handleAttrPresenceName(node) {
|
||||
const attrName = node.name;
|
||||
const continuation = handleArray(node.cont);
|
||||
return (el, ...tail) => (Object.prototype.hasOwnProperty.call(el.attribs, attrName))
|
||||
? continuation(el, ...tail)
|
||||
: [];
|
||||
}
|
||||
function handleAttrValueName(node) {
|
||||
const callbacks = [];
|
||||
for (const matcher of node.matchers) {
|
||||
const predicate = matcher.predicate;
|
||||
const continuation = handleArray(matcher.cont);
|
||||
callbacks.push((attr, el, ...tail) => (predicate(attr) ? continuation(el, ...tail) : []));
|
||||
}
|
||||
const attrName = node.name;
|
||||
return (el, ...tail) => {
|
||||
const attr = el.attribs[attrName];
|
||||
return (attr || attr === '')
|
||||
? callbacks.flatMap(cb => cb(attr, el, ...tail))
|
||||
: [];
|
||||
};
|
||||
}
|
||||
function handlePushElementNode(node) {
|
||||
const continuation = handleArray(node.cont);
|
||||
const leftElementGetter = (node.combinator === '+')
|
||||
? getPrecedingElement
|
||||
: getParentElement;
|
||||
return (el, ...tail) => {
|
||||
const next = leftElementGetter(el);
|
||||
if (next === null) {
|
||||
return [];
|
||||
}
|
||||
return continuation(next, el, ...tail);
|
||||
};
|
||||
}
|
||||
const getPrecedingElement = (el) => {
|
||||
const prev = el.prev;
|
||||
if (prev === null) {
|
||||
return null;
|
||||
}
|
||||
return (isTag(prev)) ? prev : getPrecedingElement(prev);
|
||||
};
|
||||
const getParentElement = (el) => {
|
||||
const parent = el.parent;
|
||||
return (parent && isTag(parent)) ? parent : null;
|
||||
};
|
||||
function handlePopElementNode(node) {
|
||||
const continuation = handleArray(node.cont);
|
||||
return (el, next, ...tail) => continuation(next, ...tail);
|
||||
}
|
||||
|
||||
export { hp2Builder };
|
47
node_modules/@selderee/plugin-htmlparser2/package.json
generated
vendored
Normal file
47
node_modules/@selderee/plugin-htmlparser2/package.json
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "@selderee/plugin-htmlparser2",
|
||||
"version": "0.11.0",
|
||||
"description": "selderee plugin - selectors decision tree builder for htmlparser2 DOM.",
|
||||
"keywords": [
|
||||
"htmlparser2",
|
||||
"selderee",
|
||||
"plugin",
|
||||
"selderee plugin"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/mxxii/selderee.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mxxii/selderee/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mxxii/selderee",
|
||||
"author": "KillyMXI",
|
||||
"funding": "https://ko-fi.com/killymxi",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"import": "./lib/hp2-builder.mjs",
|
||||
"require": "./lib/hp2-builder.cjs"
|
||||
},
|
||||
"type": "module",
|
||||
"main": "./lib/hp2-builder.cjs",
|
||||
"module": "./lib/hp2-builder.mjs",
|
||||
"types": "./lib/hp2-builder.d.ts",
|
||||
"typedocMain": "./src/hp2-builder.ts",
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"scripts": {
|
||||
"build:rollup": "rollup -c",
|
||||
"build:types": "tsc -d --emitDeclarationOnly --declarationDir ./lib",
|
||||
"build": "npm run clean && npm run build:rollup && npm run build:types",
|
||||
"clean": "rimraf lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"domhandler": "^5.0.3",
|
||||
"selderee": "^0.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"htmlparser2": "^8.0.1"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user