@tbela99/css-parser 0.7.1 → 0.9.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/.editorconfig +484 -0
- package/README.md +140 -84
- package/dist/index-umd-web.js +8461 -51655
- package/dist/index.cjs +8437 -51636
- package/dist/index.d.ts +220 -68
- package/dist/lib/ast/expand.js +46 -9
- package/dist/lib/ast/features/calc.js +76 -12
- package/dist/lib/ast/features/inlinecssvariables.js +6 -1
- package/dist/lib/ast/features/prefix.js +17 -9
- package/dist/lib/ast/features/shorthand.js +1 -0
- package/dist/lib/ast/math/expression.js +299 -11
- package/dist/lib/ast/math/math.js +7 -1
- package/dist/lib/ast/minify.js +30 -16
- package/dist/lib/ast/types.js +59 -49
- package/dist/lib/ast/walk.js +92 -18
- package/dist/lib/parser/declaration/list.js +1 -0
- package/dist/lib/parser/declaration/map.js +60 -52
- package/dist/lib/parser/declaration/set.js +1 -12
- package/dist/lib/parser/parse.js +371 -119
- package/dist/lib/parser/tokenize.js +31 -6
- package/dist/lib/parser/utils/declaration.js +2 -2
- package/dist/lib/parser/utils/type.js +6 -6
- package/dist/lib/renderer/color/a98rgb.js +1 -0
- package/dist/lib/renderer/color/color.js +1 -0
- package/dist/lib/renderer/color/colormix.js +1 -0
- package/dist/lib/renderer/color/hex.js +2 -1
- package/dist/lib/renderer/color/hsl.js +2 -1
- package/dist/lib/renderer/color/hwb.js +3 -2
- package/dist/lib/renderer/color/lab.js +2 -1
- package/dist/lib/renderer/color/lch.js +2 -1
- package/dist/lib/renderer/color/oklab.js +3 -2
- package/dist/lib/renderer/color/oklch.js +2 -1
- package/dist/lib/renderer/color/p3.js +2 -1
- package/dist/lib/renderer/color/prophotoRgb.js +56 -0
- package/dist/lib/renderer/color/prophotorgb.js +1 -1
- package/dist/lib/renderer/color/rec2020.js +1 -0
- package/dist/lib/renderer/color/relativecolor.js +52 -28
- package/dist/lib/renderer/color/rgb.js +2 -1
- package/dist/lib/renderer/color/srgb.js +3 -2
- package/dist/lib/renderer/color/utils/components.js +1 -0
- package/dist/lib/renderer/color/utils/constants.js +2 -1
- package/dist/lib/renderer/color/xyz.js +2 -1
- package/dist/lib/renderer/color/xyzd50.js +1 -0
- package/dist/lib/renderer/render.js +62 -12
- package/dist/lib/syntax/syntax.js +362 -4
- package/dist/lib/validation/at-rules/container.js +353 -0
- package/dist/lib/validation/at-rules/counter-style.js +78 -0
- package/dist/lib/validation/at-rules/custom-media.js +52 -0
- package/dist/lib/validation/at-rules/document.js +114 -0
- package/dist/lib/validation/at-rules/else.js +5 -0
- package/dist/lib/validation/at-rules/font-feature-values.js +52 -0
- package/dist/lib/validation/at-rules/import.js +199 -0
- package/dist/lib/validation/at-rules/keyframes.js +70 -0
- package/dist/lib/validation/at-rules/layer.js +30 -0
- package/dist/lib/validation/at-rules/media.js +254 -0
- package/dist/lib/validation/at-rules/namespace.js +85 -0
- package/dist/lib/validation/at-rules/page-margin-box.js +56 -0
- package/dist/lib/validation/at-rules/page.js +88 -0
- package/dist/lib/validation/at-rules/supports.js +262 -0
- package/dist/lib/validation/at-rules/when.js +178 -0
- package/dist/lib/validation/atrule.js +187 -0
- package/dist/lib/validation/config.js +35 -2
- package/dist/lib/validation/config.json.js +1683 -50905
- package/dist/lib/validation/declaration.js +102 -0
- package/dist/lib/validation/parser/parse.js +1137 -7
- package/dist/lib/validation/parser/types.js +28 -12
- package/dist/lib/validation/selector.js +26 -444
- package/dist/lib/validation/syntax.js +1475 -0
- package/dist/lib/validation/syntaxes/complex-selector-list.js +45 -0
- package/dist/lib/validation/syntaxes/complex-selector.js +53 -0
- package/dist/lib/validation/syntaxes/compound-selector.js +226 -0
- package/dist/lib/validation/syntaxes/family-name.js +91 -0
- package/dist/lib/validation/syntaxes/image.js +29 -0
- package/dist/lib/validation/syntaxes/keyframe-block-list.js +27 -0
- package/dist/lib/validation/syntaxes/keyframe-selector.js +137 -0
- package/dist/lib/validation/syntaxes/layer-name.js +67 -0
- package/dist/lib/validation/syntaxes/relative-selector-list.js +57 -0
- package/dist/lib/validation/syntaxes/relative-selector.js +36 -0
- package/dist/lib/validation/syntaxes/selector-list.js +5 -0
- package/dist/lib/validation/syntaxes/selector.js +5 -0
- package/dist/lib/validation/syntaxes/url.js +75 -0
- package/dist/lib/validation/utils/list.js +24 -0
- package/dist/lib/validation/utils/whitespace.js +22 -0
- package/dist/node/index.js +5 -5
- package/dist/web/index.js +5 -1
- package/dist/web/load.js +1 -0
- package/package.json +16 -14
- package/dist/lib/ast/utils/minifyfeature.js +0 -9
- package/dist/lib/iterable/weakset.js +0 -58
- package/dist/lib/parser/utils/syntax.js +0 -450
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { EnumToken, ValidationLevel } from '../ast/types.js';
|
|
2
|
+
import '../ast/minify.js';
|
|
3
|
+
import '../ast/walk.js';
|
|
4
|
+
import '../parser/parse.js';
|
|
5
|
+
import '../renderer/color/utils/constants.js';
|
|
6
|
+
import '../renderer/sourcemap/lib/encode.js';
|
|
7
|
+
import '../parser/utils/config.js';
|
|
8
|
+
import { getParsedSyntax, getSyntaxConfig } from './config.js';
|
|
9
|
+
import { validateSyntax } from './syntax.js';
|
|
10
|
+
|
|
11
|
+
function validateDeclaration(declaration, options, root) {
|
|
12
|
+
const config = getSyntaxConfig();
|
|
13
|
+
let name = declaration.nam;
|
|
14
|
+
if (!(name in config.declarations) && !(name in config.syntaxes)) {
|
|
15
|
+
if (name[0] == '-') {
|
|
16
|
+
const match = /^-([a-z]+)-(.*)$/.exec(name);
|
|
17
|
+
if (match != null) {
|
|
18
|
+
name = match[2];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// root is at-rule - check if declaration allowed
|
|
23
|
+
if (root?.typ == EnumToken.AtRuleNodeType) {
|
|
24
|
+
//
|
|
25
|
+
const syntax = getParsedSyntax("atRules" /* ValidationSyntaxGroupEnum.AtRules */, '@' + root.nam)?.[0];
|
|
26
|
+
// console.error({syntax});
|
|
27
|
+
if (syntax != null) {
|
|
28
|
+
if (!('chi' in syntax)) {
|
|
29
|
+
return {
|
|
30
|
+
valid: ValidationLevel.Drop,
|
|
31
|
+
node: declaration,
|
|
32
|
+
syntax,
|
|
33
|
+
error: 'declaration not allowed here'
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (name.startsWith('--')) {
|
|
37
|
+
return {
|
|
38
|
+
valid: ValidationLevel.Valid,
|
|
39
|
+
node: declaration,
|
|
40
|
+
syntax: null,
|
|
41
|
+
error: ''
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// console.error({syntax});
|
|
45
|
+
const config = getSyntaxConfig();
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
const obj = config["atRules" /* ValidationSyntaxGroupEnum.AtRules */]['@' + root.nam];
|
|
48
|
+
if ('descriptors' in obj) {
|
|
49
|
+
const descriptors = obj.descriptors;
|
|
50
|
+
if (!(name in descriptors)) {
|
|
51
|
+
return {
|
|
52
|
+
valid: ValidationLevel.Drop,
|
|
53
|
+
node: declaration,
|
|
54
|
+
syntax: `<${declaration.nam}>`,
|
|
55
|
+
error: ` declaration <${declaration.nam}> is not allowed in <@${root.nam}>`
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const syntax = getParsedSyntax("atRules" /* ValidationSyntaxGroupEnum.AtRules */, ['@' + root.nam, 'descriptors', name]);
|
|
59
|
+
return validateSyntax(syntax, declaration.val, root, options);
|
|
60
|
+
}
|
|
61
|
+
// console.error({name});
|
|
62
|
+
// if (!(name in config.declarations) && !(name in config.syntaxes)) {
|
|
63
|
+
//
|
|
64
|
+
// return {
|
|
65
|
+
//
|
|
66
|
+
// valid: ValidationLevel.Drop,
|
|
67
|
+
// node: declaration,
|
|
68
|
+
// syntax: null,
|
|
69
|
+
// error: `unknown declaration "${declaration.nam}"`
|
|
70
|
+
// }
|
|
71
|
+
// }
|
|
72
|
+
//
|
|
73
|
+
// return validateSyntax((syntax as ValidationAtRuleDefinitionToken).chi as ValidationToken[], [declaration], root, options);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (name.startsWith('--')) {
|
|
77
|
+
return {
|
|
78
|
+
valid: ValidationLevel.Valid,
|
|
79
|
+
node: declaration,
|
|
80
|
+
syntax: null,
|
|
81
|
+
error: ''
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (!(name in config.declarations) && !(name in config.syntaxes)) {
|
|
85
|
+
return {
|
|
86
|
+
valid: ValidationLevel.Drop,
|
|
87
|
+
node: declaration,
|
|
88
|
+
syntax: `<${declaration.nam}>`,
|
|
89
|
+
error: `unknown declaration "${declaration.nam}"`
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// return {
|
|
93
|
+
//
|
|
94
|
+
// valid: ValidationLevel.Valid,
|
|
95
|
+
// node: declaration,
|
|
96
|
+
// syntax: null,
|
|
97
|
+
// error: ''
|
|
98
|
+
// }
|
|
99
|
+
return validateSyntax(getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, name), declaration.val);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { validateDeclaration };
|