forked from daren.hsu/line_push
update
This commit is contained in:
+177
-143
@@ -1,28 +1,51 @@
|
||||
# css-select [](https://npmjs.org/package/css-select) [](http://travis-ci.org/fb55/css-select) [](https://npmjs.org/package/css-select) [](https://coveralls.io/r/fb55/css-select)
|
||||
# css-select [](https://npmjs.org/package/css-select) [](http://travis-ci.com/fb55/css-select) [](https://npmjs.org/package/css-select) [](https://coveralls.io/r/fb55/css-select)
|
||||
|
||||
a CSS selector compiler/engine
|
||||
A CSS selector compiler and engine
|
||||
|
||||
## What?
|
||||
|
||||
css-select turns CSS selectors into functions that tests if elements match them. When searching for elements, testing is executed "from the top", similar to how browsers execute CSS selectors.
|
||||
As a **compiler**, css-select turns CSS selectors into functions that tests if
|
||||
elements match them.
|
||||
|
||||
In its default configuration, css-select queries the DOM structure of the [`domhandler`](https://github.com/fb55/domhandler) module (also known as htmlparser2 DOM).
|
||||
It uses [`domutils`](https://github.com/fb55/domutils) as its default adapter over the DOM structure. See Options below for details on querying alternative DOM structures.
|
||||
As an **engine**, css-select looks through a DOM tree, searching for elements.
|
||||
Elements are tested "from the top", similar to how browsers execute CSS
|
||||
selectors.
|
||||
|
||||
__Features:__
|
||||
In its default configuration, css-select queries the DOM structure of the
|
||||
[`domhandler`](https://github.com/fb55/domhandler) module (also known as
|
||||
htmlparser2 DOM). To query alternative DOM structures, see [`Options`](#options)
|
||||
below.
|
||||
|
||||
- Full implementation of CSS3 selectors
|
||||
- Partial implementation of jQuery/Sizzle extensions
|
||||
- Very high test coverage
|
||||
- Pretty good performance
|
||||
**Features:**
|
||||
|
||||
- 🔬 Full implementation of CSS3 selectors, as well as most CSS4 selectors
|
||||
- 🧪 Partial implementation of jQuery/Sizzle extensions (see
|
||||
[cheerio-select](https://github.com/cheeriojs/cheerio-select) for the
|
||||
remaining selectors)
|
||||
- 🧑🔬 High test coverage, including the full test suites from Sizzle, Qwery and
|
||||
NWMatcher.
|
||||
- 🥼 Reliably great performance
|
||||
|
||||
## Why?
|
||||
|
||||
The traditional approach of executing CSS selectors, named left-to-right execution, is to execute every component of the selector in order, from left to right _(duh)_. The execution of the selector `a b` for example will first query for `a` elements, then search these for `b` elements. (That's the approach of eg. [`Sizzle`](https://github.com/jquery/sizzle), [`nwmatcher`](https://github.com/dperini/nwmatcher/) and [`qwery`](https://github.com/ded/qwery).)
|
||||
Most CSS engines written in JavaScript execute selectors left-to-right. That
|
||||
means thet execute every component of the selector in order, from left to right
|
||||
_(duh)_. As an example: For the selector `a b`, these engines will first query
|
||||
for `a` elements, then search these for `b` elements. (That's the approach of
|
||||
eg. [`Sizzle`](https://github.com/jquery/sizzle),
|
||||
[`nwmatcher`](https://github.com/dperini/nwmatcher/) and
|
||||
[`qwery`](https://github.com/ded/qwery).)
|
||||
|
||||
While this works, it has some downsides: Children of `a`s will be checked multiple times; first, to check if they are also `a`s, then, for every superior `a` once, if they are `b`s. Using [Big O notation](http://en.wikipedia.org/wiki/Big_O_notation), that would be `O(n^(k+1))`, where `k` is the number of descendant selectors (that's the space in the example above).
|
||||
While this works, it has some downsides: Children of `a`s will be checked
|
||||
multiple times; first, to check if they are also `a`s, then, for every superior
|
||||
`a` once, if they are `b`s. Using
|
||||
[Big O notation](http://en.wikipedia.org/wiki/Big_O_notation), that would be
|
||||
`O(n^(k+1))`, where `k` is the number of descendant selectors (that's the space
|
||||
in the example above).
|
||||
|
||||
The far more efficient approach is to first look for `b` elements, then check if they have superior `a` elements: Using big O notation again, that would be `O(n)`. That's called right-to-left execution.
|
||||
The far more efficient approach is to first look for `b` elements, then check if
|
||||
they have superior `a` elements: Using big O notation again, that would be
|
||||
`O(n)`. That's called right-to-left execution.
|
||||
|
||||
And that's what css-select does – and why it's quite performant.
|
||||
|
||||
@@ -32,25 +55,42 @@ By building a stack of functions.
|
||||
|
||||
_Wait, what?_
|
||||
|
||||
Okay, so let's suppose we want to compile the selector `a b` again, for right-to-left execution. We start by _parsing_ the selector, which means we turn the selector into an array of the building-blocks of the selector, so we can distinguish them easily. That's what the [`css-what`](https://github.com/fb55/css-what) module is for, if you want to have a look.
|
||||
Okay, so let's suppose we want to compile the selector `a b`, for right-to-left
|
||||
execution. We start by _parsing_ the selector. This turns the selector into an
|
||||
array of the building blocks. That's what the
|
||||
[`css-what`](https://github.com/fb55/css-what) module is for, if you want to
|
||||
have a look.
|
||||
|
||||
Anyway, after parsing, we end up with an array like this one:
|
||||
|
||||
```js
|
||||
[
|
||||
{ type: 'tag', name: 'a' },
|
||||
{ type: 'descendant' },
|
||||
{ type: 'tag', name: 'b' }
|
||||
]
|
||||
{ type: "tag", name: "a" },
|
||||
{ type: "descendant" },
|
||||
{ type: "tag", name: "b" },
|
||||
];
|
||||
```
|
||||
|
||||
Actually, this array is wrapped in another array, but that's another story (involving commas in selectors).
|
||||
(Actually, this array is wrapped in another array, but that's another story,
|
||||
involving commas in selectors.)
|
||||
|
||||
Now that we know the meaning of every part of the selector, we can compile it. That's where it becomes interesting.
|
||||
Now that we know the meaning of every part of the selector, we can compile it.
|
||||
That is where things become interesting.
|
||||
|
||||
The basic idea is to turn every part of the selector into a function, which takes an element as its only argument. The function checks whether a passed element matches its part of the selector: If it does, the element is passed to the next turned-into-a-function part of the selector, which does the same. If an element is accepted by all parts of the selector, it _matches_ the selector and double rainbow ALL THE WAY.
|
||||
The basic idea is to turn every part of the selector into a function, which
|
||||
takes an element as its only argument. The function checks whether a passed
|
||||
element matches its part of the selector: If it does, the element is passed to
|
||||
the next function representing the next part of the selector. That function does
|
||||
the same. If an element is accepted by all parts of the selector, it _matches_
|
||||
the selector and double rainbow ALL THE WAY.
|
||||
|
||||
As said before, we want to do right-to-left execution with all the big O improvements nonsense, so elements are passed from the rightmost part of the selector (`b` in our example) to the leftmost (~~which would be `c`~~ of course `a`).
|
||||
As said before, we want to do right-to-left execution with all the big O
|
||||
improvements. That means elements are passed from the rightmost part of the
|
||||
selector (`b` in our example) to the leftmost (~~which would be `c`~~ of course
|
||||
`a`).
|
||||
|
||||
For traversals, such as the _descendant_ operating the space between `a` and
|
||||
`b`, we walk up the DOM tree, starting from the element passed as argument.
|
||||
|
||||
_//TODO: More in-depth description. Implementation details. Build a spaceship._
|
||||
|
||||
@@ -60,150 +100,138 @@ _//TODO: More in-depth description. Implementation details. Build a spaceship._
|
||||
const CSSselect = require("css-select");
|
||||
```
|
||||
|
||||
__Note:__ css-select throws errors when invalid selectors are passed to it, contrary to the behavior in browsers, which swallow them. This is done to aid with writing css selectors, but can be unexpected when processing arbitrary strings.
|
||||
**Note:** css-select throws errors when invalid selectors are passed to it.This
|
||||
is done to aid with writing css selectors, but can be unexpected when processing
|
||||
arbitrary strings.
|
||||
|
||||
#### `CSSselect(query, elems, options)`
|
||||
#### `CSSselect.selectAll(query, elems, options)`
|
||||
|
||||
Queries `elems`, returns an array containing all matches.
|
||||
|
||||
- `query` can be either a CSS selector or a function.
|
||||
- `elems` can be either an array of elements, or a single element. If it is an element, its children will be queried.
|
||||
- `options` is described below.
|
||||
- `query` can be either a CSS selector or a function.
|
||||
- `elems` can be either an array of elements, or a single element. If it is an
|
||||
element, its children will be queried.
|
||||
- `options` is described below.
|
||||
|
||||
Aliases: `CSSselect.selectAll(query, elems)`, `CSSselect.iterate(query, elems)`.
|
||||
Aliases: `default` export, `CSSselect.iterate(query, elems)`.
|
||||
|
||||
#### `CSSselect.compile(query)`
|
||||
#### `CSSselect.compile(query, options)`
|
||||
|
||||
Compiles the query, returns a function.
|
||||
|
||||
#### `CSSselect.is(elem, query, options)`
|
||||
|
||||
Tests whether or not an element is matched by `query`. `query` can be either a CSS selector or a function.
|
||||
Tests whether or not an element is matched by `query`. `query` can be either a
|
||||
CSS selector or a function.
|
||||
|
||||
#### `CSSselect.selectOne(query, elems, options)`
|
||||
|
||||
Arguments are the same as for `CSSselect(query, elems)`. Only returns the first match, or `null` if there was no match.
|
||||
Arguments are the same as for `CSSselect.selectAll(query, elems)`. Only returns
|
||||
the first match, or `null` if there was no match.
|
||||
|
||||
### Options
|
||||
|
||||
- `xmlMode`: When enabled, tag names will be case-sensitive. Default: `false`.
|
||||
- `strict`: Limits the module to only use CSS3 selectors. Default: `false`.
|
||||
- `rootFunc`: The last function in the stack, will be called with the last element that's looked at. Should return `true`.
|
||||
- `adapter`: The adapter to use when interacting with the backing DOM structure. By default it uses [`domutils`](https://github.com/fb55/domutils).
|
||||
All options are optional.
|
||||
|
||||
- `xmlMode`: When enabled, tag names will be case-sensitive. Default: `false`.
|
||||
- `rootFunc`: The last function in the stack, will be called with the last
|
||||
element that's looked at.
|
||||
- `adapter`: The adapter to use when interacting with the backing DOM
|
||||
structure. By default it uses the `domutils` module.
|
||||
- `context`: The context of the current query. Used to limit the scope of
|
||||
searches. Can be matched directly using the `:scope` pseudo-selector.
|
||||
- `cacheResults`: Allow css-select to cache results for some selectors,
|
||||
sometimes greatly improving querying performance. Disable this if your
|
||||
document can change in between queries with the same compiled selector.
|
||||
Default: `true`.
|
||||
|
||||
#### Custom Adapters
|
||||
|
||||
A custom adapter must implement the following functions:
|
||||
A custom adapter must match the interface described
|
||||
[here](https://github.com/fb55/css-select/blob/1aa44bdd64aaf2ebdfd7f338e2e76bed36521957/src/types.ts#L6-L96).
|
||||
|
||||
```
|
||||
isTag, existsOne, getAttributeValue, getChildren, getName, getParent,
|
||||
getSiblings, getText, hasAttrib, removeSubsets, findAll, findOne
|
||||
```
|
||||
|
||||
The method signature notation used below should be fairly intuitive - if not,
|
||||
see the [`rtype`](https://github.com/ericelliott/rtype) or
|
||||
[`TypeScript`](https://www.typescriptlang.org/) docs, as it is very similar to
|
||||
both of those. You may also want to look at
|
||||
-[`domutils`](https://github.com/fb55/domutils) to see the default
|
||||
-implementation, or at
|
||||
-[`css-select-browser-adapter`](https://github.com/nrkn/css-select-browser-adapter/blob/master/index.js)
|
||||
-for an implementation backed by the DOM.
|
||||
|
||||
```ts
|
||||
{
|
||||
// is the node a tag?
|
||||
isTag: ( node:Node ) => isTag:Boolean,
|
||||
|
||||
// does at least one of passed element nodes pass the test predicate?
|
||||
existsOne: ( test:Predicate, elems:[ElementNode] ) => existsOne:Boolean,
|
||||
|
||||
// get the attribute value
|
||||
getAttributeValue: ( elem:ElementNode, name:String ) => value:String,
|
||||
|
||||
// get the node's children
|
||||
getChildren: ( node:Node ) => children:[Node],
|
||||
|
||||
// get the name of the tag
|
||||
getName: ( elem:ElementNode ) => tagName:String,
|
||||
|
||||
// get the parent of the node
|
||||
getParent: ( node:Node ) => parentNode:Node,
|
||||
|
||||
/*
|
||||
get the siblings of the node. Note that unlike jQuery's `siblings` method,
|
||||
this is expected to include the current node as well
|
||||
*/
|
||||
getSiblings: ( node:Node ) => siblings:[Node],
|
||||
|
||||
// get the text content of the node, and its children if it has any
|
||||
getText: ( node:Node ) => text:String,
|
||||
|
||||
// does the element have the named attribute?
|
||||
hasAttrib: ( elem:ElementNode, name:String ) => hasAttrib:Boolean,
|
||||
|
||||
// takes an array of nodes, and removes any duplicates, as well as any nodes
|
||||
// whose ancestors are also in the array
|
||||
removeSubsets: ( nodes:[Node] ) => unique:[Node],
|
||||
|
||||
// finds all of the element nodes in the array that match the test predicate,
|
||||
// as well as any of their children that match it
|
||||
findAll: ( test:Predicate, nodes:[Node] ) => elems:[ElementNode],
|
||||
|
||||
// finds the first node in the array that matches the test predicate, or one
|
||||
// of its children
|
||||
findOne: ( test:Predicate, elems:[ElementNode] ) => findOne:ElementNode,
|
||||
|
||||
/*
|
||||
The adapter can also optionally include an equals method, if your DOM
|
||||
structure needs a custom equality test to compare two objects which refer
|
||||
to the same underlying node. If not provided, `css-select` will fall back to
|
||||
`a === b`.
|
||||
*/
|
||||
equals: ( a:Node, b:Node ) => Boolean
|
||||
}
|
||||
```
|
||||
You may want to have a look at [`domutils`](https://github.com/fb55/domutils) to
|
||||
see the default implementation, or at
|
||||
[`css-select-browser-adapter`](https://github.com/nrkn/css-select-browser-adapter/blob/master/index.js)
|
||||
for an implementation backed by the DOM.
|
||||
|
||||
## Supported selectors
|
||||
|
||||
_As defined by CSS 4 and / or jQuery._
|
||||
|
||||
* Universal (`*`)
|
||||
* Tag (`<tagname>`)
|
||||
* Descendant (` `)
|
||||
* Child (`>`)
|
||||
* Parent (`<`) *
|
||||
* Sibling (`+`)
|
||||
* Adjacent (`~`)
|
||||
* Attribute (`[attr=foo]`), with supported comparisons:
|
||||
* `[attr]` (existential)
|
||||
* `=`
|
||||
* `~=`
|
||||
* `|=`
|
||||
* `*=`
|
||||
* `^=`
|
||||
* `$=`
|
||||
* `!=` *
|
||||
* Also, `i` can be added after the comparison to make the comparison case-insensitive (eg. `[attr=foo i]`) *
|
||||
* Pseudos:
|
||||
* `:not`
|
||||
* `:contains` *
|
||||
* `:icontains` * (case-insensitive version of `:contains`)
|
||||
* `:has` *
|
||||
* `:root`
|
||||
* `:empty`
|
||||
* `:parent` *
|
||||
* `:[first|last]-child[-of-type]`
|
||||
* `:only-of-type`, `:only-child`
|
||||
* `:nth-[last-]child[-of-type]`
|
||||
* `:link`
|
||||
* `:visited`, `:hover`, `:active` * (these depend on optional Adapter methods, so these will work only if implemented in Adapter)
|
||||
* `:selected` *, `:checked`
|
||||
* `:enabled`, `:disabled`
|
||||
* `:required`, `:optional`
|
||||
* `:header`, `:button`, `:input`, `:text`, `:checkbox`, `:file`, `:password`, `:reset`, `:radio` etc. *
|
||||
* `:matches` *
|
||||
|
||||
__*__: Not part of CSS3
|
||||
- [Selector lists](https://developer.mozilla.org/en-US/docs/Web/CSS/Selector_list)
|
||||
(`,`)
|
||||
- [Universal](https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors)
|
||||
(`*`)
|
||||
- [Type](https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors)
|
||||
(`<tagname>`)
|
||||
- [Descendant](https://developer.mozilla.org/en-US/docs/Web/CSS/Descendant_combinator)
|
||||
(` `)
|
||||
- [Child](https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator)
|
||||
(`>`)
|
||||
- Parent (`<`)
|
||||
- [Adjacent sibling](https://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_sibling_combinator)
|
||||
(`+`)
|
||||
- [General sibling](https://developer.mozilla.org/en-US/docs/Web/CSS/General_sibling_combinator)
|
||||
(`~`)
|
||||
- [Attribute](https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors)
|
||||
(`[attr=foo]`), with supported comparisons:
|
||||
- `[attr]` (existential)
|
||||
- `=`
|
||||
- `~=`
|
||||
- `|=`
|
||||
- `*=`
|
||||
- `^=`
|
||||
- `$=`
|
||||
- `!=`
|
||||
- `i` and `s` can be added after the comparison to make the comparison
|
||||
case-insensitive or case-sensitive (eg. `[attr=foo i]`). If neither is
|
||||
supplied, css-select will follow the HTML spec's
|
||||
[case-sensitivity rules](https://html.spec.whatwg.org/multipage/semantics-other.html#case-sensitivity-of-selectors).
|
||||
- Pseudos:
|
||||
- [`:not`](https://developer.mozilla.org/en-US/docs/Web/CSS/:not)
|
||||
- [`:contains`](https://api.jquery.com/contains-selector)
|
||||
- `:icontains` (case-insensitive version of `:contains`)
|
||||
- [`:has`](https://developer.mozilla.org/en-US/docs/Web/CSS/:has)
|
||||
- [`:root`](https://developer.mozilla.org/en-US/docs/Web/CSS/:root)
|
||||
- [`:empty`](https://developer.mozilla.org/en-US/docs/Web/CSS/:empty)
|
||||
- [`:parent`](https://api.jquery.com/parent-selector)
|
||||
- [`:first-child`](https://developer.mozilla.org/en-US/docs/Web/CSS/:first-child),
|
||||
[`:last-child`](https://developer.mozilla.org/en-US/docs/Web/CSS/:last-child),
|
||||
[`:first-of-type`](https://developer.mozilla.org/en-US/docs/Web/CSS/:first-of-type),
|
||||
[`:last-of-type`](https://developer.mozilla.org/en-US/docs/Web/CSS/:last-of-type)
|
||||
- [`:only-of-type`](https://developer.mozilla.org/en-US/docs/Web/CSS/:only-of-type),
|
||||
[`:only-child`](https://developer.mozilla.org/en-US/docs/Web/CSS/:only-child)
|
||||
- [`:nth-child`](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child),
|
||||
[`:nth-last-child`](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-last-child),
|
||||
[`:nth-of-type`](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-of-type),
|
||||
[`:nth-last-of-type`](https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-last-of-type),
|
||||
- [`:link`](https://developer.mozilla.org/en-US/docs/Web/CSS/:link),
|
||||
[`:any-link`](https://developer.mozilla.org/en-US/docs/Web/CSS/:any-link)
|
||||
- [`:visited`](https://developer.mozilla.org/en-US/docs/Web/CSS/:visited),
|
||||
[`:hover`](https://developer.mozilla.org/en-US/docs/Web/CSS/:hover),
|
||||
[`:active`](https://developer.mozilla.org/en-US/docs/Web/CSS/:active)
|
||||
(these depend on optional `Adapter` methods, so these will only match
|
||||
elements if implemented in `Adapter`)
|
||||
- [`:selected`](https://api.jquery.com/selected-selector),
|
||||
[`:checked`](https://developer.mozilla.org/en-US/docs/Web/CSS/:checked)
|
||||
- [`:enabled`](https://developer.mozilla.org/en-US/docs/Web/CSS/:enabled),
|
||||
[`:disabled`](https://developer.mozilla.org/en-US/docs/Web/CSS/:disabled)
|
||||
- [`:required`](https://developer.mozilla.org/en-US/docs/Web/CSS/:required),
|
||||
[`:optional`](https://developer.mozilla.org/en-US/docs/Web/CSS/:optional)
|
||||
- [`:header`](https://api.jquery.com/header-selector),
|
||||
[`:button`](https://api.jquery.com/button-selector),
|
||||
[`:input`](https://api.jquery.com/input-selector),
|
||||
[`:text`](https://api.jquery.com/text-selector),
|
||||
[`:checkbox`](https://api.jquery.com/checkbox-selector),
|
||||
[`:file`](https://api.jquery.com/file-selector),
|
||||
[`:password`](https://api.jquery.com/password-selector),
|
||||
[`:reset`](https://api.jquery.com/reset-selector),
|
||||
[`:radio`](https://api.jquery.com/radio-selector) etc.
|
||||
- [`:is`](https://developer.mozilla.org/en-US/docs/Web/CSS/:is), plus its
|
||||
legacy alias `:matches`
|
||||
- [`:scope`](https://developer.mozilla.org/en-US/docs/Web/CSS/:scope)
|
||||
(uses the context from the passed options)
|
||||
|
||||
---
|
||||
|
||||
@@ -211,11 +239,17 @@ License: BSD-2-Clause
|
||||
|
||||
## Security contact information
|
||||
|
||||
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security).
|
||||
Tidelift will coordinate the fix and disclosure.
|
||||
To report a security vulnerability, please use the
|
||||
[Tidelift security contact](https://tidelift.com/security). Tidelift will
|
||||
coordinate the fix and disclosure.
|
||||
|
||||
## `css-select` for enterprise
|
||||
|
||||
Available as part of the Tidelift Subscription
|
||||
|
||||
The maintainers of `css-select` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-css-select?utm_source=npm-css-select&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||
The maintainers of `css-select` and thousands of other packages are working with
|
||||
Tidelift to deliver commercial support and maintenance for the open source
|
||||
dependencies you use to build your applications. Save time, reduce risk, and
|
||||
improve code health, while paying the maintainers of the exact dependencies you
|
||||
use.
|
||||
[Learn more.](https://tidelift.com/subscription/pkg/npm-css-select?utm_source=npm-css-select&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { CompiledQuery, InternalOptions } from "./types";
|
||||
import type { AttributeSelector, AttributeAction } from "css-what";
|
||||
/**
|
||||
* Attribute selectors
|
||||
*/
|
||||
export declare const attributeRules: Record<AttributeAction, <Node, ElementNode extends Node>(next: CompiledQuery<ElementNode>, data: AttributeSelector, options: InternalOptions<Node, ElementNode>) => CompiledQuery<ElementNode>>;
|
||||
//# sourceMappingURL=attributes.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../src/attributes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AA+EnE;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAC/B,eAAe,EACf,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EAC3B,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,EAChC,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,KAC1C,aAAa,CAAC,WAAW,CAAC,CAsLlC,CAAC"}
|
||||
+156
-114
@@ -1,190 +1,232 @@
|
||||
var falseFunc = require("boolbase").falseFunc;
|
||||
|
||||
//https://github.com/slevithan/XRegExp/blob/master/src/xregexp.js#L469
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.attributeRules = void 0;
|
||||
var boolbase_1 = require("boolbase");
|
||||
/**
|
||||
* All reserved characters in a regex, used for escaping.
|
||||
*
|
||||
* Taken from XRegExp, (c) 2007-2020 Steven Levithan under the MIT license
|
||||
* https://github.com/slevithan/xregexp/blob/95eeebeb8fac8754d54eafe2b4743661ac1cf028/src/xregexp.js#L794
|
||||
*/
|
||||
var reChars = /[-[\]{}()*+?.,\\^$|#\s]/g;
|
||||
|
||||
/*
|
||||
attribute selectors
|
||||
*/
|
||||
var attributeRules = {
|
||||
__proto__: null,
|
||||
equals: function(next, data, options) {
|
||||
function escapeRegex(value) {
|
||||
return value.replace(reChars, "\\$&");
|
||||
}
|
||||
/**
|
||||
* Attributes that are case-insensitive in HTML.
|
||||
*
|
||||
* @private
|
||||
* @see https://html.spec.whatwg.org/multipage/semantics-other.html#case-sensitivity-of-selectors
|
||||
*/
|
||||
var caseInsensitiveAttributes = new Set([
|
||||
"accept",
|
||||
"accept-charset",
|
||||
"align",
|
||||
"alink",
|
||||
"axis",
|
||||
"bgcolor",
|
||||
"charset",
|
||||
"checked",
|
||||
"clear",
|
||||
"codetype",
|
||||
"color",
|
||||
"compact",
|
||||
"declare",
|
||||
"defer",
|
||||
"dir",
|
||||
"direction",
|
||||
"disabled",
|
||||
"enctype",
|
||||
"face",
|
||||
"frame",
|
||||
"hreflang",
|
||||
"http-equiv",
|
||||
"lang",
|
||||
"language",
|
||||
"link",
|
||||
"media",
|
||||
"method",
|
||||
"multiple",
|
||||
"nohref",
|
||||
"noresize",
|
||||
"noshade",
|
||||
"nowrap",
|
||||
"readonly",
|
||||
"rel",
|
||||
"rev",
|
||||
"rules",
|
||||
"scope",
|
||||
"scrolling",
|
||||
"selected",
|
||||
"shape",
|
||||
"target",
|
||||
"text",
|
||||
"type",
|
||||
"valign",
|
||||
"valuetype",
|
||||
"vlink",
|
||||
]);
|
||||
function shouldIgnoreCase(selector, options) {
|
||||
return typeof selector.ignoreCase === "boolean"
|
||||
? selector.ignoreCase
|
||||
: selector.ignoreCase === "quirks"
|
||||
? !!options.quirksMode
|
||||
: !options.xmlMode && caseInsensitiveAttributes.has(selector.name);
|
||||
}
|
||||
/**
|
||||
* Attribute selectors
|
||||
*/
|
||||
exports.attributeRules = {
|
||||
equals: function (next, data, options) {
|
||||
var adapter = options.adapter;
|
||||
var name = data.name;
|
||||
var value = data.value;
|
||||
var adapter = options.adapter;
|
||||
|
||||
if (data.ignoreCase) {
|
||||
if (shouldIgnoreCase(data, options)) {
|
||||
value = value.toLowerCase();
|
||||
|
||||
return function equalsIC(elem) {
|
||||
return function (elem) {
|
||||
var attr = adapter.getAttributeValue(elem, name);
|
||||
return attr != null && attr.toLowerCase() === value && next(elem);
|
||||
return (attr != null &&
|
||||
attr.length === value.length &&
|
||||
attr.toLowerCase() === value &&
|
||||
next(elem));
|
||||
};
|
||||
}
|
||||
|
||||
return function equals(elem) {
|
||||
return function (elem) {
|
||||
return adapter.getAttributeValue(elem, name) === value && next(elem);
|
||||
};
|
||||
},
|
||||
hyphen: function(next, data, options) {
|
||||
hyphen: function (next, data, options) {
|
||||
var adapter = options.adapter;
|
||||
var name = data.name;
|
||||
var value = data.value;
|
||||
var len = value.length;
|
||||
var adapter = options.adapter;
|
||||
|
||||
if (data.ignoreCase) {
|
||||
if (shouldIgnoreCase(data, options)) {
|
||||
value = value.toLowerCase();
|
||||
|
||||
return function hyphenIC(elem) {
|
||||
var attr = adapter.getAttributeValue(elem, name);
|
||||
return (
|
||||
attr != null &&
|
||||
return (attr != null &&
|
||||
(attr.length === len || attr.charAt(len) === "-") &&
|
||||
attr.substr(0, len).toLowerCase() === value &&
|
||||
next(elem)
|
||||
);
|
||||
next(elem));
|
||||
};
|
||||
}
|
||||
|
||||
return function hyphen(elem) {
|
||||
var attr = adapter.getAttributeValue(elem, name);
|
||||
return (
|
||||
attr != null &&
|
||||
attr.substr(0, len) === value &&
|
||||
return (attr != null &&
|
||||
(attr.length === len || attr.charAt(len) === "-") &&
|
||||
next(elem)
|
||||
);
|
||||
attr.substr(0, len) === value &&
|
||||
next(elem));
|
||||
};
|
||||
},
|
||||
element: function(next, data, options) {
|
||||
var name = data.name;
|
||||
var value = data.value;
|
||||
element: function (next, data, options) {
|
||||
var adapter = options.adapter;
|
||||
|
||||
var name = data.name, value = data.value;
|
||||
if (/\s/.test(value)) {
|
||||
return falseFunc;
|
||||
return boolbase_1.falseFunc;
|
||||
}
|
||||
|
||||
value = value.replace(reChars, "\\$&");
|
||||
|
||||
var pattern = "(?:^|\\s)" + value + "(?:$|\\s)",
|
||||
flags = data.ignoreCase ? "i" : "",
|
||||
regex = new RegExp(pattern, flags);
|
||||
|
||||
var regex = new RegExp("(?:^|\\s)".concat(escapeRegex(value), "(?:$|\\s)"), shouldIgnoreCase(data, options) ? "i" : "");
|
||||
return function element(elem) {
|
||||
var attr = adapter.getAttributeValue(elem, name);
|
||||
return attr != null && regex.test(attr) && next(elem);
|
||||
return (attr != null &&
|
||||
attr.length >= value.length &&
|
||||
regex.test(attr) &&
|
||||
next(elem));
|
||||
};
|
||||
},
|
||||
exists: function(next, data, options) {
|
||||
var name = data.name;
|
||||
exists: function (next, _a, _b) {
|
||||
var name = _a.name;
|
||||
var adapter = _b.adapter;
|
||||
return function (elem) { return adapter.hasAttrib(elem, name) && next(elem); };
|
||||
},
|
||||
start: function (next, data, options) {
|
||||
var adapter = options.adapter;
|
||||
|
||||
return function exists(elem) {
|
||||
return adapter.hasAttrib(elem, name) && next(elem);
|
||||
};
|
||||
},
|
||||
start: function(next, data, options) {
|
||||
var name = data.name;
|
||||
var value = data.value;
|
||||
var len = value.length;
|
||||
var adapter = options.adapter;
|
||||
|
||||
if (len === 0) {
|
||||
return falseFunc;
|
||||
return boolbase_1.falseFunc;
|
||||
}
|
||||
|
||||
if (data.ignoreCase) {
|
||||
if (shouldIgnoreCase(data, options)) {
|
||||
value = value.toLowerCase();
|
||||
|
||||
return function startIC(elem) {
|
||||
return function (elem) {
|
||||
var attr = adapter.getAttributeValue(elem, name);
|
||||
return attr != null && attr.substr(0, len).toLowerCase() === value && next(elem);
|
||||
return (attr != null &&
|
||||
attr.length >= len &&
|
||||
attr.substr(0, len).toLowerCase() === value &&
|
||||
next(elem));
|
||||
};
|
||||
}
|
||||
|
||||
return function start(elem) {
|
||||
var attr = adapter.getAttributeValue(elem, name);
|
||||
return attr != null && attr.substr(0, len) === value && next(elem);
|
||||
return function (elem) {
|
||||
var _a;
|
||||
return !!((_a = adapter.getAttributeValue(elem, name)) === null || _a === void 0 ? void 0 : _a.startsWith(value)) &&
|
||||
next(elem);
|
||||
};
|
||||
},
|
||||
end: function(next, data, options) {
|
||||
end: function (next, data, options) {
|
||||
var adapter = options.adapter;
|
||||
var name = data.name;
|
||||
var value = data.value;
|
||||
var len = -value.length;
|
||||
var adapter = options.adapter;
|
||||
|
||||
if (len === 0) {
|
||||
return falseFunc;
|
||||
return boolbase_1.falseFunc;
|
||||
}
|
||||
|
||||
if (data.ignoreCase) {
|
||||
if (shouldIgnoreCase(data, options)) {
|
||||
value = value.toLowerCase();
|
||||
|
||||
return function endIC(elem) {
|
||||
var attr = adapter.getAttributeValue(elem, name);
|
||||
return attr != null && attr.substr(len).toLowerCase() === value && next(elem);
|
||||
return function (elem) {
|
||||
var _a;
|
||||
return ((_a = adapter
|
||||
.getAttributeValue(elem, name)) === null || _a === void 0 ? void 0 : _a.substr(len).toLowerCase()) === value && next(elem);
|
||||
};
|
||||
}
|
||||
|
||||
return function end(elem) {
|
||||
var attr = adapter.getAttributeValue(elem, name);
|
||||
return attr != null && attr.substr(len) === value && next(elem);
|
||||
return function (elem) {
|
||||
var _a;
|
||||
return !!((_a = adapter.getAttributeValue(elem, name)) === null || _a === void 0 ? void 0 : _a.endsWith(value)) &&
|
||||
next(elem);
|
||||
};
|
||||
},
|
||||
any: function(next, data, options) {
|
||||
var name = data.name;
|
||||
var value = data.value;
|
||||
any: function (next, data, options) {
|
||||
var adapter = options.adapter;
|
||||
|
||||
var name = data.name, value = data.value;
|
||||
if (value === "") {
|
||||
return falseFunc;
|
||||
return boolbase_1.falseFunc;
|
||||
}
|
||||
|
||||
if (data.ignoreCase) {
|
||||
var regex = new RegExp(value.replace(reChars, "\\$&"), "i");
|
||||
|
||||
if (shouldIgnoreCase(data, options)) {
|
||||
var regex_1 = new RegExp(escapeRegex(value), "i");
|
||||
return function anyIC(elem) {
|
||||
var attr = adapter.getAttributeValue(elem, name);
|
||||
return attr != null && regex.test(attr) && next(elem);
|
||||
return (attr != null &&
|
||||
attr.length >= value.length &&
|
||||
regex_1.test(attr) &&
|
||||
next(elem));
|
||||
};
|
||||
}
|
||||
|
||||
return function any(elem) {
|
||||
var attr = adapter.getAttributeValue(elem, name);
|
||||
return attr != null && attr.indexOf(value) >= 0 && next(elem);
|
||||
return function (elem) {
|
||||
var _a;
|
||||
return !!((_a = adapter.getAttributeValue(elem, name)) === null || _a === void 0 ? void 0 : _a.includes(value)) &&
|
||||
next(elem);
|
||||
};
|
||||
},
|
||||
not: function(next, data, options) {
|
||||
not: function (next, data, options) {
|
||||
var adapter = options.adapter;
|
||||
var name = data.name;
|
||||
var value = data.value;
|
||||
var adapter = options.adapter;
|
||||
|
||||
if (value === "") {
|
||||
return function notEmpty(elem) {
|
||||
return function (elem) {
|
||||
return !!adapter.getAttributeValue(elem, name) && next(elem);
|
||||
};
|
||||
} else if (data.ignoreCase) {
|
||||
}
|
||||
else if (shouldIgnoreCase(data, options)) {
|
||||
value = value.toLowerCase();
|
||||
|
||||
return function notIC(elem) {
|
||||
return function (elem) {
|
||||
var attr = adapter.getAttributeValue(elem, name);
|
||||
return attr != null && attr.toLowerCase() !== value && next(elem);
|
||||
return ((attr == null ||
|
||||
attr.length !== value.length ||
|
||||
attr.toLowerCase() !== value) &&
|
||||
next(elem));
|
||||
};
|
||||
}
|
||||
|
||||
return function not(elem) {
|
||||
return function (elem) {
|
||||
return adapter.getAttributeValue(elem, name) !== value && next(elem);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
compile: function(next, data, options) {
|
||||
if (options && options.strict && (data.ignoreCase || data.action === "not")) {
|
||||
throw new Error("Unsupported attribute selector");
|
||||
}
|
||||
return attributeRules[data.action](next, data, options);
|
||||
},
|
||||
rules: attributeRules
|
||||
};
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { InternalSelector } from "./types";
|
||||
import { Selector } from "css-what";
|
||||
import type { CompiledQuery, InternalOptions } from "./types";
|
||||
/**
|
||||
* Compiles a selector to an executable function.
|
||||
*
|
||||
* @param selector Selector to compile.
|
||||
* @param options Compilation options.
|
||||
* @param context Optional context for the selector.
|
||||
*/
|
||||
export declare function compile<Node, ElementNode extends Node>(selector: string | Selector[][], options: InternalOptions<Node, ElementNode>, context?: Node[] | Node): CompiledQuery<Node>;
|
||||
export declare function compileUnsafe<Node, ElementNode extends Node>(selector: string | Selector[][], options: InternalOptions<Node, ElementNode>, context?: Node[] | Node): CompiledQuery<ElementNode>;
|
||||
export declare function compileToken<Node, ElementNode extends Node>(token: InternalSelector[][], options: InternalOptions<Node, ElementNode>, context?: Node[] | Node): CompiledQuery<ElementNode>;
|
||||
//# sourceMappingURL=compile.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAS,QAAQ,EAAgB,MAAM,UAAU,CAAC;AASzD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE9D;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EAClD,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE,EAAE,EAC/B,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,GACxB,aAAa,CAAC,IAAI,CAAC,CAGrB;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EACxD,QAAQ,EAAE,MAAM,GAAG,QAAQ,EAAE,EAAE,EAC/B,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,GACxB,aAAa,CAAC,WAAW,CAAC,CAG5B;AAiDD,wBAAgB,YAAY,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EACvD,KAAK,EAAE,gBAAgB,EAAE,EAAE,EAC3B,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,GACxB,aAAa,CAAC,WAAW,CAAC,CA2C5B"}
|
||||
+87
-187
@@ -1,219 +1,119 @@
|
||||
/*
|
||||
compiles a selector to an executable function
|
||||
*/
|
||||
|
||||
module.exports = compile;
|
||||
|
||||
var parse = require("css-what").parse;
|
||||
var BaseFuncs = require("boolbase");
|
||||
var sortRules = require("./sort.js");
|
||||
var procedure = require("./procedure.json");
|
||||
var Rules = require("./general.js");
|
||||
var Pseudos = require("./pseudos.js");
|
||||
var trueFunc = BaseFuncs.trueFunc;
|
||||
var falseFunc = BaseFuncs.falseFunc;
|
||||
|
||||
var filters = Pseudos.filters;
|
||||
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.compileToken = exports.compileUnsafe = exports.compile = void 0;
|
||||
var css_what_1 = require("css-what");
|
||||
var boolbase_1 = require("boolbase");
|
||||
var sort_1 = __importDefault(require("./sort"));
|
||||
var procedure_1 = require("./procedure");
|
||||
var general_1 = require("./general");
|
||||
var subselects_1 = require("./pseudo-selectors/subselects");
|
||||
/**
|
||||
* Compiles a selector to an executable function.
|
||||
*
|
||||
* @param selector Selector to compile.
|
||||
* @param options Compilation options.
|
||||
* @param context Optional context for the selector.
|
||||
*/
|
||||
function compile(selector, options, context) {
|
||||
var next = compileUnsafe(selector, options, context);
|
||||
return wrap(next, options);
|
||||
return (0, subselects_1.ensureIsTag)(next, options.adapter);
|
||||
}
|
||||
|
||||
function wrap(next, options) {
|
||||
var adapter = options.adapter;
|
||||
|
||||
return function base(elem) {
|
||||
return adapter.isTag(elem) && next(elem);
|
||||
};
|
||||
}
|
||||
|
||||
exports.compile = compile;
|
||||
function compileUnsafe(selector, options, context) {
|
||||
var token = parse(selector, options);
|
||||
var token = typeof selector === "string" ? (0, css_what_1.parse)(selector) : selector;
|
||||
return compileToken(token, options, context);
|
||||
}
|
||||
|
||||
exports.compileUnsafe = compileUnsafe;
|
||||
function includesScopePseudo(t) {
|
||||
return (
|
||||
t.type === "pseudo" &&
|
||||
return (t.type === "pseudo" &&
|
||||
(t.name === "scope" ||
|
||||
(Array.isArray(t.data) &&
|
||||
t.data.some(function(data) {
|
||||
return data.some(includesScopePseudo);
|
||||
})))
|
||||
);
|
||||
t.data.some(function (data) { return data.some(includesScopePseudo); }))));
|
||||
}
|
||||
|
||||
var DESCENDANT_TOKEN = { type: "descendant" };
|
||||
var FLEXIBLE_DESCENDANT_TOKEN = { type: "_flexibleDescendant" };
|
||||
var SCOPE_TOKEN = { type: "pseudo", name: "scope" };
|
||||
var PLACEHOLDER_ELEMENT = {};
|
||||
|
||||
//CSS 4 Spec (Draft): 3.3.1. Absolutizing a Scope-relative Selector
|
||||
//http://www.w3.org/TR/selectors4/#absolutizing
|
||||
function absolutize(token, options, context) {
|
||||
var adapter = options.adapter;
|
||||
|
||||
//TODO better check if context is document
|
||||
var hasContext =
|
||||
!!context &&
|
||||
!!context.length &&
|
||||
context.every(function(e) {
|
||||
return e === PLACEHOLDER_ELEMENT || !!adapter.getParent(e);
|
||||
});
|
||||
|
||||
token.forEach(function(t) {
|
||||
if (t.length > 0 && isTraversal(t[0]) && t[0].type !== "descendant") {
|
||||
//don't return in else branch
|
||||
} else if (hasContext && !(Array.isArray(t) ? t.some(includesScopePseudo) : includesScopePseudo(t))) {
|
||||
t.unshift(DESCENDANT_TOKEN);
|
||||
} else {
|
||||
return;
|
||||
var DESCENDANT_TOKEN = { type: css_what_1.SelectorType.Descendant };
|
||||
var FLEXIBLE_DESCENDANT_TOKEN = {
|
||||
type: "_flexibleDescendant",
|
||||
};
|
||||
var SCOPE_TOKEN = {
|
||||
type: css_what_1.SelectorType.Pseudo,
|
||||
name: "scope",
|
||||
data: null,
|
||||
};
|
||||
/*
|
||||
* CSS 4 Spec (Draft): 3.3.1. Absolutizing a Scope-relative Selector
|
||||
* http://www.w3.org/TR/selectors4/#absolutizing
|
||||
*/
|
||||
function absolutize(token, _a, context) {
|
||||
var adapter = _a.adapter;
|
||||
// TODO Use better check if the context is a document
|
||||
var hasContext = !!(context === null || context === void 0 ? void 0 : context.every(function (e) {
|
||||
var parent = adapter.isTag(e) && adapter.getParent(e);
|
||||
return e === subselects_1.PLACEHOLDER_ELEMENT || (parent && adapter.isTag(parent));
|
||||
}));
|
||||
for (var _i = 0, token_1 = token; _i < token_1.length; _i++) {
|
||||
var t = token_1[_i];
|
||||
if (t.length > 0 && (0, procedure_1.isTraversal)(t[0]) && t[0].type !== "descendant") {
|
||||
// Don't continue in else branch
|
||||
}
|
||||
else if (hasContext && !t.some(includesScopePseudo)) {
|
||||
t.unshift(DESCENDANT_TOKEN);
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
|
||||
t.unshift(SCOPE_TOKEN);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function compileToken(token, options, context) {
|
||||
token = token.filter(function(t) {
|
||||
return t.length > 0;
|
||||
});
|
||||
|
||||
token.forEach(sortRules);
|
||||
|
||||
var _a;
|
||||
token = token.filter(function (t) { return t.length > 0; });
|
||||
token.forEach(sort_1.default);
|
||||
context = (_a = options.context) !== null && _a !== void 0 ? _a : context;
|
||||
var isArrayContext = Array.isArray(context);
|
||||
|
||||
context = (options && options.context) || context;
|
||||
|
||||
if (context && !isArrayContext) context = [context];
|
||||
|
||||
absolutize(token, options, context);
|
||||
|
||||
var finalContext = context && (Array.isArray(context) ? context : [context]);
|
||||
absolutize(token, options, finalContext);
|
||||
var shouldTestNextSiblings = false;
|
||||
|
||||
var query = token
|
||||
.map(function(rules) {
|
||||
if (rules[0] && rules[1] && rules[0].name === "scope") {
|
||||
var ruleType = rules[1].type;
|
||||
if (isArrayContext && ruleType === "descendant") {
|
||||
rules[1] = FLEXIBLE_DESCENDANT_TOKEN;
|
||||
} else if (ruleType === "adjacent" || ruleType === "sibling") {
|
||||
shouldTestNextSiblings = true;
|
||||
}
|
||||
.map(function (rules) {
|
||||
if (rules.length >= 2) {
|
||||
var first = rules[0], second = rules[1];
|
||||
if (first.type !== "pseudo" || first.name !== "scope") {
|
||||
// Ignore
|
||||
}
|
||||
return compileRules(rules, options, context);
|
||||
})
|
||||
.reduce(reduceRules, falseFunc);
|
||||
|
||||
else if (isArrayContext && second.type === "descendant") {
|
||||
rules[1] = FLEXIBLE_DESCENDANT_TOKEN;
|
||||
}
|
||||
else if (second.type === "adjacent" ||
|
||||
second.type === "sibling") {
|
||||
shouldTestNextSiblings = true;
|
||||
}
|
||||
}
|
||||
return compileRules(rules, options, finalContext);
|
||||
})
|
||||
.reduce(reduceRules, boolbase_1.falseFunc);
|
||||
query.shouldTestNextSiblings = shouldTestNextSiblings;
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
function isTraversal(t) {
|
||||
return procedure[t.type] < 0;
|
||||
}
|
||||
|
||||
exports.compileToken = compileToken;
|
||||
function compileRules(rules, options, context) {
|
||||
return rules.reduce(function(func, rule) {
|
||||
if (func === falseFunc) return func;
|
||||
|
||||
if (!(rule.type in Rules)) {
|
||||
throw new Error("Rule type " + rule.type + " is not supported by css-select");
|
||||
}
|
||||
|
||||
return Rules[rule.type](func, rule, options, context);
|
||||
}, (options && options.rootFunc) || trueFunc);
|
||||
var _a;
|
||||
return rules.reduce(function (previous, rule) {
|
||||
return previous === boolbase_1.falseFunc
|
||||
? boolbase_1.falseFunc
|
||||
: (0, general_1.compileGeneralSelector)(previous, rule, options, context, compileToken);
|
||||
}, (_a = options.rootFunc) !== null && _a !== void 0 ? _a : boolbase_1.trueFunc);
|
||||
}
|
||||
|
||||
function reduceRules(a, b) {
|
||||
if (b === falseFunc || a === trueFunc) {
|
||||
if (b === boolbase_1.falseFunc || a === boolbase_1.trueFunc) {
|
||||
return a;
|
||||
}
|
||||
if (a === falseFunc || b === trueFunc) {
|
||||
if (a === boolbase_1.falseFunc || b === boolbase_1.trueFunc) {
|
||||
return b;
|
||||
}
|
||||
|
||||
return function combine(elem) {
|
||||
return a(elem) || b(elem);
|
||||
};
|
||||
}
|
||||
|
||||
function containsTraversal(t) {
|
||||
return t.some(isTraversal);
|
||||
}
|
||||
|
||||
//:not, :has and :matches have to compile selectors
|
||||
//doing this in lib/pseudos.js would lead to circular dependencies,
|
||||
//so we add them here
|
||||
filters.not = function(next, token, options, context) {
|
||||
var opts = {
|
||||
xmlMode: !!(options && options.xmlMode),
|
||||
strict: !!(options && options.strict),
|
||||
adapter: options.adapter
|
||||
};
|
||||
|
||||
if (opts.strict) {
|
||||
if (token.length > 1 || token.some(containsTraversal)) {
|
||||
throw new Error("complex selectors in :not aren't allowed in strict mode");
|
||||
}
|
||||
}
|
||||
|
||||
var func = compileToken(token, opts, context);
|
||||
|
||||
if (func === falseFunc) return next;
|
||||
if (func === trueFunc) return falseFunc;
|
||||
|
||||
return function not(elem) {
|
||||
return !func(elem) && next(elem);
|
||||
};
|
||||
};
|
||||
|
||||
filters.has = function(next, token, options) {
|
||||
var adapter = options.adapter;
|
||||
var opts = {
|
||||
xmlMode: !!(options && options.xmlMode),
|
||||
strict: !!(options && options.strict),
|
||||
adapter: adapter
|
||||
};
|
||||
|
||||
//FIXME: Uses an array as a pointer to the current element (side effects)
|
||||
var context = token.some(containsTraversal) ? [PLACEHOLDER_ELEMENT] : null;
|
||||
|
||||
var func = compileToken(token, opts, context);
|
||||
|
||||
if (func === falseFunc) return falseFunc;
|
||||
if (func === trueFunc) {
|
||||
return function hasChild(elem) {
|
||||
return adapter.getChildren(elem).some(adapter.isTag) && next(elem);
|
||||
};
|
||||
}
|
||||
|
||||
func = wrap(func, options);
|
||||
|
||||
if (context) {
|
||||
return function has(elem) {
|
||||
return next(elem) && ((context[0] = elem), adapter.existsOne(func, adapter.getChildren(elem)));
|
||||
};
|
||||
}
|
||||
|
||||
return function has(elem) {
|
||||
return next(elem) && adapter.existsOne(func, adapter.getChildren(elem));
|
||||
};
|
||||
};
|
||||
|
||||
filters.matches = function(next, token, options, context) {
|
||||
var opts = {
|
||||
xmlMode: !!(options && options.xmlMode),
|
||||
strict: !!(options && options.strict),
|
||||
rootFunc: next,
|
||||
adapter: options.adapter
|
||||
};
|
||||
|
||||
return compileToken(token, opts, context);
|
||||
};
|
||||
|
||||
compile.compileToken = compileToken;
|
||||
compile.compileUnsafe = compileUnsafe;
|
||||
compile.Pseudos = Pseudos;
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import type { CompiledQuery, InternalOptions, InternalSelector, CompileToken } from "./types";
|
||||
export declare function compileGeneralSelector<Node, ElementNode extends Node>(next: CompiledQuery<ElementNode>, selector: InternalSelector, options: InternalOptions<Node, ElementNode>, context: Node[] | undefined, compileToken: CompileToken<Node, ElementNode>): CompiledQuery<ElementNode>;
|
||||
//# sourceMappingURL=general.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../src/general.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,YAAY,EACf,MAAM,SAAS,CAAC;AAOjB,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EACjE,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,EAChC,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,OAAO,EAAE,IAAI,EAAE,GAAG,SAAS,EAC3B,YAAY,EAAE,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,GAC9C,aAAa,CAAC,WAAW,CAAC,CAiK5B"}
|
||||
+130
-107
@@ -1,117 +1,140 @@
|
||||
var attributes = require("./attributes.js");
|
||||
var Pseudos = require("./pseudos");
|
||||
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.compileGeneralSelector = void 0;
|
||||
var attributes_1 = require("./attributes");
|
||||
var pseudo_selectors_1 = require("./pseudo-selectors");
|
||||
var css_what_1 = require("css-what");
|
||||
/*
|
||||
all available rules
|
||||
*/
|
||||
module.exports = {
|
||||
__proto__: null,
|
||||
|
||||
attribute: attributes.compile,
|
||||
pseudo: Pseudos.compile,
|
||||
|
||||
//tags
|
||||
tag: function(next, data, options) {
|
||||
var name = data.name;
|
||||
var adapter = options.adapter;
|
||||
|
||||
return function tag(elem) {
|
||||
return adapter.getName(elem) === name && next(elem);
|
||||
};
|
||||
},
|
||||
|
||||
//traversal
|
||||
descendant: function(next, data, options) {
|
||||
// eslint-disable-next-line no-undef
|
||||
var isFalseCache = typeof WeakSet !== "undefined" ? new WeakSet() : null;
|
||||
var adapter = options.adapter;
|
||||
|
||||
return function descendant(elem) {
|
||||
var found = false;
|
||||
|
||||
while (!found && (elem = adapter.getParent(elem))) {
|
||||
if (!isFalseCache || !isFalseCache.has(elem)) {
|
||||
found = next(elem);
|
||||
if (!found && isFalseCache) {
|
||||
isFalseCache.add(elem);
|
||||
* All available rules
|
||||
*/
|
||||
function compileGeneralSelector(next, selector, options, context, compileToken) {
|
||||
var adapter = options.adapter, equals = options.equals;
|
||||
switch (selector.type) {
|
||||
case css_what_1.SelectorType.PseudoElement: {
|
||||
throw new Error("Pseudo-elements are not supported by css-select");
|
||||
}
|
||||
case css_what_1.SelectorType.ColumnCombinator: {
|
||||
throw new Error("Column combinators are not yet supported by css-select");
|
||||
}
|
||||
case css_what_1.SelectorType.Attribute: {
|
||||
if (selector.namespace != null) {
|
||||
throw new Error("Namespaced attributes are not yet supported by css-select");
|
||||
}
|
||||
if (!options.xmlMode || options.lowerCaseAttributeNames) {
|
||||
selector.name = selector.name.toLowerCase();
|
||||
}
|
||||
return attributes_1.attributeRules[selector.action](next, selector, options);
|
||||
}
|
||||
case css_what_1.SelectorType.Pseudo: {
|
||||
return (0, pseudo_selectors_1.compilePseudoSelector)(next, selector, options, context, compileToken);
|
||||
}
|
||||
// Tags
|
||||
case css_what_1.SelectorType.Tag: {
|
||||
if (selector.namespace != null) {
|
||||
throw new Error("Namespaced tag names are not yet supported by css-select");
|
||||
}
|
||||
var name_1 = selector.name;
|
||||
if (!options.xmlMode || options.lowerCaseTags) {
|
||||
name_1 = name_1.toLowerCase();
|
||||
}
|
||||
return function tag(elem) {
|
||||
return adapter.getName(elem) === name_1 && next(elem);
|
||||
};
|
||||
}
|
||||
// Traversal
|
||||
case css_what_1.SelectorType.Descendant: {
|
||||
if (options.cacheResults === false ||
|
||||
typeof WeakSet === "undefined") {
|
||||
return function descendant(elem) {
|
||||
var current = elem;
|
||||
while ((current = adapter.getParent(current))) {
|
||||
if (adapter.isTag(current) && next(current)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
// @ts-expect-error `ElementNode` is not extending object
|
||||
var isFalseCache_1 = new WeakSet();
|
||||
return function cachedDescendant(elem) {
|
||||
var current = elem;
|
||||
while ((current = adapter.getParent(current))) {
|
||||
if (!isFalseCache_1.has(current)) {
|
||||
if (adapter.isTag(current) && next(current)) {
|
||||
return true;
|
||||
}
|
||||
isFalseCache_1.add(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
};
|
||||
},
|
||||
_flexibleDescendant: function(next, data, options) {
|
||||
var adapter = options.adapter;
|
||||
|
||||
// Include element itself, only used while querying an array
|
||||
return function descendant(elem) {
|
||||
var found = next(elem);
|
||||
|
||||
while (!found && (elem = adapter.getParent(elem))) {
|
||||
found = next(elem);
|
||||
}
|
||||
|
||||
return found;
|
||||
};
|
||||
},
|
||||
parent: function(next, data, options) {
|
||||
if (options && options.strict) {
|
||||
throw new Error("Parent selector isn't part of CSS3");
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
var adapter = options.adapter;
|
||||
|
||||
return function parent(elem) {
|
||||
return adapter.getChildren(elem).some(test);
|
||||
};
|
||||
|
||||
function test(elem) {
|
||||
return adapter.isTag(elem) && next(elem);
|
||||
case "_flexibleDescendant": {
|
||||
// Include element itself, only used while querying an array
|
||||
return function flexibleDescendant(elem) {
|
||||
var current = elem;
|
||||
do {
|
||||
if (adapter.isTag(current) && next(current))
|
||||
return true;
|
||||
} while ((current = adapter.getParent(current)));
|
||||
return false;
|
||||
};
|
||||
}
|
||||
},
|
||||
child: function(next, data, options) {
|
||||
var adapter = options.adapter;
|
||||
|
||||
return function child(elem) {
|
||||
var parent = adapter.getParent(elem);
|
||||
return !!parent && next(parent);
|
||||
};
|
||||
},
|
||||
sibling: function(next, data, options) {
|
||||
var adapter = options.adapter;
|
||||
|
||||
return function sibling(elem) {
|
||||
var siblings = adapter.getSiblings(elem);
|
||||
|
||||
for (var i = 0; i < siblings.length; i++) {
|
||||
if (adapter.isTag(siblings[i])) {
|
||||
if (siblings[i] === elem) break;
|
||||
if (next(siblings[i])) return true;
|
||||
case css_what_1.SelectorType.Parent: {
|
||||
return function parent(elem) {
|
||||
return adapter
|
||||
.getChildren(elem)
|
||||
.some(function (elem) { return adapter.isTag(elem) && next(elem); });
|
||||
};
|
||||
}
|
||||
case css_what_1.SelectorType.Child: {
|
||||
return function child(elem) {
|
||||
var parent = adapter.getParent(elem);
|
||||
return parent != null && adapter.isTag(parent) && next(parent);
|
||||
};
|
||||
}
|
||||
case css_what_1.SelectorType.Sibling: {
|
||||
return function sibling(elem) {
|
||||
var siblings = adapter.getSiblings(elem);
|
||||
for (var i = 0; i < siblings.length; i++) {
|
||||
var currentSibling = siblings[i];
|
||||
if (equals(elem, currentSibling))
|
||||
break;
|
||||
if (adapter.isTag(currentSibling) && next(currentSibling)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
case css_what_1.SelectorType.Adjacent: {
|
||||
if (adapter.prevElementSibling) {
|
||||
return function adjacent(elem) {
|
||||
var previous = adapter.prevElementSibling(elem);
|
||||
return previous != null && next(previous);
|
||||
};
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
},
|
||||
adjacent: function(next, data, options) {
|
||||
var adapter = options.adapter;
|
||||
|
||||
return function adjacent(elem) {
|
||||
var siblings = adapter.getSiblings(elem),
|
||||
lastElement;
|
||||
|
||||
for (var i = 0; i < siblings.length; i++) {
|
||||
if (adapter.isTag(siblings[i])) {
|
||||
if (siblings[i] === elem) break;
|
||||
lastElement = siblings[i];
|
||||
return function adjacent(elem) {
|
||||
var siblings = adapter.getSiblings(elem);
|
||||
var lastElement;
|
||||
for (var i = 0; i < siblings.length; i++) {
|
||||
var currentSibling = siblings[i];
|
||||
if (equals(elem, currentSibling))
|
||||
break;
|
||||
if (adapter.isTag(currentSibling)) {
|
||||
lastElement = currentSibling;
|
||||
}
|
||||
}
|
||||
return !!lastElement && next(lastElement);
|
||||
};
|
||||
}
|
||||
case css_what_1.SelectorType.Universal: {
|
||||
if (selector.namespace != null && selector.namespace !== "*") {
|
||||
throw new Error("Namespaced universal selectors are not yet supported by css-select");
|
||||
}
|
||||
|
||||
return !!lastElement && next(lastElement);
|
||||
};
|
||||
},
|
||||
universal: function(next) {
|
||||
return next;
|
||||
return next;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
exports.compileGeneralSelector = compileGeneralSelector;
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
import type { CompiledQuery, Options, Query, Adapter } from "./types";
|
||||
export type { Options };
|
||||
/**
|
||||
* Compiles the query, returns a function.
|
||||
*/
|
||||
export declare const compile: <Node_1, ElementNode extends Node_1>(selector: string | import("css-what").Selector[][], options?: Options<Node_1, ElementNode> | undefined, context?: Node_1 | Node_1[] | undefined) => CompiledQuery<Node_1>;
|
||||
export declare const _compileUnsafe: <Node_1, ElementNode extends Node_1>(selector: string | import("css-what").Selector[][], options?: Options<Node_1, ElementNode> | undefined, context?: Node_1 | Node_1[] | undefined) => CompiledQuery<ElementNode>;
|
||||
export declare const _compileToken: <Node_1, ElementNode extends Node_1>(selector: import("./types").InternalSelector[][], options?: Options<Node_1, ElementNode> | undefined, context?: Node_1 | Node_1[] | undefined) => CompiledQuery<ElementNode>;
|
||||
export declare function prepareContext<Node, ElementNode extends Node>(elems: Node | Node[], adapter: Adapter<Node, ElementNode>, shouldTestNextSiblings?: boolean): Node[];
|
||||
/**
|
||||
* @template Node The generic Node type for the DOM adapter being used.
|
||||
* @template ElementNode The Node type for elements for the DOM adapter being used.
|
||||
* @param elems Elements to query. If it is an element, its children will be queried..
|
||||
* @param query can be either a CSS selector string or a compiled query function.
|
||||
* @param [options] options for querying the document.
|
||||
* @see compile for supported selector queries.
|
||||
* @returns All matching elements.
|
||||
*
|
||||
*/
|
||||
export declare const selectAll: <Node_1, ElementNode extends Node_1>(query: Query<ElementNode>, elements: Node_1 | Node_1[], options?: Options<Node_1, ElementNode> | undefined) => ElementNode[];
|
||||
/**
|
||||
* @template Node The generic Node type for the DOM adapter being used.
|
||||
* @template ElementNode The Node type for elements for the DOM adapter being used.
|
||||
* @param elems Elements to query. If it is an element, its children will be queried..
|
||||
* @param query can be either a CSS selector string or a compiled query function.
|
||||
* @param [options] options for querying the document.
|
||||
* @see compile for supported selector queries.
|
||||
* @returns the first match, or null if there was no match.
|
||||
*/
|
||||
export declare const selectOne: <Node_1, ElementNode extends Node_1>(query: Query<ElementNode>, elements: Node_1 | Node_1[], options?: Options<Node_1, ElementNode> | undefined) => ElementNode | null;
|
||||
/**
|
||||
* Tests whether or not an element is matched by query.
|
||||
*
|
||||
* @template Node The generic Node type for the DOM adapter being used.
|
||||
* @template ElementNode The Node type for elements for the DOM adapter being used.
|
||||
* @param elem The element to test if it matches the query.
|
||||
* @param query can be either a CSS selector string or a compiled query function.
|
||||
* @param [options] options for querying the document.
|
||||
* @see compile for supported selector queries.
|
||||
* @returns
|
||||
*/
|
||||
export declare function is<Node, ElementNode extends Node>(elem: ElementNode, query: Query<ElementNode>, options?: Options<Node, ElementNode>): boolean;
|
||||
/**
|
||||
* Alias for selectAll(query, elems, options).
|
||||
* @see [compile] for supported selector queries.
|
||||
*/
|
||||
export default selectAll;
|
||||
export { filters, pseudos, aliases } from "./pseudo-selectors";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACR,aAAa,EACb,OAAO,EAEP,KAAK,EACL,OAAO,EAEV,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,OAAO,EAAE,CAAC;AA0CxB;;GAEG;AACH,eAAO,MAAM,OAAO,gNAA0B,CAAC;AAC/C,eAAO,MAAM,cAAc,qNAA6B,CAAC;AACzD,eAAO,MAAM,aAAa,mNAA4B,CAAC;AA6BvD,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EACzD,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,EACpB,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,EACnC,sBAAsB,UAAQ,GAC/B,IAAI,EAAE,CAYR;AAiBD;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,mKASrB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,wKASrB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,EAAE,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EAC7C,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,EACzB,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,GACrC,OAAO,CAKT;AAED;;;GAGG;AACH,eAAe,SAAS,CAAC;AAGzB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC"}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.aliases = exports.pseudos = exports.filters = exports.is = exports.selectOne = exports.selectAll = exports.prepareContext = exports._compileToken = exports._compileUnsafe = exports.compile = void 0;
|
||||
var DomUtils = __importStar(require("domutils"));
|
||||
var boolbase_1 = require("boolbase");
|
||||
var compile_1 = require("./compile");
|
||||
var subselects_1 = require("./pseudo-selectors/subselects");
|
||||
var defaultEquals = function (a, b) { return a === b; };
|
||||
var defaultOptions = {
|
||||
adapter: DomUtils,
|
||||
equals: defaultEquals,
|
||||
};
|
||||
function convertOptionFormats(options) {
|
||||
var _a, _b, _c, _d;
|
||||
/*
|
||||
* We force one format of options to the other one.
|
||||
*/
|
||||
// @ts-expect-error Default options may have incompatible `Node` / `ElementNode`.
|
||||
var opts = options !== null && options !== void 0 ? options : defaultOptions;
|
||||
// @ts-expect-error Same as above.
|
||||
(_a = opts.adapter) !== null && _a !== void 0 ? _a : (opts.adapter = DomUtils);
|
||||
// @ts-expect-error `equals` does not exist on `Options`
|
||||
(_b = opts.equals) !== null && _b !== void 0 ? _b : (opts.equals = (_d = (_c = opts.adapter) === null || _c === void 0 ? void 0 : _c.equals) !== null && _d !== void 0 ? _d : defaultEquals);
|
||||
return opts;
|
||||
}
|
||||
function wrapCompile(func) {
|
||||
return function addAdapter(selector, options, context) {
|
||||
var opts = convertOptionFormats(options);
|
||||
return func(selector, opts, context);
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Compiles the query, returns a function.
|
||||
*/
|
||||
exports.compile = wrapCompile(compile_1.compile);
|
||||
exports._compileUnsafe = wrapCompile(compile_1.compileUnsafe);
|
||||
exports._compileToken = wrapCompile(compile_1.compileToken);
|
||||
function getSelectorFunc(searchFunc) {
|
||||
return function select(query, elements, options) {
|
||||
var opts = convertOptionFormats(options);
|
||||
if (typeof query !== "function") {
|
||||
query = (0, compile_1.compileUnsafe)(query, opts, elements);
|
||||
}
|
||||
var filteredElements = prepareContext(elements, opts.adapter, query.shouldTestNextSiblings);
|
||||
return searchFunc(query, filteredElements, opts);
|
||||
};
|
||||
}
|
||||
function prepareContext(elems, adapter, shouldTestNextSiblings) {
|
||||
if (shouldTestNextSiblings === void 0) { shouldTestNextSiblings = false; }
|
||||
/*
|
||||
* Add siblings if the query requires them.
|
||||
* See https://github.com/fb55/css-select/pull/43#issuecomment-225414692
|
||||
*/
|
||||
if (shouldTestNextSiblings) {
|
||||
elems = appendNextSiblings(elems, adapter);
|
||||
}
|
||||
return Array.isArray(elems)
|
||||
? adapter.removeSubsets(elems)
|
||||
: adapter.getChildren(elems);
|
||||
}
|
||||
exports.prepareContext = prepareContext;
|
||||
function appendNextSiblings(elem, adapter) {
|
||||
// Order matters because jQuery seems to check the children before the siblings
|
||||
var elems = Array.isArray(elem) ? elem.slice(0) : [elem];
|
||||
var elemsLength = elems.length;
|
||||
for (var i = 0; i < elemsLength; i++) {
|
||||
var nextSiblings = (0, subselects_1.getNextSiblings)(elems[i], adapter);
|
||||
elems.push.apply(elems, nextSiblings);
|
||||
}
|
||||
return elems;
|
||||
}
|
||||
/**
|
||||
* @template Node The generic Node type for the DOM adapter being used.
|
||||
* @template ElementNode The Node type for elements for the DOM adapter being used.
|
||||
* @param elems Elements to query. If it is an element, its children will be queried..
|
||||
* @param query can be either a CSS selector string or a compiled query function.
|
||||
* @param [options] options for querying the document.
|
||||
* @see compile for supported selector queries.
|
||||
* @returns All matching elements.
|
||||
*
|
||||
*/
|
||||
exports.selectAll = getSelectorFunc(function (query, elems, options) {
|
||||
return query === boolbase_1.falseFunc || !elems || elems.length === 0
|
||||
? []
|
||||
: options.adapter.findAll(query, elems);
|
||||
});
|
||||
/**
|
||||
* @template Node The generic Node type for the DOM adapter being used.
|
||||
* @template ElementNode The Node type for elements for the DOM adapter being used.
|
||||
* @param elems Elements to query. If it is an element, its children will be queried..
|
||||
* @param query can be either a CSS selector string or a compiled query function.
|
||||
* @param [options] options for querying the document.
|
||||
* @see compile for supported selector queries.
|
||||
* @returns the first match, or null if there was no match.
|
||||
*/
|
||||
exports.selectOne = getSelectorFunc(function (query, elems, options) {
|
||||
return query === boolbase_1.falseFunc || !elems || elems.length === 0
|
||||
? null
|
||||
: options.adapter.findOne(query, elems);
|
||||
});
|
||||
/**
|
||||
* Tests whether or not an element is matched by query.
|
||||
*
|
||||
* @template Node The generic Node type for the DOM adapter being used.
|
||||
* @template ElementNode The Node type for elements for the DOM adapter being used.
|
||||
* @param elem The element to test if it matches the query.
|
||||
* @param query can be either a CSS selector string or a compiled query function.
|
||||
* @param [options] options for querying the document.
|
||||
* @see compile for supported selector queries.
|
||||
* @returns
|
||||
*/
|
||||
function is(elem, query, options) {
|
||||
var opts = convertOptionFormats(options);
|
||||
return (typeof query === "function" ? query : (0, compile_1.compile)(query, opts))(elem);
|
||||
}
|
||||
exports.is = is;
|
||||
/**
|
||||
* Alias for selectAll(query, elems, options).
|
||||
* @see [compile] for supported selector queries.
|
||||
*/
|
||||
exports.default = exports.selectAll;
|
||||
// Export filters, pseudos and aliases to allow users to supply their own.
|
||||
var pseudo_selectors_1 = require("./pseudo-selectors");
|
||||
Object.defineProperty(exports, "filters", { enumerable: true, get: function () { return pseudo_selectors_1.filters; } });
|
||||
Object.defineProperty(exports, "pseudos", { enumerable: true, get: function () { return pseudo_selectors_1.pseudos; } });
|
||||
Object.defineProperty(exports, "aliases", { enumerable: true, get: function () { return pseudo_selectors_1.aliases; } });
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type { Traversal } from "css-what";
|
||||
import type { InternalSelector } from "./types";
|
||||
export declare const procedure: Record<InternalSelector["type"], number>;
|
||||
export declare function isTraversal(t: InternalSelector): t is Traversal;
|
||||
//# sourceMappingURL=procedure.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"procedure.d.ts","sourceRoot":"","sources":["../src/procedure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEhD,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,MAAM,CAa9D,CAAC;AAEF,wBAAgB,WAAW,CAAC,CAAC,EAAE,gBAAgB,GAAG,CAAC,IAAI,SAAS,CAE/D"}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isTraversal = exports.procedure = void 0;
|
||||
exports.procedure = {
|
||||
universal: 50,
|
||||
tag: 30,
|
||||
attribute: 1,
|
||||
pseudo: 0,
|
||||
"pseudo-element": 0,
|
||||
"column-combinator": -1,
|
||||
descendant: -1,
|
||||
child: -1,
|
||||
parent: -1,
|
||||
sibling: -1,
|
||||
adjacent: -1,
|
||||
_flexibleDescendant: -1,
|
||||
};
|
||||
function isTraversal(t) {
|
||||
return exports.procedure[t.type] < 0;
|
||||
}
|
||||
exports.isTraversal = isTraversal;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Aliases are pseudos that are expressed as selectors.
|
||||
*/
|
||||
export declare const aliases: Record<string, string>;
|
||||
//# sourceMappingURL=aliases.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"aliases.d.ts","sourceRoot":"","sources":["../../src/pseudo-selectors/aliases.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAwC1C,CAAC"}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.aliases = void 0;
|
||||
/**
|
||||
* Aliases are pseudos that are expressed as selectors.
|
||||
*/
|
||||
exports.aliases = {
|
||||
// Links
|
||||
"any-link": ":is(a, area, link)[href]",
|
||||
link: ":any-link:not(:visited)",
|
||||
// Forms
|
||||
// https://html.spec.whatwg.org/multipage/scripting.html#disabled-elements
|
||||
disabled: ":is(\n :is(button, input, select, textarea, optgroup, option)[disabled],\n optgroup[disabled] > option,\n fieldset[disabled]:not(fieldset[disabled] legend:first-of-type *)\n )",
|
||||
enabled: ":not(:disabled)",
|
||||
checked: ":is(:is(input[type=radio], input[type=checkbox])[checked], option:selected)",
|
||||
required: ":is(input, select, textarea)[required]",
|
||||
optional: ":is(input, select, textarea):not([required])",
|
||||
// JQuery extensions
|
||||
// https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-selectedness
|
||||
selected: "option:is([selected], select:not([multiple]):not(:has(> option[selected])) > :first-of-type)",
|
||||
checkbox: "[type=checkbox]",
|
||||
file: "[type=file]",
|
||||
password: "[type=password]",
|
||||
radio: "[type=radio]",
|
||||
reset: "[type=reset]",
|
||||
image: "[type=image]",
|
||||
submit: "[type=submit]",
|
||||
parent: ":not(:empty)",
|
||||
header: ":is(h1, h2, h3, h4, h5, h6)",
|
||||
button: ":is(button, input[type=button])",
|
||||
input: ":is(input, textarea, select, button)",
|
||||
text: "input:is(:not([type!='']), [type=text])",
|
||||
};
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { CompiledQuery, InternalOptions } from "../types";
|
||||
export declare type Filter = <Node, ElementNode extends Node>(next: CompiledQuery<ElementNode>, text: string, options: InternalOptions<Node, ElementNode>, context?: Node[]) => CompiledQuery<ElementNode>;
|
||||
export declare const filters: Record<string, Filter>;
|
||||
//# sourceMappingURL=filters.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"filters.d.ts","sourceRoot":"","sources":["../../src/pseudo-selectors/filters.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAW,MAAM,UAAU,CAAC;AAExE,oBAAY,MAAM,GAAG,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EAChD,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,EAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,OAAO,CAAC,EAAE,IAAI,EAAE,KACf,aAAa,CAAC,WAAW,CAAC,CAAC;AAYhC,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA2I1C,CAAC"}
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.filters = void 0;
|
||||
var nth_check_1 = __importDefault(require("nth-check"));
|
||||
var boolbase_1 = require("boolbase");
|
||||
function getChildFunc(next, adapter) {
|
||||
return function (elem) {
|
||||
var parent = adapter.getParent(elem);
|
||||
return parent != null && adapter.isTag(parent) && next(elem);
|
||||
};
|
||||
}
|
||||
exports.filters = {
|
||||
contains: function (next, text, _a) {
|
||||
var adapter = _a.adapter;
|
||||
return function contains(elem) {
|
||||
return next(elem) && adapter.getText(elem).includes(text);
|
||||
};
|
||||
},
|
||||
icontains: function (next, text, _a) {
|
||||
var adapter = _a.adapter;
|
||||
var itext = text.toLowerCase();
|
||||
return function icontains(elem) {
|
||||
return (next(elem) &&
|
||||
adapter.getText(elem).toLowerCase().includes(itext));
|
||||
};
|
||||
},
|
||||
// Location specific methods
|
||||
"nth-child": function (next, rule, _a) {
|
||||
var adapter = _a.adapter, equals = _a.equals;
|
||||
var func = (0, nth_check_1.default)(rule);
|
||||
if (func === boolbase_1.falseFunc)
|
||||
return boolbase_1.falseFunc;
|
||||
if (func === boolbase_1.trueFunc)
|
||||
return getChildFunc(next, adapter);
|
||||
return function nthChild(elem) {
|
||||
var siblings = adapter.getSiblings(elem);
|
||||
var pos = 0;
|
||||
for (var i = 0; i < siblings.length; i++) {
|
||||
if (equals(elem, siblings[i]))
|
||||
break;
|
||||
if (adapter.isTag(siblings[i])) {
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
return func(pos) && next(elem);
|
||||
};
|
||||
},
|
||||
"nth-last-child": function (next, rule, _a) {
|
||||
var adapter = _a.adapter, equals = _a.equals;
|
||||
var func = (0, nth_check_1.default)(rule);
|
||||
if (func === boolbase_1.falseFunc)
|
||||
return boolbase_1.falseFunc;
|
||||
if (func === boolbase_1.trueFunc)
|
||||
return getChildFunc(next, adapter);
|
||||
return function nthLastChild(elem) {
|
||||
var siblings = adapter.getSiblings(elem);
|
||||
var pos = 0;
|
||||
for (var i = siblings.length - 1; i >= 0; i--) {
|
||||
if (equals(elem, siblings[i]))
|
||||
break;
|
||||
if (adapter.isTag(siblings[i])) {
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
return func(pos) && next(elem);
|
||||
};
|
||||
},
|
||||
"nth-of-type": function (next, rule, _a) {
|
||||
var adapter = _a.adapter, equals = _a.equals;
|
||||
var func = (0, nth_check_1.default)(rule);
|
||||
if (func === boolbase_1.falseFunc)
|
||||
return boolbase_1.falseFunc;
|
||||
if (func === boolbase_1.trueFunc)
|
||||
return getChildFunc(next, adapter);
|
||||
return function nthOfType(elem) {
|
||||
var siblings = adapter.getSiblings(elem);
|
||||
var pos = 0;
|
||||
for (var i = 0; i < siblings.length; i++) {
|
||||
var currentSibling = siblings[i];
|
||||
if (equals(elem, currentSibling))
|
||||
break;
|
||||
if (adapter.isTag(currentSibling) &&
|
||||
adapter.getName(currentSibling) === adapter.getName(elem)) {
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
return func(pos) && next(elem);
|
||||
};
|
||||
},
|
||||
"nth-last-of-type": function (next, rule, _a) {
|
||||
var adapter = _a.adapter, equals = _a.equals;
|
||||
var func = (0, nth_check_1.default)(rule);
|
||||
if (func === boolbase_1.falseFunc)
|
||||
return boolbase_1.falseFunc;
|
||||
if (func === boolbase_1.trueFunc)
|
||||
return getChildFunc(next, adapter);
|
||||
return function nthLastOfType(elem) {
|
||||
var siblings = adapter.getSiblings(elem);
|
||||
var pos = 0;
|
||||
for (var i = siblings.length - 1; i >= 0; i--) {
|
||||
var currentSibling = siblings[i];
|
||||
if (equals(elem, currentSibling))
|
||||
break;
|
||||
if (adapter.isTag(currentSibling) &&
|
||||
adapter.getName(currentSibling) === adapter.getName(elem)) {
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
return func(pos) && next(elem);
|
||||
};
|
||||
},
|
||||
// TODO determine the actual root element
|
||||
root: function (next, _rule, _a) {
|
||||
var adapter = _a.adapter;
|
||||
return function (elem) {
|
||||
var parent = adapter.getParent(elem);
|
||||
return (parent == null || !adapter.isTag(parent)) && next(elem);
|
||||
};
|
||||
},
|
||||
scope: function (next, rule, options, context) {
|
||||
var equals = options.equals;
|
||||
if (!context || context.length === 0) {
|
||||
// Equivalent to :root
|
||||
return exports.filters.root(next, rule, options);
|
||||
}
|
||||
if (context.length === 1) {
|
||||
// NOTE: can't be unpacked, as :has uses this for side-effects
|
||||
return function (elem) { return equals(context[0], elem) && next(elem); };
|
||||
}
|
||||
return function (elem) { return context.includes(elem) && next(elem); };
|
||||
},
|
||||
hover: dynamicStatePseudo("isHovered"),
|
||||
visited: dynamicStatePseudo("isVisited"),
|
||||
active: dynamicStatePseudo("isActive"),
|
||||
};
|
||||
/**
|
||||
* Dynamic state pseudos. These depend on optional Adapter methods.
|
||||
*
|
||||
* @param name The name of the adapter method to call.
|
||||
* @returns Pseudo for the `filters` object.
|
||||
*/
|
||||
function dynamicStatePseudo(name) {
|
||||
return function dynamicPseudo(next, _rule, _a) {
|
||||
var adapter = _a.adapter;
|
||||
var func = adapter[name];
|
||||
if (typeof func !== "function") {
|
||||
return boolbase_1.falseFunc;
|
||||
}
|
||||
return function active(elem) {
|
||||
return func(elem) && next(elem);
|
||||
};
|
||||
};
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import type { CompiledQuery, InternalOptions, CompileToken } from "../types";
|
||||
import { PseudoSelector } from "css-what";
|
||||
import { filters } from "./filters";
|
||||
import { pseudos } from "./pseudos";
|
||||
import { aliases } from "./aliases";
|
||||
export { filters, pseudos, aliases };
|
||||
export declare function compilePseudoSelector<Node, ElementNode extends Node>(next: CompiledQuery<ElementNode>, selector: PseudoSelector, options: InternalOptions<Node, ElementNode>, context: Node[] | undefined, compileToken: CompileToken<Node, ElementNode>): CompiledQuery<ElementNode>;
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pseudo-selectors/index.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAS,cAAc,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAoB,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAErC,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EAChE,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,EAChC,QAAQ,EAAE,cAAc,EACxB,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,OAAO,EAAE,IAAI,EAAE,GAAG,SAAS,EAC3B,YAAY,EAAE,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,GAC9C,aAAa,CAAC,WAAW,CAAC,CA6B5B"}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.compilePseudoSelector = exports.aliases = exports.pseudos = exports.filters = void 0;
|
||||
/*
|
||||
* Pseudo selectors
|
||||
*
|
||||
* Pseudo selectors are available in three forms:
|
||||
*
|
||||
* 1. Filters are called when the selector is compiled and return a function
|
||||
* that has to return either false, or the results of `next()`.
|
||||
* 2. Pseudos are called on execution. They have to return a boolean.
|
||||
* 3. Subselects work like filters, but have an embedded selector that will be run separately.
|
||||
*
|
||||
* Filters are great if you want to do some pre-processing, or change the call order
|
||||
* of `next()` and your code.
|
||||
* Pseudos should be used to implement simple checks.
|
||||
*/
|
||||
var boolbase_1 = require("boolbase");
|
||||
var css_what_1 = require("css-what");
|
||||
var filters_1 = require("./filters");
|
||||
Object.defineProperty(exports, "filters", { enumerable: true, get: function () { return filters_1.filters; } });
|
||||
var pseudos_1 = require("./pseudos");
|
||||
Object.defineProperty(exports, "pseudos", { enumerable: true, get: function () { return pseudos_1.pseudos; } });
|
||||
var aliases_1 = require("./aliases");
|
||||
Object.defineProperty(exports, "aliases", { enumerable: true, get: function () { return aliases_1.aliases; } });
|
||||
var subselects_1 = require("./subselects");
|
||||
function compilePseudoSelector(next, selector, options, context, compileToken) {
|
||||
var name = selector.name, data = selector.data;
|
||||
if (Array.isArray(data)) {
|
||||
return subselects_1.subselects[name](next, data, options, context, compileToken);
|
||||
}
|
||||
if (name in aliases_1.aliases) {
|
||||
if (data != null) {
|
||||
throw new Error("Pseudo ".concat(name, " doesn't have any arguments"));
|
||||
}
|
||||
// The alias has to be parsed here, to make sure options are respected.
|
||||
var alias = (0, css_what_1.parse)(aliases_1.aliases[name]);
|
||||
return subselects_1.subselects.is(next, alias, options, context, compileToken);
|
||||
}
|
||||
if (name in filters_1.filters) {
|
||||
return filters_1.filters[name](next, data, options, context);
|
||||
}
|
||||
if (name in pseudos_1.pseudos) {
|
||||
var pseudo_1 = pseudos_1.pseudos[name];
|
||||
(0, pseudos_1.verifyPseudoArgs)(pseudo_1, name, data);
|
||||
return pseudo_1 === boolbase_1.falseFunc
|
||||
? boolbase_1.falseFunc
|
||||
: next === boolbase_1.trueFunc
|
||||
? function (elem) { return pseudo_1(elem, options, data); }
|
||||
: function (elem) { return pseudo_1(elem, options, data) && next(elem); };
|
||||
}
|
||||
throw new Error("unmatched pseudo-class :".concat(name));
|
||||
}
|
||||
exports.compilePseudoSelector = compilePseudoSelector;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import { PseudoSelector } from "css-what";
|
||||
import type { InternalOptions } from "../types";
|
||||
export declare type Pseudo = <Node, ElementNode extends Node>(elem: ElementNode, options: InternalOptions<Node, ElementNode>, subselect?: ElementNode | string | null) => boolean;
|
||||
export declare const pseudos: Record<string, Pseudo>;
|
||||
export declare function verifyPseudoArgs(func: Pseudo, name: string, subselect: PseudoSelector["data"]): void;
|
||||
//# sourceMappingURL=pseudos.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"pseudos.d.ts","sourceRoot":"","sources":["../../src/pseudo-selectors/pseudos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD,oBAAY,MAAM,GAAG,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EAChD,IAAI,EAAE,WAAW,EACjB,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,SAAS,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,KACtC,OAAO,CAAC;AAGb,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA8E1C,CAAC;AAEF,wBAAgB,gBAAgB,CAC5B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,cAAc,CAAC,MAAM,CAAC,GAClC,IAAI,CAQN"}
|
||||
+89
@@ -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;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import { CompileToken } from "./../types";
|
||||
import type { Selector } from "css-what";
|
||||
import type { CompiledQuery, InternalOptions, Adapter } from "../types";
|
||||
/** Used as a placeholder for :has. Will be replaced with the actual element. */
|
||||
export declare const PLACEHOLDER_ELEMENT: {};
|
||||
export declare function ensureIsTag<Node, ElementNode extends Node>(next: CompiledQuery<ElementNode>, adapter: Adapter<Node, ElementNode>): CompiledQuery<Node>;
|
||||
export declare type Subselect = <Node, ElementNode extends Node>(next: CompiledQuery<ElementNode>, subselect: Selector[][], options: InternalOptions<Node, ElementNode>, context: Node[] | undefined, compileToken: CompileToken<Node, ElementNode>) => CompiledQuery<ElementNode>;
|
||||
export declare function getNextSiblings<Node, ElementNode extends Node>(elem: Node, adapter: Adapter<Node, ElementNode>): ElementNode[];
|
||||
export declare const subselects: Record<string, Subselect>;
|
||||
//# sourceMappingURL=subselects.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"subselects.d.ts","sourceRoot":"","sources":["../../src/pseudo-selectors/subselects.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGxE,gFAAgF;AAChF,eAAO,MAAM,mBAAmB,IAAK,CAAC;AAEtC,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EACtD,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,EAChC,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,GACpC,aAAa,CAAC,IAAI,CAAC,CAGrB;AAED,oBAAY,SAAS,GAAG,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EACnD,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,EAChC,SAAS,EAAE,QAAQ,EAAE,EAAE,EACvB,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,OAAO,EAAE,IAAI,EAAE,GAAG,SAAS,EAC3B,YAAY,EAAE,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,KAC5C,aAAa,CAAC,WAAW,CAAC,CAAC;AAEhC,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,EAC1D,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,GACpC,WAAW,EAAE,CAMf;AAkBD,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CA6EhD,CAAC"}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
"use strict";
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.subselects = exports.getNextSiblings = exports.ensureIsTag = exports.PLACEHOLDER_ELEMENT = void 0;
|
||||
var boolbase_1 = require("boolbase");
|
||||
var procedure_1 = require("../procedure");
|
||||
/** Used as a placeholder for :has. Will be replaced with the actual element. */
|
||||
exports.PLACEHOLDER_ELEMENT = {};
|
||||
function ensureIsTag(next, adapter) {
|
||||
if (next === boolbase_1.falseFunc)
|
||||
return boolbase_1.falseFunc;
|
||||
return function (elem) { return adapter.isTag(elem) && next(elem); };
|
||||
}
|
||||
exports.ensureIsTag = ensureIsTag;
|
||||
function getNextSiblings(elem, adapter) {
|
||||
var siblings = adapter.getSiblings(elem);
|
||||
if (siblings.length <= 1)
|
||||
return [];
|
||||
var elemIndex = siblings.indexOf(elem);
|
||||
if (elemIndex < 0 || elemIndex === siblings.length - 1)
|
||||
return [];
|
||||
return siblings.slice(elemIndex + 1).filter(adapter.isTag);
|
||||
}
|
||||
exports.getNextSiblings = getNextSiblings;
|
||||
var is = function (next, token, options, context, compileToken) {
|
||||
var opts = {
|
||||
xmlMode: !!options.xmlMode,
|
||||
adapter: options.adapter,
|
||||
equals: options.equals,
|
||||
};
|
||||
var func = compileToken(token, opts, context);
|
||||
return function (elem) { return func(elem) && next(elem); };
|
||||
};
|
||||
/*
|
||||
* :not, :has, :is, :matches and :where have to compile selectors
|
||||
* doing this in src/pseudos.ts would lead to circular dependencies,
|
||||
* so we add them here
|
||||
*/
|
||||
exports.subselects = {
|
||||
is: is,
|
||||
/**
|
||||
* `:matches` and `:where` are aliases for `:is`.
|
||||
*/
|
||||
matches: is,
|
||||
where: is,
|
||||
not: function (next, token, options, context, compileToken) {
|
||||
var opts = {
|
||||
xmlMode: !!options.xmlMode,
|
||||
adapter: options.adapter,
|
||||
equals: options.equals,
|
||||
};
|
||||
var func = compileToken(token, opts, context);
|
||||
if (func === boolbase_1.falseFunc)
|
||||
return next;
|
||||
if (func === boolbase_1.trueFunc)
|
||||
return boolbase_1.falseFunc;
|
||||
return function not(elem) {
|
||||
return !func(elem) && next(elem);
|
||||
};
|
||||
},
|
||||
has: function (next, subselect, options, _context, compileToken) {
|
||||
var adapter = options.adapter;
|
||||
var opts = {
|
||||
xmlMode: !!options.xmlMode,
|
||||
adapter: adapter,
|
||||
equals: options.equals,
|
||||
};
|
||||
// @ts-expect-error Uses an array as a pointer to the current element (side effects)
|
||||
var context = subselect.some(function (s) {
|
||||
return s.some(procedure_1.isTraversal);
|
||||
})
|
||||
? [exports.PLACEHOLDER_ELEMENT]
|
||||
: undefined;
|
||||
var compiled = compileToken(subselect, opts, context);
|
||||
if (compiled === boolbase_1.falseFunc)
|
||||
return boolbase_1.falseFunc;
|
||||
if (compiled === boolbase_1.trueFunc) {
|
||||
return function (elem) {
|
||||
return adapter.getChildren(elem).some(adapter.isTag) && next(elem);
|
||||
};
|
||||
}
|
||||
var hasElement = ensureIsTag(compiled, adapter);
|
||||
var _a = compiled.shouldTestNextSiblings, shouldTestNextSiblings = _a === void 0 ? false : _a;
|
||||
/*
|
||||
* `shouldTestNextSiblings` will only be true if the query starts with
|
||||
* a traversal (sibling or adjacent). That means we will always have a context.
|
||||
*/
|
||||
if (context) {
|
||||
return function (elem) {
|
||||
context[0] = elem;
|
||||
var childs = adapter.getChildren(elem);
|
||||
var nextElements = shouldTestNextSiblings
|
||||
? __spreadArray(__spreadArray([], childs, true), getNextSiblings(elem, adapter), true) : childs;
|
||||
return (next(elem) && adapter.existsOne(hasElement, nextElements));
|
||||
};
|
||||
}
|
||||
return function (elem) {
|
||||
return next(elem) &&
|
||||
adapter.existsOne(hasElement, adapter.getChildren(elem));
|
||||
};
|
||||
},
|
||||
};
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import type { InternalSelector } from "./types";
|
||||
/**
|
||||
* Sort the parts of the passed selector,
|
||||
* as there is potential for optimization
|
||||
* (some types of selectors are faster than others)
|
||||
*
|
||||
* @param arr Selector to sort
|
||||
*/
|
||||
export default function sortByProcedure(arr: InternalSelector[]): void;
|
||||
//# sourceMappingURL=sort.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../src/sort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAehD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,GAAG,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAerE"}
|
||||
+40
-35
@@ -1,15 +1,8 @@
|
||||
module.exports = sortByProcedure;
|
||||
|
||||
/*
|
||||
sort the parts of the passed selector,
|
||||
as there is potential for optimization
|
||||
(some types of selectors are faster than others)
|
||||
*/
|
||||
|
||||
var procedure = require("./procedure.json");
|
||||
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var css_what_1 = require("css-what");
|
||||
var procedure_1 = require("./procedure");
|
||||
var attributes = {
|
||||
__proto__: null,
|
||||
exists: 10,
|
||||
equals: 8,
|
||||
not: 7,
|
||||
@@ -17,16 +10,21 @@ var attributes = {
|
||||
end: 6,
|
||||
any: 5,
|
||||
hyphen: 4,
|
||||
element: 4
|
||||
element: 4,
|
||||
};
|
||||
|
||||
/**
|
||||
* Sort the parts of the passed selector,
|
||||
* as there is potential for optimization
|
||||
* (some types of selectors are faster than others)
|
||||
*
|
||||
* @param arr Selector to sort
|
||||
*/
|
||||
function sortByProcedure(arr) {
|
||||
var procs = arr.map(getProcedure);
|
||||
for (var i = 1; i < arr.length; i++) {
|
||||
var procNew = procs[i];
|
||||
|
||||
if (procNew < 0) continue;
|
||||
|
||||
if (procNew < 0)
|
||||
continue;
|
||||
for (var j = i - 1; j >= 0 && procNew < procs[j]; j--) {
|
||||
var token = arr[j + 1];
|
||||
arr[j + 1] = arr[j];
|
||||
@@ -36,43 +34,50 @@ function sortByProcedure(arr) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.default = sortByProcedure;
|
||||
function getProcedure(token) {
|
||||
var proc = procedure[token.type];
|
||||
|
||||
if (proc === procedure.attribute) {
|
||||
var proc = procedure_1.procedure[token.type];
|
||||
if (token.type === css_what_1.SelectorType.Attribute) {
|
||||
proc = attributes[token.action];
|
||||
|
||||
if (proc === attributes.equals && token.name === "id") {
|
||||
//prefer ID selectors (eg. #ID)
|
||||
// Prefer ID selectors (eg. #ID)
|
||||
proc = 9;
|
||||
}
|
||||
|
||||
if (token.ignoreCase) {
|
||||
//ignoreCase adds some overhead, prefer "normal" token
|
||||
//this is a binary operation, to ensure it's still an int
|
||||
/*
|
||||
* IgnoreCase adds some overhead, prefer "normal" token
|
||||
* this is a binary operation, to ensure it's still an int
|
||||
*/
|
||||
proc >>= 1;
|
||||
}
|
||||
} else if (proc === procedure.pseudo) {
|
||||
}
|
||||
else if (token.type === css_what_1.SelectorType.Pseudo) {
|
||||
if (!token.data) {
|
||||
proc = 3;
|
||||
} else if (token.name === "has" || token.name === "contains") {
|
||||
proc = 0; //expensive in any case
|
||||
} else if (token.name === "matches" || token.name === "not") {
|
||||
}
|
||||
else if (token.name === "has" || token.name === "contains") {
|
||||
proc = 0; // Expensive in any case
|
||||
}
|
||||
else if (Array.isArray(token.data)) {
|
||||
// "matches" and "not"
|
||||
proc = 0;
|
||||
for (var i = 0; i < token.data.length; i++) {
|
||||
//TODO better handling of complex selectors
|
||||
if (token.data[i].length !== 1) continue;
|
||||
// TODO better handling of complex selectors
|
||||
if (token.data[i].length !== 1)
|
||||
continue;
|
||||
var cur = getProcedure(token.data[i][0]);
|
||||
//avoid executing :has or :contains
|
||||
// Avoid executing :has or :contains
|
||||
if (cur === 0) {
|
||||
proc = 0;
|
||||
break;
|
||||
}
|
||||
if (cur > proc) proc = cur;
|
||||
if (cur > proc)
|
||||
proc = cur;
|
||||
}
|
||||
if (token.data.length > 1 && proc > 0) proc -= 1;
|
||||
} else {
|
||||
if (token.data.length > 1 && proc > 0)
|
||||
proc -= 1;
|
||||
}
|
||||
else {
|
||||
proc = 1;
|
||||
}
|
||||
}
|
||||
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
import type { Selector } from "css-what";
|
||||
export declare type InternalSelector = Selector | {
|
||||
type: "_flexibleDescendant";
|
||||
};
|
||||
export declare type Predicate<Value> = (v: Value) => boolean;
|
||||
export interface Adapter<Node, ElementNode extends Node> {
|
||||
/**
|
||||
* Is the node a tag?
|
||||
*/
|
||||
isTag: (node: Node) => node is ElementNode;
|
||||
/**
|
||||
* Does at least one of passed element nodes pass the test predicate?
|
||||
*/
|
||||
existsOne: (test: Predicate<ElementNode>, elems: Node[]) => boolean;
|
||||
/**
|
||||
* Get the attribute value.
|
||||
*/
|
||||
getAttributeValue: (elem: ElementNode, name: string) => string | undefined;
|
||||
/**
|
||||
* Get the node's children
|
||||
*/
|
||||
getChildren: (node: Node) => Node[];
|
||||
/**
|
||||
* Get the name of the tag
|
||||
*/
|
||||
getName: (elem: ElementNode) => string;
|
||||
/**
|
||||
* Get the parent of the node
|
||||
*/
|
||||
getParent: (node: ElementNode) => ElementNode | null;
|
||||
/**
|
||||
* Get the siblings of the node. Note that unlike jQuery's `siblings` method,
|
||||
* this is expected to include the current node as well
|
||||
*/
|
||||
getSiblings: (node: Node) => Node[];
|
||||
/**
|
||||
* Returns the previous element sibling of a node.
|
||||
*/
|
||||
prevElementSibling?: (node: Node) => ElementNode | null;
|
||||
/**
|
||||
* Get the text content of the node, and its children if it has any.
|
||||
*/
|
||||
getText: (node: Node) => string;
|
||||
/**
|
||||
* Does the element have the named attribute?
|
||||
*/
|
||||
hasAttrib: (elem: ElementNode, name: string) => boolean;
|
||||
/**
|
||||
* Takes an array of nodes, and removes any duplicates, as well as any
|
||||
* nodes whose ancestors are also in the array.
|
||||
*/
|
||||
removeSubsets: (nodes: Node[]) => Node[];
|
||||
/**
|
||||
* Finds all of the element nodes in the array that match the test predicate,
|
||||
* as well as any of their children that match it.
|
||||
*/
|
||||
findAll: (test: Predicate<ElementNode>, nodes: Node[]) => ElementNode[];
|
||||
/**
|
||||
* Finds the first node in the array that matches the test predicate, or one
|
||||
* of its children.
|
||||
*/
|
||||
findOne: (test: Predicate<ElementNode>, elems: Node[]) => ElementNode | null;
|
||||
/**
|
||||
* The adapter can also optionally include an equals method, if your DOM
|
||||
* structure needs a custom equality test to compare two objects which refer
|
||||
* to the same underlying node. If not provided, `css-select` will fall back to
|
||||
* `a === b`.
|
||||
*/
|
||||
equals?: (a: Node, b: Node) => boolean;
|
||||
/**
|
||||
* Is the element in hovered state?
|
||||
*/
|
||||
isHovered?: (elem: ElementNode) => boolean;
|
||||
/**
|
||||
* Is the element in visited state?
|
||||
*/
|
||||
isVisited?: (elem: ElementNode) => boolean;
|
||||
/**
|
||||
* Is the element in active state?
|
||||
*/
|
||||
isActive?: (elem: ElementNode) => boolean;
|
||||
}
|
||||
export interface Options<Node, ElementNode extends Node> {
|
||||
/**
|
||||
* When enabled, tag names will be case-sensitive.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
xmlMode?: boolean;
|
||||
/**
|
||||
* Lower-case attribute names.
|
||||
*
|
||||
* @default !xmlMode
|
||||
*/
|
||||
lowerCaseAttributeNames?: boolean;
|
||||
/**
|
||||
* Lower-case tag names.
|
||||
*
|
||||
* @default !xmlMode
|
||||
*/
|
||||
lowerCaseTags?: boolean;
|
||||
/**
|
||||
* Is the document in quirks mode?
|
||||
*
|
||||
* This will lead to .className and #id being case-insensitive.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
quirksMode?: boolean;
|
||||
/**
|
||||
* The last function in the stack, will be called with the last element
|
||||
* that's looked at.
|
||||
*/
|
||||
rootFunc?: (element: ElementNode) => boolean;
|
||||
/**
|
||||
* The adapter to use when interacting with the backing DOM structure. By
|
||||
* default it uses the `domutils` module.
|
||||
*/
|
||||
adapter?: Adapter<Node, ElementNode>;
|
||||
/**
|
||||
* The context of the current query. Used to limit the scope of searches.
|
||||
* Can be matched directly using the `:scope` pseudo-selector.
|
||||
*/
|
||||
context?: Node | Node[];
|
||||
/**
|
||||
* Allow css-select to cache results for some selectors, sometimes greatly
|
||||
* improving querying performance. Disable this if your document can
|
||||
* change in between queries with the same compiled selector.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
cacheResults?: boolean;
|
||||
}
|
||||
export interface InternalOptions<Node, ElementNode extends Node> extends Options<Node, ElementNode> {
|
||||
adapter: Adapter<Node, ElementNode>;
|
||||
equals: (a: Node, b: Node) => boolean;
|
||||
}
|
||||
export interface CompiledQuery<ElementNode> {
|
||||
(node: ElementNode): boolean;
|
||||
shouldTestNextSiblings?: boolean;
|
||||
}
|
||||
export declare type Query<ElementNode> = string | CompiledQuery<ElementNode> | Selector[][];
|
||||
export declare type CompileToken<Node, ElementNode extends Node> = (token: InternalSelector[][], options: InternalOptions<Node, ElementNode>, context?: Node[] | Node) => CompiledQuery<ElementNode>;
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,oBAAY,gBAAgB,GAAG,QAAQ,GAAG;IAAE,IAAI,EAAE,qBAAqB,CAAA;CAAE,CAAC;AAE1E,oBAAY,SAAS,CAAC,KAAK,IAAI,CAAC,CAAC,EAAE,KAAK,KAAK,OAAO,CAAC;AACrD,MAAM,WAAW,OAAO,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI;IACnD;;OAEG;IACH,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,IAAI,WAAW,CAAC;IAE3C;;OAEG;IACH,SAAS,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC;IAEpE;;OAEG;IACH,iBAAiB,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAE3E;;OAEG;IACH,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,EAAE,CAAC;IAEpC;;OAEG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,MAAM,CAAC;IAEvC;;OAEG;IACH,SAAS,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,WAAW,GAAG,IAAI,CAAC;IAErD;;;OAGG;IACH,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,EAAE,CAAC;IAEpC;;OAEG;IACH,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,WAAW,GAAG,IAAI,CAAC;IAExD;;OAEG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC;IAEhC;;OAEG;IACH,SAAS,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAExD;;;OAGG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;IAEzC;;;OAGG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,CAAC;IAExE;;;OAGG;IACH,OAAO,EAAE,CACL,IAAI,EAAE,SAAS,CAAC,WAAW,CAAC,EAC5B,KAAK,EAAE,IAAI,EAAE,KACZ,WAAW,GAAG,IAAI,CAAC;IAExB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC;IAEvC;;OAEG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC;IAE3C;;OAEG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC;IAE3C;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC;CAC7C;AAED,MAAM,WAAW,OAAO,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI;IACnD;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC;IAC7C;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACrC;;;OAGG;IACH,OAAO,CAAC,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC;IACxB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CAC1B;AAGD,MAAM,WAAW,eAAe,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,CAC3D,SAAQ,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC;IAClC,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACpC,MAAM,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC;CACzC;AAED,MAAM,WAAW,aAAa,CAAC,WAAW;IACtC,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC;IAC7B,sBAAsB,CAAC,EAAE,OAAO,CAAC;CACpC;AACD,oBAAY,KAAK,CAAC,WAAW,IACvB,MAAM,GACN,aAAa,CAAC,WAAW,CAAC,GAC1B,QAAQ,EAAE,EAAE,CAAC;AACnB,oBAAY,YAAY,CAAC,IAAI,EAAE,WAAW,SAAS,IAAI,IAAI,CACvD,KAAK,EAAE,gBAAgB,EAAE,EAAE,EAC3B,OAAO,EAAE,eAAe,CAAC,IAAI,EAAE,WAAW,CAAC,EAC3C,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,KACtB,aAAa,CAAC,WAAW,CAAC,CAAC"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+55
-31
@@ -1,32 +1,33 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"css-select@2.1.0",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"css-select@4.3.0",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "css-select@2.1.0",
|
||||
"_id": "css-select@2.1.0",
|
||||
"_from": "css-select@4.3.0",
|
||||
"_id": "css-select@4.3.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-Dqk7LQKpwLoH3VovzZnkzegqNSuAziQyNZUcrdDM401iY+R5NkGBXGmtO05/yaXQziALuPogeG0b7UAgjnTJTQ==",
|
||||
"_integrity": "sha512-wPpOYtnsVontu2mODhA19JrqWxNsfdatRKd64kmpRbQgh1KtItko5sTnEpPdpSaJszTOhEMlF/RPz28qj4HqhQ==",
|
||||
"_location": "/css-select",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "css-select@2.1.0",
|
||||
"raw": "css-select@4.3.0",
|
||||
"name": "css-select",
|
||||
"escapedName": "css-select",
|
||||
"rawSpec": "2.1.0",
|
||||
"rawSpec": "4.3.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "2.1.0"
|
||||
"fetchSpec": "4.3.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/svgo"
|
||||
"/node-html-parser",
|
||||
"/renderkid"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/css-select/-/css-select-2.1.0.tgz",
|
||||
"_spec": "2.1.0",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/css-select/-/css-select-4.3.0.tgz",
|
||||
"_spec": "4.3.0",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "Felix Boehm",
|
||||
"email": "me@feedic.com"
|
||||
@@ -36,47 +37,70 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"boolbase": "^1.0.0",
|
||||
"css-what": "^3.2.1",
|
||||
"domutils": "^1.7.0",
|
||||
"nth-check": "^1.0.2"
|
||||
"css-what": "^6.0.1",
|
||||
"domhandler": "^4.3.1",
|
||||
"domutils": "^2.8.0",
|
||||
"nth-check": "^2.0.1"
|
||||
},
|
||||
"description": "a CSS selector compiler/engine",
|
||||
"devDependencies": {
|
||||
"@types/boolbase": "^1.0.1",
|
||||
"@types/jest": "^27.4.1",
|
||||
"@types/node": "^17.0.23",
|
||||
"@typescript-eslint/eslint-plugin": "^5.16.0",
|
||||
"@typescript-eslint/parser": "^5.16.0",
|
||||
"cheerio-soupselect": "^0.1.1",
|
||||
"coveralls": "^3.0.2",
|
||||
"eslint": "^6.0.0",
|
||||
"expect.js": "^0.3.1",
|
||||
"htmlparser2": "^4.0.0",
|
||||
"istanbul": "^0.4.5",
|
||||
"mocha": "^6.0.0",
|
||||
"mocha-lcov-reporter": "^1.3.0"
|
||||
"eslint": "^8.12.0",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"htmlparser2": "^7.2.0",
|
||||
"jest": "^27.5.1",
|
||||
"prettier": "^2.6.1",
|
||||
"ts-jest": "^27.1.4",
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"lib"
|
||||
],
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/fb55"
|
||||
},
|
||||
"homepage": "https://github.com/fb55/css-select#readme",
|
||||
"jest": {
|
||||
"preset": "ts-jest",
|
||||
"testEnvironment": "node",
|
||||
"testMatch": [
|
||||
"<rootDir>/test/*.ts"
|
||||
]
|
||||
},
|
||||
"keywords": [
|
||||
"css",
|
||||
"selector",
|
||||
"sizzle"
|
||||
],
|
||||
"license": "BSD-2-Clause",
|
||||
"main": "lib/index.js",
|
||||
"name": "css-select",
|
||||
"prettier": {
|
||||
"tabWidth": 4
|
||||
"tabWidth": 4,
|
||||
"proseWrap": "always"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/fb55/css-select.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coveralls": "npm run lint && npm run lcov && (cat coverage/lcov.info | coveralls || exit 0)",
|
||||
"lcov": "istanbul cover _mocha --report lcovonly -- -R spec",
|
||||
"lint": "eslint index.js lib/*.js test/*.js",
|
||||
"test": "mocha && npm run lint"
|
||||
"build": "tsc",
|
||||
"format": "npm run format:es && npm run format:prettier",
|
||||
"format:es": "npm run lint:es -- --fix",
|
||||
"format:prettier": "npm run prettier -- --write",
|
||||
"lint": "npm run lint:es && npm run lint:prettier",
|
||||
"lint:es": "eslint src",
|
||||
"lint:prettier": "npm run prettier -- --check",
|
||||
"prepare": "npm run build",
|
||||
"prettier": "prettier '**/*.{ts,md,json,yml}'",
|
||||
"test": "npm run test:jest && npm run lint",
|
||||
"test:jest": "jest"
|
||||
},
|
||||
"types": "index.d.ts",
|
||||
"version": "2.1.0"
|
||||
"types": "lib/index.d.ts",
|
||||
"version": "4.3.0"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user