@tbela99/css-parser 1.3.0 → 1.3.2
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/CHANGELOG.md +10 -0
- package/README.md +28 -10
- package/dist/index-umd-web.js +1610 -1170
- package/dist/index.cjs +1699 -1168
- package/dist/index.d.ts +1834 -71
- package/dist/lib/ast/expand.js +4 -65
- package/dist/lib/ast/features/calc.js +2 -2
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +2 -1
- package/dist/lib/ast/features/transform.js +2 -1
- package/dist/lib/ast/features/type.js +9 -0
- package/dist/lib/ast/math/math.js +1 -1
- package/dist/lib/ast/minify.js +82 -171
- package/dist/lib/ast/types.js +369 -4
- package/dist/lib/ast/walk.js +18 -0
- package/dist/lib/fs/resolve.js +11 -3
- package/dist/lib/parser/declaration/map.js +1 -0
- package/dist/lib/parser/parse.js +106 -21
- package/dist/lib/parser/tokenize.js +40 -80
- package/dist/lib/renderer/render.js +25 -3
- package/dist/lib/renderer/sourcemap/sourcemap.js +34 -0
- package/dist/lib/syntax/color/color.js +7 -0
- package/dist/lib/syntax/color/utils/distance.js +5 -1
- package/dist/lib/syntax/syntax.js +10 -0
- package/dist/lib/validation/config.json.js +33 -30
- package/dist/lib/validation/syntax.js +3 -1
- package/dist/node.js +229 -0
- package/dist/web.js +158 -0
- package/package.json +14 -11
- package/dist/node/index.js +0 -57
- package/dist/node/load.js +0 -20
- package/dist/web/index.js +0 -66
- package/dist/web/load.js +0 -31
package/dist/index-umd-web.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
SyntaxValidationResult[SyntaxValidationResult["Lenient"] = 2] = "Lenient";
|
|
18
18
|
})(SyntaxValidationResult || (SyntaxValidationResult = {}));
|
|
19
19
|
/**
|
|
20
|
-
* validation
|
|
20
|
+
* enum of validation levels
|
|
21
21
|
*/
|
|
22
22
|
exports.ValidationLevel = void 0;
|
|
23
23
|
(function (ValidationLevel) {
|
|
@@ -35,139 +35,504 @@
|
|
|
35
35
|
ValidationLevel[ValidationLevel["All"] = 2] = "All"; // selectors + at-rules + declarations
|
|
36
36
|
})(exports.ValidationLevel || (exports.ValidationLevel = {}));
|
|
37
37
|
/**
|
|
38
|
-
* token types
|
|
38
|
+
* enum of all token types
|
|
39
39
|
*/
|
|
40
40
|
exports.EnumToken = void 0;
|
|
41
41
|
(function (EnumToken) {
|
|
42
|
+
/**
|
|
43
|
+
* comment token
|
|
44
|
+
*/
|
|
42
45
|
EnumToken[EnumToken["CommentTokenType"] = 0] = "CommentTokenType";
|
|
46
|
+
/**
|
|
47
|
+
* cdata section token
|
|
48
|
+
*/
|
|
43
49
|
EnumToken[EnumToken["CDOCOMMTokenType"] = 1] = "CDOCOMMTokenType";
|
|
50
|
+
/**
|
|
51
|
+
* style sheet node type
|
|
52
|
+
*/
|
|
44
53
|
EnumToken[EnumToken["StyleSheetNodeType"] = 2] = "StyleSheetNodeType";
|
|
54
|
+
/**
|
|
55
|
+
* at-rule node type
|
|
56
|
+
*/
|
|
45
57
|
EnumToken[EnumToken["AtRuleNodeType"] = 3] = "AtRuleNodeType";
|
|
58
|
+
/**
|
|
59
|
+
* rule node type
|
|
60
|
+
*/
|
|
46
61
|
EnumToken[EnumToken["RuleNodeType"] = 4] = "RuleNodeType";
|
|
62
|
+
/**
|
|
63
|
+
* declaration node type
|
|
64
|
+
*/
|
|
47
65
|
EnumToken[EnumToken["DeclarationNodeType"] = 5] = "DeclarationNodeType";
|
|
66
|
+
/**
|
|
67
|
+
* literal token type
|
|
68
|
+
*/
|
|
48
69
|
EnumToken[EnumToken["LiteralTokenType"] = 6] = "LiteralTokenType";
|
|
70
|
+
/**
|
|
71
|
+
* identifier token type
|
|
72
|
+
*/
|
|
49
73
|
EnumToken[EnumToken["IdenTokenType"] = 7] = "IdenTokenType";
|
|
74
|
+
/**
|
|
75
|
+
* dashed identifier token type
|
|
76
|
+
*/
|
|
50
77
|
EnumToken[EnumToken["DashedIdenTokenType"] = 8] = "DashedIdenTokenType";
|
|
78
|
+
/**
|
|
79
|
+
* comma token type
|
|
80
|
+
*/
|
|
51
81
|
EnumToken[EnumToken["CommaTokenType"] = 9] = "CommaTokenType";
|
|
82
|
+
/**
|
|
83
|
+
* colon token type
|
|
84
|
+
*/
|
|
52
85
|
EnumToken[EnumToken["ColonTokenType"] = 10] = "ColonTokenType";
|
|
86
|
+
/**
|
|
87
|
+
* semicolon token type
|
|
88
|
+
*/
|
|
53
89
|
EnumToken[EnumToken["SemiColonTokenType"] = 11] = "SemiColonTokenType";
|
|
90
|
+
/**
|
|
91
|
+
* number token type
|
|
92
|
+
*/
|
|
54
93
|
EnumToken[EnumToken["NumberTokenType"] = 12] = "NumberTokenType";
|
|
94
|
+
/**
|
|
95
|
+
* at-rule token type
|
|
96
|
+
*/
|
|
55
97
|
EnumToken[EnumToken["AtRuleTokenType"] = 13] = "AtRuleTokenType";
|
|
98
|
+
/**
|
|
99
|
+
* percentage token type
|
|
100
|
+
*/
|
|
56
101
|
EnumToken[EnumToken["PercentageTokenType"] = 14] = "PercentageTokenType";
|
|
102
|
+
/**
|
|
103
|
+
* function token type
|
|
104
|
+
*/
|
|
57
105
|
EnumToken[EnumToken["FunctionTokenType"] = 15] = "FunctionTokenType";
|
|
106
|
+
/**
|
|
107
|
+
* timeline function token type
|
|
108
|
+
*/
|
|
58
109
|
EnumToken[EnumToken["TimelineFunctionTokenType"] = 16] = "TimelineFunctionTokenType";
|
|
110
|
+
/**
|
|
111
|
+
* timing function token type
|
|
112
|
+
*/
|
|
59
113
|
EnumToken[EnumToken["TimingFunctionTokenType"] = 17] = "TimingFunctionTokenType";
|
|
114
|
+
/**
|
|
115
|
+
* url function token type
|
|
116
|
+
*/
|
|
60
117
|
EnumToken[EnumToken["UrlFunctionTokenType"] = 18] = "UrlFunctionTokenType";
|
|
118
|
+
/**
|
|
119
|
+
* image function token type
|
|
120
|
+
*/
|
|
61
121
|
EnumToken[EnumToken["ImageFunctionTokenType"] = 19] = "ImageFunctionTokenType";
|
|
122
|
+
/**
|
|
123
|
+
* string token type
|
|
124
|
+
*/
|
|
62
125
|
EnumToken[EnumToken["StringTokenType"] = 20] = "StringTokenType";
|
|
126
|
+
/**
|
|
127
|
+
* unclosed string token type
|
|
128
|
+
*/
|
|
63
129
|
EnumToken[EnumToken["UnclosedStringTokenType"] = 21] = "UnclosedStringTokenType";
|
|
130
|
+
/**
|
|
131
|
+
* dimension token type
|
|
132
|
+
*/
|
|
64
133
|
EnumToken[EnumToken["DimensionTokenType"] = 22] = "DimensionTokenType";
|
|
134
|
+
/**
|
|
135
|
+
* length token type
|
|
136
|
+
*/
|
|
65
137
|
EnumToken[EnumToken["LengthTokenType"] = 23] = "LengthTokenType";
|
|
138
|
+
/**
|
|
139
|
+
* angle token type
|
|
140
|
+
*/
|
|
66
141
|
EnumToken[EnumToken["AngleTokenType"] = 24] = "AngleTokenType";
|
|
142
|
+
/**
|
|
143
|
+
* time token type
|
|
144
|
+
*/
|
|
67
145
|
EnumToken[EnumToken["TimeTokenType"] = 25] = "TimeTokenType";
|
|
146
|
+
/**
|
|
147
|
+
* frequency token type
|
|
148
|
+
*/
|
|
68
149
|
EnumToken[EnumToken["FrequencyTokenType"] = 26] = "FrequencyTokenType";
|
|
150
|
+
/**
|
|
151
|
+
* resolution token type
|
|
152
|
+
*/
|
|
69
153
|
EnumToken[EnumToken["ResolutionTokenType"] = 27] = "ResolutionTokenType";
|
|
154
|
+
/**
|
|
155
|
+
* hash token type
|
|
156
|
+
*/
|
|
70
157
|
EnumToken[EnumToken["HashTokenType"] = 28] = "HashTokenType";
|
|
158
|
+
/**
|
|
159
|
+
* block start token type
|
|
160
|
+
*/
|
|
71
161
|
EnumToken[EnumToken["BlockStartTokenType"] = 29] = "BlockStartTokenType";
|
|
162
|
+
/**
|
|
163
|
+
* block end token type
|
|
164
|
+
*/
|
|
72
165
|
EnumToken[EnumToken["BlockEndTokenType"] = 30] = "BlockEndTokenType";
|
|
166
|
+
/**
|
|
167
|
+
* attribute start token type
|
|
168
|
+
*/
|
|
73
169
|
EnumToken[EnumToken["AttrStartTokenType"] = 31] = "AttrStartTokenType";
|
|
170
|
+
/**
|
|
171
|
+
* attribute end token type
|
|
172
|
+
*/
|
|
74
173
|
EnumToken[EnumToken["AttrEndTokenType"] = 32] = "AttrEndTokenType";
|
|
174
|
+
/**
|
|
175
|
+
* start parentheses token type
|
|
176
|
+
*/
|
|
75
177
|
EnumToken[EnumToken["StartParensTokenType"] = 33] = "StartParensTokenType";
|
|
178
|
+
/**
|
|
179
|
+
* end parentheses token type
|
|
180
|
+
*/
|
|
76
181
|
EnumToken[EnumToken["EndParensTokenType"] = 34] = "EndParensTokenType";
|
|
182
|
+
/**
|
|
183
|
+
* parentheses token type
|
|
184
|
+
*/
|
|
77
185
|
EnumToken[EnumToken["ParensTokenType"] = 35] = "ParensTokenType";
|
|
186
|
+
/**
|
|
187
|
+
* whitespace token type
|
|
188
|
+
*/
|
|
78
189
|
EnumToken[EnumToken["WhitespaceTokenType"] = 36] = "WhitespaceTokenType";
|
|
190
|
+
/**
|
|
191
|
+
* include match token type
|
|
192
|
+
*/
|
|
79
193
|
EnumToken[EnumToken["IncludeMatchTokenType"] = 37] = "IncludeMatchTokenType";
|
|
194
|
+
/**
|
|
195
|
+
* dash match token type
|
|
196
|
+
*/
|
|
80
197
|
EnumToken[EnumToken["DashMatchTokenType"] = 38] = "DashMatchTokenType";
|
|
198
|
+
/**
|
|
199
|
+
* equal match token type
|
|
200
|
+
*/
|
|
81
201
|
EnumToken[EnumToken["EqualMatchTokenType"] = 39] = "EqualMatchTokenType";
|
|
202
|
+
/**
|
|
203
|
+
* less than token type
|
|
204
|
+
*/
|
|
82
205
|
EnumToken[EnumToken["LtTokenType"] = 40] = "LtTokenType";
|
|
206
|
+
/**
|
|
207
|
+
* less than or equal to token type
|
|
208
|
+
*/
|
|
83
209
|
EnumToken[EnumToken["LteTokenType"] = 41] = "LteTokenType";
|
|
210
|
+
/**
|
|
211
|
+
* greater than token type
|
|
212
|
+
*/
|
|
84
213
|
EnumToken[EnumToken["GtTokenType"] = 42] = "GtTokenType";
|
|
214
|
+
/**
|
|
215
|
+
* greater than or equal to token type
|
|
216
|
+
*/
|
|
85
217
|
EnumToken[EnumToken["GteTokenType"] = 43] = "GteTokenType";
|
|
218
|
+
/**
|
|
219
|
+
* pseudo-class token type
|
|
220
|
+
*/
|
|
86
221
|
EnumToken[EnumToken["PseudoClassTokenType"] = 44] = "PseudoClassTokenType";
|
|
222
|
+
/**
|
|
223
|
+
* pseudo-class function token type
|
|
224
|
+
*/
|
|
87
225
|
EnumToken[EnumToken["PseudoClassFuncTokenType"] = 45] = "PseudoClassFuncTokenType";
|
|
226
|
+
/**
|
|
227
|
+
* delimiter token type
|
|
228
|
+
*/
|
|
88
229
|
EnumToken[EnumToken["DelimTokenType"] = 46] = "DelimTokenType";
|
|
230
|
+
/**
|
|
231
|
+
* URL token type
|
|
232
|
+
*/
|
|
89
233
|
EnumToken[EnumToken["UrlTokenTokenType"] = 47] = "UrlTokenTokenType";
|
|
234
|
+
/**
|
|
235
|
+
* end of file token type
|
|
236
|
+
*/
|
|
90
237
|
EnumToken[EnumToken["EOFTokenType"] = 48] = "EOFTokenType";
|
|
238
|
+
/**
|
|
239
|
+
* important token type
|
|
240
|
+
*/
|
|
91
241
|
EnumToken[EnumToken["ImportantTokenType"] = 49] = "ImportantTokenType";
|
|
242
|
+
/**
|
|
243
|
+
* color token type
|
|
244
|
+
*/
|
|
92
245
|
EnumToken[EnumToken["ColorTokenType"] = 50] = "ColorTokenType";
|
|
246
|
+
/**
|
|
247
|
+
* attribute token type
|
|
248
|
+
*/
|
|
93
249
|
EnumToken[EnumToken["AttrTokenType"] = 51] = "AttrTokenType";
|
|
250
|
+
/**
|
|
251
|
+
* bad comment token type
|
|
252
|
+
*/
|
|
94
253
|
EnumToken[EnumToken["BadCommentTokenType"] = 52] = "BadCommentTokenType";
|
|
254
|
+
/**
|
|
255
|
+
* bad cdo token type
|
|
256
|
+
*/
|
|
95
257
|
EnumToken[EnumToken["BadCdoTokenType"] = 53] = "BadCdoTokenType";
|
|
258
|
+
/**
|
|
259
|
+
* bad URL token type
|
|
260
|
+
*/
|
|
96
261
|
EnumToken[EnumToken["BadUrlTokenType"] = 54] = "BadUrlTokenType";
|
|
262
|
+
/**
|
|
263
|
+
* bad string token type
|
|
264
|
+
*/
|
|
97
265
|
EnumToken[EnumToken["BadStringTokenType"] = 55] = "BadStringTokenType";
|
|
266
|
+
/**
|
|
267
|
+
* binary expression token type
|
|
268
|
+
*/
|
|
98
269
|
EnumToken[EnumToken["BinaryExpressionTokenType"] = 56] = "BinaryExpressionTokenType";
|
|
270
|
+
/**
|
|
271
|
+
* unary expression token type
|
|
272
|
+
*/
|
|
99
273
|
EnumToken[EnumToken["UnaryExpressionTokenType"] = 57] = "UnaryExpressionTokenType";
|
|
274
|
+
/**
|
|
275
|
+
* flex token type
|
|
276
|
+
*/
|
|
100
277
|
EnumToken[EnumToken["FlexTokenType"] = 58] = "FlexTokenType";
|
|
101
|
-
|
|
278
|
+
/**
|
|
279
|
+
* token list token type
|
|
280
|
+
*/
|
|
102
281
|
EnumToken[EnumToken["ListToken"] = 59] = "ListToken";
|
|
103
282
|
/* arithmetic tokens */
|
|
283
|
+
/**
|
|
284
|
+
* addition token type
|
|
285
|
+
*/
|
|
104
286
|
EnumToken[EnumToken["Add"] = 60] = "Add";
|
|
287
|
+
/**
|
|
288
|
+
* multiplication token type
|
|
289
|
+
*/
|
|
105
290
|
EnumToken[EnumToken["Mul"] = 61] = "Mul";
|
|
291
|
+
/**
|
|
292
|
+
* division token type
|
|
293
|
+
*/
|
|
106
294
|
EnumToken[EnumToken["Div"] = 62] = "Div";
|
|
295
|
+
/**
|
|
296
|
+
* subtraction token type
|
|
297
|
+
*/
|
|
107
298
|
EnumToken[EnumToken["Sub"] = 63] = "Sub";
|
|
108
299
|
/* new tokens */
|
|
300
|
+
/**
|
|
301
|
+
* column combinator token type
|
|
302
|
+
*/
|
|
109
303
|
EnumToken[EnumToken["ColumnCombinatorTokenType"] = 64] = "ColumnCombinatorTokenType";
|
|
304
|
+
/**
|
|
305
|
+
* contain match token type
|
|
306
|
+
*/
|
|
110
307
|
EnumToken[EnumToken["ContainMatchTokenType"] = 65] = "ContainMatchTokenType";
|
|
308
|
+
/**
|
|
309
|
+
* start match token type
|
|
310
|
+
*/
|
|
111
311
|
EnumToken[EnumToken["StartMatchTokenType"] = 66] = "StartMatchTokenType";
|
|
312
|
+
/**
|
|
313
|
+
* end match token type
|
|
314
|
+
*/
|
|
112
315
|
EnumToken[EnumToken["EndMatchTokenType"] = 67] = "EndMatchTokenType";
|
|
316
|
+
/**
|
|
317
|
+
* match expression token type
|
|
318
|
+
*/
|
|
113
319
|
EnumToken[EnumToken["MatchExpressionTokenType"] = 68] = "MatchExpressionTokenType";
|
|
320
|
+
/**
|
|
321
|
+
* namespace attribute token type
|
|
322
|
+
*/
|
|
114
323
|
EnumToken[EnumToken["NameSpaceAttributeTokenType"] = 69] = "NameSpaceAttributeTokenType";
|
|
324
|
+
/**
|
|
325
|
+
* fraction token type
|
|
326
|
+
*/
|
|
115
327
|
EnumToken[EnumToken["FractionTokenType"] = 70] = "FractionTokenType";
|
|
328
|
+
/**
|
|
329
|
+
* identifier list token type
|
|
330
|
+
*/
|
|
116
331
|
EnumToken[EnumToken["IdenListTokenType"] = 71] = "IdenListTokenType";
|
|
332
|
+
/**
|
|
333
|
+
* grid template function token type
|
|
334
|
+
*/
|
|
117
335
|
EnumToken[EnumToken["GridTemplateFuncTokenType"] = 72] = "GridTemplateFuncTokenType";
|
|
336
|
+
/**
|
|
337
|
+
* keyframe rule node type
|
|
338
|
+
*/
|
|
118
339
|
EnumToken[EnumToken["KeyFrameRuleNodeType"] = 73] = "KeyFrameRuleNodeType";
|
|
340
|
+
/**
|
|
341
|
+
* class selector token type
|
|
342
|
+
*/
|
|
119
343
|
EnumToken[EnumToken["ClassSelectorTokenType"] = 74] = "ClassSelectorTokenType";
|
|
344
|
+
/**
|
|
345
|
+
* universal selector token type
|
|
346
|
+
*/
|
|
120
347
|
EnumToken[EnumToken["UniversalSelectorTokenType"] = 75] = "UniversalSelectorTokenType";
|
|
348
|
+
/**
|
|
349
|
+
* child combinator token type
|
|
350
|
+
*/
|
|
121
351
|
EnumToken[EnumToken["ChildCombinatorTokenType"] = 76] = "ChildCombinatorTokenType";
|
|
352
|
+
/**
|
|
353
|
+
* descendant combinator token type
|
|
354
|
+
*/
|
|
122
355
|
EnumToken[EnumToken["DescendantCombinatorTokenType"] = 77] = "DescendantCombinatorTokenType";
|
|
356
|
+
/**
|
|
357
|
+
* next sibling combinator token type
|
|
358
|
+
*/
|
|
123
359
|
EnumToken[EnumToken["NextSiblingCombinatorTokenType"] = 78] = "NextSiblingCombinatorTokenType";
|
|
360
|
+
/**
|
|
361
|
+
* subsequent sibling combinator token type
|
|
362
|
+
*/
|
|
124
363
|
EnumToken[EnumToken["SubsequentSiblingCombinatorTokenType"] = 79] = "SubsequentSiblingCombinatorTokenType";
|
|
364
|
+
/**
|
|
365
|
+
* nesting selector token type
|
|
366
|
+
*/
|
|
125
367
|
EnumToken[EnumToken["NestingSelectorTokenType"] = 80] = "NestingSelectorTokenType";
|
|
368
|
+
/**
|
|
369
|
+
* invalid rule token type
|
|
370
|
+
*/
|
|
126
371
|
EnumToken[EnumToken["InvalidRuleTokenType"] = 81] = "InvalidRuleTokenType";
|
|
372
|
+
/**
|
|
373
|
+
* invalid class selector token type
|
|
374
|
+
*/
|
|
127
375
|
EnumToken[EnumToken["InvalidClassSelectorTokenType"] = 82] = "InvalidClassSelectorTokenType";
|
|
376
|
+
/**
|
|
377
|
+
* invalid attribute token type
|
|
378
|
+
*/
|
|
128
379
|
EnumToken[EnumToken["InvalidAttrTokenType"] = 83] = "InvalidAttrTokenType";
|
|
380
|
+
/**
|
|
381
|
+
* invalid at rule token type
|
|
382
|
+
*/
|
|
129
383
|
EnumToken[EnumToken["InvalidAtRuleTokenType"] = 84] = "InvalidAtRuleTokenType";
|
|
384
|
+
/**
|
|
385
|
+
* media query condition token type
|
|
386
|
+
*/
|
|
130
387
|
EnumToken[EnumToken["MediaQueryConditionTokenType"] = 85] = "MediaQueryConditionTokenType";
|
|
388
|
+
/**
|
|
389
|
+
* media feature token type
|
|
390
|
+
*/
|
|
131
391
|
EnumToken[EnumToken["MediaFeatureTokenType"] = 86] = "MediaFeatureTokenType";
|
|
392
|
+
/**
|
|
393
|
+
* media feature only token type
|
|
394
|
+
*/
|
|
132
395
|
EnumToken[EnumToken["MediaFeatureOnlyTokenType"] = 87] = "MediaFeatureOnlyTokenType";
|
|
396
|
+
/**
|
|
397
|
+
* media feature not token type
|
|
398
|
+
*/
|
|
133
399
|
EnumToken[EnumToken["MediaFeatureNotTokenType"] = 88] = "MediaFeatureNotTokenType";
|
|
400
|
+
/**
|
|
401
|
+
* media feature and token type
|
|
402
|
+
*/
|
|
134
403
|
EnumToken[EnumToken["MediaFeatureAndTokenType"] = 89] = "MediaFeatureAndTokenType";
|
|
404
|
+
/**
|
|
405
|
+
* media feature or token type
|
|
406
|
+
*/
|
|
135
407
|
EnumToken[EnumToken["MediaFeatureOrTokenType"] = 90] = "MediaFeatureOrTokenType";
|
|
408
|
+
/**
|
|
409
|
+
* pseudo page token type
|
|
410
|
+
*/
|
|
136
411
|
EnumToken[EnumToken["PseudoPageTokenType"] = 91] = "PseudoPageTokenType";
|
|
412
|
+
/**
|
|
413
|
+
* pseudo element token type
|
|
414
|
+
*/
|
|
137
415
|
EnumToken[EnumToken["PseudoElementTokenType"] = 92] = "PseudoElementTokenType";
|
|
416
|
+
/**
|
|
417
|
+
* keyframe at rule node type
|
|
418
|
+
*/
|
|
138
419
|
EnumToken[EnumToken["KeyframeAtRuleNodeType"] = 93] = "KeyframeAtRuleNodeType";
|
|
420
|
+
/**
|
|
421
|
+
* invalid declaration node type
|
|
422
|
+
*/
|
|
139
423
|
EnumToken[EnumToken["InvalidDeclarationNodeType"] = 94] = "InvalidDeclarationNodeType";
|
|
140
424
|
/* aliases */
|
|
425
|
+
/**
|
|
426
|
+
* alias for time token type
|
|
427
|
+
*/
|
|
141
428
|
EnumToken[EnumToken["Time"] = 25] = "Time";
|
|
429
|
+
/**
|
|
430
|
+
* alias for identifier token type
|
|
431
|
+
*/
|
|
142
432
|
EnumToken[EnumToken["Iden"] = 7] = "Iden";
|
|
433
|
+
/**
|
|
434
|
+
* alias for end of file token type
|
|
435
|
+
*/
|
|
143
436
|
EnumToken[EnumToken["EOF"] = 48] = "EOF";
|
|
437
|
+
/**
|
|
438
|
+
* alias for hash token type
|
|
439
|
+
*/
|
|
144
440
|
EnumToken[EnumToken["Hash"] = 28] = "Hash";
|
|
441
|
+
/**
|
|
442
|
+
* alias for flex token type
|
|
443
|
+
*/
|
|
145
444
|
EnumToken[EnumToken["Flex"] = 58] = "Flex";
|
|
445
|
+
/**
|
|
446
|
+
* alias for angle token type
|
|
447
|
+
*/
|
|
146
448
|
EnumToken[EnumToken["Angle"] = 24] = "Angle";
|
|
449
|
+
/**
|
|
450
|
+
* alias for color token type
|
|
451
|
+
*/
|
|
147
452
|
EnumToken[EnumToken["Color"] = 50] = "Color";
|
|
453
|
+
/**
|
|
454
|
+
* alias for comma token type
|
|
455
|
+
*/
|
|
148
456
|
EnumToken[EnumToken["Comma"] = 9] = "Comma";
|
|
457
|
+
/**
|
|
458
|
+
* alias for string token type
|
|
459
|
+
*/
|
|
149
460
|
EnumToken[EnumToken["String"] = 20] = "String";
|
|
461
|
+
/**
|
|
462
|
+
* alias for length token type
|
|
463
|
+
*/
|
|
150
464
|
EnumToken[EnumToken["Length"] = 23] = "Length";
|
|
465
|
+
/**
|
|
466
|
+
* alias for number token type
|
|
467
|
+
*/
|
|
151
468
|
EnumToken[EnumToken["Number"] = 12] = "Number";
|
|
469
|
+
/**
|
|
470
|
+
* alias for percentage token type
|
|
471
|
+
*/
|
|
152
472
|
EnumToken[EnumToken["Perc"] = 14] = "Perc";
|
|
473
|
+
/**
|
|
474
|
+
* alias for literal token type
|
|
475
|
+
*/
|
|
153
476
|
EnumToken[EnumToken["Literal"] = 6] = "Literal";
|
|
477
|
+
/**
|
|
478
|
+
* alias for comment token type
|
|
479
|
+
*/
|
|
154
480
|
EnumToken[EnumToken["Comment"] = 0] = "Comment";
|
|
481
|
+
/**
|
|
482
|
+
* alias for url function token type
|
|
483
|
+
*/
|
|
155
484
|
EnumToken[EnumToken["UrlFunc"] = 18] = "UrlFunc";
|
|
485
|
+
/**
|
|
486
|
+
* alias for dimension token type
|
|
487
|
+
*/
|
|
156
488
|
EnumToken[EnumToken["Dimension"] = 22] = "Dimension";
|
|
489
|
+
/**
|
|
490
|
+
* alias for frequency token type
|
|
491
|
+
*/
|
|
157
492
|
EnumToken[EnumToken["Frequency"] = 26] = "Frequency";
|
|
493
|
+
/**
|
|
494
|
+
* alias for resolution token type
|
|
495
|
+
*/
|
|
158
496
|
EnumToken[EnumToken["Resolution"] = 27] = "Resolution";
|
|
497
|
+
/**
|
|
498
|
+
* alias for whitespace token type
|
|
499
|
+
*/
|
|
159
500
|
EnumToken[EnumToken["Whitespace"] = 36] = "Whitespace";
|
|
501
|
+
/**
|
|
502
|
+
* alias for identifier list token type
|
|
503
|
+
*/
|
|
160
504
|
EnumToken[EnumToken["IdenList"] = 71] = "IdenList";
|
|
505
|
+
/**
|
|
506
|
+
* alias for dashed identifier token type
|
|
507
|
+
*/
|
|
161
508
|
EnumToken[EnumToken["DashedIden"] = 8] = "DashedIden";
|
|
509
|
+
/**
|
|
510
|
+
* alias for grid template function token type
|
|
511
|
+
*/
|
|
162
512
|
EnumToken[EnumToken["GridTemplateFunc"] = 72] = "GridTemplateFunc";
|
|
513
|
+
/**
|
|
514
|
+
* alias for image function token type
|
|
515
|
+
*/
|
|
163
516
|
EnumToken[EnumToken["ImageFunc"] = 19] = "ImageFunc";
|
|
517
|
+
/**
|
|
518
|
+
* alias for comment node type
|
|
519
|
+
*/
|
|
164
520
|
EnumToken[EnumToken["CommentNodeType"] = 0] = "CommentNodeType";
|
|
521
|
+
/**
|
|
522
|
+
* alias for cdata section node type
|
|
523
|
+
*/
|
|
165
524
|
EnumToken[EnumToken["CDOCOMMNodeType"] = 1] = "CDOCOMMNodeType";
|
|
525
|
+
/**
|
|
526
|
+
* alias for timing function token type
|
|
527
|
+
*/
|
|
166
528
|
EnumToken[EnumToken["TimingFunction"] = 17] = "TimingFunction";
|
|
529
|
+
/**
|
|
530
|
+
* alias for timeline function token type
|
|
531
|
+
*/
|
|
167
532
|
EnumToken[EnumToken["TimelineFunction"] = 16] = "TimelineFunction";
|
|
168
533
|
})(exports.EnumToken || (exports.EnumToken = {}));
|
|
169
534
|
/**
|
|
170
|
-
* color types enum
|
|
535
|
+
* supported color types enum
|
|
171
536
|
*/
|
|
172
537
|
exports.ColorType = void 0;
|
|
173
538
|
(function (ColorType) {
|
|
@@ -1889,15 +2254,19 @@
|
|
|
1889
2254
|
* Calculate the distance between two okLab colors.
|
|
1890
2255
|
* @param okLab1
|
|
1891
2256
|
* @param okLab2
|
|
2257
|
+
*
|
|
2258
|
+
* @private
|
|
1892
2259
|
*/
|
|
1893
2260
|
function okLabDistance(okLab1, okLab2) {
|
|
1894
2261
|
return Math.sqrt(Math.pow(okLab1[0] - okLab2[0], 2) + Math.pow(okLab1[1] - okLab2[1], 2) + Math.pow(okLab1[2] - okLab2[2], 2));
|
|
1895
2262
|
}
|
|
1896
2263
|
/**
|
|
1897
|
-
* Check if two colors are close.
|
|
2264
|
+
* Check if two colors are close in okLab space.
|
|
1898
2265
|
* @param color1
|
|
1899
2266
|
* @param color2
|
|
1900
2267
|
* @param threshold
|
|
2268
|
+
*
|
|
2269
|
+
* @private
|
|
1901
2270
|
*/
|
|
1902
2271
|
function isOkLabClose(color1, color2, threshold = .01) {
|
|
1903
2272
|
color1 = convertColor(color1, exports.ColorType.OKLAB);
|
|
@@ -3756,6 +4125,13 @@
|
|
|
3756
4125
|
* Converts a color to another color space
|
|
3757
4126
|
* @param token
|
|
3758
4127
|
* @param to
|
|
4128
|
+
*
|
|
4129
|
+
* <code>
|
|
4130
|
+
*
|
|
4131
|
+
* const token = {typ: EnumToken.ColorTokenType, kin: ColorType.HEX, val: '#F00'}
|
|
4132
|
+
* const result = convertColor(token, ColorType.LCH);
|
|
4133
|
+
*
|
|
4134
|
+
* </code>
|
|
3759
4135
|
*/
|
|
3760
4136
|
function convertColor(token, to) {
|
|
3761
4137
|
if (token.kin == exports.ColorType.SYS ||
|
|
@@ -4303,692 +4679,6 @@
|
|
|
4303
4679
|
return angle;
|
|
4304
4680
|
}
|
|
4305
4681
|
|
|
4306
|
-
// from https://github.com/Rich-Harris/vlq/tree/master
|
|
4307
|
-
// credit: Rich Harris
|
|
4308
|
-
const integer_to_char = {};
|
|
4309
|
-
let i = 0;
|
|
4310
|
-
for (const char of 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=') {
|
|
4311
|
-
integer_to_char[i++] = char;
|
|
4312
|
-
}
|
|
4313
|
-
function encode(value) {
|
|
4314
|
-
if (typeof value === 'number') {
|
|
4315
|
-
return encode_integer(value);
|
|
4316
|
-
}
|
|
4317
|
-
let result = '';
|
|
4318
|
-
for (let i = 0; i < value.length; i += 1) {
|
|
4319
|
-
result += encode_integer(value[i]);
|
|
4320
|
-
}
|
|
4321
|
-
return result;
|
|
4322
|
-
}
|
|
4323
|
-
function encode_integer(num) {
|
|
4324
|
-
let result = '';
|
|
4325
|
-
if (num < 0) {
|
|
4326
|
-
num = (-num << 1) | 1;
|
|
4327
|
-
}
|
|
4328
|
-
else {
|
|
4329
|
-
num <<= 1;
|
|
4330
|
-
}
|
|
4331
|
-
do {
|
|
4332
|
-
let clamped = num & 31;
|
|
4333
|
-
num >>>= 5;
|
|
4334
|
-
if (num > 0) {
|
|
4335
|
-
clamped |= 32;
|
|
4336
|
-
}
|
|
4337
|
-
result += integer_to_char[clamped];
|
|
4338
|
-
} while (num > 0);
|
|
4339
|
-
return result;
|
|
4340
|
-
}
|
|
4341
|
-
|
|
4342
|
-
class SourceMap {
|
|
4343
|
-
lastLocation = null;
|
|
4344
|
-
#version = 3;
|
|
4345
|
-
#sources = [];
|
|
4346
|
-
#map = new Map;
|
|
4347
|
-
#line = -1;
|
|
4348
|
-
add(source, original) {
|
|
4349
|
-
if (original.src !== '') {
|
|
4350
|
-
if (!this.#sources.includes(original.src)) {
|
|
4351
|
-
this.#sources.push(original.src);
|
|
4352
|
-
}
|
|
4353
|
-
const line = source.sta.lin - 1;
|
|
4354
|
-
let record;
|
|
4355
|
-
if (line > this.#line) {
|
|
4356
|
-
this.#line = line;
|
|
4357
|
-
}
|
|
4358
|
-
if (!this.#map.has(line)) {
|
|
4359
|
-
record = [Math.max(0, source.sta.col - 1), this.#sources.indexOf(original.src), original.sta.lin - 1, original.sta.col - 1];
|
|
4360
|
-
this.#map.set(line, [record]);
|
|
4361
|
-
}
|
|
4362
|
-
else {
|
|
4363
|
-
const arr = this.#map.get(line);
|
|
4364
|
-
record = [Math.max(0, source.sta.col - 1 - arr[0][0]), this.#sources.indexOf(original.src) - arr[0][1], original.sta.lin - 1, original.sta.col - 1];
|
|
4365
|
-
arr.push(record);
|
|
4366
|
-
}
|
|
4367
|
-
if (this.lastLocation != null) {
|
|
4368
|
-
record[2] -= this.lastLocation.sta.lin - 1;
|
|
4369
|
-
record[3] -= this.lastLocation.sta.col - 1;
|
|
4370
|
-
}
|
|
4371
|
-
this.lastLocation = original;
|
|
4372
|
-
}
|
|
4373
|
-
}
|
|
4374
|
-
toUrl() {
|
|
4375
|
-
// /*# sourceMappingURL = ${url} */
|
|
4376
|
-
return `data:application/json,${encodeURIComponent(JSON.stringify(this.toJSON()))}`;
|
|
4377
|
-
}
|
|
4378
|
-
toJSON() {
|
|
4379
|
-
const mappings = [];
|
|
4380
|
-
let i = 0;
|
|
4381
|
-
for (; i <= this.#line; i++) {
|
|
4382
|
-
if (!this.#map.has(i)) {
|
|
4383
|
-
mappings.push('');
|
|
4384
|
-
}
|
|
4385
|
-
else {
|
|
4386
|
-
mappings.push(this.#map.get(i).reduce((acc, curr) => acc + (acc === '' ? '' : ',') + encode(curr), ''));
|
|
4387
|
-
}
|
|
4388
|
-
}
|
|
4389
|
-
return {
|
|
4390
|
-
version: this.#version,
|
|
4391
|
-
sources: this.#sources.slice(),
|
|
4392
|
-
mappings: mappings.join(';')
|
|
4393
|
-
};
|
|
4394
|
-
}
|
|
4395
|
-
}
|
|
4396
|
-
|
|
4397
|
-
function update(position, str) {
|
|
4398
|
-
let i = 0;
|
|
4399
|
-
for (; i < str.length; i++) {
|
|
4400
|
-
if (isNewLine(str[i].charCodeAt(0))) {
|
|
4401
|
-
position.lin++;
|
|
4402
|
-
position.col = 0;
|
|
4403
|
-
}
|
|
4404
|
-
else {
|
|
4405
|
-
position.col++;
|
|
4406
|
-
}
|
|
4407
|
-
}
|
|
4408
|
-
}
|
|
4409
|
-
/**
|
|
4410
|
-
* render ast
|
|
4411
|
-
* @param data
|
|
4412
|
-
* @param options
|
|
4413
|
-
*/
|
|
4414
|
-
function doRender(data, options = {}) {
|
|
4415
|
-
const minify = options.minify ?? true;
|
|
4416
|
-
const beautify = options.beautify ?? !minify;
|
|
4417
|
-
options = {
|
|
4418
|
-
...(beautify ? {
|
|
4419
|
-
indent: ' ',
|
|
4420
|
-
newLine: '\n',
|
|
4421
|
-
} : {
|
|
4422
|
-
indent: '',
|
|
4423
|
-
newLine: '',
|
|
4424
|
-
}),
|
|
4425
|
-
...(minify ? {
|
|
4426
|
-
removeEmpty: true,
|
|
4427
|
-
removeComments: true,
|
|
4428
|
-
minify: true
|
|
4429
|
-
} : {
|
|
4430
|
-
removeEmpty: false,
|
|
4431
|
-
removeComments: false,
|
|
4432
|
-
}), sourcemap: false, convertColor: true, expandNestingRules: false, preserveLicense: false, ...options
|
|
4433
|
-
};
|
|
4434
|
-
if (options.withParents) {
|
|
4435
|
-
// @ts-ignore
|
|
4436
|
-
let parent = data.parent;
|
|
4437
|
-
// @ts-ignore
|
|
4438
|
-
while (data.parent != null) {
|
|
4439
|
-
// @ts-ignore
|
|
4440
|
-
parent = { ...data.parent, chi: [{ ...data }] };
|
|
4441
|
-
// @ts-ignore
|
|
4442
|
-
parent.parent = data.parent.parent;
|
|
4443
|
-
// @ts-ignore
|
|
4444
|
-
data = parent;
|
|
4445
|
-
}
|
|
4446
|
-
}
|
|
4447
|
-
const startTime = performance.now();
|
|
4448
|
-
const errors = [];
|
|
4449
|
-
const sourcemap = options.sourcemap ? new SourceMap : null;
|
|
4450
|
-
const cache = Object.create(null);
|
|
4451
|
-
const result = {
|
|
4452
|
-
code: renderAstNode(options.expandNestingRules ? expand(data) : data, options, sourcemap, {
|
|
4453
|
-
ind: 0,
|
|
4454
|
-
lin: 1,
|
|
4455
|
-
col: 1
|
|
4456
|
-
}, errors, function reducer(acc, curr) {
|
|
4457
|
-
if (curr.typ == exports.EnumToken.CommentTokenType && options.removeComments) {
|
|
4458
|
-
if (!options.preserveLicense || !curr.val.startsWith('/*!')) {
|
|
4459
|
-
return acc;
|
|
4460
|
-
}
|
|
4461
|
-
return acc + curr.val;
|
|
4462
|
-
}
|
|
4463
|
-
return acc + renderToken(curr, options, cache, reducer, errors);
|
|
4464
|
-
}, cache), errors, stats: {
|
|
4465
|
-
total: `${(performance.now() - startTime).toFixed(2)}ms`
|
|
4466
|
-
}
|
|
4467
|
-
};
|
|
4468
|
-
if (options.output != null) {
|
|
4469
|
-
// @ts-ignore
|
|
4470
|
-
options.output = options.resolve(options.output, options.cwd).absolute;
|
|
4471
|
-
}
|
|
4472
|
-
if (sourcemap != null) {
|
|
4473
|
-
result.map = sourcemap;
|
|
4474
|
-
if (options.sourcemap === 'inline') {
|
|
4475
|
-
result.code += `\n/*# sourceMappingURL=data:application/json,${encodeURIComponent(JSON.stringify(result.map))} */`;
|
|
4476
|
-
}
|
|
4477
|
-
}
|
|
4478
|
-
return result;
|
|
4479
|
-
}
|
|
4480
|
-
function updateSourceMap(node, options, cache, sourcemap, position, str) {
|
|
4481
|
-
if ([
|
|
4482
|
-
exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType,
|
|
4483
|
-
exports.EnumToken.KeyFrameRuleNodeType, exports.EnumToken.KeyframeAtRuleNodeType
|
|
4484
|
-
].includes(node.typ)) {
|
|
4485
|
-
let src = node.loc?.src ?? '';
|
|
4486
|
-
let output = options.output ?? '';
|
|
4487
|
-
if (!(src in cache)) {
|
|
4488
|
-
// @ts-ignore
|
|
4489
|
-
cache[src] = options.resolve(src, options.cwd ?? '').relative;
|
|
4490
|
-
}
|
|
4491
|
-
if (!(output in cache)) {
|
|
4492
|
-
// @ts-ignore
|
|
4493
|
-
cache[output] = options.resolve(output, options.cwd).relative;
|
|
4494
|
-
}
|
|
4495
|
-
// @ts-ignore
|
|
4496
|
-
sourcemap.add({ src: cache[output], sta: { ...position } }, {
|
|
4497
|
-
...node.loc,
|
|
4498
|
-
// @ts-ignore
|
|
4499
|
-
src: options.resolve(cache[src], options.cwd).relative
|
|
4500
|
-
});
|
|
4501
|
-
}
|
|
4502
|
-
update(position, str);
|
|
4503
|
-
}
|
|
4504
|
-
/**
|
|
4505
|
-
* render ast node
|
|
4506
|
-
* @param data
|
|
4507
|
-
* @param options
|
|
4508
|
-
* @param sourcemap
|
|
4509
|
-
* @param position
|
|
4510
|
-
* @param errors
|
|
4511
|
-
* @param reducer
|
|
4512
|
-
* @param cache
|
|
4513
|
-
* @param level
|
|
4514
|
-
* @param indents
|
|
4515
|
-
*/
|
|
4516
|
-
function renderAstNode(data, options, sourcemap, position, errors, reducer, cache, level = 0, indents = []) {
|
|
4517
|
-
if (indents.length < level + 1) {
|
|
4518
|
-
indents.push(options.indent.repeat(level));
|
|
4519
|
-
}
|
|
4520
|
-
if (indents.length < level + 2) {
|
|
4521
|
-
indents.push(options.indent.repeat(level + 1));
|
|
4522
|
-
}
|
|
4523
|
-
const indent = indents[level];
|
|
4524
|
-
const indentSub = indents[level + 1];
|
|
4525
|
-
switch (data.typ) {
|
|
4526
|
-
case exports.EnumToken.DeclarationNodeType:
|
|
4527
|
-
return `${data.nam}:${options.indent}${(options.minify ? filterValues(data.val) : data.val).reduce(reducer, '')}`;
|
|
4528
|
-
case exports.EnumToken.CommentNodeType:
|
|
4529
|
-
case exports.EnumToken.CDOCOMMNodeType:
|
|
4530
|
-
if (data.val.startsWith('/*# sourceMappingURL=')) {
|
|
4531
|
-
// ignore sourcemap
|
|
4532
|
-
return '';
|
|
4533
|
-
}
|
|
4534
|
-
return !options.removeComments || (options.preserveLicense && data.val.startsWith('/*!')) ? data.val : '';
|
|
4535
|
-
case exports.EnumToken.StyleSheetNodeType:
|
|
4536
|
-
return data.chi.reduce((css, node) => {
|
|
4537
|
-
const str = renderAstNode(node, options, sourcemap, { ...position }, errors, reducer, cache, level, indents);
|
|
4538
|
-
if (str === '') {
|
|
4539
|
-
return css;
|
|
4540
|
-
}
|
|
4541
|
-
if (css === '') {
|
|
4542
|
-
if (sourcemap != null && node.loc != null) {
|
|
4543
|
-
updateSourceMap(node, options, cache, sourcemap, position, str);
|
|
4544
|
-
}
|
|
4545
|
-
return str;
|
|
4546
|
-
}
|
|
4547
|
-
if (sourcemap != null && node.loc != null) {
|
|
4548
|
-
update(position, options.newLine);
|
|
4549
|
-
updateSourceMap(node, options, cache, sourcemap, position, str);
|
|
4550
|
-
}
|
|
4551
|
-
return `${css}${options.newLine}${str}`;
|
|
4552
|
-
}, '');
|
|
4553
|
-
case exports.EnumToken.AtRuleNodeType:
|
|
4554
|
-
case exports.EnumToken.RuleNodeType:
|
|
4555
|
-
case exports.EnumToken.KeyFrameRuleNodeType:
|
|
4556
|
-
case exports.EnumToken.KeyframeAtRuleNodeType:
|
|
4557
|
-
if ([exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyframeAtRuleNodeType].includes(data.typ) && !('chi' in data)) {
|
|
4558
|
-
return `${indent}@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val};`;
|
|
4559
|
-
}
|
|
4560
|
-
// @ts-ignore
|
|
4561
|
-
let children = data.chi.reduce((css, node) => {
|
|
4562
|
-
let str;
|
|
4563
|
-
if (node.typ == exports.EnumToken.CommentNodeType) {
|
|
4564
|
-
str = options.removeComments && (!options.preserveLicense || !node.val.startsWith('/*!')) ? '' : node.val;
|
|
4565
|
-
}
|
|
4566
|
-
else if (node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
4567
|
-
if (!node.nam.startsWith('--') && node.val.length == 0) {
|
|
4568
|
-
// @ts-ignore
|
|
4569
|
-
errors.push({
|
|
4570
|
-
action: 'ignore',
|
|
4571
|
-
message: `render: invalid declaration ${JSON.stringify(node)}`,
|
|
4572
|
-
location: node.loc
|
|
4573
|
-
});
|
|
4574
|
-
return '';
|
|
4575
|
-
}
|
|
4576
|
-
str = `${node.nam}:${options.indent}${(options.minify ? filterValues(node.val) : node.val).reduce(reducer, '').trimEnd()};`;
|
|
4577
|
-
}
|
|
4578
|
-
else if (node.typ == exports.EnumToken.AtRuleNodeType && !('chi' in node)) {
|
|
4579
|
-
str = `${data.val === '' ? '' : options.indent || ' '}${data.val};`;
|
|
4580
|
-
}
|
|
4581
|
-
else {
|
|
4582
|
-
str = renderAstNode(node, options, sourcemap, { ...position }, errors, reducer, cache, level + 1, indents);
|
|
4583
|
-
}
|
|
4584
|
-
if (css === '') {
|
|
4585
|
-
return str;
|
|
4586
|
-
}
|
|
4587
|
-
if (str === '') {
|
|
4588
|
-
return css;
|
|
4589
|
-
}
|
|
4590
|
-
return `${css}${options.newLine}${indentSub}${str}`;
|
|
4591
|
-
}, '');
|
|
4592
|
-
if (options.removeEmpty && children === '') {
|
|
4593
|
-
return '';
|
|
4594
|
-
}
|
|
4595
|
-
if (children.endsWith(';')) {
|
|
4596
|
-
children = children.slice(0, -1);
|
|
4597
|
-
}
|
|
4598
|
-
if ([exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyframeAtRuleNodeType].includes(data.typ)) {
|
|
4599
|
-
return `@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val}${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
|
|
4600
|
-
}
|
|
4601
|
-
return data.sel + `${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
|
|
4602
|
-
case exports.EnumToken.InvalidDeclarationNodeType:
|
|
4603
|
-
case exports.EnumToken.InvalidRuleTokenType:
|
|
4604
|
-
case exports.EnumToken.InvalidAtRuleTokenType:
|
|
4605
|
-
default:
|
|
4606
|
-
return '';
|
|
4607
|
-
}
|
|
4608
|
-
}
|
|
4609
|
-
/**
|
|
4610
|
-
* render ast token
|
|
4611
|
-
* @param token
|
|
4612
|
-
* @param options
|
|
4613
|
-
* @param cache
|
|
4614
|
-
* @param reducer
|
|
4615
|
-
* @param errors
|
|
4616
|
-
*/
|
|
4617
|
-
function renderToken(token, options = {}, cache = Object.create(null), reducer, errors) {
|
|
4618
|
-
if (reducer == null) {
|
|
4619
|
-
reducer = function (acc, curr) {
|
|
4620
|
-
if (curr.typ == exports.EnumToken.CommentTokenType && options.removeComments) {
|
|
4621
|
-
if (!options.preserveLicense || !curr.val.startsWith('/*!')) {
|
|
4622
|
-
return acc;
|
|
4623
|
-
}
|
|
4624
|
-
return acc + curr.val;
|
|
4625
|
-
}
|
|
4626
|
-
return acc + renderToken(curr, options, cache, reducer, errors);
|
|
4627
|
-
};
|
|
4628
|
-
}
|
|
4629
|
-
if (token.typ == exports.EnumToken.FunctionTokenType && colorsFunc.includes(token.val)) {
|
|
4630
|
-
if (isColor(token)) {
|
|
4631
|
-
// @ts-ignore
|
|
4632
|
-
token.typ = exports.EnumToken.ColorTokenType;
|
|
4633
|
-
// @ts-ignore
|
|
4634
|
-
if (token.chi[0].typ == exports.EnumToken.IdenTokenType && token.chi[0].val == 'from') {
|
|
4635
|
-
// @ts-ignore
|
|
4636
|
-
token.cal = 'rel';
|
|
4637
|
-
}
|
|
4638
|
-
else { // @ts-ignore
|
|
4639
|
-
if (token.val == 'color-mix' && token.chi[0].typ == exports.EnumToken.IdenTokenType && token.chi[0].val == 'in') {
|
|
4640
|
-
// @ts-ignore
|
|
4641
|
-
token.cal = 'mix';
|
|
4642
|
-
}
|
|
4643
|
-
else {
|
|
4644
|
-
// @ts-ignore
|
|
4645
|
-
if (token.val == 'color') {
|
|
4646
|
-
// @ts-ignore
|
|
4647
|
-
token.cal = 'col';
|
|
4648
|
-
}
|
|
4649
|
-
// @ts-ignore
|
|
4650
|
-
token.chi = token.chi.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommaTokenType, exports.EnumToken.CommentTokenType].includes(t.typ));
|
|
4651
|
-
}
|
|
4652
|
-
}
|
|
4653
|
-
}
|
|
4654
|
-
}
|
|
4655
|
-
switch (token.typ) {
|
|
4656
|
-
case exports.EnumToken.ListToken:
|
|
4657
|
-
return token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
4658
|
-
case exports.EnumToken.BinaryExpressionTokenType:
|
|
4659
|
-
if ([exports.EnumToken.Mul, exports.EnumToken.Div].includes(token.op)) {
|
|
4660
|
-
let result = '';
|
|
4661
|
-
if (token.l.typ == exports.EnumToken.BinaryExpressionTokenType &&
|
|
4662
|
-
[exports.EnumToken.Add, exports.EnumToken.Sub].includes(token.l.op)) {
|
|
4663
|
-
result = '(' + renderToken(token.l, options, cache) + ')';
|
|
4664
|
-
}
|
|
4665
|
-
else {
|
|
4666
|
-
result = renderToken(token.l, options, cache);
|
|
4667
|
-
}
|
|
4668
|
-
result += token.op == exports.EnumToken.Mul ? '*' : '/';
|
|
4669
|
-
if (token.r.typ == exports.EnumToken.BinaryExpressionTokenType &&
|
|
4670
|
-
[exports.EnumToken.Add, exports.EnumToken.Sub].includes(token.r.op)) {
|
|
4671
|
-
result += '(' + renderToken(token.r, options, cache) + ')';
|
|
4672
|
-
}
|
|
4673
|
-
else {
|
|
4674
|
-
result += renderToken(token.r, options, cache);
|
|
4675
|
-
}
|
|
4676
|
-
return result;
|
|
4677
|
-
}
|
|
4678
|
-
return renderToken(token.l, options, cache) + (token.op == exports.EnumToken.Add ? ' + ' : (token.op == exports.EnumToken.Sub ? ' - ' : (token.op == exports.EnumToken.Mul ? '*' : '/'))) + renderToken(token.r, options, cache);
|
|
4679
|
-
case exports.EnumToken.FractionTokenType:
|
|
4680
|
-
const fraction = renderToken(token.l) + '/' + renderToken(token.r);
|
|
4681
|
-
if (+token.r.val != 0) {
|
|
4682
|
-
const value = minifyNumber(+token.l.val / +token.r.val);
|
|
4683
|
-
if (value.length <= fraction.length) {
|
|
4684
|
-
return value;
|
|
4685
|
-
}
|
|
4686
|
-
}
|
|
4687
|
-
return fraction;
|
|
4688
|
-
case exports.EnumToken.Add:
|
|
4689
|
-
return ' + ';
|
|
4690
|
-
case exports.EnumToken.Sub:
|
|
4691
|
-
return ' - ';
|
|
4692
|
-
case exports.EnumToken.UniversalSelectorTokenType:
|
|
4693
|
-
case exports.EnumToken.Mul:
|
|
4694
|
-
return '*';
|
|
4695
|
-
case exports.EnumToken.Div:
|
|
4696
|
-
return '/';
|
|
4697
|
-
case exports.EnumToken.ColorTokenType:
|
|
4698
|
-
if (token.kin == exports.ColorType.LIGHT_DARK || ('chi' in token && options.convertColor === false)) {
|
|
4699
|
-
return token.val + '(' + token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache), '') + ')';
|
|
4700
|
-
}
|
|
4701
|
-
if (options.convertColor !== false) {
|
|
4702
|
-
const value = convertColor(token, typeof options.convertColor == 'boolean' ? exports.ColorType.HEX : exports.ColorType[exports.ColorType[options.convertColor ?? 'HEX']?.toUpperCase?.().replaceAll?.('-', '_')] ?? exports.ColorType.HEX);
|
|
4703
|
-
//
|
|
4704
|
-
if (value != null) {
|
|
4705
|
-
token = value;
|
|
4706
|
-
}
|
|
4707
|
-
}
|
|
4708
|
-
if ([exports.ColorType.HEX, exports.ColorType.LIT, exports.ColorType.SYS, exports.ColorType.DPSYS].includes(token.kin)) {
|
|
4709
|
-
return token.val;
|
|
4710
|
-
}
|
|
4711
|
-
if (Array.isArray(token.chi)) {
|
|
4712
|
-
const isLegacy = ['rgb', 'rgba', 'hsl', 'hsla'].includes(token.val.toLowerCase());
|
|
4713
|
-
const useAlpha = (['rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'oklab', 'oklch', 'lab', 'lch'].includes(token.val.toLowerCase()) && token.chi.length == 4) ||
|
|
4714
|
-
('color' == token.val.toLowerCase() && token.chi.length == 5);
|
|
4715
|
-
return (token.val.endsWith('a') ? token.val.slice(0, -1) : token.val) + '(' + token.chi.reduce((acc, curr, index, array) => {
|
|
4716
|
-
if (/[,/]\s*$/.test(acc)) {
|
|
4717
|
-
if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
4718
|
-
return acc.trimEnd();
|
|
4719
|
-
}
|
|
4720
|
-
return acc.trimStart() + renderToken(curr, options, cache);
|
|
4721
|
-
}
|
|
4722
|
-
if (isLegacy && curr.typ == exports.EnumToken.CommaTokenType) {
|
|
4723
|
-
return acc.trimEnd() + ' ';
|
|
4724
|
-
}
|
|
4725
|
-
if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
4726
|
-
return acc.trimEnd() + ' ';
|
|
4727
|
-
}
|
|
4728
|
-
if (curr.typ == exports.EnumToken.CommaTokenType || (curr.typ == exports.EnumToken.LiteralTokenType && curr.val == '/')) {
|
|
4729
|
-
return acc.trimEnd() + (curr.typ == exports.EnumToken.CommaTokenType ? ',' : '/');
|
|
4730
|
-
}
|
|
4731
|
-
return acc.trimEnd() + (useAlpha && index == array.length - 1 ? '/' : ' ') + renderToken(curr, options, cache);
|
|
4732
|
-
}, '').trimStart() + ')';
|
|
4733
|
-
}
|
|
4734
|
-
case exports.EnumToken.ParensTokenType:
|
|
4735
|
-
case exports.EnumToken.FunctionTokenType:
|
|
4736
|
-
case exports.EnumToken.UrlFunctionTokenType:
|
|
4737
|
-
case exports.EnumToken.ImageFunctionTokenType:
|
|
4738
|
-
case exports.EnumToken.TimingFunctionTokenType:
|
|
4739
|
-
case exports.EnumToken.PseudoClassFuncTokenType:
|
|
4740
|
-
case exports.EnumToken.TimelineFunctionTokenType:
|
|
4741
|
-
case exports.EnumToken.GridTemplateFuncTokenType:
|
|
4742
|
-
if (token.typ == exports.EnumToken.FunctionTokenType &&
|
|
4743
|
-
mathFuncs.includes(token.val) &&
|
|
4744
|
-
token.chi.length == 1 &&
|
|
4745
|
-
![exports.EnumToken.BinaryExpressionTokenType, exports.EnumToken.FractionTokenType, exports.EnumToken.IdenTokenType].includes(token.chi[0].typ) &&
|
|
4746
|
-
// @ts-ignore
|
|
4747
|
-
token.chi[0].val?.typ != exports.EnumToken.FractionTokenType) {
|
|
4748
|
-
return token.val + '(' + token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache, reducer), '') + ')';
|
|
4749
|
-
}
|
|
4750
|
-
return ( /* options.minify && 'Pseudo-class-func' == token.typ && token.val.slice(0, 2) == '::' ? token.val.slice(1) :*/token.val ?? '') + '(' + token.chi.reduce(reducer, '') + ')';
|
|
4751
|
-
case exports.EnumToken.MatchExpressionTokenType:
|
|
4752
|
-
return renderToken(token.l, options, cache, reducer, errors) +
|
|
4753
|
-
renderToken(token.op, options, cache, reducer, errors) +
|
|
4754
|
-
renderToken(token.r, options, cache, reducer, errors) +
|
|
4755
|
-
(token.attr ? ' ' + token.attr : '');
|
|
4756
|
-
case exports.EnumToken.NameSpaceAttributeTokenType:
|
|
4757
|
-
return (token.l == null ? '' : renderToken(token.l, options, cache, reducer, errors)) + '|' +
|
|
4758
|
-
renderToken(token.r, options, cache, reducer, errors);
|
|
4759
|
-
case exports.EnumToken.BlockStartTokenType:
|
|
4760
|
-
return '{';
|
|
4761
|
-
case exports.EnumToken.BlockEndTokenType:
|
|
4762
|
-
return '}';
|
|
4763
|
-
case exports.EnumToken.StartParensTokenType:
|
|
4764
|
-
return '(';
|
|
4765
|
-
case exports.EnumToken.DelimTokenType:
|
|
4766
|
-
case exports.EnumToken.EqualMatchTokenType:
|
|
4767
|
-
return '=';
|
|
4768
|
-
case exports.EnumToken.IncludeMatchTokenType:
|
|
4769
|
-
return '~=';
|
|
4770
|
-
case exports.EnumToken.DashMatchTokenType:
|
|
4771
|
-
return '|=';
|
|
4772
|
-
case exports.EnumToken.StartMatchTokenType:
|
|
4773
|
-
return '^=';
|
|
4774
|
-
case exports.EnumToken.EndMatchTokenType:
|
|
4775
|
-
return '$=';
|
|
4776
|
-
case exports.EnumToken.ContainMatchTokenType:
|
|
4777
|
-
return '*=';
|
|
4778
|
-
case exports.EnumToken.LtTokenType:
|
|
4779
|
-
return '<';
|
|
4780
|
-
case exports.EnumToken.LteTokenType:
|
|
4781
|
-
return '<=';
|
|
4782
|
-
case exports.EnumToken.SubsequentSiblingCombinatorTokenType:
|
|
4783
|
-
return '~';
|
|
4784
|
-
case exports.EnumToken.NextSiblingCombinatorTokenType:
|
|
4785
|
-
return '+';
|
|
4786
|
-
case exports.EnumToken.GtTokenType:
|
|
4787
|
-
case exports.EnumToken.ChildCombinatorTokenType:
|
|
4788
|
-
return '>';
|
|
4789
|
-
case exports.EnumToken.GteTokenType:
|
|
4790
|
-
return '>=';
|
|
4791
|
-
case exports.EnumToken.ColumnCombinatorTokenType:
|
|
4792
|
-
return '||';
|
|
4793
|
-
case exports.EnumToken.EndParensTokenType:
|
|
4794
|
-
return ')';
|
|
4795
|
-
case exports.EnumToken.AttrStartTokenType:
|
|
4796
|
-
return '[';
|
|
4797
|
-
case exports.EnumToken.AttrEndTokenType:
|
|
4798
|
-
return ']';
|
|
4799
|
-
case exports.EnumToken.DescendantCombinatorTokenType:
|
|
4800
|
-
case exports.EnumToken.WhitespaceTokenType:
|
|
4801
|
-
return ' ';
|
|
4802
|
-
case exports.EnumToken.ColonTokenType:
|
|
4803
|
-
return ':';
|
|
4804
|
-
case exports.EnumToken.SemiColonTokenType:
|
|
4805
|
-
return ';';
|
|
4806
|
-
case exports.EnumToken.CommaTokenType:
|
|
4807
|
-
return ',';
|
|
4808
|
-
case exports.EnumToken.ImportantTokenType:
|
|
4809
|
-
return '!important';
|
|
4810
|
-
case exports.EnumToken.AttrTokenType:
|
|
4811
|
-
case exports.EnumToken.IdenListTokenType:
|
|
4812
|
-
return '[' + token.chi.reduce(reducer, '') + ']';
|
|
4813
|
-
case exports.EnumToken.TimeTokenType:
|
|
4814
|
-
case exports.EnumToken.AngleTokenType:
|
|
4815
|
-
case exports.EnumToken.LengthTokenType:
|
|
4816
|
-
case exports.EnumToken.DimensionTokenType:
|
|
4817
|
-
case exports.EnumToken.FrequencyTokenType:
|
|
4818
|
-
case exports.EnumToken.ResolutionTokenType:
|
|
4819
|
-
let val = token.val.typ == exports.EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : minifyNumber(token.val);
|
|
4820
|
-
let unit = token.unit;
|
|
4821
|
-
if (token.typ == exports.EnumToken.AngleTokenType && !val.includes('/')) {
|
|
4822
|
-
const angle = getAngle(token);
|
|
4823
|
-
let v;
|
|
4824
|
-
let value = val + unit;
|
|
4825
|
-
for (const u of ['turn', 'deg', 'rad', 'grad']) {
|
|
4826
|
-
if (token.unit == u) {
|
|
4827
|
-
continue;
|
|
4828
|
-
}
|
|
4829
|
-
switch (u) {
|
|
4830
|
-
case 'turn':
|
|
4831
|
-
v = minifyNumber(angle);
|
|
4832
|
-
if (v.length + 4 < value.length) {
|
|
4833
|
-
val = v;
|
|
4834
|
-
unit = u;
|
|
4835
|
-
value = v + u;
|
|
4836
|
-
}
|
|
4837
|
-
break;
|
|
4838
|
-
case 'deg':
|
|
4839
|
-
v = minifyNumber(angle * 360);
|
|
4840
|
-
if (v.length + 3 < value.length) {
|
|
4841
|
-
val = v;
|
|
4842
|
-
unit = u;
|
|
4843
|
-
value = v + u;
|
|
4844
|
-
}
|
|
4845
|
-
break;
|
|
4846
|
-
case 'rad':
|
|
4847
|
-
v = minifyNumber(angle * (2 * Math.PI));
|
|
4848
|
-
if (v.length + 3 < value.length) {
|
|
4849
|
-
val = v;
|
|
4850
|
-
unit = u;
|
|
4851
|
-
value = v + u;
|
|
4852
|
-
}
|
|
4853
|
-
break;
|
|
4854
|
-
case 'grad':
|
|
4855
|
-
v = minifyNumber(angle * 400);
|
|
4856
|
-
if (v.length + 4 < value.length) {
|
|
4857
|
-
val = v;
|
|
4858
|
-
unit = u;
|
|
4859
|
-
value = v + u;
|
|
4860
|
-
}
|
|
4861
|
-
break;
|
|
4862
|
-
}
|
|
4863
|
-
}
|
|
4864
|
-
}
|
|
4865
|
-
if (val === '0') {
|
|
4866
|
-
if (token.typ == exports.EnumToken.TimeTokenType) {
|
|
4867
|
-
return '0s';
|
|
4868
|
-
}
|
|
4869
|
-
if (token.typ == exports.EnumToken.FrequencyTokenType) {
|
|
4870
|
-
return '0Hz';
|
|
4871
|
-
}
|
|
4872
|
-
// @ts-ignore
|
|
4873
|
-
if (token.typ == exports.EnumToken.ResolutionTokenType) {
|
|
4874
|
-
return '0x';
|
|
4875
|
-
}
|
|
4876
|
-
return '0';
|
|
4877
|
-
}
|
|
4878
|
-
if (token.typ == exports.EnumToken.TimeTokenType) {
|
|
4879
|
-
if (unit == 'ms') {
|
|
4880
|
-
// @ts-ignore
|
|
4881
|
-
const v = minifyNumber(val / 1000);
|
|
4882
|
-
if (v.length + 1 <= val.length) {
|
|
4883
|
-
return v + 's';
|
|
4884
|
-
}
|
|
4885
|
-
return val + 'ms';
|
|
4886
|
-
}
|
|
4887
|
-
return val + 's';
|
|
4888
|
-
}
|
|
4889
|
-
if (token.typ == exports.EnumToken.ResolutionTokenType && unit == 'dppx') {
|
|
4890
|
-
unit = 'x';
|
|
4891
|
-
}
|
|
4892
|
-
return val.includes('/') ? val.replace('/', unit + '/') : val + unit;
|
|
4893
|
-
case exports.EnumToken.FlexTokenType:
|
|
4894
|
-
case exports.EnumToken.PercentageTokenType:
|
|
4895
|
-
const uni = token.typ == exports.EnumToken.PercentageTokenType ? '%' : 'fr';
|
|
4896
|
-
const perc = token.val.typ == exports.EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : minifyNumber(token.val);
|
|
4897
|
-
return options.minify && perc == '0' ? '0' : (perc.includes('/') ? perc.replace('/', uni + '/') : perc + uni);
|
|
4898
|
-
case exports.EnumToken.NumberTokenType:
|
|
4899
|
-
return token.val.typ == exports.EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : minifyNumber(token.val);
|
|
4900
|
-
case exports.EnumToken.CommentTokenType:
|
|
4901
|
-
if (options.removeComments && (!options.preserveLicense || !token.val.startsWith('/*!'))) {
|
|
4902
|
-
return '';
|
|
4903
|
-
}
|
|
4904
|
-
case exports.EnumToken.PseudoClassTokenType:
|
|
4905
|
-
case exports.EnumToken.PseudoElementTokenType:
|
|
4906
|
-
// https://www.w3.org/TR/selectors-4/#single-colon-pseudos
|
|
4907
|
-
if (token.typ == exports.EnumToken.PseudoElementTokenType && pseudoElements.includes(token.val.slice(1))) {
|
|
4908
|
-
return token.val.slice(1);
|
|
4909
|
-
}
|
|
4910
|
-
case exports.EnumToken.UrlTokenTokenType:
|
|
4911
|
-
// if (token.typ == EnumToken.UrlTokenTokenType) {
|
|
4912
|
-
//
|
|
4913
|
-
// if (options.output != null) {
|
|
4914
|
-
//
|
|
4915
|
-
// if (!('original' in token)) {
|
|
4916
|
-
//
|
|
4917
|
-
// // do not modify original token
|
|
4918
|
-
// token = {...token};
|
|
4919
|
-
// Object.defineProperty(token, 'original', {
|
|
4920
|
-
// enumerable: false,
|
|
4921
|
-
// writable: false,
|
|
4922
|
-
// value: (token as UrlToken).val
|
|
4923
|
-
// })
|
|
4924
|
-
// }
|
|
4925
|
-
//
|
|
4926
|
-
// // @ts-ignore
|
|
4927
|
-
// if (!(token.original in cache)) {
|
|
4928
|
-
//
|
|
4929
|
-
// let output: string = <string>options.output ?? '';
|
|
4930
|
-
// const key = output + 'abs';
|
|
4931
|
-
//
|
|
4932
|
-
// if (!(key in cache)) {
|
|
4933
|
-
//
|
|
4934
|
-
// // @ts-ignore
|
|
4935
|
-
// cache[key] = options.dirname(options.resolve(output, options.cwd).absolute);
|
|
4936
|
-
// }
|
|
4937
|
-
//
|
|
4938
|
-
// // @ts-ignore
|
|
4939
|
-
// cache[token.original] = options.resolve(token.original, cache[key]).relative;
|
|
4940
|
-
// }
|
|
4941
|
-
//
|
|
4942
|
-
// // @ts-ignore
|
|
4943
|
-
// token.val = cache[token.original];
|
|
4944
|
-
// }
|
|
4945
|
-
// }
|
|
4946
|
-
case exports.EnumToken.HashTokenType:
|
|
4947
|
-
case exports.EnumToken.IdenTokenType:
|
|
4948
|
-
case exports.EnumToken.AtRuleTokenType:
|
|
4949
|
-
case exports.EnumToken.StringTokenType:
|
|
4950
|
-
case exports.EnumToken.LiteralTokenType:
|
|
4951
|
-
case exports.EnumToken.DashedIdenTokenType:
|
|
4952
|
-
case exports.EnumToken.PseudoPageTokenType:
|
|
4953
|
-
case exports.EnumToken.ClassSelectorTokenType:
|
|
4954
|
-
return /* options.minify && 'Pseudo-class' == token.typ && '::' == token.val.slice(0, 2) ? token.val.slice(1) : */ token.val;
|
|
4955
|
-
case exports.EnumToken.NestingSelectorTokenType:
|
|
4956
|
-
return '&';
|
|
4957
|
-
case exports.EnumToken.InvalidAttrTokenType:
|
|
4958
|
-
return '[' + token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
4959
|
-
case exports.EnumToken.InvalidClassSelectorTokenType:
|
|
4960
|
-
return token.val;
|
|
4961
|
-
case exports.EnumToken.DeclarationNodeType:
|
|
4962
|
-
return token.nam + ':' + (options.minify ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
4963
|
-
case exports.EnumToken.MediaQueryConditionTokenType:
|
|
4964
|
-
return renderToken(token.l, options, cache, reducer, errors) + renderToken(token.op, options, cache, reducer, errors) + token.r.reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
4965
|
-
case exports.EnumToken.MediaFeatureTokenType:
|
|
4966
|
-
return token.val;
|
|
4967
|
-
case exports.EnumToken.MediaFeatureNotTokenType:
|
|
4968
|
-
return 'not ' + renderToken(token.val, options, cache, reducer, errors);
|
|
4969
|
-
case exports.EnumToken.MediaFeatureOnlyTokenType:
|
|
4970
|
-
return 'only ' + renderToken(token.val, options, cache, reducer, errors);
|
|
4971
|
-
case exports.EnumToken.MediaFeatureAndTokenType:
|
|
4972
|
-
return 'and';
|
|
4973
|
-
case exports.EnumToken.MediaFeatureOrTokenType:
|
|
4974
|
-
return 'or';
|
|
4975
|
-
}
|
|
4976
|
-
errors?.push({ action: 'ignore', message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
|
|
4977
|
-
return '';
|
|
4978
|
-
}
|
|
4979
|
-
function filterValues(values) {
|
|
4980
|
-
let i = 0;
|
|
4981
|
-
for (; i < values.length; i++) {
|
|
4982
|
-
if (values[i].typ == exports.EnumToken.ImportantTokenType && values[i - 1]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
4983
|
-
values.splice(i - 1, 1);
|
|
4984
|
-
}
|
|
4985
|
-
else if (funcLike.includes(values[i].typ) && !['var', 'calc'].includes(values[i].val) && values[i + 1]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
4986
|
-
values.splice(i + 1, 1);
|
|
4987
|
-
}
|
|
4988
|
-
}
|
|
4989
|
-
return values;
|
|
4990
|
-
}
|
|
4991
|
-
|
|
4992
4682
|
// https://www.w3.org/TR/CSS21/syndata.html#syntax
|
|
4993
4683
|
// https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token
|
|
4994
4684
|
// '\\'
|
|
@@ -5002,6 +4692,11 @@
|
|
|
5002
4692
|
const fontFormat = ['collection', 'embedded-opentype', 'opentype', 'svg', 'truetype', 'woff', 'woff2'];
|
|
5003
4693
|
const colorFontTech = ['color-colrv0', 'color-colrv1', 'color-svg', 'color-sbix', 'color-cbdt'];
|
|
5004
4694
|
const fontFeaturesTech = ['features-opentype', 'features-aat', 'features-graphite', 'incremental-patch', 'incremental-range', 'incremental-auto', 'variations', 'palettes'];
|
|
4695
|
+
/**
|
|
4696
|
+
* supported transform functions
|
|
4697
|
+
*
|
|
4698
|
+
* @internal
|
|
4699
|
+
*/
|
|
5005
4700
|
const transformFunctions = [
|
|
5006
4701
|
'translate', 'scale', 'rotate', 'skew', 'perspective',
|
|
5007
4702
|
'translateX', 'translateY', 'translateZ',
|
|
@@ -5015,6 +4710,11 @@
|
|
|
5015
4710
|
/* deprecated */
|
|
5016
4711
|
'aural', 'braille', 'embossed', 'handheld', 'projection', 'tty', 'tv', 'speech'];
|
|
5017
4712
|
// https://www.w3.org/TR/css-values-4/#math-function
|
|
4713
|
+
/**
|
|
4714
|
+
* supported math functions
|
|
4715
|
+
*
|
|
4716
|
+
* @internal
|
|
4717
|
+
*/
|
|
5018
4718
|
const mathFuncs = ['minmax', 'repeat', 'fit-content', 'calc', 'clamp', 'min', 'max', 'round', 'mod', 'rem', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2', 'pow', 'sqrt', 'hypot', 'log', 'exp', 'abs', 'sign'];
|
|
5019
4719
|
const wildCardFuncs = ['var', 'env'];
|
|
5020
4720
|
const pseudoElements = [':before', ':after', ':first-line', ':first-letter'];
|
|
@@ -5521,7 +5221,7 @@
|
|
|
5521
5221
|
// adding numbers and percentages is disallowed
|
|
5522
5222
|
// https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/lch#defining_relative_color_output_channel_components
|
|
5523
5223
|
// @ts-ignore
|
|
5524
|
-
for (const { value } of walkValues(token.chi, null, (node) => funcLike.includes(node.typ) ? WalkerOptionEnum.IgnoreChildren : null)) {
|
|
5224
|
+
for (const { value } of walkValues(token.chi, null, (node) => funcLike.includes(node.typ) ? exports.WalkerOptionEnum.IgnoreChildren : null)) {
|
|
5525
5225
|
if (funcLike.includes(value.typ)) {
|
|
5526
5226
|
for (const { value: val } of walkValues([buildExpression(value.chi)])) {
|
|
5527
5227
|
if (val.typ == exports.EnumToken.BinaryExpressionTokenType &&
|
|
@@ -7464,89 +7164,831 @@
|
|
|
7464
7164
|
map: map
|
|
7465
7165
|
};
|
|
7466
7166
|
|
|
7467
|
-
Object.freeze(config$4);
|
|
7468
|
-
const getConfig = () => config$4;
|
|
7167
|
+
Object.freeze(config$4);
|
|
7168
|
+
const getConfig = () => config$4;
|
|
7169
|
+
|
|
7170
|
+
function matchType(val, properties) {
|
|
7171
|
+
if (val.typ == exports.EnumToken.IdenTokenType && properties.keywords.includes(val.val) ||
|
|
7172
|
+
// @ts-ignore
|
|
7173
|
+
(properties.types.some((t) => exports.EnumToken[t] == val.typ))) {
|
|
7174
|
+
return true;
|
|
7175
|
+
}
|
|
7176
|
+
if (val.typ == exports.EnumToken.NumberTokenType && val.val == 0) {
|
|
7177
|
+
// @ts-ignore
|
|
7178
|
+
return properties.types.some((type) => {
|
|
7179
|
+
// @ts-ignore
|
|
7180
|
+
const typ = exports.EnumToken[type];
|
|
7181
|
+
return typ == exports.EnumToken.LengthTokenType || typ == exports.EnumToken.AngleTokenType;
|
|
7182
|
+
});
|
|
7183
|
+
}
|
|
7184
|
+
if (val.typ == exports.EnumToken.FunctionTokenType) {
|
|
7185
|
+
if (mathFuncs.includes(val.val)) {
|
|
7186
|
+
return val.chi.every(((t) => [exports.EnumToken.Add, exports.EnumToken.Mul, exports.EnumToken.Div, exports.EnumToken.Sub, exports.EnumToken.LiteralTokenType, exports.EnumToken.CommaTokenType, exports.EnumToken.WhitespaceTokenType, exports.EnumToken.DimensionTokenType, exports.EnumToken.NumberTokenType, exports.EnumToken.LengthTokenType, exports.EnumToken.AngleTokenType, exports.EnumToken.PercentageTokenType, exports.EnumToken.ResolutionTokenType, exports.EnumToken.TimeTokenType, exports.EnumToken.BinaryExpressionTokenType].includes(t.typ) || matchType(t, properties)));
|
|
7187
|
+
}
|
|
7188
|
+
// match type defined like function 'symbols()', 'url()', 'attr()' etc.
|
|
7189
|
+
// return properties.types.includes((<FunctionToken>val).val + '()')
|
|
7190
|
+
}
|
|
7191
|
+
return false;
|
|
7192
|
+
}
|
|
7193
|
+
|
|
7194
|
+
function parseDeclarationNode(node, errors, location) {
|
|
7195
|
+
while (node.val[0]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
7196
|
+
node.val.shift();
|
|
7197
|
+
}
|
|
7198
|
+
if (!node.nam.startsWith('--') && node.val.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ)).length == 0) {
|
|
7199
|
+
errors.push({
|
|
7200
|
+
action: 'drop',
|
|
7201
|
+
message: 'doParse: invalid declaration',
|
|
7202
|
+
location
|
|
7203
|
+
});
|
|
7204
|
+
return null;
|
|
7205
|
+
}
|
|
7206
|
+
for (const { value: val, parent } of walkValues(node.val, node)) {
|
|
7207
|
+
if (val.typ == exports.EnumToken.AttrTokenType && val.chi.every((t) => [exports.EnumToken.IdenTokenType, exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType].includes(t.typ))) {
|
|
7208
|
+
// @ts-ignore
|
|
7209
|
+
val.typ = exports.EnumToken.IdenListTokenType;
|
|
7210
|
+
}
|
|
7211
|
+
else if (val.typ == exports.EnumToken.StringTokenType && (node.nam == 'grid' || node.nam == 'grid-template-areas' || node.nam == 'grid-template-rows' || node.nam == 'grid-template-columns')) {
|
|
7212
|
+
val.val = val.val.at(0) + parseGridTemplate(val.val.slice(1, -1)) + val.val.at(-1);
|
|
7213
|
+
// @ts-ignore
|
|
7214
|
+
const array = parent?.chi ?? node.val;
|
|
7215
|
+
const index = array.indexOf(val);
|
|
7216
|
+
if (index > 0 && array[index - 1].typ == exports.EnumToken.WhitespaceTokenType) {
|
|
7217
|
+
array.splice(index - 1, 1);
|
|
7218
|
+
}
|
|
7219
|
+
}
|
|
7220
|
+
}
|
|
7221
|
+
return node;
|
|
7222
|
+
}
|
|
7223
|
+
function parseGridTemplate(template) {
|
|
7224
|
+
let result = '';
|
|
7225
|
+
let buffer = '';
|
|
7226
|
+
for (let i = 0; i < template.length; i++) {
|
|
7227
|
+
const char = template[i];
|
|
7228
|
+
if (isWhiteSpace(char.codePointAt(0))) {
|
|
7229
|
+
while (i + 1 < template.length && isWhiteSpace(template[i + 1].codePointAt(0))) {
|
|
7230
|
+
i++;
|
|
7231
|
+
}
|
|
7232
|
+
result += buffer + ' ';
|
|
7233
|
+
buffer = '';
|
|
7234
|
+
}
|
|
7235
|
+
else if (char == '.') {
|
|
7236
|
+
while (i + 1 < template.length && template[i + 1] == '.') {
|
|
7237
|
+
i++;
|
|
7238
|
+
}
|
|
7239
|
+
if (isWhiteSpace((result.at(-1)?.codePointAt(0)))) {
|
|
7240
|
+
result = result.slice(0, -1);
|
|
7241
|
+
}
|
|
7242
|
+
result += buffer + char;
|
|
7243
|
+
buffer = '';
|
|
7244
|
+
}
|
|
7245
|
+
else {
|
|
7246
|
+
buffer += char;
|
|
7247
|
+
}
|
|
7248
|
+
}
|
|
7249
|
+
return buffer.length > 0 ? result + buffer : result;
|
|
7250
|
+
}
|
|
7251
|
+
|
|
7252
|
+
// from https://github.com/Rich-Harris/vlq/tree/master
|
|
7253
|
+
// credit: Rich Harris
|
|
7254
|
+
const integer_to_char = {};
|
|
7255
|
+
let i = 0;
|
|
7256
|
+
for (const char of 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=') {
|
|
7257
|
+
integer_to_char[i++] = char;
|
|
7258
|
+
}
|
|
7259
|
+
function encode(value) {
|
|
7260
|
+
if (typeof value === 'number') {
|
|
7261
|
+
return encode_integer(value);
|
|
7262
|
+
}
|
|
7263
|
+
let result = '';
|
|
7264
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
7265
|
+
result += encode_integer(value[i]);
|
|
7266
|
+
}
|
|
7267
|
+
return result;
|
|
7268
|
+
}
|
|
7269
|
+
function encode_integer(num) {
|
|
7270
|
+
let result = '';
|
|
7271
|
+
if (num < 0) {
|
|
7272
|
+
num = (-num << 1) | 1;
|
|
7273
|
+
}
|
|
7274
|
+
else {
|
|
7275
|
+
num <<= 1;
|
|
7276
|
+
}
|
|
7277
|
+
do {
|
|
7278
|
+
let clamped = num & 31;
|
|
7279
|
+
num >>>= 5;
|
|
7280
|
+
if (num > 0) {
|
|
7281
|
+
clamped |= 32;
|
|
7282
|
+
}
|
|
7283
|
+
result += integer_to_char[clamped];
|
|
7284
|
+
} while (num > 0);
|
|
7285
|
+
return result;
|
|
7286
|
+
}
|
|
7287
|
+
|
|
7288
|
+
/**
|
|
7289
|
+
* Source map class
|
|
7290
|
+
* @internal
|
|
7291
|
+
*/
|
|
7292
|
+
class SourceMap {
|
|
7293
|
+
/**
|
|
7294
|
+
* Last location
|
|
7295
|
+
*/
|
|
7296
|
+
lastLocation = null;
|
|
7297
|
+
/**
|
|
7298
|
+
* Version
|
|
7299
|
+
* @private
|
|
7300
|
+
*/
|
|
7301
|
+
#version = 3;
|
|
7302
|
+
/**
|
|
7303
|
+
* Sources
|
|
7304
|
+
* @private
|
|
7305
|
+
*/
|
|
7306
|
+
#sources = [];
|
|
7307
|
+
/**
|
|
7308
|
+
* Map
|
|
7309
|
+
* @private
|
|
7310
|
+
*/
|
|
7311
|
+
#map = new Map;
|
|
7312
|
+
/**
|
|
7313
|
+
* Line
|
|
7314
|
+
* @private
|
|
7315
|
+
*/
|
|
7316
|
+
#line = -1;
|
|
7317
|
+
/**
|
|
7318
|
+
* Add a location
|
|
7319
|
+
* @param source
|
|
7320
|
+
* @param original
|
|
7321
|
+
*/
|
|
7322
|
+
add(source, original) {
|
|
7323
|
+
if (original.src !== '') {
|
|
7324
|
+
if (!this.#sources.includes(original.src)) {
|
|
7325
|
+
this.#sources.push(original.src);
|
|
7326
|
+
}
|
|
7327
|
+
const line = source.sta.lin - 1;
|
|
7328
|
+
let record;
|
|
7329
|
+
if (line > this.#line) {
|
|
7330
|
+
this.#line = line;
|
|
7331
|
+
}
|
|
7332
|
+
if (!this.#map.has(line)) {
|
|
7333
|
+
record = [Math.max(0, source.sta.col - 1), this.#sources.indexOf(original.src), original.sta.lin - 1, original.sta.col - 1];
|
|
7334
|
+
this.#map.set(line, [record]);
|
|
7335
|
+
}
|
|
7336
|
+
else {
|
|
7337
|
+
const arr = this.#map.get(line);
|
|
7338
|
+
record = [Math.max(0, source.sta.col - 1 - arr[0][0]), this.#sources.indexOf(original.src) - arr[0][1], original.sta.lin - 1, original.sta.col - 1];
|
|
7339
|
+
arr.push(record);
|
|
7340
|
+
}
|
|
7341
|
+
if (this.lastLocation != null) {
|
|
7342
|
+
record[2] -= this.lastLocation.sta.lin - 1;
|
|
7343
|
+
record[3] -= this.lastLocation.sta.col - 1;
|
|
7344
|
+
}
|
|
7345
|
+
this.lastLocation = original;
|
|
7346
|
+
}
|
|
7347
|
+
}
|
|
7348
|
+
/**
|
|
7349
|
+
* Convert to URL encoded string
|
|
7350
|
+
*/
|
|
7351
|
+
toUrl() {
|
|
7352
|
+
// /*# sourceMappingURL = ${url} */
|
|
7353
|
+
return `data:application/json,${encodeURIComponent(JSON.stringify(this.toJSON()))}`;
|
|
7354
|
+
}
|
|
7355
|
+
/**
|
|
7356
|
+
* Convert to JSON object
|
|
7357
|
+
*/
|
|
7358
|
+
toJSON() {
|
|
7359
|
+
const mappings = [];
|
|
7360
|
+
let i = 0;
|
|
7361
|
+
for (; i <= this.#line; i++) {
|
|
7362
|
+
if (!this.#map.has(i)) {
|
|
7363
|
+
mappings.push('');
|
|
7364
|
+
}
|
|
7365
|
+
else {
|
|
7366
|
+
mappings.push(this.#map.get(i).reduce((acc, curr) => acc + (acc === '' ? '' : ',') + encode(curr), ''));
|
|
7367
|
+
}
|
|
7368
|
+
}
|
|
7369
|
+
return {
|
|
7370
|
+
version: this.#version,
|
|
7371
|
+
sources: this.#sources.slice(),
|
|
7372
|
+
mappings: mappings.join(';')
|
|
7373
|
+
};
|
|
7374
|
+
}
|
|
7375
|
+
}
|
|
7469
7376
|
|
|
7470
|
-
|
|
7471
|
-
|
|
7377
|
+
/**
|
|
7378
|
+
* Update position
|
|
7379
|
+
* @param position
|
|
7380
|
+
* @param str
|
|
7381
|
+
*/
|
|
7382
|
+
function update(position, str) {
|
|
7383
|
+
let i = 0;
|
|
7384
|
+
for (; i < str.length; i++) {
|
|
7385
|
+
if (isNewLine(str[i].charCodeAt(0))) {
|
|
7386
|
+
position.lin++;
|
|
7387
|
+
position.col = 0;
|
|
7388
|
+
}
|
|
7389
|
+
else {
|
|
7390
|
+
position.col++;
|
|
7391
|
+
}
|
|
7392
|
+
}
|
|
7393
|
+
}
|
|
7394
|
+
/**
|
|
7395
|
+
* render ast
|
|
7396
|
+
* @param data
|
|
7397
|
+
* @param options
|
|
7398
|
+
* @private
|
|
7399
|
+
*/
|
|
7400
|
+
function doRender(data, options = {}) {
|
|
7401
|
+
const minify = options.minify ?? true;
|
|
7402
|
+
const beautify = options.beautify ?? !minify;
|
|
7403
|
+
options = {
|
|
7404
|
+
...(beautify ? {
|
|
7405
|
+
indent: ' ',
|
|
7406
|
+
newLine: '\n',
|
|
7407
|
+
} : {
|
|
7408
|
+
indent: '',
|
|
7409
|
+
newLine: '',
|
|
7410
|
+
}),
|
|
7411
|
+
...(minify ? {
|
|
7412
|
+
removeEmpty: true,
|
|
7413
|
+
removeComments: true,
|
|
7414
|
+
minify: true
|
|
7415
|
+
} : {
|
|
7416
|
+
removeEmpty: false,
|
|
7417
|
+
removeComments: false,
|
|
7418
|
+
}), sourcemap: false, convertColor: true, expandNestingRules: false, preserveLicense: false, ...options
|
|
7419
|
+
};
|
|
7420
|
+
if (options.withParents) {
|
|
7472
7421
|
// @ts-ignore
|
|
7473
|
-
|
|
7474
|
-
|
|
7422
|
+
let parent = data.parent;
|
|
7423
|
+
// @ts-ignore
|
|
7424
|
+
while (data.parent != null) {
|
|
7425
|
+
// @ts-ignore
|
|
7426
|
+
parent = { ...data.parent, chi: [{ ...data }] };
|
|
7427
|
+
// @ts-ignore
|
|
7428
|
+
parent.parent = data.parent.parent;
|
|
7429
|
+
// @ts-ignore
|
|
7430
|
+
data = parent;
|
|
7431
|
+
}
|
|
7475
7432
|
}
|
|
7476
|
-
|
|
7433
|
+
const startTime = performance.now();
|
|
7434
|
+
const errors = [];
|
|
7435
|
+
const sourcemap = options.sourcemap ? new SourceMap : null;
|
|
7436
|
+
const cache = Object.create(null);
|
|
7437
|
+
const result = {
|
|
7438
|
+
code: renderAstNode(options.expandNestingRules ? expand(data) : data, options, sourcemap, {
|
|
7439
|
+
ind: 0,
|
|
7440
|
+
lin: 1,
|
|
7441
|
+
col: 1
|
|
7442
|
+
}, errors, function reducer(acc, curr) {
|
|
7443
|
+
if (curr.typ == exports.EnumToken.CommentTokenType && options.removeComments) {
|
|
7444
|
+
if (!options.preserveLicense || !curr.val.startsWith('/*!')) {
|
|
7445
|
+
return acc;
|
|
7446
|
+
}
|
|
7447
|
+
return acc + curr.val;
|
|
7448
|
+
}
|
|
7449
|
+
return acc + renderToken(curr, options, cache, reducer, errors);
|
|
7450
|
+
}, cache), errors, stats: {
|
|
7451
|
+
total: `${(performance.now() - startTime).toFixed(2)}ms`
|
|
7452
|
+
}
|
|
7453
|
+
};
|
|
7454
|
+
if (options.output != null) {
|
|
7477
7455
|
// @ts-ignore
|
|
7478
|
-
|
|
7456
|
+
options.output = options.resolve(options.output, options.cwd).absolute;
|
|
7457
|
+
}
|
|
7458
|
+
if (sourcemap != null) {
|
|
7459
|
+
result.map = sourcemap;
|
|
7460
|
+
if (options.sourcemap === 'inline') {
|
|
7461
|
+
result.code += `\n/*# sourceMappingURL=data:application/json,${encodeURIComponent(JSON.stringify(result.map))} */`;
|
|
7462
|
+
}
|
|
7463
|
+
}
|
|
7464
|
+
return result;
|
|
7465
|
+
}
|
|
7466
|
+
/**
|
|
7467
|
+
* Update source map
|
|
7468
|
+
* @param node
|
|
7469
|
+
* @param options
|
|
7470
|
+
* @param cache
|
|
7471
|
+
* @param sourcemap
|
|
7472
|
+
* @param position
|
|
7473
|
+
* @param str
|
|
7474
|
+
*
|
|
7475
|
+
* @internal
|
|
7476
|
+
*/
|
|
7477
|
+
function updateSourceMap(node, options, cache, sourcemap, position, str) {
|
|
7478
|
+
if ([
|
|
7479
|
+
exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType,
|
|
7480
|
+
exports.EnumToken.KeyFrameRuleNodeType, exports.EnumToken.KeyframeAtRuleNodeType
|
|
7481
|
+
].includes(node.typ)) {
|
|
7482
|
+
let src = node.loc?.src ?? '';
|
|
7483
|
+
let output = options.output ?? '';
|
|
7484
|
+
if (!(src in cache)) {
|
|
7485
|
+
// @ts-ignore
|
|
7486
|
+
cache[src] = options.resolve(src, options.cwd ?? '').relative;
|
|
7487
|
+
}
|
|
7488
|
+
if (!(output in cache)) {
|
|
7489
|
+
// @ts-ignore
|
|
7490
|
+
cache[output] = options.resolve(output, options.cwd).relative;
|
|
7491
|
+
}
|
|
7492
|
+
// @ts-ignore
|
|
7493
|
+
sourcemap.add({ src: cache[output], sta: { ...position } }, {
|
|
7494
|
+
...node.loc,
|
|
7495
|
+
// @ts-ignore
|
|
7496
|
+
src: options.resolve(cache[src], options.cwd).relative
|
|
7497
|
+
});
|
|
7498
|
+
}
|
|
7499
|
+
update(position, str);
|
|
7500
|
+
}
|
|
7501
|
+
/**
|
|
7502
|
+
* render ast node
|
|
7503
|
+
* @param data
|
|
7504
|
+
* @param options
|
|
7505
|
+
* @param sourcemap
|
|
7506
|
+
* @param position
|
|
7507
|
+
* @param errors
|
|
7508
|
+
* @param reducer
|
|
7509
|
+
* @param cache
|
|
7510
|
+
* @param level
|
|
7511
|
+
* @param indents
|
|
7512
|
+
*
|
|
7513
|
+
* @internal
|
|
7514
|
+
*/
|
|
7515
|
+
function renderAstNode(data, options, sourcemap, position, errors, reducer, cache, level = 0, indents = []) {
|
|
7516
|
+
if (indents.length < level + 1) {
|
|
7517
|
+
indents.push(options.indent.repeat(level));
|
|
7518
|
+
}
|
|
7519
|
+
if (indents.length < level + 2) {
|
|
7520
|
+
indents.push(options.indent.repeat(level + 1));
|
|
7521
|
+
}
|
|
7522
|
+
const indent = indents[level];
|
|
7523
|
+
const indentSub = indents[level + 1];
|
|
7524
|
+
switch (data.typ) {
|
|
7525
|
+
case exports.EnumToken.DeclarationNodeType:
|
|
7526
|
+
return `${data.nam}:${options.indent}${(options.minify ? filterValues(data.val) : data.val).reduce(reducer, '')}`;
|
|
7527
|
+
case exports.EnumToken.CommentNodeType:
|
|
7528
|
+
case exports.EnumToken.CDOCOMMNodeType:
|
|
7529
|
+
if (data.val.startsWith('/*# sourceMappingURL=')) {
|
|
7530
|
+
// ignore sourcemap
|
|
7531
|
+
return '';
|
|
7532
|
+
}
|
|
7533
|
+
return !options.removeComments || (options.preserveLicense && data.val.startsWith('/*!')) ? data.val : '';
|
|
7534
|
+
case exports.EnumToken.StyleSheetNodeType:
|
|
7535
|
+
return data.chi.reduce((css, node) => {
|
|
7536
|
+
const str = renderAstNode(node, options, sourcemap, { ...position }, errors, reducer, cache, level, indents);
|
|
7537
|
+
if (str === '') {
|
|
7538
|
+
return css;
|
|
7539
|
+
}
|
|
7540
|
+
if (css === '') {
|
|
7541
|
+
if (sourcemap != null && node.loc != null) {
|
|
7542
|
+
updateSourceMap(node, options, cache, sourcemap, position, str);
|
|
7543
|
+
}
|
|
7544
|
+
return str;
|
|
7545
|
+
}
|
|
7546
|
+
if (sourcemap != null && node.loc != null) {
|
|
7547
|
+
update(position, options.newLine);
|
|
7548
|
+
updateSourceMap(node, options, cache, sourcemap, position, str);
|
|
7549
|
+
}
|
|
7550
|
+
return `${css}${options.newLine}${str}`;
|
|
7551
|
+
}, '');
|
|
7552
|
+
case exports.EnumToken.AtRuleNodeType:
|
|
7553
|
+
case exports.EnumToken.RuleNodeType:
|
|
7554
|
+
case exports.EnumToken.KeyFrameRuleNodeType:
|
|
7555
|
+
case exports.EnumToken.KeyframeAtRuleNodeType:
|
|
7556
|
+
if ([exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyframeAtRuleNodeType].includes(data.typ) && !('chi' in data)) {
|
|
7557
|
+
return `${indent}@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val};`;
|
|
7558
|
+
}
|
|
7479
7559
|
// @ts-ignore
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
|
|
7560
|
+
let children = data.chi.reduce((css, node) => {
|
|
7561
|
+
let str;
|
|
7562
|
+
if (node.typ == exports.EnumToken.CommentNodeType) {
|
|
7563
|
+
str = options.removeComments && (!options.preserveLicense || !node.val.startsWith('/*!')) ? '' : node.val;
|
|
7564
|
+
}
|
|
7565
|
+
else if (node.typ == exports.EnumToken.DeclarationNodeType) {
|
|
7566
|
+
if (!node.nam.startsWith('--') && node.val.length == 0) {
|
|
7567
|
+
// @ts-ignore
|
|
7568
|
+
errors.push({
|
|
7569
|
+
action: 'ignore',
|
|
7570
|
+
message: `render: invalid declaration ${JSON.stringify(node)}`,
|
|
7571
|
+
location: node.loc
|
|
7572
|
+
});
|
|
7573
|
+
return '';
|
|
7574
|
+
}
|
|
7575
|
+
str = `${node.nam}:${options.indent}${(options.minify ? filterValues(node.val) : node.val).reduce(reducer, '').trimEnd()};`;
|
|
7576
|
+
}
|
|
7577
|
+
else if (node.typ == exports.EnumToken.AtRuleNodeType && !('chi' in node)) {
|
|
7578
|
+
str = `${data.val === '' ? '' : options.indent || ' '}${data.val};`;
|
|
7579
|
+
}
|
|
7580
|
+
else {
|
|
7581
|
+
str = renderAstNode(node, options, sourcemap, { ...position }, errors, reducer, cache, level + 1, indents);
|
|
7582
|
+
}
|
|
7583
|
+
if (css === '') {
|
|
7584
|
+
return str;
|
|
7585
|
+
}
|
|
7586
|
+
if (str === '') {
|
|
7587
|
+
return css;
|
|
7588
|
+
}
|
|
7589
|
+
return `${css}${options.newLine}${indentSub}${str}`;
|
|
7590
|
+
}, '');
|
|
7591
|
+
if (options.removeEmpty && children === '') {
|
|
7592
|
+
return '';
|
|
7593
|
+
}
|
|
7594
|
+
if (children.endsWith(';')) {
|
|
7595
|
+
children = children.slice(0, -1);
|
|
7596
|
+
}
|
|
7597
|
+
if ([exports.EnumToken.AtRuleNodeType, exports.EnumToken.KeyframeAtRuleNodeType].includes(data.typ)) {
|
|
7598
|
+
return `@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val}${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
|
|
7599
|
+
}
|
|
7600
|
+
return data.sel + `${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
|
|
7601
|
+
case exports.EnumToken.InvalidDeclarationNodeType:
|
|
7602
|
+
case exports.EnumToken.InvalidRuleTokenType:
|
|
7603
|
+
case exports.EnumToken.InvalidAtRuleTokenType:
|
|
7604
|
+
default:
|
|
7605
|
+
return '';
|
|
7490
7606
|
}
|
|
7491
|
-
return false;
|
|
7492
7607
|
}
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
7503
|
-
|
|
7504
|
-
|
|
7608
|
+
/**
|
|
7609
|
+
* render ast token
|
|
7610
|
+
* @param token
|
|
7611
|
+
* @param options
|
|
7612
|
+
*/
|
|
7613
|
+
function renderToken(token, options = {}, cache = Object.create(null), reducer, errors) {
|
|
7614
|
+
if (reducer == null) {
|
|
7615
|
+
reducer = function (acc, curr) {
|
|
7616
|
+
if (curr.typ == exports.EnumToken.CommentTokenType && options.removeComments) {
|
|
7617
|
+
if (!options.preserveLicense || !curr.val.startsWith('/*!')) {
|
|
7618
|
+
return acc;
|
|
7619
|
+
}
|
|
7620
|
+
return acc + curr.val;
|
|
7621
|
+
}
|
|
7622
|
+
return acc + renderToken(curr, options, cache, reducer, errors);
|
|
7623
|
+
};
|
|
7505
7624
|
}
|
|
7506
|
-
|
|
7507
|
-
if (
|
|
7625
|
+
if (token.typ == exports.EnumToken.FunctionTokenType && colorsFunc.includes(token.val)) {
|
|
7626
|
+
if (isColor(token)) {
|
|
7508
7627
|
// @ts-ignore
|
|
7509
|
-
|
|
7510
|
-
}
|
|
7511
|
-
else if (val.typ == exports.EnumToken.StringTokenType && (node.nam == 'grid' || node.nam == 'grid-template-areas' || node.nam == 'grid-template-rows' || node.nam == 'grid-template-columns')) {
|
|
7512
|
-
val.val = val.val.at(0) + parseGridTemplate(val.val.slice(1, -1)) + val.val.at(-1);
|
|
7628
|
+
token.typ = exports.EnumToken.ColorTokenType;
|
|
7513
7629
|
// @ts-ignore
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
7630
|
+
if (token.chi[0].typ == exports.EnumToken.IdenTokenType && token.chi[0].val == 'from') {
|
|
7631
|
+
// @ts-ignore
|
|
7632
|
+
token.cal = 'rel';
|
|
7633
|
+
}
|
|
7634
|
+
else { // @ts-ignore
|
|
7635
|
+
if (token.val == 'color-mix' && token.chi[0].typ == exports.EnumToken.IdenTokenType && token.chi[0].val == 'in') {
|
|
7636
|
+
// @ts-ignore
|
|
7637
|
+
token.cal = 'mix';
|
|
7638
|
+
}
|
|
7639
|
+
else {
|
|
7640
|
+
// @ts-ignore
|
|
7641
|
+
if (token.val == 'color') {
|
|
7642
|
+
// @ts-ignore
|
|
7643
|
+
token.cal = 'col';
|
|
7644
|
+
}
|
|
7645
|
+
// @ts-ignore
|
|
7646
|
+
token.chi = token.chi.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommaTokenType, exports.EnumToken.CommentTokenType].includes(t.typ));
|
|
7647
|
+
}
|
|
7648
|
+
}
|
|
7649
|
+
}
|
|
7650
|
+
}
|
|
7651
|
+
switch (token.typ) {
|
|
7652
|
+
case exports.EnumToken.ListToken:
|
|
7653
|
+
return token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
7654
|
+
case exports.EnumToken.BinaryExpressionTokenType:
|
|
7655
|
+
if ([exports.EnumToken.Mul, exports.EnumToken.Div].includes(token.op)) {
|
|
7656
|
+
let result = '';
|
|
7657
|
+
if (token.l.typ == exports.EnumToken.BinaryExpressionTokenType &&
|
|
7658
|
+
[exports.EnumToken.Add, exports.EnumToken.Sub].includes(token.l.op)) {
|
|
7659
|
+
result = '(' + renderToken(token.l, options, cache) + ')';
|
|
7660
|
+
}
|
|
7661
|
+
else {
|
|
7662
|
+
result = renderToken(token.l, options, cache);
|
|
7663
|
+
}
|
|
7664
|
+
result += token.op == exports.EnumToken.Mul ? '*' : '/';
|
|
7665
|
+
if (token.r.typ == exports.EnumToken.BinaryExpressionTokenType &&
|
|
7666
|
+
[exports.EnumToken.Add, exports.EnumToken.Sub].includes(token.r.op)) {
|
|
7667
|
+
result += '(' + renderToken(token.r, options, cache) + ')';
|
|
7668
|
+
}
|
|
7669
|
+
else {
|
|
7670
|
+
result += renderToken(token.r, options, cache);
|
|
7671
|
+
}
|
|
7672
|
+
return result;
|
|
7673
|
+
}
|
|
7674
|
+
return renderToken(token.l, options, cache) + (token.op == exports.EnumToken.Add ? ' + ' : (token.op == exports.EnumToken.Sub ? ' - ' : (token.op == exports.EnumToken.Mul ? '*' : '/'))) + renderToken(token.r, options, cache);
|
|
7675
|
+
case exports.EnumToken.FractionTokenType:
|
|
7676
|
+
const fraction = renderToken(token.l) + '/' + renderToken(token.r);
|
|
7677
|
+
if (+token.r.val != 0) {
|
|
7678
|
+
const value = minifyNumber(+token.l.val / +token.r.val);
|
|
7679
|
+
if (value.length <= fraction.length) {
|
|
7680
|
+
return value;
|
|
7681
|
+
}
|
|
7682
|
+
}
|
|
7683
|
+
return fraction;
|
|
7684
|
+
case exports.EnumToken.Add:
|
|
7685
|
+
return ' + ';
|
|
7686
|
+
case exports.EnumToken.Sub:
|
|
7687
|
+
return ' - ';
|
|
7688
|
+
case exports.EnumToken.UniversalSelectorTokenType:
|
|
7689
|
+
case exports.EnumToken.Mul:
|
|
7690
|
+
return '*';
|
|
7691
|
+
case exports.EnumToken.Div:
|
|
7692
|
+
return '/';
|
|
7693
|
+
case exports.EnumToken.ColorTokenType:
|
|
7694
|
+
if (token.kin == exports.ColorType.LIGHT_DARK || ('chi' in token && options.convertColor === false)) {
|
|
7695
|
+
return token.val + '(' + token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache), '') + ')';
|
|
7696
|
+
}
|
|
7697
|
+
if (options.convertColor !== false) {
|
|
7698
|
+
const value = convertColor(token, typeof options.convertColor == 'boolean' ? exports.ColorType.HEX : exports.ColorType[exports.ColorType[options.convertColor ?? 'HEX']?.toUpperCase?.().replaceAll?.('-', '_')] ?? exports.ColorType.HEX);
|
|
7699
|
+
//
|
|
7700
|
+
if (value != null) {
|
|
7701
|
+
token = value;
|
|
7702
|
+
}
|
|
7703
|
+
}
|
|
7704
|
+
if ([exports.ColorType.HEX, exports.ColorType.LIT, exports.ColorType.SYS, exports.ColorType.DPSYS].includes(token.kin)) {
|
|
7705
|
+
return token.val;
|
|
7706
|
+
}
|
|
7707
|
+
if (Array.isArray(token.chi)) {
|
|
7708
|
+
const isLegacy = ['rgb', 'rgba', 'hsl', 'hsla'].includes(token.val.toLowerCase());
|
|
7709
|
+
const useAlpha = (['rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'oklab', 'oklch', 'lab', 'lch'].includes(token.val.toLowerCase()) && token.chi.length == 4) ||
|
|
7710
|
+
('color' == token.val.toLowerCase() && token.chi.length == 5);
|
|
7711
|
+
return (token.val.endsWith('a') ? token.val.slice(0, -1) : token.val) + '(' + token.chi.reduce((acc, curr, index, array) => {
|
|
7712
|
+
if (/[,/]\s*$/.test(acc)) {
|
|
7713
|
+
if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
7714
|
+
return acc.trimEnd();
|
|
7715
|
+
}
|
|
7716
|
+
return acc.trimStart() + renderToken(curr, options, cache);
|
|
7717
|
+
}
|
|
7718
|
+
if (isLegacy && curr.typ == exports.EnumToken.CommaTokenType) {
|
|
7719
|
+
return acc.trimEnd() + ' ';
|
|
7720
|
+
}
|
|
7721
|
+
if (curr.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
7722
|
+
return acc.trimEnd() + ' ';
|
|
7723
|
+
}
|
|
7724
|
+
if (curr.typ == exports.EnumToken.CommaTokenType || (curr.typ == exports.EnumToken.LiteralTokenType && curr.val == '/')) {
|
|
7725
|
+
return acc.trimEnd() + (curr.typ == exports.EnumToken.CommaTokenType ? ',' : '/');
|
|
7726
|
+
}
|
|
7727
|
+
return acc.trimEnd() + (useAlpha && index == array.length - 1 ? '/' : ' ') + renderToken(curr, options, cache);
|
|
7728
|
+
}, '').trimStart() + ')';
|
|
7729
|
+
}
|
|
7730
|
+
case exports.EnumToken.ParensTokenType:
|
|
7731
|
+
case exports.EnumToken.FunctionTokenType:
|
|
7732
|
+
case exports.EnumToken.UrlFunctionTokenType:
|
|
7733
|
+
case exports.EnumToken.ImageFunctionTokenType:
|
|
7734
|
+
case exports.EnumToken.TimingFunctionTokenType:
|
|
7735
|
+
case exports.EnumToken.PseudoClassFuncTokenType:
|
|
7736
|
+
case exports.EnumToken.TimelineFunctionTokenType:
|
|
7737
|
+
case exports.EnumToken.GridTemplateFuncTokenType:
|
|
7738
|
+
if (token.typ == exports.EnumToken.FunctionTokenType &&
|
|
7739
|
+
mathFuncs.includes(token.val) &&
|
|
7740
|
+
token.chi.length == 1 &&
|
|
7741
|
+
![exports.EnumToken.BinaryExpressionTokenType, exports.EnumToken.FractionTokenType, exports.EnumToken.IdenTokenType].includes(token.chi[0].typ) &&
|
|
7742
|
+
// @ts-ignore
|
|
7743
|
+
token.chi[0].val?.typ != exports.EnumToken.FractionTokenType) {
|
|
7744
|
+
return token.val + '(' + token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache, reducer), '') + ')';
|
|
7745
|
+
}
|
|
7746
|
+
return ( /* options.minify && 'Pseudo-class-func' == token.typ && token.val.slice(0, 2) == '::' ? token.val.slice(1) :*/token.val ?? '') + '(' + token.chi.reduce(reducer, '') + ')';
|
|
7747
|
+
case exports.EnumToken.MatchExpressionTokenType:
|
|
7748
|
+
return renderToken(token.l, options, cache, reducer, errors) +
|
|
7749
|
+
renderToken(token.op, options, cache, reducer, errors) +
|
|
7750
|
+
renderToken(token.r, options, cache, reducer, errors) +
|
|
7751
|
+
(token.attr ? ' ' + token.attr : '');
|
|
7752
|
+
case exports.EnumToken.NameSpaceAttributeTokenType:
|
|
7753
|
+
return (token.l == null ? '' : renderToken(token.l, options, cache, reducer, errors)) + '|' +
|
|
7754
|
+
renderToken(token.r, options, cache, reducer, errors);
|
|
7755
|
+
case exports.EnumToken.BlockStartTokenType:
|
|
7756
|
+
return '{';
|
|
7757
|
+
case exports.EnumToken.BlockEndTokenType:
|
|
7758
|
+
return '}';
|
|
7759
|
+
case exports.EnumToken.StartParensTokenType:
|
|
7760
|
+
return '(';
|
|
7761
|
+
case exports.EnumToken.DelimTokenType:
|
|
7762
|
+
case exports.EnumToken.EqualMatchTokenType:
|
|
7763
|
+
return '=';
|
|
7764
|
+
case exports.EnumToken.IncludeMatchTokenType:
|
|
7765
|
+
return '~=';
|
|
7766
|
+
case exports.EnumToken.DashMatchTokenType:
|
|
7767
|
+
return '|=';
|
|
7768
|
+
case exports.EnumToken.StartMatchTokenType:
|
|
7769
|
+
return '^=';
|
|
7770
|
+
case exports.EnumToken.EndMatchTokenType:
|
|
7771
|
+
return '$=';
|
|
7772
|
+
case exports.EnumToken.ContainMatchTokenType:
|
|
7773
|
+
return '*=';
|
|
7774
|
+
case exports.EnumToken.LtTokenType:
|
|
7775
|
+
return '<';
|
|
7776
|
+
case exports.EnumToken.LteTokenType:
|
|
7777
|
+
return '<=';
|
|
7778
|
+
case exports.EnumToken.SubsequentSiblingCombinatorTokenType:
|
|
7779
|
+
return '~';
|
|
7780
|
+
case exports.EnumToken.NextSiblingCombinatorTokenType:
|
|
7781
|
+
return '+';
|
|
7782
|
+
case exports.EnumToken.GtTokenType:
|
|
7783
|
+
case exports.EnumToken.ChildCombinatorTokenType:
|
|
7784
|
+
return '>';
|
|
7785
|
+
case exports.EnumToken.GteTokenType:
|
|
7786
|
+
return '>=';
|
|
7787
|
+
case exports.EnumToken.ColumnCombinatorTokenType:
|
|
7788
|
+
return '||';
|
|
7789
|
+
case exports.EnumToken.EndParensTokenType:
|
|
7790
|
+
return ')';
|
|
7791
|
+
case exports.EnumToken.AttrStartTokenType:
|
|
7792
|
+
return '[';
|
|
7793
|
+
case exports.EnumToken.AttrEndTokenType:
|
|
7794
|
+
return ']';
|
|
7795
|
+
case exports.EnumToken.DescendantCombinatorTokenType:
|
|
7796
|
+
case exports.EnumToken.WhitespaceTokenType:
|
|
7797
|
+
return ' ';
|
|
7798
|
+
case exports.EnumToken.ColonTokenType:
|
|
7799
|
+
return ':';
|
|
7800
|
+
case exports.EnumToken.SemiColonTokenType:
|
|
7801
|
+
return ';';
|
|
7802
|
+
case exports.EnumToken.CommaTokenType:
|
|
7803
|
+
return ',';
|
|
7804
|
+
case exports.EnumToken.ImportantTokenType:
|
|
7805
|
+
return '!important';
|
|
7806
|
+
case exports.EnumToken.AttrTokenType:
|
|
7807
|
+
case exports.EnumToken.IdenListTokenType:
|
|
7808
|
+
return '[' + token.chi.reduce(reducer, '') + ']';
|
|
7809
|
+
case exports.EnumToken.TimeTokenType:
|
|
7810
|
+
case exports.EnumToken.AngleTokenType:
|
|
7811
|
+
case exports.EnumToken.LengthTokenType:
|
|
7812
|
+
case exports.EnumToken.DimensionTokenType:
|
|
7813
|
+
case exports.EnumToken.FrequencyTokenType:
|
|
7814
|
+
case exports.EnumToken.ResolutionTokenType:
|
|
7815
|
+
let val = token.val.typ == exports.EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : minifyNumber(token.val);
|
|
7816
|
+
let unit = token.unit;
|
|
7817
|
+
if (token.typ == exports.EnumToken.AngleTokenType && !val.includes('/')) {
|
|
7818
|
+
const angle = getAngle(token);
|
|
7819
|
+
let v;
|
|
7820
|
+
let value = val + unit;
|
|
7821
|
+
for (const u of ['turn', 'deg', 'rad', 'grad']) {
|
|
7822
|
+
if (token.unit == u) {
|
|
7823
|
+
continue;
|
|
7824
|
+
}
|
|
7825
|
+
switch (u) {
|
|
7826
|
+
case 'turn':
|
|
7827
|
+
v = minifyNumber(angle);
|
|
7828
|
+
if (v.length + 4 < value.length) {
|
|
7829
|
+
val = v;
|
|
7830
|
+
unit = u;
|
|
7831
|
+
value = v + u;
|
|
7832
|
+
}
|
|
7833
|
+
break;
|
|
7834
|
+
case 'deg':
|
|
7835
|
+
v = minifyNumber(angle * 360);
|
|
7836
|
+
if (v.length + 3 < value.length) {
|
|
7837
|
+
val = v;
|
|
7838
|
+
unit = u;
|
|
7839
|
+
value = v + u;
|
|
7840
|
+
}
|
|
7841
|
+
break;
|
|
7842
|
+
case 'rad':
|
|
7843
|
+
v = minifyNumber(angle * (2 * Math.PI));
|
|
7844
|
+
if (v.length + 3 < value.length) {
|
|
7845
|
+
val = v;
|
|
7846
|
+
unit = u;
|
|
7847
|
+
value = v + u;
|
|
7848
|
+
}
|
|
7849
|
+
break;
|
|
7850
|
+
case 'grad':
|
|
7851
|
+
v = minifyNumber(angle * 400);
|
|
7852
|
+
if (v.length + 4 < value.length) {
|
|
7853
|
+
val = v;
|
|
7854
|
+
unit = u;
|
|
7855
|
+
value = v + u;
|
|
7856
|
+
}
|
|
7857
|
+
break;
|
|
7858
|
+
}
|
|
7859
|
+
}
|
|
7518
7860
|
}
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
7861
|
+
if (val === '0') {
|
|
7862
|
+
if (token.typ == exports.EnumToken.TimeTokenType) {
|
|
7863
|
+
return '0s';
|
|
7864
|
+
}
|
|
7865
|
+
if (token.typ == exports.EnumToken.FrequencyTokenType) {
|
|
7866
|
+
return '0Hz';
|
|
7867
|
+
}
|
|
7868
|
+
// @ts-ignore
|
|
7869
|
+
if (token.typ == exports.EnumToken.ResolutionTokenType) {
|
|
7870
|
+
return '0x';
|
|
7871
|
+
}
|
|
7872
|
+
return '0';
|
|
7531
7873
|
}
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7874
|
+
if (token.typ == exports.EnumToken.TimeTokenType) {
|
|
7875
|
+
if (unit == 'ms') {
|
|
7876
|
+
// @ts-ignore
|
|
7877
|
+
const v = minifyNumber(val / 1000);
|
|
7878
|
+
if (v.length + 1 <= val.length) {
|
|
7879
|
+
return v + 's';
|
|
7880
|
+
}
|
|
7881
|
+
return val + 'ms';
|
|
7882
|
+
}
|
|
7883
|
+
return val + 's';
|
|
7538
7884
|
}
|
|
7539
|
-
if (
|
|
7540
|
-
|
|
7885
|
+
if (token.typ == exports.EnumToken.ResolutionTokenType && unit == 'dppx') {
|
|
7886
|
+
unit = 'x';
|
|
7541
7887
|
}
|
|
7542
|
-
|
|
7543
|
-
|
|
7888
|
+
return val.includes('/') ? val.replace('/', unit + '/') : val + unit;
|
|
7889
|
+
case exports.EnumToken.FlexTokenType:
|
|
7890
|
+
case exports.EnumToken.PercentageTokenType:
|
|
7891
|
+
const uni = token.typ == exports.EnumToken.PercentageTokenType ? '%' : 'fr';
|
|
7892
|
+
const perc = token.val.typ == exports.EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : minifyNumber(token.val);
|
|
7893
|
+
return options.minify && perc == '0' ? '0' : (perc.includes('/') ? perc.replace('/', uni + '/') : perc + uni);
|
|
7894
|
+
case exports.EnumToken.NumberTokenType:
|
|
7895
|
+
return token.val.typ == exports.EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : minifyNumber(token.val);
|
|
7896
|
+
case exports.EnumToken.CommentTokenType:
|
|
7897
|
+
if (options.removeComments && (!options.preserveLicense || !token.val.startsWith('/*!'))) {
|
|
7898
|
+
return '';
|
|
7899
|
+
}
|
|
7900
|
+
case exports.EnumToken.PseudoClassTokenType:
|
|
7901
|
+
case exports.EnumToken.PseudoElementTokenType:
|
|
7902
|
+
// https://www.w3.org/TR/selectors-4/#single-colon-pseudos
|
|
7903
|
+
if (token.typ == exports.EnumToken.PseudoElementTokenType && pseudoElements.includes(token.val.slice(1))) {
|
|
7904
|
+
return token.val.slice(1);
|
|
7905
|
+
}
|
|
7906
|
+
case exports.EnumToken.UrlTokenTokenType:
|
|
7907
|
+
// if (token.typ == EnumToken.UrlTokenTokenType) {
|
|
7908
|
+
//
|
|
7909
|
+
// if (options.output != null) {
|
|
7910
|
+
//
|
|
7911
|
+
// if (!('original' in token)) {
|
|
7912
|
+
//
|
|
7913
|
+
// // do not modify original token
|
|
7914
|
+
// token = {...token};
|
|
7915
|
+
// Object.defineProperty(token, 'original', {
|
|
7916
|
+
// enumerable: false,
|
|
7917
|
+
// writable: false,
|
|
7918
|
+
// value: (token as UrlToken).val
|
|
7919
|
+
// })
|
|
7920
|
+
// }
|
|
7921
|
+
//
|
|
7922
|
+
// // @ts-ignore
|
|
7923
|
+
// if (!(token.original in cache)) {
|
|
7924
|
+
//
|
|
7925
|
+
// let output: string = <string>options.output ?? '';
|
|
7926
|
+
// const key = output + 'abs';
|
|
7927
|
+
//
|
|
7928
|
+
// if (!(key in cache)) {
|
|
7929
|
+
//
|
|
7930
|
+
// // @ts-ignore
|
|
7931
|
+
// cache[key] = options.dirname(options.resolve(output, options.cwd).absolute);
|
|
7932
|
+
// }
|
|
7933
|
+
//
|
|
7934
|
+
// // @ts-ignore
|
|
7935
|
+
// cache[token.original] = options.resolve(token.original, cache[key]).relative;
|
|
7936
|
+
// }
|
|
7937
|
+
//
|
|
7938
|
+
// // @ts-ignore
|
|
7939
|
+
// token.val = cache[token.original];
|
|
7940
|
+
// }
|
|
7941
|
+
// }
|
|
7942
|
+
case exports.EnumToken.HashTokenType:
|
|
7943
|
+
case exports.EnumToken.IdenTokenType:
|
|
7944
|
+
case exports.EnumToken.AtRuleTokenType:
|
|
7945
|
+
case exports.EnumToken.StringTokenType:
|
|
7946
|
+
case exports.EnumToken.LiteralTokenType:
|
|
7947
|
+
case exports.EnumToken.DashedIdenTokenType:
|
|
7948
|
+
case exports.EnumToken.PseudoPageTokenType:
|
|
7949
|
+
case exports.EnumToken.ClassSelectorTokenType:
|
|
7950
|
+
return /* options.minify && 'Pseudo-class' == token.typ && '::' == token.val.slice(0, 2) ? token.val.slice(1) : */ token.val;
|
|
7951
|
+
case exports.EnumToken.NestingSelectorTokenType:
|
|
7952
|
+
return '&';
|
|
7953
|
+
case exports.EnumToken.InvalidAttrTokenType:
|
|
7954
|
+
return '[' + token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
7955
|
+
case exports.EnumToken.InvalidClassSelectorTokenType:
|
|
7956
|
+
return token.val;
|
|
7957
|
+
case exports.EnumToken.DeclarationNodeType:
|
|
7958
|
+
return token.nam + ':' + (options.minify ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
7959
|
+
case exports.EnumToken.MediaQueryConditionTokenType:
|
|
7960
|
+
return renderToken(token.l, options, cache, reducer, errors) + renderToken(token.op, options, cache, reducer, errors) + token.r.reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
7961
|
+
case exports.EnumToken.MediaFeatureTokenType:
|
|
7962
|
+
return token.val;
|
|
7963
|
+
case exports.EnumToken.MediaFeatureNotTokenType:
|
|
7964
|
+
return 'not ' + renderToken(token.val, options, cache, reducer, errors);
|
|
7965
|
+
case exports.EnumToken.MediaFeatureOnlyTokenType:
|
|
7966
|
+
return 'only ' + renderToken(token.val, options, cache, reducer, errors);
|
|
7967
|
+
case exports.EnumToken.MediaFeatureAndTokenType:
|
|
7968
|
+
return 'and';
|
|
7969
|
+
case exports.EnumToken.MediaFeatureOrTokenType:
|
|
7970
|
+
return 'or';
|
|
7971
|
+
}
|
|
7972
|
+
errors?.push({ action: 'ignore', message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
|
|
7973
|
+
return '';
|
|
7974
|
+
}
|
|
7975
|
+
/**
|
|
7976
|
+
* Remove whitespace tokens that are not needed
|
|
7977
|
+
* @param values
|
|
7978
|
+
*
|
|
7979
|
+
* @internal
|
|
7980
|
+
*/
|
|
7981
|
+
function filterValues(values) {
|
|
7982
|
+
let i = 0;
|
|
7983
|
+
for (; i < values.length; i++) {
|
|
7984
|
+
if (values[i].typ == exports.EnumToken.ImportantTokenType && values[i - 1]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
7985
|
+
values.splice(i - 1, 1);
|
|
7544
7986
|
}
|
|
7545
|
-
else {
|
|
7546
|
-
|
|
7987
|
+
else if (funcLike.includes(values[i].typ) && !['var', 'calc'].includes(values[i].val) && values[i + 1]?.typ == exports.EnumToken.WhitespaceTokenType) {
|
|
7988
|
+
values.splice(i + 1, 1);
|
|
7547
7989
|
}
|
|
7548
7990
|
}
|
|
7549
|
-
return
|
|
7991
|
+
return values;
|
|
7550
7992
|
}
|
|
7551
7993
|
|
|
7552
7994
|
var TokenMap;
|
|
@@ -7582,7 +8024,7 @@
|
|
|
7582
8024
|
})(TokenMap || (TokenMap = {}));
|
|
7583
8025
|
function consumeWhiteSpace(parseInfo) {
|
|
7584
8026
|
let count = 0;
|
|
7585
|
-
while (isWhiteSpace(parseInfo.stream.
|
|
8027
|
+
while (isWhiteSpace(parseInfo.stream.charCodeAt(count + parseInfo.currentPosition.ind + 1))) {
|
|
7586
8028
|
count++;
|
|
7587
8029
|
}
|
|
7588
8030
|
next(parseInfo, count);
|
|
@@ -7688,11 +8130,8 @@
|
|
|
7688
8130
|
}
|
|
7689
8131
|
return parseInfo.stream.slice(parseInfo.currentPosition.ind + 1, parseInfo.currentPosition.ind + count + 1);
|
|
7690
8132
|
}
|
|
7691
|
-
function prev(parseInfo
|
|
7692
|
-
|
|
7693
|
-
return parseInfo.currentPosition.ind == 0 ? '' : parseInfo.stream.charAt(parseInfo.currentPosition.ind - 1);
|
|
7694
|
-
}
|
|
7695
|
-
return parseInfo.stream.slice(parseInfo.currentPosition.ind - 1 - count, parseInfo.currentPosition.ind - 1);
|
|
8133
|
+
function prev(parseInfo) {
|
|
8134
|
+
return parseInfo.stream.charAt(parseInfo.currentPosition.ind - 1);
|
|
7696
8135
|
}
|
|
7697
8136
|
function next(parseInfo, count = 1) {
|
|
7698
8137
|
let char = '';
|
|
@@ -7712,17 +8151,14 @@
|
|
|
7712
8151
|
}
|
|
7713
8152
|
/**
|
|
7714
8153
|
* tokenize css string
|
|
7715
|
-
* @param
|
|
8154
|
+
* @param parseInfo
|
|
8155
|
+
* @param yieldEOFToken
|
|
7716
8156
|
*/
|
|
7717
|
-
function* tokenize$1(
|
|
7718
|
-
const parseInfo = {
|
|
7719
|
-
stream,
|
|
7720
|
-
position: { ind: 0, lin: 1, col: 1 },
|
|
7721
|
-
currentPosition: { ind: -1, lin: 1, col: 0 }
|
|
7722
|
-
};
|
|
8157
|
+
function* tokenize$1(parseInfo, yieldEOFToken = true) {
|
|
7723
8158
|
let value;
|
|
7724
|
-
let buffer =
|
|
8159
|
+
let buffer = parseInfo.buffer;
|
|
7725
8160
|
let charCode;
|
|
8161
|
+
parseInfo.buffer = '';
|
|
7726
8162
|
while (value = next(parseInfo)) {
|
|
7727
8163
|
charCode = value.charCodeAt(0);
|
|
7728
8164
|
if (isWhiteSpace(charCode)) {
|
|
@@ -7985,11 +8421,6 @@
|
|
|
7985
8421
|
break;
|
|
7986
8422
|
}
|
|
7987
8423
|
}
|
|
7988
|
-
if (value === '') {
|
|
7989
|
-
yield pushToken(buffer, parseInfo, exports.EnumToken.BadUrlTokenType);
|
|
7990
|
-
buffer = '';
|
|
7991
|
-
break;
|
|
7992
|
-
}
|
|
7993
8424
|
charCode = value.charCodeAt(0);
|
|
7994
8425
|
}
|
|
7995
8426
|
// '\\'
|
|
@@ -8027,16 +8458,6 @@
|
|
|
8027
8458
|
}
|
|
8028
8459
|
while (value = next(parseInfo)) {
|
|
8029
8460
|
charCode = value.charCodeAt(0);
|
|
8030
|
-
if (charCode == 0x5c) {
|
|
8031
|
-
buffer += value + next(parseInfo);
|
|
8032
|
-
continue;
|
|
8033
|
-
}
|
|
8034
|
-
if (charCode == 0x29) {
|
|
8035
|
-
yield pushToken(buffer, parseInfo, exports.EnumToken.BadStringTokenType);
|
|
8036
|
-
yield pushToken('', parseInfo, exports.EnumToken.EndParensTokenType);
|
|
8037
|
-
buffer = '';
|
|
8038
|
-
break;
|
|
8039
|
-
}
|
|
8040
8461
|
buffer += value;
|
|
8041
8462
|
}
|
|
8042
8463
|
if (hasNewLine) {
|
|
@@ -8053,40 +8474,12 @@
|
|
|
8053
8474
|
buffer = '';
|
|
8054
8475
|
while (value = next(parseInfo)) {
|
|
8055
8476
|
charCode = value.charCodeAt(0);
|
|
8056
|
-
// ')'
|
|
8057
|
-
if (charCode == 0x29) {
|
|
8477
|
+
if (charCode == 0x29) { // ')'
|
|
8058
8478
|
yield pushToken(buffer, parseInfo, exports.EnumToken.UrlTokenTokenType);
|
|
8059
8479
|
yield pushToken('', parseInfo, exports.EnumToken.EndParensTokenType);
|
|
8060
8480
|
buffer = '';
|
|
8061
8481
|
break;
|
|
8062
8482
|
}
|
|
8063
|
-
// if (errorState) {
|
|
8064
|
-
//
|
|
8065
|
-
// buffer += whitespace + value;
|
|
8066
|
-
//
|
|
8067
|
-
// while (value = peek(parseInfo)) {
|
|
8068
|
-
//
|
|
8069
|
-
// charCode = value.charCodeAt(0);
|
|
8070
|
-
//
|
|
8071
|
-
// if (charCode == 0x5c) {
|
|
8072
|
-
//
|
|
8073
|
-
// buffer += next(parseInfo, 2);
|
|
8074
|
-
// continue;
|
|
8075
|
-
// }
|
|
8076
|
-
//
|
|
8077
|
-
// // ')'
|
|
8078
|
-
// if (charCode == 0x29) {
|
|
8079
|
-
//
|
|
8080
|
-
// break;
|
|
8081
|
-
// }
|
|
8082
|
-
//
|
|
8083
|
-
// buffer += next(parseInfo);
|
|
8084
|
-
// }
|
|
8085
|
-
//
|
|
8086
|
-
// yield pushToken(buffer, parseInfo, EnumToken.BadUrlTokenType);
|
|
8087
|
-
// buffer = '';
|
|
8088
|
-
// break;
|
|
8089
|
-
// }
|
|
8090
8483
|
buffer += value;
|
|
8091
8484
|
}
|
|
8092
8485
|
}
|
|
@@ -8123,12 +8516,8 @@
|
|
|
8123
8516
|
break;
|
|
8124
8517
|
}
|
|
8125
8518
|
buffer = '!';
|
|
8126
|
-
break;
|
|
8127
|
-
case 64 /* TokenMap.AT */:
|
|
8128
|
-
if (buffer.length > 0) {
|
|
8129
|
-
yield pushToken(buffer, parseInfo);
|
|
8130
|
-
buffer = '';
|
|
8131
|
-
}
|
|
8519
|
+
break;
|
|
8520
|
+
case 64 /* TokenMap.AT */:
|
|
8132
8521
|
buffer = value;
|
|
8133
8522
|
{
|
|
8134
8523
|
let val = peek(parseInfo);
|
|
@@ -8146,27 +8535,40 @@
|
|
|
8146
8535
|
break;
|
|
8147
8536
|
default:
|
|
8148
8537
|
buffer += value;
|
|
8149
|
-
if (buffer.length == 1) {
|
|
8150
|
-
if (buffer == 'h') {
|
|
8151
|
-
if (match$1(parseInfo, 'ttp://') || match$1(parseInfo, 'ttps://')) {
|
|
8152
|
-
let val = peek(parseInfo);
|
|
8153
|
-
while (val != ')' && val != ';' && !isWhiteSpace(val.charCodeAt(0))) {
|
|
8154
|
-
buffer += next(parseInfo);
|
|
8155
|
-
val = peek(parseInfo);
|
|
8156
|
-
}
|
|
8157
|
-
yield pushToken(buffer, parseInfo);
|
|
8158
|
-
buffer = '';
|
|
8159
|
-
break;
|
|
8160
|
-
}
|
|
8161
|
-
}
|
|
8162
|
-
}
|
|
8163
8538
|
break;
|
|
8164
8539
|
}
|
|
8165
8540
|
}
|
|
8166
|
-
if (
|
|
8167
|
-
|
|
8541
|
+
if (yieldEOFToken) {
|
|
8542
|
+
if (buffer.length > 0) {
|
|
8543
|
+
yield pushToken(buffer, parseInfo);
|
|
8544
|
+
}
|
|
8545
|
+
yield pushToken('', parseInfo, exports.EnumToken.EOFTokenType);
|
|
8546
|
+
}
|
|
8547
|
+
else {
|
|
8548
|
+
parseInfo.buffer = buffer;
|
|
8549
|
+
}
|
|
8550
|
+
}
|
|
8551
|
+
/**
|
|
8552
|
+
* tokenize readable stream
|
|
8553
|
+
* @param input
|
|
8554
|
+
*/
|
|
8555
|
+
async function* tokenizeStream(input) {
|
|
8556
|
+
const parseInfo = {
|
|
8557
|
+
stream: '',
|
|
8558
|
+
buffer: '',
|
|
8559
|
+
position: { ind: 0, lin: 1, col: 1 },
|
|
8560
|
+
currentPosition: { ind: -1, lin: 1, col: 0 }
|
|
8561
|
+
};
|
|
8562
|
+
const decoder = new TextDecoder('utf-8');
|
|
8563
|
+
const reader = input.getReader();
|
|
8564
|
+
while (true) {
|
|
8565
|
+
const { done, value } = await reader.read();
|
|
8566
|
+
parseInfo.stream += decoder.decode(value, { stream: true });
|
|
8567
|
+
yield* tokenize$1(parseInfo, done);
|
|
8568
|
+
if (done) {
|
|
8569
|
+
break;
|
|
8570
|
+
}
|
|
8168
8571
|
}
|
|
8169
|
-
yield pushToken('', parseInfo, exports.EnumToken.EOFTokenType);
|
|
8170
8572
|
}
|
|
8171
8573
|
|
|
8172
8574
|
var declarations = {
|
|
@@ -8474,10 +8876,10 @@
|
|
|
8474
8876
|
syntax: "normal | <baseline-position> | <content-distribution> | <overflow-position>? <content-position>"
|
|
8475
8877
|
},
|
|
8476
8878
|
"align-items": {
|
|
8477
|
-
syntax: "normal | stretch | <baseline-position> | [ <overflow-position>? <self-position> ]"
|
|
8879
|
+
syntax: "normal | stretch | <baseline-position> | [ <overflow-position>? <self-position> ] | anchor-center"
|
|
8478
8880
|
},
|
|
8479
8881
|
"align-self": {
|
|
8480
|
-
syntax: "auto | normal | stretch | <baseline-position> | <overflow-position>? <self-position>"
|
|
8882
|
+
syntax: "auto | normal | stretch | <baseline-position> | <overflow-position>? <self-position> | anchor-center"
|
|
8481
8883
|
},
|
|
8482
8884
|
"align-tracks": {
|
|
8483
8885
|
syntax: "[ normal | <baseline-position> | <content-distribution> | <overflow-position>? <content-position> ]#"
|
|
@@ -8537,7 +8939,7 @@
|
|
|
8537
8939
|
syntax: "<easing-function>#"
|
|
8538
8940
|
},
|
|
8539
8941
|
appearance: {
|
|
8540
|
-
syntax: "none | auto |
|
|
8942
|
+
syntax: "none | auto | <compat-auto> | <compat-special>"
|
|
8541
8943
|
},
|
|
8542
8944
|
"aspect-ratio": {
|
|
8543
8945
|
syntax: "auto || <ratio>"
|
|
@@ -8549,7 +8951,7 @@
|
|
|
8549
8951
|
syntax: "visible | hidden"
|
|
8550
8952
|
},
|
|
8551
8953
|
background: {
|
|
8552
|
-
syntax: "
|
|
8954
|
+
syntax: "<bg-layer>#? , <final-bg-layer>"
|
|
8553
8955
|
},
|
|
8554
8956
|
"background-attachment": {
|
|
8555
8957
|
syntax: "<attachment>#"
|
|
@@ -8636,10 +9038,10 @@
|
|
|
8636
9038
|
syntax: "<'border-top-color'>"
|
|
8637
9039
|
},
|
|
8638
9040
|
"border-bottom-left-radius": {
|
|
8639
|
-
syntax: "<length-percentage>{1,2}"
|
|
9041
|
+
syntax: "<length-percentage [0,∞]>{1,2}"
|
|
8640
9042
|
},
|
|
8641
9043
|
"border-bottom-right-radius": {
|
|
8642
|
-
syntax: "<length-percentage>{1,2}"
|
|
9044
|
+
syntax: "<length-percentage [0,∞]>{1,2}"
|
|
8643
9045
|
},
|
|
8644
9046
|
"border-bottom-style": {
|
|
8645
9047
|
syntax: "<line-style>"
|
|
@@ -8648,7 +9050,7 @@
|
|
|
8648
9050
|
syntax: "<line-width>"
|
|
8649
9051
|
},
|
|
8650
9052
|
"border-collapse": {
|
|
8651
|
-
syntax: "
|
|
9053
|
+
syntax: "separate | collapse"
|
|
8652
9054
|
},
|
|
8653
9055
|
"border-color": {
|
|
8654
9056
|
syntax: "<color>{1,4}"
|
|
@@ -8663,19 +9065,19 @@
|
|
|
8663
9065
|
syntax: "<'border-image-source'> || <'border-image-slice'> [ / <'border-image-width'> | / <'border-image-width'>? / <'border-image-outset'> ]? || <'border-image-repeat'>"
|
|
8664
9066
|
},
|
|
8665
9067
|
"border-image-outset": {
|
|
8666
|
-
syntax: "[ <length> | <number> ]{1,4}"
|
|
9068
|
+
syntax: "[ <length [0,∞]> | <number [0,∞]> ]{1,4} "
|
|
8667
9069
|
},
|
|
8668
9070
|
"border-image-repeat": {
|
|
8669
9071
|
syntax: "[ stretch | repeat | round | space ]{1,2}"
|
|
8670
9072
|
},
|
|
8671
9073
|
"border-image-slice": {
|
|
8672
|
-
syntax: "<number
|
|
9074
|
+
syntax: "[ <number [0,∞]> | <percentage [0,∞]> ]{1,4} && fill?"
|
|
8673
9075
|
},
|
|
8674
9076
|
"border-image-source": {
|
|
8675
9077
|
syntax: "none | <image>"
|
|
8676
9078
|
},
|
|
8677
9079
|
"border-image-width": {
|
|
8678
|
-
syntax: "[ <length-percentage> | <number> | auto ]{1,4}"
|
|
9080
|
+
syntax: "[ <length-percentage [0,∞]> | <number [0,∞]> | auto ]{1,4}"
|
|
8679
9081
|
},
|
|
8680
9082
|
"border-inline": {
|
|
8681
9083
|
syntax: "<'border-block-start'>"
|
|
@@ -8726,7 +9128,7 @@
|
|
|
8726
9128
|
syntax: "<line-width>"
|
|
8727
9129
|
},
|
|
8728
9130
|
"border-radius": {
|
|
8729
|
-
syntax: "<length-percentage>{1,4} [ / <length-percentage>{1,4} ]?"
|
|
9131
|
+
syntax: "<length-percentage [0,∞]>{1,4} [ / <length-percentage [0,∞]>{1,4} ]?"
|
|
8730
9132
|
},
|
|
8731
9133
|
"border-right": {
|
|
8732
9134
|
syntax: "<line-width> || <line-style> || <color>"
|
|
@@ -8741,7 +9143,7 @@
|
|
|
8741
9143
|
syntax: "<line-width>"
|
|
8742
9144
|
},
|
|
8743
9145
|
"border-spacing": {
|
|
8744
|
-
syntax: "<length>
|
|
9146
|
+
syntax: "<length>{1,2}"
|
|
8745
9147
|
},
|
|
8746
9148
|
"border-start-end-radius": {
|
|
8747
9149
|
syntax: "<'border-top-left-radius'>"
|
|
@@ -8759,10 +9161,10 @@
|
|
|
8759
9161
|
syntax: "<color>"
|
|
8760
9162
|
},
|
|
8761
9163
|
"border-top-left-radius": {
|
|
8762
|
-
syntax: "<length-percentage>{1,2}"
|
|
9164
|
+
syntax: "<length-percentage [0,∞]>{1,2}"
|
|
8763
9165
|
},
|
|
8764
9166
|
"border-top-right-radius": {
|
|
8765
|
-
syntax: "<length-percentage>{1,2}"
|
|
9167
|
+
syntax: "<length-percentage [0,∞]>{1,2}"
|
|
8766
9168
|
},
|
|
8767
9169
|
"border-top-style": {
|
|
8768
9170
|
syntax: "<line-style>"
|
|
@@ -8774,7 +9176,7 @@
|
|
|
8774
9176
|
syntax: "<line-width>{1,4}"
|
|
8775
9177
|
},
|
|
8776
9178
|
bottom: {
|
|
8777
|
-
syntax: "<length> | <
|
|
9179
|
+
syntax: "auto | <length-percentage> | <anchor()> | <anchor-size()>"
|
|
8778
9180
|
},
|
|
8779
9181
|
"box-align": {
|
|
8780
9182
|
syntax: "start | center | end | baseline | stretch"
|
|
@@ -8909,7 +9311,7 @@
|
|
|
8909
9311
|
syntax: "normal | [ [ size | inline-size ] || scroll-state ]"
|
|
8910
9312
|
},
|
|
8911
9313
|
content: {
|
|
8912
|
-
syntax: "normal | none | [ <content-replacement> | <content-list> ] [/ [ <string> | <counter> ]+ ]?"
|
|
9314
|
+
syntax: "normal | none | [ <content-replacement> | <content-list> ] [ / [ <string> | <counter> | <attr()> ]+ ]?"
|
|
8913
9315
|
},
|
|
8914
9316
|
"content-visibility": {
|
|
8915
9317
|
syntax: "visible | auto | hidden"
|
|
@@ -9203,16 +9605,16 @@
|
|
|
9203
9605
|
syntax: "normal | <content-distribution> | <overflow-position>? [ <content-position> | left | right ]"
|
|
9204
9606
|
},
|
|
9205
9607
|
"justify-items": {
|
|
9206
|
-
syntax: "normal | stretch | <baseline-position> | <overflow-position>? [ <self-position> | left | right ] | legacy | legacy && [ left | right | center ]"
|
|
9608
|
+
syntax: "normal | stretch | <baseline-position> | <overflow-position>? [ <self-position> | left | right ] | legacy | legacy && [ left | right | center ] | anchor-center"
|
|
9207
9609
|
},
|
|
9208
9610
|
"justify-self": {
|
|
9209
|
-
syntax: "auto | normal | stretch | <baseline-position> | <overflow-position>? [ <self-position> | left | right ]"
|
|
9611
|
+
syntax: "auto | normal | stretch | <baseline-position> | <overflow-position>? [ <self-position> | left | right ] | anchor-center"
|
|
9210
9612
|
},
|
|
9211
9613
|
"justify-tracks": {
|
|
9212
9614
|
syntax: "[ normal | <content-distribution> | <overflow-position>? [ <content-position> | left | right ] ]#"
|
|
9213
9615
|
},
|
|
9214
9616
|
left: {
|
|
9215
|
-
syntax: "<length> | <
|
|
9617
|
+
syntax: "auto | <length-percentage> | <anchor()> | <anchor-size()>"
|
|
9216
9618
|
},
|
|
9217
9619
|
"letter-spacing": {
|
|
9218
9620
|
syntax: "normal | <length> normal | <length-percentage>"
|
|
@@ -9257,7 +9659,7 @@
|
|
|
9257
9659
|
syntax: "<'margin-top'>"
|
|
9258
9660
|
},
|
|
9259
9661
|
"margin-bottom": {
|
|
9260
|
-
syntax: "<length-percentage> | auto"
|
|
9662
|
+
syntax: "<length-percentage> | auto | <anchor-size()>"
|
|
9261
9663
|
},
|
|
9262
9664
|
"margin-inline": {
|
|
9263
9665
|
syntax: "<'margin-top'>{1,2}"
|
|
@@ -9269,13 +9671,13 @@
|
|
|
9269
9671
|
syntax: "<'margin-top'>"
|
|
9270
9672
|
},
|
|
9271
9673
|
"margin-left": {
|
|
9272
|
-
syntax: "<length-percentage> | auto"
|
|
9674
|
+
syntax: "<length-percentage> | auto | <anchor-size()>"
|
|
9273
9675
|
},
|
|
9274
9676
|
"margin-right": {
|
|
9275
|
-
syntax: "<length-percentage> | auto"
|
|
9677
|
+
syntax: "<length-percentage> | auto | <anchor-size()>"
|
|
9276
9678
|
},
|
|
9277
9679
|
"margin-top": {
|
|
9278
|
-
syntax: "<length-percentage> | auto"
|
|
9680
|
+
syntax: "<length-percentage> | auto | <anchor-size()>"
|
|
9279
9681
|
},
|
|
9280
9682
|
"margin-trim": {
|
|
9281
9683
|
syntax: "none | in-flow | all"
|
|
@@ -9383,7 +9785,7 @@
|
|
|
9383
9785
|
syntax: "auto | <length-percentage [0,∞]> | min-content | max-content | fit-content | fit-content(<length-percentage [0,∞]>) | <calc-size()> | <anchor-size()> | stretch | <-non-standard-size>"
|
|
9384
9786
|
},
|
|
9385
9787
|
"mix-blend-mode": {
|
|
9386
|
-
syntax: "<blend-mode> | plus-lighter"
|
|
9788
|
+
syntax: "<blend-mode> | plus-darker | plus-lighter"
|
|
9387
9789
|
},
|
|
9388
9790
|
"object-fit": {
|
|
9389
9791
|
syntax: "fill | contain | cover | none | scale-down"
|
|
@@ -9581,7 +9983,7 @@
|
|
|
9581
9983
|
syntax: "none | both | horizontal | vertical | block | inline"
|
|
9582
9984
|
},
|
|
9583
9985
|
right: {
|
|
9584
|
-
syntax: "<length> | <
|
|
9986
|
+
syntax: "auto | <length-percentage> | <anchor()> | <anchor-size()>"
|
|
9585
9987
|
},
|
|
9586
9988
|
rotate: {
|
|
9587
9989
|
syntax: "none | <angle> | [ x | y | z | <number>{3} ] && <angle>"
|
|
@@ -9881,7 +10283,7 @@
|
|
|
9881
10283
|
syntax: "none | <dashed-ident>#"
|
|
9882
10284
|
},
|
|
9883
10285
|
top: {
|
|
9884
|
-
syntax: "<length> | <
|
|
10286
|
+
syntax: "auto | <length-percentage> | <anchor()> | <anchor-size()>"
|
|
9885
10287
|
},
|
|
9886
10288
|
"touch-action": {
|
|
9887
10289
|
syntax: "auto | none | [ [ pan-x | pan-left | pan-right ] || [ pan-y | pan-up | pan-down ] || pinch-zoom ] | manipulation"
|
|
@@ -10560,7 +10962,7 @@
|
|
|
10560
10962
|
syntax: "<visual-box> | border-area | text"
|
|
10561
10963
|
},
|
|
10562
10964
|
"bg-image": {
|
|
10563
|
-
syntax: "
|
|
10965
|
+
syntax: "<image> | none"
|
|
10564
10966
|
},
|
|
10565
10967
|
"bg-layer": {
|
|
10566
10968
|
syntax: "<bg-image> || <bg-position> [ / <bg-size> ]? || <repeat-style> || <attachment> || <visual-box> || <visual-box>"
|
|
@@ -10569,7 +10971,7 @@
|
|
|
10569
10971
|
syntax: "[ [ left | center | right | top | bottom | <length-percentage> ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ] | [ center | [ left | right ] <length-percentage>? ] && [ center | [ top | bottom ] <length-percentage>? ] ]"
|
|
10570
10972
|
},
|
|
10571
10973
|
"bg-size": {
|
|
10572
|
-
syntax: "[ <length-percentage> | auto ]{1,2} | cover | contain"
|
|
10974
|
+
syntax: "[ <length-percentage [0,∞]> | auto ]{1,2} | cover | contain"
|
|
10573
10975
|
},
|
|
10574
10976
|
"blend-mode": {
|
|
10575
10977
|
syntax: "normal | multiply | screen | overlay | darken | lighten | color-dodge | color-burn | hard-light | soft-light | difference | exclusion | hue | saturation | color | luminosity"
|
|
@@ -10659,7 +11061,10 @@
|
|
|
10659
11061
|
syntax: "[ common-ligatures | no-common-ligatures ]"
|
|
10660
11062
|
},
|
|
10661
11063
|
"compat-auto": {
|
|
10662
|
-
syntax: "searchfield | textarea |
|
|
11064
|
+
syntax: "searchfield | textarea | checkbox | radio | menulist | listbox | meter | progress-bar | button"
|
|
11065
|
+
},
|
|
11066
|
+
"compat-special": {
|
|
11067
|
+
syntax: "textfield | menulist-button"
|
|
10663
11068
|
},
|
|
10664
11069
|
"complex-selector": {
|
|
10665
11070
|
syntax: "<complex-selector-unit> [ <combinator>? <complex-selector-unit> ]*"
|
|
@@ -10839,7 +11244,7 @@
|
|
|
10839
11244
|
syntax: "[ <filter-function> | <url> ]+"
|
|
10840
11245
|
},
|
|
10841
11246
|
"final-bg-layer": {
|
|
10842
|
-
syntax: "<
|
|
11247
|
+
syntax: "<bg-image> || <bg-position> [ / <bg-size> ]? || <repeat-style> || <attachment> || <visual-box> || <visual-box> || <'background-color'>"
|
|
10843
11248
|
},
|
|
10844
11249
|
"fit-content()": {
|
|
10845
11250
|
syntax: "fit-content( <length-percentage [0,∞]> )"
|
|
@@ -16666,10 +17071,12 @@
|
|
|
16666
17071
|
}
|
|
16667
17072
|
/**
|
|
16668
17073
|
* parse css string
|
|
16669
|
-
* @param
|
|
17074
|
+
* @param iter
|
|
16670
17075
|
* @param options
|
|
17076
|
+
*
|
|
17077
|
+
* @private
|
|
16671
17078
|
*/
|
|
16672
|
-
async function doParse(
|
|
17079
|
+
async function doParse(iter, options = {}) {
|
|
16673
17080
|
if (options.signal != null) {
|
|
16674
17081
|
options.signal.addEventListener('abort', reject);
|
|
16675
17082
|
}
|
|
@@ -16739,12 +17146,13 @@
|
|
|
16739
17146
|
src: ''
|
|
16740
17147
|
};
|
|
16741
17148
|
}
|
|
16742
|
-
const iter = tokenize$1(iterator);
|
|
16743
17149
|
let item;
|
|
16744
17150
|
let node;
|
|
16745
17151
|
const rawTokens = [];
|
|
16746
17152
|
const imports = [];
|
|
16747
|
-
|
|
17153
|
+
// @ts-ignore ignore error
|
|
17154
|
+
const isAsync = typeof iter[Symbol.asyncIterator] === 'function';
|
|
17155
|
+
while (item = isAsync ? (await iter.next()).value : iter.next().value) {
|
|
16748
17156
|
stats.bytesIn = item.bytesIn;
|
|
16749
17157
|
rawTokens.push(item);
|
|
16750
17158
|
if (item.hint != null && BadTokensTypes.includes(item.hint)) {
|
|
@@ -16788,7 +17196,7 @@
|
|
|
16788
17196
|
let inBlock = 1;
|
|
16789
17197
|
tokens = [item];
|
|
16790
17198
|
do {
|
|
16791
|
-
item = iter.next().value;
|
|
17199
|
+
item = isAsync ? (await iter.next()).value : iter.next().value;
|
|
16792
17200
|
if (item == null) {
|
|
16793
17201
|
break;
|
|
16794
17202
|
}
|
|
@@ -16850,8 +17258,8 @@
|
|
|
16850
17258
|
}
|
|
16851
17259
|
}
|
|
16852
17260
|
if (context != null && context.typ == exports.EnumToken.InvalidRuleTokenType) {
|
|
16853
|
-
// @ts-ignore
|
|
16854
|
-
const index = context.chi.findIndex((node) => node
|
|
17261
|
+
// @ts-ignore ignore error
|
|
17262
|
+
const index = context.chi.findIndex((node) => node === context);
|
|
16855
17263
|
if (index > -1) {
|
|
16856
17264
|
context.chi.splice(index, 1);
|
|
16857
17265
|
}
|
|
@@ -16862,13 +17270,21 @@
|
|
|
16862
17270
|
const token = node.tokens[0];
|
|
16863
17271
|
const url = token.typ == exports.EnumToken.StringTokenType ? token.val.slice(1, -1) : token.val;
|
|
16864
17272
|
try {
|
|
16865
|
-
const root = await options.
|
|
16866
|
-
return doParse(
|
|
17273
|
+
const root = await options.getStream(url, options.src).then(async (stream) => {
|
|
17274
|
+
return doParse(tokenizeStream(stream), Object.assign({}, options, {
|
|
16867
17275
|
minify: false,
|
|
16868
17276
|
setParent: false,
|
|
16869
17277
|
src: options.resolve(url, options.src).absolute
|
|
16870
|
-
}));
|
|
17278
|
+
})); // )
|
|
16871
17279
|
});
|
|
17280
|
+
// const root: ParseResult = await options.load!(url, <string>options.src).then((src: string) => {
|
|
17281
|
+
//
|
|
17282
|
+
// return doParse(src, Object.assign({}, options, {
|
|
17283
|
+
// minify: false,
|
|
17284
|
+
// setParent: false,
|
|
17285
|
+
// src: options.resolve!(url, options.src as string).absolute
|
|
17286
|
+
// }))
|
|
17287
|
+
// });
|
|
16872
17288
|
stats.importedBytesIn += root.stats.bytesIn;
|
|
16873
17289
|
stats.imports.push(root.stats);
|
|
16874
17290
|
node.parent.chi.splice(node.parent.chi.indexOf(node), 1, ...root.ast.chi);
|
|
@@ -16877,7 +17293,7 @@
|
|
|
16877
17293
|
}
|
|
16878
17294
|
}
|
|
16879
17295
|
catch (error) {
|
|
16880
|
-
// @ts-ignore
|
|
17296
|
+
// @ts-ignore ignore error
|
|
16881
17297
|
errors.push({ action: 'ignore', message: 'doParse: ' + error.message, error });
|
|
16882
17298
|
}
|
|
16883
17299
|
}));
|
|
@@ -16901,28 +17317,33 @@
|
|
|
16901
17317
|
if (result.node.typ == exports.EnumToken.DeclarationNodeType &&
|
|
16902
17318
|
(typeof options.visitor.Declaration == 'function' || options.visitor.Declaration?.[result.node.nam] != null)) {
|
|
16903
17319
|
const callable = typeof options.visitor.Declaration == 'function' ? options.visitor.Declaration : options.visitor.Declaration[result.node.nam];
|
|
16904
|
-
const
|
|
17320
|
+
const isAsync = Object.getPrototypeOf(callable).constructor.name == 'AsyncFunction';
|
|
17321
|
+
const results = isAsync ? await callable(result.node) : callable(result.node);
|
|
16905
17322
|
if (results == null || (Array.isArray(results) && results.length == 0)) {
|
|
16906
17323
|
continue;
|
|
16907
17324
|
}
|
|
17325
|
+
// @ts-ignore
|
|
16908
17326
|
result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
|
|
16909
17327
|
}
|
|
16910
17328
|
else if (options.visitor.Rule != null && result.node.typ == exports.EnumToken.RuleNodeType) {
|
|
16911
|
-
const
|
|
17329
|
+
const isAsync = Object.getPrototypeOf(options.visitor.Rule).constructor.name == 'AsyncFunction';
|
|
17330
|
+
const results = isAsync ? await options.visitor.Rule(result.node) : options.visitor.Rule(result.node);
|
|
16912
17331
|
if (results == null || (Array.isArray(results) && results.length == 0)) {
|
|
16913
17332
|
continue;
|
|
16914
17333
|
}
|
|
17334
|
+
// @ts-ignore
|
|
16915
17335
|
result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
|
|
16916
17336
|
}
|
|
16917
17337
|
else if (options.visitor.AtRule != null &&
|
|
16918
17338
|
result.node.typ == exports.EnumToken.AtRuleNodeType &&
|
|
16919
|
-
// @ts-ignore
|
|
16920
17339
|
(typeof options.visitor.AtRule == 'function' || options.visitor.AtRule?.[result.node.nam] != null)) {
|
|
16921
17340
|
const callable = typeof options.visitor.AtRule == 'function' ? options.visitor.AtRule : options.visitor.AtRule[result.node.nam];
|
|
16922
|
-
const
|
|
17341
|
+
const isAsync = Object.getPrototypeOf(callable).constructor.name == 'AsyncFunction';
|
|
17342
|
+
const results = isAsync ? await callable(result.node) : callable(result.node);
|
|
16923
17343
|
if (results == null || (Array.isArray(results) && results.length == 0)) {
|
|
16924
17344
|
continue;
|
|
16925
17345
|
}
|
|
17346
|
+
// @ts-ignore
|
|
16926
17347
|
result.parent.chi.splice(result.parent.chi.indexOf(result.node), 1, ...(Array.isArray(results) ? results : [results]));
|
|
16927
17348
|
}
|
|
16928
17349
|
}
|
|
@@ -17033,7 +17454,13 @@
|
|
|
17033
17454
|
// @ts-ignore
|
|
17034
17455
|
['charset', 'layer', 'import'].includes(context.chi[i].nam))) {
|
|
17035
17456
|
// @ts-ignore
|
|
17036
|
-
errors.push({
|
|
17457
|
+
errors.push({
|
|
17458
|
+
action: 'drop',
|
|
17459
|
+
message: 'invalid @import',
|
|
17460
|
+
location,
|
|
17461
|
+
// @ts-ignore
|
|
17462
|
+
rawTokens: [atRule, ...tokens]
|
|
17463
|
+
});
|
|
17037
17464
|
return null;
|
|
17038
17465
|
}
|
|
17039
17466
|
}
|
|
@@ -17390,7 +17817,7 @@
|
|
|
17390
17817
|
return null;
|
|
17391
17818
|
}
|
|
17392
17819
|
for (const { value: token } of walkValues(value, null, {
|
|
17393
|
-
fn: (node) => node.typ == exports.EnumToken.FunctionTokenType && node.val == 'calc' ? WalkerOptionEnum.IgnoreChildren : null,
|
|
17820
|
+
fn: (node) => node.typ == exports.EnumToken.FunctionTokenType && node.val == 'calc' ? exports.WalkerOptionEnum.IgnoreChildren : null,
|
|
17394
17821
|
type: exports.EnumToken.FunctionTokenType
|
|
17395
17822
|
})) {
|
|
17396
17823
|
if (token.typ == exports.EnumToken.FunctionTokenType && token.val == 'calc') {
|
|
@@ -17630,6 +18057,27 @@
|
|
|
17630
18057
|
}
|
|
17631
18058
|
return tokens;
|
|
17632
18059
|
}
|
|
18060
|
+
/**
|
|
18061
|
+
* parse a string as an array of declaration nodes
|
|
18062
|
+
* @param declaration
|
|
18063
|
+
*
|
|
18064
|
+
* Example:
|
|
18065
|
+
* ````ts
|
|
18066
|
+
*
|
|
18067
|
+
* const declarations = await parseDeclarations('color: red; background: blue');
|
|
18068
|
+
* console.log(declarations);
|
|
18069
|
+
* ```
|
|
18070
|
+
*/
|
|
18071
|
+
async function parseDeclarations(declaration) {
|
|
18072
|
+
return doParse(tokenize$1({
|
|
18073
|
+
stream: `.x{${declaration}}`,
|
|
18074
|
+
buffer: '',
|
|
18075
|
+
position: { ind: 0, lin: 1, col: 1 },
|
|
18076
|
+
currentPosition: { ind: -1, lin: 1, col: 0 }
|
|
18077
|
+
}), { setParent: false, minify: false, validation: false }).then(result => {
|
|
18078
|
+
return result.ast.chi[0].chi.filter(t => t.typ == exports.EnumToken.DeclarationNodeType);
|
|
18079
|
+
});
|
|
18080
|
+
}
|
|
17633
18081
|
/**
|
|
17634
18082
|
* parse selector
|
|
17635
18083
|
* @param tokens
|
|
@@ -17731,12 +18179,33 @@
|
|
|
17731
18179
|
return tokens;
|
|
17732
18180
|
}
|
|
17733
18181
|
/**
|
|
17734
|
-
* parse css string
|
|
18182
|
+
* parse css string and return an array of tokens
|
|
17735
18183
|
* @param src
|
|
17736
18184
|
* @param options
|
|
18185
|
+
*
|
|
18186
|
+
* @private
|
|
18187
|
+
*
|
|
18188
|
+
* Example:
|
|
18189
|
+
*
|
|
18190
|
+
* ```ts
|
|
18191
|
+
*
|
|
18192
|
+
* import {parseString} from '@tbela99/css-parser';
|
|
18193
|
+
*
|
|
18194
|
+
* let tokens = parseString('body { color: red; }');
|
|
18195
|
+
* console.log(tokens);
|
|
18196
|
+
*
|
|
18197
|
+
* tokens = parseString('#c322c980');
|
|
18198
|
+
* console.log(tokens);
|
|
18199
|
+
* ```
|
|
17737
18200
|
*/
|
|
17738
18201
|
function parseString(src, options = { location: false }) {
|
|
17739
|
-
|
|
18202
|
+
const parseInfo = {
|
|
18203
|
+
stream: src,
|
|
18204
|
+
buffer: '',
|
|
18205
|
+
position: { ind: 0, lin: 1, col: 1 },
|
|
18206
|
+
currentPosition: { ind: -1, lin: 1, col: 0 }
|
|
18207
|
+
};
|
|
18208
|
+
return parseTokens([...tokenize$1(parseInfo)].reduce((acc, t) => {
|
|
17740
18209
|
if (t.hint == exports.EnumToken.EOFTokenType) {
|
|
17741
18210
|
return acc;
|
|
17742
18211
|
}
|
|
@@ -17748,6 +18217,11 @@
|
|
|
17748
18217
|
return acc;
|
|
17749
18218
|
}, []));
|
|
17750
18219
|
}
|
|
18220
|
+
/**
|
|
18221
|
+
* get token type from a string
|
|
18222
|
+
* @param val
|
|
18223
|
+
* @param hint
|
|
18224
|
+
*/
|
|
17751
18225
|
function getTokenType(val, hint) {
|
|
17752
18226
|
if (hint != null) {
|
|
17753
18227
|
return enumTokenHints.has(hint) ? { typ: hint } : { typ: hint, val };
|
|
@@ -17913,9 +18387,24 @@
|
|
|
17913
18387
|
};
|
|
17914
18388
|
}
|
|
17915
18389
|
/**
|
|
17916
|
-
* parse
|
|
18390
|
+
* parse function tokens in a token array
|
|
17917
18391
|
* @param tokens
|
|
17918
18392
|
* @param options
|
|
18393
|
+
*
|
|
18394
|
+
* Example:
|
|
18395
|
+
*
|
|
18396
|
+
* ```ts
|
|
18397
|
+
*
|
|
18398
|
+
* import {parseString, parseTokens} from '@tbela99/css-parser';
|
|
18399
|
+
*
|
|
18400
|
+
* let tokens = parseString('body { color: red; }');
|
|
18401
|
+
* console.log(parseTokens(tokens));
|
|
18402
|
+
*
|
|
18403
|
+
* tokens = parseString('#c322c980');
|
|
18404
|
+
* console.log(parseTokens(tokens));
|
|
18405
|
+
* ```
|
|
18406
|
+
*
|
|
18407
|
+
* @private
|
|
17919
18408
|
*/
|
|
17920
18409
|
function parseTokens(tokens, options = {}) {
|
|
17921
18410
|
for (let i = 0; i < tokens.length; i++) {
|
|
@@ -18239,18 +18728,36 @@
|
|
|
18239
18728
|
return true;
|
|
18240
18729
|
}
|
|
18241
18730
|
|
|
18242
|
-
|
|
18731
|
+
exports.WalkerOptionEnum = void 0;
|
|
18243
18732
|
(function (WalkerOptionEnum) {
|
|
18733
|
+
/**
|
|
18734
|
+
* ignore the current node and its children
|
|
18735
|
+
*/
|
|
18244
18736
|
WalkerOptionEnum[WalkerOptionEnum["Ignore"] = 0] = "Ignore";
|
|
18737
|
+
/**
|
|
18738
|
+
* stop walking the tree
|
|
18739
|
+
*/
|
|
18245
18740
|
WalkerOptionEnum[WalkerOptionEnum["Stop"] = 1] = "Stop";
|
|
18741
|
+
/**
|
|
18742
|
+
* ignore node and process children
|
|
18743
|
+
*/
|
|
18246
18744
|
WalkerOptionEnum[WalkerOptionEnum["Children"] = 2] = "Children";
|
|
18745
|
+
/**
|
|
18746
|
+
* ignore children
|
|
18747
|
+
*/
|
|
18247
18748
|
WalkerOptionEnum[WalkerOptionEnum["IgnoreChildren"] = 3] = "IgnoreChildren";
|
|
18248
|
-
})(WalkerOptionEnum || (WalkerOptionEnum = {}));
|
|
18249
|
-
|
|
18749
|
+
})(exports.WalkerOptionEnum || (exports.WalkerOptionEnum = {}));
|
|
18750
|
+
exports.WalkerValueEvent = void 0;
|
|
18250
18751
|
(function (WalkerValueEvent) {
|
|
18752
|
+
/**
|
|
18753
|
+
* enter node
|
|
18754
|
+
*/
|
|
18251
18755
|
WalkerValueEvent[WalkerValueEvent["Enter"] = 0] = "Enter";
|
|
18756
|
+
/**
|
|
18757
|
+
* leave node
|
|
18758
|
+
*/
|
|
18252
18759
|
WalkerValueEvent[WalkerValueEvent["Leave"] = 1] = "Leave";
|
|
18253
|
-
})(WalkerValueEvent || (WalkerValueEvent = {}));
|
|
18760
|
+
})(exports.WalkerValueEvent || (exports.WalkerValueEvent = {}));
|
|
18254
18761
|
/**
|
|
18255
18762
|
* walk ast nodes
|
|
18256
18763
|
* @param node
|
|
@@ -18264,10 +18771,10 @@
|
|
|
18264
18771
|
let option = null;
|
|
18265
18772
|
if (filter != null) {
|
|
18266
18773
|
option = filter(node);
|
|
18267
|
-
if (option === WalkerOptionEnum.Ignore) {
|
|
18774
|
+
if (option === exports.WalkerOptionEnum.Ignore) {
|
|
18268
18775
|
continue;
|
|
18269
18776
|
}
|
|
18270
|
-
if (option === WalkerOptionEnum.Stop) {
|
|
18777
|
+
if (option === exports.WalkerOptionEnum.Stop) {
|
|
18271
18778
|
break;
|
|
18272
18779
|
}
|
|
18273
18780
|
}
|
|
@@ -18276,7 +18783,7 @@
|
|
|
18276
18783
|
// @ts-ignore
|
|
18277
18784
|
yield { node, parent: map.get(node), root };
|
|
18278
18785
|
}
|
|
18279
|
-
if (option !== WalkerOptionEnum.IgnoreChildren && 'chi' in node) {
|
|
18786
|
+
if (option !== exports.WalkerOptionEnum.IgnoreChildren && 'chi' in node) {
|
|
18280
18787
|
parents.unshift(...node.chi);
|
|
18281
18788
|
for (const child of node.chi.slice()) {
|
|
18282
18789
|
map.set(child, node);
|
|
@@ -18299,29 +18806,29 @@
|
|
|
18299
18806
|
// let parent: FunctionToken | ParensToken | BinaryExpressionToken | null = null;
|
|
18300
18807
|
if (filter != null && typeof filter == 'function') {
|
|
18301
18808
|
filter = {
|
|
18302
|
-
event: WalkerValueEvent.Enter,
|
|
18809
|
+
event: exports.WalkerValueEvent.Enter,
|
|
18303
18810
|
fn: filter
|
|
18304
18811
|
};
|
|
18305
18812
|
}
|
|
18306
18813
|
else if (filter == null) {
|
|
18307
18814
|
filter = {
|
|
18308
|
-
event: WalkerValueEvent.Enter
|
|
18815
|
+
event: exports.WalkerValueEvent.Enter
|
|
18309
18816
|
};
|
|
18310
18817
|
}
|
|
18311
|
-
const eventType = filter.event ?? WalkerValueEvent.Enter;
|
|
18818
|
+
const eventType = filter.event ?? exports.WalkerValueEvent.Enter;
|
|
18312
18819
|
while (stack.length > 0) {
|
|
18313
18820
|
let value = reverse ? stack.pop() : stack.shift();
|
|
18314
18821
|
let option = null;
|
|
18315
|
-
if (filter.fn != null && eventType == WalkerValueEvent.Enter) {
|
|
18822
|
+
if (filter.fn != null && eventType == exports.WalkerValueEvent.Enter) {
|
|
18316
18823
|
const isValid = filter.type == null || value.typ == filter.type ||
|
|
18317
18824
|
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
18318
18825
|
(typeof filter.type == 'function' && filter.type(value));
|
|
18319
18826
|
if (isValid) {
|
|
18320
18827
|
option = filter.fn(value, map.get(value) ?? root);
|
|
18321
|
-
if (option === WalkerOptionEnum.Ignore) {
|
|
18828
|
+
if (option === exports.WalkerOptionEnum.Ignore) {
|
|
18322
18829
|
continue;
|
|
18323
18830
|
}
|
|
18324
|
-
if (option === WalkerOptionEnum.Stop) {
|
|
18831
|
+
if (option === exports.WalkerOptionEnum.Stop) {
|
|
18325
18832
|
break;
|
|
18326
18833
|
}
|
|
18327
18834
|
// @ts-ignore
|
|
@@ -18330,7 +18837,7 @@
|
|
|
18330
18837
|
}
|
|
18331
18838
|
}
|
|
18332
18839
|
}
|
|
18333
|
-
if (eventType == WalkerValueEvent.Enter && option !== WalkerOptionEnum.Children) {
|
|
18840
|
+
if (eventType == exports.WalkerValueEvent.Enter && option !== exports.WalkerOptionEnum.Children) {
|
|
18334
18841
|
yield {
|
|
18335
18842
|
value,
|
|
18336
18843
|
parent: map.get(value) ?? root,
|
|
@@ -18340,7 +18847,7 @@
|
|
|
18340
18847
|
root: root ?? null
|
|
18341
18848
|
};
|
|
18342
18849
|
}
|
|
18343
|
-
if (option !== WalkerOptionEnum.IgnoreChildren && 'chi' in value) {
|
|
18850
|
+
if (option !== exports.WalkerOptionEnum.IgnoreChildren && 'chi' in value) {
|
|
18344
18851
|
const sliced = value.chi.slice();
|
|
18345
18852
|
for (const child of sliced) {
|
|
18346
18853
|
map.set(child, value);
|
|
@@ -18385,7 +18892,7 @@
|
|
|
18385
18892
|
stack.unshift(...values);
|
|
18386
18893
|
}
|
|
18387
18894
|
}
|
|
18388
|
-
if (eventType == WalkerValueEvent.Leave && filter.fn != null) {
|
|
18895
|
+
if (eventType == exports.WalkerValueEvent.Leave && filter.fn != null) {
|
|
18389
18896
|
const isValid = filter.type == null || value.typ == filter.type ||
|
|
18390
18897
|
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
18391
18898
|
(typeof filter.type == 'function' && filter.type(value));
|
|
@@ -18397,7 +18904,7 @@
|
|
|
18397
18904
|
}
|
|
18398
18905
|
}
|
|
18399
18906
|
}
|
|
18400
|
-
if (eventType == WalkerValueEvent.Leave && option !== WalkerOptionEnum.Children) {
|
|
18907
|
+
if (eventType == exports.WalkerValueEvent.Leave && option !== exports.WalkerOptionEnum.Children) {
|
|
18401
18908
|
yield {
|
|
18402
18909
|
value,
|
|
18403
18910
|
parent: map.get(value) ?? root,
|
|
@@ -19657,7 +20164,7 @@
|
|
|
19657
20164
|
}
|
|
19658
20165
|
const set = new Set;
|
|
19659
20166
|
for (const { value, parent } of walkValues(node.val, node, {
|
|
19660
|
-
event: WalkerValueEvent.Enter,
|
|
20167
|
+
event: exports.WalkerValueEvent.Enter,
|
|
19661
20168
|
// @ts-ignore
|
|
19662
20169
|
fn(node, parent) {
|
|
19663
20170
|
if (parent != null &&
|
|
@@ -19669,7 +20176,7 @@
|
|
|
19669
20176
|
mathFuncs.includes(node.val) &&
|
|
19670
20177
|
node.chi.length == 1 &&
|
|
19671
20178
|
node.chi[0].typ == exports.EnumToken.IdenTokenType) {
|
|
19672
|
-
return WalkerOptionEnum.Ignore;
|
|
20179
|
+
return exports.WalkerOptionEnum.Ignore;
|
|
19673
20180
|
}
|
|
19674
20181
|
if ((node.typ == exports.EnumToken.FunctionTokenType && node.val == 'var') || (!mathFuncs.includes(parent.val) && [exports.EnumToken.ColorTokenType, exports.EnumToken.DeclarationNodeType, exports.EnumToken.RuleNodeType, exports.EnumToken.AtRuleNodeType, exports.EnumToken.StyleSheetNodeType].includes(parent?.typ))) {
|
|
19675
20182
|
return null;
|
|
@@ -19685,7 +20192,7 @@
|
|
|
19685
20192
|
// @ts-ignore
|
|
19686
20193
|
node[key] = slice;
|
|
19687
20194
|
}
|
|
19688
|
-
return WalkerOptionEnum.Ignore;
|
|
20195
|
+
return exports.WalkerOptionEnum.Ignore;
|
|
19689
20196
|
}
|
|
19690
20197
|
return null;
|
|
19691
20198
|
}
|
|
@@ -20839,11 +21346,20 @@
|
|
|
20839
21346
|
TransformCssFeature: TransformCssFeature
|
|
20840
21347
|
});
|
|
20841
21348
|
|
|
20842
|
-
|
|
21349
|
+
/**
|
|
21350
|
+
* feature walk mode
|
|
21351
|
+
*/
|
|
21352
|
+
exports.FeatureWalkMode = void 0;
|
|
20843
21353
|
(function (FeatureWalkMode) {
|
|
21354
|
+
/**
|
|
21355
|
+
* pre process
|
|
21356
|
+
*/
|
|
20844
21357
|
FeatureWalkMode[FeatureWalkMode["Pre"] = 0] = "Pre";
|
|
21358
|
+
/**
|
|
21359
|
+
* post process
|
|
21360
|
+
*/
|
|
20845
21361
|
FeatureWalkMode[FeatureWalkMode["Post"] = 1] = "Post";
|
|
20846
|
-
})(FeatureWalkMode || (FeatureWalkMode = {}));
|
|
21362
|
+
})(exports.FeatureWalkMode || (exports.FeatureWalkMode = {}));
|
|
20847
21363
|
|
|
20848
21364
|
const combinators = ['+', '>', '~', '||', '|'];
|
|
20849
21365
|
const definedPropertySettings = { configurable: true, enumerable: false, writable: true };
|
|
@@ -20851,13 +21367,14 @@
|
|
|
20851
21367
|
// @ts-ignore
|
|
20852
21368
|
const features = Object.values(allFeatures).sort((a, b) => a.ordering - b.ordering);
|
|
20853
21369
|
/**
|
|
20854
|
-
*
|
|
21370
|
+
* apply minification rules to the ast tree
|
|
20855
21371
|
* @param ast
|
|
20856
21372
|
* @param options
|
|
20857
21373
|
* @param recursive
|
|
20858
21374
|
* @param errors
|
|
20859
21375
|
* @param nestingContent
|
|
20860
|
-
*
|
|
21376
|
+
*
|
|
21377
|
+
* @private
|
|
20861
21378
|
*/
|
|
20862
21379
|
function minify(ast, options = {}, recursive = false, errors, nestingContent, context = {}) {
|
|
20863
21380
|
let preprocess = false;
|
|
@@ -20901,7 +21418,7 @@
|
|
|
20901
21418
|
if (!feature.preProcess) {
|
|
20902
21419
|
continue;
|
|
20903
21420
|
}
|
|
20904
|
-
feature.run(parent, options, parent.parent ?? ast, context, FeatureWalkMode.Pre);
|
|
21421
|
+
feature.run(parent, options, parent.parent ?? ast, context, exports.FeatureWalkMode.Pre);
|
|
20905
21422
|
}
|
|
20906
21423
|
if (('chi' in parent)) {
|
|
20907
21424
|
// @ts-ignore
|
|
@@ -20916,14 +21433,13 @@
|
|
|
20916
21433
|
for (const feature of options.features) {
|
|
20917
21434
|
if (feature.preProcess && 'cleanup' in feature) {
|
|
20918
21435
|
// @ts-ignore
|
|
20919
|
-
feature.cleanup(ast, options, context, FeatureWalkMode.Pre);
|
|
21436
|
+
feature.cleanup(ast, options, context, exports.FeatureWalkMode.Pre);
|
|
20920
21437
|
}
|
|
20921
21438
|
}
|
|
20922
21439
|
}
|
|
20923
21440
|
doMinify(ast, options, recursive, errors, nestingContent, context);
|
|
20924
21441
|
parents = [ast];
|
|
20925
21442
|
for (const parent of parents) {
|
|
20926
|
-
// parent = parents.shift() as AstNode;
|
|
20927
21443
|
if (parent.typ == exports.EnumToken.CommentTokenType ||
|
|
20928
21444
|
parent.typ == exports.EnumToken.CDOCOMMTokenType) {
|
|
20929
21445
|
continue;
|
|
@@ -20933,7 +21449,7 @@
|
|
|
20933
21449
|
if (!feature.postProcess) {
|
|
20934
21450
|
continue;
|
|
20935
21451
|
}
|
|
20936
|
-
feature.run(parent, options, parent.parent ?? ast, context, FeatureWalkMode.Post);
|
|
21452
|
+
feature.run(parent, options, parent.parent ?? ast, context, exports.FeatureWalkMode.Post);
|
|
20937
21453
|
}
|
|
20938
21454
|
}
|
|
20939
21455
|
if (('chi' in parent)) {
|
|
@@ -20950,12 +21466,21 @@
|
|
|
20950
21466
|
for (const feature of options.features) {
|
|
20951
21467
|
if (feature.postProcess && 'cleanup' in feature) {
|
|
20952
21468
|
// @ts-ignore
|
|
20953
|
-
feature.cleanup(ast, options, context, FeatureWalkMode.Post);
|
|
21469
|
+
feature.cleanup(ast, options, context, exports.FeatureWalkMode.Post);
|
|
20954
21470
|
}
|
|
20955
21471
|
}
|
|
20956
21472
|
}
|
|
20957
21473
|
return ast;
|
|
20958
21474
|
}
|
|
21475
|
+
/**
|
|
21476
|
+
* reduce selectors
|
|
21477
|
+
* @param acc
|
|
21478
|
+
* @param curr
|
|
21479
|
+
* @param index
|
|
21480
|
+
* @param array
|
|
21481
|
+
*
|
|
21482
|
+
* @private
|
|
21483
|
+
*/
|
|
20959
21484
|
function reduce(acc, curr, index, array) {
|
|
20960
21485
|
// trim :is()
|
|
20961
21486
|
// if (array.length == 1 && array[0][0] == ':is(' && array[0].at(-1) == ')') {
|
|
@@ -20966,20 +21491,21 @@
|
|
|
20966
21491
|
if (curr[1] == ' ' && !isIdent(curr[2]) && !isFunction(curr[2])) {
|
|
20967
21492
|
curr.splice(0, 2);
|
|
20968
21493
|
}
|
|
20969
|
-
// else if (combinators.includes(curr[1])) {
|
|
20970
|
-
//
|
|
20971
|
-
// curr.shift();
|
|
20972
|
-
// }
|
|
20973
21494
|
}
|
|
20974
|
-
// else { // @ts-ignore
|
|
20975
|
-
// if (this.typ == EnumToken.RuleNodeType && (isIdent(curr[0]) || isFunction(curr[0]))) {
|
|
20976
|
-
//
|
|
20977
|
-
// curr.unshift('&', ' ');
|
|
20978
|
-
// }
|
|
20979
|
-
// }
|
|
20980
21495
|
acc.push(curr.join(''));
|
|
20981
21496
|
return acc;
|
|
20982
21497
|
}
|
|
21498
|
+
/**
|
|
21499
|
+
* apply minification rules to the ast tree
|
|
21500
|
+
* @param ast
|
|
21501
|
+
* @param options
|
|
21502
|
+
* @param recursive
|
|
21503
|
+
* @param errors
|
|
21504
|
+
* @param nestingContent
|
|
21505
|
+
* @param context
|
|
21506
|
+
*
|
|
21507
|
+
* @private
|
|
21508
|
+
*/
|
|
20983
21509
|
function doMinify(ast, options = {}, recursive = false, errors, nestingContent, context = {}) {
|
|
20984
21510
|
if (!('nodes' in context)) {
|
|
20985
21511
|
context.nodes = new Set;
|
|
@@ -21006,13 +21532,6 @@
|
|
|
21006
21532
|
}
|
|
21007
21533
|
// @ts-ignore
|
|
21008
21534
|
node = ast.chi[i];
|
|
21009
|
-
// @ts-ignore
|
|
21010
|
-
// if (previous == node) {
|
|
21011
|
-
//
|
|
21012
|
-
// // @ts-ignore
|
|
21013
|
-
// ast.chi.splice(i--, 1);
|
|
21014
|
-
// continue;
|
|
21015
|
-
// }
|
|
21016
21535
|
if (node.typ == exports.EnumToken.AtRuleNodeType && node.nam == 'font-face') {
|
|
21017
21536
|
continue;
|
|
21018
21537
|
}
|
|
@@ -21164,12 +21683,7 @@
|
|
|
21164
21683
|
curr.splice(0, 2);
|
|
21165
21684
|
}
|
|
21166
21685
|
else {
|
|
21167
|
-
// if (ast.typ != EnumToken.RuleNodeType && combinators.includes(curr[1])) {
|
|
21168
|
-
//
|
|
21169
|
-
// wrap = false;
|
|
21170
|
-
// } else {
|
|
21171
21686
|
curr.splice(0, 1);
|
|
21172
|
-
// }
|
|
21173
21687
|
}
|
|
21174
21688
|
}
|
|
21175
21689
|
else if (combinators.includes(curr[0])) {
|
|
@@ -21211,11 +21725,6 @@
|
|
|
21211
21725
|
}
|
|
21212
21726
|
// @ts-ignore
|
|
21213
21727
|
let sel = wrap ? node.optimized.optimized.join('') + `:is(${rule})` : rule;
|
|
21214
|
-
// if (rule.includes('&')) {
|
|
21215
|
-
//
|
|
21216
|
-
// // @ts-ignore
|
|
21217
|
-
// rule = replaceCompound(rule, node.optimized.optimized[0]);
|
|
21218
|
-
// }
|
|
21219
21728
|
if (sel.length < node.sel.length) {
|
|
21220
21729
|
node.sel = sel;
|
|
21221
21730
|
}
|
|
@@ -21248,13 +21757,6 @@
|
|
|
21248
21757
|
node.chi.unshift(...previous.chi);
|
|
21249
21758
|
// @ts-ignore
|
|
21250
21759
|
ast.chi.splice(nodeIndex, 1);
|
|
21251
|
-
// @ts-ignore
|
|
21252
|
-
// if (!hasDeclaration(node)) {
|
|
21253
|
-
// // @ts-ignore
|
|
21254
|
-
// // minifyRule(node, <MinifyOptions>options, ast, context);
|
|
21255
|
-
// // } else {
|
|
21256
|
-
// doMinify(node, options, recursive, errors, nestingContent, context);
|
|
21257
|
-
// }
|
|
21258
21760
|
i--;
|
|
21259
21761
|
previous = node;
|
|
21260
21762
|
nodeIndex = i;
|
|
@@ -21266,13 +21768,10 @@
|
|
|
21266
21768
|
if (intersect.node1.chi.length == 0) {
|
|
21267
21769
|
// @ts-ignore
|
|
21268
21770
|
ast.chi.splice(i--, 1);
|
|
21269
|
-
// @ts-ignore
|
|
21270
|
-
// node = ast.chi[i];
|
|
21271
21771
|
}
|
|
21272
21772
|
else {
|
|
21273
21773
|
// @ts-ignore
|
|
21274
21774
|
ast.chi.splice(i--, 1, intersect.node1);
|
|
21275
|
-
// node = ast.chi intersect.node1;
|
|
21276
21775
|
}
|
|
21277
21776
|
if (intersect.node2.chi.length == 0) {
|
|
21278
21777
|
// @ts-ignore
|
|
@@ -21305,33 +21804,11 @@
|
|
|
21305
21804
|
if (recursive && previous != node) {
|
|
21306
21805
|
// @ts-ignore
|
|
21307
21806
|
if (!hasDeclaration(previous)) {
|
|
21308
|
-
// @ts-ignore
|
|
21309
|
-
// minifyRule(previous, <MinifyOptions>options, ast, context);
|
|
21310
|
-
// } else {
|
|
21311
21807
|
doMinify(previous, options, recursive, errors, nestingContent, context);
|
|
21312
21808
|
}
|
|
21313
21809
|
}
|
|
21314
21810
|
}
|
|
21315
|
-
// else {
|
|
21316
|
-
//
|
|
21317
|
-
// if ('chi' in previous) {
|
|
21318
|
-
//
|
|
21319
|
-
// // @ts-ignore
|
|
21320
|
-
// if (!hasDeclaration(previous)) {
|
|
21321
|
-
//
|
|
21322
|
-
// // @ts-ignore
|
|
21323
|
-
// // minifyRule(previous, <MinifyOptions>options, ast, context);
|
|
21324
|
-
// // } else {
|
|
21325
|
-
//
|
|
21326
|
-
// doMinify(previous, options, recursive, errors, nestingContent, context);
|
|
21327
|
-
// }
|
|
21328
|
-
// }
|
|
21329
|
-
// }
|
|
21330
21811
|
}
|
|
21331
|
-
// else if ('chi' in node) {
|
|
21332
|
-
//
|
|
21333
|
-
// doMinify(node, options, recursive, errors, nestingContent, context);
|
|
21334
|
-
// }
|
|
21335
21812
|
if (!nestingContent &&
|
|
21336
21813
|
// @ts-ignore
|
|
21337
21814
|
previous != null &&
|
|
@@ -21364,6 +21841,12 @@
|
|
|
21364
21841
|
}
|
|
21365
21842
|
return ast;
|
|
21366
21843
|
}
|
|
21844
|
+
/**
|
|
21845
|
+
* check if a rule has a declaration
|
|
21846
|
+
* @param node
|
|
21847
|
+
*
|
|
21848
|
+
* @private
|
|
21849
|
+
*/
|
|
21367
21850
|
function hasDeclaration(node) {
|
|
21368
21851
|
// @ts-ignore
|
|
21369
21852
|
for (let i = 0; i < node.chi?.length; i++) {
|
|
@@ -21379,11 +21862,10 @@
|
|
|
21379
21862
|
/**
|
|
21380
21863
|
* optimize selector
|
|
21381
21864
|
* @param selector
|
|
21865
|
+
*
|
|
21866
|
+
* @private
|
|
21382
21867
|
*/
|
|
21383
21868
|
function optimizeSelector(selector) {
|
|
21384
|
-
// if (selector.length == 0) {
|
|
21385
|
-
// return null;
|
|
21386
|
-
// }
|
|
21387
21869
|
selector = selector.reduce((acc, curr) => {
|
|
21388
21870
|
// @ts-ignore
|
|
21389
21871
|
if (curr.length > 0 && curr.at(-1).startsWith(':is(')) {
|
|
@@ -21431,11 +21913,6 @@
|
|
|
21431
21913
|
break;
|
|
21432
21914
|
}
|
|
21433
21915
|
selector.forEach((selector) => selector.splice(0, optimized.length));
|
|
21434
|
-
// combinator
|
|
21435
|
-
// if (combinators.includes(<string>optimized.at(-1))) {
|
|
21436
|
-
// const combinator: string = <string>optimized.pop();
|
|
21437
|
-
// selector.forEach((selector: string[]) => selector.unshift(combinator));
|
|
21438
|
-
// }
|
|
21439
21916
|
let reducible = optimized.length == 1;
|
|
21440
21917
|
if (optimized[0] == '&') {
|
|
21441
21918
|
if (optimized[1] == ' ') {
|
|
@@ -21483,6 +21960,8 @@
|
|
|
21483
21960
|
/**
|
|
21484
21961
|
* split selector string
|
|
21485
21962
|
* @param buffer
|
|
21963
|
+
*
|
|
21964
|
+
* @internal
|
|
21486
21965
|
*/
|
|
21487
21966
|
function splitRule(buffer) {
|
|
21488
21967
|
const result = [[]];
|
|
@@ -21490,17 +21969,6 @@
|
|
|
21490
21969
|
for (let i = 0; i < buffer.length; i++) {
|
|
21491
21970
|
let chr = buffer.charAt(i);
|
|
21492
21971
|
if (isWhiteSpace(chr.charCodeAt(0))) {
|
|
21493
|
-
// let k: number = i;
|
|
21494
|
-
// while (k + 1 < buffer.length) {
|
|
21495
|
-
//
|
|
21496
|
-
// if (isWhiteSpace(buffer[k + 1].charCodeAt(0))) {
|
|
21497
|
-
//
|
|
21498
|
-
// k++;
|
|
21499
|
-
// continue;
|
|
21500
|
-
// }
|
|
21501
|
-
//
|
|
21502
|
-
// break;
|
|
21503
|
-
// }
|
|
21504
21972
|
if (str !== '') {
|
|
21505
21973
|
// @ts-ignore
|
|
21506
21974
|
result.at(-1).push(str);
|
|
@@ -21562,22 +22030,6 @@
|
|
|
21562
22030
|
str += buffer.charAt(++i);
|
|
21563
22031
|
continue;
|
|
21564
22032
|
}
|
|
21565
|
-
// if (chr == '"' || chr == "'") {
|
|
21566
|
-
//
|
|
21567
|
-
// let k = i;
|
|
21568
|
-
// while (++k < buffer.length) {
|
|
21569
|
-
// chr = buffer.charAt(k);
|
|
21570
|
-
// str += chr;
|
|
21571
|
-
// if (chr == '//') {
|
|
21572
|
-
// str += buffer.charAt(++k);
|
|
21573
|
-
// continue;
|
|
21574
|
-
// }
|
|
21575
|
-
// if (chr == buffer.charAt(i)) {
|
|
21576
|
-
// break;
|
|
21577
|
-
// }
|
|
21578
|
-
// }
|
|
21579
|
-
// continue;
|
|
21580
|
-
// }
|
|
21581
22033
|
if (chr == '(' || chr == '[') {
|
|
21582
22034
|
const open = chr;
|
|
21583
22035
|
const close = chr == '(' ? ')' : ']';
|
|
@@ -21610,11 +22062,14 @@
|
|
|
21610
22062
|
}
|
|
21611
22063
|
return result;
|
|
21612
22064
|
}
|
|
22065
|
+
/**
|
|
22066
|
+
* reduce selector
|
|
22067
|
+
* @param acc
|
|
22068
|
+
* @param curr
|
|
22069
|
+
*
|
|
22070
|
+
* @private
|
|
22071
|
+
*/
|
|
21613
22072
|
function reduceSelector(acc, curr) {
|
|
21614
|
-
// if (acc === null) {
|
|
21615
|
-
//
|
|
21616
|
-
// return null;
|
|
21617
|
-
// }
|
|
21618
22073
|
let hasCompoundSelector = true;
|
|
21619
22074
|
// @ts-ignore
|
|
21620
22075
|
curr = curr.slice(this.match[0].length);
|
|
@@ -21626,16 +22081,6 @@
|
|
|
21626
22081
|
}
|
|
21627
22082
|
break;
|
|
21628
22083
|
}
|
|
21629
|
-
// invalid function match
|
|
21630
|
-
// if (curr.length > 0 && curr[0].endsWith('(') && curr.at(-1) != ')') {
|
|
21631
|
-
//
|
|
21632
|
-
// return null;
|
|
21633
|
-
// }
|
|
21634
|
-
//
|
|
21635
|
-
// if (curr.length == 1 && combinators.includes(curr[0].charAt(0))) {
|
|
21636
|
-
//
|
|
21637
|
-
// return null;
|
|
21638
|
-
// }
|
|
21639
22084
|
if (hasCompoundSelector && curr.length > 0) {
|
|
21640
22085
|
hasCompoundSelector = !['&'].concat(combinators).includes(curr[0].charAt(0));
|
|
21641
22086
|
}
|
|
@@ -21645,15 +22090,6 @@
|
|
|
21645
22090
|
if (index == 0) {
|
|
21646
22091
|
canReduce = curr[1] == '&';
|
|
21647
22092
|
}
|
|
21648
|
-
// else if (token.endsWith('(')) {
|
|
21649
|
-
//
|
|
21650
|
-
// if (inFunction == 0) {
|
|
21651
|
-
//
|
|
21652
|
-
// canReduce = false;
|
|
21653
|
-
// }
|
|
21654
|
-
//
|
|
21655
|
-
// inFunction++;
|
|
21656
|
-
// }
|
|
21657
22093
|
else if (token == ')') ;
|
|
21658
22094
|
else if (token == ',') {
|
|
21659
22095
|
if (!canReduce) {
|
|
@@ -21665,10 +22101,6 @@
|
|
|
21665
22101
|
acc.at(-1)?.push(token);
|
|
21666
22102
|
return acc;
|
|
21667
22103
|
}, [[]]);
|
|
21668
|
-
// if (inFunction > 0) {
|
|
21669
|
-
//
|
|
21670
|
-
// canReduce = false;
|
|
21671
|
-
// }
|
|
21672
22104
|
if (canReduce) {
|
|
21673
22105
|
curr = isCompound.reduce((acc, curr) => {
|
|
21674
22106
|
if (acc.length > 0) {
|
|
@@ -21683,7 +22115,14 @@
|
|
|
21683
22115
|
acc.push(this.match.length == 0 ? ['&'] : (hasCompoundSelector && curr[0] != '&' && (curr.length == 0 || !combinators.includes(curr[0].charAt(0))) ? ['&'].concat(curr) : curr));
|
|
21684
22116
|
return acc;
|
|
21685
22117
|
}
|
|
21686
|
-
|
|
22118
|
+
/**
|
|
22119
|
+
* match selectors
|
|
22120
|
+
* @param selector1
|
|
22121
|
+
* @param selector2
|
|
22122
|
+
*
|
|
22123
|
+
* @private
|
|
22124
|
+
*/
|
|
22125
|
+
function matchSelectors(selector1, selector2 /*, parentType: EnumToken, errors: ErrorDescription[] */) {
|
|
21687
22126
|
let match = [[]];
|
|
21688
22127
|
const j = Math.min(selector1.reduce((acc, curr) => Math.min(acc, curr.length), selector1.length > 0 ? selector1[0].length : 0), selector2.reduce((acc, curr) => Math.min(acc, curr.length), selector2.length > 0 ? selector2[0].length : 0));
|
|
21689
22128
|
let i = 0;
|
|
@@ -21714,52 +22153,15 @@
|
|
|
21714
22153
|
if (!matching) {
|
|
21715
22154
|
break;
|
|
21716
22155
|
}
|
|
21717
|
-
// if (token == ',') {
|
|
21718
|
-
//
|
|
21719
|
-
// match.push([]);
|
|
21720
|
-
// } else {
|
|
21721
22156
|
if (token.endsWith('(')) {
|
|
21722
22157
|
matchFunction++;
|
|
21723
22158
|
}
|
|
21724
|
-
// if (token.endsWith('[')) {
|
|
21725
|
-
//
|
|
21726
|
-
// inAttr++;
|
|
21727
|
-
// } else if (token == ')') {
|
|
21728
|
-
//
|
|
21729
|
-
// matchFunction--;
|
|
21730
|
-
// } else if (token == ']') {
|
|
21731
|
-
//
|
|
21732
|
-
// inAttr--;
|
|
21733
|
-
// }
|
|
21734
22159
|
match.at(-1).push(token);
|
|
21735
|
-
// }
|
|
21736
22160
|
}
|
|
21737
22161
|
// invalid function
|
|
21738
22162
|
if (matchFunction != 0 || inAttr != 0) {
|
|
21739
22163
|
return null;
|
|
21740
22164
|
}
|
|
21741
|
-
// if (parentType != EnumToken.RuleNodeType) {
|
|
21742
|
-
//
|
|
21743
|
-
// for (const part of match) {
|
|
21744
|
-
//
|
|
21745
|
-
// if (part.length > 0 && combinators.includes(part[0].charAt(0))) {
|
|
21746
|
-
//
|
|
21747
|
-
// return null;
|
|
21748
|
-
// }
|
|
21749
|
-
// }
|
|
21750
|
-
// }
|
|
21751
|
-
// if (match.length > 1) {
|
|
21752
|
-
//
|
|
21753
|
-
// errors?.push({
|
|
21754
|
-
// action: 'ignore',
|
|
21755
|
-
// message: `minify: unsupported multilevel matching\n${JSON.stringify({
|
|
21756
|
-
// match,
|
|
21757
|
-
// selector1,
|
|
21758
|
-
// selector2
|
|
21759
|
-
// }, null, 1)}`
|
|
21760
|
-
// });
|
|
21761
|
-
// return null;
|
|
21762
|
-
// }
|
|
21763
22165
|
for (const part of match) {
|
|
21764
22166
|
while (part.length > 0) {
|
|
21765
22167
|
const token = part.at(-1);
|
|
@@ -21788,6 +22190,12 @@
|
|
|
21788
22190
|
selector2
|
|
21789
22191
|
};
|
|
21790
22192
|
}
|
|
22193
|
+
/**
|
|
22194
|
+
* fix selector
|
|
22195
|
+
* @param node
|
|
22196
|
+
*
|
|
22197
|
+
* @private
|
|
22198
|
+
*/
|
|
21791
22199
|
function fixSelector(node) {
|
|
21792
22200
|
// @ts-ignore
|
|
21793
22201
|
if (node.sel.includes('&')) {
|
|
@@ -21805,6 +22213,18 @@
|
|
|
21805
22213
|
node.sel = attributes.reduce((acc, curr) => acc + renderToken(curr), '');
|
|
21806
22214
|
}
|
|
21807
22215
|
}
|
|
22216
|
+
/**
|
|
22217
|
+
* wrap nodes
|
|
22218
|
+
* @param previous
|
|
22219
|
+
* @param node
|
|
22220
|
+
* @param match
|
|
22221
|
+
* @param ast
|
|
22222
|
+
* @param reducer
|
|
22223
|
+
* @param i
|
|
22224
|
+
* @param nodeIndex
|
|
22225
|
+
*
|
|
22226
|
+
* @private
|
|
22227
|
+
*/
|
|
21808
22228
|
function wrapNodes(previous, node, match, ast, reducer, i, nodeIndex) {
|
|
21809
22229
|
// @ts-ignore
|
|
21810
22230
|
let pSel = match.selector1.reduce(reducer, []).join(',');
|
|
@@ -21850,6 +22270,15 @@
|
|
|
21850
22270
|
reduceRuleSelector(wrapper);
|
|
21851
22271
|
return wrapper;
|
|
21852
22272
|
}
|
|
22273
|
+
/**
|
|
22274
|
+
* diff nodes
|
|
22275
|
+
* @param n1
|
|
22276
|
+
* @param n2
|
|
22277
|
+
* @param reducer
|
|
22278
|
+
* @param options
|
|
22279
|
+
*
|
|
22280
|
+
* @private
|
|
22281
|
+
*/
|
|
21853
22282
|
function diff(n1, n2, reducer, options = {}) {
|
|
21854
22283
|
if (!('cache' in options)) {
|
|
21855
22284
|
options.cache = new WeakMap();
|
|
@@ -21865,10 +22294,6 @@
|
|
|
21865
22294
|
}
|
|
21866
22295
|
let i = node1.chi.length;
|
|
21867
22296
|
let j = node2.chi.length;
|
|
21868
|
-
// if (i == 0 || j == 0) {
|
|
21869
|
-
//
|
|
21870
|
-
// return null;
|
|
21871
|
-
// }
|
|
21872
22297
|
const raw1 = node1.raw;
|
|
21873
22298
|
const raw2 = node2.raw;
|
|
21874
22299
|
if (raw1 != null && raw2 != null) {
|
|
@@ -21939,10 +22364,6 @@
|
|
|
21939
22364
|
continue;
|
|
21940
22365
|
}
|
|
21941
22366
|
j = node2.chi.length;
|
|
21942
|
-
// if (j == 0) {
|
|
21943
|
-
//
|
|
21944
|
-
// break;
|
|
21945
|
-
// }
|
|
21946
22367
|
while (j--) {
|
|
21947
22368
|
if (node2.chi[j].typ == exports.EnumToken.CommentNodeType) {
|
|
21948
22369
|
continue;
|
|
@@ -21980,6 +22401,12 @@
|
|
|
21980
22401
|
}
|
|
21981
22402
|
return { result, node1: exchanged ? node2 : node1, node2: exchanged ? node1 : node2 };
|
|
21982
22403
|
}
|
|
22404
|
+
/**
|
|
22405
|
+
* reduce rule selector
|
|
22406
|
+
* @param node
|
|
22407
|
+
*
|
|
22408
|
+
* @private
|
|
22409
|
+
*/
|
|
21983
22410
|
function reduceRuleSelector(node) {
|
|
21984
22411
|
if (node.raw == null) {
|
|
21985
22412
|
Object.defineProperty(node, 'raw', { ...definedPropertySettings, value: splitRule(node.sel) });
|
|
@@ -22023,27 +22450,12 @@
|
|
|
22023
22450
|
}
|
|
22024
22451
|
|
|
22025
22452
|
/**
|
|
22026
|
-
* expand
|
|
22453
|
+
* expand css nesting ast nodes
|
|
22027
22454
|
* @param ast
|
|
22455
|
+
*
|
|
22456
|
+
* @private
|
|
22028
22457
|
*/
|
|
22029
22458
|
function expand(ast) {
|
|
22030
|
-
//
|
|
22031
|
-
// if (![EnumToken.RuleNodeType, EnumToken.StyleSheetNodeType, EnumToken.AtRuleNodeType].includes(ast.typ)) {
|
|
22032
|
-
//
|
|
22033
|
-
// return ast;
|
|
22034
|
-
// }
|
|
22035
|
-
// if (EnumToken.RuleNodeType == ast.typ) {
|
|
22036
|
-
//
|
|
22037
|
-
// return <AstRuleStyleSheet>{
|
|
22038
|
-
// typ: EnumToken.StyleSheetNodeType,
|
|
22039
|
-
// chi: expandRule(<AstRule>ast)
|
|
22040
|
-
// }
|
|
22041
|
-
// }
|
|
22042
|
-
//
|
|
22043
|
-
// if (!('chi' in ast)) {
|
|
22044
|
-
//
|
|
22045
|
-
// return ast;
|
|
22046
|
-
// }
|
|
22047
22459
|
const result = { ...ast, chi: [] };
|
|
22048
22460
|
// @ts-ignore
|
|
22049
22461
|
for (let i = 0; i < ast.chi.length; i++) {
|
|
@@ -22067,11 +22479,6 @@
|
|
|
22067
22479
|
// @ts-ignore
|
|
22068
22480
|
result.chi.push({ ...(hasRule ? expand(node) : node) });
|
|
22069
22481
|
}
|
|
22070
|
-
// else {
|
|
22071
|
-
//
|
|
22072
|
-
// // @ts-ignore
|
|
22073
|
-
// result.chi.push(node);
|
|
22074
|
-
// }
|
|
22075
22482
|
}
|
|
22076
22483
|
return result;
|
|
22077
22484
|
}
|
|
@@ -22085,14 +22492,6 @@
|
|
|
22085
22492
|
const rule = ast.chi[i];
|
|
22086
22493
|
if (!rule.sel.includes('&')) {
|
|
22087
22494
|
const selRule = splitRule(rule.sel);
|
|
22088
|
-
// if (selRule.length > 1) {
|
|
22089
|
-
//
|
|
22090
|
-
// const r: string = ':is(' + selRule.map(a => a.join('')).join(',') + ')';
|
|
22091
|
-
// rule.sel = splitRule(ast.sel).reduce((a: string[], b: string[]): string[] => a.concat([b.join('') + r]), <string[]>[]).join(',');
|
|
22092
|
-
//
|
|
22093
|
-
// }
|
|
22094
|
-
// else {
|
|
22095
|
-
// selRule = splitRule(selRule.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.join(''), ''));
|
|
22096
22495
|
const arSelf = splitRule(ast.sel).filter((r) => r.every((t) => t != ':before' && t != ':after' && !t.startsWith('::'))).reduce((acc, curr) => acc.concat([curr.join('')]), []).join(',');
|
|
22097
22496
|
if (arSelf.length == 0) {
|
|
22098
22497
|
ast.chi.splice(i--, 1);
|
|
@@ -22130,10 +22529,6 @@
|
|
|
22130
22529
|
if (s == '&' || parentSelector) {
|
|
22131
22530
|
withCompound.push(s);
|
|
22132
22531
|
}
|
|
22133
|
-
// else {
|
|
22134
|
-
//
|
|
22135
|
-
// withoutCompound.push(s.slice(1));
|
|
22136
|
-
// }
|
|
22137
22532
|
}
|
|
22138
22533
|
}
|
|
22139
22534
|
else {
|
|
@@ -22144,10 +22539,6 @@
|
|
|
22144
22539
|
withCompound.push(s);
|
|
22145
22540
|
}
|
|
22146
22541
|
}
|
|
22147
|
-
// else {
|
|
22148
|
-
//
|
|
22149
|
-
// withoutCompound.push(s);
|
|
22150
|
-
// }
|
|
22151
22542
|
}
|
|
22152
22543
|
const selectors = [];
|
|
22153
22544
|
const selector = rules.length > 1 ? ':is(' + rules.map(a => a.join('')).join(',') + ')' : rules[0].join('');
|
|
@@ -22179,13 +22570,6 @@
|
|
|
22179
22570
|
if (withCompound.length == 1) {
|
|
22180
22571
|
selectors.push(replaceCompound(withCompound[0], selector));
|
|
22181
22572
|
}
|
|
22182
|
-
// else {
|
|
22183
|
-
//
|
|
22184
|
-
// for (const w of withCompound) {
|
|
22185
|
-
//
|
|
22186
|
-
// selectors.push(replaceCompound(w, selector));
|
|
22187
|
-
// }
|
|
22188
|
-
// }
|
|
22189
22573
|
}
|
|
22190
22574
|
rule.sel = selectors.reduce((acc, curr) => curr.length == 0 ? acc : acc + (acc.length > 0 ? ',' : '') + curr, '');
|
|
22191
22575
|
}
|
|
@@ -22226,11 +22610,6 @@
|
|
|
22226
22610
|
// @ts-ignore
|
|
22227
22611
|
astAtRule.chi.push(...expandRule(r));
|
|
22228
22612
|
}
|
|
22229
|
-
// else {
|
|
22230
|
-
//
|
|
22231
|
-
// // @ts-ignore
|
|
22232
|
-
// astAtRule.chi.push(r);
|
|
22233
|
-
// }
|
|
22234
22613
|
}
|
|
22235
22614
|
}
|
|
22236
22615
|
// @ts-ignore
|
|
@@ -22257,12 +22636,6 @@
|
|
|
22257
22636
|
if (replacement == null) {
|
|
22258
22637
|
replacement = parseString(replace);
|
|
22259
22638
|
}
|
|
22260
|
-
// if (tokens[1].typ == EnumToken.IdenTokenType) {
|
|
22261
|
-
//
|
|
22262
|
-
//
|
|
22263
|
-
// (t.value as LiteralToken).val = (replacement as Token[]).length == 1 || (!replace.includes(' ') && replace.charAt(0).match(/[:.]/)) ? (tokens[1] as IdentToken).val + replace : replaceCompoundLiteral((tokens[1] as IdentToken).val + '&', replace);
|
|
22264
|
-
// tokens.splice(1, 1);
|
|
22265
|
-
// } else {
|
|
22266
22639
|
t.value.val = replaceCompoundLiteral(t.value.val, replace);
|
|
22267
22640
|
// }
|
|
22268
22641
|
continue;
|
|
@@ -22270,10 +22643,6 @@
|
|
|
22270
22643
|
const rule = splitRule(replace);
|
|
22271
22644
|
t.value.val = rule.length > 1 ? ':is(' + replace + ')' : replace;
|
|
22272
22645
|
}
|
|
22273
|
-
// else if ((t.value as LiteralToken).val.length > 1 && (t.value as LiteralToken).val.charAt(0) == '&') {
|
|
22274
|
-
//
|
|
22275
|
-
// (t.value as LiteralToken).val = replaceCompoundLiteral((t.value as LiteralToken).val, replace);
|
|
22276
|
-
// }
|
|
22277
22646
|
}
|
|
22278
22647
|
}
|
|
22279
22648
|
return tokens.reduce((acc, curr) => acc + renderToken(curr), '');
|
|
@@ -22286,10 +22655,6 @@
|
|
|
22286
22655
|
tokens.push('&');
|
|
22287
22656
|
tokens.push('');
|
|
22288
22657
|
}
|
|
22289
|
-
// else {
|
|
22290
|
-
//
|
|
22291
|
-
// tokens[tokens.length - 1] += selector.charAt(i);
|
|
22292
|
-
// }
|
|
22293
22658
|
}
|
|
22294
22659
|
return tokens.sort((a, b) => {
|
|
22295
22660
|
if (a == '&') {
|
|
@@ -22309,6 +22674,7 @@
|
|
|
22309
22674
|
/**
|
|
22310
22675
|
* return the directory name of a path
|
|
22311
22676
|
* @param path
|
|
22677
|
+
* @internal
|
|
22312
22678
|
*/
|
|
22313
22679
|
function dirname(path) {
|
|
22314
22680
|
if (path == '/' || path === '') {
|
|
@@ -22331,6 +22697,11 @@
|
|
|
22331
22697
|
parts.pop();
|
|
22332
22698
|
return parts.length == 0 ? '/' : parts.join('/');
|
|
22333
22699
|
}
|
|
22700
|
+
/**
|
|
22701
|
+
* split path
|
|
22702
|
+
* @param result
|
|
22703
|
+
* @private
|
|
22704
|
+
*/
|
|
22334
22705
|
function splitPath(result) {
|
|
22335
22706
|
const parts = [''];
|
|
22336
22707
|
let i = 0;
|
|
@@ -22360,9 +22731,11 @@
|
|
|
22360
22731
|
}
|
|
22361
22732
|
/**
|
|
22362
22733
|
* resolve path
|
|
22363
|
-
* @param url
|
|
22364
|
-
* @param currentDirectory
|
|
22365
|
-
* @param cwd
|
|
22734
|
+
* @param url url or path to resolve
|
|
22735
|
+
* @param currentDirectory directory used to resolve the path
|
|
22736
|
+
* @param cwd current working directory
|
|
22737
|
+
*
|
|
22738
|
+
* @private
|
|
22366
22739
|
*/
|
|
22367
22740
|
function resolve(url, currentDirectory, cwd) {
|
|
22368
22741
|
if (matchUrl.test(url)) {
|
|
@@ -22402,23 +22775,23 @@
|
|
|
22402
22775
|
};
|
|
22403
22776
|
}
|
|
22404
22777
|
|
|
22405
|
-
function parseResponse(response) {
|
|
22406
|
-
if (!response.ok) {
|
|
22407
|
-
throw new Error(`${response.status} ${response.statusText} ${response.url}`);
|
|
22408
|
-
}
|
|
22409
|
-
return response.text();
|
|
22410
|
-
}
|
|
22411
22778
|
/**
|
|
22412
|
-
*
|
|
22779
|
+
* web module entry point
|
|
22780
|
+
* @module web
|
|
22781
|
+
*/
|
|
22782
|
+
/**
|
|
22783
|
+
* load file or url as stream
|
|
22413
22784
|
* @param url
|
|
22414
22785
|
* @param currentFile
|
|
22786
|
+
*
|
|
22787
|
+
* @private
|
|
22415
22788
|
*/
|
|
22416
|
-
async function
|
|
22789
|
+
async function getStream(url, currentFile = '.') {
|
|
22417
22790
|
let t;
|
|
22418
22791
|
if (matchUrl.test(url)) {
|
|
22419
22792
|
t = new URL(url);
|
|
22420
22793
|
}
|
|
22421
|
-
else if (matchUrl.test(currentFile)) {
|
|
22794
|
+
else if (currentFile != null && matchUrl.test(currentFile)) {
|
|
22422
22795
|
t = new URL(url, currentFile);
|
|
22423
22796
|
}
|
|
22424
22797
|
else {
|
|
@@ -22427,33 +22800,96 @@
|
|
|
22427
22800
|
t = new URL(path, self.origin);
|
|
22428
22801
|
}
|
|
22429
22802
|
// @ts-ignore
|
|
22430
|
-
return fetch(t, t.origin != self.origin ? { mode: 'cors' } : {}).then(
|
|
22803
|
+
return fetch(t, t.origin != self.origin ? { mode: 'cors' } : {}).then((response) => {
|
|
22804
|
+
if (!response.ok) {
|
|
22805
|
+
throw new Error(`${response.status} ${response.statusText} ${response.url}`);
|
|
22806
|
+
}
|
|
22807
|
+
return response.body;
|
|
22808
|
+
});
|
|
22431
22809
|
}
|
|
22432
|
-
|
|
22433
22810
|
/**
|
|
22434
22811
|
* render ast node
|
|
22812
|
+
* @param data
|
|
22813
|
+
* @param options
|
|
22435
22814
|
*/
|
|
22436
22815
|
function render(data, options = {}) {
|
|
22437
22816
|
return doRender(data, Object.assign(options, {
|
|
22438
|
-
|
|
22817
|
+
getStream,
|
|
22439
22818
|
resolve,
|
|
22440
22819
|
dirname,
|
|
22441
22820
|
cwd: options.cwd ?? self.location.pathname.endsWith('/') ? self.location.pathname : dirname(self.location.pathname)
|
|
22442
22821
|
}));
|
|
22443
22822
|
}
|
|
22823
|
+
/**
|
|
22824
|
+
* parse css file
|
|
22825
|
+
* @param file url or path
|
|
22826
|
+
* @param options
|
|
22827
|
+
*/
|
|
22828
|
+
async function parseFile(file, options = {}) {
|
|
22829
|
+
return getStream(file).then(stream => parse(stream, { src: file, ...options }));
|
|
22830
|
+
}
|
|
22444
22831
|
/**
|
|
22445
22832
|
* parse css
|
|
22833
|
+
* @param stream
|
|
22834
|
+
* @param opt
|
|
22446
22835
|
*/
|
|
22447
|
-
async function parse(
|
|
22448
|
-
return doParse(
|
|
22449
|
-
|
|
22836
|
+
async function parse(stream, opt = {}) {
|
|
22837
|
+
return doParse(stream instanceof ReadableStream ? tokenizeStream(stream) : tokenize$1({
|
|
22838
|
+
stream,
|
|
22839
|
+
buffer: '',
|
|
22840
|
+
position: { ind: 0, lin: 1, col: 1 },
|
|
22841
|
+
currentPosition: { ind: -1, lin: 1, col: 0 }
|
|
22842
|
+
}), Object.assign(opt, {
|
|
22843
|
+
getStream,
|
|
22450
22844
|
resolve,
|
|
22451
22845
|
dirname,
|
|
22452
22846
|
cwd: opt.cwd ?? self.location.pathname.endsWith('/') ? self.location.pathname : dirname(self.location.pathname)
|
|
22453
22847
|
}));
|
|
22454
22848
|
}
|
|
22455
22849
|
/**
|
|
22456
|
-
*
|
|
22850
|
+
* transform css file
|
|
22851
|
+
* @param file url or path
|
|
22852
|
+
* @param options
|
|
22853
|
+
*
|
|
22854
|
+
* Example:
|
|
22855
|
+
*
|
|
22856
|
+
* ```ts
|
|
22857
|
+
*
|
|
22858
|
+
* import {transformFile} from '@tbela99/css-parser/web';
|
|
22859
|
+
*
|
|
22860
|
+
* // remote file
|
|
22861
|
+
* let result = await transformFile('https://docs.deno.com/styles.css');
|
|
22862
|
+
* console.log(result.code);
|
|
22863
|
+
*
|
|
22864
|
+
* // local file
|
|
22865
|
+
* result = await transformFile('./css/styles.css');
|
|
22866
|
+
* console.log(result.code);
|
|
22867
|
+
* ```
|
|
22868
|
+
*/
|
|
22869
|
+
async function transformFile(file, options = {}) {
|
|
22870
|
+
return getStream(file).then(stream => transform(stream, { src: file, ...options }));
|
|
22871
|
+
}
|
|
22872
|
+
/**
|
|
22873
|
+
* transform css
|
|
22874
|
+
* @param css
|
|
22875
|
+
* @param options
|
|
22876
|
+
*
|
|
22877
|
+
* Example:
|
|
22878
|
+
*
|
|
22879
|
+
* ```ts
|
|
22880
|
+
*
|
|
22881
|
+
* import {transform} from '@tbela99/css-parser/web';
|
|
22882
|
+
*
|
|
22883
|
+
* // css string
|
|
22884
|
+
* let result = await transform(css);
|
|
22885
|
+
* console.log(result.code);
|
|
22886
|
+
*
|
|
22887
|
+
* // using readable stream
|
|
22888
|
+
* const response = await fetch('https://docs.deno.com/styles.css');
|
|
22889
|
+
* result = await transform(response.body, {beautify: true});
|
|
22890
|
+
*
|
|
22891
|
+
* console.log(result.code);
|
|
22892
|
+
* ```
|
|
22457
22893
|
*/
|
|
22458
22894
|
async function transform(css, options = {}) {
|
|
22459
22895
|
options = { minify: true, removeEmpty: true, removeCharset: true, ...options };
|
|
@@ -22474,20 +22910,24 @@
|
|
|
22474
22910
|
});
|
|
22475
22911
|
}
|
|
22476
22912
|
|
|
22913
|
+
exports.SourceMap = SourceMap;
|
|
22477
22914
|
exports.convertColor = convertColor;
|
|
22478
22915
|
exports.dirname = dirname;
|
|
22479
22916
|
exports.expand = expand;
|
|
22917
|
+
exports.getStream = getStream;
|
|
22480
22918
|
exports.isOkLabClose = isOkLabClose;
|
|
22481
|
-
exports.load = load;
|
|
22482
22919
|
exports.minify = minify;
|
|
22483
22920
|
exports.okLabDistance = okLabDistance;
|
|
22484
22921
|
exports.parse = parse;
|
|
22922
|
+
exports.parseDeclarations = parseDeclarations;
|
|
22923
|
+
exports.parseFile = parseFile;
|
|
22485
22924
|
exports.parseString = parseString;
|
|
22486
22925
|
exports.parseTokens = parseTokens;
|
|
22487
22926
|
exports.render = render;
|
|
22488
22927
|
exports.renderToken = renderToken;
|
|
22489
22928
|
exports.resolve = resolve;
|
|
22490
22929
|
exports.transform = transform;
|
|
22930
|
+
exports.transformFile = transformFile;
|
|
22491
22931
|
exports.walk = walk;
|
|
22492
22932
|
exports.walkValues = walkValues;
|
|
22493
22933
|
|