@tbela99/css-parser 0.7.1 → 0.8.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/README.md +136 -82
- package/dist/index-umd-web.js +6956 -51524
- package/dist/index.cjs +6955 -51528
- package/dist/index.d.ts +180 -65
- package/dist/lib/ast/expand.js +34 -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 +1 -1
- package/dist/lib/ast/types.js +58 -49
- package/dist/lib/ast/walk.js +80 -18
- package/dist/lib/parser/declaration/list.js +1 -0
- package/dist/lib/parser/declaration/map.js +1 -0
- package/dist/lib/parser/declaration/set.js +1 -0
- package/dist/lib/parser/parse.js +285 -72
- package/dist/lib/parser/tokenize.js +16 -3
- 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 +1 -0
- package/dist/lib/renderer/color/hsl.js +1 -0
- package/dist/lib/renderer/color/hwb.js +1 -0
- package/dist/lib/renderer/color/lab.js +1 -0
- package/dist/lib/renderer/color/lch.js +1 -0
- package/dist/lib/renderer/color/oklab.js +1 -0
- package/dist/lib/renderer/color/oklch.js +1 -0
- package/dist/lib/renderer/color/p3.js +1 -0
- package/dist/lib/renderer/color/prophotoRgb.js +56 -0
- 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 +1 -0
- package/dist/lib/renderer/color/srgb.js +1 -0
- package/dist/lib/renderer/color/utils/components.js +1 -0
- package/dist/lib/renderer/color/utils/constants.js +1 -0
- package/dist/lib/renderer/color/xyz.js +1 -0
- package/dist/lib/renderer/color/xyzd50.js +1 -0
- package/dist/lib/renderer/render.js +28 -6
- package/dist/lib/syntax/syntax.js +27 -4
- package/dist/lib/validation/at-rules/counter-style.js +78 -0
- package/dist/lib/validation/at-rules/document.js +114 -0
- package/dist/lib/validation/at-rules/font-feature-values.js +49 -0
- package/dist/lib/validation/at-rules/import.js +196 -0
- package/dist/lib/validation/at-rules/keyframes.js +70 -0
- package/dist/lib/validation/at-rules/layer.js +27 -0
- package/dist/lib/validation/at-rules/media.js +166 -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/atrule.js +172 -0
- package/dist/lib/validation/config.js +30 -2
- package/dist/lib/validation/config.json.js +1560 -50902
- package/dist/lib/validation/declaration.js +72 -0
- package/dist/lib/validation/parser/parse.js +1059 -7
- package/dist/lib/validation/parser/types.js +27 -12
- package/dist/lib/validation/selector.js +23 -444
- package/dist/lib/validation/syntax.js +1429 -0
- package/dist/lib/validation/syntaxes/complex-selector-list.js +41 -0
- package/dist/lib/validation/syntaxes/complex-selector.js +283 -0
- package/dist/lib/validation/syntaxes/family-name.js +91 -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 +27 -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 +4 -4
- package/dist/web/index.js +4 -0
- package/dist/web/load.js +1 -0
- package/package.json +15 -13
- 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,72 @@
|
|
|
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
|
+
const syntax = getParsedSyntax("atRules" /* ValidationSyntaxGroupEnum.AtRules */, '@' + root.nam)?.[0];
|
|
25
|
+
if (syntax != null) {
|
|
26
|
+
if (!('chi' in syntax)) {
|
|
27
|
+
return {
|
|
28
|
+
valid: ValidationLevel.Drop,
|
|
29
|
+
node: declaration,
|
|
30
|
+
syntax,
|
|
31
|
+
error: 'declaration not allowed here'
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (name.startsWith('--')) {
|
|
35
|
+
return {
|
|
36
|
+
valid: ValidationLevel.Valid,
|
|
37
|
+
node: declaration,
|
|
38
|
+
syntax: null,
|
|
39
|
+
error: ''
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (!(name in config.declarations) && !(name in config.syntaxes)) {
|
|
43
|
+
return {
|
|
44
|
+
valid: ValidationLevel.Drop,
|
|
45
|
+
node: declaration,
|
|
46
|
+
syntax: null,
|
|
47
|
+
error: `unknown declaration "${declaration.nam}"`
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return validateSyntax(syntax.chi, [declaration], root, options);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (name.startsWith('--')) {
|
|
54
|
+
return {
|
|
55
|
+
valid: ValidationLevel.Valid,
|
|
56
|
+
node: declaration,
|
|
57
|
+
syntax: null,
|
|
58
|
+
error: ''
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (!(name in config.declarations) && !(name in config.syntaxes)) {
|
|
62
|
+
return {
|
|
63
|
+
valid: ValidationLevel.Drop,
|
|
64
|
+
node: declaration,
|
|
65
|
+
syntax: null,
|
|
66
|
+
error: `unknown declaration "${declaration.nam}"`
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return validateSyntax(getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, name), declaration.val);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { validateDeclaration };
|