@tbela99/css-parser 1.6.9 → 1.8.1
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 +42 -1
- package/README.md +1 -0
- package/dist/index-umd-web.js +1139 -529
- package/dist/index.cjs +1138 -528
- package/dist/index.d.ts +259 -8
- package/dist/package.json.js +2 -2
- package/dist/src/data/properties.json.js +1 -1
- package/dist/src/data/validation.json.js +11 -2
- package/dist/src/lib/ast/clone.js +1 -1
- package/dist/src/lib/ast/expand.js +1 -1
- package/dist/src/lib/ast/features/calc.js +1 -1
- package/dist/src/lib/ast/features/if.js +1 -1
- package/dist/src/lib/ast/features/index.js +1 -1
- package/dist/src/lib/ast/features/inlinecssvariables.js +6 -5
- package/dist/src/lib/ast/features/prefix.js +1 -1
- package/dist/src/lib/ast/features/shorthand.js +39 -22
- package/dist/src/lib/ast/features/transform.js +1 -1
- package/dist/src/lib/ast/features/type.js +1 -1
- package/dist/src/lib/ast/find.js +26 -21
- package/dist/src/lib/ast/math/expression.js +4 -1
- package/dist/src/lib/ast/math/math.js +1 -1
- package/dist/src/lib/ast/minify.js +31 -3
- package/dist/src/lib/ast/node.js +1 -1
- package/dist/src/lib/ast/transform/compute.js +1 -1
- package/dist/src/lib/ast/transform/matrix.js +1 -1
- package/dist/src/lib/ast/transform/minify.js +1 -1
- package/dist/src/lib/ast/transform/perspective.js +1 -1
- package/dist/src/lib/ast/transform/rotate.js +1 -1
- package/dist/src/lib/ast/transform/scale.js +1 -1
- package/dist/src/lib/ast/transform/skew.js +1 -1
- package/dist/src/lib/ast/transform/translate.js +1 -1
- package/dist/src/lib/ast/transform/utils.js +1 -1
- package/dist/src/lib/ast/types.js +5 -1
- package/dist/src/lib/ast/walk.js +319 -94
- package/dist/src/lib/fs/resolve.js +1 -1
- package/dist/src/lib/parser/declaration/list.js +35 -1
- package/dist/src/lib/parser/declaration/map.js +2 -2
- package/dist/src/lib/parser/declaration/set.js +1 -1
- package/dist/src/lib/parser/linesmap.js +1 -1
- package/dist/src/lib/parser/parse.js +504 -177
- package/dist/src/lib/parser/source.js +1 -1
- package/dist/src/lib/parser/tokenize.js +23 -3
- package/dist/src/lib/parser/utils/angle.js +1 -1
- package/dist/src/lib/parser/utils/at-rule-container.js +1 -1
- package/dist/src/lib/parser/utils/at-rule-font-feature-values.js +1 -1
- package/dist/src/lib/parser/utils/at-rule-generic.js +1 -1
- package/dist/src/lib/parser/utils/at-rule-import.js +1 -1
- package/dist/src/lib/parser/utils/at-rule-media.js +2 -2
- package/dist/src/lib/parser/utils/at-rule-support.js +2 -2
- package/dist/src/lib/parser/utils/at-rule-when-else.js +1 -1
- package/dist/src/lib/parser/utils/at-rule.js +1 -1
- package/dist/src/lib/parser/utils/base64.js +1 -1
- package/dist/src/lib/parser/utils/cache.js +1 -1
- package/dist/src/lib/parser/utils/config.js +1 -1
- package/dist/src/lib/parser/utils/declaration.js +1 -1
- package/dist/src/lib/parser/utils/eq.js +1 -1
- package/dist/src/lib/parser/utils/hash.js +1 -1
- package/dist/src/lib/parser/utils/selector.js +1 -1
- package/dist/src/lib/parser/utils/text.js +1 -1
- package/dist/src/lib/parser/utils/token.js +12 -4
- package/dist/src/lib/parser/utils/type.js +1 -1
- package/dist/src/lib/printer/render.js +6 -3
- package/dist/src/lib/printer/sourcemap/lib/codec.js +1 -1
- package/dist/src/lib/printer/sourcemap/sourcemap.js +1 -1
- package/dist/src/lib/syntax/color/a98rgb.js +1 -1
- package/dist/src/lib/syntax/color/alpha.js +1 -1
- package/dist/src/lib/syntax/color/cmyk.js +1 -1
- package/dist/src/lib/syntax/color/color-mix.js +1 -1
- package/dist/src/lib/syntax/color/color.js +1 -1
- package/dist/src/lib/syntax/color/hex.js +1 -1
- package/dist/src/lib/syntax/color/hsl.js +1 -1
- package/dist/src/lib/syntax/color/hwb.js +1 -1
- package/dist/src/lib/syntax/color/lab.js +1 -1
- package/dist/src/lib/syntax/color/lch.js +1 -1
- package/dist/src/lib/syntax/color/oklab.js +1 -1
- package/dist/src/lib/syntax/color/oklch.js +1 -1
- package/dist/src/lib/syntax/color/p3.js +1 -1
- package/dist/src/lib/syntax/color/prophotorgb.js +1 -1
- package/dist/src/lib/syntax/color/rec2020.js +1 -1
- package/dist/src/lib/syntax/color/relative-color.js +1 -1
- package/dist/src/lib/syntax/color/rgb.js +1 -1
- package/dist/src/lib/syntax/color/srgb.js +1 -1
- package/dist/src/lib/syntax/color/utils/color-type.js +1 -1
- package/dist/src/lib/syntax/color/utils/colorspace.js +1 -1
- package/dist/src/lib/syntax/color/utils/components.js +1 -1
- package/dist/src/lib/syntax/color/utils/distance.js +1 -1
- package/dist/src/lib/syntax/color/utils/make-color.js +1 -1
- package/dist/src/lib/syntax/color/utils/matrix.js +1 -1
- package/dist/src/lib/syntax/color/xyz.js +1 -1
- package/dist/src/lib/syntax/color/xyzd50.js +1 -1
- package/dist/src/lib/syntax/constants.js +1 -1
- package/dist/src/lib/syntax/syntax.js +1 -1
- package/dist/src/lib/validation/config.js +20 -3
- package/dist/src/lib/validation/match.js +105 -200
- package/dist/src/lib/validation/parser/parse.js +8 -3
- package/dist/src/lib/validation/parser/typedef.js +1 -1
- package/dist/src/lib/validation/utils/list.js +1 -1
- package/dist/src/node.js +2 -1
- package/dist/src/types.js +1 -1
- package/dist/src/utils/sync.js +1 -1
- package/dist/src/web.js +2 -1
- package/package.json +8 -7
- package/CONTRIBUTING.md +0 -119
package/dist/src/lib/ast/find.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 1.
|
|
5
|
+
Version: 1.8.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken } from './types.js';
|
|
9
9
|
import { walk, walkValues } from './walk.js';
|
|
10
|
-
import { TOKENS } from '../syntax/constants.js';
|
|
10
|
+
import { PARENT, TOKENS } from '../syntax/constants.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Search the ast subtree and return the first match
|
|
@@ -41,9 +41,9 @@ button {
|
|
|
41
41
|
* @returns
|
|
42
42
|
*/
|
|
43
43
|
function find(ast, matcher) {
|
|
44
|
-
for (const
|
|
45
|
-
if (matcher(node, parent)) {
|
|
46
|
-
return node;
|
|
44
|
+
for (const r of walk(ast)) {
|
|
45
|
+
if (matcher(r.node, r.parent)) {
|
|
46
|
+
return r.node;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
return null;
|
|
@@ -82,21 +82,25 @@ button {
|
|
|
82
82
|
*/
|
|
83
83
|
function findByValue(ast, matcher) {
|
|
84
84
|
let source;
|
|
85
|
-
for (const
|
|
85
|
+
for (const r1 of walk(ast)) {
|
|
86
86
|
source = null;
|
|
87
|
-
if (node.typ === EnumToken.DeclarationNodeType) {
|
|
88
|
-
source = node.val;
|
|
87
|
+
if (r1.node.typ === EnumToken.DeclarationNodeType) {
|
|
88
|
+
source = r1.node.val;
|
|
89
89
|
}
|
|
90
|
-
else if (Array.isArray(node[TOKENS])) {
|
|
91
|
-
source = node[TOKENS];
|
|
90
|
+
else if (Array.isArray(r1.node[TOKENS])) {
|
|
91
|
+
source = r1.node[TOKENS];
|
|
92
92
|
}
|
|
93
93
|
if (source == null) {
|
|
94
94
|
continue;
|
|
95
95
|
}
|
|
96
|
-
for (const
|
|
97
|
-
if (matcher(value, node)) {
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
for (const r2 of walkValues(source, r1.node)) {
|
|
97
|
+
if (matcher(r2.value, r1.node)) {
|
|
98
|
+
return {
|
|
99
|
+
// @ts-ignore
|
|
100
|
+
node: r1.node,
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
value: { node: r2.value, parent: r2.parent, root: r2.root, parents: r2.parents },
|
|
103
|
+
};
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
106
|
}
|
|
@@ -138,9 +142,9 @@ button-small {
|
|
|
138
142
|
*/
|
|
139
143
|
function findAll(ast, matcher) {
|
|
140
144
|
const result = [];
|
|
141
|
-
for (const
|
|
142
|
-
if (matcher(node,
|
|
143
|
-
result.push(node);
|
|
145
|
+
for (const r of walk(ast)) {
|
|
146
|
+
if (matcher(r.node, r.node[PARENT])) {
|
|
147
|
+
result.push(r.node);
|
|
144
148
|
}
|
|
145
149
|
}
|
|
146
150
|
return result;
|
|
@@ -176,11 +180,12 @@ button {
|
|
|
176
180
|
* @returns
|
|
177
181
|
*/
|
|
178
182
|
function findLast(ast, matcher) {
|
|
179
|
-
for (const
|
|
180
|
-
|
|
181
|
-
|
|
183
|
+
for (const result of walk(ast, null, true))
|
|
184
|
+
// for (const { node, parent } of walk(ast as AstNode, null, true)) {
|
|
185
|
+
if (matcher(result.node, result.parent)) {
|
|
186
|
+
return result.node;
|
|
182
187
|
}
|
|
183
|
-
}
|
|
188
|
+
// }
|
|
184
189
|
return null;
|
|
185
190
|
}
|
|
186
191
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 1.
|
|
5
|
+
Version: 1.8.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { equalsIgnoreCase } from '../../parser/utils/text.js';
|
|
@@ -139,6 +139,9 @@ function evaluate(tokens) {
|
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
if (acc.length > 0 && curr[0] != EnumToken.ListToken) {
|
|
142
|
+
if ("val" in token && +token.val == 0) {
|
|
143
|
+
return acc;
|
|
144
|
+
}
|
|
142
145
|
acc.push({
|
|
143
146
|
typ: EnumToken.Add,
|
|
144
147
|
[LOCSRCID]: token[LOCSRCID],
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 1.
|
|
5
|
+
Version: 1.8.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { eq } from '../parser/utils/eq.js';
|
|
@@ -17,6 +17,7 @@ import { TOKENS, PARENT, OPTIMIZED, RAW, combinators, LOCEND, LOCSTA, LOCSRCID }
|
|
|
17
17
|
import { replaceNodeOrValue } from '../parser/utils/token.js';
|
|
18
18
|
import { parseString } from '../parser/parse.js';
|
|
19
19
|
import { replaceCompound } from './expand.js';
|
|
20
|
+
import { equalsIgnoreCase } from '../parser/utils/text.js';
|
|
20
21
|
|
|
21
22
|
const notEndingWith = ["(", "["].concat(combinators);
|
|
22
23
|
const rules = [
|
|
@@ -366,8 +367,35 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
|
|
|
366
367
|
previous = ast.chi[--nodeIndex];
|
|
367
368
|
}
|
|
368
369
|
node = ast.chi[i];
|
|
369
|
-
if (node.typ === EnumToken.AtRuleNodeType
|
|
370
|
-
|
|
370
|
+
if (node.typ === EnumToken.AtRuleNodeType) {
|
|
371
|
+
if (node.nam === "font-face") {
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
// https://drafts.csswg.org/css-mixins/#:~:text=The%20value%20of%20the%20result%20descriptor%20is%20always%2016px%20in%20the%20above%20example
|
|
375
|
+
if (equalsIgnoreCase(node.nam, "function")) {
|
|
376
|
+
const chi = node.chi;
|
|
377
|
+
let k = chi?.length;
|
|
378
|
+
let slice = false;
|
|
379
|
+
while (k--) {
|
|
380
|
+
if (chi[k].typ === EnumToken.CommentNodeType ||
|
|
381
|
+
chi[k].typ === EnumToken.WhitespaceTokenType) {
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (chi[k].typ === EnumToken.DeclarationNodeType &&
|
|
385
|
+
equalsIgnoreCase(chi[k].nam, "result")) {
|
|
386
|
+
slice = true;
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (k > 0 && slice) {
|
|
391
|
+
while (k--) {
|
|
392
|
+
if (chi[k].typ === EnumToken.AtRuleNodeType) {
|
|
393
|
+
chi.splice(k, 1);
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
371
399
|
}
|
|
372
400
|
if (node.typ === EnumToken.KeyframesAtRuleNodeType) {
|
|
373
401
|
if (previous?.typ === EnumToken.KeyframesAtRuleNodeType &&
|
package/dist/src/lib/ast/node.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 1.
|
|
5
|
+
Version: 1.8.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
@@ -691,6 +691,10 @@ var EnumToken;
|
|
|
691
691
|
* CSS type token
|
|
692
692
|
*/
|
|
693
693
|
EnumToken[EnumToken["CssTypeTokenType"] = 144] = "CssTypeTokenType";
|
|
694
|
+
/**
|
|
695
|
+
* user defined dimension token type
|
|
696
|
+
*/
|
|
697
|
+
EnumToken[EnumToken["UserDefinedDimensionTokenType"] = 145] = "UserDefinedDimensionTokenType";
|
|
694
698
|
/* aliases */
|
|
695
699
|
/**
|
|
696
700
|
* alias for time token type
|