@tbela99/css-parser 1.4.2 → 1.4.3
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/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
- package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
- package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
- package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
- package/.repl_history +4 -0
- package/CHANGELOG.md +164 -4
- package/README.md +43 -0
- package/badges/coverage.svg +20 -0
- package/deno.lock +2861 -0
- package/dist/config.json.js +33 -1
- package/dist/index-umd-web.js +24382 -18476
- package/dist/index.cjs +24522 -18618
- package/dist/index.d.ts +1396 -929
- package/dist/lib/ast/clone.d.ts +10 -0
- package/dist/lib/ast/clone.js +45 -0
- package/dist/lib/ast/expand.d.ts +14 -0
- package/dist/lib/ast/expand.js +89 -64
- package/dist/lib/ast/features/calc.d.ts +10 -0
- package/dist/lib/ast/features/calc.js +62 -24
- package/dist/lib/ast/features/if.d.ts +10 -0
- package/dist/lib/ast/features/if.js +215 -0
- package/dist/lib/ast/features/index.d.ts +6 -0
- package/dist/lib/ast/features/index.js +1 -0
- package/dist/lib/ast/features/inlinecssvariables.d.ts +15 -0
- package/dist/lib/ast/features/inlinecssvariables.js +32 -27
- package/dist/lib/ast/features/prefix.d.ts +8 -0
- package/dist/lib/ast/features/prefix.js +68 -43
- package/dist/lib/ast/features/shorthand.d.ts +12 -0
- package/dist/lib/ast/features/shorthand.js +6 -9
- package/dist/lib/ast/features/transform.d.ts +10 -0
- package/dist/lib/ast/features/transform.js +9 -13
- package/dist/lib/ast/features/type.d.ts +15 -0
- package/dist/lib/ast/find.d.ts +165 -0
- package/dist/lib/ast/find.js +175 -0
- package/dist/lib/ast/math/expression.d.ts +18 -0
- package/dist/lib/ast/math/expression.js +140 -98
- package/dist/lib/ast/math/math.d.ts +6 -0
- package/dist/lib/ast/math/math.js +30 -41
- package/dist/lib/ast/minify.d.ts +19 -0
- package/dist/lib/ast/minify.js +541 -217
- package/dist/lib/ast/transform/compute.d.ts +8 -0
- package/dist/lib/ast/transform/compute.js +82 -69
- package/dist/lib/ast/transform/matrix.d.ts +22 -0
- package/dist/lib/ast/transform/matrix.js +12 -26
- package/dist/lib/ast/transform/minify.d.ts +5 -0
- package/dist/lib/ast/transform/minify.js +20 -20
- package/dist/lib/ast/transform/perspective.d.ts +3 -0
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.d.ts +12 -0
- package/dist/lib/ast/transform/rotate.js +1 -1
- package/dist/lib/ast/transform/scale.d.ts +6 -0
- package/dist/lib/ast/transform/scale.js +1 -1
- package/dist/lib/ast/transform/skew.d.ts +4 -0
- package/dist/lib/ast/transform/skew.js +1 -1
- package/dist/lib/ast/transform/translate.d.ts +6 -0
- package/dist/lib/ast/transform/translate.js +1 -1
- package/dist/lib/ast/transform/utils.d.ts +9 -0
- package/dist/lib/ast/types.d.ts +903 -0
- package/dist/lib/ast/types.js +277 -23
- package/dist/lib/ast/walk.d.ts +162 -0
- package/dist/lib/ast/walk.js +116 -60
- package/dist/lib/fs/resolve.d.ts +20 -0
- package/dist/lib/fs/resolve.js +37 -45
- package/dist/lib/parser/declaration/list.d.ts +16 -0
- package/dist/lib/parser/declaration/list.js +26 -24
- package/dist/lib/parser/declaration/map.d.ts +15 -0
- package/dist/lib/parser/declaration/map.js +140 -95
- package/dist/lib/parser/declaration/set.d.ts +9 -0
- package/dist/lib/parser/declaration/set.js +30 -25
- package/dist/lib/parser/node.d.ts +7 -0
- package/dist/lib/parser/parse.d.ts +107 -0
- package/dist/lib/parser/parse.js +1454 -1445
- package/dist/lib/parser/tokenize.d.ts +57 -0
- package/dist/lib/parser/tokenize.js +557 -404
- package/dist/lib/parser/utils/at-rule-container.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-container.js +486 -0
- package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
- package/dist/lib/parser/utils/at-rule-generic.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-generic.js +118 -0
- package/dist/lib/parser/utils/at-rule-import.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-import.js +393 -0
- package/dist/lib/parser/utils/at-rule-media.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-media.js +603 -0
- package/dist/lib/parser/utils/at-rule-page.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-page.js +28 -0
- package/dist/lib/parser/utils/at-rule-support.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-support.js +366 -0
- package/dist/lib/parser/utils/at-rule-token.d.ts +1 -0
- package/dist/lib/parser/utils/at-rule-when-else.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
- package/dist/lib/parser/utils/at-rule.d.ts +13 -0
- package/dist/lib/parser/utils/at-rule.js +37 -0
- package/dist/lib/parser/utils/cache.d.ts +6 -0
- package/dist/lib/parser/utils/cache.js +19 -0
- package/dist/lib/parser/utils/config.d.ts +2 -0
- package/dist/lib/parser/utils/config.js +1 -0
- package/dist/lib/parser/utils/declaration-list.d.ts +5 -0
- package/dist/lib/parser/utils/declaration.d.ts +18 -0
- package/dist/lib/parser/utils/declaration.js +569 -91
- package/dist/lib/parser/utils/eq.d.ts +1 -0
- package/dist/lib/parser/utils/hash.d.ts +21 -0
- package/dist/lib/parser/utils/hash.js +1 -1
- package/dist/lib/parser/utils/selector.d.ts +5 -0
- package/dist/lib/parser/utils/selector.js +476 -0
- package/dist/lib/parser/utils/text.d.ts +3 -0
- package/dist/lib/parser/utils/text.js +17 -1
- package/dist/lib/parser/utils/token.d.ts +14 -0
- package/dist/lib/parser/utils/token.js +102 -0
- package/dist/lib/parser/utils/type.d.ts +2 -0
- package/dist/lib/parser/utils/type.js +29 -18
- package/dist/lib/renderer/render.d.ts +28 -0
- package/dist/lib/renderer/render.js +421 -262
- package/dist/lib/renderer/sourcemap/lib/encode.d.ts +1 -0
- package/dist/lib/renderer/sourcemap/sourcemap.d.ts +26 -0
- package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
- package/dist/lib/syntax/color/a98rgb.d.ts +2 -0
- package/dist/lib/syntax/color/a98rgb.js +8 -12
- package/dist/lib/syntax/color/cmyk.d.ts +10 -0
- package/dist/lib/syntax/color/cmyk.js +23 -21
- package/dist/lib/syntax/color/color-mix.d.ts +2 -0
- package/dist/lib/syntax/color/color-mix.js +88 -77
- package/dist/lib/syntax/color/color.d.ts +42 -0
- package/dist/lib/syntax/color/color.js +65 -68
- package/dist/lib/syntax/color/hex.d.ts +16 -0
- package/dist/lib/syntax/color/hex.js +27 -31
- package/dist/lib/syntax/color/hsl.d.ts +20 -0
- package/dist/lib/syntax/color/hsl.js +5 -12
- package/dist/lib/syntax/color/hsv.d.ts +2 -0
- package/dist/lib/syntax/color/hwb.d.ts +21 -0
- package/dist/lib/syntax/color/hwb.js +8 -21
- package/dist/lib/syntax/color/lab.d.ts +25 -0
- package/dist/lib/syntax/color/lab.js +20 -21
- package/dist/lib/syntax/color/lch.d.ts +23 -0
- package/dist/lib/syntax/color/lch.js +13 -15
- package/dist/lib/syntax/color/oklab.d.ts +22 -0
- package/dist/lib/syntax/color/oklab.js +20 -39
- package/dist/lib/syntax/color/oklch.d.ts +20 -0
- package/dist/lib/syntax/color/oklch.js +14 -16
- package/dist/lib/syntax/color/p3.d.ts +6 -0
- package/dist/lib/syntax/color/p3.js +0 -8
- package/dist/lib/syntax/color/prophotorgb.d.ts +2 -0
- package/dist/lib/syntax/color/rec2020.d.ts +2 -0
- package/dist/lib/syntax/color/rec2020.js +9 -13
- package/dist/lib/syntax/color/relativecolor.d.ts +13 -0
- package/dist/lib/syntax/color/relativecolor.js +68 -41
- package/dist/lib/syntax/color/rgb.d.ts +20 -0
- package/dist/lib/syntax/color/rgb.js +14 -18
- package/dist/lib/syntax/color/srgb.d.ts +23 -0
- package/dist/lib/syntax/color/srgb.js +27 -26
- package/dist/lib/syntax/color/utils/components.d.ts +2 -0
- package/dist/lib/syntax/color/utils/components.js +30 -14
- package/dist/lib/syntax/color/utils/distance.d.ts +18 -0
- package/dist/lib/syntax/color/utils/distance.js +1 -8
- package/dist/lib/syntax/color/utils/matrix.d.ts +6 -0
- package/dist/lib/syntax/color/xyz.d.ts +5 -0
- package/dist/lib/syntax/color/xyz.js +8 -20
- package/dist/lib/syntax/color/xyzd50.d.ts +4 -0
- package/dist/lib/syntax/color/xyzd50.js +6 -20
- package/dist/lib/syntax/constants.d.ts +67 -0
- package/dist/lib/syntax/constants.js +436 -0
- package/dist/lib/syntax/syntax.d.ts +38 -0
- package/dist/lib/syntax/syntax.js +533 -568
- package/dist/lib/validation/config.d.ts +14 -0
- package/dist/lib/validation/config.js +72 -33
- package/dist/lib/validation/config.json.js +1159 -74
- package/dist/lib/validation/json.d.ts +2 -0
- package/dist/lib/validation/match.d.ts +38 -0
- package/dist/lib/validation/match.js +2985 -0
- package/dist/lib/validation/parser/parse.d.ts +8 -0
- package/dist/lib/validation/parser/parse.js +684 -935
- package/dist/lib/validation/parser/typedef.d.ts +95 -0
- package/dist/lib/validation/parser/typedef.js +100 -0
- package/dist/lib/validation/utils/list.d.ts +4 -0
- package/dist/lib/validation/utils/list.js +4 -11
- package/dist/lib/validation/utils/whitespace.d.ts +2 -0
- package/dist/lib/validation/utils/whitespace.js +2 -8
- package/dist/node.d.ts +207 -0
- package/dist/node.js +42 -39
- package/dist/web.d.ts +169 -0
- package/dist/web.js +38 -33
- package/package.json +15 -12
- package/playground/index.html +1328 -0
- package/playground/sw.js +55 -0
- package/playground/tree.js +176 -0
- package/dist/lib/syntax/color/utils/constants.js +0 -214
- package/dist/lib/syntax/utils.js +0 -70
- package/dist/lib/validation/at-rules/container.js +0 -342
- package/dist/lib/validation/at-rules/counter-style.js +0 -90
- package/dist/lib/validation/at-rules/custom-media.js +0 -50
- package/dist/lib/validation/at-rules/document.js +0 -89
- package/dist/lib/validation/at-rules/else.js +0 -5
- package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
- package/dist/lib/validation/at-rules/import.js +0 -150
- package/dist/lib/validation/at-rules/keyframes.js +0 -67
- package/dist/lib/validation/at-rules/layer.js +0 -41
- package/dist/lib/validation/at-rules/media.js +0 -255
- package/dist/lib/validation/at-rules/namespace.js +0 -81
- package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
- package/dist/lib/validation/at-rules/page.js +0 -100
- package/dist/lib/validation/at-rules/supports.js +0 -295
- package/dist/lib/validation/at-rules/when.js +0 -185
- package/dist/lib/validation/atrule.js +0 -184
- package/dist/lib/validation/selector.js +0 -36
- package/dist/lib/validation/syntax.js +0 -1073
- package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
- package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
- package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
- package/dist/lib/validation/syntaxes/family-name.js +0 -57
- package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
- package/dist/lib/validation/syntaxes/layer-name.js +0 -57
- package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
- package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
- package/dist/lib/validation/syntaxes/selector-list.js +0 -5
- package/dist/lib/validation/syntaxes/selector.js +0 -5
- package/dist/lib/validation/syntaxes/url.js +0 -40
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { SyntaxValidationResult } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
|
-
import '../../syntax/color/utils/constants.js';
|
|
8
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
|
-
import { validateSelector } from './selector.js';
|
|
10
|
-
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
11
|
-
import { splitTokenList } from '../utils/list.js';
|
|
12
|
-
|
|
13
|
-
function validateComplexSelectorList(tokens, root, options) {
|
|
14
|
-
tokens = tokens.slice();
|
|
15
|
-
consumeWhitespace(tokens);
|
|
16
|
-
let result = null;
|
|
17
|
-
for (const t of splitTokenList(tokens)) {
|
|
18
|
-
result = validateSelector(t, root, options);
|
|
19
|
-
if (result.valid == SyntaxValidationResult.Drop) {
|
|
20
|
-
return result;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { validateComplexSelectorList };
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
2
|
-
import { splitTokenList } from '../utils/list.js';
|
|
3
|
-
import { EnumToken, SyntaxValidationResult } from '../../ast/types.js';
|
|
4
|
-
import '../../ast/minify.js';
|
|
5
|
-
import '../../ast/walk.js';
|
|
6
|
-
import '../../parser/parse.js';
|
|
7
|
-
import '../../parser/tokenize.js';
|
|
8
|
-
import '../../parser/utils/config.js';
|
|
9
|
-
import '../../syntax/color/utils/constants.js';
|
|
10
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
11
|
-
import { validateCompoundSelector } from './compound-selector.js';
|
|
12
|
-
|
|
13
|
-
const combinatorsTokens = [EnumToken.ChildCombinatorTokenType, EnumToken.ColumnCombinatorTokenType,
|
|
14
|
-
// EnumToken.DescendantCombinatorTokenType,
|
|
15
|
-
EnumToken.NextSiblingCombinatorTokenType, EnumToken.SubsequentSiblingCombinatorTokenType];
|
|
16
|
-
// <compound-selector> [ <combinator>? <compound-selector> ]*
|
|
17
|
-
function validateComplexSelector(tokens, root, options) {
|
|
18
|
-
// [ <type-selector>? <subclass-selector>* [ <pseudo-element-selector> <pseudo-class-selector>* ]* ]!
|
|
19
|
-
tokens = tokens.slice();
|
|
20
|
-
consumeWhitespace(tokens);
|
|
21
|
-
if (tokens.length == 0) {
|
|
22
|
-
return {
|
|
23
|
-
valid: SyntaxValidationResult.Drop,
|
|
24
|
-
context: [],
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
node: root,
|
|
27
|
-
syntax: null,
|
|
28
|
-
error: 'expected selector'
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
// const config = getSyntaxConfig();
|
|
32
|
-
//
|
|
33
|
-
// let match: number = 0;
|
|
34
|
-
let result = null;
|
|
35
|
-
// const combinators: EnumToken[] = combinatorsTokens.filter((t: EnumToken) => t != EnumToken.DescendantCombinatorTokenType);
|
|
36
|
-
for (const t of splitTokenList(tokens, combinatorsTokens)) {
|
|
37
|
-
result = validateCompoundSelector(t, root, options);
|
|
38
|
-
if (result.valid == SyntaxValidationResult.Drop) {
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// @ts-ignore
|
|
43
|
-
return result ?? {
|
|
44
|
-
valid: SyntaxValidationResult.Drop,
|
|
45
|
-
context: [],
|
|
46
|
-
node: root,
|
|
47
|
-
syntax: null,
|
|
48
|
-
error: 'expecting compound-selector'
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export { combinatorsTokens, validateComplexSelector };
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { SyntaxValidationResult, EnumToken } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
|
-
import { mozExtensions, webkitExtensions } from '../../syntax/syntax.js';
|
|
8
|
-
import '../../syntax/color/utils/constants.js';
|
|
9
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
10
|
-
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
11
|
-
import { getSyntaxConfig } from '../config.js';
|
|
12
|
-
|
|
13
|
-
function validateCompoundSelector(tokens, root, options) {
|
|
14
|
-
if (tokens.length == 0) {
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
return {
|
|
17
|
-
valid: SyntaxValidationResult.Drop,
|
|
18
|
-
context: [],
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
node: root,
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
syntax: null,
|
|
23
|
-
error: 'expected selector'
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
tokens = tokens.slice();
|
|
27
|
-
consumeWhitespace(tokens);
|
|
28
|
-
const config = getSyntaxConfig();
|
|
29
|
-
let match = 0;
|
|
30
|
-
let length = tokens.length;
|
|
31
|
-
while (tokens.length > 0) {
|
|
32
|
-
while (tokens.length > 0 && tokens[0].typ == EnumToken.NestingSelectorTokenType) {
|
|
33
|
-
if (!options?.nestedSelector) {
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
return {
|
|
36
|
-
valid: SyntaxValidationResult.Drop,
|
|
37
|
-
context: [],
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
node: tokens[0],
|
|
40
|
-
syntax: null,
|
|
41
|
-
error: 'nested selector not allowed'
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
match++;
|
|
45
|
-
tokens.shift();
|
|
46
|
-
consumeWhitespace(tokens);
|
|
47
|
-
}
|
|
48
|
-
// <type-selector>
|
|
49
|
-
while (tokens.length > 0 &&
|
|
50
|
-
[
|
|
51
|
-
EnumToken.IdenTokenType,
|
|
52
|
-
EnumToken.NameSpaceAttributeTokenType,
|
|
53
|
-
EnumToken.ClassSelectorTokenType,
|
|
54
|
-
EnumToken.HashTokenType,
|
|
55
|
-
EnumToken.UniversalSelectorTokenType
|
|
56
|
-
].includes(tokens[0].typ)) {
|
|
57
|
-
match++;
|
|
58
|
-
tokens.shift();
|
|
59
|
-
consumeWhitespace(tokens);
|
|
60
|
-
}
|
|
61
|
-
while (tokens.length > 0 && tokens[0].typ == EnumToken.PseudoClassFuncTokenType) {
|
|
62
|
-
if (!mozExtensions.has(tokens[0].val + '()') &&
|
|
63
|
-
!webkitExtensions.has(tokens[0].val + '()') &&
|
|
64
|
-
!((tokens[0].val + '()') in config.selectors)) {
|
|
65
|
-
if (!options?.lenient || /^(:?)-webkit-/.test(tokens[0].val)) {
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
return {
|
|
68
|
-
valid: SyntaxValidationResult.Drop,
|
|
69
|
-
context: [],
|
|
70
|
-
// @ts-ignore
|
|
71
|
-
node: tokens[0],
|
|
72
|
-
syntax: null,
|
|
73
|
-
error: 'unknown pseudo-class: ' + tokens[0].val + '()'
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
match++;
|
|
78
|
-
tokens.shift();
|
|
79
|
-
consumeWhitespace(tokens);
|
|
80
|
-
}
|
|
81
|
-
while (tokens.length > 0 && (tokens[0].typ == EnumToken.PseudoElementTokenType || tokens[0].typ == EnumToken.PseudoClassTokenType)) {
|
|
82
|
-
const isPseudoElement = tokens[0].typ == EnumToken.PseudoElementTokenType;
|
|
83
|
-
if (
|
|
84
|
-
// https://developer.mozilla.org/en-US/docs/Web/CSS/WebKit_Extensions#pseudo-elements
|
|
85
|
-
!(isPseudoElement && tokens[0].val.startsWith('::-webkit-')) &&
|
|
86
|
-
!mozExtensions.has(tokens[0].val) &&
|
|
87
|
-
!webkitExtensions.has(tokens[0].val) &&
|
|
88
|
-
!(tokens[0].val in config.selectors) &&
|
|
89
|
-
!(!isPseudoElement &&
|
|
90
|
-
(':' + tokens[0].val) in config.selectors)) {
|
|
91
|
-
if (!options?.lenient || /^(:?)-webkit-/.test(tokens[0].val)) {
|
|
92
|
-
// @ts-ignore
|
|
93
|
-
return {
|
|
94
|
-
valid: SyntaxValidationResult.Drop,
|
|
95
|
-
context: [],
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
node: tokens[0],
|
|
98
|
-
syntax: null,
|
|
99
|
-
error: 'unknown pseudo-class: ' + tokens[0].val
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
match++;
|
|
104
|
-
tokens.shift();
|
|
105
|
-
consumeWhitespace(tokens);
|
|
106
|
-
}
|
|
107
|
-
while (tokens.length > 0 && tokens[0].typ == EnumToken.AttrTokenType) {
|
|
108
|
-
const children = tokens[0].chi.slice();
|
|
109
|
-
consumeWhitespace(children);
|
|
110
|
-
if (children.length == 0 || ![
|
|
111
|
-
EnumToken.IdenTokenType,
|
|
112
|
-
EnumToken.NameSpaceAttributeTokenType,
|
|
113
|
-
EnumToken.MatchExpressionTokenType
|
|
114
|
-
].includes(children[0].typ)) {
|
|
115
|
-
// @ts-ignore
|
|
116
|
-
return {
|
|
117
|
-
valid: SyntaxValidationResult.Drop,
|
|
118
|
-
context: [],
|
|
119
|
-
node: tokens[0],
|
|
120
|
-
syntax: null,
|
|
121
|
-
error: 'invalid attribute selector'
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
if (children[0].typ == EnumToken.MatchExpressionTokenType) {
|
|
125
|
-
if (children.length != 1) {
|
|
126
|
-
return {
|
|
127
|
-
valid: SyntaxValidationResult.Drop,
|
|
128
|
-
context: [],
|
|
129
|
-
node: tokens[0],
|
|
130
|
-
syntax: null,
|
|
131
|
-
error: 'invalid <attribute-selector>'
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
if (![
|
|
135
|
-
EnumToken.IdenTokenType,
|
|
136
|
-
EnumToken.NameSpaceAttributeTokenType
|
|
137
|
-
].includes(children[0].l.typ) ||
|
|
138
|
-
![
|
|
139
|
-
EnumToken.EqualMatchTokenType, EnumToken.DashMatchTokenType,
|
|
140
|
-
EnumToken.StartMatchTokenType, EnumToken.ContainMatchTokenType,
|
|
141
|
-
EnumToken.EndMatchTokenType, EnumToken.IncludeMatchTokenType
|
|
142
|
-
].includes(children[0].op.typ) ||
|
|
143
|
-
![
|
|
144
|
-
EnumToken.StringTokenType,
|
|
145
|
-
EnumToken.IdenTokenType
|
|
146
|
-
].includes(children[0].r.typ) ||
|
|
147
|
-
(children[0].attr != null && !['i', 's'].includes(children[0].attr))) {
|
|
148
|
-
// @ts-ignore
|
|
149
|
-
return {
|
|
150
|
-
valid: SyntaxValidationResult.Drop,
|
|
151
|
-
context: [],
|
|
152
|
-
node: tokens[0],
|
|
153
|
-
syntax: null,
|
|
154
|
-
error: 'invalid attribute selector'
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
match++;
|
|
159
|
-
tokens.shift();
|
|
160
|
-
consumeWhitespace(tokens);
|
|
161
|
-
}
|
|
162
|
-
if (length == tokens.length) {
|
|
163
|
-
return {
|
|
164
|
-
valid: SyntaxValidationResult.Drop,
|
|
165
|
-
context: [],
|
|
166
|
-
// @ts-ignore
|
|
167
|
-
node: tokens[0],
|
|
168
|
-
// @ts-ignore
|
|
169
|
-
syntax: null,
|
|
170
|
-
error: 'expected compound selector'
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
length = tokens.length;
|
|
174
|
-
}
|
|
175
|
-
return match == 0 ? {
|
|
176
|
-
valid: SyntaxValidationResult.Drop,
|
|
177
|
-
context: [],
|
|
178
|
-
// @ts-ignore
|
|
179
|
-
node: root,
|
|
180
|
-
// @ts-ignore
|
|
181
|
-
syntax: null,
|
|
182
|
-
error: 'expected compound selector'
|
|
183
|
-
} :
|
|
184
|
-
// @ts-ignore
|
|
185
|
-
{
|
|
186
|
-
valid: SyntaxValidationResult.Valid,
|
|
187
|
-
context: [],
|
|
188
|
-
// @ts-ignore
|
|
189
|
-
node: root,
|
|
190
|
-
// @ts-ignore
|
|
191
|
-
syntax: null,
|
|
192
|
-
error: null
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export { validateCompoundSelector };
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { EnumToken, SyntaxValidationResult } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
|
-
import '../../syntax/color/utils/constants.js';
|
|
8
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
|
-
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
10
|
-
|
|
11
|
-
function validateFamilyName(tokens, atRule) {
|
|
12
|
-
let node;
|
|
13
|
-
tokens = tokens.slice();
|
|
14
|
-
consumeWhitespace(tokens);
|
|
15
|
-
if (tokens.length == 0 || tokens[0].typ == EnumToken.CommaTokenType) {
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
return {
|
|
18
|
-
valid: SyntaxValidationResult.Drop,
|
|
19
|
-
matches: [],
|
|
20
|
-
node: tokens[0],
|
|
21
|
-
syntax: null,
|
|
22
|
-
error: 'unexpected token',
|
|
23
|
-
tokens
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
while (tokens.length > 0) {
|
|
27
|
-
node = tokens[0];
|
|
28
|
-
if (![EnumToken.IdenTokenType, EnumToken.StringTokenType].includes(node.typ)) {
|
|
29
|
-
// @ts-ignore
|
|
30
|
-
return {
|
|
31
|
-
valid: SyntaxValidationResult.Drop,
|
|
32
|
-
matches: [],
|
|
33
|
-
node,
|
|
34
|
-
syntax: null,
|
|
35
|
-
error: 'unexpected token',
|
|
36
|
-
tokens
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
tokens.shift();
|
|
40
|
-
consumeWhitespace(tokens);
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
if (tokens.length > 0 && tokens[0].typ == EnumToken.CommaTokenType) {
|
|
43
|
-
tokens.shift();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
return {
|
|
48
|
-
valid: SyntaxValidationResult.Valid,
|
|
49
|
-
matches: [],
|
|
50
|
-
node: null,
|
|
51
|
-
syntax: null,
|
|
52
|
-
error: '',
|
|
53
|
-
tokens
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export { validateFamilyName };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
2
|
-
import { splitTokenList } from '../utils/list.js';
|
|
3
|
-
import { EnumToken, SyntaxValidationResult } from '../../ast/types.js';
|
|
4
|
-
import '../../ast/minify.js';
|
|
5
|
-
import '../../ast/walk.js';
|
|
6
|
-
import '../../parser/parse.js';
|
|
7
|
-
import '../../parser/tokenize.js';
|
|
8
|
-
import '../../parser/utils/config.js';
|
|
9
|
-
import '../../syntax/color/utils/constants.js';
|
|
10
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
11
|
-
|
|
12
|
-
function validateKeyframeSelector(tokens, options) {
|
|
13
|
-
consumeWhitespace(tokens);
|
|
14
|
-
for (const t of splitTokenList(tokens)) {
|
|
15
|
-
if (t.length != 1 || (t[0].typ != EnumToken.PercentageTokenType && !(t[0].typ == EnumToken.IdenTokenType && ['from', 'to', 'cover', 'contain', 'entry', 'exit', 'entry-crossing', 'exit-crossing'].includes(t[0].val)))) {
|
|
16
|
-
return {
|
|
17
|
-
valid: SyntaxValidationResult.Drop,
|
|
18
|
-
context: [],
|
|
19
|
-
node: t[0],
|
|
20
|
-
syntax: null,
|
|
21
|
-
error: 'expected keyframe selector'
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
return {
|
|
27
|
-
valid: SyntaxValidationResult.Valid,
|
|
28
|
-
context: [],
|
|
29
|
-
node: null,
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
syntax: null,
|
|
32
|
-
error: ''
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { validateKeyframeSelector };
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { EnumToken, SyntaxValidationResult } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
|
-
import '../../syntax/color/utils/constants.js';
|
|
8
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
|
-
|
|
10
|
-
function validateLayerName(tokens) {
|
|
11
|
-
const slice = tokens.reduce((acc, curr) => {
|
|
12
|
-
if (curr.typ == EnumToken.CommaTokenType) {
|
|
13
|
-
acc.push([]);
|
|
14
|
-
}
|
|
15
|
-
else if (curr.typ != EnumToken.CommentTokenType) {
|
|
16
|
-
acc[acc.length - 1].push(curr);
|
|
17
|
-
}
|
|
18
|
-
return acc;
|
|
19
|
-
}, [[]]);
|
|
20
|
-
for (let i = 0; i < slice.length; i++) {
|
|
21
|
-
if (slice[i].length == 0) {
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
return {
|
|
24
|
-
valid: SyntaxValidationResult.Drop,
|
|
25
|
-
matches: tokens,
|
|
26
|
-
node: null,
|
|
27
|
-
syntax: null,
|
|
28
|
-
error: 'Invalid ident',
|
|
29
|
-
tokens
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
for (let j = 0; j < slice[i].length; j++) {
|
|
33
|
-
if (slice[i][j].typ != EnumToken.IdenTokenType && slice[i][j].typ != EnumToken.ClassSelectorTokenType) {
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
return {
|
|
36
|
-
valid: SyntaxValidationResult.Drop,
|
|
37
|
-
matches: tokens,
|
|
38
|
-
node: slice[i][j],
|
|
39
|
-
syntax: '<layer-name>',
|
|
40
|
-
error: 'expecting ident or class selector',
|
|
41
|
-
tokens
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// @ts-ignore
|
|
47
|
-
return {
|
|
48
|
-
valid: SyntaxValidationResult.Valid,
|
|
49
|
-
matches: tokens,
|
|
50
|
-
node: null,
|
|
51
|
-
syntax: null,
|
|
52
|
-
error: '',
|
|
53
|
-
tokens
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export { validateLayerName };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { SyntaxValidationResult } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
|
-
import '../../syntax/color/utils/constants.js';
|
|
8
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
|
-
import { validateRelativeSelector } from './relative-selector.js';
|
|
10
|
-
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
11
|
-
import { splitTokenList } from '../utils/list.js';
|
|
12
|
-
|
|
13
|
-
function validateRelativeSelectorList(tokens, root, options) {
|
|
14
|
-
tokens = tokens.slice();
|
|
15
|
-
consumeWhitespace(tokens);
|
|
16
|
-
for (const t of splitTokenList(tokens)) {
|
|
17
|
-
const result = validateRelativeSelector(t, root, options);
|
|
18
|
-
if (result.valid == SyntaxValidationResult.Drop) {
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
return {
|
|
24
|
-
valid: SyntaxValidationResult.Valid,
|
|
25
|
-
node: root,
|
|
26
|
-
syntax: null,
|
|
27
|
-
error: ''
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { validateRelativeSelectorList };
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
2
|
-
import '../../ast/types.js';
|
|
3
|
-
import '../../ast/minify.js';
|
|
4
|
-
import '../../ast/walk.js';
|
|
5
|
-
import '../../parser/parse.js';
|
|
6
|
-
import '../../parser/tokenize.js';
|
|
7
|
-
import '../../parser/utils/config.js';
|
|
8
|
-
import '../../syntax/color/utils/constants.js';
|
|
9
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
10
|
-
import { validateSelector } from './selector.js';
|
|
11
|
-
import { combinatorsTokens } from './complex-selector.js';
|
|
12
|
-
|
|
13
|
-
function validateRelativeSelector(tokens, root, options) {
|
|
14
|
-
tokens = tokens.slice();
|
|
15
|
-
consumeWhitespace(tokens);
|
|
16
|
-
// if (tokens.length == 0) {
|
|
17
|
-
//
|
|
18
|
-
// // @ts-ignore
|
|
19
|
-
// return {
|
|
20
|
-
// valid: ValidationLevel.Drop,
|
|
21
|
-
// matches: [],
|
|
22
|
-
// // @ts-ignore
|
|
23
|
-
// node: root,
|
|
24
|
-
// // @ts-ignore
|
|
25
|
-
// syntax: null,
|
|
26
|
-
// error: 'expected selector',
|
|
27
|
-
// tokens
|
|
28
|
-
// }
|
|
29
|
-
// }
|
|
30
|
-
// , EnumToken.DescendantCombinatorTokenType
|
|
31
|
-
if (combinatorsTokens.includes(tokens[0].typ)) {
|
|
32
|
-
tokens.shift();
|
|
33
|
-
consumeWhitespace(tokens);
|
|
34
|
-
}
|
|
35
|
-
return validateSelector(tokens, root, options);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { validateRelativeSelector };
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { EnumToken, SyntaxValidationResult } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
|
-
import '../../syntax/color/utils/constants.js';
|
|
8
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
|
-
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
10
|
-
|
|
11
|
-
function validateURL(token) {
|
|
12
|
-
const children = token.chi.slice();
|
|
13
|
-
consumeWhitespace(children);
|
|
14
|
-
if (children.length > 0 && [EnumToken.UrlTokenTokenType, EnumToken.StringTokenType, EnumToken.HashTokenType].includes(children[0].typ)) {
|
|
15
|
-
children.shift();
|
|
16
|
-
}
|
|
17
|
-
consumeWhitespace(children);
|
|
18
|
-
if (children.length > 0) {
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
return {
|
|
21
|
-
valid: SyntaxValidationResult.Drop,
|
|
22
|
-
context: [],
|
|
23
|
-
node: children[0] ?? token,
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
syntax: 'url()',
|
|
26
|
-
error: 'unexpected token'
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
// @ts-ignore
|
|
30
|
-
return {
|
|
31
|
-
valid: SyntaxValidationResult.Valid,
|
|
32
|
-
context: [],
|
|
33
|
-
node: token,
|
|
34
|
-
// @ts-ignore
|
|
35
|
-
syntax: 'url()',
|
|
36
|
-
error: ''
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export { validateURL };
|