@tbela99/css-parser 0.9.1 → 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/LICENSE.md +1 -1
- package/README.md +29 -17
- package/dist/index-umd-web.js +7461 -4360
- package/dist/index.cjs +8608 -5507
- package/dist/index.d.ts +203 -61
- package/dist/lib/ast/expand.js +2 -1
- package/dist/lib/ast/features/calc.js +19 -11
- package/dist/lib/ast/features/index.js +1 -0
- package/dist/lib/ast/features/inlinecssvariables.js +47 -29
- package/dist/lib/ast/features/prefix.js +117 -91
- package/dist/lib/ast/features/shorthand.js +34 -14
- package/dist/lib/ast/features/transform.js +67 -0
- package/dist/lib/ast/features/type.js +7 -0
- package/dist/lib/ast/math/expression.js +20 -10
- package/dist/lib/ast/math/math.js +20 -2
- package/dist/lib/ast/minify.js +209 -80
- package/dist/lib/ast/transform/compute.js +337 -0
- package/dist/lib/ast/transform/convert.js +33 -0
- package/dist/lib/ast/transform/matrix.js +112 -0
- package/dist/lib/ast/transform/minify.js +296 -0
- package/dist/lib/ast/transform/perspective.js +10 -0
- package/dist/lib/ast/transform/rotate.js +40 -0
- package/dist/lib/ast/transform/scale.js +32 -0
- package/dist/lib/ast/transform/skew.js +23 -0
- package/dist/lib/ast/transform/translate.js +32 -0
- package/dist/lib/ast/transform/utils.js +198 -0
- package/dist/lib/ast/types.js +18 -15
- package/dist/lib/ast/walk.js +54 -22
- 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 +449 -340
- package/dist/lib/parser/tokenize.js +147 -72
- package/dist/lib/parser/utils/declaration.js +5 -4
- package/dist/lib/parser/utils/type.js +2 -1
- package/dist/lib/renderer/color/a98rgb.js +2 -1
- package/dist/lib/renderer/color/{colormix.js → color-mix.js} +16 -7
- package/dist/lib/renderer/color/color.js +264 -170
- package/dist/lib/renderer/color/hex.js +19 -8
- package/dist/lib/renderer/color/hsl.js +9 -3
- package/dist/lib/renderer/color/hwb.js +2 -1
- package/dist/lib/renderer/color/lab.js +10 -1
- package/dist/lib/renderer/color/lch.js +10 -1
- package/dist/lib/renderer/color/oklab.js +10 -1
- package/dist/lib/renderer/color/oklch.js +10 -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 +27 -32
- package/dist/lib/renderer/color/rgb.js +14 -10
- package/dist/lib/renderer/color/srgb.js +48 -23
- package/dist/lib/renderer/color/utils/components.js +18 -6
- 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 +108 -43
- package/dist/lib/syntax/syntax.js +267 -136
- package/dist/lib/validation/at-rules/container.js +81 -103
- 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 +19 -23
- package/dist/lib/validation/at-rules/layer.js +5 -5
- package/dist/lib/validation/at-rules/media.js +42 -53
- 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 -18
- 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 +8 -5
- package/dist/lib/validation/syntax.js +724 -1405
- 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 +6 -5
- package/dist/lib/validation/syntaxes/keyframe-selector.js +23 -105
- 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 +17 -15
- package/dist/lib/validation/syntaxes/url.js +18 -22
- package/dist/lib/validation/utils/list.js +20 -2
- package/dist/lib/validation/utils/whitespace.js +2 -1
- package/dist/node/index.js +4 -2
- package/dist/node/load.js +6 -1
- package/dist/web/index.js +4 -2
- package/dist/web/load.js +5 -0
- package/package.json +16 -15
- package/dist/lib/renderer/color/prophotoRgb.js +0 -56
- package/dist/lib/validation/declaration.js +0 -94
- package/dist/lib/validation/syntaxes/image.js +0 -29
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
import { consumeWhitespace } from '../utils/whitespace.js';
|
|
2
|
-
import
|
|
2
|
+
import '../../ast/types.js';
|
|
3
3
|
import '../../ast/minify.js';
|
|
4
4
|
import '../../ast/walk.js';
|
|
5
5
|
import '../../parser/parse.js';
|
|
6
|
+
import '../../parser/tokenize.js';
|
|
7
|
+
import '../../parser/utils/config.js';
|
|
6
8
|
import '../../renderer/color/utils/constants.js';
|
|
7
9
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
8
|
-
import '../../parser/utils/config.js';
|
|
9
10
|
import { validateSelector } from './selector.js';
|
|
10
11
|
import { combinatorsTokens } from './complex-selector.js';
|
|
11
12
|
|
|
12
13
|
function validateRelativeSelector(tokens, root, options) {
|
|
13
14
|
tokens = tokens.slice();
|
|
14
15
|
consumeWhitespace(tokens);
|
|
15
|
-
if (tokens.length == 0) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
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
|
+
// }
|
|
28
30
|
// , EnumToken.DescendantCombinatorTokenType
|
|
29
31
|
if (combinatorsTokens.includes(tokens[0].typ)) {
|
|
30
32
|
tokens.shift();
|
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
import { EnumToken,
|
|
1
|
+
import { EnumToken, SyntaxValidationResult } 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 { consumeWhitespace } from '../utils/whitespace.js';
|
|
9
10
|
|
|
10
11
|
function validateURL(token) {
|
|
11
12
|
if (token.typ == EnumToken.UrlTokenTokenType) {
|
|
12
13
|
// @ts-ignore
|
|
13
14
|
return {
|
|
14
|
-
valid:
|
|
15
|
-
|
|
15
|
+
valid: SyntaxValidationResult.Valid,
|
|
16
|
+
context: [],
|
|
16
17
|
node: token,
|
|
17
18
|
// @ts-ignore
|
|
18
19
|
syntax: 'url()',
|
|
19
|
-
error: ''
|
|
20
|
-
tokens: []
|
|
20
|
+
error: ''
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
if (token.typ != EnumToken.UrlFunctionTokenType) {
|
|
24
24
|
// @ts-ignore
|
|
25
25
|
return {
|
|
26
|
-
valid:
|
|
27
|
-
|
|
26
|
+
valid: SyntaxValidationResult.Drop,
|
|
27
|
+
context: [],
|
|
28
28
|
node: token,
|
|
29
29
|
// @ts-ignore
|
|
30
30
|
syntax: 'url()',
|
|
31
|
-
error: 'expected url()'
|
|
32
|
-
tokens: []
|
|
31
|
+
error: 'expected url()'
|
|
33
32
|
};
|
|
34
33
|
}
|
|
35
34
|
const children = token.chi.slice();
|
|
@@ -37,13 +36,12 @@ function validateURL(token) {
|
|
|
37
36
|
if (children.length == 0 || ![EnumToken.UrlTokenTokenType, EnumToken.StringTokenType, EnumToken.HashTokenType].includes(children[0].typ)) {
|
|
38
37
|
// @ts-ignore
|
|
39
38
|
return {
|
|
40
|
-
valid:
|
|
41
|
-
|
|
39
|
+
valid: SyntaxValidationResult.Drop,
|
|
40
|
+
context: [],
|
|
42
41
|
node: children[0] ?? token,
|
|
43
42
|
// @ts-ignore
|
|
44
43
|
syntax: 'url()',
|
|
45
|
-
error: 'expected url-token'
|
|
46
|
-
tokens: children
|
|
44
|
+
error: 'expected url-token'
|
|
47
45
|
};
|
|
48
46
|
}
|
|
49
47
|
children.shift();
|
|
@@ -51,24 +49,22 @@ function validateURL(token) {
|
|
|
51
49
|
if (children.length > 0) {
|
|
52
50
|
// @ts-ignore
|
|
53
51
|
return {
|
|
54
|
-
valid:
|
|
55
|
-
|
|
52
|
+
valid: SyntaxValidationResult.Drop,
|
|
53
|
+
context: [],
|
|
56
54
|
node: children[0] ?? token,
|
|
57
55
|
// @ts-ignore
|
|
58
56
|
syntax: 'url()',
|
|
59
|
-
error: 'unexpected token'
|
|
60
|
-
tokens: children
|
|
57
|
+
error: 'unexpected token'
|
|
61
58
|
};
|
|
62
59
|
}
|
|
63
60
|
// @ts-ignore
|
|
64
61
|
return {
|
|
65
|
-
valid:
|
|
66
|
-
|
|
62
|
+
valid: SyntaxValidationResult.Valid,
|
|
63
|
+
context: [],
|
|
67
64
|
node: token,
|
|
68
65
|
// @ts-ignore
|
|
69
66
|
syntax: 'url()',
|
|
70
|
-
error: ''
|
|
71
|
-
tokens: []
|
|
67
|
+
error: ''
|
|
72
68
|
};
|
|
73
69
|
}
|
|
74
70
|
|
|
@@ -2,10 +2,28 @@ import { 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
|
|
|
10
|
+
function stripCommaToken(tokenList) {
|
|
11
|
+
let result = [];
|
|
12
|
+
let last = null;
|
|
13
|
+
for (let i = 0; i < tokenList.length; i++) {
|
|
14
|
+
if (tokenList[i].typ == EnumToken.CommaTokenType && last != null && last.typ == EnumToken.CommaTokenType) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (tokenList[i].typ != EnumToken.WhitespaceTokenType) {
|
|
18
|
+
last = tokenList[i];
|
|
19
|
+
}
|
|
20
|
+
if (tokenList[i].typ == EnumToken.CommentTokenType || tokenList[i].typ == EnumToken.CommaTokenType) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
result.push(tokenList[i]);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
9
27
|
function splitTokenList(tokenList, split = [EnumToken.CommaTokenType]) {
|
|
10
28
|
return tokenList.reduce((acc, curr) => {
|
|
11
29
|
if (curr.typ == EnumToken.CommentTokenType) {
|
|
@@ -21,4 +39,4 @@ function splitTokenList(tokenList, split = [EnumToken.CommaTokenType]) {
|
|
|
21
39
|
}, [[]]);
|
|
22
40
|
}
|
|
23
41
|
|
|
24
|
-
export { splitTokenList };
|
|
42
|
+
export { splitTokenList, stripCommaToken };
|
|
@@ -2,9 +2,10 @@ import { 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
|
|
|
9
10
|
function consumeWhitespace(tokens) {
|
|
10
11
|
if (tokens.length == 0) {
|
package/dist/node/index.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
|
-
export { EnumToken } from '../lib/ast/types.js';
|
|
2
|
+
export { EnumToken, ValidationLevel } from '../lib/ast/types.js';
|
|
3
3
|
export { minify } from '../lib/ast/minify.js';
|
|
4
4
|
export { walk, walkValues } from '../lib/ast/walk.js';
|
|
5
5
|
export { expand } from '../lib/ast/expand.js';
|
|
6
6
|
import { doRender } from '../lib/renderer/render.js';
|
|
7
7
|
export { renderToken } from '../lib/renderer/render.js';
|
|
8
|
+
import '../lib/renderer/color/utils/constants.js';
|
|
8
9
|
import { doParse } from '../lib/parser/parse.js';
|
|
9
10
|
export { parseString, parseTokens } from '../lib/parser/parse.js';
|
|
10
|
-
import '../lib/
|
|
11
|
+
import '../lib/parser/tokenize.js';
|
|
11
12
|
import '../lib/parser/utils/config.js';
|
|
12
13
|
import '../lib/validation/config.js';
|
|
13
14
|
import '../lib/validation/parser/types.js';
|
|
14
15
|
import '../lib/validation/parser/parse.js';
|
|
15
16
|
import '../lib/validation/syntaxes/complex-selector.js';
|
|
17
|
+
import '../lib/validation/syntax.js';
|
|
16
18
|
import { dirname, resolve } from '../lib/fs/resolve.js';
|
|
17
19
|
import { load } from './load.js';
|
|
18
20
|
|
package/dist/node/load.js
CHANGED
|
@@ -7,7 +7,12 @@ function parseResponse(response) {
|
|
|
7
7
|
}
|
|
8
8
|
return response.text();
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* load file
|
|
12
|
+
* @param url
|
|
13
|
+
* @param currentFile
|
|
14
|
+
*/
|
|
15
|
+
async function load(url, currentFile = '.') {
|
|
11
16
|
const resolved = resolve(url, currentFile);
|
|
12
17
|
return matchUrl.test(resolved.absolute) ? fetch(resolved.absolute).then(parseResponse) : readFile(resolved.absolute, { encoding: 'utf-8' });
|
|
13
18
|
}
|
package/dist/web/index.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
export { EnumToken } from '../lib/ast/types.js';
|
|
1
|
+
export { EnumToken, ValidationLevel } from '../lib/ast/types.js';
|
|
2
2
|
export { minify } from '../lib/ast/minify.js';
|
|
3
3
|
export { walk, walkValues } from '../lib/ast/walk.js';
|
|
4
4
|
export { expand } from '../lib/ast/expand.js';
|
|
5
5
|
import { doRender } from '../lib/renderer/render.js';
|
|
6
6
|
export { renderToken } from '../lib/renderer/render.js';
|
|
7
|
+
import '../lib/renderer/color/utils/constants.js';
|
|
7
8
|
import { doParse } from '../lib/parser/parse.js';
|
|
8
9
|
export { parseString, parseTokens } from '../lib/parser/parse.js';
|
|
9
|
-
import '../lib/
|
|
10
|
+
import '../lib/parser/tokenize.js';
|
|
10
11
|
import '../lib/parser/utils/config.js';
|
|
11
12
|
import '../lib/validation/config.js';
|
|
12
13
|
import '../lib/validation/parser/types.js';
|
|
13
14
|
import '../lib/validation/parser/parse.js';
|
|
14
15
|
import '../lib/validation/syntaxes/complex-selector.js';
|
|
16
|
+
import '../lib/validation/syntax.js';
|
|
15
17
|
import { dirname, resolve } from '../lib/fs/resolve.js';
|
|
16
18
|
import { load } from './load.js';
|
|
17
19
|
|
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": "v1.1.0",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/node/index.js",
|
|
7
7
|
"./node": "./dist/node/index.js",
|
|
@@ -17,9 +17,10 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "rollup -c;./build.sh dist/index.d.ts 'declare interface' 'declare type'",
|
|
19
19
|
"test": "web-test-runner \"test/**/web.spec.js\" --node-resolve --playwright --browsers chromium firefox webkit --root-dir=.; mocha --reporter-options='maxDiffSize=1801920' \"test/**/node.spec.js\"",
|
|
20
|
+
"test:web": "web-test-runner \"test/**/web.spec.js\" --node-resolve --playwright --browsers chromium firefox webkit --root-dir=.",
|
|
20
21
|
"test:node": "mocha --reporter-options='maxDiffSize=1801920' \"test/**/node.spec.js\"",
|
|
21
|
-
"test:cov": "c8 -x dist/lib/validation/syntax.js -x 'dist/lib/validation/parser/*.js' --reporter=html --reporter=text --reporter=json-summary mocha --reporter-options='maxDiffSize=1801920' \"test/**/node.spec.js\"",
|
|
22
|
-
"test:web-cov": "web-test-runner -x dist/lib/validation/syntax.js,dist/lib/validation/parser \"test/**/web.spec.js\" --node-resolve --playwright --browsers chromium firefox webkit --root-dir=. --coverage",
|
|
22
|
+
"test:cov": "c8 -x 'test/specs/**/*.js' -x dist/lib/validation/syntax.js -x 'dist/lib/validation/parser/*.js' --reporter=html --reporter=text --reporter=json-summary mocha --reporter-options='maxDiffSize=1801920' \"test/**/node.spec.js\"",
|
|
23
|
+
"test:web-cov": "web-test-runner -x 'test/specs/**/*.js' -x dist/lib/validation/syntax.js,dist/lib/validation/parser \"test/**/web.spec.js\" --node-resolve --playwright --browsers chromium firefox webkit --root-dir=. --coverage",
|
|
23
24
|
"profile": "node --enable-source-maps --inspect-brk test/inspect.js",
|
|
24
25
|
"syntax-update": "esno tools/validation.ts",
|
|
25
26
|
"debug": "web-test-runner \"test/**/web.spec.js\" --manual --open --node-resolve --root-dir=."
|
|
@@ -51,22 +52,22 @@
|
|
|
51
52
|
"homepage": "https://github.com/tbela99/css-parser#readme",
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@esm-bundle/chai": "^4.3.4-fix.0",
|
|
54
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
55
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
55
56
|
"@rollup/plugin-json": "^6.1.0",
|
|
56
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
57
|
-
"@rollup/plugin-typescript": "^12.1.
|
|
58
|
-
"@types/chai": "^5.
|
|
57
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
58
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
59
|
+
"@types/chai": "^5.2.2",
|
|
59
60
|
"@types/mocha": "^10.0.10",
|
|
60
|
-
"@types/node": "^
|
|
61
|
-
"@types/web": "^0.0.
|
|
62
|
-
"@web/test-runner": "^0.20.
|
|
63
|
-
"@web/test-runner-playwright": "^0.11.
|
|
61
|
+
"@types/node": "^24.0.10",
|
|
62
|
+
"@types/web": "^0.0.245",
|
|
63
|
+
"@web/test-runner": "^0.20.2",
|
|
64
|
+
"@web/test-runner-playwright": "^0.11.1",
|
|
64
65
|
"c8": "^10.1.3",
|
|
65
66
|
"esno": "^4.8.0",
|
|
66
|
-
"mocha": "^11.1
|
|
67
|
-
"playwright": "^1.
|
|
68
|
-
"rollup": "^4.
|
|
69
|
-
"rollup-plugin-dts": "^6.
|
|
67
|
+
"mocha": "^11.7.1",
|
|
68
|
+
"playwright": "^1.53.2",
|
|
69
|
+
"rollup": "^4.44.2",
|
|
70
|
+
"rollup-plugin-dts": "^6.2.1",
|
|
70
71
|
"tslib": "^2.8.1"
|
|
71
72
|
}
|
|
72
73
|
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { srgb2xyz } from './xyz.js';
|
|
2
|
-
import { XYZ_D65_to_D50, xyzd502srgb } from './xyzd50.js';
|
|
3
|
-
|
|
4
|
-
function prophotorgb2srgbvalues(r, g, b, a = null) {
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
return xyzd502srgb(...prophotorgb2xyz50(r, g, b, a));
|
|
7
|
-
}
|
|
8
|
-
function srgb2prophotorgbvalues(r, g, b, a) {
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
return xyz50_to_prophotorgb(...XYZ_D65_to_D50(...srgb2xyz(r, g, b, a)));
|
|
11
|
-
}
|
|
12
|
-
function prophotorgb2lin_ProPhoto(r, g, b, a = null) {
|
|
13
|
-
return [r, g, b].map(v => {
|
|
14
|
-
let abs = Math.abs(v);
|
|
15
|
-
if (abs >= 16 / 512) {
|
|
16
|
-
return Math.sign(v) * Math.pow(abs, 1.8);
|
|
17
|
-
}
|
|
18
|
-
return v / 16;
|
|
19
|
-
}).concat(a == null || a == 1 ? [] : [a]);
|
|
20
|
-
}
|
|
21
|
-
function prophotorgb2xyz50(r, g, b, a = null) {
|
|
22
|
-
[r, g, b, a] = prophotorgb2lin_ProPhoto(r, g, b, a);
|
|
23
|
-
const xyz = [
|
|
24
|
-
0.7977666449006423 * r +
|
|
25
|
-
0.1351812974005331 * g +
|
|
26
|
-
0.0313477341283922 * b,
|
|
27
|
-
0.2880748288194013 * r +
|
|
28
|
-
0.7118352342418731 * g +
|
|
29
|
-
0.0000899369387256 * b,
|
|
30
|
-
0.8251046025104602 * b
|
|
31
|
-
];
|
|
32
|
-
return xyz.concat(a == null || a == 1 ? [] : [a]);
|
|
33
|
-
}
|
|
34
|
-
function xyz50_to_prophotorgb(x, y, z, a) {
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
return gam_prophotorgb(...[
|
|
37
|
-
x * 1.3457868816471585 -
|
|
38
|
-
y * 0.2555720873797946 -
|
|
39
|
-
0.0511018649755453 * z,
|
|
40
|
-
x * -0.5446307051249019 +
|
|
41
|
-
y * 1.5082477428451466 +
|
|
42
|
-
0.0205274474364214 * z,
|
|
43
|
-
1.2119675456389452 * z
|
|
44
|
-
].concat(a == null || a == 1 ? [] : [a]));
|
|
45
|
-
}
|
|
46
|
-
function gam_prophotorgb(r, g, b, a) {
|
|
47
|
-
return [r, g, b].map(v => {
|
|
48
|
-
let abs = Math.abs(v);
|
|
49
|
-
if (abs >= 1 / 512) {
|
|
50
|
-
return Math.sign(v) * Math.pow(abs, 1 / 1.8);
|
|
51
|
-
}
|
|
52
|
-
return 16 * v;
|
|
53
|
-
}).concat(a == null || a == 1 ? [] : [a]);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export { prophotorgb2srgbvalues, srgb2prophotorgbvalues };
|
|
@@ -1,94 +0,0 @@
|
|
|
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 { getSyntaxConfig, getParsedSyntax } 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
|
-
if (syntax != null) {
|
|
27
|
-
if (!('chi' in syntax)) {
|
|
28
|
-
return {
|
|
29
|
-
valid: ValidationLevel.Drop,
|
|
30
|
-
node: declaration,
|
|
31
|
-
syntax,
|
|
32
|
-
error: 'declaration not allowed here'
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
if (name.startsWith('--')) {
|
|
36
|
-
return {
|
|
37
|
-
valid: ValidationLevel.Valid,
|
|
38
|
-
node: declaration,
|
|
39
|
-
syntax: null,
|
|
40
|
-
error: ''
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
// console.error({syntax});
|
|
44
|
-
const config = getSyntaxConfig();
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
const obj = config["atRules" /* ValidationSyntaxGroupEnum.AtRules */]['@' + root.nam];
|
|
47
|
-
if ('descriptors' in obj) {
|
|
48
|
-
const descriptors = obj.descriptors;
|
|
49
|
-
if (!(name in descriptors)) {
|
|
50
|
-
return {
|
|
51
|
-
valid: ValidationLevel.Drop,
|
|
52
|
-
node: declaration,
|
|
53
|
-
syntax: `<${declaration.nam}>`,
|
|
54
|
-
error: `declaration <${declaration.nam}> is not allowed in <@${root.nam}>`
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
const syntax = getParsedSyntax("atRules" /* ValidationSyntaxGroupEnum.AtRules */, ['@' + root.nam, 'descriptors', name]);
|
|
58
|
-
return validateSyntax(syntax, declaration.val, root, options);
|
|
59
|
-
}
|
|
60
|
-
// console.error({name});
|
|
61
|
-
// if (!(name in config.declarations) && !(name in config.syntaxes)) {
|
|
62
|
-
//
|
|
63
|
-
// return {
|
|
64
|
-
//
|
|
65
|
-
// valid: ValidationLevel.Drop,
|
|
66
|
-
// node: declaration,
|
|
67
|
-
// syntax: null,
|
|
68
|
-
// error: `unknown declaration "${declaration.nam}"`
|
|
69
|
-
// }
|
|
70
|
-
// }
|
|
71
|
-
//
|
|
72
|
-
// return validateSyntax((syntax as ValidationAtRuleDefinitionToken).chi as ValidationToken[], [declaration], root, options);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (name.startsWith('--')) {
|
|
76
|
-
return {
|
|
77
|
-
valid: ValidationLevel.Valid,
|
|
78
|
-
node: declaration,
|
|
79
|
-
syntax: null,
|
|
80
|
-
error: ''
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
if (!(name in config.declarations) && !(name in config.syntaxes)) {
|
|
84
|
-
return {
|
|
85
|
-
valid: ValidationLevel.Drop,
|
|
86
|
-
node: declaration,
|
|
87
|
-
syntax: `<${declaration.nam}>`,
|
|
88
|
-
error: `unknown declaration "${declaration.nam}"`
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
return validateSyntax(getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, name), declaration.val);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export { validateDeclaration };
|
|
@@ -1,29 +0,0 @@
|
|
|
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 { validateSyntax } from '../syntax.js';
|
|
9
|
-
import { getParsedSyntax } from '../config.js';
|
|
10
|
-
import { validateURL } from './url.js';
|
|
11
|
-
|
|
12
|
-
function validateImage(token) {
|
|
13
|
-
if (token.typ == EnumToken.UrlFunctionTokenType) {
|
|
14
|
-
return validateURL(token);
|
|
15
|
-
}
|
|
16
|
-
if (token.typ == EnumToken.ImageFunctionTokenType) {
|
|
17
|
-
return validateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, token.val + '()'), token.chi);
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
valid: ValidationLevel.Drop,
|
|
21
|
-
matches: [],
|
|
22
|
-
node: token,
|
|
23
|
-
syntax: 'image()',
|
|
24
|
-
error: 'expected <image> or <url>',
|
|
25
|
-
tokens: []
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { validateImage };
|