@tbela99/css-parser 1.3.2 → 1.3.3
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 +5 -0
- package/README.md +41 -5
- package/dist/index-umd-web.js +1272 -961
- package/dist/index.cjs +1194 -920
- package/dist/index.d.ts +921 -264
- package/dist/lib/ast/features/calc.js +5 -6
- package/dist/lib/ast/features/inlinecssvariables.js +5 -6
- package/dist/lib/ast/features/prefix.js +4 -14
- package/dist/lib/ast/features/shorthand.js +4 -6
- package/dist/lib/ast/features/transform.js +5 -6
- package/dist/lib/ast/features/type.js +4 -2
- package/dist/lib/ast/minify.js +55 -114
- package/dist/lib/ast/types.js +2 -2
- package/dist/lib/ast/walk.js +149 -59
- package/dist/lib/fs/resolve.js +6 -4
- package/dist/lib/parser/declaration/list.js +1 -1
- package/dist/lib/parser/parse.js +297 -57
- package/dist/lib/parser/tokenize.js +1 -1
- package/dist/lib/renderer/render.js +5 -5
- package/dist/lib/syntax/color/cmyk.js +6 -3
- package/dist/lib/syntax/color/color-mix.js +2 -3
- package/dist/lib/syntax/color/color.js +28 -6
- package/dist/lib/syntax/color/hex.js +3 -0
- package/dist/lib/syntax/color/hsl.js +18 -7
- package/dist/lib/syntax/color/hwb.js +3 -3
- package/dist/lib/syntax/color/lab.js +4 -4
- package/dist/lib/syntax/color/lch.js +7 -4
- package/dist/lib/syntax/color/oklab.js +4 -4
- package/dist/lib/syntax/color/oklch.js +18 -6
- package/dist/lib/syntax/color/relativecolor.js +9 -56
- package/dist/lib/syntax/color/srgb.js +1 -1
- package/dist/lib/validation/config.json.js +4 -12
- package/dist/node.js +53 -31
- package/dist/web.js +76 -17
- package/package.json +2 -3
|
@@ -8,16 +8,14 @@ import '../minify.js';
|
|
|
8
8
|
import '../../parser/parse.js';
|
|
9
9
|
import '../../parser/tokenize.js';
|
|
10
10
|
import '../../parser/utils/config.js';
|
|
11
|
+
import { FeatureWalkMode } from './type.js';
|
|
11
12
|
|
|
12
13
|
class ComputeCalcExpressionFeature {
|
|
13
14
|
get ordering() {
|
|
14
15
|
return 1;
|
|
15
16
|
}
|
|
16
|
-
get
|
|
17
|
-
return
|
|
18
|
-
}
|
|
19
|
-
get postProcess() {
|
|
20
|
-
return true;
|
|
17
|
+
get processMode() {
|
|
18
|
+
return FeatureWalkMode.Post;
|
|
21
19
|
}
|
|
22
20
|
static register(options) {
|
|
23
21
|
if (options.computeCalcExpression) {
|
|
@@ -27,7 +25,7 @@ class ComputeCalcExpressionFeature {
|
|
|
27
25
|
}
|
|
28
26
|
run(ast) {
|
|
29
27
|
if (!('chi' in ast)) {
|
|
30
|
-
return;
|
|
28
|
+
return null;
|
|
31
29
|
}
|
|
32
30
|
for (const node of ast.chi) {
|
|
33
31
|
if (node.typ != EnumToken.DeclarationNodeType) {
|
|
@@ -106,6 +104,7 @@ class ComputeCalcExpressionFeature {
|
|
|
106
104
|
}
|
|
107
105
|
}
|
|
108
106
|
}
|
|
107
|
+
return null;
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
|
|
@@ -7,6 +7,7 @@ import { splitRule } from '../minify.js';
|
|
|
7
7
|
import '../../parser/parse.js';
|
|
8
8
|
import '../../parser/tokenize.js';
|
|
9
9
|
import '../../parser/utils/config.js';
|
|
10
|
+
import { FeatureWalkMode } from './type.js';
|
|
10
11
|
|
|
11
12
|
function inlineExpression(token) {
|
|
12
13
|
const result = [];
|
|
@@ -54,11 +55,8 @@ class InlineCssVariablesFeature {
|
|
|
54
55
|
get ordering() {
|
|
55
56
|
return 0;
|
|
56
57
|
}
|
|
57
|
-
get
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
get postProcess() {
|
|
61
|
-
return false;
|
|
58
|
+
get processMode() {
|
|
59
|
+
return FeatureWalkMode.Pre;
|
|
62
60
|
}
|
|
63
61
|
static register(options) {
|
|
64
62
|
if (options.inlineCssVariables) {
|
|
@@ -68,7 +66,7 @@ class InlineCssVariablesFeature {
|
|
|
68
66
|
}
|
|
69
67
|
run(ast, options = {}, parent, context) {
|
|
70
68
|
if (!('chi' in ast)) {
|
|
71
|
-
return;
|
|
69
|
+
return null;
|
|
72
70
|
}
|
|
73
71
|
if (!('variableScope' in context)) {
|
|
74
72
|
context.variableScope = new Map;
|
|
@@ -111,6 +109,7 @@ class InlineCssVariablesFeature {
|
|
|
111
109
|
replace(node, variableScope);
|
|
112
110
|
}
|
|
113
111
|
}
|
|
112
|
+
return null;
|
|
114
113
|
}
|
|
115
114
|
cleanup(ast, options = {}, context) {
|
|
116
115
|
const variableScope = context.variableScope;
|
|
@@ -13,6 +13,7 @@ import '../../renderer/sourcemap/lib/encode.js';
|
|
|
13
13
|
import '../../validation/syntaxes/complex-selector.js';
|
|
14
14
|
import { evaluateSyntax } from '../../validation/syntax.js';
|
|
15
15
|
import { funcLike } from '../../syntax/color/utils/constants.js';
|
|
16
|
+
import { FeatureWalkMode } from './type.js';
|
|
16
17
|
|
|
17
18
|
const config = getSyntaxConfig();
|
|
18
19
|
function replacePseudo(tokens) {
|
|
@@ -59,11 +60,8 @@ class ComputePrefixFeature {
|
|
|
59
60
|
get ordering() {
|
|
60
61
|
return 2;
|
|
61
62
|
}
|
|
62
|
-
get
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
get postProcess() {
|
|
66
|
-
return false;
|
|
63
|
+
get processMode() {
|
|
64
|
+
return FeatureWalkMode.Pre;
|
|
67
65
|
}
|
|
68
66
|
static register(options) {
|
|
69
67
|
if (options.removePrefix) {
|
|
@@ -128,7 +126,7 @@ class ComputePrefixFeature {
|
|
|
128
126
|
}
|
|
129
127
|
}
|
|
130
128
|
}
|
|
131
|
-
else if (node.typ == EnumToken.AtRuleNodeType || node.typ == EnumToken.
|
|
129
|
+
else if (node.typ == EnumToken.AtRuleNodeType || node.typ == EnumToken.KeyframesAtRuleNodeType) {
|
|
132
130
|
if (node.nam.startsWith('-')) {
|
|
133
131
|
const match = node.nam.match(/^-([^-]+)-(.+)$/);
|
|
134
132
|
if (match != null && '@' + match[2] in config.atRules) {
|
|
@@ -136,14 +134,6 @@ class ComputePrefixFeature {
|
|
|
136
134
|
}
|
|
137
135
|
}
|
|
138
136
|
if (node.typ == EnumToken.AtRuleNodeType && node.val !== '') {
|
|
139
|
-
// if ((node as AstAtRule).tokens == null) {
|
|
140
|
-
//
|
|
141
|
-
// Object.defineProperty(node, 'tokens', {
|
|
142
|
-
// // @ts-ignore
|
|
143
|
-
// ...definedPropertySettings,
|
|
144
|
-
// value: parseAtRulePrelude(parseString((node as AstAtRule).val), node as AstAtRule),
|
|
145
|
-
// })
|
|
146
|
-
// }
|
|
147
137
|
if (replaceAstNodes(node.tokens)) {
|
|
148
138
|
node.val = node.tokens.reduce((acc, curr) => acc + renderToken(curr), '');
|
|
149
139
|
}
|
|
@@ -7,16 +7,14 @@ import '../../parser/tokenize.js';
|
|
|
7
7
|
import '../../parser/utils/config.js';
|
|
8
8
|
import '../../syntax/color/utils/constants.js';
|
|
9
9
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
10
|
+
import { FeatureWalkMode } from './type.js';
|
|
10
11
|
|
|
11
12
|
class ComputeShorthandFeature {
|
|
12
13
|
get ordering() {
|
|
13
14
|
return 3;
|
|
14
15
|
}
|
|
15
|
-
get
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
get postProcess() {
|
|
19
|
-
return true;
|
|
16
|
+
get processMode() {
|
|
17
|
+
return FeatureWalkMode.Post;
|
|
20
18
|
}
|
|
21
19
|
static register(options) {
|
|
22
20
|
if (options.computeShorthand) {
|
|
@@ -26,7 +24,7 @@ class ComputeShorthandFeature {
|
|
|
26
24
|
}
|
|
27
25
|
run(ast, options = {}, parent, context) {
|
|
28
26
|
if (!('chi' in ast)) {
|
|
29
|
-
return
|
|
27
|
+
return null;
|
|
30
28
|
}
|
|
31
29
|
// @ts-ignore
|
|
32
30
|
const j = ast.chi.length;
|
|
@@ -10,16 +10,14 @@ import { filterValues, renderToken } from '../../renderer/render.js';
|
|
|
10
10
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
11
11
|
import { compute } from '../transform/compute.js';
|
|
12
12
|
import { eqMatrix } from '../transform/minify.js';
|
|
13
|
+
import { FeatureWalkMode } from './type.js';
|
|
13
14
|
|
|
14
15
|
class TransformCssFeature {
|
|
15
16
|
get ordering() {
|
|
16
17
|
return 4;
|
|
17
18
|
}
|
|
18
|
-
get
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
get postProcess() {
|
|
22
|
-
return true;
|
|
19
|
+
get processMode() {
|
|
20
|
+
return FeatureWalkMode.Post;
|
|
23
21
|
}
|
|
24
22
|
static register(options) {
|
|
25
23
|
// @ts-ignore
|
|
@@ -30,7 +28,7 @@ class TransformCssFeature {
|
|
|
30
28
|
}
|
|
31
29
|
run(ast) {
|
|
32
30
|
if (!('chi' in ast)) {
|
|
33
|
-
return;
|
|
31
|
+
return null;
|
|
34
32
|
}
|
|
35
33
|
let i = 0;
|
|
36
34
|
let node;
|
|
@@ -77,6 +75,7 @@ class TransformCssFeature {
|
|
|
77
75
|
return acc;
|
|
78
76
|
}, [matrix]);
|
|
79
77
|
}
|
|
78
|
+
return null;
|
|
80
79
|
}
|
|
81
80
|
}
|
|
82
81
|
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* feature walk mode
|
|
3
|
+
*
|
|
4
|
+
* @internal
|
|
3
5
|
*/
|
|
4
6
|
var FeatureWalkMode;
|
|
5
7
|
(function (FeatureWalkMode) {
|
|
6
8
|
/**
|
|
7
9
|
* pre process
|
|
8
10
|
*/
|
|
9
|
-
FeatureWalkMode[FeatureWalkMode["Pre"] =
|
|
11
|
+
FeatureWalkMode[FeatureWalkMode["Pre"] = 1] = "Pre";
|
|
10
12
|
/**
|
|
11
13
|
* post process
|
|
12
14
|
*/
|
|
13
|
-
FeatureWalkMode[FeatureWalkMode["Post"] =
|
|
15
|
+
FeatureWalkMode[FeatureWalkMode["Post"] = 2] = "Post";
|
|
14
16
|
})(FeatureWalkMode || (FeatureWalkMode = {}));
|
|
15
17
|
|
|
16
18
|
export { FeatureWalkMode };
|