@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/lib/ast/expand.js
CHANGED
|
@@ -5,30 +5,16 @@ import '../parser/utils/config.js';
|
|
|
5
5
|
import { EnumToken } from './types.js';
|
|
6
6
|
import { walkValues } from './walk.js';
|
|
7
7
|
import { renderToken } from '../renderer/render.js';
|
|
8
|
+
import '../renderer/sourcemap/lib/encode.js';
|
|
8
9
|
import '../syntax/color/utils/constants.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
|
-
* expand
|
|
12
|
+
* expand css nesting ast nodes
|
|
12
13
|
* @param ast
|
|
14
|
+
*
|
|
15
|
+
* @private
|
|
13
16
|
*/
|
|
14
17
|
function expand(ast) {
|
|
15
|
-
//
|
|
16
|
-
// if (![EnumToken.RuleNodeType, EnumToken.StyleSheetNodeType, EnumToken.AtRuleNodeType].includes(ast.typ)) {
|
|
17
|
-
//
|
|
18
|
-
// return ast;
|
|
19
|
-
// }
|
|
20
|
-
// if (EnumToken.RuleNodeType == ast.typ) {
|
|
21
|
-
//
|
|
22
|
-
// return <AstRuleStyleSheet>{
|
|
23
|
-
// typ: EnumToken.StyleSheetNodeType,
|
|
24
|
-
// chi: expandRule(<AstRule>ast)
|
|
25
|
-
// }
|
|
26
|
-
// }
|
|
27
|
-
//
|
|
28
|
-
// if (!('chi' in ast)) {
|
|
29
|
-
//
|
|
30
|
-
// return ast;
|
|
31
|
-
// }
|
|
32
18
|
const result = { ...ast, chi: [] };
|
|
33
19
|
// @ts-ignore
|
|
34
20
|
for (let i = 0; i < ast.chi.length; i++) {
|
|
@@ -52,11 +38,6 @@ function expand(ast) {
|
|
|
52
38
|
// @ts-ignore
|
|
53
39
|
result.chi.push({ ...(hasRule ? expand(node) : node) });
|
|
54
40
|
}
|
|
55
|
-
// else {
|
|
56
|
-
//
|
|
57
|
-
// // @ts-ignore
|
|
58
|
-
// result.chi.push(node);
|
|
59
|
-
// }
|
|
60
41
|
}
|
|
61
42
|
return result;
|
|
62
43
|
}
|
|
@@ -70,14 +51,6 @@ function expandRule(node) {
|
|
|
70
51
|
const rule = ast.chi[i];
|
|
71
52
|
if (!rule.sel.includes('&')) {
|
|
72
53
|
const selRule = splitRule(rule.sel);
|
|
73
|
-
// if (selRule.length > 1) {
|
|
74
|
-
//
|
|
75
|
-
// const r: string = ':is(' + selRule.map(a => a.join('')).join(',') + ')';
|
|
76
|
-
// rule.sel = splitRule(ast.sel).reduce((a: string[], b: string[]): string[] => a.concat([b.join('') + r]), <string[]>[]).join(',');
|
|
77
|
-
//
|
|
78
|
-
// }
|
|
79
|
-
// else {
|
|
80
|
-
// selRule = splitRule(selRule.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.join(''), ''));
|
|
81
54
|
const arSelf = splitRule(ast.sel).filter((r) => r.every((t) => t != ':before' && t != ':after' && !t.startsWith('::'))).reduce((acc, curr) => acc.concat([curr.join('')]), []).join(',');
|
|
82
55
|
if (arSelf.length == 0) {
|
|
83
56
|
ast.chi.splice(i--, 1);
|
|
@@ -115,10 +88,6 @@ function expandRule(node) {
|
|
|
115
88
|
if (s == '&' || parentSelector) {
|
|
116
89
|
withCompound.push(s);
|
|
117
90
|
}
|
|
118
|
-
// else {
|
|
119
|
-
//
|
|
120
|
-
// withoutCompound.push(s.slice(1));
|
|
121
|
-
// }
|
|
122
91
|
}
|
|
123
92
|
}
|
|
124
93
|
else {
|
|
@@ -129,10 +98,6 @@ function expandRule(node) {
|
|
|
129
98
|
withCompound.push(s);
|
|
130
99
|
}
|
|
131
100
|
}
|
|
132
|
-
// else {
|
|
133
|
-
//
|
|
134
|
-
// withoutCompound.push(s);
|
|
135
|
-
// }
|
|
136
101
|
}
|
|
137
102
|
const selectors = [];
|
|
138
103
|
const selector = rules.length > 1 ? ':is(' + rules.map(a => a.join('')).join(',') + ')' : rules[0].join('');
|
|
@@ -164,13 +129,6 @@ function expandRule(node) {
|
|
|
164
129
|
if (withCompound.length == 1) {
|
|
165
130
|
selectors.push(replaceCompound(withCompound[0], selector));
|
|
166
131
|
}
|
|
167
|
-
// else {
|
|
168
|
-
//
|
|
169
|
-
// for (const w of withCompound) {
|
|
170
|
-
//
|
|
171
|
-
// selectors.push(replaceCompound(w, selector));
|
|
172
|
-
// }
|
|
173
|
-
// }
|
|
174
132
|
}
|
|
175
133
|
rule.sel = selectors.reduce((acc, curr) => curr.length == 0 ? acc : acc + (acc.length > 0 ? ',' : '') + curr, '');
|
|
176
134
|
}
|
|
@@ -211,11 +169,6 @@ function expandRule(node) {
|
|
|
211
169
|
// @ts-ignore
|
|
212
170
|
astAtRule.chi.push(...expandRule(r));
|
|
213
171
|
}
|
|
214
|
-
// else {
|
|
215
|
-
//
|
|
216
|
-
// // @ts-ignore
|
|
217
|
-
// astAtRule.chi.push(r);
|
|
218
|
-
// }
|
|
219
172
|
}
|
|
220
173
|
}
|
|
221
174
|
// @ts-ignore
|
|
@@ -242,12 +195,6 @@ function replaceCompound(input, replace) {
|
|
|
242
195
|
if (replacement == null) {
|
|
243
196
|
replacement = parseString(replace);
|
|
244
197
|
}
|
|
245
|
-
// if (tokens[1].typ == EnumToken.IdenTokenType) {
|
|
246
|
-
//
|
|
247
|
-
//
|
|
248
|
-
// (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);
|
|
249
|
-
// tokens.splice(1, 1);
|
|
250
|
-
// } else {
|
|
251
198
|
t.value.val = replaceCompoundLiteral(t.value.val, replace);
|
|
252
199
|
// }
|
|
253
200
|
continue;
|
|
@@ -255,10 +202,6 @@ function replaceCompound(input, replace) {
|
|
|
255
202
|
const rule = splitRule(replace);
|
|
256
203
|
t.value.val = rule.length > 1 ? ':is(' + replace + ')' : replace;
|
|
257
204
|
}
|
|
258
|
-
// else if ((t.value as LiteralToken).val.length > 1 && (t.value as LiteralToken).val.charAt(0) == '&') {
|
|
259
|
-
//
|
|
260
|
-
// (t.value as LiteralToken).val = replaceCompoundLiteral((t.value as LiteralToken).val, replace);
|
|
261
|
-
// }
|
|
262
205
|
}
|
|
263
206
|
}
|
|
264
207
|
return tokens.reduce((acc, curr) => acc + renderToken(curr), '');
|
|
@@ -271,10 +214,6 @@ function replaceCompoundLiteral(selector, replace) {
|
|
|
271
214
|
tokens.push('&');
|
|
272
215
|
tokens.push('');
|
|
273
216
|
}
|
|
274
|
-
// else {
|
|
275
|
-
//
|
|
276
|
-
// tokens[tokens.length - 1] += selector.charAt(i);
|
|
277
|
-
// }
|
|
278
217
|
}
|
|
279
218
|
return tokens.sort((a, b) => {
|
|
280
219
|
if (a == '&') {
|
|
@@ -2,12 +2,12 @@ import { EnumToken } from '../types.js';
|
|
|
2
2
|
import { walkValues, WalkerValueEvent, WalkerOptionEnum } from '../walk.js';
|
|
3
3
|
import { evaluate } from '../math/expression.js';
|
|
4
4
|
import { renderToken } from '../../renderer/render.js';
|
|
5
|
-
import '../../
|
|
5
|
+
import '../../renderer/sourcemap/lib/encode.js';
|
|
6
|
+
import { mathFuncs } from '../../syntax/syntax.js';
|
|
6
7
|
import '../minify.js';
|
|
7
8
|
import '../../parser/parse.js';
|
|
8
9
|
import '../../parser/tokenize.js';
|
|
9
10
|
import '../../parser/utils/config.js';
|
|
10
|
-
import { mathFuncs } from '../../syntax/syntax.js';
|
|
11
11
|
|
|
12
12
|
class ComputeCalcExpressionFeature {
|
|
13
13
|
get ordering() {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { EnumToken } from '../types.js';
|
|
2
2
|
import { walkValues } from '../walk.js';
|
|
3
3
|
import { renderToken } from '../../renderer/render.js';
|
|
4
|
-
import '../../
|
|
4
|
+
import '../../renderer/sourcemap/lib/encode.js';
|
|
5
|
+
import { mathFuncs } from '../../syntax/syntax.js';
|
|
5
6
|
import { splitRule } from '../minify.js';
|
|
6
7
|
import '../../parser/parse.js';
|
|
7
8
|
import '../../parser/tokenize.js';
|
|
8
9
|
import '../../parser/utils/config.js';
|
|
9
|
-
import { mathFuncs } from '../../syntax/syntax.js';
|
|
10
10
|
|
|
11
11
|
function inlineExpression(token) {
|
|
12
12
|
const result = [];
|
|
@@ -9,9 +9,10 @@ import '../../parser/tokenize.js';
|
|
|
9
9
|
import '../../parser/utils/config.js';
|
|
10
10
|
import { pseudoAliasMap } from '../../syntax/syntax.js';
|
|
11
11
|
import { renderToken } from '../../renderer/render.js';
|
|
12
|
-
import
|
|
12
|
+
import '../../renderer/sourcemap/lib/encode.js';
|
|
13
13
|
import '../../validation/syntaxes/complex-selector.js';
|
|
14
14
|
import { evaluateSyntax } from '../../validation/syntax.js';
|
|
15
|
+
import { funcLike } from '../../syntax/color/utils/constants.js';
|
|
15
16
|
|
|
16
17
|
const config = getSyntaxConfig();
|
|
17
18
|
function replacePseudo(tokens) {
|
|
@@ -5,8 +5,9 @@ import '../walk.js';
|
|
|
5
5
|
import '../../parser/parse.js';
|
|
6
6
|
import '../../parser/tokenize.js';
|
|
7
7
|
import '../../parser/utils/config.js';
|
|
8
|
-
import { filterValues, renderToken } from '../../renderer/render.js';
|
|
9
8
|
import '../../syntax/color/utils/constants.js';
|
|
9
|
+
import { filterValues, renderToken } from '../../renderer/render.js';
|
|
10
|
+
import '../../renderer/sourcemap/lib/encode.js';
|
|
10
11
|
import { compute } from '../transform/compute.js';
|
|
11
12
|
import { eqMatrix } from '../transform/minify.js';
|
|
12
13
|
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* feature walk mode
|
|
3
|
+
*/
|
|
1
4
|
var FeatureWalkMode;
|
|
2
5
|
(function (FeatureWalkMode) {
|
|
6
|
+
/**
|
|
7
|
+
* pre process
|
|
8
|
+
*/
|
|
3
9
|
FeatureWalkMode[FeatureWalkMode["Pre"] = 0] = "Pre";
|
|
10
|
+
/**
|
|
11
|
+
* post process
|
|
12
|
+
*/
|
|
4
13
|
FeatureWalkMode[FeatureWalkMode["Post"] = 1] = "Post";
|
|
5
14
|
})(FeatureWalkMode || (FeatureWalkMode = {}));
|
|
6
15
|
|
|
@@ -4,8 +4,8 @@ import '../walk.js';
|
|
|
4
4
|
import '../../parser/parse.js';
|
|
5
5
|
import '../../parser/tokenize.js';
|
|
6
6
|
import '../../parser/utils/config.js';
|
|
7
|
-
import '../../syntax/color/utils/constants.js';
|
|
8
7
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
8
|
+
import '../../syntax/color/utils/constants.js';
|
|
9
9
|
import { minifyNumber } from '../../syntax/utils.js';
|
|
10
10
|
|
|
11
11
|
function gcd(x, y) {
|