mirror of
https://github.com/sern-handler/website
synced 2026-06-14 20:02:21 +00:00
feat: migrate to starlight
This commit is contained in:
19
node_modules/css-selector-parser/LICENSE
generated
vendored
Normal file
19
node_modules/css-selector-parser/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2013 Dulin Marat
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
162
node_modules/css-selector-parser/README.md
generated
vendored
Normal file
162
node_modules/css-selector-parser/README.md
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
css-selector-parser
|
||||
===================
|
||||
|
||||
* Fast and low memory CSS selector parser.
|
||||
* Parses CSS selector into object-model (AST).
|
||||
* Compliant with all historical and modern CSS specs.
|
||||
* Covered with tests.
|
||||
* Documented.
|
||||
* Supported CSS selector standards:
|
||||
* `css1`: https://www.w3.org/TR/CSS1/
|
||||
* `css2`: https://www.w3.org/TR/CSS2/
|
||||
* `css3`/`selectors-3`: https://www.w3.org/TR/selectors-3/
|
||||
* `selectors-4`: https://www.w3.org/TR/selectors-4/
|
||||
* `latest`: refers to `selectors-4`
|
||||
* `progressive`: `latest` + accepts unknown psudo-classes, psudo-elements and attribute case sensitivity modifiers
|
||||
|
||||
**Important:**
|
||||
* [Migrating from 1.x to 3.x](CHANGELOG.md#migrating-from-1x-to-3x).
|
||||
* [Migrating from 2.x to 3.x](CHANGELOG.md#migrating-from-2x-to-3x).
|
||||
* [Migrating from 1.x to 2.x](CHANGELOG.md#220).
|
||||
|
||||
Latest releases: [Changelog](CHANGELOG.md).
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
```
|
||||
npm install css-selector-parser
|
||||
```
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
### Parsing
|
||||
|
||||
```javascript
|
||||
import {createParser} from 'css-selector-parser';
|
||||
|
||||
const parse = createParser();
|
||||
const selector = parse('a[href^="/"], .container:has(nav) > a[href]:nth-child(2)::before');
|
||||
|
||||
console.log(selector);
|
||||
```
|
||||
|
||||
Produces:
|
||||
|
||||
```javascript
|
||||
({
|
||||
type: 'Selector',
|
||||
rules: [
|
||||
{
|
||||
type: 'Rule',
|
||||
items: [
|
||||
{ type: 'TagName', name: 'a' },
|
||||
{
|
||||
type: 'Attribute',
|
||||
name: 'href',
|
||||
operator: '^=',
|
||||
value: { type: 'String', value: '/' }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'Rule',
|
||||
items: [
|
||||
{ type: 'ClassName', name: 'container' },
|
||||
{
|
||||
type: 'PseudoClass',
|
||||
name: 'has',
|
||||
argument: {
|
||||
type: 'Selector',
|
||||
rules: [
|
||||
{
|
||||
type: 'Rule',
|
||||
items: [ { type: 'TagName', name: 'nav' } ]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
nestedRule: {
|
||||
type: 'Rule',
|
||||
items: [
|
||||
{ type: 'TagName', name: 'a' },
|
||||
{ type: 'Attribute', name: 'href' },
|
||||
{
|
||||
type: 'PseudoClass',
|
||||
name: 'nth-child',
|
||||
argument: { type: 'Formula', a: 0, b: 2 }
|
||||
},
|
||||
{
|
||||
type: 'PseudoElement',
|
||||
name: 'before'
|
||||
}
|
||||
],
|
||||
combinator: '>'
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
```
|
||||
|
||||
### Constructing AST and rendering
|
||||
|
||||
```javascript
|
||||
import {ast, render} from 'css-selector-parser';
|
||||
|
||||
const selector = ast.selector({
|
||||
rules: [
|
||||
ast.rule({
|
||||
items: [
|
||||
ast.tagName({name: 'a'}),
|
||||
ast.attribute({name: 'href', operator: '^=', value: ast.string({value: '/'})})
|
||||
]
|
||||
}),
|
||||
ast.rule({
|
||||
items: [
|
||||
ast.className({name: 'container'}),
|
||||
ast.pseudoClass({
|
||||
name: 'has',
|
||||
argument: ast.selector({
|
||||
rules: [ast.rule({items: [ast.tagName({name: 'nav'})]})]
|
||||
})
|
||||
})
|
||||
],
|
||||
nestedRule: ast.rule({
|
||||
combinator: '>',
|
||||
items: [
|
||||
ast.tagName({name: 'a'}),
|
||||
ast.attribute({name: 'href'}),
|
||||
ast.pseudoClass({
|
||||
name: 'nth-child',
|
||||
argument: ast.formula({a: 0, b: 2})
|
||||
}),
|
||||
ast.pseudoElement({name: 'before'})
|
||||
]
|
||||
})
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
console.log(render(selector)); // a[href^="/"], .container:has(nav) > a[href]:nth-child(2)::before
|
||||
```
|
||||
|
||||
API
|
||||
---
|
||||
|
||||
* [Full API Documentation](docs/modules.md)
|
||||
* [Parsing CSS selectors](docs/modules.md#createParser)
|
||||
* [Constructing CSS AST](docs/modules.md#ast)
|
||||
* [Rendering CSS AST](docs/modules.md#render)
|
||||
|
||||
LICENSE
|
||||
-------
|
||||
|
||||
MIT
|
||||
|
||||
## 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.
|
||||
286
node_modules/css-selector-parser/dist/cjs/ast.d.ts
generated
vendored
Normal file
286
node_modules/css-selector-parser/dist/cjs/ast.d.ts
generated
vendored
Normal file
@@ -0,0 +1,286 @@
|
||||
/**
|
||||
* CSS Selector AST root.
|
||||
* Contains list of CSS rules (separated by a comma in the input CSS selector string).
|
||||
* Generated by {@link AstFactory.selector ast.selector}.
|
||||
*/
|
||||
export interface AstSelector {
|
||||
type: 'Selector';
|
||||
/**
|
||||
* List of CSS rules. Every rule contains conditions. Selector is considered matched once at least one rule matches.
|
||||
*/
|
||||
rules: AstRule[];
|
||||
}
|
||||
/**
|
||||
* A single CSS rule that contains match conditions.
|
||||
* Can nest another rule with or without a combinator (i.e. `"div > span"`).
|
||||
* Generated by {@link AstFactory.rule ast.rule}.
|
||||
*/
|
||||
export interface AstRule {
|
||||
type: 'Rule';
|
||||
/** Items of a CSS rule. Can be tag, ids, class names, pseudo-classes and pseudo-elements. */
|
||||
items: (AstTagName | AstWildcardTag | AstId | AstClassName | AstAttribute | AstPseudoClass | AstPseudoElement)[];
|
||||
/** Rule combinator which was used to nest this rule (i.e. `">"` in case of `"div > span"` if the current rule is `"span"`). */
|
||||
combinator?: string;
|
||||
/** Nested rule if specified (i.e. `"div > span"`). */
|
||||
nestedRule?: AstRule;
|
||||
}
|
||||
/**
|
||||
* Named tag, i.e. `"div"`. Part of CSS Qualified Names.
|
||||
* Generated by {@link AstFactory.tagName ast.tagName}.
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors
|
||||
* @see https://drafts.csswg.org/css-namespaces-3/#css-qnames
|
||||
*/
|
||||
export interface AstTagName {
|
||||
type: 'TagName';
|
||||
/** Tag name, i.e. `"div"`. */
|
||||
name: string;
|
||||
/** Namespace according to https://www.w3.org/TR/css3-namespace/. */
|
||||
namespace?: AstNamespaceName | AstWildcardNamespace | AstNoNamespace;
|
||||
}
|
||||
/**
|
||||
* ID condition. Matches by id attribute value.
|
||||
* Generated by {@link AstFactory.id ast.id}.
|
||||
* https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors
|
||||
* @example "#root"
|
||||
*/
|
||||
export interface AstId {
|
||||
type: 'Id';
|
||||
/** ID name. I.e. `#root` -> `"root"`. */
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* Class name condition. Matches by class attribute value.
|
||||
* Generated by {@link AstFactory.className ast.className}.
|
||||
* https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors
|
||||
* @example ".user"
|
||||
*/
|
||||
export interface AstClassName {
|
||||
type: 'ClassName';
|
||||
/** ID name. I.e. `.user` -> `"user"`. */
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* Wildcard tag (universal selector): `*`.
|
||||
* Generated by {@link AstFactory.wildcardTag ast.wildcardTag}.
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors
|
||||
* @see https://drafts.csswg.org/css-namespaces-3/#css-qnames
|
||||
*/
|
||||
export interface AstWildcardTag {
|
||||
type: 'WildcardTag';
|
||||
/** Namespace according to https://www.w3.org/TR/css3-namespace/. */
|
||||
namespace?: AstNamespaceName | AstWildcardNamespace | AstNoNamespace;
|
||||
}
|
||||
/**
|
||||
* Named namespace declaration (i.e. `ns|div`).
|
||||
* Generated by {@link AstFactory.namespaceName ast.namespaceName}.
|
||||
* @see https://drafts.csswg.org/css-namespaces-3/#css-qnames
|
||||
*/
|
||||
export interface AstNamespaceName {
|
||||
type: 'NamespaceName';
|
||||
/** Namespace name (i.e. `"ns"` in case of `"ns|div"`). "*/
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* Wildcard namespace (universal selector): `*`.
|
||||
* Generated by {@link AstFactory.wildcardNamespace ast.wildcardNamespace}.
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors
|
||||
* @see https://drafts.csswg.org/css-namespaces-3/#css-qnames
|
||||
*/
|
||||
export interface AstWildcardNamespace {
|
||||
type: 'WildcardNamespace';
|
||||
}
|
||||
/**
|
||||
* Explicit no-namespace declaration (i.e. `|div`).
|
||||
* Generated by {@link AstFactory.noNamespace ast.noNamespace}.
|
||||
* @see https://drafts.csswg.org/css-namespaces-3/#css-qnames
|
||||
*/
|
||||
export interface AstNoNamespace {
|
||||
type: 'NoNamespace';
|
||||
}
|
||||
/**
|
||||
* Attribute selector.
|
||||
* Generated by {@link AstFactory.attribute ast.attribute}.
|
||||
* @example "[role='button' i]"
|
||||
*/
|
||||
export interface AstAttribute {
|
||||
type: 'Attribute';
|
||||
/** Attribute name (i.e. `"href"` in case if `"[href]"`). */
|
||||
name: string;
|
||||
/** Namespace according to https://drafts.csswg.org/selectors/#attrnmsp. */
|
||||
namespace?: AstNamespaceName | AstWildcardNamespace | AstNoNamespace;
|
||||
/** Comparison operator (i.e. `"|="` in case if `"[role|=button]"`). */
|
||||
operator?: string;
|
||||
/** Comparison value (i.e. `"button"` in case if `"[role=button]"`). */
|
||||
value?: AstString | AstSubstitution;
|
||||
/** Comparison case sensitivity modifier (i.e. `"i"` in case if `"[role='button' i]"`). */
|
||||
caseSensitivityModifier?: string;
|
||||
}
|
||||
/**
|
||||
* Pseudo-class selector.
|
||||
* Generated by {@link AstFactory.pseudoClass ast.pseudoClass}.
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements
|
||||
* @example ":lang(en)"
|
||||
*/
|
||||
export interface AstPseudoClass {
|
||||
type: 'PseudoClass';
|
||||
/** Pseudo-class name (i.e. `"hover"` in case of `":hover"`). */
|
||||
name: string;
|
||||
/** Pseudo-class value (i.e. `"en"` in case of `":lang(en)"`). */
|
||||
argument?: AstSubstitution | AstSelector | AstString | AstFormula | AstFormulaOfSelector;
|
||||
}
|
||||
/**
|
||||
* Pseudo-class selector.
|
||||
* Generated by {@link AstFactory.pseudoElement ast.pseudoElement}.
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements
|
||||
* @example "::before"
|
||||
*/
|
||||
export interface AstPseudoElement {
|
||||
type: 'PseudoElement';
|
||||
/** Pseudo-element name (i.e. `"before"` in case of `"::before"`). */
|
||||
name: string;
|
||||
/** Pseudo-element value (i.e. `"foo"` in case of `"::part(foo)"`). */
|
||||
argument?: AstSubstitution | AstString | AstSelector;
|
||||
}
|
||||
/**
|
||||
* String value. Can be used as attribute value of pseudo-class string value.
|
||||
* For instance `:lang(en)` -> `{type: 'AstPseudoClass'..., argument: {type: 'String', value: 'en'}}`.
|
||||
* Generated by {@link AstFactory.string ast.string}.
|
||||
*/
|
||||
export interface AstString {
|
||||
type: 'String';
|
||||
/** The actual string value. */
|
||||
value: string;
|
||||
}
|
||||
/**
|
||||
* Pseudo-class formula value. `a` is multiplier of `n` and `b` us added on top. Formula: `an + b`.
|
||||
* For instance `:nth-child(2n + 1)` -> `{type: 'AstPseudoClass'..., argument: {type: 'Formula', a: 2, b: 1}}`.
|
||||
* Generated by {@link AstFactory.formula ast.formula}.
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child#functional_notation
|
||||
*/
|
||||
export interface AstFormula {
|
||||
type: 'Formula';
|
||||
/** Multiplier of `n`. */
|
||||
a: number;
|
||||
/** Constant added to `a*n`. */
|
||||
b: number;
|
||||
}
|
||||
/**
|
||||
* Pseudo-class formula of selector value. `a` is multiplier of `n` and `b` us added on top. Formula: `an + b`.
|
||||
* Formula is followed by `of` keyword and then goes a CSS selector.
|
||||
* For instance `:nth-child(2n + 1 of div)` ->
|
||||
* `{type: 'AstPseudoClass'..., argument: {type: 'FormulaOfSelector', a: 2, b: 1, selector: {type: 'Selector', rules: [{type: 'Rule', items: [{type: 'TagName', name: 'div'}]}]}}}`.
|
||||
* Generated by {@link AstFactory.formulaOfSelector ast.formulaOfSelector}.
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child#functional_notation
|
||||
*/
|
||||
export interface AstFormulaOfSelector {
|
||||
type: 'FormulaOfSelector';
|
||||
/** Multiplier of `n`. */
|
||||
a: number;
|
||||
/** Constant added to `a*n`. */
|
||||
b: number;
|
||||
/** Selector that goes after formula (i.e. `"div -> span"` in case of `":nth-child(2n + 1 of div > span)"` */
|
||||
selector: AstRule;
|
||||
}
|
||||
/**
|
||||
* Substitution is not part of CSS spec, but rather a useful extension on top of CSS if you need to pass variables.
|
||||
* Generated by {@link AstFactory.substitution ast.substitution}.
|
||||
*/
|
||||
export interface AstSubstitution {
|
||||
type: 'Substitution';
|
||||
/** Substitution name (i.e. "var" in case of `"[role=$var]"` or `":lang($var)"`). */
|
||||
name: string;
|
||||
}
|
||||
/** One of pseudo-class argument types. */
|
||||
export type AstPseudoClassArgument = AstSubstitution | AstSelector | AstString | AstFormula | AstFormulaOfSelector;
|
||||
/** One of pseudo-element argument types. */
|
||||
export type AstPseudoElementArgument = AstSubstitution | AstString | AstSelector;
|
||||
/** One of CSS AST entity types. */
|
||||
export type AstEntity = AstSelector | AstRule | AstTagName | AstWildcardTag | AstId | AstClassName | AstNamespaceName | AstWildcardNamespace | AstNoNamespace | AstSubstitution | AstString | AstFormula | AstFormulaOfSelector | AstPseudoClass | AstAttribute | AstPseudoElement;
|
||||
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
|
||||
type ToAstFactory<T> = UnionToIntersection<T extends {
|
||||
type: infer Type;
|
||||
} ? Type extends string ? {
|
||||
[K in Uncapitalize<Type>]: {} extends Omit<T, 'type'> ? (props?: {
|
||||
[PK in keyof Omit<T, 'type'>]: Omit<T, 'type'>[PK];
|
||||
}) => T : (props: {
|
||||
[PK in keyof Omit<T, 'type'>]: Omit<T, 'type'>[PK];
|
||||
}) => T;
|
||||
} & {
|
||||
[K in `is${Type}`]: (entity: unknown) => entity is T;
|
||||
} : never : never>;
|
||||
/** @internal */
|
||||
type AstFactoryBase = {
|
||||
[K in keyof ToAstFactory<AstEntity>]: ToAstFactory<AstEntity>[K];
|
||||
};
|
||||
/**
|
||||
* AST structure generators and matchers.
|
||||
* For instance, `ast.selector({rules: [...]})` creates AstSelector and `ast.isSelector(...)` checks if
|
||||
* AstSelector was specified.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* // Represents CSS selector: ns|div#user-34.user.user-active[role="button"]:lang(en)::before > *
|
||||
* const selector = ast.selector({
|
||||
* rules: [
|
||||
* ast.rule({
|
||||
* items: [
|
||||
* ast.tagName({name: 'div', namespace: ast.namespaceName({name: 'ns'})}),
|
||||
* ast.id({name: 'user-34'}),
|
||||
* ast.className({name: 'user'}),
|
||||
* ast.className({name: 'user-active'}),
|
||||
* ast.attribute({
|
||||
* name: 'role',
|
||||
* operator: '=',
|
||||
* value: ast.string({value: 'button'})
|
||||
* }),
|
||||
* ast.pseudoClass({
|
||||
* name: 'lang',
|
||||
* argument: ast.string({value: 'en'})
|
||||
* }),
|
||||
* ast.pseudoElement({name: 'before'})
|
||||
* ],
|
||||
* nestedRule: ast.rule({combinator: '>', items: [ast.wildcardTag()]})
|
||||
* })
|
||||
* ]
|
||||
* });
|
||||
* console.log(ast.isSelector(selector)); // prints true
|
||||
* console.log(ast.isRule(selector)); // prints false
|
||||
*/
|
||||
export interface AstFactory extends AstFactoryBase {
|
||||
}
|
||||
/**
|
||||
* AST structure generators and matchers.
|
||||
* For instance, `ast.selector({rules: [...]})` creates AstSelector and `ast.isSelector(...)` checks if
|
||||
* AstSelector was specified.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* // Represents CSS selector: ns|div#user-34.user.user-active[role="button"]:lang(en)::before > *
|
||||
* const selector = ast.selector({
|
||||
* rules: [
|
||||
* ast.rule({
|
||||
* items: [
|
||||
* ast.tagName({name: 'div', namespace: ast.namespaceName({name: 'ns'})}),
|
||||
* ast.id({name: 'user-34'}),
|
||||
* ast.className({name: 'user'}),
|
||||
* ast.className({name: 'user-active'}),
|
||||
* ast.attribute({
|
||||
* name: 'role',
|
||||
* operator: '=',
|
||||
* value: ast.string({value: 'button'})
|
||||
* }),
|
||||
* ast.pseudoClass({
|
||||
* name: 'lang',
|
||||
* argument: ast.string({value: 'en'})
|
||||
* }),
|
||||
* ast.pseudoElement({name: 'before'})
|
||||
* ],
|
||||
* nestedRule: ast.rule({combinator: '>', items: [ast.wildcardTag()]})
|
||||
* })
|
||||
* ]
|
||||
* });
|
||||
* console.log(ast.isSelector(selector)); // prints true
|
||||
* console.log(ast.isRule(selector)); // prints false
|
||||
*/
|
||||
export declare const ast: AstFactory;
|
||||
export {};
|
||||
60
node_modules/css-selector-parser/dist/cjs/ast.js
generated
vendored
Normal file
60
node_modules/css-selector-parser/dist/cjs/ast.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ast = void 0;
|
||||
function astMethods(type) {
|
||||
return function (generatorName, checkerName) {
|
||||
var _a;
|
||||
return (_a = {},
|
||||
_a[generatorName] = function (props) { return (__assign({ type: type }, props)); },
|
||||
_a[checkerName] = function (entity) {
|
||||
return typeof entity === 'object' && entity !== null && entity.type === type;
|
||||
},
|
||||
_a);
|
||||
};
|
||||
}
|
||||
/**
|
||||
* AST structure generators and matchers.
|
||||
* For instance, `ast.selector({rules: [...]})` creates AstSelector and `ast.isSelector(...)` checks if
|
||||
* AstSelector was specified.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* // Represents CSS selector: ns|div#user-34.user.user-active[role="button"]:lang(en)::before > *
|
||||
* const selector = ast.selector({
|
||||
* rules: [
|
||||
* ast.rule({
|
||||
* items: [
|
||||
* ast.tagName({name: 'div', namespace: ast.namespaceName({name: 'ns'})}),
|
||||
* ast.id({name: 'user-34'}),
|
||||
* ast.className({name: 'user'}),
|
||||
* ast.className({name: 'user-active'}),
|
||||
* ast.attribute({
|
||||
* name: 'role',
|
||||
* operator: '=',
|
||||
* value: ast.string({value: 'button'})
|
||||
* }),
|
||||
* ast.pseudoClass({
|
||||
* name: 'lang',
|
||||
* argument: ast.string({value: 'en'})
|
||||
* }),
|
||||
* ast.pseudoElement({name: 'before'})
|
||||
* ],
|
||||
* nestedRule: ast.rule({combinator: '>', items: [ast.wildcardTag()]})
|
||||
* })
|
||||
* ]
|
||||
* });
|
||||
* console.log(ast.isSelector(selector)); // prints true
|
||||
* console.log(ast.isRule(selector)); // prints false
|
||||
*/
|
||||
exports.ast = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, astMethods('Selector')('selector', 'isSelector')), astMethods('Rule')('rule', 'isRule')), astMethods('TagName')('tagName', 'isTagName')), astMethods('Id')('id', 'isId')), astMethods('ClassName')('className', 'isClassName')), astMethods('WildcardTag')('wildcardTag', 'isWildcardTag')), astMethods('NamespaceName')('namespaceName', 'isNamespaceName')), astMethods('WildcardNamespace')('wildcardNamespace', 'isWildcardNamespace')), astMethods('NoNamespace')('noNamespace', 'isNoNamespace')), astMethods('Attribute')('attribute', 'isAttribute')), astMethods('PseudoClass')('pseudoClass', 'isPseudoClass')), astMethods('PseudoElement')('pseudoElement', 'isPseudoElement')), astMethods('String')('string', 'isString')), astMethods('Formula')('formula', 'isFormula')), astMethods('FormulaOfSelector')('formulaOfSelector', 'isFormulaOfSelector')), astMethods('Substitution')('substitution', 'isSubstitution'));
|
||||
4
node_modules/css-selector-parser/dist/cjs/index.d.ts
generated
vendored
Normal file
4
node_modules/css-selector-parser/dist/cjs/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export { createParser, Parser, ParserError } from './parser.js';
|
||||
export { render } from './render.js';
|
||||
export { ast, AstAttribute, AstClassName, AstEntity, AstFactory, AstFormula, AstFormulaOfSelector, AstId, AstNamespaceName, AstNoNamespace, AstPseudoClass, AstPseudoElement, AstRule, AstSelector, AstString, AstSubstitution, AstTagName, AstWildcardNamespace, AstWildcardTag } from './ast.js';
|
||||
export { CssLevel, SyntaxDefinition } from './syntax-definitions.js';
|
||||
9
node_modules/css-selector-parser/dist/cjs/index.js
generated
vendored
Normal file
9
node_modules/css-selector-parser/dist/cjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ast = exports.render = exports.createParser = void 0;
|
||||
var parser_js_1 = require("./parser.js");
|
||||
Object.defineProperty(exports, "createParser", { enumerable: true, get: function () { return parser_js_1.createParser; } });
|
||||
var render_js_1 = require("./render.js");
|
||||
Object.defineProperty(exports, "render", { enumerable: true, get: function () { return render_js_1.render; } });
|
||||
var ast_js_1 = require("./ast.js");
|
||||
Object.defineProperty(exports, "ast", { enumerable: true, get: function () { return ast_js_1.ast; } });
|
||||
13
node_modules/css-selector-parser/dist/cjs/indexes.d.ts
generated
vendored
Normal file
13
node_modules/css-selector-parser/dist/cjs/indexes.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface MulticharIndex {
|
||||
[key: string]: MulticharIndexChar;
|
||||
}
|
||||
export interface MulticharIndexChar {
|
||||
chars: MulticharIndex;
|
||||
self?: string;
|
||||
}
|
||||
type RegularIndex = Record<string, boolean>;
|
||||
export declare const emptyMulticharIndex: MulticharIndex;
|
||||
export declare const emptyRegularIndex: RegularIndex;
|
||||
export declare function createMulticharIndex(items: string[]): MulticharIndex;
|
||||
export declare function createRegularIndex(items: string[]): RegularIndex;
|
||||
export {};
|
||||
41
node_modules/css-selector-parser/dist/cjs/indexes.js
generated
vendored
Normal file
41
node_modules/css-selector-parser/dist/cjs/indexes.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createRegularIndex = exports.createMulticharIndex = exports.emptyRegularIndex = exports.emptyMulticharIndex = void 0;
|
||||
exports.emptyMulticharIndex = {};
|
||||
exports.emptyRegularIndex = {};
|
||||
function extendIndex(item, index) {
|
||||
var currentIndex = index;
|
||||
for (var pos = 0; pos < item.length; pos++) {
|
||||
var isLast = pos === item.length - 1;
|
||||
var char = item.charAt(pos);
|
||||
var charIndex = currentIndex[char] || (currentIndex[char] = { chars: {} });
|
||||
if (isLast) {
|
||||
charIndex.self = item;
|
||||
}
|
||||
currentIndex = charIndex.chars;
|
||||
}
|
||||
}
|
||||
function createMulticharIndex(items) {
|
||||
if (items.length === 0) {
|
||||
return exports.emptyMulticharIndex;
|
||||
}
|
||||
var index = {};
|
||||
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
||||
var item = items_1[_i];
|
||||
extendIndex(item, index);
|
||||
}
|
||||
return index;
|
||||
}
|
||||
exports.createMulticharIndex = createMulticharIndex;
|
||||
function createRegularIndex(items) {
|
||||
if (items.length === 0) {
|
||||
return exports.emptyRegularIndex;
|
||||
}
|
||||
var result = {};
|
||||
for (var _i = 0, items_2 = items; _i < items_2.length; _i++) {
|
||||
var item = items_2[_i];
|
||||
result[item] = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.createRegularIndex = createRegularIndex;
|
||||
1
node_modules/css-selector-parser/dist/cjs/package.json
generated
vendored
Normal file
1
node_modules/css-selector-parser/dist/cjs/package.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"type": "commonjs"}
|
||||
41
node_modules/css-selector-parser/dist/cjs/parser.d.ts
generated
vendored
Normal file
41
node_modules/css-selector-parser/dist/cjs/parser.d.ts
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { AstSelector } from './ast.js';
|
||||
import { CssLevel, SyntaxDefinition } from './syntax-definitions.js';
|
||||
/**
|
||||
* This error is thrown when parser encounters problems in CSS string.
|
||||
* On top of the usual error, it has `position` property to indicate where in the input string the error happened.
|
||||
*/
|
||||
export interface ParserError extends Error {
|
||||
message: string;
|
||||
name: 'ParserError';
|
||||
position: number;
|
||||
}
|
||||
/**
|
||||
* Parses CSS selector string and returns CSS selector AST.
|
||||
* @throws {ParserError}
|
||||
*/
|
||||
export type Parser = (input: string) => AstSelector;
|
||||
/**
|
||||
* Creates a parse function to be used later to parse CSS selectors.
|
||||
*/
|
||||
export declare function createParser(options?: {
|
||||
/**
|
||||
* CSS Syntax options to be used for parsing.
|
||||
* Can either be one of the predefined CSS levels ({@link CssLevel}) or a more detailed syntax definition ({@link SyntaxDefinition}).
|
||||
* Default: `"latest"`
|
||||
*/
|
||||
syntax?: CssLevel | SyntaxDefinition;
|
||||
/**
|
||||
* Flag to enable substitutes.
|
||||
* This is not part of CSS syntax, but rather a useful feature to pass variables into CSS selectors.
|
||||
* Default: `false`
|
||||
* @example "[attr=$variable]"
|
||||
*/
|
||||
substitutes?: boolean;
|
||||
/**
|
||||
* CSS selector parser in modern browsers is very forgiving. For instance, it works fine with unclosed attribute
|
||||
* selectors: `"[attr=value"`.
|
||||
* Set to `false` in order to mimic browser behaviour.
|
||||
* Default: `true`
|
||||
*/
|
||||
strict?: boolean;
|
||||
}): Parser;
|
||||
726
node_modules/css-selector-parser/dist/cjs/parser.js
generated
vendored
Normal file
726
node_modules/css-selector-parser/dist/cjs/parser.js
generated
vendored
Normal file
@@ -0,0 +1,726 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createParser = void 0;
|
||||
var indexes_js_1 = require("./indexes.js");
|
||||
var pseudo_signatures_js_1 = require("./pseudo-signatures.js");
|
||||
var syntax_definitions_js_1 = require("./syntax-definitions.js");
|
||||
var utils_js_1 = require("./utils.js");
|
||||
var errorPrefix = "css-selector-parser parse error: ";
|
||||
/**
|
||||
* Creates a parse function to be used later to parse CSS selectors.
|
||||
*/
|
||||
function createParser(options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
var _a = options.syntax, syntax = _a === void 0 ? 'latest' : _a, substitutes = options.substitutes, _b = options.strict, strict = _b === void 0 ? true : _b;
|
||||
var syntaxDefinition = typeof syntax === 'object' ? syntax : syntax_definitions_js_1.cssSyntaxDefinitions[syntax];
|
||||
if (syntaxDefinition.baseSyntax) {
|
||||
syntaxDefinition = (0, syntax_definitions_js_1.extendSyntaxDefinition)(syntax_definitions_js_1.cssSyntaxDefinitions[syntaxDefinition.baseSyntax], syntaxDefinition);
|
||||
}
|
||||
var _c = syntaxDefinition.tag
|
||||
? [true, Boolean((0, syntax_definitions_js_1.getXmlOptions)(syntaxDefinition.tag).wildcard)]
|
||||
: [false, false], tagNameEnabled = _c[0], tagNameWildcardEnabled = _c[1];
|
||||
var idEnabled = Boolean(syntaxDefinition.ids);
|
||||
var classNamesEnabled = Boolean(syntaxDefinition.classNames);
|
||||
var namespaceEnabled = Boolean(syntaxDefinition.namespace);
|
||||
var namespaceWildcardEnabled = syntaxDefinition.namespace &&
|
||||
(syntaxDefinition.namespace === true || syntaxDefinition.namespace.wildcard === true);
|
||||
if (namespaceEnabled && !tagNameEnabled) {
|
||||
throw new Error("".concat(errorPrefix, "Namespaces cannot be enabled while tags are disabled."));
|
||||
}
|
||||
var substitutesEnabled = Boolean(substitutes);
|
||||
var combinatorsIndex = syntaxDefinition.combinators
|
||||
? (0, indexes_js_1.createMulticharIndex)(syntaxDefinition.combinators)
|
||||
: indexes_js_1.emptyMulticharIndex;
|
||||
var _d = syntaxDefinition.attributes
|
||||
? [
|
||||
true,
|
||||
syntaxDefinition.attributes.operators
|
||||
? (0, indexes_js_1.createMulticharIndex)(syntaxDefinition.attributes.operators)
|
||||
: indexes_js_1.emptyMulticharIndex,
|
||||
syntaxDefinition.attributes.caseSensitivityModifiers
|
||||
? (0, indexes_js_1.createRegularIndex)(syntaxDefinition.attributes.caseSensitivityModifiers)
|
||||
: indexes_js_1.emptyRegularIndex,
|
||||
syntaxDefinition.attributes.unknownCaseSensitivityModifiers === 'accept'
|
||||
]
|
||||
: [false, indexes_js_1.emptyMulticharIndex, indexes_js_1.emptyRegularIndex, false], attributesEnabled = _d[0], attributesOperatorsIndex = _d[1], attributesCaseSensitivityModifiers = _d[2], attributesAcceptUnknownCaseSensitivityModifiers = _d[3];
|
||||
var attributesCaseSensitivityModifiersEnabled = attributesAcceptUnknownCaseSensitivityModifiers || Object.keys(attributesCaseSensitivityModifiers).length > 0;
|
||||
var _e = syntaxDefinition.pseudoClasses
|
||||
? [
|
||||
true,
|
||||
syntaxDefinition.pseudoClasses.definitions
|
||||
? (0, pseudo_signatures_js_1.calculatePseudoSignatures)(syntaxDefinition.pseudoClasses.definitions)
|
||||
: pseudo_signatures_js_1.emptyPseudoSignatures,
|
||||
syntaxDefinition.pseudoClasses.unknown === 'accept'
|
||||
]
|
||||
: [false, pseudo_signatures_js_1.emptyPseudoSignatures, false], pseudoClassesEnabled = _e[0], pseudoClassesDefinitions = _e[1], pseudoClassesAcceptUnknown = _e[2];
|
||||
var _f = syntaxDefinition.pseudoElements
|
||||
? [
|
||||
true,
|
||||
syntaxDefinition.pseudoElements.notation === 'singleColon' ||
|
||||
syntaxDefinition.pseudoElements.notation === 'both',
|
||||
!syntaxDefinition.pseudoElements.notation ||
|
||||
syntaxDefinition.pseudoElements.notation === 'doubleColon' ||
|
||||
syntaxDefinition.pseudoElements.notation === 'both',
|
||||
syntaxDefinition.pseudoElements.definitions
|
||||
? (0, pseudo_signatures_js_1.calculatePseudoSignatures)(Array.isArray(syntaxDefinition.pseudoElements.definitions)
|
||||
? { NoArgument: syntaxDefinition.pseudoElements.definitions }
|
||||
: syntaxDefinition.pseudoElements.definitions)
|
||||
: pseudo_signatures_js_1.emptyPseudoSignatures,
|
||||
syntaxDefinition.pseudoElements.unknown === 'accept'
|
||||
]
|
||||
: [false, false, false, pseudo_signatures_js_1.emptyPseudoSignatures, false], pseudoElementsEnabled = _f[0], pseudoElementsSingleColonNotationEnabled = _f[1], pseudoElementsDoubleColonNotationEnabled = _f[2], pseudoElementsDefinitions = _f[3], pseudoElementsAcceptUnknown = _f[4];
|
||||
var str = '';
|
||||
var l = str.length;
|
||||
var pos = 0;
|
||||
var chr = '';
|
||||
var is = function (comparison) { return chr === comparison; };
|
||||
var isTagStart = function () { return is('*') || (0, utils_js_1.isIdentStart)(chr); };
|
||||
var rewind = function (newPos) {
|
||||
pos = newPos;
|
||||
chr = str.charAt(pos);
|
||||
};
|
||||
var next = function () {
|
||||
pos++;
|
||||
chr = str.charAt(pos);
|
||||
};
|
||||
var readAndNext = function () {
|
||||
var current = chr;
|
||||
pos++;
|
||||
chr = str.charAt(pos);
|
||||
return current;
|
||||
};
|
||||
/** @throws ParserError */
|
||||
function fail(errorMessage) {
|
||||
var position = Math.min(l - 1, pos);
|
||||
var error = new Error("".concat(errorPrefix).concat(errorMessage, " Pos: ").concat(position, "."));
|
||||
error.position = position;
|
||||
error.name = 'ParserError';
|
||||
throw error;
|
||||
}
|
||||
function assert(condition, errorMessage) {
|
||||
if (!condition) {
|
||||
return fail(errorMessage);
|
||||
}
|
||||
}
|
||||
var assertNonEof = function () {
|
||||
assert(pos < l, 'Unexpected end of input.');
|
||||
};
|
||||
var isEof = function () { return pos >= l; };
|
||||
var pass = function (character) {
|
||||
assert(pos < l, "Expected \"".concat(character, "\" but end of input reached."));
|
||||
assert(chr === character, "Expected \"".concat(character, "\" but \"").concat(chr, "\" found."));
|
||||
pos++;
|
||||
chr = str.charAt(pos);
|
||||
};
|
||||
function matchMulticharIndex(index) {
|
||||
var match = matchMulticharIndexPos(index, pos);
|
||||
if (match) {
|
||||
pos += match.length;
|
||||
chr = str.charAt(pos);
|
||||
return match;
|
||||
}
|
||||
}
|
||||
function matchMulticharIndexPos(index, subPos) {
|
||||
var char = str.charAt(subPos);
|
||||
var charIndex = index[char];
|
||||
if (charIndex) {
|
||||
var subMatch = matchMulticharIndexPos(charIndex.chars, subPos + 1);
|
||||
if (subMatch) {
|
||||
return subMatch;
|
||||
}
|
||||
if (charIndex.self) {
|
||||
return charIndex.self;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @see https://www.w3.org/TR/css-syntax/#hex-digit-diagram
|
||||
*/
|
||||
function parseHex() {
|
||||
var hex = readAndNext();
|
||||
var count = 1;
|
||||
while ((0, utils_js_1.isHex)(chr) && count < utils_js_1.maxHexLength) {
|
||||
hex += readAndNext();
|
||||
count++;
|
||||
}
|
||||
skipSingleWhitespace();
|
||||
return String.fromCharCode(parseInt(hex, 16));
|
||||
}
|
||||
/**
|
||||
* @see https://www.w3.org/TR/css-syntax/#string-token-diagram
|
||||
*/
|
||||
function parseString(quote) {
|
||||
var result = '';
|
||||
pass(quote);
|
||||
while (pos < l) {
|
||||
if (is(quote)) {
|
||||
next();
|
||||
return result;
|
||||
}
|
||||
else if (is('\\')) {
|
||||
next();
|
||||
if (is(quote)) {
|
||||
result += quote;
|
||||
next();
|
||||
}
|
||||
else if (chr === '\n' || chr === '\f') {
|
||||
next();
|
||||
}
|
||||
else if (chr === '\r') {
|
||||
next();
|
||||
if (is('\n')) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
else if ((0, utils_js_1.isHex)(chr)) {
|
||||
result += parseHex();
|
||||
}
|
||||
else {
|
||||
result += chr;
|
||||
next();
|
||||
}
|
||||
}
|
||||
else {
|
||||
result += chr;
|
||||
next();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @see https://www.w3.org/TR/css-syntax/#ident-token-diagram
|
||||
*/
|
||||
function parseIdentifier() {
|
||||
if (!(0, utils_js_1.isIdentStart)(chr)) {
|
||||
return null;
|
||||
}
|
||||
var result = '';
|
||||
while (is('-')) {
|
||||
result += chr;
|
||||
next();
|
||||
}
|
||||
if (result === '-' && !(0, utils_js_1.isIdent)(chr) && !is('\\')) {
|
||||
fail('Identifiers cannot consist of a single hyphen.');
|
||||
}
|
||||
if (strict && result.length >= 2) {
|
||||
// Checking this only for strict mode since browsers work fine with these identifiers.
|
||||
fail('Identifiers cannot start with two hyphens with strict mode on.');
|
||||
}
|
||||
if (utils_js_1.digitsChars[chr]) {
|
||||
fail('Identifiers cannot start with hyphens followed by digits.');
|
||||
}
|
||||
while (pos < l) {
|
||||
if ((0, utils_js_1.isIdent)(chr)) {
|
||||
result += readAndNext();
|
||||
}
|
||||
else if (is('\\')) {
|
||||
next();
|
||||
assertNonEof();
|
||||
if ((0, utils_js_1.isHex)(chr)) {
|
||||
result += parseHex();
|
||||
}
|
||||
else {
|
||||
result += readAndNext();
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function parsePseudoClassString() {
|
||||
var result = '';
|
||||
while (pos < l) {
|
||||
if (is(')')) {
|
||||
break;
|
||||
}
|
||||
else if (is('\\')) {
|
||||
next();
|
||||
if (isEof() && !strict) {
|
||||
return (result + '\\').trim();
|
||||
}
|
||||
assertNonEof();
|
||||
if ((0, utils_js_1.isHex)(chr)) {
|
||||
result += parseHex();
|
||||
}
|
||||
else {
|
||||
result += readAndNext();
|
||||
}
|
||||
}
|
||||
else {
|
||||
result += readAndNext();
|
||||
}
|
||||
}
|
||||
return result.trim();
|
||||
}
|
||||
function skipSingleWhitespace() {
|
||||
if (chr === ' ' || chr === '\t' || chr === '\f' || chr === '\n') {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
if (chr === '\r') {
|
||||
next();
|
||||
}
|
||||
if (chr === '\n') {
|
||||
next();
|
||||
}
|
||||
}
|
||||
function skipWhitespace() {
|
||||
while (utils_js_1.whitespaceChars[chr]) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
function parseSelector(relative) {
|
||||
if (relative === void 0) { relative = false; }
|
||||
skipWhitespace();
|
||||
var rules = [parseRule(relative)];
|
||||
while (is(',')) {
|
||||
next();
|
||||
skipWhitespace();
|
||||
rules.push(parseRule(relative));
|
||||
}
|
||||
return {
|
||||
type: 'Selector',
|
||||
rules: rules
|
||||
};
|
||||
}
|
||||
function parseAttribute() {
|
||||
pass('[');
|
||||
skipWhitespace();
|
||||
var attr;
|
||||
if (is('|')) {
|
||||
assert(namespaceEnabled, 'Namespaces are not enabled.');
|
||||
next();
|
||||
var name_1 = parseIdentifier();
|
||||
assert(name_1, 'Expected attribute name.');
|
||||
attr = {
|
||||
type: 'Attribute',
|
||||
name: name_1,
|
||||
namespace: { type: 'NoNamespace' }
|
||||
};
|
||||
}
|
||||
else if (is('*')) {
|
||||
assert(namespaceEnabled, 'Namespaces are not enabled.');
|
||||
assert(namespaceWildcardEnabled, 'Wildcard namespace is not enabled.');
|
||||
next();
|
||||
pass('|');
|
||||
var name_2 = parseIdentifier();
|
||||
assert(name_2, 'Expected attribute name.');
|
||||
attr = {
|
||||
type: 'Attribute',
|
||||
name: name_2,
|
||||
namespace: { type: 'WildcardNamespace' }
|
||||
};
|
||||
}
|
||||
else {
|
||||
var identifier = parseIdentifier();
|
||||
assert(identifier, 'Expected attribute name.');
|
||||
attr = {
|
||||
type: 'Attribute',
|
||||
name: identifier
|
||||
};
|
||||
if (is('|')) {
|
||||
var savedPos = pos;
|
||||
next();
|
||||
if ((0, utils_js_1.isIdentStart)(chr)) {
|
||||
assert(namespaceEnabled, 'Namespaces are not enabled.');
|
||||
var name_3 = parseIdentifier();
|
||||
assert(name_3, 'Expected attribute name.');
|
||||
attr = {
|
||||
type: 'Attribute',
|
||||
name: name_3,
|
||||
namespace: { type: 'NamespaceName', name: identifier }
|
||||
};
|
||||
}
|
||||
else {
|
||||
rewind(savedPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(attr.name, 'Expected attribute name.');
|
||||
skipWhitespace();
|
||||
if (isEof() && !strict) {
|
||||
return attr;
|
||||
}
|
||||
if (is(']')) {
|
||||
next();
|
||||
}
|
||||
else {
|
||||
attr.operator = matchMulticharIndex(attributesOperatorsIndex);
|
||||
assert(attr.operator, 'Expected a valid attribute selector operator.');
|
||||
skipWhitespace();
|
||||
assertNonEof();
|
||||
if (utils_js_1.quoteChars[chr]) {
|
||||
attr.value = {
|
||||
type: 'String',
|
||||
value: parseString(chr)
|
||||
};
|
||||
}
|
||||
else if (substitutesEnabled && is('$')) {
|
||||
next();
|
||||
var name_4 = parseIdentifier();
|
||||
assert(name_4, 'Expected substitute name.');
|
||||
attr.value = {
|
||||
type: 'Substitution',
|
||||
name: name_4
|
||||
};
|
||||
}
|
||||
else {
|
||||
var value = parseIdentifier();
|
||||
assert(value, 'Expected attribute value.');
|
||||
attr.value = {
|
||||
type: 'String',
|
||||
value: value
|
||||
};
|
||||
}
|
||||
skipWhitespace();
|
||||
if (isEof() && !strict) {
|
||||
return attr;
|
||||
}
|
||||
if (!is(']')) {
|
||||
var caseSensitivityModifier = parseIdentifier();
|
||||
assert(caseSensitivityModifier, 'Expected end of attribute selector.');
|
||||
attr.caseSensitivityModifier = caseSensitivityModifier;
|
||||
assert(attributesCaseSensitivityModifiersEnabled, 'Attribute case sensitivity modifiers are not enabled.');
|
||||
assert(attributesAcceptUnknownCaseSensitivityModifiers ||
|
||||
attributesCaseSensitivityModifiers[attr.caseSensitivityModifier], 'Unknown attribute case sensitivity modifier.');
|
||||
skipWhitespace();
|
||||
if (isEof() && !strict) {
|
||||
return attr;
|
||||
}
|
||||
}
|
||||
pass(']');
|
||||
}
|
||||
return attr;
|
||||
}
|
||||
function parseNumber() {
|
||||
var result = '';
|
||||
while (utils_js_1.digitsChars[chr]) {
|
||||
result += readAndNext();
|
||||
}
|
||||
assert(result !== '', 'Formula parse error.');
|
||||
return parseInt(result);
|
||||
}
|
||||
var isNumberStart = function () { return is('-') || is('+') || utils_js_1.digitsChars[chr]; };
|
||||
function parseFormula() {
|
||||
if (is('e') || is('o')) {
|
||||
var ident = parseIdentifier();
|
||||
if (ident === 'even') {
|
||||
skipWhitespace();
|
||||
return [2, 0];
|
||||
}
|
||||
if (ident === 'odd') {
|
||||
skipWhitespace();
|
||||
return [2, 1];
|
||||
}
|
||||
}
|
||||
var firstNumber = null;
|
||||
var firstNumberMultiplier = 1;
|
||||
if (is('-')) {
|
||||
next();
|
||||
firstNumberMultiplier = -1;
|
||||
}
|
||||
if (isNumberStart()) {
|
||||
if (is('+')) {
|
||||
next();
|
||||
}
|
||||
firstNumber = parseNumber();
|
||||
if (!is('\\') && !is('n')) {
|
||||
return [0, firstNumber * firstNumberMultiplier];
|
||||
}
|
||||
}
|
||||
if (firstNumber === null) {
|
||||
firstNumber = 1;
|
||||
}
|
||||
firstNumber *= firstNumberMultiplier;
|
||||
var identifier;
|
||||
if (is('\\')) {
|
||||
next();
|
||||
if ((0, utils_js_1.isHex)(chr)) {
|
||||
identifier = parseHex();
|
||||
}
|
||||
else {
|
||||
identifier = readAndNext();
|
||||
}
|
||||
}
|
||||
else {
|
||||
identifier = readAndNext();
|
||||
}
|
||||
assert(identifier === 'n', 'Formula parse error: expected "n".');
|
||||
skipWhitespace();
|
||||
if (is('+') || is('-')) {
|
||||
var sign = is('+') ? 1 : -1;
|
||||
next();
|
||||
skipWhitespace();
|
||||
return [firstNumber, sign * parseNumber()];
|
||||
}
|
||||
else {
|
||||
return [firstNumber, 0];
|
||||
}
|
||||
}
|
||||
function parsePseudoArgument(pseudoName, type, signature) {
|
||||
var argument;
|
||||
if (is('(')) {
|
||||
next();
|
||||
skipWhitespace();
|
||||
if (substitutesEnabled && is('$')) {
|
||||
next();
|
||||
var name_5 = parseIdentifier();
|
||||
assert(name_5, 'Expected substitute name.');
|
||||
argument = {
|
||||
type: 'Substitution',
|
||||
name: name_5
|
||||
};
|
||||
}
|
||||
else if (signature.type === 'String') {
|
||||
argument = {
|
||||
type: 'String',
|
||||
value: parsePseudoClassString()
|
||||
};
|
||||
assert(argument.value, "Expected ".concat(type, " argument value."));
|
||||
}
|
||||
else if (signature.type === 'Selector') {
|
||||
argument = parseSelector(true);
|
||||
}
|
||||
else if (signature.type === 'Formula') {
|
||||
var _a = parseFormula(), a = _a[0], b = _a[1];
|
||||
argument = {
|
||||
type: 'Formula',
|
||||
a: a,
|
||||
b: b
|
||||
};
|
||||
if (signature.ofSelector) {
|
||||
skipWhitespace();
|
||||
if (is('o') || is('\\')) {
|
||||
var ident = parseIdentifier();
|
||||
assert(ident === 'of', 'Formula of selector parse error.');
|
||||
skipWhitespace();
|
||||
argument = {
|
||||
type: 'FormulaOfSelector',
|
||||
a: a,
|
||||
b: b,
|
||||
selector: parseRule()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return fail("Invalid ".concat(type, " signature."));
|
||||
}
|
||||
skipWhitespace();
|
||||
if (isEof() && !strict) {
|
||||
return argument;
|
||||
}
|
||||
pass(')');
|
||||
}
|
||||
else {
|
||||
assert(signature.optional, "Argument is required for ".concat(type, " \"").concat(pseudoName, "\"."));
|
||||
}
|
||||
return argument;
|
||||
}
|
||||
function parseTagName() {
|
||||
if (is('*')) {
|
||||
assert(tagNameWildcardEnabled, 'Wildcard tag name is not enabled.');
|
||||
next();
|
||||
return { type: 'WildcardTag' };
|
||||
}
|
||||
else if ((0, utils_js_1.isIdentStart)(chr)) {
|
||||
assert(tagNameEnabled, 'Tag names are not enabled.');
|
||||
var name_6 = parseIdentifier();
|
||||
assert(name_6, 'Expected tag name.');
|
||||
return {
|
||||
type: 'TagName',
|
||||
name: name_6
|
||||
};
|
||||
}
|
||||
else {
|
||||
return fail('Expected tag name.');
|
||||
}
|
||||
}
|
||||
function parseTagNameWithNamespace() {
|
||||
if (is('*')) {
|
||||
var savedPos = pos;
|
||||
next();
|
||||
if (!is('|')) {
|
||||
rewind(savedPos);
|
||||
return parseTagName();
|
||||
}
|
||||
next();
|
||||
if (!isTagStart()) {
|
||||
rewind(savedPos);
|
||||
return parseTagName();
|
||||
}
|
||||
assert(namespaceEnabled, 'Namespaces are not enabled.');
|
||||
assert(namespaceWildcardEnabled, 'Wildcard namespace is not enabled.');
|
||||
var tagName = parseTagName();
|
||||
tagName.namespace = { type: 'WildcardNamespace' };
|
||||
return tagName;
|
||||
}
|
||||
else if (is('|')) {
|
||||
assert(namespaceEnabled, 'Namespaces are not enabled.');
|
||||
next();
|
||||
var tagName = parseTagName();
|
||||
tagName.namespace = { type: 'NoNamespace' };
|
||||
return tagName;
|
||||
}
|
||||
else if ((0, utils_js_1.isIdentStart)(chr)) {
|
||||
var identifier = parseIdentifier();
|
||||
assert(identifier, 'Expected tag name.');
|
||||
if (!is('|')) {
|
||||
assert(tagNameEnabled, 'Tag names are not enabled.');
|
||||
return {
|
||||
type: 'TagName',
|
||||
name: identifier
|
||||
};
|
||||
}
|
||||
var savedPos = pos;
|
||||
next();
|
||||
if (!isTagStart()) {
|
||||
rewind(savedPos);
|
||||
return {
|
||||
type: 'TagName',
|
||||
name: identifier
|
||||
};
|
||||
}
|
||||
assert(namespaceEnabled, 'Namespaces are not enabled.');
|
||||
var tagName = parseTagName();
|
||||
tagName.namespace = { type: 'NamespaceName', name: identifier };
|
||||
return tagName;
|
||||
}
|
||||
else {
|
||||
return fail('Expected tag name.');
|
||||
}
|
||||
}
|
||||
function parseRule(relative) {
|
||||
var _a, _b;
|
||||
if (relative === void 0) { relative = false; }
|
||||
var rule = { type: 'Rule', items: [] };
|
||||
if (relative) {
|
||||
var combinator = matchMulticharIndex(combinatorsIndex);
|
||||
if (combinator) {
|
||||
rule.combinator = combinator;
|
||||
skipWhitespace();
|
||||
}
|
||||
}
|
||||
while (pos < l) {
|
||||
if (isTagStart()) {
|
||||
assert(rule.items.length === 0, 'Unexpected tag/namespace start.');
|
||||
rule.items.push(parseTagNameWithNamespace());
|
||||
}
|
||||
else if (is('|')) {
|
||||
var savedPos = pos;
|
||||
next();
|
||||
if (isTagStart()) {
|
||||
assert(rule.items.length === 0, 'Unexpected tag/namespace start.');
|
||||
rewind(savedPos);
|
||||
rule.items.push(parseTagNameWithNamespace());
|
||||
}
|
||||
else {
|
||||
rewind(savedPos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (is('.')) {
|
||||
assert(classNamesEnabled, 'Class names are not enabled.');
|
||||
next();
|
||||
var className = parseIdentifier();
|
||||
assert(className, 'Expected class name.');
|
||||
rule.items.push({ type: 'ClassName', name: className });
|
||||
}
|
||||
else if (is('#')) {
|
||||
assert(idEnabled, 'IDs are not enabled.');
|
||||
next();
|
||||
var idName = parseIdentifier();
|
||||
assert(idName, 'Expected ID name.');
|
||||
rule.items.push({ type: 'Id', name: idName });
|
||||
}
|
||||
else if (is('[')) {
|
||||
assert(attributesEnabled, 'Attributes are not enabled.');
|
||||
rule.items.push(parseAttribute());
|
||||
}
|
||||
else if (is(':')) {
|
||||
var isDoubleColon = false;
|
||||
var isPseudoElement = false;
|
||||
next();
|
||||
if (is(':')) {
|
||||
assert(pseudoElementsEnabled, 'Pseudo elements are not enabled.');
|
||||
assert(pseudoElementsDoubleColonNotationEnabled, 'Pseudo elements double colon notation is not enabled.');
|
||||
isDoubleColon = true;
|
||||
next();
|
||||
}
|
||||
var pseudoName = parseIdentifier();
|
||||
assert(isDoubleColon || pseudoName, 'Expected pseudo-class name.');
|
||||
assert(!isDoubleColon || pseudoName, 'Expected pseudo-element name.');
|
||||
assert(pseudoName, 'Expected pseudo-class name.');
|
||||
assert(!isDoubleColon ||
|
||||
pseudoElementsAcceptUnknown ||
|
||||
Object.prototype.hasOwnProperty.call(pseudoElementsDefinitions, pseudoName), "Unknown pseudo-element \"".concat(pseudoName, "\"."));
|
||||
isPseudoElement =
|
||||
pseudoElementsEnabled &&
|
||||
(isDoubleColon ||
|
||||
(!isDoubleColon &&
|
||||
pseudoElementsSingleColonNotationEnabled &&
|
||||
Object.prototype.hasOwnProperty.call(pseudoElementsDefinitions, pseudoName)));
|
||||
if (isPseudoElement) {
|
||||
var signature = (_a = pseudoElementsDefinitions[pseudoName]) !== null && _a !== void 0 ? _a : (pseudoElementsAcceptUnknown && pseudo_signatures_js_1.defaultPseudoSignature);
|
||||
var pseudoElement = {
|
||||
type: 'PseudoElement',
|
||||
name: pseudoName
|
||||
};
|
||||
var argument = parsePseudoArgument(pseudoName, 'pseudo-element', signature);
|
||||
if (argument) {
|
||||
assert(argument.type !== 'Formula' && argument.type !== 'FormulaOfSelector', 'Pseudo-elements cannot have formula argument.');
|
||||
pseudoElement.argument = argument;
|
||||
}
|
||||
rule.items.push(pseudoElement);
|
||||
}
|
||||
else {
|
||||
assert(pseudoClassesEnabled, 'Pseudo-classes are not enabled.');
|
||||
var signature = (_b = pseudoClassesDefinitions[pseudoName]) !== null && _b !== void 0 ? _b : (pseudoClassesAcceptUnknown && pseudo_signatures_js_1.defaultPseudoSignature);
|
||||
assert(signature, "Unknown pseudo-class: \"".concat(pseudoName, "\"."));
|
||||
var argument = parsePseudoArgument(pseudoName, 'pseudo-class', signature);
|
||||
var pseudoClass = {
|
||||
type: 'PseudoClass',
|
||||
name: pseudoName
|
||||
};
|
||||
if (argument) {
|
||||
pseudoClass.argument = argument;
|
||||
}
|
||||
rule.items.push(pseudoClass);
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rule.items.length === 0) {
|
||||
if (isEof()) {
|
||||
return fail('Expected rule but end of input reached.');
|
||||
}
|
||||
else {
|
||||
return fail("Expected rule but \"".concat(chr, "\" found."));
|
||||
}
|
||||
}
|
||||
skipWhitespace();
|
||||
if (!isEof() && !is(',') && !is(')')) {
|
||||
var combinator = matchMulticharIndex(combinatorsIndex);
|
||||
skipWhitespace();
|
||||
rule.nestedRule = parseRule();
|
||||
rule.nestedRule.combinator = combinator;
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
return function (input) {
|
||||
// noinspection SuspiciousTypeOfGuard
|
||||
if (typeof input !== 'string') {
|
||||
throw new Error("".concat(errorPrefix, "Expected string input."));
|
||||
}
|
||||
str = input;
|
||||
l = str.length;
|
||||
pos = 0;
|
||||
chr = str.charAt(0);
|
||||
return parseSelector();
|
||||
};
|
||||
}
|
||||
exports.createParser = createParser;
|
||||
25
node_modules/css-selector-parser/dist/cjs/pseudo-signatures.d.ts
generated
vendored
Normal file
25
node_modules/css-selector-parser/dist/cjs/pseudo-signatures.d.ts
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { PseudoClassType } from './syntax-definitions.js';
|
||||
export type PseudoSignature = {
|
||||
optional: boolean;
|
||||
} & ({
|
||||
type: 'Formula';
|
||||
ofSelector?: boolean;
|
||||
} | {
|
||||
type: 'String';
|
||||
} | {
|
||||
type: 'Selector';
|
||||
} | {
|
||||
type: 'NoArgument';
|
||||
});
|
||||
export type PseudoSignatures = Record<string, PseudoSignature>;
|
||||
export declare const emptyPseudoSignatures: PseudoSignatures;
|
||||
export declare const defaultPseudoSignature: PseudoSignature;
|
||||
type PseudoArgumentType = PseudoClassType;
|
||||
export type CategoriesIndex<T1 extends string, T2 extends string> = {
|
||||
[K in T1]?: T2[];
|
||||
};
|
||||
export declare function inverseCategories<T1 extends string, T2 extends string>(obj: CategoriesIndex<T1, T2>): CategoriesIndex<T2, T1>;
|
||||
export declare function calculatePseudoSignatures<T extends PseudoArgumentType>(definitions: {
|
||||
[K in T]?: string[];
|
||||
}): PseudoSignatures;
|
||||
export {};
|
||||
68
node_modules/css-selector-parser/dist/cjs/pseudo-signatures.js
generated
vendored
Normal file
68
node_modules/css-selector-parser/dist/cjs/pseudo-signatures.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.calculatePseudoSignatures = exports.inverseCategories = exports.defaultPseudoSignature = exports.emptyPseudoSignatures = void 0;
|
||||
exports.emptyPseudoSignatures = {};
|
||||
exports.defaultPseudoSignature = {
|
||||
type: 'String',
|
||||
optional: true
|
||||
};
|
||||
function calculatePseudoSignature(types) {
|
||||
var result = {
|
||||
type: 'NoArgument',
|
||||
optional: false
|
||||
};
|
||||
function setResultType(type) {
|
||||
if (result.type && result.type !== type && result.type !== 'NoArgument') {
|
||||
throw new Error("Conflicting pseudo-class argument type: \"".concat(result.type, "\" vs \"").concat(type, "\"."));
|
||||
}
|
||||
result.type = type;
|
||||
}
|
||||
for (var _i = 0, types_1 = types; _i < types_1.length; _i++) {
|
||||
var type = types_1[_i];
|
||||
if (type === 'NoArgument') {
|
||||
result.optional = true;
|
||||
}
|
||||
if (type === 'Formula') {
|
||||
setResultType('Formula');
|
||||
}
|
||||
if (type === 'FormulaOfSelector') {
|
||||
setResultType('Formula');
|
||||
result.ofSelector = true;
|
||||
}
|
||||
if (type === 'String') {
|
||||
setResultType('String');
|
||||
}
|
||||
if (type === 'Selector') {
|
||||
setResultType('Selector');
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function inverseCategories(obj) {
|
||||
var result = {};
|
||||
for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
|
||||
var category = _a[_i];
|
||||
var items = obj[category];
|
||||
if (items) {
|
||||
for (var _b = 0, _c = items; _b < _c.length; _b++) {
|
||||
var item = _c[_b];
|
||||
(result[item] || (result[item] = [])).push(category);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.inverseCategories = inverseCategories;
|
||||
function calculatePseudoSignatures(definitions) {
|
||||
var pseudoClassesToArgumentTypes = inverseCategories(definitions);
|
||||
var result = {};
|
||||
for (var _i = 0, _a = Object.keys(pseudoClassesToArgumentTypes); _i < _a.length; _i++) {
|
||||
var pseudoClass = _a[_i];
|
||||
var argumentTypes = pseudoClassesToArgumentTypes[pseudoClass];
|
||||
if (argumentTypes) {
|
||||
result[pseudoClass] = calculatePseudoSignature(argumentTypes);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.calculatePseudoSignatures = calculatePseudoSignatures;
|
||||
25
node_modules/css-selector-parser/dist/cjs/render.d.ts
generated
vendored
Normal file
25
node_modules/css-selector-parser/dist/cjs/render.d.ts
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { AstEntity } from './ast.js';
|
||||
/**
|
||||
* Renders CSS Selector AST back to a string.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* import {ast, render} from 'css-selector-parser';
|
||||
*
|
||||
* const selector = ast.selector({
|
||||
* rules: [
|
||||
* ast.rule({
|
||||
* items: [
|
||||
* ast.tagName({name: 'a'}),
|
||||
* ast.id({name: 'user-23'}),
|
||||
* ast.className({name: 'user'}),
|
||||
* ast.pseudoClass({name: 'visited'}),
|
||||
* ast.pseudoElement({name: 'before'})
|
||||
* ]
|
||||
* })
|
||||
* ]
|
||||
* });
|
||||
*
|
||||
* console.log(render(selector)); // a#user-23.user:visited::before
|
||||
*/
|
||||
export declare function render(entity: AstEntity): string;
|
||||
150
node_modules/css-selector-parser/dist/cjs/render.js
generated
vendored
Normal file
150
node_modules/css-selector-parser/dist/cjs/render.js
generated
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.render = void 0;
|
||||
var utils_js_1 = require("./utils.js");
|
||||
var errorPrefix = "css-selector-parser render error: ";
|
||||
function renderNamespace(namespace) {
|
||||
if (namespace.type === 'WildcardNamespace') {
|
||||
return '*|';
|
||||
}
|
||||
else if (namespace.type === 'NamespaceName') {
|
||||
return "".concat((0, utils_js_1.escapeIdentifier)(namespace.name), "|");
|
||||
}
|
||||
else if (namespace.type === 'NoNamespace') {
|
||||
return '|';
|
||||
}
|
||||
throw new Error("".concat(errorPrefix, "Unknown namespace type: ").concat(namespace.type, "."));
|
||||
}
|
||||
function renderSubstitution(sub) {
|
||||
return "$".concat((0, utils_js_1.escapeIdentifier)(sub.name));
|
||||
}
|
||||
function renderFormula(a, b) {
|
||||
if (a) {
|
||||
var result = "".concat(a === 1 ? '' : a === -1 ? '-' : a, "n");
|
||||
if (b) {
|
||||
result += "".concat(b > 0 ? '+' : '').concat(b);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
return String(b);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Renders CSS Selector AST back to a string.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* import {ast, render} from 'css-selector-parser';
|
||||
*
|
||||
* const selector = ast.selector({
|
||||
* rules: [
|
||||
* ast.rule({
|
||||
* items: [
|
||||
* ast.tagName({name: 'a'}),
|
||||
* ast.id({name: 'user-23'}),
|
||||
* ast.className({name: 'user'}),
|
||||
* ast.pseudoClass({name: 'visited'}),
|
||||
* ast.pseudoElement({name: 'before'})
|
||||
* ]
|
||||
* })
|
||||
* ]
|
||||
* });
|
||||
*
|
||||
* console.log(render(selector)); // a#user-23.user:visited::before
|
||||
*/
|
||||
function render(entity) {
|
||||
if (entity.type === 'Selector') {
|
||||
return entity.rules.map(render).join(', ');
|
||||
}
|
||||
if (entity.type === 'Rule') {
|
||||
var result = '';
|
||||
var items = entity.items, combinator = entity.combinator, nestedRule = entity.nestedRule;
|
||||
if (combinator) {
|
||||
result += "".concat(combinator, " ");
|
||||
}
|
||||
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
||||
var item = items_1[_i];
|
||||
result += render(item);
|
||||
}
|
||||
if (nestedRule) {
|
||||
result += " ".concat(render(nestedRule));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else if (entity.type === 'TagName' || entity.type === 'WildcardTag') {
|
||||
var result = '';
|
||||
var namespace = entity.namespace;
|
||||
if (namespace) {
|
||||
result += renderNamespace(namespace);
|
||||
}
|
||||
if (entity.type === 'TagName') {
|
||||
result += (0, utils_js_1.escapeIdentifier)(entity.name);
|
||||
}
|
||||
else if (entity.type === 'WildcardTag') {
|
||||
result += '*';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else if (entity.type === 'Id') {
|
||||
return "#".concat((0, utils_js_1.escapeIdentifier)(entity.name));
|
||||
}
|
||||
else if (entity.type === 'ClassName') {
|
||||
return ".".concat((0, utils_js_1.escapeIdentifier)(entity.name));
|
||||
}
|
||||
else if (entity.type === 'Attribute') {
|
||||
var name_1 = entity.name, namespace = entity.namespace, operator = entity.operator, value = entity.value, caseSensitivityModifier = entity.caseSensitivityModifier;
|
||||
var result = '[';
|
||||
if (namespace) {
|
||||
result += renderNamespace(namespace);
|
||||
}
|
||||
result += (0, utils_js_1.escapeIdentifier)(name_1);
|
||||
if (operator && value) {
|
||||
result += operator;
|
||||
if (value.type === 'String') {
|
||||
result += (0, utils_js_1.escapeString)(value.value);
|
||||
}
|
||||
else if (value.type === 'Substitution') {
|
||||
result += renderSubstitution(value);
|
||||
}
|
||||
else {
|
||||
throw new Error("Unknown attribute value type: ".concat(value.type, "."));
|
||||
}
|
||||
if (caseSensitivityModifier) {
|
||||
result += " ".concat((0, utils_js_1.escapeIdentifier)(caseSensitivityModifier));
|
||||
}
|
||||
}
|
||||
result += ']';
|
||||
return result;
|
||||
}
|
||||
else if (entity.type === 'PseudoClass') {
|
||||
var name_2 = entity.name, argument = entity.argument;
|
||||
var result = ":".concat((0, utils_js_1.escapeIdentifier)(name_2));
|
||||
if (argument) {
|
||||
result += "(".concat(argument.type === 'String' ? (0, utils_js_1.escapeIdentifier)(argument.value) : render(argument), ")");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else if (entity.type === 'PseudoElement') {
|
||||
var name_3 = entity.name, argument = entity.argument;
|
||||
var result = "::".concat((0, utils_js_1.escapeIdentifier)(name_3));
|
||||
if (argument) {
|
||||
result += "(".concat(argument.type === 'String' ? (0, utils_js_1.escapeIdentifier)(argument.value) : render(argument), ")");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else if (entity.type === 'String') {
|
||||
throw new Error("".concat(errorPrefix, "String cannot be rendered outside of context."));
|
||||
}
|
||||
else if (entity.type === 'Formula') {
|
||||
return renderFormula(entity.a, entity.b);
|
||||
}
|
||||
else if (entity.type === 'FormulaOfSelector') {
|
||||
return renderFormula(entity.a, entity.b) + ' of ' + render(entity.selector);
|
||||
}
|
||||
else if (entity.type === 'Substitution') {
|
||||
return "$".concat((0, utils_js_1.escapeIdentifier)(entity.name));
|
||||
}
|
||||
throw new Error("Unknown type specified to render method: ".concat(entity.type, "."));
|
||||
}
|
||||
exports.render = render;
|
||||
134
node_modules/css-selector-parser/dist/cjs/syntax-definitions.d.ts
generated
vendored
Normal file
134
node_modules/css-selector-parser/dist/cjs/syntax-definitions.d.ts
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
import { AstPseudoClassArgument, AstPseudoElementArgument } from './ast.js';
|
||||
export type PseudoClassType = Exclude<'NoArgument' | AstPseudoClassArgument['type'], 'Substitution'>;
|
||||
export type PseudoElementType = Exclude<'NoArgument' | AstPseudoElementArgument['type'], 'Substitution'>;
|
||||
export type CssLevel = 'css1' | 'css2' | 'css3' | 'selectors-3' | 'selectors-4' | 'latest' | 'progressive';
|
||||
/**
|
||||
* CSS Selector Syntax Definition can be used to define custom CSS selector parsing rules.
|
||||
*/
|
||||
export interface SyntaxDefinition {
|
||||
/**
|
||||
* When specified, syntax will be based on the specified predefined CSS standard.
|
||||
* If not specified, syntax will be defined from scratch.
|
||||
*/
|
||||
baseSyntax?: CssLevel;
|
||||
/**
|
||||
* CSS Tag (type).
|
||||
* @example div
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Type_Class_and_ID_Selectors
|
||||
*/
|
||||
tag?: {
|
||||
/**
|
||||
* Allows using wildcard (*).
|
||||
*/
|
||||
wildcard?: boolean;
|
||||
} | boolean;
|
||||
/**
|
||||
* CSS3 Namespaces.
|
||||
* @example ns|div
|
||||
* @see https://www.w3.org/TR/css3-namespace/
|
||||
*/
|
||||
namespace?: {
|
||||
/**
|
||||
* Allows using wildcard (*).
|
||||
*/
|
||||
wildcard?: boolean;
|
||||
} | boolean;
|
||||
/**
|
||||
* CSS IDs (yes, there can be multiple).
|
||||
* @example #root#root
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Type_Class_and_ID_Selectors
|
||||
*/
|
||||
ids?: boolean;
|
||||
/**
|
||||
* CSS Class Names
|
||||
* @example .element.highlighted
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Type_Class_and_ID_Selectors
|
||||
*/
|
||||
classNames?: boolean;
|
||||
/**
|
||||
* CSS selector rule nesting combinators.
|
||||
* @example div.class > span
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Combinators
|
||||
*/
|
||||
combinators?: string[];
|
||||
/**
|
||||
* CSS Attribute Selector.
|
||||
* @example [href="#"]
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Attribute_selectors
|
||||
*/
|
||||
attributes?: {
|
||||
/**
|
||||
* Attribute comparison operator list.
|
||||
* @example ['=', '~=', '|=', '^=', '$=', '*=']
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors#syntax
|
||||
*/
|
||||
operators?: string[];
|
||||
/**
|
||||
* How to handle unknown case sensitivity modifiers.
|
||||
* `accept` - still parse.
|
||||
* `reject` - throw an error.
|
||||
*/
|
||||
unknownCaseSensitivityModifiers?: 'accept' | 'reject';
|
||||
/**
|
||||
* List of pre-defined case sensitivity modifiers.
|
||||
* @example ['i', 'I', 's', 'S']
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors#syntax
|
||||
*/
|
||||
caseSensitivityModifiers?: string[];
|
||||
} | false;
|
||||
/**
|
||||
* CSS Pseudo-elements.
|
||||
* @example ::before
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements
|
||||
*/
|
||||
pseudoElements?: {
|
||||
/**
|
||||
* How to handle unknown pseudo-elements.
|
||||
* `accept` - still parse.
|
||||
* `reject` - throw an error.
|
||||
*/
|
||||
unknown?: 'accept' | 'reject';
|
||||
/**
|
||||
* In the past pseudo selements were defined starting with a single colon.
|
||||
* Later this notation changed to double colon.
|
||||
*/
|
||||
notation?: 'singleColon' | 'doubleColon' | 'both';
|
||||
/**
|
||||
* List of predefined pseudo-elements. If string array is specified, the pseudo-elements are assumed to be
|
||||
* NoArgument.
|
||||
* @example ['before', 'after']
|
||||
* @example {NoArgument: ['before', 'after'], String: ['highlight'], Selector: ['slotted']}
|
||||
*/
|
||||
definitions?: string[] | {
|
||||
[K in PseudoElementType]?: string[];
|
||||
};
|
||||
} | false;
|
||||
/**
|
||||
* CSS Pseudo-classes.
|
||||
* @example :nth-child(2n+1)
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements
|
||||
*/
|
||||
pseudoClasses?: {
|
||||
/**
|
||||
* How to handle unknown pseudo-classes.
|
||||
* `accept` - still parse.
|
||||
* `reject` - throw an error.
|
||||
*/
|
||||
unknown?: 'accept' | 'reject';
|
||||
/**
|
||||
* Predefined pseudo-classes.
|
||||
* @example {NoArgument: ['first-child'], Formula: ['nth-child'], String: ['dir'], Selector: ['not']}
|
||||
*/
|
||||
definitions?: {
|
||||
[K in PseudoClassType]?: string[];
|
||||
};
|
||||
} | false;
|
||||
}
|
||||
interface SyntaxDefinitionXmlOptions {
|
||||
wildcard?: boolean;
|
||||
}
|
||||
export declare function getXmlOptions(param: SyntaxDefinitionXmlOptions | boolean | undefined): SyntaxDefinitionXmlOptions;
|
||||
type MergeMethod<T> = (base: T, extension: T) => T;
|
||||
export declare const extendSyntaxDefinition: MergeMethod<SyntaxDefinition>;
|
||||
export declare const cssSyntaxDefinitions: Record<CssLevel, SyntaxDefinition>;
|
||||
export {};
|
||||
255
node_modules/css-selector-parser/dist/cjs/syntax-definitions.js
generated
vendored
Normal file
255
node_modules/css-selector-parser/dist/cjs/syntax-definitions.js
generated
vendored
Normal file
@@ -0,0 +1,255 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.cssSyntaxDefinitions = exports.extendSyntaxDefinition = exports.getXmlOptions = void 0;
|
||||
var emptyXmlOptions = {};
|
||||
var defaultXmlOptions = { wildcard: true };
|
||||
function getXmlOptions(param) {
|
||||
if (param) {
|
||||
if (typeof param === 'boolean') {
|
||||
return defaultXmlOptions;
|
||||
}
|
||||
else {
|
||||
return param;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return emptyXmlOptions;
|
||||
}
|
||||
}
|
||||
exports.getXmlOptions = getXmlOptions;
|
||||
function withMigration(migration, merge) {
|
||||
return function (base, extension) { return merge(migration(base), migration(extension)); };
|
||||
}
|
||||
function withNoNegative(merge) {
|
||||
return function (base, extension) {
|
||||
var result = merge(base, extension);
|
||||
if (!result) {
|
||||
throw new Error("Syntax definition cannot be null or undefined.");
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
function withPositive(positive, merge) {
|
||||
return function (base, extension) {
|
||||
if (extension === true) {
|
||||
return positive;
|
||||
}
|
||||
return merge(base === true ? positive : base, extension);
|
||||
};
|
||||
}
|
||||
function mergeSection(values) {
|
||||
return function (base, extension) {
|
||||
if (!extension || !base) {
|
||||
return extension;
|
||||
}
|
||||
if (typeof extension !== 'object' || extension === null) {
|
||||
throw new Error("Unexpected syntax definition extension type: ".concat(extension, "."));
|
||||
}
|
||||
var result = __assign({}, base);
|
||||
for (var _i = 0, _a = Object.entries(extension); _i < _a.length; _i++) {
|
||||
var _b = _a[_i], key = _b[0], value = _b[1];
|
||||
var mergeSchema = values[key];
|
||||
result[key] = mergeSchema(base[key], value);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
function replaceValueIfSpecified(base, extension) {
|
||||
if (extension !== undefined) {
|
||||
return extension;
|
||||
}
|
||||
return base;
|
||||
}
|
||||
function concatArray(base, extension) {
|
||||
if (!extension) {
|
||||
return base;
|
||||
}
|
||||
if (!base) {
|
||||
return extension;
|
||||
}
|
||||
return base.concat(extension);
|
||||
}
|
||||
function mergeDefinitions(base, extension) {
|
||||
if (!extension) {
|
||||
return base;
|
||||
}
|
||||
if (!base) {
|
||||
return extension;
|
||||
}
|
||||
var result = __assign({}, base);
|
||||
for (var _i = 0, _a = Object.entries(extension); _i < _a.length; _i++) {
|
||||
var _b = _a[_i], key = _b[0], value = _b[1];
|
||||
if (!value) {
|
||||
delete result[key];
|
||||
continue;
|
||||
}
|
||||
var baseValue = base[key];
|
||||
if (!baseValue) {
|
||||
result[key] = value;
|
||||
continue;
|
||||
}
|
||||
result[key] = baseValue.concat(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.extendSyntaxDefinition = withNoNegative(mergeSection({
|
||||
baseSyntax: replaceValueIfSpecified,
|
||||
tag: withPositive(defaultXmlOptions, mergeSection({
|
||||
wildcard: replaceValueIfSpecified
|
||||
})),
|
||||
ids: replaceValueIfSpecified,
|
||||
classNames: replaceValueIfSpecified,
|
||||
namespace: withPositive(defaultXmlOptions, mergeSection({
|
||||
wildcard: replaceValueIfSpecified
|
||||
})),
|
||||
combinators: concatArray,
|
||||
attributes: mergeSection({
|
||||
operators: concatArray,
|
||||
caseSensitivityModifiers: concatArray,
|
||||
unknownCaseSensitivityModifiers: replaceValueIfSpecified
|
||||
}),
|
||||
pseudoClasses: mergeSection({
|
||||
unknown: replaceValueIfSpecified,
|
||||
definitions: mergeDefinitions
|
||||
}),
|
||||
pseudoElements: mergeSection({
|
||||
unknown: replaceValueIfSpecified,
|
||||
notation: replaceValueIfSpecified,
|
||||
definitions: withMigration(function (definitions) { return (Array.isArray(definitions) ? { NoArgument: definitions } : definitions); }, mergeDefinitions)
|
||||
})
|
||||
}));
|
||||
var css1SyntaxDefinition = {
|
||||
tag: {},
|
||||
ids: true,
|
||||
classNames: true,
|
||||
combinators: [],
|
||||
pseudoElements: {
|
||||
unknown: 'reject',
|
||||
notation: 'singleColon',
|
||||
definitions: ['first-letter', 'first-line']
|
||||
},
|
||||
pseudoClasses: {
|
||||
unknown: 'reject',
|
||||
definitions: {
|
||||
NoArgument: ['link', 'visited', 'active']
|
||||
}
|
||||
}
|
||||
};
|
||||
var css2SyntaxDefinition = (0, exports.extendSyntaxDefinition)(css1SyntaxDefinition, {
|
||||
tag: { wildcard: true },
|
||||
combinators: ['>', '+'],
|
||||
attributes: {
|
||||
unknownCaseSensitivityModifiers: 'reject',
|
||||
operators: ['=', '~=', '|=']
|
||||
},
|
||||
pseudoElements: {
|
||||
definitions: ['before', 'after']
|
||||
},
|
||||
pseudoClasses: {
|
||||
unknown: 'reject',
|
||||
definitions: {
|
||||
NoArgument: ['hover', 'focus', 'first-child'],
|
||||
String: ['lang']
|
||||
}
|
||||
}
|
||||
});
|
||||
var selectors3SyntaxDefinition = (0, exports.extendSyntaxDefinition)(css2SyntaxDefinition, {
|
||||
namespace: {
|
||||
wildcard: true
|
||||
},
|
||||
combinators: ['~'],
|
||||
attributes: {
|
||||
operators: ['^=', '$=', '*=']
|
||||
},
|
||||
pseudoElements: {
|
||||
notation: 'both'
|
||||
},
|
||||
pseudoClasses: {
|
||||
definitions: {
|
||||
NoArgument: [
|
||||
'root',
|
||||
'last-child',
|
||||
'first-of-type',
|
||||
'last-of-type',
|
||||
'only-child',
|
||||
'only-of-type',
|
||||
'empty',
|
||||
'target',
|
||||
'enabled',
|
||||
'disabled',
|
||||
'checked',
|
||||
'indeterminate'
|
||||
],
|
||||
Formula: ['nth-child', 'nth-last-child', 'nth-of-type', 'nth-last-of-type'],
|
||||
Selector: ['not']
|
||||
}
|
||||
}
|
||||
});
|
||||
var selectors4SyntaxDefinition = (0, exports.extendSyntaxDefinition)(selectors3SyntaxDefinition, {
|
||||
combinators: ['||'],
|
||||
attributes: {
|
||||
caseSensitivityModifiers: ['i', 'I', 's', 'S']
|
||||
},
|
||||
pseudoClasses: {
|
||||
definitions: {
|
||||
NoArgument: [
|
||||
'any-link',
|
||||
'local-link',
|
||||
'target-within',
|
||||
'scope',
|
||||
'current',
|
||||
'past',
|
||||
'future',
|
||||
'focus-within',
|
||||
'focus-visible',
|
||||
'read-write',
|
||||
'read-only',
|
||||
'placeholder-shown',
|
||||
'default',
|
||||
'valid',
|
||||
'invalid',
|
||||
'in-range',
|
||||
'out-of-range',
|
||||
'required',
|
||||
'optional',
|
||||
'blank',
|
||||
'user-invalid'
|
||||
],
|
||||
Formula: ['nth-col', 'nth-last-col'],
|
||||
String: ['dir'],
|
||||
FormulaOfSelector: ['nth-child', 'nth-last-child'],
|
||||
Selector: ['current', 'is', 'where', 'has']
|
||||
}
|
||||
}
|
||||
});
|
||||
var progressiveSyntaxDefinition = (0, exports.extendSyntaxDefinition)(selectors4SyntaxDefinition, {
|
||||
pseudoElements: {
|
||||
unknown: 'accept'
|
||||
},
|
||||
pseudoClasses: {
|
||||
unknown: 'accept'
|
||||
},
|
||||
attributes: {
|
||||
unknownCaseSensitivityModifiers: 'accept'
|
||||
}
|
||||
});
|
||||
exports.cssSyntaxDefinitions = {
|
||||
css1: css1SyntaxDefinition,
|
||||
css2: css2SyntaxDefinition,
|
||||
css3: selectors3SyntaxDefinition,
|
||||
'selectors-3': selectors3SyntaxDefinition,
|
||||
'selectors-4': selectors4SyntaxDefinition,
|
||||
latest: selectors4SyntaxDefinition,
|
||||
progressive: progressiveSyntaxDefinition
|
||||
};
|
||||
11
node_modules/css-selector-parser/dist/cjs/utils.d.ts
generated
vendored
Normal file
11
node_modules/css-selector-parser/dist/cjs/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export declare function isIdentStart(c: string): boolean;
|
||||
export declare function isIdent(c: string): boolean;
|
||||
export declare function isHex(c: string): boolean;
|
||||
export declare const identEscapeChars: Record<string, boolean>;
|
||||
export declare const stringRenderEscapeChars: Record<string, boolean>;
|
||||
export declare const whitespaceChars: Record<string, boolean>;
|
||||
export declare const quoteChars: Record<string, boolean>;
|
||||
export declare const digitsChars: Record<string, boolean>;
|
||||
export declare const maxHexLength = 6;
|
||||
export declare function escapeIdentifier(s: string): string;
|
||||
export declare function escapeString(s: string): string;
|
||||
137
node_modules/css-selector-parser/dist/cjs/utils.js
generated
vendored
Normal file
137
node_modules/css-selector-parser/dist/cjs/utils.js
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.escapeString = exports.escapeIdentifier = exports.maxHexLength = exports.digitsChars = exports.quoteChars = exports.whitespaceChars = exports.stringRenderEscapeChars = exports.identEscapeChars = exports.isHex = exports.isIdent = exports.isIdentStart = void 0;
|
||||
function isIdentStart(c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c === '-' || c === '_' || c === '\\' || c >= '\u00a0';
|
||||
}
|
||||
exports.isIdentStart = isIdentStart;
|
||||
function isIdent(c) {
|
||||
return ((c >= 'a' && c <= 'z') ||
|
||||
(c >= 'A' && c <= 'Z') ||
|
||||
(c >= '0' && c <= '9') ||
|
||||
c === '-' ||
|
||||
c === '_' ||
|
||||
c >= '\u00a0');
|
||||
}
|
||||
exports.isIdent = isIdent;
|
||||
function isHex(c) {
|
||||
return (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || (c >= '0' && c <= '9');
|
||||
}
|
||||
exports.isHex = isHex;
|
||||
exports.identEscapeChars = {
|
||||
'!': true,
|
||||
'"': true,
|
||||
'#': true,
|
||||
$: true,
|
||||
'%': true,
|
||||
'&': true,
|
||||
"'": true,
|
||||
'(': true,
|
||||
')': true,
|
||||
'*': true,
|
||||
'+': true,
|
||||
',': true,
|
||||
'.': true,
|
||||
'/': true,
|
||||
';': true,
|
||||
'<': true,
|
||||
'=': true,
|
||||
'>': true,
|
||||
'?': true,
|
||||
'@': true,
|
||||
'[': true,
|
||||
'\\': true,
|
||||
']': true,
|
||||
'^': true,
|
||||
'`': true,
|
||||
'{': true,
|
||||
'|': true,
|
||||
'}': true,
|
||||
'~': true
|
||||
};
|
||||
exports.stringRenderEscapeChars = {
|
||||
'\n': true,
|
||||
'\r': true,
|
||||
'\t': true,
|
||||
'\f': true,
|
||||
'\v': true
|
||||
};
|
||||
exports.whitespaceChars = {
|
||||
' ': true,
|
||||
'\t': true,
|
||||
'\n': true,
|
||||
'\r': true,
|
||||
'\f': true
|
||||
};
|
||||
exports.quoteChars = {
|
||||
'"': true,
|
||||
"'": true
|
||||
};
|
||||
exports.digitsChars = {
|
||||
0: true,
|
||||
1: true,
|
||||
2: true,
|
||||
3: true,
|
||||
4: true,
|
||||
5: true,
|
||||
6: true,
|
||||
7: true,
|
||||
8: true,
|
||||
9: true
|
||||
};
|
||||
exports.maxHexLength = 6;
|
||||
function escapeIdentifier(s) {
|
||||
var len = s.length;
|
||||
var result = '';
|
||||
var i = 0;
|
||||
while (i < len) {
|
||||
var chr = s.charAt(i);
|
||||
if (exports.identEscapeChars[chr] || (chr === '-' && i === 1 && s.charAt(0) === '-')) {
|
||||
result += '\\' + chr;
|
||||
}
|
||||
else {
|
||||
if (chr === '-' ||
|
||||
chr === '_' ||
|
||||
(chr >= 'A' && chr <= 'Z') ||
|
||||
(chr >= 'a' && chr <= 'z') ||
|
||||
(chr >= '0' && chr <= '9' && i !== 0 && !(i === 1 && s.charAt(0) === '-'))) {
|
||||
result += chr;
|
||||
}
|
||||
else {
|
||||
var charCode = chr.charCodeAt(0);
|
||||
if ((charCode & 0xf800) === 0xd800) {
|
||||
var extraCharCode = s.charCodeAt(i++);
|
||||
if ((charCode & 0xfc00) !== 0xd800 || (extraCharCode & 0xfc00) !== 0xdc00) {
|
||||
throw Error('UCS-2(decode): illegal sequence');
|
||||
}
|
||||
charCode = ((charCode & 0x3ff) << 10) + (extraCharCode & 0x3ff) + 0x10000;
|
||||
}
|
||||
result += '\\' + charCode.toString(16) + ' ';
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return result.trim();
|
||||
}
|
||||
exports.escapeIdentifier = escapeIdentifier;
|
||||
function escapeString(s) {
|
||||
var len = s.length;
|
||||
var result = '';
|
||||
var i = 0;
|
||||
while (i < len) {
|
||||
var chr = s.charAt(i);
|
||||
if (chr === '"') {
|
||||
chr = '\\"';
|
||||
}
|
||||
else if (chr === '\\') {
|
||||
chr = '\\\\';
|
||||
}
|
||||
else if (exports.stringRenderEscapeChars[chr]) {
|
||||
chr = '\\' + chr.charCodeAt(0).toString(16) + (i === len - 1 ? '' : ' ');
|
||||
}
|
||||
result += chr;
|
||||
i++;
|
||||
}
|
||||
return "\"".concat(result, "\"");
|
||||
}
|
||||
exports.escapeString = escapeString;
|
||||
286
node_modules/css-selector-parser/dist/mjs/ast.d.ts
generated
vendored
Normal file
286
node_modules/css-selector-parser/dist/mjs/ast.d.ts
generated
vendored
Normal file
@@ -0,0 +1,286 @@
|
||||
/**
|
||||
* CSS Selector AST root.
|
||||
* Contains list of CSS rules (separated by a comma in the input CSS selector string).
|
||||
* Generated by {@link AstFactory.selector ast.selector}.
|
||||
*/
|
||||
export interface AstSelector {
|
||||
type: 'Selector';
|
||||
/**
|
||||
* List of CSS rules. Every rule contains conditions. Selector is considered matched once at least one rule matches.
|
||||
*/
|
||||
rules: AstRule[];
|
||||
}
|
||||
/**
|
||||
* A single CSS rule that contains match conditions.
|
||||
* Can nest another rule with or without a combinator (i.e. `"div > span"`).
|
||||
* Generated by {@link AstFactory.rule ast.rule}.
|
||||
*/
|
||||
export interface AstRule {
|
||||
type: 'Rule';
|
||||
/** Items of a CSS rule. Can be tag, ids, class names, pseudo-classes and pseudo-elements. */
|
||||
items: (AstTagName | AstWildcardTag | AstId | AstClassName | AstAttribute | AstPseudoClass | AstPseudoElement)[];
|
||||
/** Rule combinator which was used to nest this rule (i.e. `">"` in case of `"div > span"` if the current rule is `"span"`). */
|
||||
combinator?: string;
|
||||
/** Nested rule if specified (i.e. `"div > span"`). */
|
||||
nestedRule?: AstRule;
|
||||
}
|
||||
/**
|
||||
* Named tag, i.e. `"div"`. Part of CSS Qualified Names.
|
||||
* Generated by {@link AstFactory.tagName ast.tagName}.
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Type_selectors
|
||||
* @see https://drafts.csswg.org/css-namespaces-3/#css-qnames
|
||||
*/
|
||||
export interface AstTagName {
|
||||
type: 'TagName';
|
||||
/** Tag name, i.e. `"div"`. */
|
||||
name: string;
|
||||
/** Namespace according to https://www.w3.org/TR/css3-namespace/. */
|
||||
namespace?: AstNamespaceName | AstWildcardNamespace | AstNoNamespace;
|
||||
}
|
||||
/**
|
||||
* ID condition. Matches by id attribute value.
|
||||
* Generated by {@link AstFactory.id ast.id}.
|
||||
* https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors
|
||||
* @example "#root"
|
||||
*/
|
||||
export interface AstId {
|
||||
type: 'Id';
|
||||
/** ID name. I.e. `#root` -> `"root"`. */
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* Class name condition. Matches by class attribute value.
|
||||
* Generated by {@link AstFactory.className ast.className}.
|
||||
* https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors
|
||||
* @example ".user"
|
||||
*/
|
||||
export interface AstClassName {
|
||||
type: 'ClassName';
|
||||
/** ID name. I.e. `.user` -> `"user"`. */
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* Wildcard tag (universal selector): `*`.
|
||||
* Generated by {@link AstFactory.wildcardTag ast.wildcardTag}.
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors
|
||||
* @see https://drafts.csswg.org/css-namespaces-3/#css-qnames
|
||||
*/
|
||||
export interface AstWildcardTag {
|
||||
type: 'WildcardTag';
|
||||
/** Namespace according to https://www.w3.org/TR/css3-namespace/. */
|
||||
namespace?: AstNamespaceName | AstWildcardNamespace | AstNoNamespace;
|
||||
}
|
||||
/**
|
||||
* Named namespace declaration (i.e. `ns|div`).
|
||||
* Generated by {@link AstFactory.namespaceName ast.namespaceName}.
|
||||
* @see https://drafts.csswg.org/css-namespaces-3/#css-qnames
|
||||
*/
|
||||
export interface AstNamespaceName {
|
||||
type: 'NamespaceName';
|
||||
/** Namespace name (i.e. `"ns"` in case of `"ns|div"`). "*/
|
||||
name: string;
|
||||
}
|
||||
/**
|
||||
* Wildcard namespace (universal selector): `*`.
|
||||
* Generated by {@link AstFactory.wildcardNamespace ast.wildcardNamespace}.
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Universal_selectors
|
||||
* @see https://drafts.csswg.org/css-namespaces-3/#css-qnames
|
||||
*/
|
||||
export interface AstWildcardNamespace {
|
||||
type: 'WildcardNamespace';
|
||||
}
|
||||
/**
|
||||
* Explicit no-namespace declaration (i.e. `|div`).
|
||||
* Generated by {@link AstFactory.noNamespace ast.noNamespace}.
|
||||
* @see https://drafts.csswg.org/css-namespaces-3/#css-qnames
|
||||
*/
|
||||
export interface AstNoNamespace {
|
||||
type: 'NoNamespace';
|
||||
}
|
||||
/**
|
||||
* Attribute selector.
|
||||
* Generated by {@link AstFactory.attribute ast.attribute}.
|
||||
* @example "[role='button' i]"
|
||||
*/
|
||||
export interface AstAttribute {
|
||||
type: 'Attribute';
|
||||
/** Attribute name (i.e. `"href"` in case if `"[href]"`). */
|
||||
name: string;
|
||||
/** Namespace according to https://drafts.csswg.org/selectors/#attrnmsp. */
|
||||
namespace?: AstNamespaceName | AstWildcardNamespace | AstNoNamespace;
|
||||
/** Comparison operator (i.e. `"|="` in case if `"[role|=button]"`). */
|
||||
operator?: string;
|
||||
/** Comparison value (i.e. `"button"` in case if `"[role=button]"`). */
|
||||
value?: AstString | AstSubstitution;
|
||||
/** Comparison case sensitivity modifier (i.e. `"i"` in case if `"[role='button' i]"`). */
|
||||
caseSensitivityModifier?: string;
|
||||
}
|
||||
/**
|
||||
* Pseudo-class selector.
|
||||
* Generated by {@link AstFactory.pseudoClass ast.pseudoClass}.
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements
|
||||
* @example ":lang(en)"
|
||||
*/
|
||||
export interface AstPseudoClass {
|
||||
type: 'PseudoClass';
|
||||
/** Pseudo-class name (i.e. `"hover"` in case of `":hover"`). */
|
||||
name: string;
|
||||
/** Pseudo-class value (i.e. `"en"` in case of `":lang(en)"`). */
|
||||
argument?: AstSubstitution | AstSelector | AstString | AstFormula | AstFormulaOfSelector;
|
||||
}
|
||||
/**
|
||||
* Pseudo-class selector.
|
||||
* Generated by {@link AstFactory.pseudoElement ast.pseudoElement}.
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements
|
||||
* @example "::before"
|
||||
*/
|
||||
export interface AstPseudoElement {
|
||||
type: 'PseudoElement';
|
||||
/** Pseudo-element name (i.e. `"before"` in case of `"::before"`). */
|
||||
name: string;
|
||||
/** Pseudo-element value (i.e. `"foo"` in case of `"::part(foo)"`). */
|
||||
argument?: AstSubstitution | AstString | AstSelector;
|
||||
}
|
||||
/**
|
||||
* String value. Can be used as attribute value of pseudo-class string value.
|
||||
* For instance `:lang(en)` -> `{type: 'AstPseudoClass'..., argument: {type: 'String', value: 'en'}}`.
|
||||
* Generated by {@link AstFactory.string ast.string}.
|
||||
*/
|
||||
export interface AstString {
|
||||
type: 'String';
|
||||
/** The actual string value. */
|
||||
value: string;
|
||||
}
|
||||
/**
|
||||
* Pseudo-class formula value. `a` is multiplier of `n` and `b` us added on top. Formula: `an + b`.
|
||||
* For instance `:nth-child(2n + 1)` -> `{type: 'AstPseudoClass'..., argument: {type: 'Formula', a: 2, b: 1}}`.
|
||||
* Generated by {@link AstFactory.formula ast.formula}.
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child#functional_notation
|
||||
*/
|
||||
export interface AstFormula {
|
||||
type: 'Formula';
|
||||
/** Multiplier of `n`. */
|
||||
a: number;
|
||||
/** Constant added to `a*n`. */
|
||||
b: number;
|
||||
}
|
||||
/**
|
||||
* Pseudo-class formula of selector value. `a` is multiplier of `n` and `b` us added on top. Formula: `an + b`.
|
||||
* Formula is followed by `of` keyword and then goes a CSS selector.
|
||||
* For instance `:nth-child(2n + 1 of div)` ->
|
||||
* `{type: 'AstPseudoClass'..., argument: {type: 'FormulaOfSelector', a: 2, b: 1, selector: {type: 'Selector', rules: [{type: 'Rule', items: [{type: 'TagName', name: 'div'}]}]}}}`.
|
||||
* Generated by {@link AstFactory.formulaOfSelector ast.formulaOfSelector}.
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child#functional_notation
|
||||
*/
|
||||
export interface AstFormulaOfSelector {
|
||||
type: 'FormulaOfSelector';
|
||||
/** Multiplier of `n`. */
|
||||
a: number;
|
||||
/** Constant added to `a*n`. */
|
||||
b: number;
|
||||
/** Selector that goes after formula (i.e. `"div -> span"` in case of `":nth-child(2n + 1 of div > span)"` */
|
||||
selector: AstRule;
|
||||
}
|
||||
/**
|
||||
* Substitution is not part of CSS spec, but rather a useful extension on top of CSS if you need to pass variables.
|
||||
* Generated by {@link AstFactory.substitution ast.substitution}.
|
||||
*/
|
||||
export interface AstSubstitution {
|
||||
type: 'Substitution';
|
||||
/** Substitution name (i.e. "var" in case of `"[role=$var]"` or `":lang($var)"`). */
|
||||
name: string;
|
||||
}
|
||||
/** One of pseudo-class argument types. */
|
||||
export type AstPseudoClassArgument = AstSubstitution | AstSelector | AstString | AstFormula | AstFormulaOfSelector;
|
||||
/** One of pseudo-element argument types. */
|
||||
export type AstPseudoElementArgument = AstSubstitution | AstString | AstSelector;
|
||||
/** One of CSS AST entity types. */
|
||||
export type AstEntity = AstSelector | AstRule | AstTagName | AstWildcardTag | AstId | AstClassName | AstNamespaceName | AstWildcardNamespace | AstNoNamespace | AstSubstitution | AstString | AstFormula | AstFormulaOfSelector | AstPseudoClass | AstAttribute | AstPseudoElement;
|
||||
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never;
|
||||
type ToAstFactory<T> = UnionToIntersection<T extends {
|
||||
type: infer Type;
|
||||
} ? Type extends string ? {
|
||||
[K in Uncapitalize<Type>]: {} extends Omit<T, 'type'> ? (props?: {
|
||||
[PK in keyof Omit<T, 'type'>]: Omit<T, 'type'>[PK];
|
||||
}) => T : (props: {
|
||||
[PK in keyof Omit<T, 'type'>]: Omit<T, 'type'>[PK];
|
||||
}) => T;
|
||||
} & {
|
||||
[K in `is${Type}`]: (entity: unknown) => entity is T;
|
||||
} : never : never>;
|
||||
/** @internal */
|
||||
type AstFactoryBase = {
|
||||
[K in keyof ToAstFactory<AstEntity>]: ToAstFactory<AstEntity>[K];
|
||||
};
|
||||
/**
|
||||
* AST structure generators and matchers.
|
||||
* For instance, `ast.selector({rules: [...]})` creates AstSelector and `ast.isSelector(...)` checks if
|
||||
* AstSelector was specified.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* // Represents CSS selector: ns|div#user-34.user.user-active[role="button"]:lang(en)::before > *
|
||||
* const selector = ast.selector({
|
||||
* rules: [
|
||||
* ast.rule({
|
||||
* items: [
|
||||
* ast.tagName({name: 'div', namespace: ast.namespaceName({name: 'ns'})}),
|
||||
* ast.id({name: 'user-34'}),
|
||||
* ast.className({name: 'user'}),
|
||||
* ast.className({name: 'user-active'}),
|
||||
* ast.attribute({
|
||||
* name: 'role',
|
||||
* operator: '=',
|
||||
* value: ast.string({value: 'button'})
|
||||
* }),
|
||||
* ast.pseudoClass({
|
||||
* name: 'lang',
|
||||
* argument: ast.string({value: 'en'})
|
||||
* }),
|
||||
* ast.pseudoElement({name: 'before'})
|
||||
* ],
|
||||
* nestedRule: ast.rule({combinator: '>', items: [ast.wildcardTag()]})
|
||||
* })
|
||||
* ]
|
||||
* });
|
||||
* console.log(ast.isSelector(selector)); // prints true
|
||||
* console.log(ast.isRule(selector)); // prints false
|
||||
*/
|
||||
export interface AstFactory extends AstFactoryBase {
|
||||
}
|
||||
/**
|
||||
* AST structure generators and matchers.
|
||||
* For instance, `ast.selector({rules: [...]})` creates AstSelector and `ast.isSelector(...)` checks if
|
||||
* AstSelector was specified.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* // Represents CSS selector: ns|div#user-34.user.user-active[role="button"]:lang(en)::before > *
|
||||
* const selector = ast.selector({
|
||||
* rules: [
|
||||
* ast.rule({
|
||||
* items: [
|
||||
* ast.tagName({name: 'div', namespace: ast.namespaceName({name: 'ns'})}),
|
||||
* ast.id({name: 'user-34'}),
|
||||
* ast.className({name: 'user'}),
|
||||
* ast.className({name: 'user-active'}),
|
||||
* ast.attribute({
|
||||
* name: 'role',
|
||||
* operator: '=',
|
||||
* value: ast.string({value: 'button'})
|
||||
* }),
|
||||
* ast.pseudoClass({
|
||||
* name: 'lang',
|
||||
* argument: ast.string({value: 'en'})
|
||||
* }),
|
||||
* ast.pseudoElement({name: 'before'})
|
||||
* ],
|
||||
* nestedRule: ast.rule({combinator: '>', items: [ast.wildcardTag()]})
|
||||
* })
|
||||
* ]
|
||||
* });
|
||||
* console.log(ast.isSelector(selector)); // prints true
|
||||
* console.log(ast.isRule(selector)); // prints false
|
||||
*/
|
||||
export declare const ast: AstFactory;
|
||||
export {};
|
||||
57
node_modules/css-selector-parser/dist/mjs/ast.js
generated
vendored
Normal file
57
node_modules/css-selector-parser/dist/mjs/ast.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
function astMethods(type) {
|
||||
return function (generatorName, checkerName) {
|
||||
var _a;
|
||||
return (_a = {},
|
||||
_a[generatorName] = function (props) { return (__assign({ type: type }, props)); },
|
||||
_a[checkerName] = function (entity) {
|
||||
return typeof entity === 'object' && entity !== null && entity.type === type;
|
||||
},
|
||||
_a);
|
||||
};
|
||||
}
|
||||
/**
|
||||
* AST structure generators and matchers.
|
||||
* For instance, `ast.selector({rules: [...]})` creates AstSelector and `ast.isSelector(...)` checks if
|
||||
* AstSelector was specified.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* // Represents CSS selector: ns|div#user-34.user.user-active[role="button"]:lang(en)::before > *
|
||||
* const selector = ast.selector({
|
||||
* rules: [
|
||||
* ast.rule({
|
||||
* items: [
|
||||
* ast.tagName({name: 'div', namespace: ast.namespaceName({name: 'ns'})}),
|
||||
* ast.id({name: 'user-34'}),
|
||||
* ast.className({name: 'user'}),
|
||||
* ast.className({name: 'user-active'}),
|
||||
* ast.attribute({
|
||||
* name: 'role',
|
||||
* operator: '=',
|
||||
* value: ast.string({value: 'button'})
|
||||
* }),
|
||||
* ast.pseudoClass({
|
||||
* name: 'lang',
|
||||
* argument: ast.string({value: 'en'})
|
||||
* }),
|
||||
* ast.pseudoElement({name: 'before'})
|
||||
* ],
|
||||
* nestedRule: ast.rule({combinator: '>', items: [ast.wildcardTag()]})
|
||||
* })
|
||||
* ]
|
||||
* });
|
||||
* console.log(ast.isSelector(selector)); // prints true
|
||||
* console.log(ast.isRule(selector)); // prints false
|
||||
*/
|
||||
export var ast = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, astMethods('Selector')('selector', 'isSelector')), astMethods('Rule')('rule', 'isRule')), astMethods('TagName')('tagName', 'isTagName')), astMethods('Id')('id', 'isId')), astMethods('ClassName')('className', 'isClassName')), astMethods('WildcardTag')('wildcardTag', 'isWildcardTag')), astMethods('NamespaceName')('namespaceName', 'isNamespaceName')), astMethods('WildcardNamespace')('wildcardNamespace', 'isWildcardNamespace')), astMethods('NoNamespace')('noNamespace', 'isNoNamespace')), astMethods('Attribute')('attribute', 'isAttribute')), astMethods('PseudoClass')('pseudoClass', 'isPseudoClass')), astMethods('PseudoElement')('pseudoElement', 'isPseudoElement')), astMethods('String')('string', 'isString')), astMethods('Formula')('formula', 'isFormula')), astMethods('FormulaOfSelector')('formulaOfSelector', 'isFormulaOfSelector')), astMethods('Substitution')('substitution', 'isSubstitution'));
|
||||
4
node_modules/css-selector-parser/dist/mjs/index.d.ts
generated
vendored
Normal file
4
node_modules/css-selector-parser/dist/mjs/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export { createParser, Parser, ParserError } from './parser.js';
|
||||
export { render } from './render.js';
|
||||
export { ast, AstAttribute, AstClassName, AstEntity, AstFactory, AstFormula, AstFormulaOfSelector, AstId, AstNamespaceName, AstNoNamespace, AstPseudoClass, AstPseudoElement, AstRule, AstSelector, AstString, AstSubstitution, AstTagName, AstWildcardNamespace, AstWildcardTag } from './ast.js';
|
||||
export { CssLevel, SyntaxDefinition } from './syntax-definitions.js';
|
||||
3
node_modules/css-selector-parser/dist/mjs/index.js
generated
vendored
Normal file
3
node_modules/css-selector-parser/dist/mjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export { createParser } from './parser.js';
|
||||
export { render } from './render.js';
|
||||
export { ast } from './ast.js';
|
||||
13
node_modules/css-selector-parser/dist/mjs/indexes.d.ts
generated
vendored
Normal file
13
node_modules/css-selector-parser/dist/mjs/indexes.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface MulticharIndex {
|
||||
[key: string]: MulticharIndexChar;
|
||||
}
|
||||
export interface MulticharIndexChar {
|
||||
chars: MulticharIndex;
|
||||
self?: string;
|
||||
}
|
||||
type RegularIndex = Record<string, boolean>;
|
||||
export declare const emptyMulticharIndex: MulticharIndex;
|
||||
export declare const emptyRegularIndex: RegularIndex;
|
||||
export declare function createMulticharIndex(items: string[]): MulticharIndex;
|
||||
export declare function createRegularIndex(items: string[]): RegularIndex;
|
||||
export {};
|
||||
36
node_modules/css-selector-parser/dist/mjs/indexes.js
generated
vendored
Normal file
36
node_modules/css-selector-parser/dist/mjs/indexes.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
export var emptyMulticharIndex = {};
|
||||
export var emptyRegularIndex = {};
|
||||
function extendIndex(item, index) {
|
||||
var currentIndex = index;
|
||||
for (var pos = 0; pos < item.length; pos++) {
|
||||
var isLast = pos === item.length - 1;
|
||||
var char = item.charAt(pos);
|
||||
var charIndex = currentIndex[char] || (currentIndex[char] = { chars: {} });
|
||||
if (isLast) {
|
||||
charIndex.self = item;
|
||||
}
|
||||
currentIndex = charIndex.chars;
|
||||
}
|
||||
}
|
||||
export function createMulticharIndex(items) {
|
||||
if (items.length === 0) {
|
||||
return emptyMulticharIndex;
|
||||
}
|
||||
var index = {};
|
||||
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
||||
var item = items_1[_i];
|
||||
extendIndex(item, index);
|
||||
}
|
||||
return index;
|
||||
}
|
||||
export function createRegularIndex(items) {
|
||||
if (items.length === 0) {
|
||||
return emptyRegularIndex;
|
||||
}
|
||||
var result = {};
|
||||
for (var _i = 0, items_2 = items; _i < items_2.length; _i++) {
|
||||
var item = items_2[_i];
|
||||
result[item] = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
1
node_modules/css-selector-parser/dist/mjs/package.json
generated
vendored
Normal file
1
node_modules/css-selector-parser/dist/mjs/package.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"type": "module"}
|
||||
41
node_modules/css-selector-parser/dist/mjs/parser.d.ts
generated
vendored
Normal file
41
node_modules/css-selector-parser/dist/mjs/parser.d.ts
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { AstSelector } from './ast.js';
|
||||
import { CssLevel, SyntaxDefinition } from './syntax-definitions.js';
|
||||
/**
|
||||
* This error is thrown when parser encounters problems in CSS string.
|
||||
* On top of the usual error, it has `position` property to indicate where in the input string the error happened.
|
||||
*/
|
||||
export interface ParserError extends Error {
|
||||
message: string;
|
||||
name: 'ParserError';
|
||||
position: number;
|
||||
}
|
||||
/**
|
||||
* Parses CSS selector string and returns CSS selector AST.
|
||||
* @throws {ParserError}
|
||||
*/
|
||||
export type Parser = (input: string) => AstSelector;
|
||||
/**
|
||||
* Creates a parse function to be used later to parse CSS selectors.
|
||||
*/
|
||||
export declare function createParser(options?: {
|
||||
/**
|
||||
* CSS Syntax options to be used for parsing.
|
||||
* Can either be one of the predefined CSS levels ({@link CssLevel}) or a more detailed syntax definition ({@link SyntaxDefinition}).
|
||||
* Default: `"latest"`
|
||||
*/
|
||||
syntax?: CssLevel | SyntaxDefinition;
|
||||
/**
|
||||
* Flag to enable substitutes.
|
||||
* This is not part of CSS syntax, but rather a useful feature to pass variables into CSS selectors.
|
||||
* Default: `false`
|
||||
* @example "[attr=$variable]"
|
||||
*/
|
||||
substitutes?: boolean;
|
||||
/**
|
||||
* CSS selector parser in modern browsers is very forgiving. For instance, it works fine with unclosed attribute
|
||||
* selectors: `"[attr=value"`.
|
||||
* Set to `false` in order to mimic browser behaviour.
|
||||
* Default: `true`
|
||||
*/
|
||||
strict?: boolean;
|
||||
}): Parser;
|
||||
722
node_modules/css-selector-parser/dist/mjs/parser.js
generated
vendored
Normal file
722
node_modules/css-selector-parser/dist/mjs/parser.js
generated
vendored
Normal file
@@ -0,0 +1,722 @@
|
||||
import { createMulticharIndex, createRegularIndex, emptyMulticharIndex, emptyRegularIndex } from './indexes.js';
|
||||
import { calculatePseudoSignatures, defaultPseudoSignature, emptyPseudoSignatures } from './pseudo-signatures.js';
|
||||
import { cssSyntaxDefinitions, extendSyntaxDefinition, getXmlOptions } from './syntax-definitions.js';
|
||||
import { digitsChars, isHex, isIdent, isIdentStart, maxHexLength, quoteChars, whitespaceChars } from './utils.js';
|
||||
var errorPrefix = "css-selector-parser parse error: ";
|
||||
/**
|
||||
* Creates a parse function to be used later to parse CSS selectors.
|
||||
*/
|
||||
export function createParser(options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
var _a = options.syntax, syntax = _a === void 0 ? 'latest' : _a, substitutes = options.substitutes, _b = options.strict, strict = _b === void 0 ? true : _b;
|
||||
var syntaxDefinition = typeof syntax === 'object' ? syntax : cssSyntaxDefinitions[syntax];
|
||||
if (syntaxDefinition.baseSyntax) {
|
||||
syntaxDefinition = extendSyntaxDefinition(cssSyntaxDefinitions[syntaxDefinition.baseSyntax], syntaxDefinition);
|
||||
}
|
||||
var _c = syntaxDefinition.tag
|
||||
? [true, Boolean(getXmlOptions(syntaxDefinition.tag).wildcard)]
|
||||
: [false, false], tagNameEnabled = _c[0], tagNameWildcardEnabled = _c[1];
|
||||
var idEnabled = Boolean(syntaxDefinition.ids);
|
||||
var classNamesEnabled = Boolean(syntaxDefinition.classNames);
|
||||
var namespaceEnabled = Boolean(syntaxDefinition.namespace);
|
||||
var namespaceWildcardEnabled = syntaxDefinition.namespace &&
|
||||
(syntaxDefinition.namespace === true || syntaxDefinition.namespace.wildcard === true);
|
||||
if (namespaceEnabled && !tagNameEnabled) {
|
||||
throw new Error("".concat(errorPrefix, "Namespaces cannot be enabled while tags are disabled."));
|
||||
}
|
||||
var substitutesEnabled = Boolean(substitutes);
|
||||
var combinatorsIndex = syntaxDefinition.combinators
|
||||
? createMulticharIndex(syntaxDefinition.combinators)
|
||||
: emptyMulticharIndex;
|
||||
var _d = syntaxDefinition.attributes
|
||||
? [
|
||||
true,
|
||||
syntaxDefinition.attributes.operators
|
||||
? createMulticharIndex(syntaxDefinition.attributes.operators)
|
||||
: emptyMulticharIndex,
|
||||
syntaxDefinition.attributes.caseSensitivityModifiers
|
||||
? createRegularIndex(syntaxDefinition.attributes.caseSensitivityModifiers)
|
||||
: emptyRegularIndex,
|
||||
syntaxDefinition.attributes.unknownCaseSensitivityModifiers === 'accept'
|
||||
]
|
||||
: [false, emptyMulticharIndex, emptyRegularIndex, false], attributesEnabled = _d[0], attributesOperatorsIndex = _d[1], attributesCaseSensitivityModifiers = _d[2], attributesAcceptUnknownCaseSensitivityModifiers = _d[3];
|
||||
var attributesCaseSensitivityModifiersEnabled = attributesAcceptUnknownCaseSensitivityModifiers || Object.keys(attributesCaseSensitivityModifiers).length > 0;
|
||||
var _e = syntaxDefinition.pseudoClasses
|
||||
? [
|
||||
true,
|
||||
syntaxDefinition.pseudoClasses.definitions
|
||||
? calculatePseudoSignatures(syntaxDefinition.pseudoClasses.definitions)
|
||||
: emptyPseudoSignatures,
|
||||
syntaxDefinition.pseudoClasses.unknown === 'accept'
|
||||
]
|
||||
: [false, emptyPseudoSignatures, false], pseudoClassesEnabled = _e[0], pseudoClassesDefinitions = _e[1], pseudoClassesAcceptUnknown = _e[2];
|
||||
var _f = syntaxDefinition.pseudoElements
|
||||
? [
|
||||
true,
|
||||
syntaxDefinition.pseudoElements.notation === 'singleColon' ||
|
||||
syntaxDefinition.pseudoElements.notation === 'both',
|
||||
!syntaxDefinition.pseudoElements.notation ||
|
||||
syntaxDefinition.pseudoElements.notation === 'doubleColon' ||
|
||||
syntaxDefinition.pseudoElements.notation === 'both',
|
||||
syntaxDefinition.pseudoElements.definitions
|
||||
? calculatePseudoSignatures(Array.isArray(syntaxDefinition.pseudoElements.definitions)
|
||||
? { NoArgument: syntaxDefinition.pseudoElements.definitions }
|
||||
: syntaxDefinition.pseudoElements.definitions)
|
||||
: emptyPseudoSignatures,
|
||||
syntaxDefinition.pseudoElements.unknown === 'accept'
|
||||
]
|
||||
: [false, false, false, emptyPseudoSignatures, false], pseudoElementsEnabled = _f[0], pseudoElementsSingleColonNotationEnabled = _f[1], pseudoElementsDoubleColonNotationEnabled = _f[2], pseudoElementsDefinitions = _f[3], pseudoElementsAcceptUnknown = _f[4];
|
||||
var str = '';
|
||||
var l = str.length;
|
||||
var pos = 0;
|
||||
var chr = '';
|
||||
var is = function (comparison) { return chr === comparison; };
|
||||
var isTagStart = function () { return is('*') || isIdentStart(chr); };
|
||||
var rewind = function (newPos) {
|
||||
pos = newPos;
|
||||
chr = str.charAt(pos);
|
||||
};
|
||||
var next = function () {
|
||||
pos++;
|
||||
chr = str.charAt(pos);
|
||||
};
|
||||
var readAndNext = function () {
|
||||
var current = chr;
|
||||
pos++;
|
||||
chr = str.charAt(pos);
|
||||
return current;
|
||||
};
|
||||
/** @throws ParserError */
|
||||
function fail(errorMessage) {
|
||||
var position = Math.min(l - 1, pos);
|
||||
var error = new Error("".concat(errorPrefix).concat(errorMessage, " Pos: ").concat(position, "."));
|
||||
error.position = position;
|
||||
error.name = 'ParserError';
|
||||
throw error;
|
||||
}
|
||||
function assert(condition, errorMessage) {
|
||||
if (!condition) {
|
||||
return fail(errorMessage);
|
||||
}
|
||||
}
|
||||
var assertNonEof = function () {
|
||||
assert(pos < l, 'Unexpected end of input.');
|
||||
};
|
||||
var isEof = function () { return pos >= l; };
|
||||
var pass = function (character) {
|
||||
assert(pos < l, "Expected \"".concat(character, "\" but end of input reached."));
|
||||
assert(chr === character, "Expected \"".concat(character, "\" but \"").concat(chr, "\" found."));
|
||||
pos++;
|
||||
chr = str.charAt(pos);
|
||||
};
|
||||
function matchMulticharIndex(index) {
|
||||
var match = matchMulticharIndexPos(index, pos);
|
||||
if (match) {
|
||||
pos += match.length;
|
||||
chr = str.charAt(pos);
|
||||
return match;
|
||||
}
|
||||
}
|
||||
function matchMulticharIndexPos(index, subPos) {
|
||||
var char = str.charAt(subPos);
|
||||
var charIndex = index[char];
|
||||
if (charIndex) {
|
||||
var subMatch = matchMulticharIndexPos(charIndex.chars, subPos + 1);
|
||||
if (subMatch) {
|
||||
return subMatch;
|
||||
}
|
||||
if (charIndex.self) {
|
||||
return charIndex.self;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @see https://www.w3.org/TR/css-syntax/#hex-digit-diagram
|
||||
*/
|
||||
function parseHex() {
|
||||
var hex = readAndNext();
|
||||
var count = 1;
|
||||
while (isHex(chr) && count < maxHexLength) {
|
||||
hex += readAndNext();
|
||||
count++;
|
||||
}
|
||||
skipSingleWhitespace();
|
||||
return String.fromCharCode(parseInt(hex, 16));
|
||||
}
|
||||
/**
|
||||
* @see https://www.w3.org/TR/css-syntax/#string-token-diagram
|
||||
*/
|
||||
function parseString(quote) {
|
||||
var result = '';
|
||||
pass(quote);
|
||||
while (pos < l) {
|
||||
if (is(quote)) {
|
||||
next();
|
||||
return result;
|
||||
}
|
||||
else if (is('\\')) {
|
||||
next();
|
||||
if (is(quote)) {
|
||||
result += quote;
|
||||
next();
|
||||
}
|
||||
else if (chr === '\n' || chr === '\f') {
|
||||
next();
|
||||
}
|
||||
else if (chr === '\r') {
|
||||
next();
|
||||
if (is('\n')) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
else if (isHex(chr)) {
|
||||
result += parseHex();
|
||||
}
|
||||
else {
|
||||
result += chr;
|
||||
next();
|
||||
}
|
||||
}
|
||||
else {
|
||||
result += chr;
|
||||
next();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @see https://www.w3.org/TR/css-syntax/#ident-token-diagram
|
||||
*/
|
||||
function parseIdentifier() {
|
||||
if (!isIdentStart(chr)) {
|
||||
return null;
|
||||
}
|
||||
var result = '';
|
||||
while (is('-')) {
|
||||
result += chr;
|
||||
next();
|
||||
}
|
||||
if (result === '-' && !isIdent(chr) && !is('\\')) {
|
||||
fail('Identifiers cannot consist of a single hyphen.');
|
||||
}
|
||||
if (strict && result.length >= 2) {
|
||||
// Checking this only for strict mode since browsers work fine with these identifiers.
|
||||
fail('Identifiers cannot start with two hyphens with strict mode on.');
|
||||
}
|
||||
if (digitsChars[chr]) {
|
||||
fail('Identifiers cannot start with hyphens followed by digits.');
|
||||
}
|
||||
while (pos < l) {
|
||||
if (isIdent(chr)) {
|
||||
result += readAndNext();
|
||||
}
|
||||
else if (is('\\')) {
|
||||
next();
|
||||
assertNonEof();
|
||||
if (isHex(chr)) {
|
||||
result += parseHex();
|
||||
}
|
||||
else {
|
||||
result += readAndNext();
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function parsePseudoClassString() {
|
||||
var result = '';
|
||||
while (pos < l) {
|
||||
if (is(')')) {
|
||||
break;
|
||||
}
|
||||
else if (is('\\')) {
|
||||
next();
|
||||
if (isEof() && !strict) {
|
||||
return (result + '\\').trim();
|
||||
}
|
||||
assertNonEof();
|
||||
if (isHex(chr)) {
|
||||
result += parseHex();
|
||||
}
|
||||
else {
|
||||
result += readAndNext();
|
||||
}
|
||||
}
|
||||
else {
|
||||
result += readAndNext();
|
||||
}
|
||||
}
|
||||
return result.trim();
|
||||
}
|
||||
function skipSingleWhitespace() {
|
||||
if (chr === ' ' || chr === '\t' || chr === '\f' || chr === '\n') {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
if (chr === '\r') {
|
||||
next();
|
||||
}
|
||||
if (chr === '\n') {
|
||||
next();
|
||||
}
|
||||
}
|
||||
function skipWhitespace() {
|
||||
while (whitespaceChars[chr]) {
|
||||
next();
|
||||
}
|
||||
}
|
||||
function parseSelector(relative) {
|
||||
if (relative === void 0) { relative = false; }
|
||||
skipWhitespace();
|
||||
var rules = [parseRule(relative)];
|
||||
while (is(',')) {
|
||||
next();
|
||||
skipWhitespace();
|
||||
rules.push(parseRule(relative));
|
||||
}
|
||||
return {
|
||||
type: 'Selector',
|
||||
rules: rules
|
||||
};
|
||||
}
|
||||
function parseAttribute() {
|
||||
pass('[');
|
||||
skipWhitespace();
|
||||
var attr;
|
||||
if (is('|')) {
|
||||
assert(namespaceEnabled, 'Namespaces are not enabled.');
|
||||
next();
|
||||
var name_1 = parseIdentifier();
|
||||
assert(name_1, 'Expected attribute name.');
|
||||
attr = {
|
||||
type: 'Attribute',
|
||||
name: name_1,
|
||||
namespace: { type: 'NoNamespace' }
|
||||
};
|
||||
}
|
||||
else if (is('*')) {
|
||||
assert(namespaceEnabled, 'Namespaces are not enabled.');
|
||||
assert(namespaceWildcardEnabled, 'Wildcard namespace is not enabled.');
|
||||
next();
|
||||
pass('|');
|
||||
var name_2 = parseIdentifier();
|
||||
assert(name_2, 'Expected attribute name.');
|
||||
attr = {
|
||||
type: 'Attribute',
|
||||
name: name_2,
|
||||
namespace: { type: 'WildcardNamespace' }
|
||||
};
|
||||
}
|
||||
else {
|
||||
var identifier = parseIdentifier();
|
||||
assert(identifier, 'Expected attribute name.');
|
||||
attr = {
|
||||
type: 'Attribute',
|
||||
name: identifier
|
||||
};
|
||||
if (is('|')) {
|
||||
var savedPos = pos;
|
||||
next();
|
||||
if (isIdentStart(chr)) {
|
||||
assert(namespaceEnabled, 'Namespaces are not enabled.');
|
||||
var name_3 = parseIdentifier();
|
||||
assert(name_3, 'Expected attribute name.');
|
||||
attr = {
|
||||
type: 'Attribute',
|
||||
name: name_3,
|
||||
namespace: { type: 'NamespaceName', name: identifier }
|
||||
};
|
||||
}
|
||||
else {
|
||||
rewind(savedPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(attr.name, 'Expected attribute name.');
|
||||
skipWhitespace();
|
||||
if (isEof() && !strict) {
|
||||
return attr;
|
||||
}
|
||||
if (is(']')) {
|
||||
next();
|
||||
}
|
||||
else {
|
||||
attr.operator = matchMulticharIndex(attributesOperatorsIndex);
|
||||
assert(attr.operator, 'Expected a valid attribute selector operator.');
|
||||
skipWhitespace();
|
||||
assertNonEof();
|
||||
if (quoteChars[chr]) {
|
||||
attr.value = {
|
||||
type: 'String',
|
||||
value: parseString(chr)
|
||||
};
|
||||
}
|
||||
else if (substitutesEnabled && is('$')) {
|
||||
next();
|
||||
var name_4 = parseIdentifier();
|
||||
assert(name_4, 'Expected substitute name.');
|
||||
attr.value = {
|
||||
type: 'Substitution',
|
||||
name: name_4
|
||||
};
|
||||
}
|
||||
else {
|
||||
var value = parseIdentifier();
|
||||
assert(value, 'Expected attribute value.');
|
||||
attr.value = {
|
||||
type: 'String',
|
||||
value: value
|
||||
};
|
||||
}
|
||||
skipWhitespace();
|
||||
if (isEof() && !strict) {
|
||||
return attr;
|
||||
}
|
||||
if (!is(']')) {
|
||||
var caseSensitivityModifier = parseIdentifier();
|
||||
assert(caseSensitivityModifier, 'Expected end of attribute selector.');
|
||||
attr.caseSensitivityModifier = caseSensitivityModifier;
|
||||
assert(attributesCaseSensitivityModifiersEnabled, 'Attribute case sensitivity modifiers are not enabled.');
|
||||
assert(attributesAcceptUnknownCaseSensitivityModifiers ||
|
||||
attributesCaseSensitivityModifiers[attr.caseSensitivityModifier], 'Unknown attribute case sensitivity modifier.');
|
||||
skipWhitespace();
|
||||
if (isEof() && !strict) {
|
||||
return attr;
|
||||
}
|
||||
}
|
||||
pass(']');
|
||||
}
|
||||
return attr;
|
||||
}
|
||||
function parseNumber() {
|
||||
var result = '';
|
||||
while (digitsChars[chr]) {
|
||||
result += readAndNext();
|
||||
}
|
||||
assert(result !== '', 'Formula parse error.');
|
||||
return parseInt(result);
|
||||
}
|
||||
var isNumberStart = function () { return is('-') || is('+') || digitsChars[chr]; };
|
||||
function parseFormula() {
|
||||
if (is('e') || is('o')) {
|
||||
var ident = parseIdentifier();
|
||||
if (ident === 'even') {
|
||||
skipWhitespace();
|
||||
return [2, 0];
|
||||
}
|
||||
if (ident === 'odd') {
|
||||
skipWhitespace();
|
||||
return [2, 1];
|
||||
}
|
||||
}
|
||||
var firstNumber = null;
|
||||
var firstNumberMultiplier = 1;
|
||||
if (is('-')) {
|
||||
next();
|
||||
firstNumberMultiplier = -1;
|
||||
}
|
||||
if (isNumberStart()) {
|
||||
if (is('+')) {
|
||||
next();
|
||||
}
|
||||
firstNumber = parseNumber();
|
||||
if (!is('\\') && !is('n')) {
|
||||
return [0, firstNumber * firstNumberMultiplier];
|
||||
}
|
||||
}
|
||||
if (firstNumber === null) {
|
||||
firstNumber = 1;
|
||||
}
|
||||
firstNumber *= firstNumberMultiplier;
|
||||
var identifier;
|
||||
if (is('\\')) {
|
||||
next();
|
||||
if (isHex(chr)) {
|
||||
identifier = parseHex();
|
||||
}
|
||||
else {
|
||||
identifier = readAndNext();
|
||||
}
|
||||
}
|
||||
else {
|
||||
identifier = readAndNext();
|
||||
}
|
||||
assert(identifier === 'n', 'Formula parse error: expected "n".');
|
||||
skipWhitespace();
|
||||
if (is('+') || is('-')) {
|
||||
var sign = is('+') ? 1 : -1;
|
||||
next();
|
||||
skipWhitespace();
|
||||
return [firstNumber, sign * parseNumber()];
|
||||
}
|
||||
else {
|
||||
return [firstNumber, 0];
|
||||
}
|
||||
}
|
||||
function parsePseudoArgument(pseudoName, type, signature) {
|
||||
var argument;
|
||||
if (is('(')) {
|
||||
next();
|
||||
skipWhitespace();
|
||||
if (substitutesEnabled && is('$')) {
|
||||
next();
|
||||
var name_5 = parseIdentifier();
|
||||
assert(name_5, 'Expected substitute name.');
|
||||
argument = {
|
||||
type: 'Substitution',
|
||||
name: name_5
|
||||
};
|
||||
}
|
||||
else if (signature.type === 'String') {
|
||||
argument = {
|
||||
type: 'String',
|
||||
value: parsePseudoClassString()
|
||||
};
|
||||
assert(argument.value, "Expected ".concat(type, " argument value."));
|
||||
}
|
||||
else if (signature.type === 'Selector') {
|
||||
argument = parseSelector(true);
|
||||
}
|
||||
else if (signature.type === 'Formula') {
|
||||
var _a = parseFormula(), a = _a[0], b = _a[1];
|
||||
argument = {
|
||||
type: 'Formula',
|
||||
a: a,
|
||||
b: b
|
||||
};
|
||||
if (signature.ofSelector) {
|
||||
skipWhitespace();
|
||||
if (is('o') || is('\\')) {
|
||||
var ident = parseIdentifier();
|
||||
assert(ident === 'of', 'Formula of selector parse error.');
|
||||
skipWhitespace();
|
||||
argument = {
|
||||
type: 'FormulaOfSelector',
|
||||
a: a,
|
||||
b: b,
|
||||
selector: parseRule()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return fail("Invalid ".concat(type, " signature."));
|
||||
}
|
||||
skipWhitespace();
|
||||
if (isEof() && !strict) {
|
||||
return argument;
|
||||
}
|
||||
pass(')');
|
||||
}
|
||||
else {
|
||||
assert(signature.optional, "Argument is required for ".concat(type, " \"").concat(pseudoName, "\"."));
|
||||
}
|
||||
return argument;
|
||||
}
|
||||
function parseTagName() {
|
||||
if (is('*')) {
|
||||
assert(tagNameWildcardEnabled, 'Wildcard tag name is not enabled.');
|
||||
next();
|
||||
return { type: 'WildcardTag' };
|
||||
}
|
||||
else if (isIdentStart(chr)) {
|
||||
assert(tagNameEnabled, 'Tag names are not enabled.');
|
||||
var name_6 = parseIdentifier();
|
||||
assert(name_6, 'Expected tag name.');
|
||||
return {
|
||||
type: 'TagName',
|
||||
name: name_6
|
||||
};
|
||||
}
|
||||
else {
|
||||
return fail('Expected tag name.');
|
||||
}
|
||||
}
|
||||
function parseTagNameWithNamespace() {
|
||||
if (is('*')) {
|
||||
var savedPos = pos;
|
||||
next();
|
||||
if (!is('|')) {
|
||||
rewind(savedPos);
|
||||
return parseTagName();
|
||||
}
|
||||
next();
|
||||
if (!isTagStart()) {
|
||||
rewind(savedPos);
|
||||
return parseTagName();
|
||||
}
|
||||
assert(namespaceEnabled, 'Namespaces are not enabled.');
|
||||
assert(namespaceWildcardEnabled, 'Wildcard namespace is not enabled.');
|
||||
var tagName = parseTagName();
|
||||
tagName.namespace = { type: 'WildcardNamespace' };
|
||||
return tagName;
|
||||
}
|
||||
else if (is('|')) {
|
||||
assert(namespaceEnabled, 'Namespaces are not enabled.');
|
||||
next();
|
||||
var tagName = parseTagName();
|
||||
tagName.namespace = { type: 'NoNamespace' };
|
||||
return tagName;
|
||||
}
|
||||
else if (isIdentStart(chr)) {
|
||||
var identifier = parseIdentifier();
|
||||
assert(identifier, 'Expected tag name.');
|
||||
if (!is('|')) {
|
||||
assert(tagNameEnabled, 'Tag names are not enabled.');
|
||||
return {
|
||||
type: 'TagName',
|
||||
name: identifier
|
||||
};
|
||||
}
|
||||
var savedPos = pos;
|
||||
next();
|
||||
if (!isTagStart()) {
|
||||
rewind(savedPos);
|
||||
return {
|
||||
type: 'TagName',
|
||||
name: identifier
|
||||
};
|
||||
}
|
||||
assert(namespaceEnabled, 'Namespaces are not enabled.');
|
||||
var tagName = parseTagName();
|
||||
tagName.namespace = { type: 'NamespaceName', name: identifier };
|
||||
return tagName;
|
||||
}
|
||||
else {
|
||||
return fail('Expected tag name.');
|
||||
}
|
||||
}
|
||||
function parseRule(relative) {
|
||||
var _a, _b;
|
||||
if (relative === void 0) { relative = false; }
|
||||
var rule = { type: 'Rule', items: [] };
|
||||
if (relative) {
|
||||
var combinator = matchMulticharIndex(combinatorsIndex);
|
||||
if (combinator) {
|
||||
rule.combinator = combinator;
|
||||
skipWhitespace();
|
||||
}
|
||||
}
|
||||
while (pos < l) {
|
||||
if (isTagStart()) {
|
||||
assert(rule.items.length === 0, 'Unexpected tag/namespace start.');
|
||||
rule.items.push(parseTagNameWithNamespace());
|
||||
}
|
||||
else if (is('|')) {
|
||||
var savedPos = pos;
|
||||
next();
|
||||
if (isTagStart()) {
|
||||
assert(rule.items.length === 0, 'Unexpected tag/namespace start.');
|
||||
rewind(savedPos);
|
||||
rule.items.push(parseTagNameWithNamespace());
|
||||
}
|
||||
else {
|
||||
rewind(savedPos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (is('.')) {
|
||||
assert(classNamesEnabled, 'Class names are not enabled.');
|
||||
next();
|
||||
var className = parseIdentifier();
|
||||
assert(className, 'Expected class name.');
|
||||
rule.items.push({ type: 'ClassName', name: className });
|
||||
}
|
||||
else if (is('#')) {
|
||||
assert(idEnabled, 'IDs are not enabled.');
|
||||
next();
|
||||
var idName = parseIdentifier();
|
||||
assert(idName, 'Expected ID name.');
|
||||
rule.items.push({ type: 'Id', name: idName });
|
||||
}
|
||||
else if (is('[')) {
|
||||
assert(attributesEnabled, 'Attributes are not enabled.');
|
||||
rule.items.push(parseAttribute());
|
||||
}
|
||||
else if (is(':')) {
|
||||
var isDoubleColon = false;
|
||||
var isPseudoElement = false;
|
||||
next();
|
||||
if (is(':')) {
|
||||
assert(pseudoElementsEnabled, 'Pseudo elements are not enabled.');
|
||||
assert(pseudoElementsDoubleColonNotationEnabled, 'Pseudo elements double colon notation is not enabled.');
|
||||
isDoubleColon = true;
|
||||
next();
|
||||
}
|
||||
var pseudoName = parseIdentifier();
|
||||
assert(isDoubleColon || pseudoName, 'Expected pseudo-class name.');
|
||||
assert(!isDoubleColon || pseudoName, 'Expected pseudo-element name.');
|
||||
assert(pseudoName, 'Expected pseudo-class name.');
|
||||
assert(!isDoubleColon ||
|
||||
pseudoElementsAcceptUnknown ||
|
||||
Object.prototype.hasOwnProperty.call(pseudoElementsDefinitions, pseudoName), "Unknown pseudo-element \"".concat(pseudoName, "\"."));
|
||||
isPseudoElement =
|
||||
pseudoElementsEnabled &&
|
||||
(isDoubleColon ||
|
||||
(!isDoubleColon &&
|
||||
pseudoElementsSingleColonNotationEnabled &&
|
||||
Object.prototype.hasOwnProperty.call(pseudoElementsDefinitions, pseudoName)));
|
||||
if (isPseudoElement) {
|
||||
var signature = (_a = pseudoElementsDefinitions[pseudoName]) !== null && _a !== void 0 ? _a : (pseudoElementsAcceptUnknown && defaultPseudoSignature);
|
||||
var pseudoElement = {
|
||||
type: 'PseudoElement',
|
||||
name: pseudoName
|
||||
};
|
||||
var argument = parsePseudoArgument(pseudoName, 'pseudo-element', signature);
|
||||
if (argument) {
|
||||
assert(argument.type !== 'Formula' && argument.type !== 'FormulaOfSelector', 'Pseudo-elements cannot have formula argument.');
|
||||
pseudoElement.argument = argument;
|
||||
}
|
||||
rule.items.push(pseudoElement);
|
||||
}
|
||||
else {
|
||||
assert(pseudoClassesEnabled, 'Pseudo-classes are not enabled.');
|
||||
var signature = (_b = pseudoClassesDefinitions[pseudoName]) !== null && _b !== void 0 ? _b : (pseudoClassesAcceptUnknown && defaultPseudoSignature);
|
||||
assert(signature, "Unknown pseudo-class: \"".concat(pseudoName, "\"."));
|
||||
var argument = parsePseudoArgument(pseudoName, 'pseudo-class', signature);
|
||||
var pseudoClass = {
|
||||
type: 'PseudoClass',
|
||||
name: pseudoName
|
||||
};
|
||||
if (argument) {
|
||||
pseudoClass.argument = argument;
|
||||
}
|
||||
rule.items.push(pseudoClass);
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rule.items.length === 0) {
|
||||
if (isEof()) {
|
||||
return fail('Expected rule but end of input reached.');
|
||||
}
|
||||
else {
|
||||
return fail("Expected rule but \"".concat(chr, "\" found."));
|
||||
}
|
||||
}
|
||||
skipWhitespace();
|
||||
if (!isEof() && !is(',') && !is(')')) {
|
||||
var combinator = matchMulticharIndex(combinatorsIndex);
|
||||
skipWhitespace();
|
||||
rule.nestedRule = parseRule();
|
||||
rule.nestedRule.combinator = combinator;
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
return function (input) {
|
||||
// noinspection SuspiciousTypeOfGuard
|
||||
if (typeof input !== 'string') {
|
||||
throw new Error("".concat(errorPrefix, "Expected string input."));
|
||||
}
|
||||
str = input;
|
||||
l = str.length;
|
||||
pos = 0;
|
||||
chr = str.charAt(0);
|
||||
return parseSelector();
|
||||
};
|
||||
}
|
||||
25
node_modules/css-selector-parser/dist/mjs/pseudo-signatures.d.ts
generated
vendored
Normal file
25
node_modules/css-selector-parser/dist/mjs/pseudo-signatures.d.ts
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { PseudoClassType } from './syntax-definitions.js';
|
||||
export type PseudoSignature = {
|
||||
optional: boolean;
|
||||
} & ({
|
||||
type: 'Formula';
|
||||
ofSelector?: boolean;
|
||||
} | {
|
||||
type: 'String';
|
||||
} | {
|
||||
type: 'Selector';
|
||||
} | {
|
||||
type: 'NoArgument';
|
||||
});
|
||||
export type PseudoSignatures = Record<string, PseudoSignature>;
|
||||
export declare const emptyPseudoSignatures: PseudoSignatures;
|
||||
export declare const defaultPseudoSignature: PseudoSignature;
|
||||
type PseudoArgumentType = PseudoClassType;
|
||||
export type CategoriesIndex<T1 extends string, T2 extends string> = {
|
||||
[K in T1]?: T2[];
|
||||
};
|
||||
export declare function inverseCategories<T1 extends string, T2 extends string>(obj: CategoriesIndex<T1, T2>): CategoriesIndex<T2, T1>;
|
||||
export declare function calculatePseudoSignatures<T extends PseudoArgumentType>(definitions: {
|
||||
[K in T]?: string[];
|
||||
}): PseudoSignatures;
|
||||
export {};
|
||||
63
node_modules/css-selector-parser/dist/mjs/pseudo-signatures.js
generated
vendored
Normal file
63
node_modules/css-selector-parser/dist/mjs/pseudo-signatures.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
export var emptyPseudoSignatures = {};
|
||||
export var defaultPseudoSignature = {
|
||||
type: 'String',
|
||||
optional: true
|
||||
};
|
||||
function calculatePseudoSignature(types) {
|
||||
var result = {
|
||||
type: 'NoArgument',
|
||||
optional: false
|
||||
};
|
||||
function setResultType(type) {
|
||||
if (result.type && result.type !== type && result.type !== 'NoArgument') {
|
||||
throw new Error("Conflicting pseudo-class argument type: \"".concat(result.type, "\" vs \"").concat(type, "\"."));
|
||||
}
|
||||
result.type = type;
|
||||
}
|
||||
for (var _i = 0, types_1 = types; _i < types_1.length; _i++) {
|
||||
var type = types_1[_i];
|
||||
if (type === 'NoArgument') {
|
||||
result.optional = true;
|
||||
}
|
||||
if (type === 'Formula') {
|
||||
setResultType('Formula');
|
||||
}
|
||||
if (type === 'FormulaOfSelector') {
|
||||
setResultType('Formula');
|
||||
result.ofSelector = true;
|
||||
}
|
||||
if (type === 'String') {
|
||||
setResultType('String');
|
||||
}
|
||||
if (type === 'Selector') {
|
||||
setResultType('Selector');
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export function inverseCategories(obj) {
|
||||
var result = {};
|
||||
for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
|
||||
var category = _a[_i];
|
||||
var items = obj[category];
|
||||
if (items) {
|
||||
for (var _b = 0, _c = items; _b < _c.length; _b++) {
|
||||
var item = _c[_b];
|
||||
(result[item] || (result[item] = [])).push(category);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export function calculatePseudoSignatures(definitions) {
|
||||
var pseudoClassesToArgumentTypes = inverseCategories(definitions);
|
||||
var result = {};
|
||||
for (var _i = 0, _a = Object.keys(pseudoClassesToArgumentTypes); _i < _a.length; _i++) {
|
||||
var pseudoClass = _a[_i];
|
||||
var argumentTypes = pseudoClassesToArgumentTypes[pseudoClass];
|
||||
if (argumentTypes) {
|
||||
result[pseudoClass] = calculatePseudoSignature(argumentTypes);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
25
node_modules/css-selector-parser/dist/mjs/render.d.ts
generated
vendored
Normal file
25
node_modules/css-selector-parser/dist/mjs/render.d.ts
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { AstEntity } from './ast.js';
|
||||
/**
|
||||
* Renders CSS Selector AST back to a string.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* import {ast, render} from 'css-selector-parser';
|
||||
*
|
||||
* const selector = ast.selector({
|
||||
* rules: [
|
||||
* ast.rule({
|
||||
* items: [
|
||||
* ast.tagName({name: 'a'}),
|
||||
* ast.id({name: 'user-23'}),
|
||||
* ast.className({name: 'user'}),
|
||||
* ast.pseudoClass({name: 'visited'}),
|
||||
* ast.pseudoElement({name: 'before'})
|
||||
* ]
|
||||
* })
|
||||
* ]
|
||||
* });
|
||||
*
|
||||
* console.log(render(selector)); // a#user-23.user:visited::before
|
||||
*/
|
||||
export declare function render(entity: AstEntity): string;
|
||||
146
node_modules/css-selector-parser/dist/mjs/render.js
generated
vendored
Normal file
146
node_modules/css-selector-parser/dist/mjs/render.js
generated
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
import { escapeIdentifier, escapeString } from './utils.js';
|
||||
var errorPrefix = "css-selector-parser render error: ";
|
||||
function renderNamespace(namespace) {
|
||||
if (namespace.type === 'WildcardNamespace') {
|
||||
return '*|';
|
||||
}
|
||||
else if (namespace.type === 'NamespaceName') {
|
||||
return "".concat(escapeIdentifier(namespace.name), "|");
|
||||
}
|
||||
else if (namespace.type === 'NoNamespace') {
|
||||
return '|';
|
||||
}
|
||||
throw new Error("".concat(errorPrefix, "Unknown namespace type: ").concat(namespace.type, "."));
|
||||
}
|
||||
function renderSubstitution(sub) {
|
||||
return "$".concat(escapeIdentifier(sub.name));
|
||||
}
|
||||
function renderFormula(a, b) {
|
||||
if (a) {
|
||||
var result = "".concat(a === 1 ? '' : a === -1 ? '-' : a, "n");
|
||||
if (b) {
|
||||
result += "".concat(b > 0 ? '+' : '').concat(b);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
return String(b);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Renders CSS Selector AST back to a string.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* import {ast, render} from 'css-selector-parser';
|
||||
*
|
||||
* const selector = ast.selector({
|
||||
* rules: [
|
||||
* ast.rule({
|
||||
* items: [
|
||||
* ast.tagName({name: 'a'}),
|
||||
* ast.id({name: 'user-23'}),
|
||||
* ast.className({name: 'user'}),
|
||||
* ast.pseudoClass({name: 'visited'}),
|
||||
* ast.pseudoElement({name: 'before'})
|
||||
* ]
|
||||
* })
|
||||
* ]
|
||||
* });
|
||||
*
|
||||
* console.log(render(selector)); // a#user-23.user:visited::before
|
||||
*/
|
||||
export function render(entity) {
|
||||
if (entity.type === 'Selector') {
|
||||
return entity.rules.map(render).join(', ');
|
||||
}
|
||||
if (entity.type === 'Rule') {
|
||||
var result = '';
|
||||
var items = entity.items, combinator = entity.combinator, nestedRule = entity.nestedRule;
|
||||
if (combinator) {
|
||||
result += "".concat(combinator, " ");
|
||||
}
|
||||
for (var _i = 0, items_1 = items; _i < items_1.length; _i++) {
|
||||
var item = items_1[_i];
|
||||
result += render(item);
|
||||
}
|
||||
if (nestedRule) {
|
||||
result += " ".concat(render(nestedRule));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else if (entity.type === 'TagName' || entity.type === 'WildcardTag') {
|
||||
var result = '';
|
||||
var namespace = entity.namespace;
|
||||
if (namespace) {
|
||||
result += renderNamespace(namespace);
|
||||
}
|
||||
if (entity.type === 'TagName') {
|
||||
result += escapeIdentifier(entity.name);
|
||||
}
|
||||
else if (entity.type === 'WildcardTag') {
|
||||
result += '*';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else if (entity.type === 'Id') {
|
||||
return "#".concat(escapeIdentifier(entity.name));
|
||||
}
|
||||
else if (entity.type === 'ClassName') {
|
||||
return ".".concat(escapeIdentifier(entity.name));
|
||||
}
|
||||
else if (entity.type === 'Attribute') {
|
||||
var name_1 = entity.name, namespace = entity.namespace, operator = entity.operator, value = entity.value, caseSensitivityModifier = entity.caseSensitivityModifier;
|
||||
var result = '[';
|
||||
if (namespace) {
|
||||
result += renderNamespace(namespace);
|
||||
}
|
||||
result += escapeIdentifier(name_1);
|
||||
if (operator && value) {
|
||||
result += operator;
|
||||
if (value.type === 'String') {
|
||||
result += escapeString(value.value);
|
||||
}
|
||||
else if (value.type === 'Substitution') {
|
||||
result += renderSubstitution(value);
|
||||
}
|
||||
else {
|
||||
throw new Error("Unknown attribute value type: ".concat(value.type, "."));
|
||||
}
|
||||
if (caseSensitivityModifier) {
|
||||
result += " ".concat(escapeIdentifier(caseSensitivityModifier));
|
||||
}
|
||||
}
|
||||
result += ']';
|
||||
return result;
|
||||
}
|
||||
else if (entity.type === 'PseudoClass') {
|
||||
var name_2 = entity.name, argument = entity.argument;
|
||||
var result = ":".concat(escapeIdentifier(name_2));
|
||||
if (argument) {
|
||||
result += "(".concat(argument.type === 'String' ? escapeIdentifier(argument.value) : render(argument), ")");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else if (entity.type === 'PseudoElement') {
|
||||
var name_3 = entity.name, argument = entity.argument;
|
||||
var result = "::".concat(escapeIdentifier(name_3));
|
||||
if (argument) {
|
||||
result += "(".concat(argument.type === 'String' ? escapeIdentifier(argument.value) : render(argument), ")");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else if (entity.type === 'String') {
|
||||
throw new Error("".concat(errorPrefix, "String cannot be rendered outside of context."));
|
||||
}
|
||||
else if (entity.type === 'Formula') {
|
||||
return renderFormula(entity.a, entity.b);
|
||||
}
|
||||
else if (entity.type === 'FormulaOfSelector') {
|
||||
return renderFormula(entity.a, entity.b) + ' of ' + render(entity.selector);
|
||||
}
|
||||
else if (entity.type === 'Substitution') {
|
||||
return "$".concat(escapeIdentifier(entity.name));
|
||||
}
|
||||
throw new Error("Unknown type specified to render method: ".concat(entity.type, "."));
|
||||
}
|
||||
134
node_modules/css-selector-parser/dist/mjs/syntax-definitions.d.ts
generated
vendored
Normal file
134
node_modules/css-selector-parser/dist/mjs/syntax-definitions.d.ts
generated
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
import { AstPseudoClassArgument, AstPseudoElementArgument } from './ast.js';
|
||||
export type PseudoClassType = Exclude<'NoArgument' | AstPseudoClassArgument['type'], 'Substitution'>;
|
||||
export type PseudoElementType = Exclude<'NoArgument' | AstPseudoElementArgument['type'], 'Substitution'>;
|
||||
export type CssLevel = 'css1' | 'css2' | 'css3' | 'selectors-3' | 'selectors-4' | 'latest' | 'progressive';
|
||||
/**
|
||||
* CSS Selector Syntax Definition can be used to define custom CSS selector parsing rules.
|
||||
*/
|
||||
export interface SyntaxDefinition {
|
||||
/**
|
||||
* When specified, syntax will be based on the specified predefined CSS standard.
|
||||
* If not specified, syntax will be defined from scratch.
|
||||
*/
|
||||
baseSyntax?: CssLevel;
|
||||
/**
|
||||
* CSS Tag (type).
|
||||
* @example div
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Type_Class_and_ID_Selectors
|
||||
*/
|
||||
tag?: {
|
||||
/**
|
||||
* Allows using wildcard (*).
|
||||
*/
|
||||
wildcard?: boolean;
|
||||
} | boolean;
|
||||
/**
|
||||
* CSS3 Namespaces.
|
||||
* @example ns|div
|
||||
* @see https://www.w3.org/TR/css3-namespace/
|
||||
*/
|
||||
namespace?: {
|
||||
/**
|
||||
* Allows using wildcard (*).
|
||||
*/
|
||||
wildcard?: boolean;
|
||||
} | boolean;
|
||||
/**
|
||||
* CSS IDs (yes, there can be multiple).
|
||||
* @example #root#root
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Type_Class_and_ID_Selectors
|
||||
*/
|
||||
ids?: boolean;
|
||||
/**
|
||||
* CSS Class Names
|
||||
* @example .element.highlighted
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Type_Class_and_ID_Selectors
|
||||
*/
|
||||
classNames?: boolean;
|
||||
/**
|
||||
* CSS selector rule nesting combinators.
|
||||
* @example div.class > span
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Combinators
|
||||
*/
|
||||
combinators?: string[];
|
||||
/**
|
||||
* CSS Attribute Selector.
|
||||
* @example [href="#"]
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Attribute_selectors
|
||||
*/
|
||||
attributes?: {
|
||||
/**
|
||||
* Attribute comparison operator list.
|
||||
* @example ['=', '~=', '|=', '^=', '$=', '*=']
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors#syntax
|
||||
*/
|
||||
operators?: string[];
|
||||
/**
|
||||
* How to handle unknown case sensitivity modifiers.
|
||||
* `accept` - still parse.
|
||||
* `reject` - throw an error.
|
||||
*/
|
||||
unknownCaseSensitivityModifiers?: 'accept' | 'reject';
|
||||
/**
|
||||
* List of pre-defined case sensitivity modifiers.
|
||||
* @example ['i', 'I', 's', 'S']
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors#syntax
|
||||
*/
|
||||
caseSensitivityModifiers?: string[];
|
||||
} | false;
|
||||
/**
|
||||
* CSS Pseudo-elements.
|
||||
* @example ::before
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements
|
||||
*/
|
||||
pseudoElements?: {
|
||||
/**
|
||||
* How to handle unknown pseudo-elements.
|
||||
* `accept` - still parse.
|
||||
* `reject` - throw an error.
|
||||
*/
|
||||
unknown?: 'accept' | 'reject';
|
||||
/**
|
||||
* In the past pseudo selements were defined starting with a single colon.
|
||||
* Later this notation changed to double colon.
|
||||
*/
|
||||
notation?: 'singleColon' | 'doubleColon' | 'both';
|
||||
/**
|
||||
* List of predefined pseudo-elements. If string array is specified, the pseudo-elements are assumed to be
|
||||
* NoArgument.
|
||||
* @example ['before', 'after']
|
||||
* @example {NoArgument: ['before', 'after'], String: ['highlight'], Selector: ['slotted']}
|
||||
*/
|
||||
definitions?: string[] | {
|
||||
[K in PseudoElementType]?: string[];
|
||||
};
|
||||
} | false;
|
||||
/**
|
||||
* CSS Pseudo-classes.
|
||||
* @example :nth-child(2n+1)
|
||||
* @see https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Selectors/Pseudo-classes_and_pseudo-elements
|
||||
*/
|
||||
pseudoClasses?: {
|
||||
/**
|
||||
* How to handle unknown pseudo-classes.
|
||||
* `accept` - still parse.
|
||||
* `reject` - throw an error.
|
||||
*/
|
||||
unknown?: 'accept' | 'reject';
|
||||
/**
|
||||
* Predefined pseudo-classes.
|
||||
* @example {NoArgument: ['first-child'], Formula: ['nth-child'], String: ['dir'], Selector: ['not']}
|
||||
*/
|
||||
definitions?: {
|
||||
[K in PseudoClassType]?: string[];
|
||||
};
|
||||
} | false;
|
||||
}
|
||||
interface SyntaxDefinitionXmlOptions {
|
||||
wildcard?: boolean;
|
||||
}
|
||||
export declare function getXmlOptions(param: SyntaxDefinitionXmlOptions | boolean | undefined): SyntaxDefinitionXmlOptions;
|
||||
type MergeMethod<T> = (base: T, extension: T) => T;
|
||||
export declare const extendSyntaxDefinition: MergeMethod<SyntaxDefinition>;
|
||||
export declare const cssSyntaxDefinitions: Record<CssLevel, SyntaxDefinition>;
|
||||
export {};
|
||||
251
node_modules/css-selector-parser/dist/mjs/syntax-definitions.js
generated
vendored
Normal file
251
node_modules/css-selector-parser/dist/mjs/syntax-definitions.js
generated
vendored
Normal file
@@ -0,0 +1,251 @@
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var emptyXmlOptions = {};
|
||||
var defaultXmlOptions = { wildcard: true };
|
||||
export function getXmlOptions(param) {
|
||||
if (param) {
|
||||
if (typeof param === 'boolean') {
|
||||
return defaultXmlOptions;
|
||||
}
|
||||
else {
|
||||
return param;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return emptyXmlOptions;
|
||||
}
|
||||
}
|
||||
function withMigration(migration, merge) {
|
||||
return function (base, extension) { return merge(migration(base), migration(extension)); };
|
||||
}
|
||||
function withNoNegative(merge) {
|
||||
return function (base, extension) {
|
||||
var result = merge(base, extension);
|
||||
if (!result) {
|
||||
throw new Error("Syntax definition cannot be null or undefined.");
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
function withPositive(positive, merge) {
|
||||
return function (base, extension) {
|
||||
if (extension === true) {
|
||||
return positive;
|
||||
}
|
||||
return merge(base === true ? positive : base, extension);
|
||||
};
|
||||
}
|
||||
function mergeSection(values) {
|
||||
return function (base, extension) {
|
||||
if (!extension || !base) {
|
||||
return extension;
|
||||
}
|
||||
if (typeof extension !== 'object' || extension === null) {
|
||||
throw new Error("Unexpected syntax definition extension type: ".concat(extension, "."));
|
||||
}
|
||||
var result = __assign({}, base);
|
||||
for (var _i = 0, _a = Object.entries(extension); _i < _a.length; _i++) {
|
||||
var _b = _a[_i], key = _b[0], value = _b[1];
|
||||
var mergeSchema = values[key];
|
||||
result[key] = mergeSchema(base[key], value);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
function replaceValueIfSpecified(base, extension) {
|
||||
if (extension !== undefined) {
|
||||
return extension;
|
||||
}
|
||||
return base;
|
||||
}
|
||||
function concatArray(base, extension) {
|
||||
if (!extension) {
|
||||
return base;
|
||||
}
|
||||
if (!base) {
|
||||
return extension;
|
||||
}
|
||||
return base.concat(extension);
|
||||
}
|
||||
function mergeDefinitions(base, extension) {
|
||||
if (!extension) {
|
||||
return base;
|
||||
}
|
||||
if (!base) {
|
||||
return extension;
|
||||
}
|
||||
var result = __assign({}, base);
|
||||
for (var _i = 0, _a = Object.entries(extension); _i < _a.length; _i++) {
|
||||
var _b = _a[_i], key = _b[0], value = _b[1];
|
||||
if (!value) {
|
||||
delete result[key];
|
||||
continue;
|
||||
}
|
||||
var baseValue = base[key];
|
||||
if (!baseValue) {
|
||||
result[key] = value;
|
||||
continue;
|
||||
}
|
||||
result[key] = baseValue.concat(value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
export var extendSyntaxDefinition = withNoNegative(mergeSection({
|
||||
baseSyntax: replaceValueIfSpecified,
|
||||
tag: withPositive(defaultXmlOptions, mergeSection({
|
||||
wildcard: replaceValueIfSpecified
|
||||
})),
|
||||
ids: replaceValueIfSpecified,
|
||||
classNames: replaceValueIfSpecified,
|
||||
namespace: withPositive(defaultXmlOptions, mergeSection({
|
||||
wildcard: replaceValueIfSpecified
|
||||
})),
|
||||
combinators: concatArray,
|
||||
attributes: mergeSection({
|
||||
operators: concatArray,
|
||||
caseSensitivityModifiers: concatArray,
|
||||
unknownCaseSensitivityModifiers: replaceValueIfSpecified
|
||||
}),
|
||||
pseudoClasses: mergeSection({
|
||||
unknown: replaceValueIfSpecified,
|
||||
definitions: mergeDefinitions
|
||||
}),
|
||||
pseudoElements: mergeSection({
|
||||
unknown: replaceValueIfSpecified,
|
||||
notation: replaceValueIfSpecified,
|
||||
definitions: withMigration(function (definitions) { return (Array.isArray(definitions) ? { NoArgument: definitions } : definitions); }, mergeDefinitions)
|
||||
})
|
||||
}));
|
||||
var css1SyntaxDefinition = {
|
||||
tag: {},
|
||||
ids: true,
|
||||
classNames: true,
|
||||
combinators: [],
|
||||
pseudoElements: {
|
||||
unknown: 'reject',
|
||||
notation: 'singleColon',
|
||||
definitions: ['first-letter', 'first-line']
|
||||
},
|
||||
pseudoClasses: {
|
||||
unknown: 'reject',
|
||||
definitions: {
|
||||
NoArgument: ['link', 'visited', 'active']
|
||||
}
|
||||
}
|
||||
};
|
||||
var css2SyntaxDefinition = extendSyntaxDefinition(css1SyntaxDefinition, {
|
||||
tag: { wildcard: true },
|
||||
combinators: ['>', '+'],
|
||||
attributes: {
|
||||
unknownCaseSensitivityModifiers: 'reject',
|
||||
operators: ['=', '~=', '|=']
|
||||
},
|
||||
pseudoElements: {
|
||||
definitions: ['before', 'after']
|
||||
},
|
||||
pseudoClasses: {
|
||||
unknown: 'reject',
|
||||
definitions: {
|
||||
NoArgument: ['hover', 'focus', 'first-child'],
|
||||
String: ['lang']
|
||||
}
|
||||
}
|
||||
});
|
||||
var selectors3SyntaxDefinition = extendSyntaxDefinition(css2SyntaxDefinition, {
|
||||
namespace: {
|
||||
wildcard: true
|
||||
},
|
||||
combinators: ['~'],
|
||||
attributes: {
|
||||
operators: ['^=', '$=', '*=']
|
||||
},
|
||||
pseudoElements: {
|
||||
notation: 'both'
|
||||
},
|
||||
pseudoClasses: {
|
||||
definitions: {
|
||||
NoArgument: [
|
||||
'root',
|
||||
'last-child',
|
||||
'first-of-type',
|
||||
'last-of-type',
|
||||
'only-child',
|
||||
'only-of-type',
|
||||
'empty',
|
||||
'target',
|
||||
'enabled',
|
||||
'disabled',
|
||||
'checked',
|
||||
'indeterminate'
|
||||
],
|
||||
Formula: ['nth-child', 'nth-last-child', 'nth-of-type', 'nth-last-of-type'],
|
||||
Selector: ['not']
|
||||
}
|
||||
}
|
||||
});
|
||||
var selectors4SyntaxDefinition = extendSyntaxDefinition(selectors3SyntaxDefinition, {
|
||||
combinators: ['||'],
|
||||
attributes: {
|
||||
caseSensitivityModifiers: ['i', 'I', 's', 'S']
|
||||
},
|
||||
pseudoClasses: {
|
||||
definitions: {
|
||||
NoArgument: [
|
||||
'any-link',
|
||||
'local-link',
|
||||
'target-within',
|
||||
'scope',
|
||||
'current',
|
||||
'past',
|
||||
'future',
|
||||
'focus-within',
|
||||
'focus-visible',
|
||||
'read-write',
|
||||
'read-only',
|
||||
'placeholder-shown',
|
||||
'default',
|
||||
'valid',
|
||||
'invalid',
|
||||
'in-range',
|
||||
'out-of-range',
|
||||
'required',
|
||||
'optional',
|
||||
'blank',
|
||||
'user-invalid'
|
||||
],
|
||||
Formula: ['nth-col', 'nth-last-col'],
|
||||
String: ['dir'],
|
||||
FormulaOfSelector: ['nth-child', 'nth-last-child'],
|
||||
Selector: ['current', 'is', 'where', 'has']
|
||||
}
|
||||
}
|
||||
});
|
||||
var progressiveSyntaxDefinition = extendSyntaxDefinition(selectors4SyntaxDefinition, {
|
||||
pseudoElements: {
|
||||
unknown: 'accept'
|
||||
},
|
||||
pseudoClasses: {
|
||||
unknown: 'accept'
|
||||
},
|
||||
attributes: {
|
||||
unknownCaseSensitivityModifiers: 'accept'
|
||||
}
|
||||
});
|
||||
export var cssSyntaxDefinitions = {
|
||||
css1: css1SyntaxDefinition,
|
||||
css2: css2SyntaxDefinition,
|
||||
css3: selectors3SyntaxDefinition,
|
||||
'selectors-3': selectors3SyntaxDefinition,
|
||||
'selectors-4': selectors4SyntaxDefinition,
|
||||
latest: selectors4SyntaxDefinition,
|
||||
progressive: progressiveSyntaxDefinition
|
||||
};
|
||||
11
node_modules/css-selector-parser/dist/mjs/utils.d.ts
generated
vendored
Normal file
11
node_modules/css-selector-parser/dist/mjs/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export declare function isIdentStart(c: string): boolean;
|
||||
export declare function isIdent(c: string): boolean;
|
||||
export declare function isHex(c: string): boolean;
|
||||
export declare const identEscapeChars: Record<string, boolean>;
|
||||
export declare const stringRenderEscapeChars: Record<string, boolean>;
|
||||
export declare const whitespaceChars: Record<string, boolean>;
|
||||
export declare const quoteChars: Record<string, boolean>;
|
||||
export declare const digitsChars: Record<string, boolean>;
|
||||
export declare const maxHexLength = 6;
|
||||
export declare function escapeIdentifier(s: string): string;
|
||||
export declare function escapeString(s: string): string;
|
||||
129
node_modules/css-selector-parser/dist/mjs/utils.js
generated
vendored
Normal file
129
node_modules/css-selector-parser/dist/mjs/utils.js
generated
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
export function isIdentStart(c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c === '-' || c === '_' || c === '\\' || c >= '\u00a0';
|
||||
}
|
||||
export function isIdent(c) {
|
||||
return ((c >= 'a' && c <= 'z') ||
|
||||
(c >= 'A' && c <= 'Z') ||
|
||||
(c >= '0' && c <= '9') ||
|
||||
c === '-' ||
|
||||
c === '_' ||
|
||||
c >= '\u00a0');
|
||||
}
|
||||
export function isHex(c) {
|
||||
return (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || (c >= '0' && c <= '9');
|
||||
}
|
||||
export var identEscapeChars = {
|
||||
'!': true,
|
||||
'"': true,
|
||||
'#': true,
|
||||
$: true,
|
||||
'%': true,
|
||||
'&': true,
|
||||
"'": true,
|
||||
'(': true,
|
||||
')': true,
|
||||
'*': true,
|
||||
'+': true,
|
||||
',': true,
|
||||
'.': true,
|
||||
'/': true,
|
||||
';': true,
|
||||
'<': true,
|
||||
'=': true,
|
||||
'>': true,
|
||||
'?': true,
|
||||
'@': true,
|
||||
'[': true,
|
||||
'\\': true,
|
||||
']': true,
|
||||
'^': true,
|
||||
'`': true,
|
||||
'{': true,
|
||||
'|': true,
|
||||
'}': true,
|
||||
'~': true
|
||||
};
|
||||
export var stringRenderEscapeChars = {
|
||||
'\n': true,
|
||||
'\r': true,
|
||||
'\t': true,
|
||||
'\f': true,
|
||||
'\v': true
|
||||
};
|
||||
export var whitespaceChars = {
|
||||
' ': true,
|
||||
'\t': true,
|
||||
'\n': true,
|
||||
'\r': true,
|
||||
'\f': true
|
||||
};
|
||||
export var quoteChars = {
|
||||
'"': true,
|
||||
"'": true
|
||||
};
|
||||
export var digitsChars = {
|
||||
0: true,
|
||||
1: true,
|
||||
2: true,
|
||||
3: true,
|
||||
4: true,
|
||||
5: true,
|
||||
6: true,
|
||||
7: true,
|
||||
8: true,
|
||||
9: true
|
||||
};
|
||||
export var maxHexLength = 6;
|
||||
export function escapeIdentifier(s) {
|
||||
var len = s.length;
|
||||
var result = '';
|
||||
var i = 0;
|
||||
while (i < len) {
|
||||
var chr = s.charAt(i);
|
||||
if (identEscapeChars[chr] || (chr === '-' && i === 1 && s.charAt(0) === '-')) {
|
||||
result += '\\' + chr;
|
||||
}
|
||||
else {
|
||||
if (chr === '-' ||
|
||||
chr === '_' ||
|
||||
(chr >= 'A' && chr <= 'Z') ||
|
||||
(chr >= 'a' && chr <= 'z') ||
|
||||
(chr >= '0' && chr <= '9' && i !== 0 && !(i === 1 && s.charAt(0) === '-'))) {
|
||||
result += chr;
|
||||
}
|
||||
else {
|
||||
var charCode = chr.charCodeAt(0);
|
||||
if ((charCode & 0xf800) === 0xd800) {
|
||||
var extraCharCode = s.charCodeAt(i++);
|
||||
if ((charCode & 0xfc00) !== 0xd800 || (extraCharCode & 0xfc00) !== 0xdc00) {
|
||||
throw Error('UCS-2(decode): illegal sequence');
|
||||
}
|
||||
charCode = ((charCode & 0x3ff) << 10) + (extraCharCode & 0x3ff) + 0x10000;
|
||||
}
|
||||
result += '\\' + charCode.toString(16) + ' ';
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return result.trim();
|
||||
}
|
||||
export function escapeString(s) {
|
||||
var len = s.length;
|
||||
var result = '';
|
||||
var i = 0;
|
||||
while (i < len) {
|
||||
var chr = s.charAt(i);
|
||||
if (chr === '"') {
|
||||
chr = '\\"';
|
||||
}
|
||||
else if (chr === '\\') {
|
||||
chr = '\\\\';
|
||||
}
|
||||
else if (stringRenderEscapeChars[chr]) {
|
||||
chr = '\\' + chr.charCodeAt(0).toString(16) + (i === len - 1 ? '' : ' ');
|
||||
}
|
||||
result += chr;
|
||||
i++;
|
||||
}
|
||||
return "\"".concat(result, "\"");
|
||||
}
|
||||
103
node_modules/css-selector-parser/package.json
generated
vendored
Normal file
103
node_modules/css-selector-parser/package.json
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
{
|
||||
"name": "css-selector-parser",
|
||||
"version": "3.0.5",
|
||||
"description": "Powerful and compliant CSS selector parser.",
|
||||
"keywords": [
|
||||
"css",
|
||||
"css selector",
|
||||
"css selector parser",
|
||||
"pseudo-classes",
|
||||
"pseudo-elements",
|
||||
"css attributes",
|
||||
"css tags",
|
||||
"css classes"
|
||||
],
|
||||
"author": {
|
||||
"name": "Marat Dulin",
|
||||
"email": "mdevils@yandex.ru"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/mdevils"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://patreon.com/mdevils"
|
||||
}
|
||||
],
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^17.6.6",
|
||||
"@commitlint/config-conventional": "^17.6.6",
|
||||
"@types/jest": "^29.5.2",
|
||||
"@typescript-eslint/eslint-plugin": "^7.1.0",
|
||||
"@typescript-eslint/parser": "^7.1.0",
|
||||
"eslint": "^8.43.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-prettier": "^5.1.3",
|
||||
"husky": "^4.3.8",
|
||||
"jest": "^29.5.0",
|
||||
"jest-ts-webcompat-resolver": "^1.0.0",
|
||||
"prettier": "^3.2.5",
|
||||
"standard-version": "^9.5.0",
|
||||
"ts-jest": "^29.1.0",
|
||||
"ts-node": "^10.9.1",
|
||||
"typedoc": "^0.24.8",
|
||||
"typedoc-plugin-markdown": "^3.15.3",
|
||||
"typescript": "^4.9.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mdevils/css-selector-parser.git"
|
||||
},
|
||||
"main": "./dist/cjs/index.js",
|
||||
"module": "./dist/mjs/index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/mjs/index.js",
|
||||
"require": "./dist/cjs/index.js"
|
||||
}
|
||||
},
|
||||
"typings": "./dist/cjs/index",
|
||||
"types": "./dist/cjs/index",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "rm -Rf dist && tsc -p tsconfig.json && tsc -p tsconfig.mjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json && echo '{\"type\": \"module\"}' > dist/mjs/package.json",
|
||||
"build:docs": "rm -Rf docs && typedoc --excludeInternal --excludeExternals --disableSources --plugin typedoc-plugin-markdown --entryDocument ../README.md --out docs src/index.ts && ts-node tools/cleanup-docs.ts",
|
||||
"test": "jest test",
|
||||
"test:watch": "jest --watch test",
|
||||
"test:dist": "TEST_DIST=cjs npm run test",
|
||||
"lint": "eslint {src,test,benchmark}/**.ts",
|
||||
"lint:fix": "eslint --fix {src,test,benchmark}/**.ts",
|
||||
"benchmark": "ts-node benchmark/benchmark.ts",
|
||||
"release": "standard-version",
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "npm run lint && npm run test",
|
||||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
||||
}
|
||||
},
|
||||
"commitlint": {
|
||||
"extends": [
|
||||
"@commitlint/config-conventional"
|
||||
],
|
||||
"rules": {
|
||||
"subject-case": [
|
||||
2,
|
||||
"never",
|
||||
[
|
||||
"start-case",
|
||||
"pascal-case"
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user