UNPKG

4.76 kBTypeScriptView Raw
1export interface Stylesheet {
2 rules: Rule[];
3}
4export type Rule = QualifiedRule | AtRule;
5export interface AtRule {
6 type: 'at-rule';
7 name: string;
8 prelude: InputToken[];
9 block: SimpleBlock;
10}
11export interface QualifiedRule {
12 type: 'qualified-rule';
13 prelude: InputToken[];
14 block: SimpleBlock;
15}
16export type InputToken = '(' | ')' | '{' | '}' | '[' | ']' | ':' | ';' | ',' | ' ' | '^=' | '|=' | '$=' | '*=' | '~=' | '<!--' | '-->' | undefined | /* <EOF-token> */ InputTokenObject | FunctionInputToken | FunctionToken | SimpleBlock | AtKeywordToken;
17export declare const enum TokenObjectType {
18 /**
19 * <string-token>
20 */
21 string = 1,
22 /**
23 * <delim-token>
24 */
25 delim = 2,
26 /**
27 * <number-token>
28 */
29 number = 3,
30 /**
31 * <percentage-token>
32 */
33 percentage = 4,
34 /**
35 * <dimension-token>
36 */
37 dimension = 5,
38 /**
39 * <ident-token>
40 */
41 ident = 6,
42 /**
43 * <url-token>
44 */
45 url = 7,
46 /**
47 * <function-token>
48 * This is a token indicating a function's leading: <ident-token>(
49 */
50 functionToken = 8,
51 /**
52 * <simple-block>
53 */
54 simpleBlock = 9,
55 /**
56 * <comment-token>
57 */
58 comment = 10,
59 /**
60 * <at-keyword-token>
61 */
62 atKeyword = 11,
63 /**
64 * <hash-token>
65 */
66 hash = 12,
67 /**
68 * <function>
69 * This is a complete consumed function: <function-token>([<component-value> [, <component-value>]*])")"
70 */
71 function = 14
72}
73export interface InputTokenObject {
74 type: TokenObjectType;
75 text: string;
76}
77/**
78 * This is a "<ident>(" token.
79 */
80export interface FunctionInputToken extends InputTokenObject {
81 name: string;
82}
83/**
84 * This is a completely parsed function like "<ident>([component [, component]*])".
85 */
86export interface FunctionToken extends FunctionInputToken {
87 components: any[];
88}
89export interface SimpleBlock extends InputTokenObject {
90 associatedToken: InputToken;
91 values: InputToken[];
92}
93export type AtKeywordToken = InputTokenObject;
94/**
95 * CSS parser following relatively close:
96 * CSS Syntax Module Level 3
97 * https://www.w3.org/TR/css-syntax-3/
98 */
99export declare class CSS3Parser {
100 private text;
101 private nextInputCodePointIndex;
102 private reconsumedInputToken;
103 private topLevelFlag;
104 constructor(text: string);
105 /**
106 * For testing purposes.
107 * This method allows us to run and assert the proper working of the tokenizer.
108 */
109 tokenize(): InputToken[];
110 /**
111 * 4.3.1. Consume a token
112 * https://www.w3.org/TR/css-syntax-3/#consume-a-token
113 */
114 private consumeAToken;
115 private consumeADelimToken;
116 private consumeAWhitespace;
117 private consumeAHashToken;
118 private consumeCDO;
119 private consumeCDC;
120 private consumeAMatchToken;
121 /**
122 * 4.3.2. Consume a numeric token
123 * https://www.w3.org/TR/css-syntax-3/#consume-a-numeric-token
124 */
125 private consumeANumericToken;
126 /**
127 * 4.3.3. Consume an ident-like token
128 * https://www.w3.org/TR/css-syntax-3/#consume-an-ident-like-token
129 */
130 private consumeAnIdentLikeToken;
131 /**
132 * 4.3.4. Consume a string token
133 * https://www.w3.org/TR/css-syntax-3/#consume-a-string-token
134 */
135 private consumeAStringToken;
136 /**
137 * 4.3.5. Consume a url token
138 * https://www.w3.org/TR/css-syntax-3/#consume-a-url-token
139 */
140 private consumeAURLToken;
141 /**
142 * 4.3.11. Consume a name
143 * https://www.w3.org/TR/css-syntax-3/#consume-a-name
144 */
145 private consumeAName;
146 private consumeAtKeyword;
147 private consumeAComment;
148 private reconsumeTheCurrentInputToken;
149 /**
150 * 5.3.1. Parse a stylesheet
151 * https://www.w3.org/TR/css-syntax-3/#parse-a-stylesheet
152 */
153 parseAStylesheet(): Stylesheet;
154 /**
155 * 5.4.1. Consume a list of rules
156 * https://www.w3.org/TR/css-syntax-3/#consume-a-list-of-rules
157 */
158 consumeAListOfRules(): Rule[];
159 /**
160 * 5.4.2. Consume an at-rule
161 * https://www.w3.org/TR/css-syntax-3/#consume-an-at-rule
162 */
163 consumeAnAtRule(): AtRule;
164 /**
165 * 5.4.3. Consume a qualified rule
166 * https://www.w3.org/TR/css-syntax-3/#consume-a-qualified-rule
167 */
168 consumeAQualifiedRule(): QualifiedRule;
169 /**
170 * 5.4.6. Consume a component value
171 * https://www.w3.org/TR/css-syntax-3/#consume-a-component-value
172 */
173 private consumeAComponentValue;
174 /**
175 * 5.4.7. Consume a simple block
176 * https://www.w3.org/TR/css-syntax-3/#consume-a-simple-block
177 */
178 private consumeASimpleBlock;
179 /**
180 * 5.4.8. Consume a function
181 * https://www.w3.org/TR/css-syntax-3/#consume-a-function
182 */
183 private consumeAFunction;
184}
185
\No newline at end of file