1 | import { DataType as CSSWhatDataType } from 'css-what';
|
2 | import '../../globals';
|
3 | import * as ReworkCSS from '../../css';
|
4 | export declare const MEDIA_QUERY_SEPARATOR = "&&";
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export interface Node {
|
10 | parent?: Node;
|
11 | _modalParent?: Node;
|
12 | id?: string;
|
13 | nodeName?: string;
|
14 | cssType?: string;
|
15 | cssClasses?: Set<string>;
|
16 | cssPseudoClasses?: Set<string>;
|
17 | getChildIndex?(node: Node): number;
|
18 | getChildAt?(index: number): Node;
|
19 | getChildrenCount?(): number;
|
20 | }
|
21 | export interface Declaration {
|
22 | property: string;
|
23 | value: string;
|
24 | }
|
25 | export type ChangeMap<T extends Node> = Map<T, Changes>;
|
26 | export interface Changes {
|
27 | attributes?: Set<string>;
|
28 | pseudoClasses?: Set<string>;
|
29 | }
|
30 | declare const enum Rarity {
|
31 | Invalid = 4,
|
32 | Id = 3,
|
33 | Class = 2,
|
34 | Type = 1,
|
35 | PseudoClass = 0,
|
36 | Attribute = 0,
|
37 | Universal = 0,
|
38 | Inline = 0
|
39 | }
|
40 | declare const enum PseudoClassSelectorList {
|
41 | Regular = 0,
|
42 | Forgiving = 1,
|
43 | Relative = 2
|
44 | }
|
45 | declare enum Combinator {
|
46 | 'descendant' = " ",
|
47 | 'child' = ">",
|
48 | 'adjacent' = "+",
|
49 | 'sibling' = "~",
|
50 | 'parent' = "<",
|
51 | 'column-combinator' = "||"
|
52 | }
|
53 | declare type AttributeTest = 'exists' | 'equals' | 'start' | 'end' | 'any' | 'element' | 'hyphen';
|
54 | interface LookupSorter {
|
55 | sortById(id: string, sel: SelectorCore): any;
|
56 | sortByClass(cssClass: string, sel: SelectorCore): any;
|
57 | sortByType(cssType: string, sel: SelectorCore): any;
|
58 | sortAsUniversal(sel: SelectorCore): any;
|
59 | }
|
60 | export declare abstract class SelectorBase {
|
61 | |
62 |
|
63 |
|
64 | dynamic: boolean;
|
65 | abstract match(node: Node): boolean;
|
66 | abstract mayMatch(node: Node): boolean;
|
67 | abstract trackChanges(node: Node, map: ChangeAccumulator): void;
|
68 | }
|
69 | export declare abstract class SelectorCore extends SelectorBase {
|
70 | pos: number;
|
71 | specificity: number;
|
72 | rarity: Rarity;
|
73 | combinator: Combinator;
|
74 | ruleset: RuleSet;
|
75 | |
76 |
|
77 |
|
78 |
|
79 | abstract accumulateChanges(node: Node, map: ChangeAccumulator): boolean;
|
80 | lookupSort(sorter: LookupSorter, base?: SelectorCore): void;
|
81 | }
|
82 | export declare abstract class SimpleSelector extends SelectorCore {
|
83 | accumulateChanges(node: Node, map?: ChangeAccumulator): boolean;
|
84 | mayMatch(node: Node): boolean;
|
85 | trackChanges(node: Node, map: ChangeAccumulator): void;
|
86 | }
|
87 | export declare class InvalidSelector extends SimpleSelector {
|
88 | e: Error;
|
89 | constructor(e: Error);
|
90 | toString(): string;
|
91 | match(node: Node): boolean;
|
92 | lookupSort(sorter: LookupSorter, base?: SelectorCore): void;
|
93 | }
|
94 | export declare class UniversalSelector extends SimpleSelector {
|
95 | toString(): string;
|
96 | match(node: Node): boolean;
|
97 | }
|
98 | export declare class IdSelector extends SimpleSelector {
|
99 | id: string;
|
100 | constructor(id: string);
|
101 | toString(): string;
|
102 | match(node: Node): boolean;
|
103 | lookupSort(sorter: LookupSorter, base?: SelectorCore): void;
|
104 | }
|
105 | export declare class TypeSelector extends SimpleSelector {
|
106 | cssType: string;
|
107 | constructor(cssType: string);
|
108 | toString(): string;
|
109 | match(node: Node): boolean;
|
110 | lookupSort(sorter: LookupSorter, base?: SelectorCore): void;
|
111 | }
|
112 | export declare class ClassSelector extends SimpleSelector {
|
113 | cssClass: string;
|
114 | constructor(cssClass: string);
|
115 | toString(): string;
|
116 | match(node: Node): boolean;
|
117 | lookupSort(sorter: LookupSorter, base?: SelectorCore): void;
|
118 | }
|
119 | export declare class AttributeSelector extends SimpleSelector {
|
120 | attribute: string;
|
121 | test: AttributeTest;
|
122 | value: string;
|
123 | ignoreCase: boolean;
|
124 | constructor(attribute: string, test: AttributeTest, value: string, ignoreCase: boolean);
|
125 | toString(): string;
|
126 | match(node: Node): boolean;
|
127 | mayMatch(node: Node): boolean;
|
128 | trackChanges(node: Node, map: ChangeAccumulator): void;
|
129 | }
|
130 | export declare class PseudoClassSelector extends SimpleSelector {
|
131 | cssPseudoClass: string;
|
132 | constructor(cssPseudoClass: string);
|
133 | toString(): string;
|
134 | match(node: Node): boolean;
|
135 | mayMatch(node: Node): boolean;
|
136 | trackChanges(node: Node, map: ChangeAccumulator): void;
|
137 | }
|
138 | export declare abstract class FunctionalPseudoClassSelector extends PseudoClassSelector {
|
139 | protected selectors: Array<SimpleSelector | SimpleSelectorSequence | ComplexSelector>;
|
140 | protected selectorListType?: PseudoClassSelectorList;
|
141 | constructor(cssPseudoClass: string, dataType: CSSWhatDataType);
|
142 | toString(): string;
|
143 | match(node: Node): boolean;
|
144 | mayMatch(node: Node): boolean;
|
145 | trackChanges(node: Node, map: ChangeAccumulator): void;
|
146 | }
|
147 | export declare class NotFunctionalPseudoClassSelector extends FunctionalPseudoClassSelector {
|
148 | match(node: Node): boolean;
|
149 | }
|
150 | export declare class IsFunctionalPseudoClassSelector extends FunctionalPseudoClassSelector {
|
151 | match(node: Node): boolean;
|
152 | lookupSort(sorter: LookupSorter, base?: SelectorCore): void;
|
153 | }
|
154 | export declare class WhereFunctionalPseudoClassSelector extends FunctionalPseudoClassSelector {
|
155 | match(node: Node): boolean;
|
156 | lookupSort(sorter: LookupSorter, base?: SelectorCore): void;
|
157 | }
|
158 | export declare class SimpleSelectorSequence extends SimpleSelector {
|
159 | selectors: SimpleSelector[];
|
160 | private head;
|
161 | constructor(selectors: SimpleSelector[]);
|
162 | toString(): string;
|
163 | match(node: Node): boolean;
|
164 | mayMatch(node: Node): boolean;
|
165 | trackChanges(node: Node, map: ChangeAccumulator): void;
|
166 | lookupSort(sorter: LookupSorter, base?: SelectorCore): void;
|
167 | }
|
168 | export declare class ComplexSelector extends SelectorCore {
|
169 | selectors: SimpleSelector[];
|
170 | private groups;
|
171 | private last;
|
172 | constructor(selectors: SimpleSelector[]);
|
173 | toString(): string;
|
174 | match(node: Node): boolean;
|
175 | mayMatch(node: Node): boolean;
|
176 | trackChanges(node: Node, map: ChangeAccumulator): void;
|
177 | lookupSort(sorter: LookupSorter, base?: SelectorCore): void;
|
178 | accumulateChanges(node: Node, map?: ChangeAccumulator): boolean;
|
179 | }
|
180 | export declare namespace Selector {
|
181 | class ChildGroup extends SelectorBase {
|
182 | private selectors;
|
183 | constructor(selectors: SelectorBase[]);
|
184 | getMatchingNode(node: Node, strict: boolean): Node;
|
185 | match(node: Node): boolean;
|
186 | mayMatch(node: Node): boolean;
|
187 | trackChanges(node: Node, map: ChangeAccumulator): void;
|
188 | }
|
189 | class SiblingGroup extends SelectorBase {
|
190 | private selectors;
|
191 | constructor(selectors: SimpleSelector[]);
|
192 | match(node: Node): boolean;
|
193 | mayMatch(node: Node): boolean;
|
194 | trackChanges(node: Node, map: ChangeAccumulator): void;
|
195 | }
|
196 | interface Bound {
|
197 | left: Node;
|
198 | right: Node;
|
199 | }
|
200 | }
|
201 | export declare class RuleSet {
|
202 | selectors: SelectorCore[];
|
203 | declarations: Declaration[];
|
204 | mediaQueryString: string;
|
205 | tag?: string | number;
|
206 | scopedTag?: string;
|
207 | constructor(selectors: SelectorCore[], declarations: Declaration[]);
|
208 | toString(): string;
|
209 | lookupSort(sorter: LookupSorter): void;
|
210 | }
|
211 | export declare function fromAstNode(astRule: ReworkCSS.Rule): RuleSet;
|
212 | export declare function createSelector(sel: string): SimpleSelector | SimpleSelectorSequence | ComplexSelector;
|
213 | export declare function matchMediaQueryString(mediaQueryString: string, cachedQueries: string[]): boolean;
|
214 | export declare abstract class SelectorScope<T extends Node> implements LookupSorter {
|
215 | private id;
|
216 | private class;
|
217 | private type;
|
218 | private universal;
|
219 | position: number;
|
220 | getSelectorCandidates(node: T): SelectorCore[];
|
221 | sortById(id: string, sel: SelectorCore): void;
|
222 | sortByClass(cssClass: string, sel: SelectorCore): void;
|
223 | sortByType(cssType: string, sel: SelectorCore): void;
|
224 | sortAsUniversal(sel: SelectorCore): void;
|
225 | private addToMap;
|
226 | private makeDocSelector;
|
227 | }
|
228 | export declare class MediaQuerySelectorScope<T extends Node> extends SelectorScope<T> {
|
229 | private _mediaQueryString;
|
230 | constructor(mediaQueryString: string);
|
231 | get mediaQueryString(): string;
|
232 | }
|
233 | export declare class StyleSheetSelectorScope<T extends Node> extends SelectorScope<T> {
|
234 | private mediaQuerySelectorScopes;
|
235 | constructor(rulesets: RuleSet[]);
|
236 | private createMediaQuerySelectorScope;
|
237 | private lookupRulesets;
|
238 | query(node: T): SelectorsMatch<T>;
|
239 | }
|
240 | interface ChangeAccumulator {
|
241 | addAttribute(node: Node, attribute: string): void;
|
242 | addPseudoClass(node: Node, pseudoClass: string): void;
|
243 | }
|
244 | export declare class SelectorsMatch<T extends Node> implements ChangeAccumulator {
|
245 | changeMap: ChangeMap<T>;
|
246 | selectors: SelectorCore[];
|
247 | addAttribute(node: T, attribute: string): void;
|
248 | addPseudoClass(node: T, pseudoClass: string): void;
|
249 | properties(node: T): Changes;
|
250 | }
|
251 | export declare const CSSHelper: {
|
252 | createSelector: typeof createSelector;
|
253 | SelectorCore: typeof SelectorCore;
|
254 | SimpleSelector: typeof SimpleSelector;
|
255 | InvalidSelector: typeof InvalidSelector;
|
256 | UniversalSelector: typeof UniversalSelector;
|
257 | TypeSelector: typeof TypeSelector;
|
258 | ClassSelector: typeof ClassSelector;
|
259 | AttributeSelector: typeof AttributeSelector;
|
260 | PseudoClassSelector: typeof PseudoClassSelector;
|
261 | SimpleSelectorSequence: typeof SimpleSelectorSequence;
|
262 | Selector: typeof Selector;
|
263 | RuleSet: typeof RuleSet;
|
264 | SelectorScope: typeof SelectorScope;
|
265 | MediaQuerySelectorScope: typeof MediaQuerySelectorScope;
|
266 | StyleSheetSelectorScope: typeof StyleSheetSelectorScope;
|
267 | fromAstNode: typeof fromAstNode;
|
268 | SelectorsMatch: typeof SelectorsMatch;
|
269 | };
|
270 | export {};
|