@tbela99/css-parser 2.0.1 → 2.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/CHANGELOG.md +86 -1
- package/README.md +15 -7
- package/architecture.png +0 -0
- package/dist/{src/data → data}/properties.json.js +86 -2
- package/dist/{src/data → data}/validation.json.js +4848 -3750
- package/dist/index-umd-web.js +18234 -9498
- package/dist/index.d.ts +1251 -373
- package/dist/{src/lib → lib}/ast/arena-node.js +119 -57
- package/dist/{src/lib → lib}/ast/arena.js +1034 -655
- package/dist/{src/lib → lib}/ast/cache.js +36 -31
- package/dist/{src/lib → lib}/ast/features/calc.js +37 -27
- package/dist/{src/lib → lib}/ast/features/if.js +24 -19
- package/dist/{src/lib → lib}/ast/features/index.js +3 -2
- package/dist/{src/lib → lib}/ast/features/inlinecssvariables.js +42 -23
- package/dist/lib/ast/features/mixin.js +953 -0
- package/dist/{src/lib → lib}/ast/features/prefix.js +82 -69
- package/dist/lib/ast/features/shorthand.js +129 -0
- package/dist/lib/ast/features/transform.js +188 -0
- package/dist/{src/lib → lib}/ast/features/type.js +2 -2
- package/dist/{src/lib → lib}/ast/math/expression.js +150 -150
- package/dist/{src/lib → lib}/ast/math/math.js +8 -8
- package/dist/{src/lib → lib}/ast/minify.js +932 -354
- package/dist/lib/ast/mixins/custom-function.js +393 -0
- package/dist/lib/ast/mixins/utils.js +53 -0
- package/dist/lib/ast/mixins/variables.js +678 -0
- package/dist/lib/ast/strings.js +906 -0
- package/dist/lib/ast/transform/compute.js +560 -0
- package/dist/lib/ast/transform/matrix.js +67 -0
- package/dist/lib/ast/transform/minify.js +325 -0
- package/dist/lib/ast/transform/perspective.js +24 -0
- package/dist/{src/lib → lib}/ast/transform/rotate.js +16 -7
- package/dist/lib/ast/transform/scale.js +43 -0
- package/dist/lib/ast/transform/skew.js +38 -0
- package/dist/lib/ast/transform/translate.js +56 -0
- package/dist/lib/ast/transform/utils.js +390 -0
- package/dist/{src/lib → lib}/ast/types.js +7 -15
- package/dist/{src/lib → lib}/ast/walk.js +19 -19
- package/dist/{src/lib → lib}/fs/resolve.js +15 -15
- package/dist/{src/lib → lib}/parser/declaration/list.js +55 -26
- package/dist/{src/lib → lib}/parser/declaration/map.js +85 -72
- package/dist/{src/lib → lib}/parser/declaration/set.js +32 -27
- package/dist/lib/parser/input.js +85 -0
- package/dist/{src/lib → lib}/parser/linesmap.js +3 -16
- package/dist/{src/lib → lib}/parser/parse.js +852 -619
- package/dist/lib/parser/source.js +71 -0
- package/dist/{src/lib → lib}/parser/tokenize.js +886 -722
- package/dist/{src/lib → lib}/parser/utils/angle.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-container.js +68 -35
- package/dist/{src/lib → lib}/parser/utils/at-rule-font-feature-values.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-generic.js +31 -13
- package/dist/{src/lib → lib}/parser/utils/at-rule-import.js +29 -16
- package/dist/{src/lib → lib}/parser/utils/at-rule-media.js +77 -58
- package/dist/{src/lib → lib}/parser/utils/at-rule-support.js +18 -20
- package/dist/{src/lib → lib}/parser/utils/at-rule-when-else.js +9 -8
- package/dist/{src/lib → lib}/parser/utils/at-rule.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/base64.js +2 -2
- package/dist/lib/parser/utils/cache.js +53 -0
- package/dist/lib/parser/utils/canonical.js +78 -0
- package/dist/lib/parser/utils/codes.js +93 -0
- package/dist/{src/lib → lib}/parser/utils/config.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/declaration.js +67 -49
- package/dist/{src/lib → lib}/parser/utils/eq.js +14 -14
- package/dist/{src/lib → lib}/parser/utils/hash.js +4 -4
- package/dist/lib/parser/utils/selector.js +720 -0
- package/dist/{src/lib → lib}/parser/utils/text.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/token.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/type.js +11 -9
- package/dist/{src/lib → lib}/printer/render.js +536 -243
- package/dist/lib/printer/result.js +148 -0
- package/dist/{src/lib → lib}/printer/sourcemap/lib/codec.js +5 -8
- package/dist/{src/lib → lib}/printer/sourcemap/sourcemap.js +13 -13
- package/dist/lib/printer/writer.js +252 -0
- package/dist/{src/lib → lib}/syntax/color/a98rgb.js +6 -6
- package/dist/{src/lib → lib}/syntax/color/alpha.js +12 -11
- package/dist/{src/lib → lib}/syntax/color/cmyk.js +11 -6
- package/dist/{src/lib → lib}/syntax/color/color-mix.js +78 -67
- package/dist/{src/lib → lib}/syntax/color/color.js +52 -47
- package/dist/{src/lib → lib}/syntax/color/hex.js +17 -17
- package/dist/{src/lib → lib}/syntax/color/hsl.js +8 -8
- package/dist/{src/lib → lib}/syntax/color/hwb.js +6 -7
- package/dist/{src/lib → lib}/syntax/color/lab.js +8 -8
- package/dist/{src/lib → lib}/syntax/color/lch.js +12 -11
- package/dist/{src/lib → lib}/syntax/color/oklab.js +9 -9
- package/dist/{src/lib → lib}/syntax/color/oklch.js +5 -5
- package/dist/{src/lib → lib}/syntax/color/p3.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/prophotorgb.js +4 -4
- package/dist/{src/lib → lib}/syntax/color/rec2020.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/relative-color.js +41 -34
- package/dist/{src/lib → lib}/syntax/color/rgb.js +17 -17
- package/dist/{src/lib → lib}/syntax/color/srgb.js +20 -20
- package/dist/{src/lib → lib}/syntax/color/utils/color-type.js +6 -4
- package/dist/{src/lib → lib}/syntax/color/utils/colorspace.js +12 -14
- package/dist/{src/lib → lib}/syntax/color/utils/components.js +13 -13
- package/dist/{src/lib → lib}/syntax/color/utils/distance.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/utils/make-color.js +6 -4
- package/dist/{src/lib → lib}/syntax/color/utils/matrix.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/xyz.js +5 -10
- package/dist/{src/lib → lib}/syntax/color/xyzd50.js +3 -3
- package/dist/{src/lib → lib}/syntax/constants.js +30 -3
- package/dist/{src/lib → lib}/syntax/syntax.js +151 -116
- package/dist/lib/validation/config.js +173 -0
- package/dist/lib/validation/first.js +571 -0
- package/dist/{src/lib → lib}/validation/match.js +1256 -579
- package/dist/{src/lib → lib}/validation/parser/parse.js +85 -59
- package/dist/{src/lib → lib}/validation/parser/typedef.js +6 -2
- package/dist/{src/lib → lib}/validation/utils/list.js +3 -19
- package/dist/{src/node.js → node.js} +92 -80
- package/dist/{src/types.js → types.js} +2 -2
- package/dist/{src/utils → utils}/sync.js +13 -8
- package/dist/version.d.ts +4 -0
- package/dist/version.js +13 -0
- package/dist/{src/web.js → web.js} +80 -75
- package/package.json +13 -13
- package/dist/package.json.js +0 -10
- package/dist/src/lib/ast/features/shorthand.js +0 -87
- package/dist/src/lib/ast/features/transform.js +0 -85
- package/dist/src/lib/ast/transform/compute.js +0 -358
- package/dist/src/lib/ast/transform/matrix.js +0 -88
- package/dist/src/lib/ast/transform/minify.js +0 -267
- package/dist/src/lib/ast/transform/perspective.js +0 -16
- package/dist/src/lib/ast/transform/scale.js +0 -39
- package/dist/src/lib/ast/transform/skew.js +0 -30
- package/dist/src/lib/ast/transform/translate.js +0 -39
- package/dist/src/lib/ast/transform/utils.js +0 -287
- package/dist/src/lib/parser/source.js +0 -127
- package/dist/src/lib/parser/utils/cache.js +0 -54
- package/dist/src/lib/parser/utils/selector.js +0 -440
- package/dist/src/lib/validation/config.js +0 -120
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
3
|
-
|
|
4
|
-
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.0.1
|
|
6
|
-
License: MIT
|
|
7
|
-
*/
|
|
8
|
-
import config from '../../data/validation.json.js';
|
|
9
|
-
import { trimSyntaxArray, parseSyntax } from './parser/parse.js';
|
|
10
|
-
import { ValidationTokenEnum } from './parser/typedef.js';
|
|
11
|
-
import { memoize } from '../parser/utils/cache.js';
|
|
12
|
-
|
|
13
|
-
const parsedSyntaxes = new Map();
|
|
14
|
-
Object.freeze(config);
|
|
15
|
-
function getSyntaxConfig() {
|
|
16
|
-
// @ts-expect-error
|
|
17
|
-
return config;
|
|
18
|
-
}
|
|
19
|
-
function findNode(group, key) {
|
|
20
|
-
// @ts-expect-error
|
|
21
|
-
let obj = config[group];
|
|
22
|
-
// @ts-expect-error
|
|
23
|
-
if (obj[key] == null) {
|
|
24
|
-
if (key.charAt(0) == "@" || key.charAt(0) == "-") {
|
|
25
|
-
const matches = key.match(/^(@?)(-[a-zA-Z]+)-(.*?)$/);
|
|
26
|
-
if (matches != null) {
|
|
27
|
-
key = matches[1] + matches[3];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
// @ts-expect-error
|
|
31
|
-
if (obj[key] == null) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
// @ts-expect-error
|
|
36
|
-
obj = obj[key];
|
|
37
|
-
return obj;
|
|
38
|
-
}
|
|
39
|
-
const getParsedSyntax = memoize((group, key) => {
|
|
40
|
-
// @ts-expect-error
|
|
41
|
-
const obj = findNode(group, key);
|
|
42
|
-
if (obj == null) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
const index = group + "." + key;
|
|
46
|
-
if (!parsedSyntaxes.has(index)) {
|
|
47
|
-
const syntax = Object.freeze(trimSyntaxArray(parseSyntax(obj.syntax)));
|
|
48
|
-
parsedSyntaxes.set(index, syntax);
|
|
49
|
-
}
|
|
50
|
-
return parsedSyntaxes.get(index);
|
|
51
|
-
});
|
|
52
|
-
const getSyntaxRule = memoize((group, key) => {
|
|
53
|
-
const node = findNode(group, key);
|
|
54
|
-
if (node == null) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
let syntaxRules = getParsedSyntax(group, key);
|
|
58
|
-
if (syntaxRules == null) {
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
let blockStart = -1;
|
|
62
|
-
let blockEnd = -1;
|
|
63
|
-
let i;
|
|
64
|
-
for (i = 0; i < syntaxRules.length; i++) {
|
|
65
|
-
if (syntaxRules[i].typ === ValidationTokenEnum.OpenCurlyBrace ||
|
|
66
|
-
syntaxRules[i].typ === ValidationTokenEnum.SemiColon) {
|
|
67
|
-
blockStart = i;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (blockStart != -1) {
|
|
72
|
-
i = syntaxRules.length;
|
|
73
|
-
while (i--) {
|
|
74
|
-
if (syntaxRules[i].typ === ValidationTokenEnum.CloseCurlyBrace) {
|
|
75
|
-
blockEnd = i;
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
let block = blockStart == -1 ? null : trimSyntaxArray(syntaxRules.slice(blockStart + 1, blockEnd));
|
|
81
|
-
let prelude = trimSyntaxArray(blockStart == -1 ? syntaxRules.slice() : syntaxRules.slice(0, blockStart));
|
|
82
|
-
let propertyDescriptors = null;
|
|
83
|
-
// @ts-expect-error
|
|
84
|
-
if (node.descriptors != null) {
|
|
85
|
-
propertyDescriptors = {};
|
|
86
|
-
// @ts-expect-error
|
|
87
|
-
for (const [key, value] of Object.entries(node.descriptors)) {
|
|
88
|
-
// @ts-expect-error
|
|
89
|
-
propertyDescriptors[key] = parseSyntax(typeof value === "string" ? value : value.syntax);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
let optionalBody = false;
|
|
93
|
-
if (block == null || block.length === 0) {
|
|
94
|
-
let k = prelude.length - 1;
|
|
95
|
-
if (ValidationTokenEnum.SemiColon === prelude[k].typ) {
|
|
96
|
-
k--;
|
|
97
|
-
}
|
|
98
|
-
if (k >= 0 && ValidationTokenEnum.Bracket === prelude[k].typ) {
|
|
99
|
-
if (prelude[k].chi[0].typ ===
|
|
100
|
-
ValidationTokenEnum.OpenCurlyBrace &&
|
|
101
|
-
prelude[k].chi.at(-1).typ ===
|
|
102
|
-
ValidationTokenEnum.CloseCurlyBrace) {
|
|
103
|
-
block = prelude[k].chi.slice(1, -1);
|
|
104
|
-
optionalBody = prelude[k].isOptional ?? false;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
optionalBody,
|
|
110
|
-
acceptAnyDeclaration: node.syntax.includes("<declaration-list>"),
|
|
111
|
-
acceptAnyRule: node.syntax.includes("<group-rule-body>") ||
|
|
112
|
-
node.syntax.includes("<stylesheet>"),
|
|
113
|
-
getPreludeRules: () => prelude,
|
|
114
|
-
getBlockRules: () => (block == null || block.length === 0 ? null : block),
|
|
115
|
-
// getRules: () => syntaxRules,
|
|
116
|
-
getPropertyDescriptors: () => propertyDescriptors,
|
|
117
|
-
};
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
export { getParsedSyntax, getSyntaxConfig, getSyntaxRule };
|