@tbela99/css-parser 1.7.0 → 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 +30 -0
- package/README.md +1 -0
- package/dist/index-umd-web.js +926 -293
- package/dist/index.cjs +925 -292
- package/dist/index.d.ts +251 -7
- package/dist/package.json.js +2 -2
- package/dist/src/data/properties.json.js +1 -1
- package/dist/src/data/validation.json.js +4 -1
- 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 +1 -1
- 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 +1 -1
- 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 +25 -1
- package/dist/src/lib/parser/declaration/map.js +1 -1
- 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 +501 -165
- 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 +1 -1
- package/dist/src/lib/parser/utils/at-rule-support.js +1 -1
- 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 -5
- package/dist/src/lib/parser/utils/type.js +1 -1
- package/dist/src/lib/printer/render.js +5 -2
- 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 +1 -1
- package/dist/src/lib/validation/match.js +8 -5
- package/dist/src/lib/validation/parser/parse.js +1 -1
- 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 +1 -1
- package/dist/src/types.js +1 -1
- package/dist/src/utils/sync.js +1 -1
- package/dist/src/web.js +1 -1
- package/package.json +4 -4
|
@@ -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 { EnumToken, ColorType } from '../ast/types.js';
|
|
@@ -45,7 +45,6 @@ function assignTokenMap(entries, tokenType, suffix = "", lowercase = false) {
|
|
|
45
45
|
SymbolsMapTokensLower[key.toLowerCase()] = tokenType;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
SymbolsMapTokens[""] = EnumToken.DelimTokenType;
|
|
49
48
|
SymbolsMapTokens["+"] = EnumToken.Plus;
|
|
50
49
|
SymbolsMapTokens["="] = EnumToken.DelimTokenType;
|
|
51
50
|
SymbolsMapTokens["|"] = EnumToken.PipeTokenType;
|
|
@@ -494,6 +493,11 @@ class Tokenizer {
|
|
|
494
493
|
hasLetter = true;
|
|
495
494
|
break;
|
|
496
495
|
}
|
|
496
|
+
// dashed ident as unit
|
|
497
|
+
if (codepoint == 0x2d && parseInfo.stream.charCodeAt(position + 1) == 0x2d) {
|
|
498
|
+
hasLetter = true;
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
497
501
|
return 0;
|
|
498
502
|
}
|
|
499
503
|
if (!hasLetter && !hasPercent) {
|
|
@@ -522,6 +526,10 @@ class Tokenizer {
|
|
|
522
526
|
else if (isLetter(codepoint)) {
|
|
523
527
|
hasLetter = true;
|
|
524
528
|
}
|
|
529
|
+
// custom ident as unit
|
|
530
|
+
else if (codepoint == 0x2d && parseInfo.stream.charCodeAt(position + 1) == 0x2d) {
|
|
531
|
+
hasLetter = true;
|
|
532
|
+
}
|
|
525
533
|
else {
|
|
526
534
|
return 0;
|
|
527
535
|
}
|
|
@@ -559,6 +567,10 @@ class Tokenizer {
|
|
|
559
567
|
hasLetter = true;
|
|
560
568
|
break;
|
|
561
569
|
}
|
|
570
|
+
else if (codepoint == 0x2d && parseInfo.stream.charCodeAt(position + 1) == 0x2d) {
|
|
571
|
+
hasLetter = true;
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
562
574
|
if (codepoint == 37 /* TokenMap.PERCENTAGE */) {
|
|
563
575
|
hasPercent = true;
|
|
564
576
|
break;
|
|
@@ -622,6 +634,11 @@ class Tokenizer {
|
|
|
622
634
|
hasLetter = true;
|
|
623
635
|
break;
|
|
624
636
|
}
|
|
637
|
+
// custom ident as unit
|
|
638
|
+
else if (codepoint == 0x2d && parseInfo.stream.charCodeAt(position + 1) == 0x2d) {
|
|
639
|
+
hasLetter = true;
|
|
640
|
+
break;
|
|
641
|
+
}
|
|
625
642
|
else if (codepoint == 37 /* TokenMap.PERCENTAGE */) {
|
|
626
643
|
hasPercent = true;
|
|
627
644
|
break;
|
|
@@ -663,7 +680,7 @@ class Tokenizer {
|
|
|
663
680
|
const slice = codepoint == 0x45 || codepoint == 0x65 ? position - 1 : position;
|
|
664
681
|
while (position + 1 <= parseInfo.stream.length) {
|
|
665
682
|
codepoint = parseInfo.stream.charCodeAt(++position);
|
|
666
|
-
if (!isLetter(codepoint)) {
|
|
683
|
+
if (!isLetter(codepoint) && codepoint != 0x2d) {
|
|
667
684
|
break;
|
|
668
685
|
}
|
|
669
686
|
}
|
|
@@ -948,6 +965,9 @@ class Tokenizer {
|
|
|
948
965
|
this.val = parseFloat(parseInfo.stream.slice(parseInfo.position - parseInfo.offset, options?.slice));
|
|
949
966
|
if (hint != EnumToken.PercentageTokenType) {
|
|
950
967
|
this.unit = val;
|
|
968
|
+
if (val.startsWith("--")) {
|
|
969
|
+
this.typ = EnumToken.UserDefinedDimensionTokenType;
|
|
970
|
+
}
|
|
951
971
|
}
|
|
952
972
|
}
|
|
953
973
|
else if (hint == EnumToken.NumberTokenType) {
|
|
@@ -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 { EnumToken } from '../../ast/types.js';
|
|
@@ -17,7 +17,7 @@ const trimTokenSpace = new Set([
|
|
|
17
17
|
EnumToken.LteTokenType,
|
|
18
18
|
EnumToken.ChildCombinatorTokenType,
|
|
19
19
|
EnumToken.PipeTokenType,
|
|
20
|
-
EnumToken.ColonTokenType
|
|
20
|
+
EnumToken.ColonTokenType,
|
|
21
21
|
]);
|
|
22
22
|
const trimSpaceAfter = new Set([
|
|
23
23
|
...tokensfuncSet.values(),
|
|
@@ -39,9 +39,16 @@ function replaceNodeOrValue(parent, node, replacement) {
|
|
|
39
39
|
if (replacement == null || (Array.isArray(replacement) && replacement.length === 0)) {
|
|
40
40
|
throw new TypeError(`replacement is null`);
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
|
|
42
|
+
if (!Array.isArray(replacement)) {
|
|
43
|
+
if (replacement[PARENT] != parent) {
|
|
44
|
+
replacement[PARENT] = parent;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
for (const newNode of replacement) {
|
|
49
|
+
if (newNode[PARENT] != parent) {
|
|
50
|
+
newNode[PARENT] = parent;
|
|
51
|
+
}
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
if (parent.typ == EnumToken.BinaryExpressionTokenType) {
|
|
@@ -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 { convertColor, getAngle } from '../syntax/color/color.js';
|
|
@@ -1146,6 +1146,7 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
|
|
|
1146
1146
|
case EnumToken.DimensionTokenType:
|
|
1147
1147
|
case EnumToken.FrequencyTokenType:
|
|
1148
1148
|
case EnumToken.ResolutionTokenType:
|
|
1149
|
+
case EnumToken.UserDefinedDimensionTokenType:
|
|
1149
1150
|
let val = token.val.typ == EnumToken.FractionTokenType
|
|
1150
1151
|
? renderValue(token.val, options, cache)
|
|
1151
1152
|
: minifyNumber(token.val);
|
|
@@ -1345,8 +1346,10 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
|
|
|
1345
1346
|
case EnumToken.BadUrlTokenType:
|
|
1346
1347
|
case EnumToken.EOFTokenType:
|
|
1347
1348
|
return "";
|
|
1349
|
+
case EnumToken.ComposesSelectorNodeType:
|
|
1350
|
+
return `${token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "")}${token.r == null ? "" : " from " + renderValue(token.r, options, cache, reducer)}`;
|
|
1348
1351
|
default:
|
|
1349
|
-
console.
|
|
1352
|
+
console.error({ token });
|
|
1350
1353
|
throw new Error(`Unsupported token type for ${EnumToken[token.typ]}`);
|
|
1351
1354
|
}
|
|
1352
1355
|
// errors?.push({ action: "ignore", message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
|