• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1export type Selector =
2    | PseudoSelector
3    | PseudoElement
4    | AttributeSelector
5    | TagSelector
6    | UniversalSelector
7    | Traversal;
8
9export enum SelectorType {
10    Attribute = "attribute",
11    Pseudo = "pseudo",
12    PseudoElement = "pseudo-element",
13    Tag = "tag",
14    Universal = "universal",
15
16    // Traversals
17    Adjacent = "adjacent",
18    Child = "child",
19    Descendant = "descendant",
20    Parent = "parent",
21    Sibling = "sibling",
22    ColumnCombinator = "column-combinator",
23}
24
25/**
26 * Modes for ignore case.
27 *
28 * This could be updated to an enum, and the object is
29 * the current stand-in that will allow code to be updated
30 * without big changes.
31 */
32export const IgnoreCaseMode = {
33    Unknown: null,
34    QuirksMode: "quirks",
35    IgnoreCase: true,
36    CaseSensitive: false,
37} as const;
38
39export interface AttributeSelector {
40    type: SelectorType.Attribute;
41    name: string;
42    action: AttributeAction;
43    value: string;
44    ignoreCase: "quirks" | boolean | null;
45    namespace: string | null;
46}
47
48export type DataType = Selector[][] | null | string;
49
50export interface PseudoSelector {
51    type: SelectorType.Pseudo;
52    name: string;
53    data: DataType;
54}
55
56export interface PseudoElement {
57    type: SelectorType.PseudoElement;
58    name: string;
59    data: string | null;
60}
61
62export interface TagSelector {
63    type: SelectorType.Tag;
64    name: string;
65    namespace: string | null;
66}
67
68export interface UniversalSelector {
69    type: SelectorType.Universal;
70    namespace: string | null;
71}
72
73export interface Traversal {
74    type: TraversalType;
75}
76
77export enum AttributeAction {
78    Any = "any",
79    Element = "element",
80    End = "end",
81    Equals = "equals",
82    Exists = "exists",
83    Hyphen = "hyphen",
84    Not = "not",
85    Start = "start",
86}
87
88export type TraversalType =
89    | SelectorType.Adjacent
90    | SelectorType.Child
91    | SelectorType.Descendant
92    | SelectorType.Parent
93    | SelectorType.Sibling
94    | SelectorType.ColumnCombinator;
95