@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,57 @@
|
|
|
1
|
+
import { 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 { validateRelativeSelector } from './relative-selector.js';
|
|
9
|
+
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
10
|
+
import { splitTokenList } from '../utils/list.js';
|
|
11
|
+
|
|
12
|
+
function validateRelativeSelectorList(tokens, root, options) {
|
|
13
|
+
tokens = tokens.slice();
|
|
14
|
+
consumeWhitespace(tokens);
|
|
15
|
+
if (tokens.length == 0) {
|
|
16
|
+
return {
|
|
17
|
+
valid: ValidationLevel.Drop,
|
|
18
|
+
matches: [],
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
node: root,
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
syntax: null,
|
|
23
|
+
error: 'expecting relative selector list',
|
|
24
|
+
tokens
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
for (const t of splitTokenList(tokens)) {
|
|
28
|
+
if (t.length == 0) {
|
|
29
|
+
return {
|
|
30
|
+
valid: ValidationLevel.Drop,
|
|
31
|
+
matches: [],
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
node: root,
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
syntax: null,
|
|
36
|
+
error: 'unexpected comma',
|
|
37
|
+
tokens
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const result = validateRelativeSelector(t, root, options);
|
|
41
|
+
if (result.valid == ValidationLevel.Drop) {
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
valid: ValidationLevel.Valid,
|
|
47
|
+
matches: [],
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
node: root,
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
syntax: null,
|
|
52
|
+
error: '',
|
|
53
|
+
tokens
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { validateRelativeSelectorList };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
2
|
+
import { ValidationLevel } from '../../ast/types.js';
|
|
3
|
+
import '../../ast/minify.js';
|
|
4
|
+
import '../../ast/walk.js';
|
|
5
|
+
import '../../parser/parse.js';
|
|
6
|
+
import '../../renderer/color/utils/constants.js';
|
|
7
|
+
import '../../renderer/sourcemap/lib/encode.js';
|
|
8
|
+
import '../../parser/utils/config.js';
|
|
9
|
+
import { validateSelector } from './selector.js';
|
|
10
|
+
import { combinatorsTokens } from './complex-selector.js';
|
|
11
|
+
|
|
12
|
+
function validateRelativeSelector(tokens, root, options) {
|
|
13
|
+
tokens = tokens.slice();
|
|
14
|
+
consumeWhitespace(tokens);
|
|
15
|
+
if (tokens.length == 0) {
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
return {
|
|
18
|
+
valid: ValidationLevel.Drop,
|
|
19
|
+
matches: [],
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
node: root,
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
syntax: null,
|
|
24
|
+
error: 'expected selector',
|
|
25
|
+
tokens
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
// , EnumToken.DescendantCombinatorTokenType
|
|
29
|
+
if (combinatorsTokens.includes(tokens[0].typ)) {
|
|
30
|
+
tokens.shift();
|
|
31
|
+
consumeWhitespace(tokens);
|
|
32
|
+
}
|
|
33
|
+
return validateSelector(tokens, root, options);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { validateRelativeSelector };
|
|
@@ -0,0 +1,75 @@
|
|
|
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 { consumeWhitespace } from '../utils/whitespace.js';
|
|
9
|
+
|
|
10
|
+
function validateURL(token) {
|
|
11
|
+
if (token.typ == EnumToken.UrlTokenTokenType) {
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
return {
|
|
14
|
+
valid: ValidationLevel.Valid,
|
|
15
|
+
matches: [],
|
|
16
|
+
node: token,
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
syntax: 'url()',
|
|
19
|
+
error: '',
|
|
20
|
+
tokens: []
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (token.typ != EnumToken.UrlFunctionTokenType) {
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
return {
|
|
26
|
+
valid: ValidationLevel.Drop,
|
|
27
|
+
matches: [],
|
|
28
|
+
node: token,
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
syntax: 'url()',
|
|
31
|
+
error: 'expected url()',
|
|
32
|
+
tokens: []
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const children = token.chi.slice();
|
|
36
|
+
consumeWhitespace(children);
|
|
37
|
+
if (children.length == 0 || ![EnumToken.UrlTokenTokenType, EnumToken.StringTokenType, EnumToken.HashTokenType].includes(children[0].typ)) {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
return {
|
|
40
|
+
valid: ValidationLevel.Drop,
|
|
41
|
+
matches: [],
|
|
42
|
+
node: children[0] ?? token,
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
syntax: 'url()',
|
|
45
|
+
error: 'expected url-token',
|
|
46
|
+
tokens: children
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
children.shift();
|
|
50
|
+
consumeWhitespace(children);
|
|
51
|
+
if (children.length > 0) {
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
return {
|
|
54
|
+
valid: ValidationLevel.Drop,
|
|
55
|
+
matches: [],
|
|
56
|
+
node: children[0] ?? token,
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
syntax: 'url()',
|
|
59
|
+
error: 'unexpected token',
|
|
60
|
+
tokens: children
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
return {
|
|
65
|
+
valid: ValidationLevel.Valid,
|
|
66
|
+
matches: [],
|
|
67
|
+
node: token,
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
syntax: 'url()',
|
|
70
|
+
error: '',
|
|
71
|
+
tokens: []
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { validateURL };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EnumToken } 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
|
+
|
|
9
|
+
function splitTokenList(tokenList, split = [EnumToken.CommaTokenType]) {
|
|
10
|
+
return tokenList.reduce((acc, curr) => {
|
|
11
|
+
if (curr.typ == EnumToken.CommentTokenType) {
|
|
12
|
+
return acc;
|
|
13
|
+
}
|
|
14
|
+
if (split.includes(curr.typ)) {
|
|
15
|
+
acc.push([]);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
acc[acc.length - 1].push(curr);
|
|
19
|
+
}
|
|
20
|
+
return acc;
|
|
21
|
+
}, [[]]);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { splitTokenList };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EnumToken } 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
|
+
|
|
9
|
+
function consumeWhitespace(tokens) {
|
|
10
|
+
if (tokens.length == 0) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if (tokens[0].typ != EnumToken.WhitespaceTokenType && tokens[0].typ != EnumToken.DescendantCombinatorTokenType) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
while (tokens.length > 0 && (tokens[0].typ == EnumToken.WhitespaceTokenType || tokens[0].typ == EnumToken.DescendantCombinatorTokenType)) {
|
|
17
|
+
tokens.shift();
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { consumeWhitespace };
|
package/dist/node/index.js
CHANGED
|
@@ -9,13 +9,13 @@ import { doParse } from '../lib/parser/parse.js';
|
|
|
9
9
|
export { parseString, parseTokens } from '../lib/parser/parse.js';
|
|
10
10
|
import '../lib/renderer/color/utils/constants.js';
|
|
11
11
|
import '../lib/parser/utils/config.js';
|
|
12
|
-
import
|
|
12
|
+
import '../lib/validation/config.js';
|
|
13
|
+
import '../lib/validation/parser/types.js';
|
|
14
|
+
import '../lib/validation/parser/parse.js';
|
|
15
|
+
import '../lib/validation/syntaxes/complex-selector.js';
|
|
16
|
+
import { dirname, resolve } from '../lib/fs/resolve.js';
|
|
13
17
|
import { load } from './load.js';
|
|
14
18
|
|
|
15
|
-
/**
|
|
16
|
-
* entry point for node and other runtimes
|
|
17
|
-
* @module
|
|
18
|
-
*/
|
|
19
19
|
/**
|
|
20
20
|
* render ast node
|
|
21
21
|
*/
|
package/dist/web/index.js
CHANGED
|
@@ -8,7 +8,11 @@ import { doParse } from '../lib/parser/parse.js';
|
|
|
8
8
|
export { parseString, parseTokens } from '../lib/parser/parse.js';
|
|
9
9
|
import '../lib/renderer/color/utils/constants.js';
|
|
10
10
|
import '../lib/parser/utils/config.js';
|
|
11
|
-
import
|
|
11
|
+
import '../lib/validation/config.js';
|
|
12
|
+
import '../lib/validation/parser/types.js';
|
|
13
|
+
import '../lib/validation/parser/parse.js';
|
|
14
|
+
import '../lib/validation/syntaxes/complex-selector.js';
|
|
15
|
+
import { dirname, resolve } from '../lib/fs/resolve.js';
|
|
12
16
|
import { load } from './load.js';
|
|
13
17
|
|
|
14
18
|
/**
|
package/dist/web/load.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbela99/css-parser",
|
|
3
3
|
"description": "CSS parser for node and the browser",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "v0.9.0",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/node/index.js",
|
|
7
7
|
"./umd": "./dist/index-umd-web.js",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"test:cov": "c8 --reporter=html --reporter=text --reporter=json-summary mocha --reporter-options='maxDiffSize=1801920' \"test/**/node.spec.js\"",
|
|
21
21
|
"test:web-cov": "web-test-runner \"test/**/web.spec.js\" --node-resolve --playwright --browsers chromium firefox webkit --root-dir=. --coverage",
|
|
22
22
|
"profile": "node --enable-source-maps --inspect-brk test/inspect.js",
|
|
23
|
+
"syntax-update": "esno tools/validation.ts",
|
|
23
24
|
"debug": "web-test-runner \"test/**/web.spec.js\" --manual --open --node-resolve --root-dir=."
|
|
24
25
|
},
|
|
25
26
|
"repository": {
|
|
@@ -49,21 +50,22 @@
|
|
|
49
50
|
"homepage": "https://github.com/tbela99/css-parser#readme",
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@esm-bundle/chai": "^4.3.4-fix.0",
|
|
52
|
-
"@rollup/plugin-commonjs": "^
|
|
53
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
|
53
54
|
"@rollup/plugin-json": "^6.1.0",
|
|
54
|
-
"@rollup/plugin-node-resolve": "^
|
|
55
|
-
"@rollup/plugin-typescript": "^
|
|
56
|
-
"@types/chai": "^
|
|
57
|
-
"@types/mocha": "^10.0.
|
|
58
|
-
"@types/node": "^22.
|
|
59
|
-
"@types/web": "^0.0.
|
|
60
|
-
"@web/test-runner": "^0.
|
|
55
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
56
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
57
|
+
"@types/chai": "^5.0.1",
|
|
58
|
+
"@types/mocha": "^10.0.10",
|
|
59
|
+
"@types/node": "^22.13.5",
|
|
60
|
+
"@types/web": "^0.0.206",
|
|
61
|
+
"@web/test-runner": "^0.20.0",
|
|
61
62
|
"@web/test-runner-playwright": "^0.11.0",
|
|
62
|
-
"c8": "^10.1.
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
63
|
+
"c8": "^10.1.3",
|
|
64
|
+
"esno": "^4.8.0",
|
|
65
|
+
"mocha": "^11.1.0",
|
|
66
|
+
"playwright": "^1.50.1",
|
|
67
|
+
"rollup": "^4.34.8",
|
|
66
68
|
"rollup-plugin-dts": "^6.1.1",
|
|
67
|
-
"tslib": "^2.
|
|
69
|
+
"tslib": "^2.8.1"
|
|
68
70
|
}
|
|
69
71
|
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
class IterableWeakSet {
|
|
2
|
-
#weakset = new WeakSet;
|
|
3
|
-
#set = new Set;
|
|
4
|
-
// constructor(iterable?: Iterable<any>) {
|
|
5
|
-
//
|
|
6
|
-
// if (iterable) {
|
|
7
|
-
//
|
|
8
|
-
// for (const value of iterable) {
|
|
9
|
-
//
|
|
10
|
-
// const ref: WeakRef<any> = new WeakRef(value);
|
|
11
|
-
//
|
|
12
|
-
// this.#weakset.add(value);
|
|
13
|
-
// this.#set.add(ref);
|
|
14
|
-
// }
|
|
15
|
-
// }
|
|
16
|
-
// }
|
|
17
|
-
has(value) {
|
|
18
|
-
return this.#weakset.has(value);
|
|
19
|
-
}
|
|
20
|
-
// delete(value: any): boolean {
|
|
21
|
-
//
|
|
22
|
-
// if (this.#weakset.has(value)) {
|
|
23
|
-
//
|
|
24
|
-
// for (const ref of this.#set) {
|
|
25
|
-
//
|
|
26
|
-
// if (ref.deref() === value) {
|
|
27
|
-
//
|
|
28
|
-
// this.#set.delete(ref);
|
|
29
|
-
// break;
|
|
30
|
-
// }
|
|
31
|
-
// }
|
|
32
|
-
//
|
|
33
|
-
// return this.#weakset.delete(value);
|
|
34
|
-
// }
|
|
35
|
-
//
|
|
36
|
-
// return false;
|
|
37
|
-
// }
|
|
38
|
-
add(value) {
|
|
39
|
-
if (!this.#weakset.has(value)) {
|
|
40
|
-
this.#weakset.add(value);
|
|
41
|
-
this.#set.add(new WeakRef(value));
|
|
42
|
-
}
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
*[Symbol.iterator]() {
|
|
46
|
-
for (const ref of new Set(this.#set)) {
|
|
47
|
-
const key = ref.deref();
|
|
48
|
-
if (key != null) {
|
|
49
|
-
yield key;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
this.#set.delete(ref);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export { IterableWeakSet };
|