@tbela99/css-parser 1.0.0 → 1.1.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 +265 -0
- package/README.md +16 -11
- package/dist/index-umd-web.js +3613 -1829
- package/dist/index.cjs +3611 -1827
- package/dist/index.d.ts +160 -50
- package/dist/lib/ast/expand.js +2 -1
- package/dist/lib/ast/features/calc.js +12 -1
- package/dist/lib/ast/features/inlinecssvariables.js +47 -24
- package/dist/lib/ast/features/prefix.js +117 -86
- package/dist/lib/ast/features/shorthand.js +29 -6
- package/dist/lib/ast/features/transform.js +10 -3
- package/dist/lib/ast/features/type.js +7 -0
- package/dist/lib/ast/math/expression.js +7 -1
- package/dist/lib/ast/math/math.js +6 -0
- package/dist/lib/ast/minify.js +165 -77
- package/dist/lib/ast/transform/compute.js +1 -0
- package/dist/lib/ast/transform/matrix.js +1 -0
- package/dist/lib/ast/types.js +17 -15
- package/dist/lib/ast/walk.js +33 -7
- package/dist/lib/fs/resolve.js +10 -0
- package/dist/lib/parser/declaration/list.js +48 -45
- package/dist/lib/parser/declaration/map.js +1 -0
- package/dist/lib/parser/declaration/set.js +2 -1
- package/dist/lib/parser/parse.js +364 -276
- package/dist/lib/parser/tokenize.js +147 -72
- package/dist/lib/parser/utils/declaration.js +4 -3
- package/dist/lib/parser/utils/type.js +2 -1
- package/dist/lib/renderer/color/a98rgb.js +2 -1
- package/dist/lib/renderer/color/color-mix.js +10 -7
- package/dist/lib/renderer/color/color.js +171 -153
- 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 +2 -1
- 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 +2 -1
- package/dist/lib/renderer/color/oklch.js +2 -1
- package/dist/lib/renderer/color/p3.js +2 -1
- package/dist/lib/renderer/color/rec2020.js +2 -1
- package/dist/lib/renderer/color/relativecolor.js +17 -11
- package/dist/lib/renderer/color/rgb.js +4 -3
- package/dist/lib/renderer/color/srgb.js +18 -17
- package/dist/lib/renderer/color/utils/components.js +6 -5
- package/dist/lib/renderer/color/utils/constants.js +47 -3
- package/dist/lib/renderer/color/xyz.js +2 -1
- package/dist/lib/renderer/color/xyzd50.js +2 -1
- package/dist/lib/renderer/render.js +48 -20
- package/dist/lib/syntax/syntax.js +253 -140
- package/dist/lib/validation/at-rules/container.js +75 -97
- package/dist/lib/validation/at-rules/counter-style.js +9 -8
- package/dist/lib/validation/at-rules/custom-media.js +13 -15
- package/dist/lib/validation/at-rules/document.js +22 -27
- package/dist/lib/validation/at-rules/font-feature-values.js +8 -8
- package/dist/lib/validation/at-rules/import.js +30 -81
- package/dist/lib/validation/at-rules/keyframes.js +18 -22
- package/dist/lib/validation/at-rules/layer.js +5 -5
- package/dist/lib/validation/at-rules/media.js +42 -52
- package/dist/lib/validation/at-rules/namespace.js +19 -23
- package/dist/lib/validation/at-rules/page-margin-box.js +15 -18
- package/dist/lib/validation/at-rules/page.js +8 -7
- package/dist/lib/validation/at-rules/supports.js +73 -82
- package/dist/lib/validation/at-rules/when.js +32 -36
- package/dist/lib/validation/atrule.js +15 -14
- package/dist/lib/validation/config.js +24 -1
- package/dist/lib/validation/config.json.js +563 -63
- package/dist/lib/validation/parser/parse.js +196 -185
- package/dist/lib/validation/parser/types.js +1 -1
- package/dist/lib/validation/selector.js +3 -3
- package/dist/lib/validation/syntax.js +828 -0
- package/dist/lib/validation/syntaxes/complex-selector-list.js +10 -11
- package/dist/lib/validation/syntaxes/complex-selector.js +10 -11
- package/dist/lib/validation/syntaxes/compound-selector.js +40 -50
- package/dist/lib/validation/syntaxes/family-name.js +9 -8
- package/dist/lib/validation/syntaxes/keyframe-block-list.js +4 -3
- package/dist/lib/validation/syntaxes/keyframe-selector.js +15 -18
- package/dist/lib/validation/syntaxes/layer-name.js +6 -5
- package/dist/lib/validation/syntaxes/relative-selector-list.js +7 -6
- package/dist/lib/validation/syntaxes/relative-selector.js +2 -1
- package/dist/lib/validation/syntaxes/url.js +18 -22
- package/dist/lib/validation/utils/list.js +2 -1
- package/dist/lib/validation/utils/whitespace.js +2 -1
- package/dist/node/index.js +4 -2
- package/dist/node/load.js +5 -0
- package/dist/web/index.js +4 -2
- package/dist/web/load.js +5 -0
- package/package.json +12 -11
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SyntaxValidationResult, EnumToken } from '../ast/types.js';
|
|
2
2
|
import '../ast/minify.js';
|
|
3
3
|
import '../ast/walk.js';
|
|
4
4
|
import '../parser/parse.js';
|
|
5
|
+
import '../parser/tokenize.js';
|
|
6
|
+
import '../parser/utils/config.js';
|
|
5
7
|
import '../renderer/color/utils/constants.js';
|
|
6
8
|
import '../renderer/sourcemap/lib/encode.js';
|
|
7
|
-
import '../parser/utils/config.js';
|
|
8
9
|
import { getSyntaxConfig, getParsedSyntax } from './config.js';
|
|
9
10
|
import { validateAtRuleMedia } from './at-rules/media.js';
|
|
10
11
|
import { validateAtRuleCounterStyle } from './at-rules/counter-style.js';
|
|
@@ -25,7 +26,7 @@ function validateAtRule(atRule, options, root) {
|
|
|
25
26
|
if (atRule.nam == 'charset') {
|
|
26
27
|
const valid = atRule.val.match(/^"[a-zA-Z][a-zA-Z0-9_-]+"$/i) != null;
|
|
27
28
|
return {
|
|
28
|
-
valid: valid ?
|
|
29
|
+
valid: valid ? SyntaxValidationResult.Valid : SyntaxValidationResult.Drop,
|
|
29
30
|
node: atRule,
|
|
30
31
|
syntax: null,
|
|
31
32
|
error: ''
|
|
@@ -33,7 +34,7 @@ function validateAtRule(atRule, options, root) {
|
|
|
33
34
|
}
|
|
34
35
|
if (['font-face', 'view-transition', 'starting-style'].includes(atRule.nam)) {
|
|
35
36
|
return {
|
|
36
|
-
valid:
|
|
37
|
+
valid: SyntaxValidationResult.Valid,
|
|
37
38
|
node: atRule,
|
|
38
39
|
syntax: '@' + atRule.nam,
|
|
39
40
|
error: ''
|
|
@@ -78,7 +79,7 @@ function validateAtRule(atRule, options, root) {
|
|
|
78
79
|
if (['position-try', 'property', 'font-palette-values'].includes(atRule.nam)) {
|
|
79
80
|
if (!('tokens' in atRule)) {
|
|
80
81
|
return {
|
|
81
|
-
valid:
|
|
82
|
+
valid: SyntaxValidationResult.Drop,
|
|
82
83
|
node: atRule,
|
|
83
84
|
syntax: '@' + atRule.nam,
|
|
84
85
|
error: 'expected prelude'
|
|
@@ -86,7 +87,7 @@ function validateAtRule(atRule, options, root) {
|
|
|
86
87
|
}
|
|
87
88
|
if (!('chi' in atRule)) {
|
|
88
89
|
return {
|
|
89
|
-
valid:
|
|
90
|
+
valid: SyntaxValidationResult.Drop,
|
|
90
91
|
node: atRule,
|
|
91
92
|
syntax: '@' + atRule.nam,
|
|
92
93
|
error: 'expected body'
|
|
@@ -95,7 +96,7 @@ function validateAtRule(atRule, options, root) {
|
|
|
95
96
|
const chi = atRule.tokens.filter((t) => t.typ != EnumToken.WhitespaceTokenType && t.typ != EnumToken.CommentTokenType);
|
|
96
97
|
if (chi.length != 1) {
|
|
97
98
|
return {
|
|
98
|
-
valid:
|
|
99
|
+
valid: SyntaxValidationResult.Drop,
|
|
99
100
|
node: atRule,
|
|
100
101
|
syntax: '@' + atRule.nam,
|
|
101
102
|
error: 'expected ' + (atRule.nam == 'property' ? 'custom-property-name' : 'dashed-ident')
|
|
@@ -104,7 +105,7 @@ function validateAtRule(atRule, options, root) {
|
|
|
104
105
|
if (chi[0].typ != EnumToken.DashedIdenTokenType) {
|
|
105
106
|
// @ts-ignore
|
|
106
107
|
return {
|
|
107
|
-
valid:
|
|
108
|
+
valid: SyntaxValidationResult.Drop,
|
|
108
109
|
node: atRule,
|
|
109
110
|
syntax: '@' + atRule.nam,
|
|
110
111
|
error: 'expected ' + (atRule.nam == 'property' ? 'custom-property-name' : 'dashed-ident')
|
|
@@ -112,7 +113,7 @@ function validateAtRule(atRule, options, root) {
|
|
|
112
113
|
}
|
|
113
114
|
// @ts-ignore
|
|
114
115
|
return {
|
|
115
|
-
valid:
|
|
116
|
+
valid: SyntaxValidationResult.Valid,
|
|
116
117
|
node: atRule,
|
|
117
118
|
syntax: '@' + atRule.nam,
|
|
118
119
|
error: ''
|
|
@@ -126,7 +127,7 @@ function validateAtRule(atRule, options, root) {
|
|
|
126
127
|
if (!(root == null || (root.typ == EnumToken.AtRuleNodeType && root.nam == 'page'))) {
|
|
127
128
|
// @ts-ignore
|
|
128
129
|
return {
|
|
129
|
-
valid:
|
|
130
|
+
valid: SyntaxValidationResult.Drop,
|
|
130
131
|
node: atRule,
|
|
131
132
|
syntax: '@page',
|
|
132
133
|
error: 'not allowed here'
|
|
@@ -146,14 +147,14 @@ function validateAtRule(atRule, options, root) {
|
|
|
146
147
|
if (!(name in config.atRules)) {
|
|
147
148
|
if (options.lenient) {
|
|
148
149
|
return {
|
|
149
|
-
valid:
|
|
150
|
+
valid: SyntaxValidationResult.Lenient,
|
|
150
151
|
node: atRule,
|
|
151
152
|
syntax: null,
|
|
152
153
|
error: ''
|
|
153
154
|
};
|
|
154
155
|
}
|
|
155
156
|
return {
|
|
156
|
-
valid:
|
|
157
|
+
valid: SyntaxValidationResult.Drop,
|
|
157
158
|
node: atRule,
|
|
158
159
|
syntax: null,
|
|
159
160
|
error: 'unknown at-rule'
|
|
@@ -162,7 +163,7 @@ function validateAtRule(atRule, options, root) {
|
|
|
162
163
|
const syntax = getParsedSyntax("atRules" /* ValidationSyntaxGroupEnum.AtRules */, name)?.[0];
|
|
163
164
|
if ('chi' in syntax && !('chi' in atRule)) {
|
|
164
165
|
return {
|
|
165
|
-
valid:
|
|
166
|
+
valid: SyntaxValidationResult.Drop,
|
|
166
167
|
node: atRule,
|
|
167
168
|
syntax,
|
|
168
169
|
error: 'missing at-rule body'
|
|
@@ -173,7 +174,7 @@ function validateAtRule(atRule, options, root) {
|
|
|
173
174
|
// return validateSyntax(syntax.prelude as ValidationToken[], atRule.tokens as Token[], root, options);
|
|
174
175
|
// }
|
|
175
176
|
return {
|
|
176
|
-
valid:
|
|
177
|
+
valid: SyntaxValidationResult.Valid,
|
|
177
178
|
node: null,
|
|
178
179
|
syntax,
|
|
179
180
|
error: ''
|
|
@@ -8,6 +8,29 @@ function getSyntaxConfig() {
|
|
|
8
8
|
// @ts-ignore
|
|
9
9
|
return config;
|
|
10
10
|
}
|
|
11
|
+
function getSyntax(group, key) {
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
let obj = config[group];
|
|
14
|
+
const keys = Array.isArray(key) ? key : [key];
|
|
15
|
+
for (let i = 0; i < keys.length; i++) {
|
|
16
|
+
key = keys[i];
|
|
17
|
+
if (!(key in obj)) {
|
|
18
|
+
if ((i == 0 && key.charAt(0) == '@') || key.charAt(0) == '-') {
|
|
19
|
+
const matches = key.match(/^(@?)(-[a-zA-Z]+)-(.*?)$/);
|
|
20
|
+
if (matches != null) {
|
|
21
|
+
key = matches[1] + matches[3];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (!(key in obj)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
obj = obj[key];
|
|
30
|
+
}
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
return obj?.syntax ?? null;
|
|
33
|
+
}
|
|
11
34
|
function getParsedSyntax(group, key) {
|
|
12
35
|
// @ts-ignore
|
|
13
36
|
let obj = config[group];
|
|
@@ -39,4 +62,4 @@ function getParsedSyntax(group, key) {
|
|
|
39
62
|
return parsedSyntaxes.get(index);
|
|
40
63
|
}
|
|
41
64
|
|
|
42
|
-
export { getParsedSyntax, getSyntaxConfig };
|
|
65
|
+
export { getParsedSyntax, getSyntax, getSyntaxConfig };
|