@tbela99/css-parser 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{LICENSE → LICENSE.md} +1 -1
- package/README.md +250 -77
- package/dist/config.json.js +245 -1
- package/dist/index-umd-web.js +4241 -1583
- package/dist/index.cjs +4242 -1584
- package/dist/index.d.ts +71 -23
- package/dist/lib/ast/expand.js +1 -1
- package/dist/lib/ast/features/calc.js +31 -192
- package/dist/lib/ast/features/index.js +3 -3
- package/dist/lib/ast/features/inlinecssvariables.js +6 -6
- package/dist/lib/ast/features/shorthand.js +5 -6
- package/dist/lib/ast/math/expression.js +220 -0
- package/dist/lib/ast/{features/utils → math}/math.js +4 -4
- package/dist/lib/ast/minify.js +0 -1
- package/dist/lib/ast/types.js +31 -13
- package/dist/lib/ast/utils/minifyfeature.js +4 -3
- package/dist/lib/ast/walk.js +24 -4
- package/dist/lib/fs/resolve.js +4 -3
- package/dist/lib/parser/declaration/list.js +6 -2
- package/dist/lib/parser/declaration/map.js +158 -24
- package/dist/lib/parser/declaration/set.js +42 -22
- package/dist/lib/parser/parse.js +345 -349
- package/dist/lib/parser/tokenize.js +220 -223
- package/dist/lib/parser/utils/declaration.js +67 -0
- package/dist/lib/parser/utils/syntax.js +172 -6
- package/dist/lib/parser/utils/type.js +2 -2
- package/dist/lib/renderer/color/a98rgb.js +64 -0
- package/dist/lib/renderer/color/color.js +521 -0
- package/dist/lib/renderer/color/colormix.js +337 -0
- package/dist/lib/renderer/color/hex.js +92 -0
- package/dist/lib/renderer/color/hsl.js +118 -0
- package/dist/lib/renderer/color/hsv.js +20 -0
- package/dist/lib/renderer/color/hwb.js +101 -0
- package/dist/lib/renderer/color/lab.js +136 -0
- package/dist/lib/renderer/color/lch.js +79 -0
- package/dist/lib/renderer/color/oklab.js +121 -0
- package/dist/lib/renderer/color/oklch.js +65 -0
- package/dist/lib/renderer/color/p3.js +57 -0
- package/dist/lib/renderer/color/prophotorgb.js +56 -0
- package/dist/lib/renderer/color/rec2020.js +70 -0
- package/dist/lib/renderer/color/relativecolor.js +152 -0
- package/dist/lib/renderer/color/rgb.js +44 -0
- package/dist/lib/renderer/color/srgb.js +261 -0
- package/dist/lib/renderer/color/utils/components.js +20 -0
- package/dist/lib/renderer/color/utils/constants.js +191 -0
- package/dist/lib/renderer/color/utils/matrix.js +35 -0
- package/dist/lib/renderer/color/xyz.js +64 -0
- package/dist/lib/renderer/color/xyzd50.js +33 -0
- package/dist/lib/renderer/render.js +128 -30
- package/dist/node/index.js +1 -1
- package/dist/node/load.js +1 -1
- package/dist/web/index.js +1 -1
- package/package.json +19 -18
- package/quickjs.sh +1 -0
- package/dist/lib/iterable/weakmap.js +0 -53
- package/dist/lib/renderer/utils/color.js +0 -499
- /package/dist/lib/iterable/{set.js → weakset.js} +0 -0
|
@@ -2,182 +2,178 @@ import { isWhiteSpace, isNewLine, isDigit, isNonPrintable } from './utils/syntax
|
|
|
2
2
|
import { EnumToken } from '../ast/types.js';
|
|
3
3
|
import '../ast/minify.js';
|
|
4
4
|
import './parse.js';
|
|
5
|
-
import '../renderer/utils/
|
|
5
|
+
import '../renderer/color/utils/constants.js';
|
|
6
6
|
import '../renderer/sourcemap/lib/encode.js';
|
|
7
7
|
|
|
8
|
-
function
|
|
9
|
-
let
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const position = {
|
|
13
|
-
ind: Math.max(ind, 0),
|
|
14
|
-
lin: lin,
|
|
15
|
-
col: Math.max(col, 1)
|
|
16
|
-
};
|
|
17
|
-
let value;
|
|
18
|
-
let buffer = '';
|
|
19
|
-
function consumeWhiteSpace() {
|
|
20
|
-
let count = 0;
|
|
21
|
-
while (isWhiteSpace(stream.charAt(count + ind + 1).charCodeAt(0))) {
|
|
22
|
-
count++;
|
|
23
|
-
}
|
|
24
|
-
next(count);
|
|
25
|
-
return count;
|
|
8
|
+
function consumeWhiteSpace(parseInfo) {
|
|
9
|
+
let count = 0;
|
|
10
|
+
while (isWhiteSpace(parseInfo.stream.charAt(count + parseInfo.currentPosition.ind + 1).charCodeAt(0))) {
|
|
11
|
+
count++;
|
|
26
12
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
13
|
+
next(parseInfo, count);
|
|
14
|
+
return count;
|
|
15
|
+
}
|
|
16
|
+
function pushToken(token, parseInfo, hint) {
|
|
17
|
+
const result = { token, hint, position: { ...parseInfo.position }, bytesIn: parseInfo.currentPosition.ind + 1 };
|
|
18
|
+
parseInfo.position.ind = parseInfo.currentPosition.ind;
|
|
19
|
+
parseInfo.position.lin = parseInfo.currentPosition.lin;
|
|
20
|
+
parseInfo.position.col = Math.max(parseInfo.currentPosition.col, 1);
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
function* consumeString(quoteStr, buffer, parseInfo) {
|
|
24
|
+
const quote = quoteStr;
|
|
25
|
+
let value;
|
|
26
|
+
let hasNewLine = false;
|
|
27
|
+
if (buffer.length > 0) {
|
|
28
|
+
yield pushToken(buffer, parseInfo);
|
|
29
|
+
buffer = '';
|
|
33
30
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
codepoint = sequence.charCodeAt(i);
|
|
51
|
-
if (codepoint == 0x20 ||
|
|
52
|
-
(codepoint >= 0x61 && codepoint <= 0x66) ||
|
|
53
|
-
(codepoint >= 0x41 && codepoint <= 0x46) ||
|
|
54
|
-
(codepoint >= 0x30 && codepoint <= 0x39)) {
|
|
55
|
-
escapeSequence += sequence[i];
|
|
56
|
-
if (codepoint == 0x20) {
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
if (i == 1) {
|
|
64
|
-
buffer += value + sequence[i];
|
|
65
|
-
next(2);
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
if (escapeSequence.trimEnd().length > 0) {
|
|
69
|
-
const codepoint = Number(`0x${escapeSequence.trimEnd()}`);
|
|
70
|
-
if (codepoint == 0 ||
|
|
71
|
-
// leading surrogate
|
|
72
|
-
(0xD800 <= codepoint && codepoint <= 0xDBFF) ||
|
|
73
|
-
// trailing surrogate
|
|
74
|
-
(0xDC00 <= codepoint && codepoint <= 0xDFFF)) {
|
|
75
|
-
buffer += String.fromCodePoint(0xFFFD);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
buffer += String.fromCodePoint(codepoint);
|
|
31
|
+
buffer += quoteStr;
|
|
32
|
+
while (value = peek(parseInfo)) {
|
|
33
|
+
if (value == '\\') {
|
|
34
|
+
const sequence = peek(parseInfo, 6);
|
|
35
|
+
let escapeSequence = '';
|
|
36
|
+
let codepoint;
|
|
37
|
+
let i;
|
|
38
|
+
for (i = 1; i < sequence.length; i++) {
|
|
39
|
+
codepoint = sequence.charCodeAt(i);
|
|
40
|
+
if (codepoint == 0x20 ||
|
|
41
|
+
(codepoint >= 0x61 && codepoint <= 0x66) ||
|
|
42
|
+
(codepoint >= 0x41 && codepoint <= 0x46) ||
|
|
43
|
+
(codepoint >= 0x30 && codepoint <= 0x39)) {
|
|
44
|
+
escapeSequence += sequence[i];
|
|
45
|
+
if (codepoint == 0x20) {
|
|
46
|
+
break;
|
|
79
47
|
}
|
|
80
|
-
next(escapeSequence.length + 1 + (isWhiteSpace(peek()?.charCodeAt(0)) ? 1 : 0));
|
|
81
48
|
continue;
|
|
82
49
|
}
|
|
83
|
-
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (value == quote) {
|
|
87
|
-
buffer += value;
|
|
88
|
-
yield pushToken(buffer, hasNewLine ? EnumToken.BadStringTokenType : EnumToken.StringTokenType);
|
|
89
|
-
next();
|
|
90
|
-
// i += value.length;
|
|
91
|
-
buffer = '';
|
|
92
|
-
return;
|
|
50
|
+
break;
|
|
93
51
|
}
|
|
94
|
-
if (
|
|
95
|
-
|
|
52
|
+
if (i == 1) {
|
|
53
|
+
buffer += value + sequence[i];
|
|
54
|
+
next(parseInfo, 2);
|
|
55
|
+
continue;
|
|
96
56
|
}
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
57
|
+
if (escapeSequence.trimEnd().length > 0) {
|
|
58
|
+
const codepoint = Number(`0x${escapeSequence.trimEnd()}`);
|
|
59
|
+
if (codepoint == 0 ||
|
|
60
|
+
// leading surrogate
|
|
61
|
+
(0xD800 <= codepoint && codepoint <= 0xDBFF) ||
|
|
62
|
+
// trailing surrogate
|
|
63
|
+
(0xDC00 <= codepoint && codepoint <= 0xDFFF)) {
|
|
64
|
+
buffer += String.fromCodePoint(0xFFFD);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
buffer += String.fromCodePoint(codepoint);
|
|
68
|
+
}
|
|
69
|
+
next(parseInfo, escapeSequence.length + 1 + (isWhiteSpace(peek(parseInfo)?.charCodeAt(0)) ? 1 : 0));
|
|
70
|
+
continue;
|
|
102
71
|
}
|
|
72
|
+
buffer += next(parseInfo, 2);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (value == quote) {
|
|
103
76
|
buffer += value;
|
|
104
|
-
|
|
77
|
+
yield pushToken(buffer, parseInfo, hasNewLine ? EnumToken.BadStringTokenType : EnumToken.StringTokenType);
|
|
78
|
+
next(parseInfo);
|
|
79
|
+
// i += value.length;
|
|
80
|
+
buffer = '';
|
|
81
|
+
return;
|
|
105
82
|
}
|
|
106
|
-
if (
|
|
107
|
-
|
|
83
|
+
if (isNewLine(value.charCodeAt(0))) {
|
|
84
|
+
hasNewLine = true;
|
|
108
85
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
86
|
+
if (hasNewLine && value == ';') {
|
|
87
|
+
yield pushToken(buffer + value, parseInfo, EnumToken.BadStringTokenType);
|
|
88
|
+
buffer = '';
|
|
89
|
+
next(parseInfo);
|
|
90
|
+
break;
|
|
112
91
|
}
|
|
113
|
-
buffer
|
|
92
|
+
buffer += value;
|
|
93
|
+
next(parseInfo);
|
|
114
94
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return stream.charAt(ind + 1);
|
|
118
|
-
}
|
|
119
|
-
return stream.slice(ind + 1, ind + count + 1);
|
|
95
|
+
if (hasNewLine) {
|
|
96
|
+
yield pushToken(buffer, parseInfo, EnumToken.BadStringTokenType);
|
|
120
97
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
return stream.slice(ind - 1 - count, ind - 1);
|
|
98
|
+
else {
|
|
99
|
+
// EOF - 'Unclosed-string' fixed
|
|
100
|
+
yield pushToken(buffer + quote, parseInfo, EnumToken.StringTokenType);
|
|
126
101
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
102
|
+
}
|
|
103
|
+
function peek(parseInfo, count = 1) {
|
|
104
|
+
if (count == 1) {
|
|
105
|
+
return parseInfo.stream.charAt(parseInfo.currentPosition.ind + 1);
|
|
106
|
+
}
|
|
107
|
+
return parseInfo.stream.slice(parseInfo.currentPosition.ind + 1, parseInfo.currentPosition.ind + count + 1);
|
|
108
|
+
}
|
|
109
|
+
function prev(parseInfo, count = 1) {
|
|
110
|
+
if (count == 1) {
|
|
111
|
+
return parseInfo.currentPosition.ind == 0 ? '' : parseInfo.stream.charAt(parseInfo.currentPosition.ind - 1);
|
|
112
|
+
}
|
|
113
|
+
return parseInfo.stream.slice(parseInfo.currentPosition.ind - 1 - count, parseInfo.currentPosition.ind - 1);
|
|
114
|
+
}
|
|
115
|
+
function next(parseInfo, count = 1) {
|
|
116
|
+
let char = '';
|
|
117
|
+
let chr = '';
|
|
118
|
+
if (count < 0) {
|
|
119
|
+
return '';
|
|
120
|
+
}
|
|
121
|
+
while (count-- && (chr = parseInfo.stream.charAt(parseInfo.currentPosition.ind + 1))) {
|
|
122
|
+
char += chr;
|
|
123
|
+
const codepoint = parseInfo.stream.charCodeAt(++parseInfo.currentPosition.ind);
|
|
124
|
+
if (isNaN(codepoint)) {
|
|
125
|
+
return char;
|
|
132
126
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (isNewLine(codepoint)) {
|
|
140
|
-
lin++;
|
|
141
|
-
col = 0;
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
col++;
|
|
145
|
-
}
|
|
127
|
+
if (isNewLine(codepoint)) {
|
|
128
|
+
parseInfo.currentPosition.lin++;
|
|
129
|
+
parseInfo.currentPosition.col = 0;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
parseInfo.currentPosition.col++;
|
|
146
133
|
}
|
|
147
|
-
return char;
|
|
148
134
|
}
|
|
149
|
-
|
|
135
|
+
return char;
|
|
136
|
+
}
|
|
137
|
+
function* tokenize(stream) {
|
|
138
|
+
const parseInfo = {
|
|
139
|
+
stream,
|
|
140
|
+
position: { ind: 0, lin: 1, col: 1 },
|
|
141
|
+
currentPosition: { ind: -1, lin: 1, col: 0 }
|
|
142
|
+
};
|
|
143
|
+
let value;
|
|
144
|
+
let buffer = '';
|
|
145
|
+
while (value = next(parseInfo)) {
|
|
150
146
|
if (isWhiteSpace(value.charCodeAt(0))) {
|
|
151
147
|
if (buffer.length > 0) {
|
|
152
|
-
yield pushToken(buffer);
|
|
148
|
+
yield pushToken(buffer, parseInfo);
|
|
153
149
|
buffer = '';
|
|
154
150
|
}
|
|
155
|
-
while (value = next()) {
|
|
151
|
+
while (value = next(parseInfo)) {
|
|
156
152
|
if (!isWhiteSpace(value.charCodeAt(0))) {
|
|
157
153
|
break;
|
|
158
154
|
}
|
|
159
155
|
}
|
|
160
|
-
yield pushToken('', EnumToken.WhitespaceTokenType);
|
|
156
|
+
yield pushToken('', parseInfo, EnumToken.WhitespaceTokenType);
|
|
161
157
|
buffer = '';
|
|
162
158
|
}
|
|
163
159
|
switch (value) {
|
|
164
160
|
case '/':
|
|
165
161
|
if (buffer.length > 0) {
|
|
166
|
-
yield pushToken(buffer);
|
|
162
|
+
yield pushToken(buffer, parseInfo);
|
|
167
163
|
buffer = '';
|
|
168
|
-
if (peek() != '*') {
|
|
169
|
-
yield pushToken(value);
|
|
164
|
+
if (peek(parseInfo) != '*') {
|
|
165
|
+
yield pushToken(value, parseInfo);
|
|
170
166
|
break;
|
|
171
167
|
}
|
|
172
168
|
}
|
|
173
169
|
buffer += value;
|
|
174
|
-
if (peek() == '*') {
|
|
175
|
-
buffer += next();
|
|
176
|
-
while (value = next()) {
|
|
170
|
+
if (peek(parseInfo) == '*') {
|
|
171
|
+
buffer += next(parseInfo);
|
|
172
|
+
while (value = next(parseInfo)) {
|
|
177
173
|
if (value == '*') {
|
|
178
174
|
buffer += value;
|
|
179
|
-
if (peek() == '/') {
|
|
180
|
-
yield pushToken(buffer + next(), EnumToken.CommentTokenType);
|
|
175
|
+
if (peek(parseInfo) == '/') {
|
|
176
|
+
yield pushToken(buffer + next(parseInfo), parseInfo, EnumToken.CommentTokenType);
|
|
181
177
|
buffer = '';
|
|
182
178
|
break;
|
|
183
179
|
}
|
|
@@ -186,71 +182,72 @@ function* tokenize(stream) {
|
|
|
186
182
|
buffer += value;
|
|
187
183
|
}
|
|
188
184
|
}
|
|
189
|
-
yield pushToken(buffer, EnumToken.BadCommentTokenType);
|
|
185
|
+
yield pushToken(buffer, parseInfo, EnumToken.BadCommentTokenType);
|
|
190
186
|
buffer = '';
|
|
191
187
|
}
|
|
192
188
|
break;
|
|
193
189
|
case '<':
|
|
194
190
|
if (buffer.length > 0) {
|
|
195
|
-
yield pushToken(buffer);
|
|
191
|
+
yield pushToken(buffer, parseInfo);
|
|
196
192
|
buffer = '';
|
|
197
193
|
}
|
|
198
|
-
if (peek() == '=') {
|
|
199
|
-
yield pushToken('', EnumToken.LteTokenType);
|
|
200
|
-
next();
|
|
194
|
+
if (peek(parseInfo) == '=') {
|
|
195
|
+
yield pushToken('', parseInfo, EnumToken.LteTokenType);
|
|
196
|
+
next(parseInfo);
|
|
201
197
|
break;
|
|
202
198
|
}
|
|
203
199
|
buffer += value;
|
|
204
|
-
if (peek(3) == '!--') {
|
|
205
|
-
buffer += next(3);
|
|
206
|
-
while (value = next()) {
|
|
200
|
+
if (peek(parseInfo, 3) == '!--') {
|
|
201
|
+
buffer += next(parseInfo, 3);
|
|
202
|
+
while (value = next(parseInfo)) {
|
|
207
203
|
buffer += value;
|
|
208
|
-
if (value == '-' && peek(2) == '->') {
|
|
204
|
+
if (value == '-' && peek(parseInfo, 2) == '->') {
|
|
209
205
|
break;
|
|
210
206
|
}
|
|
211
207
|
}
|
|
212
208
|
if (value === '') {
|
|
213
|
-
yield pushToken(buffer, EnumToken.BadCdoTokenType);
|
|
209
|
+
yield pushToken(buffer, parseInfo, EnumToken.BadCdoTokenType);
|
|
214
210
|
}
|
|
215
211
|
else {
|
|
216
|
-
yield pushToken(buffer + next(2), EnumToken.CDOCOMMTokenType);
|
|
212
|
+
yield pushToken(buffer + next(parseInfo, 2), parseInfo, EnumToken.CDOCOMMTokenType);
|
|
217
213
|
}
|
|
218
214
|
buffer = '';
|
|
219
215
|
}
|
|
220
216
|
break;
|
|
221
217
|
case '\\':
|
|
222
218
|
// EOF
|
|
223
|
-
if (!(value = next())) {
|
|
219
|
+
if (!(value = next(parseInfo))) {
|
|
224
220
|
// end of stream ignore \\
|
|
225
221
|
if (buffer.length > 0) {
|
|
226
|
-
yield pushToken(buffer);
|
|
222
|
+
yield pushToken(buffer, parseInfo);
|
|
227
223
|
buffer = '';
|
|
228
224
|
}
|
|
229
225
|
break;
|
|
230
226
|
}
|
|
231
|
-
buffer += prev() + value;
|
|
227
|
+
buffer += prev(parseInfo) + value;
|
|
232
228
|
break;
|
|
233
229
|
case '"':
|
|
234
230
|
case "'":
|
|
235
|
-
yield* consumeString(value);
|
|
231
|
+
yield* consumeString(value, buffer, parseInfo);
|
|
232
|
+
buffer = '';
|
|
236
233
|
break;
|
|
237
234
|
case '^':
|
|
238
235
|
case '~':
|
|
239
236
|
case '|':
|
|
240
237
|
case '$':
|
|
241
|
-
if (value == '|' && peek() == '|') {
|
|
242
|
-
next();
|
|
243
|
-
yield pushToken('', EnumToken.ColumnCombinatorTokenType);
|
|
238
|
+
if (value == '|' && peek(parseInfo) == '|') {
|
|
239
|
+
next(parseInfo);
|
|
240
|
+
yield pushToken('', parseInfo, EnumToken.ColumnCombinatorTokenType);
|
|
244
241
|
buffer = '';
|
|
245
242
|
break;
|
|
246
243
|
}
|
|
247
244
|
if (buffer.length > 0) {
|
|
248
|
-
yield pushToken(buffer);
|
|
245
|
+
yield pushToken(buffer, parseInfo);
|
|
249
246
|
buffer = '';
|
|
250
247
|
}
|
|
251
248
|
buffer += value;
|
|
252
|
-
if (!(value = peek())) {
|
|
253
|
-
yield pushToken(buffer);
|
|
249
|
+
if (!(value = peek(parseInfo))) {
|
|
250
|
+
yield pushToken(buffer, parseInfo);
|
|
254
251
|
buffer = '';
|
|
255
252
|
break;
|
|
256
253
|
}
|
|
@@ -258,46 +255,46 @@ function* tokenize(stream) {
|
|
|
258
255
|
// ^=
|
|
259
256
|
// $=
|
|
260
257
|
// |=
|
|
261
|
-
if (peek() == '=') {
|
|
262
|
-
next();
|
|
258
|
+
if (peek(parseInfo) == '=') {
|
|
259
|
+
next(parseInfo);
|
|
263
260
|
switch (buffer.charAt(0)) {
|
|
264
261
|
case '~':
|
|
265
|
-
yield pushToken(buffer, EnumToken.IncludeMatchTokenType);
|
|
262
|
+
yield pushToken(buffer, parseInfo, EnumToken.IncludeMatchTokenType);
|
|
266
263
|
break;
|
|
267
264
|
case '^':
|
|
268
|
-
yield pushToken(buffer, EnumToken.StartMatchTokenType);
|
|
265
|
+
yield pushToken(buffer, parseInfo, EnumToken.StartMatchTokenType);
|
|
269
266
|
break;
|
|
270
267
|
case '$':
|
|
271
|
-
yield pushToken(buffer, EnumToken.EndMatchTokenType);
|
|
268
|
+
yield pushToken(buffer, parseInfo, EnumToken.EndMatchTokenType);
|
|
272
269
|
break;
|
|
273
270
|
case '|':
|
|
274
|
-
yield pushToken(buffer, EnumToken.DashMatchTokenType);
|
|
271
|
+
yield pushToken(buffer, parseInfo, EnumToken.DashMatchTokenType);
|
|
275
272
|
break;
|
|
276
273
|
}
|
|
277
274
|
buffer = '';
|
|
278
275
|
break;
|
|
279
276
|
}
|
|
280
|
-
yield pushToken(buffer);
|
|
277
|
+
yield pushToken(buffer, parseInfo);
|
|
281
278
|
buffer = '';
|
|
282
279
|
break;
|
|
283
280
|
case '>':
|
|
284
281
|
if (buffer !== '') {
|
|
285
|
-
yield pushToken(buffer);
|
|
282
|
+
yield pushToken(buffer, parseInfo);
|
|
286
283
|
buffer = '';
|
|
287
284
|
}
|
|
288
|
-
if (peek() == '=') {
|
|
289
|
-
yield pushToken('', EnumToken.GteTokenType);
|
|
290
|
-
next();
|
|
285
|
+
if (peek(parseInfo) == '=') {
|
|
286
|
+
yield pushToken('', parseInfo, EnumToken.GteTokenType);
|
|
287
|
+
next(parseInfo);
|
|
291
288
|
}
|
|
292
289
|
else {
|
|
293
|
-
yield pushToken('', EnumToken.GtTokenType);
|
|
290
|
+
yield pushToken('', parseInfo, EnumToken.GtTokenType);
|
|
294
291
|
}
|
|
295
|
-
consumeWhiteSpace();
|
|
292
|
+
consumeWhiteSpace(parseInfo);
|
|
296
293
|
break;
|
|
297
294
|
case '.':
|
|
298
|
-
const codepoint = peek().charCodeAt(0);
|
|
295
|
+
const codepoint = peek(parseInfo).charCodeAt(0);
|
|
299
296
|
if (!isDigit(codepoint) && buffer !== '') {
|
|
300
|
-
yield pushToken(buffer);
|
|
297
|
+
yield pushToken(buffer, parseInfo);
|
|
301
298
|
buffer = value;
|
|
302
299
|
break;
|
|
303
300
|
}
|
|
@@ -309,47 +306,47 @@ function* tokenize(stream) {
|
|
|
309
306
|
case ',':
|
|
310
307
|
case '=':
|
|
311
308
|
if (buffer.length > 0) {
|
|
312
|
-
yield pushToken(buffer);
|
|
309
|
+
yield pushToken(buffer, parseInfo);
|
|
313
310
|
buffer = '';
|
|
314
311
|
}
|
|
315
|
-
const val = peek();
|
|
312
|
+
const val = peek(parseInfo);
|
|
316
313
|
if (val == '=') {
|
|
317
|
-
next();
|
|
318
|
-
yield pushToken(value + val, EnumToken.ContainMatchTokenType);
|
|
314
|
+
next(parseInfo);
|
|
315
|
+
yield pushToken(value + val, parseInfo, EnumToken.ContainMatchTokenType);
|
|
319
316
|
break;
|
|
320
317
|
}
|
|
321
318
|
if (value == ':' && ':' == val) {
|
|
322
|
-
buffer += value + next();
|
|
319
|
+
buffer += value + next(parseInfo);
|
|
323
320
|
break;
|
|
324
321
|
}
|
|
325
|
-
yield pushToken(value);
|
|
322
|
+
yield pushToken(value, parseInfo);
|
|
326
323
|
buffer = '';
|
|
327
|
-
if (['+', '*', '/'].includes(value) && isWhiteSpace(peek().charCodeAt(0))) {
|
|
328
|
-
yield pushToken(next());
|
|
324
|
+
if (['+', '*', '/'].includes(value) && isWhiteSpace(peek(parseInfo).charCodeAt(0))) {
|
|
325
|
+
yield pushToken(next(parseInfo), parseInfo);
|
|
329
326
|
}
|
|
330
|
-
while (isWhiteSpace(peek().charCodeAt(0))) {
|
|
331
|
-
next();
|
|
327
|
+
while (isWhiteSpace(peek(parseInfo).charCodeAt(0))) {
|
|
328
|
+
next(parseInfo);
|
|
332
329
|
}
|
|
333
330
|
break;
|
|
334
331
|
case ')':
|
|
335
332
|
if (buffer.length > 0) {
|
|
336
|
-
yield pushToken(buffer);
|
|
333
|
+
yield pushToken(buffer, parseInfo);
|
|
337
334
|
buffer = '';
|
|
338
335
|
}
|
|
339
|
-
yield pushToken('', EnumToken.EndParensTokenType);
|
|
336
|
+
yield pushToken('', parseInfo, EnumToken.EndParensTokenType);
|
|
340
337
|
break;
|
|
341
338
|
case '(':
|
|
342
339
|
if (buffer.length == 0) {
|
|
343
|
-
yield pushToken(value);
|
|
340
|
+
yield pushToken(value, parseInfo);
|
|
344
341
|
break;
|
|
345
342
|
}
|
|
346
343
|
buffer += value;
|
|
347
344
|
// @ts-ignore
|
|
348
345
|
if (buffer == 'url(') {
|
|
349
|
-
yield pushToken(buffer);
|
|
346
|
+
yield pushToken(buffer, parseInfo);
|
|
350
347
|
buffer = '';
|
|
351
|
-
consumeWhiteSpace();
|
|
352
|
-
value = peek();
|
|
348
|
+
consumeWhiteSpace(parseInfo);
|
|
349
|
+
value = peek(parseInfo);
|
|
353
350
|
let cp;
|
|
354
351
|
let whitespace = '';
|
|
355
352
|
let hasWhiteSpace = false;
|
|
@@ -358,15 +355,15 @@ function* tokenize(stream) {
|
|
|
358
355
|
const quote = value;
|
|
359
356
|
let inquote = true;
|
|
360
357
|
let hasNewLine = false;
|
|
361
|
-
buffer = next();
|
|
362
|
-
while (value = next()) {
|
|
358
|
+
buffer = next(parseInfo);
|
|
359
|
+
while (value = next(parseInfo)) {
|
|
363
360
|
cp = value.charCodeAt(0);
|
|
364
361
|
// consume an invalid string
|
|
365
362
|
if (inquote) {
|
|
366
363
|
buffer += value;
|
|
367
364
|
if (isNewLine(cp)) {
|
|
368
365
|
hasNewLine = true;
|
|
369
|
-
while (value = next()) {
|
|
366
|
+
while (value = next(parseInfo)) {
|
|
370
367
|
buffer += value;
|
|
371
368
|
if (value == ';') {
|
|
372
369
|
inquote = false;
|
|
@@ -374,7 +371,7 @@ function* tokenize(stream) {
|
|
|
374
371
|
}
|
|
375
372
|
}
|
|
376
373
|
if (value === '') {
|
|
377
|
-
yield pushToken(buffer, EnumToken.BadUrlTokenType);
|
|
374
|
+
yield pushToken(buffer, parseInfo, EnumToken.BadUrlTokenType);
|
|
378
375
|
buffer = '';
|
|
379
376
|
break;
|
|
380
377
|
}
|
|
@@ -382,7 +379,7 @@ function* tokenize(stream) {
|
|
|
382
379
|
}
|
|
383
380
|
// '\\'
|
|
384
381
|
if (cp == 0x5c) {
|
|
385
|
-
buffer += next();
|
|
382
|
+
buffer += next(parseInfo);
|
|
386
383
|
}
|
|
387
384
|
else if (value == quote) {
|
|
388
385
|
inquote = false;
|
|
@@ -392,16 +389,16 @@ function* tokenize(stream) {
|
|
|
392
389
|
if (!inquote) {
|
|
393
390
|
if (isWhiteSpace(cp)) {
|
|
394
391
|
whitespace += value;
|
|
395
|
-
while (value = peek()) {
|
|
392
|
+
while (value = peek(parseInfo)) {
|
|
396
393
|
hasWhiteSpace = true;
|
|
397
394
|
if (isWhiteSpace(value?.charCodeAt(0))) {
|
|
398
|
-
whitespace += next();
|
|
395
|
+
whitespace += next(parseInfo);
|
|
399
396
|
continue;
|
|
400
397
|
}
|
|
401
398
|
break;
|
|
402
399
|
}
|
|
403
|
-
if (!(value = next())) {
|
|
404
|
-
yield pushToken(buffer, hasNewLine ? EnumToken.BadUrlTokenType : EnumToken.UrlTokenTokenType);
|
|
400
|
+
if (!(value = next(parseInfo))) {
|
|
401
|
+
yield pushToken(buffer, parseInfo, hasNewLine ? EnumToken.BadUrlTokenType : EnumToken.UrlTokenTokenType);
|
|
405
402
|
buffer = '';
|
|
406
403
|
break;
|
|
407
404
|
}
|
|
@@ -409,27 +406,27 @@ function* tokenize(stream) {
|
|
|
409
406
|
cp = value.charCodeAt(0);
|
|
410
407
|
// ')'
|
|
411
408
|
if (cp == 0x29) {
|
|
412
|
-
yield pushToken(buffer, hasNewLine ? EnumToken.BadStringTokenType : EnumToken.StringTokenType);
|
|
413
|
-
yield pushToken('', EnumToken.EndParensTokenType);
|
|
409
|
+
yield pushToken(buffer, parseInfo, hasNewLine ? EnumToken.BadStringTokenType : EnumToken.StringTokenType);
|
|
410
|
+
yield pushToken('', parseInfo, EnumToken.EndParensTokenType);
|
|
414
411
|
buffer = '';
|
|
415
412
|
break;
|
|
416
413
|
}
|
|
417
|
-
while (value = next()) {
|
|
414
|
+
while (value = next(parseInfo)) {
|
|
418
415
|
cp = value.charCodeAt(0);
|
|
419
416
|
if (cp == 0x5c) {
|
|
420
|
-
buffer += value + next();
|
|
417
|
+
buffer += value + next(parseInfo);
|
|
421
418
|
continue;
|
|
422
419
|
}
|
|
423
420
|
if (cp == 0x29) {
|
|
424
|
-
yield pushToken(buffer, EnumToken.BadStringTokenType);
|
|
425
|
-
yield pushToken('', EnumToken.EndParensTokenType);
|
|
421
|
+
yield pushToken(buffer, parseInfo, EnumToken.BadStringTokenType);
|
|
422
|
+
yield pushToken('', parseInfo, EnumToken.EndParensTokenType);
|
|
426
423
|
buffer = '';
|
|
427
424
|
break;
|
|
428
425
|
}
|
|
429
426
|
buffer += value;
|
|
430
427
|
}
|
|
431
428
|
if (hasNewLine) {
|
|
432
|
-
yield pushToken(buffer, EnumToken.BadStringTokenType);
|
|
429
|
+
yield pushToken(buffer, parseInfo, EnumToken.BadStringTokenType);
|
|
433
430
|
buffer = '';
|
|
434
431
|
}
|
|
435
432
|
break;
|
|
@@ -440,20 +437,20 @@ function* tokenize(stream) {
|
|
|
440
437
|
}
|
|
441
438
|
else {
|
|
442
439
|
buffer = '';
|
|
443
|
-
while (value = next()) {
|
|
440
|
+
while (value = next(parseInfo)) {
|
|
444
441
|
cp = value.charCodeAt(0);
|
|
445
442
|
// ')'
|
|
446
443
|
if (cp == 0x29) {
|
|
447
|
-
yield pushToken(buffer, EnumToken.UrlTokenTokenType);
|
|
448
|
-
yield pushToken('', EnumToken.EndParensTokenType);
|
|
444
|
+
yield pushToken(buffer, parseInfo, EnumToken.UrlTokenTokenType);
|
|
445
|
+
yield pushToken('', parseInfo, EnumToken.EndParensTokenType);
|
|
449
446
|
buffer = '';
|
|
450
447
|
break;
|
|
451
448
|
}
|
|
452
449
|
if (isWhiteSpace(cp)) {
|
|
453
450
|
hasWhiteSpace = true;
|
|
454
451
|
whitespace = value;
|
|
455
|
-
while (isWhiteSpace(peek()?.charCodeAt(0))) {
|
|
456
|
-
whitespace += next();
|
|
452
|
+
while (isWhiteSpace(peek(parseInfo)?.charCodeAt(0))) {
|
|
453
|
+
whitespace += next(parseInfo);
|
|
457
454
|
}
|
|
458
455
|
continue;
|
|
459
456
|
}
|
|
@@ -469,19 +466,19 @@ function* tokenize(stream) {
|
|
|
469
466
|
}
|
|
470
467
|
if (errorState) {
|
|
471
468
|
buffer += whitespace + value;
|
|
472
|
-
while (value = peek()) {
|
|
469
|
+
while (value = peek(parseInfo)) {
|
|
473
470
|
cp = value.charCodeAt(0);
|
|
474
471
|
if (cp == 0x5c) {
|
|
475
|
-
buffer += next(2);
|
|
472
|
+
buffer += next(parseInfo, 2);
|
|
476
473
|
continue;
|
|
477
474
|
}
|
|
478
475
|
// ')'
|
|
479
476
|
if (cp == 0x29) {
|
|
480
477
|
break;
|
|
481
478
|
}
|
|
482
|
-
buffer += next();
|
|
479
|
+
buffer += next(parseInfo);
|
|
483
480
|
}
|
|
484
|
-
yield pushToken(buffer, EnumToken.BadUrlTokenType);
|
|
481
|
+
yield pushToken(buffer, parseInfo, EnumToken.BadUrlTokenType);
|
|
485
482
|
buffer = '';
|
|
486
483
|
break;
|
|
487
484
|
}
|
|
@@ -489,13 +486,13 @@ function* tokenize(stream) {
|
|
|
489
486
|
}
|
|
490
487
|
}
|
|
491
488
|
if (buffer !== '') {
|
|
492
|
-
yield pushToken(buffer, EnumToken.UrlTokenTokenType);
|
|
489
|
+
yield pushToken(buffer, parseInfo, EnumToken.UrlTokenTokenType);
|
|
493
490
|
buffer = '';
|
|
494
491
|
break;
|
|
495
492
|
}
|
|
496
493
|
break;
|
|
497
494
|
}
|
|
498
|
-
yield pushToken(buffer);
|
|
495
|
+
yield pushToken(buffer, parseInfo);
|
|
499
496
|
buffer = '';
|
|
500
497
|
break;
|
|
501
498
|
case '[':
|
|
@@ -504,19 +501,19 @@ function* tokenize(stream) {
|
|
|
504
501
|
case '}':
|
|
505
502
|
case ';':
|
|
506
503
|
if (buffer.length > 0) {
|
|
507
|
-
yield pushToken(buffer);
|
|
504
|
+
yield pushToken(buffer, parseInfo);
|
|
508
505
|
buffer = '';
|
|
509
506
|
}
|
|
510
|
-
yield pushToken(value);
|
|
507
|
+
yield pushToken(value, parseInfo);
|
|
511
508
|
break;
|
|
512
509
|
case '!':
|
|
513
510
|
if (buffer.length > 0) {
|
|
514
|
-
yield pushToken(buffer);
|
|
511
|
+
yield pushToken(buffer, parseInfo);
|
|
515
512
|
buffer = '';
|
|
516
513
|
}
|
|
517
|
-
if (peek(9) == 'important') {
|
|
518
|
-
yield pushToken('', EnumToken.ImportantTokenType);
|
|
519
|
-
next(9);
|
|
514
|
+
if (peek(parseInfo, 9) == 'important') {
|
|
515
|
+
yield pushToken('', parseInfo, EnumToken.ImportantTokenType);
|
|
516
|
+
next(parseInfo, 9);
|
|
520
517
|
buffer = '';
|
|
521
518
|
break;
|
|
522
519
|
}
|
|
@@ -528,9 +525,9 @@ function* tokenize(stream) {
|
|
|
528
525
|
}
|
|
529
526
|
}
|
|
530
527
|
if (buffer.length > 0) {
|
|
531
|
-
yield pushToken(buffer);
|
|
528
|
+
yield pushToken(buffer, parseInfo);
|
|
532
529
|
}
|
|
533
|
-
// yield pushToken('',
|
|
530
|
+
// yield pushToken('', EnumToken.EOFTokenType);
|
|
534
531
|
}
|
|
535
532
|
|
|
536
533
|
export { tokenize };
|