@tbela99/css-parser 1.4.1 → 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 +168 -4
- package/README.md +82 -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 +24393 -18479
- package/dist/index.cjs +27430 -21519
- package/dist/index.d.ts +1403 -933
- 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 +543 -215
- 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 +53 -47
- package/dist/web.d.ts +169 -0
- package/dist/web.js +50 -41
- package/package.json +18 -13
- 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,14 +1,8 @@
|
|
|
1
1
|
import { convertColor, getNumber } from './color.js';
|
|
2
2
|
import { ColorType, EnumToken } from '../../ast/types.js';
|
|
3
|
-
import '../../ast/minify.js';
|
|
4
3
|
import { walkValues } from '../../ast/walk.js';
|
|
5
|
-
import '../../parser/parse.js';
|
|
6
|
-
import '../../parser/tokenize.js';
|
|
7
|
-
import '../../parser/utils/config.js';
|
|
8
|
-
import { mathFuncs } from '../syntax.js';
|
|
9
|
-
import { colorRange } from './utils/constants.js';
|
|
10
4
|
import { evaluateFunc, evaluate } from '../../ast/math/expression.js';
|
|
11
|
-
import '
|
|
5
|
+
import { colorRange, mathFuncs } from '../constants.js';
|
|
12
6
|
|
|
13
7
|
function parseRelativeColor(relativeKeys, original, rExp, gExp, bExp, aExp) {
|
|
14
8
|
let r;
|
|
@@ -18,88 +12,121 @@ function parseRelativeColor(relativeKeys, original, rExp, gExp, bExp, aExp) {
|
|
|
18
12
|
let keys = {};
|
|
19
13
|
let values = {};
|
|
20
14
|
// colorFuncColorSpace x,y,z or r,g,b
|
|
21
|
-
const names = relativeKeys.startsWith(
|
|
22
|
-
|
|
15
|
+
const names = relativeKeys.startsWith("xyz")
|
|
16
|
+
? "xyz"
|
|
17
|
+
: ["srgb", "srgb-linear", "display-p3", "a98-rgb", "prophoto-rgb", "rec2020", "rgb"].includes(relativeKeys.toLowerCase())
|
|
18
|
+
? "rgb"
|
|
19
|
+
: relativeKeys.slice(-3);
|
|
20
|
+
const converted = (convertColor(original, ColorType[relativeKeys.toUpperCase().replaceAll("-", "_")]));
|
|
23
21
|
if (converted == null) {
|
|
24
22
|
return null;
|
|
25
23
|
}
|
|
26
|
-
const children = converted.chi.filter(t => ![EnumToken.WhitespaceTokenType, EnumToken.LiteralTokenType, EnumToken.CommentTokenType].includes(t.typ));
|
|
24
|
+
const children = converted.chi.filter((t) => ![EnumToken.WhitespaceTokenType, EnumToken.LiteralTokenType, EnumToken.CommentTokenType].includes(t.typ));
|
|
27
25
|
[r, g, b, alpha] = converted.kin == ColorType.COLOR ? children.slice(1) : children;
|
|
28
26
|
values = {
|
|
29
27
|
[names[0]]: getValue(r, converted, names[0]),
|
|
30
28
|
[names[1]]: getValue(g, converted, names[1]), // string,
|
|
31
29
|
[names[2]]: getValue(b, converted, names[2]),
|
|
32
30
|
// @ts-ignore
|
|
33
|
-
alpha: alpha == null
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
alpha: alpha == null
|
|
32
|
+
? {
|
|
33
|
+
typ: EnumToken.NumberTokenType,
|
|
34
|
+
val: 1,
|
|
35
|
+
}
|
|
36
|
+
: alpha.typ == EnumToken.IdenTokenType && alpha.val == "none"
|
|
37
|
+
? {
|
|
38
|
+
typ: EnumToken.NumberTokenType,
|
|
39
|
+
val: 0,
|
|
40
|
+
}
|
|
41
|
+
: alpha.typ == EnumToken.PercentageTokenType
|
|
42
|
+
? {
|
|
43
|
+
typ: EnumToken.NumberTokenType,
|
|
44
|
+
val: getNumber(alpha),
|
|
45
|
+
}
|
|
46
|
+
: alpha,
|
|
43
47
|
};
|
|
44
48
|
keys = {
|
|
45
49
|
[names[0]]: getValue(rExp, converted, names[0]),
|
|
46
50
|
[names[1]]: getValue(gExp, converted, names[1]),
|
|
47
51
|
[names[2]]: getValue(bExp, converted, names[2]),
|
|
48
52
|
// @ts-ignore
|
|
49
|
-
alpha: getValue(aExp == null
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
alpha: getValue(aExp == null
|
|
54
|
+
? {
|
|
55
|
+
typ: EnumToken.NumberTokenType,
|
|
56
|
+
val: 1,
|
|
57
|
+
}
|
|
58
|
+
: aExp.typ == EnumToken.IdenTokenType && aExp.val == "none"
|
|
59
|
+
? {
|
|
60
|
+
typ: EnumToken.NumberTokenType,
|
|
61
|
+
val: 0,
|
|
62
|
+
}
|
|
63
|
+
: aExp),
|
|
56
64
|
};
|
|
57
|
-
|
|
65
|
+
const result = computeComponentValue(keys, converted, values);
|
|
66
|
+
if (result?.alpha?.typ == EnumToken.NumberTokenType && result.alpha.val === 1) {
|
|
67
|
+
const { alpha, ...components } = result;
|
|
68
|
+
return components;
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
// return computeComponentValue(keys, converted, values);
|
|
58
72
|
}
|
|
59
73
|
function getValue(t, converted, component) {
|
|
60
74
|
if (t.typ == EnumToken.PercentageTokenType) {
|
|
61
75
|
let value = getNumber(t);
|
|
62
|
-
let colorSpace = ColorType[converted.kin].toLowerCase().replaceAll(
|
|
76
|
+
let colorSpace = ColorType[converted.kin].toLowerCase().replaceAll("-", "_");
|
|
63
77
|
if (colorSpace in colorRange) {
|
|
64
78
|
// @ts-ignore
|
|
65
79
|
value *= colorRange[colorSpace][component].at(-1);
|
|
66
80
|
}
|
|
67
81
|
return {
|
|
68
82
|
typ: EnumToken.NumberTokenType,
|
|
69
|
-
val: value
|
|
83
|
+
val: value,
|
|
70
84
|
};
|
|
71
85
|
}
|
|
72
86
|
return t;
|
|
73
87
|
}
|
|
74
88
|
function computeComponentValue(expr, converted, values) {
|
|
75
89
|
for (const object of [values, expr]) {
|
|
76
|
-
if (
|
|
90
|
+
if ("h" in object) {
|
|
77
91
|
// normalize hue
|
|
78
92
|
for (const k of walkValues([object.h])) {
|
|
79
|
-
if (k.value.typ == EnumToken.AngleTokenType && k.value.unit ==
|
|
93
|
+
if (k.value.typ == EnumToken.AngleTokenType && k.value.unit == "deg") {
|
|
80
94
|
k.value.typ = EnumToken.NumberTokenType;
|
|
81
95
|
}
|
|
82
96
|
}
|
|
83
97
|
}
|
|
84
98
|
}
|
|
85
99
|
for (const [key, exp] of Object.entries(expr)) {
|
|
86
|
-
if ([
|
|
100
|
+
if ([
|
|
101
|
+
EnumToken.NumberTokenType,
|
|
102
|
+
EnumToken.PercentageTokenType,
|
|
103
|
+
EnumToken.AngleTokenType,
|
|
104
|
+
EnumToken.LengthTokenType,
|
|
105
|
+
].includes(exp.typ)) ;
|
|
87
106
|
else if (exp.typ == EnumToken.IdenTokenType && exp.val in values) {
|
|
88
107
|
expr[key] = values[exp.val];
|
|
89
108
|
}
|
|
90
|
-
else if (exp.typ == EnumToken.
|
|
109
|
+
else if (exp.typ == EnumToken.MathFunctionTokenType ||
|
|
110
|
+
(exp.typ == EnumToken.FunctionTokenType && mathFuncs.includes(exp.val))) {
|
|
91
111
|
for (let { value, parent } of walkValues(exp.chi, exp)) {
|
|
92
112
|
if (value.typ == EnumToken.IdenTokenType) {
|
|
93
113
|
// @ts-ignore
|
|
94
|
-
replaceValue(parent, value,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
114
|
+
replaceValue(parent, value,
|
|
115
|
+
// @ts-expect-error
|
|
116
|
+
values[value.val] ??
|
|
117
|
+
{
|
|
118
|
+
typ: EnumToken.NumberTokenType,
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
val: "" + Math[value.val.toUpperCase()],
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
});
|
|
100
123
|
}
|
|
101
124
|
}
|
|
102
|
-
const result = exp.typ
|
|
125
|
+
const result = (exp.typ === EnumToken.MathFunctionTokenType ||
|
|
126
|
+
(exp.typ == EnumToken.FunctionTokenType && mathFuncs.includes(exp.val))) &&
|
|
127
|
+
exp.val !== "calc"
|
|
128
|
+
? evaluateFunc(exp)
|
|
129
|
+
: evaluate(exp.chi);
|
|
103
130
|
if (result.length == 1 && result[0].typ != EnumToken.BinaryExpressionTokenType) {
|
|
104
131
|
expr[key] = result[0];
|
|
105
132
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ColorToken } from "../../../@types/index.d.ts";
|
|
2
|
+
export declare function srgb2rgb(value: number): number;
|
|
3
|
+
export declare function hex2RgbToken(token: ColorToken): ColorToken | null;
|
|
4
|
+
export declare function hsl2RgbToken(token: ColorToken): ColorToken | null;
|
|
5
|
+
export declare function hwb2RgbToken(token: ColorToken): ColorToken | null;
|
|
6
|
+
export declare function cmyk2RgbToken(token: ColorToken): ColorToken | null;
|
|
7
|
+
export declare function oklab2RgbToken(token: ColorToken): ColorToken | null;
|
|
8
|
+
export declare function oklch2RgbToken(token: ColorToken): ColorToken | null;
|
|
9
|
+
export declare function lab2RgbToken(token: ColorToken): ColorToken | null;
|
|
10
|
+
export declare function lch2RgbToken(token: ColorToken): ColorToken | null;
|
|
11
|
+
export declare function color2RgbToken(token: ColorToken): ColorToken | null;
|
|
12
|
+
export declare function hex2rgbvalues(token: ColorToken): number[];
|
|
13
|
+
export declare function hwb2rgbvalues(token: ColorToken): number[] | null;
|
|
14
|
+
export declare function hsl2rgbvalues(token: ColorToken): number[] | null;
|
|
15
|
+
export declare function hsl2srgbvalues(token: ColorToken): number[] | null;
|
|
16
|
+
export declare function cmyk2rgbvalues(token: ColorToken): number[] | null;
|
|
17
|
+
export declare function oklab2rgbvalues(token: ColorToken): number[] | null;
|
|
18
|
+
export declare function oklch2rgbvalues(token: ColorToken): number[] | null;
|
|
19
|
+
export declare function lab2rgbvalues(token: ColorToken): number[] | null;
|
|
20
|
+
export declare function lch2rgbvalues(token: ColorToken): number[] | null;
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { color2srgbvalues, minmax } from './color.js';
|
|
2
|
-
import { COLORS_NAMES } from './utils/constants.js';
|
|
3
|
-
import { EnumToken, ColorType } 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
2
|
import { expandHexValue } from './hex.js';
|
|
10
3
|
import { hslvalues, hslvalues2srgbvalues, lch2srgbvalues, lab2srgbvalues, oklch2srgbvalues, oklab2srgbvalues, cmyk2srgbvalues, hwb2srgbvalues } from './srgb.js';
|
|
11
|
-
import '../../
|
|
4
|
+
import { EnumToken, ColorType } from '../../ast/types.js';
|
|
5
|
+
import { COLORS_NAMES } from '../constants.js';
|
|
12
6
|
|
|
13
7
|
function srgb2rgb(value) {
|
|
14
8
|
return minmax(Math.round(value * 255), 0, 255);
|
|
@@ -70,7 +64,7 @@ function color2RgbToken(token) {
|
|
|
70
64
|
if (values == null) {
|
|
71
65
|
return null;
|
|
72
66
|
}
|
|
73
|
-
return rgb2RgbToken(values.map((t, index) => index == 3 ? t : srgb2rgb(t)));
|
|
67
|
+
return rgb2RgbToken(values.map((t, index) => (index == 3 ? t : srgb2rgb(t))));
|
|
74
68
|
}
|
|
75
69
|
function rgb2RgbToken(values) {
|
|
76
70
|
const chi = [
|
|
@@ -83,9 +77,9 @@ function rgb2RgbToken(values) {
|
|
|
83
77
|
}
|
|
84
78
|
return {
|
|
85
79
|
typ: EnumToken.ColorTokenType,
|
|
86
|
-
val:
|
|
80
|
+
val: "rgb",
|
|
87
81
|
chi,
|
|
88
|
-
kin: ColorType.RGB
|
|
82
|
+
kin: ColorType.RGB,
|
|
89
83
|
};
|
|
90
84
|
}
|
|
91
85
|
function hex2rgbvalues(token) {
|
|
@@ -105,14 +99,16 @@ function hex2rgbvalues(token) {
|
|
|
105
99
|
return rgb;
|
|
106
100
|
}
|
|
107
101
|
function hwb2rgbvalues(token) {
|
|
108
|
-
return hwb2srgbvalues(token)?.map?.((t, index) => index == 3 ? t : srgb2rgb(t)) ?? null;
|
|
102
|
+
return hwb2srgbvalues(token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
|
|
109
103
|
}
|
|
110
104
|
function hsl2rgbvalues(token) {
|
|
111
105
|
let { h, s, l, a } = hslvalues(token) ?? {};
|
|
112
106
|
if (h == null || s == null || l == null) {
|
|
113
107
|
return null;
|
|
114
108
|
}
|
|
115
|
-
return hslvalues2srgbvalues(h, s, l)
|
|
109
|
+
return hslvalues2srgbvalues(h, s, l)
|
|
110
|
+
.map((t) => minmax(Math.round(t * 255), 0, 255))
|
|
111
|
+
.concat(a == 1 || a == null ? [] : [a]);
|
|
116
112
|
}
|
|
117
113
|
function hsl2srgbvalues(token) {
|
|
118
114
|
let { h, s, l, a } = hslvalues(token) ?? {};
|
|
@@ -122,19 +118,19 @@ function hsl2srgbvalues(token) {
|
|
|
122
118
|
return hslvalues2srgbvalues(h, s, l).concat(a == 1 || a == null ? [] : [a]);
|
|
123
119
|
}
|
|
124
120
|
function cmyk2rgbvalues(token) {
|
|
125
|
-
return cmyk2srgbvalues(token)?.map?.((t, index) => index == 3 ? t : srgb2rgb(t)) ?? null;
|
|
121
|
+
return cmyk2srgbvalues(token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
|
|
126
122
|
}
|
|
127
123
|
function oklab2rgbvalues(token) {
|
|
128
|
-
return oklab2srgbvalues(token)?.map?.((t, index) => index == 3 ? t : srgb2rgb(t)) ?? null;
|
|
124
|
+
return oklab2srgbvalues(token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
|
|
129
125
|
}
|
|
130
126
|
function oklch2rgbvalues(token) {
|
|
131
|
-
return oklch2srgbvalues(token)?.map?.((t, index) => index == 3 ? t : srgb2rgb(t)) ?? null;
|
|
127
|
+
return oklch2srgbvalues(token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
|
|
132
128
|
}
|
|
133
129
|
function lab2rgbvalues(token) {
|
|
134
|
-
return lab2srgbvalues(token)?.map?.((t, index) => index == 3 ? t : srgb2rgb(t)) ?? null;
|
|
130
|
+
return lab2srgbvalues(token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
|
|
135
131
|
}
|
|
136
132
|
function lch2rgbvalues(token) {
|
|
137
|
-
return lch2srgbvalues(token)?.map?.((t, index) => index == 3 ? t : srgb2rgb(t)) ?? null;
|
|
133
|
+
return lch2srgbvalues(token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
|
|
138
134
|
}
|
|
139
135
|
|
|
140
136
|
export { cmyk2RgbToken, cmyk2rgbvalues, color2RgbToken, hex2RgbToken, hex2rgbvalues, hsl2RgbToken, hsl2rgbvalues, hsl2srgbvalues, hwb2RgbToken, hwb2rgbvalues, lab2RgbToken, lab2rgbvalues, lch2RgbToken, lch2rgbvalues, oklab2RgbToken, oklab2rgbvalues, oklch2RgbToken, oklch2rgbvalues, srgb2rgb };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ColorToken, IdentToken } from "../../../@types/index.d.ts";
|
|
2
|
+
export declare function srgbvalues(token: ColorToken | IdentToken): number[] | null;
|
|
3
|
+
export declare function rgb2srgb(token: ColorToken): number[] | null;
|
|
4
|
+
export declare function rgb2srgbvalues(token: ColorToken): number[] | null;
|
|
5
|
+
export declare function rgbvalues2srgbvalues(r: number, g: number, b: number, a?: number | null): number[] | null;
|
|
6
|
+
export declare function hex2srgbvalues(token: ColorToken): number[];
|
|
7
|
+
export declare function xyz2srgb(x: number, y: number, z: number, alpha?: number | null): number[];
|
|
8
|
+
export declare function hwb2srgbvalues(token: ColorToken): number[] | null;
|
|
9
|
+
export declare function hsl2srgb(token: ColorToken): number[] | null;
|
|
10
|
+
export declare function cmyk2srgbvalues(token: ColorToken): number[] | null;
|
|
11
|
+
export declare function oklab2srgbvalues(token: ColorToken): number[] | null;
|
|
12
|
+
export declare function oklch2srgbvalues(token: ColorToken): number[] | null;
|
|
13
|
+
export declare function hslvalues(token: ColorToken): {
|
|
14
|
+
h: number;
|
|
15
|
+
s: number;
|
|
16
|
+
l: number;
|
|
17
|
+
a?: number | null;
|
|
18
|
+
} | null;
|
|
19
|
+
export declare function hslvalues2srgbvalues(h: number, s: number, l: number, a?: number | null): number[];
|
|
20
|
+
export declare function lab2srgbvalues(token: ColorToken): number[] | null;
|
|
21
|
+
export declare function lch2srgbvalues(token: ColorToken): number[] | null;
|
|
22
|
+
export declare function srgb2lsrgbvalues(r: number, g: number, b: number, a?: number | null): number[];
|
|
23
|
+
export declare function lsrgb2srgbvalues(r: number, g: number, b: number, alpha?: number | null): number[];
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import { COLORS_NAMES } from './utils/constants.js';
|
|
2
1
|
import { getComponents } from './utils/components.js';
|
|
3
2
|
import { color2srgbvalues, getNumber, getAngle } from './color.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import '../../ast/minify.js';
|
|
7
|
-
import '../../ast/walk.js';
|
|
8
|
-
import '../../parser/parse.js';
|
|
9
|
-
import '../../parser/tokenize.js';
|
|
10
|
-
import '../../parser/utils/config.js';
|
|
3
|
+
import { EnumToken, ColorType } from '../../ast/types.js';
|
|
4
|
+
import { Lab_to_sRGB, getLABComponents, lchvalues2labvalues } from './lab.js';
|
|
11
5
|
import { expandHexValue } from './hex.js';
|
|
12
|
-
import {
|
|
6
|
+
import { OKLab_to_sRGB, getOKLABComponents } from './oklab.js';
|
|
13
7
|
import { getLCHComponents } from './lch.js';
|
|
14
8
|
import { getOKLCHComponents } from './oklch.js';
|
|
15
9
|
import { XYZ_to_lin_sRGB } from './xyz.js';
|
|
16
|
-
import '
|
|
10
|
+
import { COLORS_NAMES } from '../constants.js';
|
|
11
|
+
import { parseColor } from '../syntax.js';
|
|
17
12
|
|
|
18
13
|
// from https://www.w3.org/TR/css-color-4/#color-conversion-code
|
|
19
14
|
// srgb-linear -> srgb
|
|
20
15
|
// 0 <= r, g, b <= 1
|
|
21
16
|
function srgbvalues(token) {
|
|
17
|
+
if (token.typ === EnumToken.IdenTokenType) {
|
|
18
|
+
token = parseColor(token);
|
|
19
|
+
}
|
|
22
20
|
switch (token.kin) {
|
|
23
21
|
case ColorType.LIT:
|
|
24
22
|
case ColorType.HEX:
|
|
@@ -45,10 +43,18 @@ function srgbvalues(token) {
|
|
|
45
43
|
return null;
|
|
46
44
|
}
|
|
47
45
|
function rgb2srgb(token) {
|
|
48
|
-
return getComponents(token)?.map?.((t, index) => index == 3
|
|
46
|
+
return (getComponents(token)?.map?.((t, index) => index == 3
|
|
47
|
+
? t.typ == EnumToken.IdenTokenType && t.val == "none"
|
|
48
|
+
? 1
|
|
49
|
+
: getNumber(t)
|
|
50
|
+
: ((t.typ == EnumToken.PercentageTokenType ? 255 : 1) *
|
|
51
|
+
getNumber(t)) /
|
|
52
|
+
255) ?? null);
|
|
49
53
|
}
|
|
50
54
|
function rgb2srgbvalues(token) {
|
|
51
|
-
return getComponents(token)?.map?.((t, index) => index == 3
|
|
55
|
+
return (getComponents(token)?.map?.((t, index) => index == 3
|
|
56
|
+
? getNumber(t)
|
|
57
|
+
: getNumber(t) / 255) ?? null);
|
|
52
58
|
}
|
|
53
59
|
function hex2srgbvalues(token) {
|
|
54
60
|
const value = expandHexValue(token.kin == ColorType.LIT ? COLORS_NAMES[token.val.toLowerCase()] : token.val);
|
|
@@ -71,9 +77,9 @@ function hwb2srgbvalues(token) {
|
|
|
71
77
|
if (hue == null || white == null || black == null) {
|
|
72
78
|
return [];
|
|
73
79
|
}
|
|
74
|
-
const rgb = hslvalues2srgbvalues(hue, 1, .5);
|
|
80
|
+
const rgb = hslvalues2srgbvalues(hue, 1, 0.5);
|
|
75
81
|
for (let i = 0; i < 3; i++) {
|
|
76
|
-
rgb[i] *=
|
|
82
|
+
rgb[i] *= 1 - white - black;
|
|
77
83
|
rgb[i] = rgb[i] + white;
|
|
78
84
|
}
|
|
79
85
|
if (alpha != null && alpha != 1) {
|
|
@@ -112,20 +118,11 @@ function cmyk2srgbvalues(token) {
|
|
|
112
118
|
const rgb = [
|
|
113
119
|
1 - Math.min(1, c * (1 - k) + k),
|
|
114
120
|
1 - Math.min(1, m * (1 - k) + k),
|
|
115
|
-
1 - Math.min(1, y * (1 - k) + k)
|
|
121
|
+
1 - Math.min(1, y * (1 - k) + k),
|
|
116
122
|
];
|
|
117
123
|
if (components.length == 5) {
|
|
118
124
|
rgb.push(getNumber(components[4]));
|
|
119
125
|
}
|
|
120
|
-
// @ts-ignore
|
|
121
|
-
// if (token.chi.length >= 9) {
|
|
122
|
-
//
|
|
123
|
-
// // @ts-ignore
|
|
124
|
-
// t = <NumberToken | PercentageToken>token.chi[8];
|
|
125
|
-
//
|
|
126
|
-
// // @ts-ignore
|
|
127
|
-
// rgb.push(getNumber(t));
|
|
128
|
-
// }
|
|
129
126
|
return rgb;
|
|
130
127
|
}
|
|
131
128
|
function oklab2srgbvalues(token) {
|
|
@@ -177,7 +174,7 @@ function hslvalues(token) {
|
|
|
177
174
|
return a == null ? { h, s, l } : { h, s, l, a };
|
|
178
175
|
}
|
|
179
176
|
function hslvalues2srgbvalues(h, s, l, a = null) {
|
|
180
|
-
let v = l <= .5 ? l * (1.0 + s) : l + s - l * s;
|
|
177
|
+
let v = l <= 0.5 ? l * (1.0 + s) : l + s - l * s;
|
|
181
178
|
let r = l;
|
|
182
179
|
let g = l;
|
|
183
180
|
let b = l;
|
|
@@ -241,8 +238,12 @@ function lab2srgbvalues(token) {
|
|
|
241
238
|
return rgb;
|
|
242
239
|
}
|
|
243
240
|
function lch2srgbvalues(token) {
|
|
241
|
+
const components = getLCHComponents(token);
|
|
242
|
+
if (components == null) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
244
245
|
// @ts-ignore
|
|
245
|
-
const [l, a, b, alpha] = lchvalues2labvalues(...
|
|
246
|
+
const [l, a, b, alpha] = lchvalues2labvalues(...components);
|
|
246
247
|
if (l == null || a == null || b == null) {
|
|
247
248
|
return null;
|
|
248
249
|
}
|
|
@@ -1,41 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '../../../ast/minify.js';
|
|
1
|
+
import { EnumToken, ColorType } from '../../../ast/types.js';
|
|
3
2
|
import { walkValues } from '../../../ast/walk.js';
|
|
4
|
-
import '
|
|
5
|
-
import '../../../parser/tokenize.js';
|
|
6
|
-
import '../../../parser/utils/config.js';
|
|
7
|
-
import { COLORS_NAMES } from './constants.js';
|
|
3
|
+
import { COLORS_NAMES } from '../../constants.js';
|
|
8
4
|
import { expandHexValue } from '../hex.js';
|
|
9
|
-
import '
|
|
5
|
+
import { isColor, parseColor } from '../../syntax.js';
|
|
10
6
|
|
|
11
7
|
function getComponents(token) {
|
|
8
|
+
if (token.typ === EnumToken.IdenTokenType) {
|
|
9
|
+
if (isColor(token)) {
|
|
10
|
+
parseColor(token);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
12
16
|
if (token.kin == ColorType.HEX || token.kin == ColorType.LIT) {
|
|
13
17
|
const value = expandHexValue(token.kin == ColorType.LIT ? COLORS_NAMES[token.val.toLowerCase()] : token.val);
|
|
14
18
|
// @ts-ignore
|
|
15
|
-
return value
|
|
19
|
+
return value
|
|
20
|
+
.slice(1)
|
|
21
|
+
.match(/([a-fA-F0-9]{2})/g)
|
|
22
|
+
.map((t, index) => {
|
|
16
23
|
return { typ: EnumToken.Number, val: index < 3 ? parseInt(t, 16) : parseInt(t, 16) / 255 };
|
|
17
24
|
});
|
|
18
25
|
}
|
|
19
26
|
const result = [];
|
|
20
|
-
for (const child of
|
|
27
|
+
for (const child of token.chi) {
|
|
21
28
|
if ([
|
|
22
|
-
EnumToken.LiteralTokenType,
|
|
29
|
+
EnumToken.LiteralTokenType,
|
|
30
|
+
EnumToken.CommentTokenType,
|
|
31
|
+
EnumToken.CommaTokenType,
|
|
32
|
+
EnumToken.WhitespaceTokenType,
|
|
23
33
|
].includes(child.typ)) {
|
|
24
34
|
continue;
|
|
25
35
|
}
|
|
26
|
-
if (child.typ
|
|
27
|
-
|
|
36
|
+
if (child.typ === EnumToken.IdenTokenType && isColor(child)) {
|
|
37
|
+
parseColor(child);
|
|
38
|
+
}
|
|
39
|
+
if (child.typ === EnumToken.FunctionTokenType ||
|
|
40
|
+
child.typ === EnumToken.WildCardFunctionTokenType ||
|
|
41
|
+
child.typ === EnumToken.MathFunctionTokenType) {
|
|
42
|
+
if ("var" == child.val.toLowerCase()) {
|
|
28
43
|
return null;
|
|
29
44
|
}
|
|
30
45
|
else {
|
|
31
46
|
for (const { value } of walkValues(child.chi)) {
|
|
32
|
-
if (value.typ == EnumToken.
|
|
47
|
+
if (value.typ == EnumToken.WildCardFunctionTokenDefType &&
|
|
48
|
+
"var" === value.val.toLowerCase()) {
|
|
33
49
|
return null;
|
|
34
50
|
}
|
|
35
51
|
}
|
|
36
52
|
}
|
|
37
53
|
}
|
|
38
|
-
if (child.typ == EnumToken.ColorTokenType &&
|
|
54
|
+
if (child.typ == EnumToken.ColorTokenType && "currentcolor" === child.val.toLowerCase()) {
|
|
39
55
|
return null;
|
|
40
56
|
}
|
|
41
57
|
result.push(child);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ColorToken } from "../../../../@types/index.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Calculate the distance between two okLab colors.
|
|
4
|
+
* @param okLab1
|
|
5
|
+
* @param okLab2
|
|
6
|
+
*
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
export declare function okLabDistance(okLab1: [number, number, number], okLab2: [number, number, number]): number;
|
|
10
|
+
/**
|
|
11
|
+
* Check if two colors are close in okLab space.
|
|
12
|
+
* @param color1
|
|
13
|
+
* @param color2
|
|
14
|
+
* @param threshold
|
|
15
|
+
*
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
export declare function isOkLabClose(color1: ColorToken, color2: ColorToken, threshold?: number): boolean;
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { convertColor } from '../color.js';
|
|
2
2
|
import { getOKLABComponents } from '../oklab.js';
|
|
3
3
|
import { ColorType } 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 './constants.js';
|
|
10
|
-
import '../../../renderer/sourcemap/lib/encode.js';
|
|
11
4
|
|
|
12
5
|
/**
|
|
13
6
|
* Calculate the distance between two okLab colors.
|
|
@@ -27,7 +20,7 @@ function okLabDistance(okLab1, okLab2) {
|
|
|
27
20
|
*
|
|
28
21
|
* @private
|
|
29
22
|
*/
|
|
30
|
-
function isOkLabClose(color1, color2, threshold = .01) {
|
|
23
|
+
function isOkLabClose(color1, color2, threshold = 0.01) {
|
|
31
24
|
color1 = convertColor(color1, ColorType.OKLAB);
|
|
32
25
|
color2 = convertColor(color2, ColorType.OKLAB);
|
|
33
26
|
if (color1 == null || color2 == null) {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function lab2xyz(l: number, a: number, b: number, alpha?: number): number[];
|
|
2
|
+
export declare function XYZ_to_lin_sRGB(x: number, y: number, z: number, alpha?: number | null): number[];
|
|
3
|
+
export declare function XYZ_D50_to_D65(x: number, y: number, z: number): number[];
|
|
4
|
+
export declare function srgb2xyz(r: number, g: number, b: number, alpha?: number): number[];
|
|
5
|
+
export declare function srgb2xyz_d50(r: number, g: number, b: number, alpha?: number): number[];
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { multiplyMatrices } from './utils/matrix.js';
|
|
2
|
-
import './utils/constants.js';
|
|
3
|
-
import '../../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
2
|
import { srgb2lsrgbvalues } from './srgb.js';
|
|
10
3
|
import { XYZ_D65_to_D50 } from './xyzd50.js';
|
|
11
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
12
4
|
|
|
13
5
|
function XYZ_to_lin_sRGB(x, y, z, alpha = null) {
|
|
14
6
|
// convert XYZ to linear-light sRGB
|
|
@@ -18,32 +10,28 @@ function XYZ_to_lin_sRGB(x, y, z, alpha = null) {
|
|
|
18
10
|
[705 / 12673, -2585 / 12673, 705 / 667],
|
|
19
11
|
];
|
|
20
12
|
const XYZ = [x, y, z]; // convert to XYZ
|
|
21
|
-
return multiplyMatrices(M, XYZ)
|
|
13
|
+
return multiplyMatrices(M, XYZ)
|
|
14
|
+
.map((v) => v)
|
|
15
|
+
.concat(alpha == null || alpha == 1 ? [] : [alpha]);
|
|
22
16
|
}
|
|
23
17
|
function XYZ_D50_to_D65(x, y, z) {
|
|
24
18
|
// Bradford chromatic adaptation from D50 to D65
|
|
25
19
|
const M = [
|
|
26
20
|
[0.9554734527042182, -0.023098536874261423, 0.0632593086610217],
|
|
27
21
|
[-0.028369706963208136, 1.0099954580058226, 0.021041398966943008],
|
|
28
|
-
[0.012314001688319899, -0.020507696433477912, 1.3303659366080753]
|
|
22
|
+
[0.012314001688319899, -0.020507696433477912, 1.3303659366080753],
|
|
29
23
|
];
|
|
30
24
|
const XYZ = [x, y, z];
|
|
31
|
-
return multiplyMatrices(M, XYZ);
|
|
25
|
+
return multiplyMatrices(M, XYZ);
|
|
32
26
|
}
|
|
33
27
|
// xyz d65
|
|
34
28
|
function srgb2xyz(r, g, b, alpha) {
|
|
35
29
|
[r, g, b] = srgb2lsrgbvalues(r, g, b);
|
|
36
30
|
// xyx d65
|
|
37
31
|
let rgb = [
|
|
38
|
-
0.4123907992659595 * r +
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
0.21263900587151036 * r +
|
|
42
|
-
0.7151686787677559 * g +
|
|
43
|
-
0.07219231536073371 * b,
|
|
44
|
-
0.01933081871559185 * r +
|
|
45
|
-
0.11919477979462599 * g +
|
|
46
|
-
0.9505321522496606 * b
|
|
32
|
+
0.4123907992659595 * r + 0.35758433938387796 * g + 0.1804807884018343 * b,
|
|
33
|
+
0.21263900587151036 * r + 0.7151686787677559 * g + 0.07219231536073371 * b,
|
|
34
|
+
0.01933081871559185 * r + 0.11919477979462599 * g + 0.9505321522496606 * b,
|
|
47
35
|
];
|
|
48
36
|
if (alpha != null && alpha != 1) {
|
|
49
37
|
rgb.push(alpha);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function srgb2xyzd50values(r: number, g: number, b: number, alpha?: number | null): number[];
|
|
2
|
+
export declare function xyzd502lch(x: number, y: number, z: number, alpha?: number): number[];
|
|
3
|
+
export declare function XYZ_D65_to_D50(x: number, y: number, z: number, alpha?: number | null): number[];
|
|
4
|
+
export declare function xyzd502srgb(x: number, y: number, z: number, alpha?: number | null): number[];
|