@tbela99/css-parser 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +205 -2
- package/dist/config.json.js +386 -4
- package/dist/index-umd-web.js +1540 -665
- package/dist/index.cjs +1540 -665
- package/dist/index.d.ts +498 -692
- package/dist/lib/ast/expand.js +11 -11
- package/dist/lib/ast/features/calc.js +17 -48
- package/dist/lib/ast/features/inlinecssvariables.js +42 -27
- package/dist/lib/ast/features/shorthand.js +4 -3
- package/dist/lib/ast/features/utils/math.js +95 -0
- package/dist/lib/ast/minify.js +34 -29
- package/dist/lib/ast/types.js +91 -78
- package/dist/lib/ast/walk.js +18 -5
- package/dist/lib/iterable/set.js +48 -0
- package/dist/lib/iterable/weakmap.js +53 -0
- package/dist/lib/parser/declaration/list.js +3 -3
- package/dist/lib/parser/declaration/map.js +53 -5
- package/dist/lib/parser/declaration/set.js +2 -2
- package/dist/lib/parser/parse.js +561 -361
- package/dist/lib/parser/tokenize.js +42 -13
- package/dist/lib/parser/utils/type.js +7 -2
- package/dist/lib/renderer/render.js +88 -41
- package/dist/node/index.js +8 -12
- package/dist/web/index.js +8 -12
- package/package.json +7 -5
- /package/dist/lib/ast/{utiles → utils}/minifyfeature.js +0 -0
|
@@ -16,7 +16,6 @@ function* tokenize(stream) {
|
|
|
16
16
|
};
|
|
17
17
|
let value;
|
|
18
18
|
let buffer = '';
|
|
19
|
-
// let input: string = '';
|
|
20
19
|
function consumeWhiteSpace() {
|
|
21
20
|
let count = 0;
|
|
22
21
|
while (isWhiteSpace(stream.charAt(count + ind + 1).charCodeAt(0))) {
|
|
@@ -26,7 +25,7 @@ function* tokenize(stream) {
|
|
|
26
25
|
return count;
|
|
27
26
|
}
|
|
28
27
|
function pushToken(token, hint) {
|
|
29
|
-
const result = { token, hint, position: { ...position }, bytesIn: ind };
|
|
28
|
+
const result = { token, hint, position: { ...position }, bytesIn: ind + 1 };
|
|
30
29
|
position.ind = ind;
|
|
31
30
|
position.lin = lin;
|
|
32
31
|
position.col = col == 0 ? 1 : col;
|
|
@@ -223,8 +222,10 @@ function* tokenize(stream) {
|
|
|
223
222
|
// EOF
|
|
224
223
|
if (!(value = next())) {
|
|
225
224
|
// end of stream ignore \\
|
|
226
|
-
|
|
227
|
-
|
|
225
|
+
if (buffer.length > 0) {
|
|
226
|
+
yield pushToken(buffer);
|
|
227
|
+
buffer = '';
|
|
228
|
+
}
|
|
228
229
|
break;
|
|
229
230
|
}
|
|
230
231
|
buffer += prev() + value;
|
|
@@ -233,29 +234,51 @@ function* tokenize(stream) {
|
|
|
233
234
|
case "'":
|
|
234
235
|
yield* consumeString(value);
|
|
235
236
|
break;
|
|
237
|
+
case '^':
|
|
236
238
|
case '~':
|
|
237
239
|
case '|':
|
|
240
|
+
case '$':
|
|
241
|
+
if (value == '|' && peek() == '|') {
|
|
242
|
+
next();
|
|
243
|
+
yield pushToken('', EnumToken.ColumnCombinatorTokenType);
|
|
244
|
+
buffer = '';
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
238
247
|
if (buffer.length > 0) {
|
|
239
248
|
yield pushToken(buffer);
|
|
240
249
|
buffer = '';
|
|
241
250
|
}
|
|
242
251
|
buffer += value;
|
|
243
|
-
if (!(value =
|
|
252
|
+
if (!(value = peek())) {
|
|
244
253
|
yield pushToken(buffer);
|
|
245
254
|
buffer = '';
|
|
246
255
|
break;
|
|
247
256
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
257
|
+
// ~=
|
|
258
|
+
// ^=
|
|
259
|
+
// $=
|
|
260
|
+
// |=
|
|
261
|
+
if (peek() == '=') {
|
|
262
|
+
next();
|
|
263
|
+
switch (buffer.charAt(0)) {
|
|
264
|
+
case '~':
|
|
265
|
+
yield pushToken(buffer, EnumToken.IncludeMatchTokenType);
|
|
266
|
+
break;
|
|
267
|
+
case '^':
|
|
268
|
+
yield pushToken(buffer, EnumToken.StartMatchTokenType);
|
|
269
|
+
break;
|
|
270
|
+
case '$':
|
|
271
|
+
yield pushToken(buffer, EnumToken.EndMatchTokenType);
|
|
272
|
+
break;
|
|
273
|
+
case '|':
|
|
274
|
+
yield pushToken(buffer, EnumToken.DashMatchTokenType);
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
251
277
|
buffer = '';
|
|
252
278
|
break;
|
|
253
279
|
}
|
|
254
280
|
yield pushToken(buffer);
|
|
255
|
-
|
|
256
|
-
value = next();
|
|
257
|
-
}
|
|
258
|
-
buffer = value;
|
|
281
|
+
buffer = '';
|
|
259
282
|
break;
|
|
260
283
|
case '>':
|
|
261
284
|
if (buffer !== '') {
|
|
@@ -289,7 +312,13 @@ function* tokenize(stream) {
|
|
|
289
312
|
yield pushToken(buffer);
|
|
290
313
|
buffer = '';
|
|
291
314
|
}
|
|
292
|
-
|
|
315
|
+
const val = peek();
|
|
316
|
+
if (val == '=') {
|
|
317
|
+
next();
|
|
318
|
+
yield pushToken(value + val, EnumToken.ContainMatchTokenType);
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
if (value == ':' && ':' == val) {
|
|
293
322
|
buffer += value + next();
|
|
294
323
|
break;
|
|
295
324
|
}
|
|
@@ -4,6 +4,7 @@ import '../parse.js';
|
|
|
4
4
|
import '../../renderer/utils/color.js';
|
|
5
5
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
6
6
|
|
|
7
|
+
// https://www.w3.org/TR/css-values-4/#math-function
|
|
7
8
|
const funcList = ['clamp', 'calc'];
|
|
8
9
|
function matchType(val, properties) {
|
|
9
10
|
if (val.typ == EnumToken.IdenTokenType && properties.keywords.includes(val.val) ||
|
|
@@ -19,8 +20,12 @@ function matchType(val, properties) {
|
|
|
19
20
|
return typ == EnumToken.LengthTokenType || typ == EnumToken.AngleTokenType;
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
|
-
if (val.typ == EnumToken.FunctionTokenType
|
|
23
|
-
|
|
23
|
+
if (val.typ == EnumToken.FunctionTokenType) {
|
|
24
|
+
if (funcList.includes(val.val)) {
|
|
25
|
+
return val.chi.every((t => [EnumToken.LiteralTokenType, EnumToken.CommaTokenType, EnumToken.WhitespaceTokenType, EnumToken.StartParensTokenType, EnumToken.EndParensTokenType].includes(t.typ) || matchType(t, properties)));
|
|
26
|
+
}
|
|
27
|
+
// match type defined like function 'symbols()', 'url()', 'attr()' etc.
|
|
28
|
+
// return properties.types.includes((<FunctionToken>val).val + '()')
|
|
24
29
|
}
|
|
25
30
|
return false;
|
|
26
31
|
}
|
|
@@ -76,21 +76,19 @@ function doRender(data, options = {}) {
|
|
|
76
76
|
}
|
|
77
77
|
if (sourcemap != null) {
|
|
78
78
|
result.map = sourcemap.toJSON();
|
|
79
|
-
// @ts-ignore
|
|
80
|
-
// result.map.sources = result.map.sources?.map(s => <string>options?.resolve(s, <string>options?.cwd)?.relative)
|
|
81
79
|
}
|
|
82
80
|
return result;
|
|
83
81
|
}
|
|
84
82
|
function updateSourceMap(node, options, cache, sourcemap, position, str) {
|
|
85
|
-
if ([
|
|
83
|
+
if ([EnumToken.RuleNodeType, EnumToken.AtRuleNodeType].includes(node.typ)) {
|
|
86
84
|
let src = node.loc?.src ?? '';
|
|
87
85
|
let output = options.output ?? '';
|
|
88
|
-
if (src !== '') {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
86
|
+
// if (src !== '') {
|
|
87
|
+
if (!(src in cache)) {
|
|
88
|
+
// @ts-ignore
|
|
89
|
+
cache[src] = options.resolve(src, options.cwd ?? '').relative;
|
|
93
90
|
}
|
|
91
|
+
// }
|
|
94
92
|
if (!(output in cache)) {
|
|
95
93
|
// @ts-ignore
|
|
96
94
|
cache[output] = options.resolve(output, options.cwd).relative;
|
|
@@ -115,16 +113,16 @@ function renderAstNode(data, options, sourcemap, position, errors, reducer, cach
|
|
|
115
113
|
const indent = indents[level];
|
|
116
114
|
const indentSub = indents[level + 1];
|
|
117
115
|
switch (data.typ) {
|
|
118
|
-
case
|
|
116
|
+
case EnumToken.DeclarationNodeType:
|
|
119
117
|
return `${data.nam}:${options.indent}${data.val.reduce(reducer, '')}`;
|
|
120
|
-
case
|
|
121
|
-
case
|
|
118
|
+
case EnumToken.CommentNodeType:
|
|
119
|
+
case EnumToken.CDOCOMMNodeType:
|
|
122
120
|
if (data.val.startsWith('# sourceMappingURL=')) {
|
|
123
121
|
// ignore sourcemap
|
|
124
122
|
return '';
|
|
125
123
|
}
|
|
126
124
|
return !options.removeComments || (options.preserveLicense && data.val.startsWith('/*!')) ? data.val : '';
|
|
127
|
-
case
|
|
125
|
+
case EnumToken.StyleSheetNodeType:
|
|
128
126
|
return data.chi.reduce((css, node) => {
|
|
129
127
|
const str = renderAstNode(node, options, sourcemap, { ...position }, errors, reducer, cache, level, indents);
|
|
130
128
|
if (str === '') {
|
|
@@ -142,18 +140,18 @@ function renderAstNode(data, options, sourcemap, position, errors, reducer, cach
|
|
|
142
140
|
}
|
|
143
141
|
return `${css}${options.newLine}${str}`;
|
|
144
142
|
}, '');
|
|
145
|
-
case
|
|
146
|
-
case
|
|
147
|
-
if (data.typ ==
|
|
143
|
+
case EnumToken.AtRuleNodeType:
|
|
144
|
+
case EnumToken.RuleNodeType:
|
|
145
|
+
if (data.typ == EnumToken.AtRuleNodeType && !('chi' in data)) {
|
|
148
146
|
return `${indent}@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val};`;
|
|
149
147
|
}
|
|
150
148
|
// @ts-ignore
|
|
151
149
|
let children = data.chi.reduce((css, node) => {
|
|
152
150
|
let str;
|
|
153
|
-
if (node.typ ==
|
|
151
|
+
if (node.typ == EnumToken.CommentNodeType) {
|
|
154
152
|
str = options.removeComments && (!options.preserveLicense || !node.val.startsWith('/*!')) ? '' : node.val;
|
|
155
153
|
}
|
|
156
|
-
else if (node.typ ==
|
|
154
|
+
else if (node.typ == EnumToken.DeclarationNodeType) {
|
|
157
155
|
if (node.val.length == 0) {
|
|
158
156
|
// @ts-ignore
|
|
159
157
|
errors.push({
|
|
@@ -165,7 +163,7 @@ function renderAstNode(data, options, sourcemap, position, errors, reducer, cach
|
|
|
165
163
|
}
|
|
166
164
|
str = `${node.nam}:${options.indent}${node.val.reduce(reducer, '').trimEnd()};`;
|
|
167
165
|
}
|
|
168
|
-
else if (node.typ ==
|
|
166
|
+
else if (node.typ == EnumToken.AtRuleNodeType && !('chi' in node)) {
|
|
169
167
|
str = `${data.val === '' ? '' : options.indent || ' '}${data.val};`;
|
|
170
168
|
}
|
|
171
169
|
else {
|
|
@@ -182,7 +180,7 @@ function renderAstNode(data, options, sourcemap, position, errors, reducer, cach
|
|
|
182
180
|
if (children.endsWith(';')) {
|
|
183
181
|
children = children.slice(0, -1);
|
|
184
182
|
}
|
|
185
|
-
if (data.typ ==
|
|
183
|
+
if (data.typ == EnumToken.AtRuleNodeType) {
|
|
186
184
|
return `@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val}${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
|
|
187
185
|
}
|
|
188
186
|
return data.sel + `${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
|
|
@@ -205,7 +203,35 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
205
203
|
case EnumToken.ListToken:
|
|
206
204
|
return token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache), '');
|
|
207
205
|
case EnumToken.BinaryExpressionTokenType:
|
|
206
|
+
if ([EnumToken.Mul, EnumToken.Div].includes(token.op)) {
|
|
207
|
+
let result = '';
|
|
208
|
+
if (token.l.typ == EnumToken.BinaryExpressionTokenType &&
|
|
209
|
+
[EnumToken.Add, EnumToken.Sub].includes(token.l.op)) {
|
|
210
|
+
result = '(' + renderToken(token.l, options, cache) + ')';
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
result = renderToken(token.l, options, cache);
|
|
214
|
+
}
|
|
215
|
+
result += token.op == EnumToken.Mul ? '*' : '/';
|
|
216
|
+
if (token.r.typ == EnumToken.BinaryExpressionTokenType &&
|
|
217
|
+
[EnumToken.Add, EnumToken.Sub].includes(token.r.op)) {
|
|
218
|
+
result += '(' + renderToken(token.r, options, cache) + ')';
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
result += renderToken(token.r, options, cache);
|
|
222
|
+
}
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
208
225
|
return renderToken(token.l, options, cache) + (token.op == EnumToken.Add ? ' + ' : (token.op == EnumToken.Sub ? ' - ' : (token.op == EnumToken.Mul ? '*' : '/'))) + renderToken(token.r, options, cache);
|
|
226
|
+
case EnumToken.FractionTokenType:
|
|
227
|
+
const fraction = renderToken(token.l) + '/' + renderToken(token.r);
|
|
228
|
+
if (+token.r.val != 0) {
|
|
229
|
+
const value = reduceNumber(+token.l.val / +token.r.val);
|
|
230
|
+
if (value.length <= fraction.length) {
|
|
231
|
+
return value;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return fraction;
|
|
209
235
|
case EnumToken.Add:
|
|
210
236
|
return ' + ';
|
|
211
237
|
case EnumToken.Sub:
|
|
@@ -258,21 +284,45 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
258
284
|
case EnumToken.ParensTokenType:
|
|
259
285
|
case EnumToken.FunctionTokenType:
|
|
260
286
|
case EnumToken.UrlFunctionTokenType:
|
|
287
|
+
case EnumToken.ImageFunctionTokenType:
|
|
261
288
|
case EnumToken.PseudoClassFuncTokenType:
|
|
289
|
+
case EnumToken.TimingFunctionTokenType:
|
|
290
|
+
case EnumToken.TimelineFunctionTokenType:
|
|
262
291
|
if (token.typ == EnumToken.FunctionTokenType &&
|
|
263
292
|
token.val == 'calc' &&
|
|
264
|
-
token.chi.length == 1
|
|
293
|
+
token.chi.length == 1 &&
|
|
294
|
+
token.chi[0].typ != EnumToken.BinaryExpressionTokenType &&
|
|
295
|
+
token.chi[0].typ != EnumToken.FractionTokenType &&
|
|
296
|
+
token.chi[0].val?.typ != EnumToken.FractionTokenType) {
|
|
265
297
|
// calc(200px) => 200px
|
|
266
298
|
return token.chi.reduce((acc, curr) => acc + renderToken(curr, options, cache, reducer), '');
|
|
267
299
|
}
|
|
268
300
|
// @ts-ignore
|
|
269
301
|
return ( /* options.minify && 'Pseudo-class-func' == token.typ && token.val.slice(0, 2) == '::' ? token.val.slice(1) :*/token.val ?? '') + '(' + token.chi.reduce(reducer, '') + ')';
|
|
302
|
+
case EnumToken.MatchExpressionTokenType:
|
|
303
|
+
return renderToken(token.l, options, cache, reducer, errors) +
|
|
304
|
+
renderToken({ typ: token.op }, options, cache, reducer, errors) +
|
|
305
|
+
renderToken(token.r, options, cache, reducer, errors) +
|
|
306
|
+
(token.attr ? ' ' + token.attr : '');
|
|
307
|
+
case EnumToken.NameSpaceAttributeTokenType:
|
|
308
|
+
return (token.l == null ? '' : renderToken(token.l, options, cache, reducer, errors) + '|') +
|
|
309
|
+
renderToken(token.r, options, cache, reducer, errors);
|
|
310
|
+
case EnumToken.BlockStartTokenType:
|
|
311
|
+
return '{';
|
|
312
|
+
case EnumToken.BlockEndTokenType:
|
|
313
|
+
return '}';
|
|
270
314
|
case EnumToken.StartParensTokenType:
|
|
271
315
|
return '(';
|
|
272
|
-
case EnumToken.
|
|
316
|
+
case EnumToken.IncludeMatchTokenType:
|
|
273
317
|
return '~=';
|
|
274
318
|
case EnumToken.DashMatchTokenType:
|
|
275
319
|
return '|=';
|
|
320
|
+
case EnumToken.StartMatchTokenType:
|
|
321
|
+
return '^=';
|
|
322
|
+
case EnumToken.EndMatchTokenType:
|
|
323
|
+
return '$=';
|
|
324
|
+
case EnumToken.ContainMatchTokenType:
|
|
325
|
+
return '*=';
|
|
276
326
|
case EnumToken.LtTokenType:
|
|
277
327
|
return '<';
|
|
278
328
|
case EnumToken.LteTokenType:
|
|
@@ -281,6 +331,8 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
281
331
|
return '>';
|
|
282
332
|
case EnumToken.GteTokenType:
|
|
283
333
|
return '>=';
|
|
334
|
+
case EnumToken.ColumnCombinatorTokenType:
|
|
335
|
+
return '||';
|
|
284
336
|
case EnumToken.EndParensTokenType:
|
|
285
337
|
return ')';
|
|
286
338
|
case EnumToken.AttrStartTokenType:
|
|
@@ -305,19 +357,9 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
305
357
|
case EnumToken.DimensionTokenType:
|
|
306
358
|
case EnumToken.FrequencyTokenType:
|
|
307
359
|
case EnumToken.ResolutionTokenType:
|
|
308
|
-
|
|
309
|
-
const result = renderToken(token.val, options, cache);
|
|
310
|
-
if (!('unit' in token)) {
|
|
311
|
-
return result;
|
|
312
|
-
}
|
|
313
|
-
if (!result.includes(' ')) {
|
|
314
|
-
return result + token.unit;
|
|
315
|
-
}
|
|
316
|
-
return `(${result})*1${token.unit}`;
|
|
317
|
-
}
|
|
318
|
-
let val = reduceNumber(token.val);
|
|
360
|
+
let val = token.val.typ == EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : reduceNumber(token.val);
|
|
319
361
|
let unit = token.unit;
|
|
320
|
-
if (token.typ == EnumToken.AngleTokenType) {
|
|
362
|
+
if (token.typ == EnumToken.AngleTokenType && !val.includes('/')) {
|
|
321
363
|
const angle = getAngle(token);
|
|
322
364
|
let v;
|
|
323
365
|
let value = val + unit;
|
|
@@ -374,16 +416,21 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
374
416
|
}
|
|
375
417
|
return '0';
|
|
376
418
|
}
|
|
377
|
-
return val + unit;
|
|
419
|
+
return val.includes('/') ? val.replace('/', unit + '/') : val + unit;
|
|
378
420
|
case EnumToken.PercentageTokenType:
|
|
379
|
-
const perc = reduceNumber(token.val);
|
|
380
|
-
return options.minify && perc == '0' ? '0' : perc + '%';
|
|
421
|
+
const perc = token.val.typ == EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : reduceNumber(token.val);
|
|
422
|
+
return options.minify && perc == '0' ? '0' : (perc.includes('/') ? perc.replace('/', '%/') : perc + '%');
|
|
381
423
|
case EnumToken.NumberTokenType:
|
|
382
|
-
return reduceNumber(token.val);
|
|
424
|
+
return token.val.typ == EnumToken.FractionTokenType ? renderToken(token.val, options, cache) : reduceNumber(token.val);
|
|
383
425
|
case EnumToken.CommentTokenType:
|
|
384
426
|
if (options.removeComments && (!options.preserveLicense || !token.val.startsWith('/*!'))) {
|
|
385
427
|
return '';
|
|
386
428
|
}
|
|
429
|
+
case EnumToken.PseudoClassTokenType:
|
|
430
|
+
// https://www.w3.org/TR/selectors-4/#single-colon-pseudos
|
|
431
|
+
if (token.typ == EnumToken.PseudoClassTokenType && ['::before', '::after', '::first-line', '::first-letter'].includes(token.val)) {
|
|
432
|
+
return token.val.slice(1);
|
|
433
|
+
}
|
|
387
434
|
case EnumToken.UrlTokenTokenType:
|
|
388
435
|
if (token.typ == EnumToken.UrlTokenTokenType) {
|
|
389
436
|
if (options.output != null) {
|
|
@@ -407,13 +454,13 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
407
454
|
token.val = cache[token.original];
|
|
408
455
|
}
|
|
409
456
|
}
|
|
410
|
-
case EnumToken.AtRuleTokenType:
|
|
411
457
|
case EnumToken.HashTokenType:
|
|
412
|
-
case EnumToken.PseudoClassTokenType:
|
|
413
|
-
case EnumToken.LiteralTokenType:
|
|
414
|
-
case EnumToken.StringTokenType:
|
|
415
458
|
case EnumToken.IdenTokenType:
|
|
416
459
|
case EnumToken.DelimTokenType:
|
|
460
|
+
case EnumToken.AtRuleTokenType:
|
|
461
|
+
case EnumToken.StringTokenType:
|
|
462
|
+
case EnumToken.LiteralTokenType:
|
|
463
|
+
case EnumToken.DashedIdenTokenType:
|
|
417
464
|
return /* options.minify && 'Pseudo-class' == token.typ && '::' == token.val.slice(0, 2) ? token.val.slice(1) : */ token.val;
|
|
418
465
|
}
|
|
419
466
|
errors?.push({ action: 'ignore', message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
|
package/dist/node/index.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
export { EnumToken
|
|
2
|
-
export {
|
|
1
|
+
export { EnumToken } from '../lib/ast/types.js';
|
|
2
|
+
export { minify } from '../lib/ast/minify.js';
|
|
3
3
|
export { walk, walkValues } from '../lib/ast/walk.js';
|
|
4
|
-
export { expand
|
|
4
|
+
export { expand } from '../lib/ast/expand.js';
|
|
5
5
|
import { doRender } from '../lib/renderer/render.js';
|
|
6
|
-
export {
|
|
6
|
+
export { renderToken } from '../lib/renderer/render.js';
|
|
7
7
|
import { doParse } from '../lib/parser/parse.js';
|
|
8
|
-
export { parseString, parseTokens
|
|
9
|
-
|
|
10
|
-
export { isAngle, isAtKeyword, isColor, isDigit, isDimension, isFrequency, isFunction, isHash, isHexColor, isIdent, isIdentCodepoint, isIdentStart, isLength, isNewLine, isNonPrintable, isNumber, isPercentage, isPseudo, isResolution, isTime, isWhiteSpace, parseDimension } from '../lib/parser/utils/syntax.js';
|
|
11
|
-
export { getConfig } from '../lib/parser/utils/config.js';
|
|
12
|
-
export { funcList, matchType } from '../lib/parser/utils/type.js';
|
|
13
|
-
import { load } from './load.js';
|
|
8
|
+
export { parseString, parseTokens } from '../lib/parser/parse.js';
|
|
9
|
+
import '../lib/renderer/utils/color.js';
|
|
14
10
|
import { resolve, dirname } from '../lib/fs/resolve.js';
|
|
15
|
-
|
|
11
|
+
import { load } from './load.js';
|
|
16
12
|
|
|
17
13
|
function render(data, options = {}) {
|
|
18
14
|
return doRender(data, Object.assign(options, { load, resolve, dirname, cwd: options.cwd ?? process.cwd() }));
|
|
@@ -39,4 +35,4 @@ async function transform(css, options = {}) {
|
|
|
39
35
|
});
|
|
40
36
|
}
|
|
41
37
|
|
|
42
|
-
export { dirname,
|
|
38
|
+
export { dirname, load, parse, render, resolve, transform };
|
package/dist/web/index.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
export { EnumToken
|
|
2
|
-
export {
|
|
1
|
+
export { EnumToken } from '../lib/ast/types.js';
|
|
2
|
+
export { minify } from '../lib/ast/minify.js';
|
|
3
3
|
export { walk, walkValues } from '../lib/ast/walk.js';
|
|
4
|
-
export { expand
|
|
4
|
+
export { expand } from '../lib/ast/expand.js';
|
|
5
5
|
import { doRender } from '../lib/renderer/render.js';
|
|
6
|
-
export {
|
|
6
|
+
export { renderToken } from '../lib/renderer/render.js';
|
|
7
7
|
import { doParse } from '../lib/parser/parse.js';
|
|
8
|
-
export { parseString, parseTokens
|
|
9
|
-
|
|
10
|
-
export { isAngle, isAtKeyword, isColor, isDigit, isDimension, isFrequency, isFunction, isHash, isHexColor, isIdent, isIdentCodepoint, isIdentStart, isLength, isNewLine, isNonPrintable, isNumber, isPercentage, isPseudo, isResolution, isTime, isWhiteSpace, parseDimension } from '../lib/parser/utils/syntax.js';
|
|
11
|
-
export { getConfig } from '../lib/parser/utils/config.js';
|
|
12
|
-
export { funcList, matchType } from '../lib/parser/utils/type.js';
|
|
13
|
-
import { load } from './load.js';
|
|
8
|
+
export { parseString, parseTokens } from '../lib/parser/parse.js';
|
|
9
|
+
import '../lib/renderer/utils/color.js';
|
|
14
10
|
import { resolve, dirname } from '../lib/fs/resolve.js';
|
|
15
|
-
|
|
11
|
+
import { load } from './load.js';
|
|
16
12
|
|
|
17
13
|
function render(data, options = {}) {
|
|
18
14
|
return doRender(data, Object.assign(options, {
|
|
@@ -49,4 +45,4 @@ async function transform(css, options = {}) {
|
|
|
49
45
|
});
|
|
50
46
|
}
|
|
51
47
|
|
|
52
|
-
export { dirname,
|
|
48
|
+
export { dirname, load, parse, render, resolve, transform };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbela99/css-parser",
|
|
3
3
|
"description": "CSS parser for node and the browser",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/node/index.js",
|
|
7
7
|
"./umd": "./dist/index-umd-web.js",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"type": "module",
|
|
12
12
|
"typings": "dist/index.d.ts",
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "rollup -c",
|
|
15
|
-
"test": "web-test-runner \"test/**/*.web.spec.js\" --node-resolve --root-dir=.; mocha --reporter-options='maxDiffSize=1801920' \"test/**/*.node.spec.js\"",
|
|
14
|
+
"build": "rollup -c;./build.sh dist/index.d.ts 'declare interface' 'declare type'",
|
|
15
|
+
"test": "web-test-runner \"test/**/*.web.spec.js\" --node-resolve --playwright --browsers chromium firefox webkit --root-dir=.; mocha --reporter-options='maxDiffSize=1801920' \"test/**/*.node.spec.js\"",
|
|
16
16
|
"test:cov": "c8 --reporter=html --reporter=text --reporter=json-summary mocha --reporter-options='maxDiffSize=1801920' \"test/**/*.node.spec.js\"",
|
|
17
|
-
"test:web-cov": "web-test-runner \"test/**/*.web.spec.js\" --node-resolve --root-dir=. --coverage",
|
|
17
|
+
"test:web-cov": "web-test-runner --playwright --browsers chromium firefox webkit \"test/**/*.web.spec.js\" --node-resolve --root-dir=. --coverage",
|
|
18
18
|
"profile": "node --inspect-brk test/inspect.mjs",
|
|
19
19
|
"debug": "web-test-runner \"test/**/*.web.spec.js\" --manual --open --node-resolve --root-dir=."
|
|
20
20
|
},
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"browser",
|
|
35
35
|
"css-nesting",
|
|
36
36
|
"css-compiler",
|
|
37
|
-
"nested-css"
|
|
37
|
+
"nested-css",
|
|
38
|
+
"walker"
|
|
38
39
|
],
|
|
39
40
|
"author": "Thierry Bela",
|
|
40
41
|
"license": "MIT OR LGPL-3.0",
|
|
@@ -52,6 +53,7 @@
|
|
|
52
53
|
"@types/mocha": "^10.0.1",
|
|
53
54
|
"@types/node": "^20.4.10",
|
|
54
55
|
"@web/test-runner": "^0.17.0",
|
|
56
|
+
"@web/test-runner-playwright": "^0.11.0",
|
|
55
57
|
"c8": "^8.0.1",
|
|
56
58
|
"mocha": "^10.2.0",
|
|
57
59
|
"rollup": "^3.28.0",
|
|
File without changes
|