Files
website/node_modules/css-selector-parser/dist/mjs/syntax-definitions.d.ts
2024-05-06 17:15:30 -04:00

135 lines
4.9 KiB
TypeScript

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 {};