@tbela99/css-parser 1.6.6 → 1.6.7
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 +50 -0
- package/README.md +1 -58
- package/architecture.png +0 -0
- package/dist/index-umd-web.js +605 -410
- package/dist/index.cjs +605 -410
- package/dist/index.d.ts +16 -8
- package/dist/lib/ast/expand.js +12 -10
- package/dist/lib/ast/features/prefix.js +1 -3
- package/dist/lib/ast/features/transform.js +1 -1
- package/dist/lib/ast/types.js +16 -8
- package/dist/lib/ast/walk.js +9 -0
- package/dist/lib/parser/declaration/list.js +17 -8
- package/dist/lib/parser/declaration/map.js +2 -1
- package/dist/lib/parser/parse.js +32 -28
- package/dist/lib/parser/utils/declaration.js +10 -0
- package/dist/lib/printer/render.js +11 -8
- package/dist/lib/syntax/color/color-mix.js +132 -48
- package/dist/lib/syntax/color/color.js +0 -1
- package/dist/lib/syntax/color/hsl.js +45 -38
- package/dist/lib/syntax/color/hsv.js +1 -15
- package/dist/lib/syntax/color/hwb.js +83 -53
- package/dist/lib/syntax/color/oklab.js +1 -1
- package/dist/lib/syntax/color/relative-color.js +29 -0
- package/dist/lib/syntax/color/srgb.js +81 -58
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -27,35 +27,43 @@ exports.EnumAstNodeStatus = void 0;
|
|
|
27
27
|
/**
|
|
28
28
|
* Node passed validation
|
|
29
29
|
*/
|
|
30
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Validated"] =
|
|
30
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Validated"] = 1] = "Validated";
|
|
31
31
|
/**
|
|
32
32
|
* Node is invalid
|
|
33
33
|
*/
|
|
34
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Invalid"] =
|
|
34
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Invalid"] = 2] = "Invalid";
|
|
35
35
|
/**
|
|
36
36
|
* node is not validated
|
|
37
37
|
*/
|
|
38
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Unvalidated"] =
|
|
38
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Unvalidated"] = 4] = "Unvalidated";
|
|
39
39
|
/**
|
|
40
40
|
* Node did not pass validation, but is preserved.
|
|
41
41
|
*/
|
|
42
|
-
EnumAstNodeStatus[EnumAstNodeStatus["ValidationFailed"] =
|
|
42
|
+
EnumAstNodeStatus[EnumAstNodeStatus["ValidationFailed"] = 8] = "ValidationFailed";
|
|
43
43
|
/**
|
|
44
44
|
* Parsing the node is not supported yet or the node syntax definition does not exist.
|
|
45
45
|
*/
|
|
46
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Unknown"] =
|
|
46
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Unknown"] = 16] = "Unknown";
|
|
47
47
|
/**
|
|
48
48
|
* Failed to parse the node.
|
|
49
49
|
*/
|
|
50
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Unparsed"] =
|
|
50
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Unparsed"] = 32] = "Unparsed";
|
|
51
51
|
/**
|
|
52
52
|
* Node is disallowed in the context
|
|
53
53
|
*/
|
|
54
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Disallowed"] =
|
|
54
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Disallowed"] = 64] = "Disallowed";
|
|
55
55
|
/**
|
|
56
56
|
* Node is malformed
|
|
57
57
|
*/
|
|
58
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Malformed"] =
|
|
58
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Malformed"] = 128] = "Malformed";
|
|
59
|
+
/**
|
|
60
|
+
* Important declaration
|
|
61
|
+
*/
|
|
62
|
+
EnumAstNodeStatus[EnumAstNodeStatus["ImportantDeclaration"] = 256] = "ImportantDeclaration";
|
|
63
|
+
/**
|
|
64
|
+
* Color component without unit
|
|
65
|
+
*/
|
|
66
|
+
EnumAstNodeStatus[EnumAstNodeStatus["PowerlessColorComponent"] = 512] = "PowerlessColorComponent";
|
|
59
67
|
})(exports.EnumAstNodeStatus || (exports.EnumAstNodeStatus = {}));
|
|
60
68
|
/**
|
|
61
69
|
* Enum of validation levels
|
|
@@ -7488,7 +7496,7 @@ function oklabToken(values) {
|
|
|
7488
7496
|
{ typ: exports.EnumToken.NumberTokenType, val: values[1] },
|
|
7489
7497
|
{ typ: exports.EnumToken.NumberTokenType, val: values[2] },
|
|
7490
7498
|
];
|
|
7491
|
-
if (values.length == 4) {
|
|
7499
|
+
if (values.length == 4 && values[3] != 1) {
|
|
7492
7500
|
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
|
|
7493
7501
|
typ: exports.EnumToken.PercentageTokenType,
|
|
7494
7502
|
val: values[3] * 100,
|
|
@@ -7877,6 +7885,222 @@ function Lab_to_XYZ(l, a, b) {
|
|
|
7877
7885
|
return xyz.map((value, i) => value * D50[i]);
|
|
7878
7886
|
}
|
|
7879
7887
|
|
|
7888
|
+
function rgb2hwbToken(token) {
|
|
7889
|
+
const values = rgb2hwbvalues(token);
|
|
7890
|
+
if (values == null) {
|
|
7891
|
+
return null;
|
|
7892
|
+
}
|
|
7893
|
+
return hwbToken(values);
|
|
7894
|
+
}
|
|
7895
|
+
function hsl2hwbToken(token) {
|
|
7896
|
+
const values = hsl2hwbvalues(token);
|
|
7897
|
+
if (values == null) {
|
|
7898
|
+
return null;
|
|
7899
|
+
}
|
|
7900
|
+
// console.error(new Error("hsl2hwbToken"));
|
|
7901
|
+
return hwbToken(values);
|
|
7902
|
+
}
|
|
7903
|
+
function cmyk2hwbToken(token) {
|
|
7904
|
+
const values = cmyk2hwbvalues(token);
|
|
7905
|
+
if (values == null) {
|
|
7906
|
+
return null;
|
|
7907
|
+
}
|
|
7908
|
+
return hwbToken(values);
|
|
7909
|
+
}
|
|
7910
|
+
function oklab2hwbToken(token) {
|
|
7911
|
+
const values = oklab2hwbvalues(token);
|
|
7912
|
+
if (values == null) {
|
|
7913
|
+
return null;
|
|
7914
|
+
}
|
|
7915
|
+
return hwbToken(values);
|
|
7916
|
+
}
|
|
7917
|
+
function oklch2hwbToken(token) {
|
|
7918
|
+
const values = oklch2hwbvalues(token);
|
|
7919
|
+
if (values == null) {
|
|
7920
|
+
return null;
|
|
7921
|
+
}
|
|
7922
|
+
return hwbToken(values);
|
|
7923
|
+
}
|
|
7924
|
+
function lab2hwbToken(token) {
|
|
7925
|
+
const values = lab2hwbvalues(token);
|
|
7926
|
+
if (values == null) {
|
|
7927
|
+
return null;
|
|
7928
|
+
}
|
|
7929
|
+
return hwbToken(values);
|
|
7930
|
+
}
|
|
7931
|
+
function lch2hwbToken(token) {
|
|
7932
|
+
const values = lch2hwbvalues(token);
|
|
7933
|
+
if (values == null) {
|
|
7934
|
+
return null;
|
|
7935
|
+
}
|
|
7936
|
+
return hwbToken(values);
|
|
7937
|
+
}
|
|
7938
|
+
function color2hwbToken(token) {
|
|
7939
|
+
const values = color2hwbvalues(token);
|
|
7940
|
+
if (values == null) {
|
|
7941
|
+
return null;
|
|
7942
|
+
}
|
|
7943
|
+
return hwbToken(values);
|
|
7944
|
+
}
|
|
7945
|
+
function hwbToken(values) {
|
|
7946
|
+
const chi = [
|
|
7947
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
7948
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[1] },
|
|
7949
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[2] },
|
|
7950
|
+
];
|
|
7951
|
+
if (values.length == 4) {
|
|
7952
|
+
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
|
|
7953
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
7954
|
+
val: values[3] * 100,
|
|
7955
|
+
});
|
|
7956
|
+
}
|
|
7957
|
+
return {
|
|
7958
|
+
typ: exports.EnumToken.ColorTokenType,
|
|
7959
|
+
val: "hwb",
|
|
7960
|
+
chi,
|
|
7961
|
+
kin: exports.ColorType.HWB,
|
|
7962
|
+
};
|
|
7963
|
+
}
|
|
7964
|
+
function rgb2hwbvalues(token) {
|
|
7965
|
+
const values = getColorComponents(token).map((t, index) => {
|
|
7966
|
+
if (index == 3) {
|
|
7967
|
+
return getNumber(t);
|
|
7968
|
+
}
|
|
7969
|
+
return getNumber(t) / 255;
|
|
7970
|
+
});
|
|
7971
|
+
// @ts-ignore
|
|
7972
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
7973
|
+
}
|
|
7974
|
+
function cmyk2hwbvalues(token) {
|
|
7975
|
+
const values = cmyk2srgbvalues(token);
|
|
7976
|
+
return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
7977
|
+
}
|
|
7978
|
+
function hsl2hwbvalues(token) {
|
|
7979
|
+
const values = hslvalues(token);
|
|
7980
|
+
if (values == null) {
|
|
7981
|
+
return null;
|
|
7982
|
+
}
|
|
7983
|
+
// @ts-ignore
|
|
7984
|
+
return hslvalues2hwbvalues(values.h, values.s, values.l, values.a);
|
|
7985
|
+
}
|
|
7986
|
+
function lab2hwbvalues(token) {
|
|
7987
|
+
const values = lab2srgbvalues(token);
|
|
7988
|
+
if (values == null) {
|
|
7989
|
+
return null;
|
|
7990
|
+
}
|
|
7991
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
7992
|
+
}
|
|
7993
|
+
function lch2hwbvalues(token) {
|
|
7994
|
+
const values = lch2srgbvalues(token);
|
|
7995
|
+
if (values == null) {
|
|
7996
|
+
return null;
|
|
7997
|
+
}
|
|
7998
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
7999
|
+
}
|
|
8000
|
+
function oklab2hwbvalues(token) {
|
|
8001
|
+
const values = oklab2srgbvalues(token);
|
|
8002
|
+
if (values == null) {
|
|
8003
|
+
return null;
|
|
8004
|
+
}
|
|
8005
|
+
// @ts-ignore
|
|
8006
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8007
|
+
}
|
|
8008
|
+
function oklch2hwbvalues(token) {
|
|
8009
|
+
const values = oklch2srgbvalues(token);
|
|
8010
|
+
// @ts-ignore
|
|
8011
|
+
return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8012
|
+
}
|
|
8013
|
+
function color2hwbvalues(token) {
|
|
8014
|
+
const values = color2srgbvalues(token);
|
|
8015
|
+
if (values == null) {
|
|
8016
|
+
return null;
|
|
8017
|
+
}
|
|
8018
|
+
// @ts-ignore
|
|
8019
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8020
|
+
}
|
|
8021
|
+
function hwbvalues(token) {
|
|
8022
|
+
const components = getColorComponents(token);
|
|
8023
|
+
if (components == null) {
|
|
8024
|
+
return null;
|
|
8025
|
+
}
|
|
8026
|
+
let t;
|
|
8027
|
+
// @ts-ignore
|
|
8028
|
+
let h = getAngle(components[0]) * 360;
|
|
8029
|
+
// @ts-ignore
|
|
8030
|
+
t = components[1];
|
|
8031
|
+
// @ts-ignore
|
|
8032
|
+
let w = getNumber(t);
|
|
8033
|
+
// @ts-ignore
|
|
8034
|
+
t = components[2];
|
|
8035
|
+
// @ts-ignore
|
|
8036
|
+
let b = getNumber(t);
|
|
8037
|
+
// if (components[1].typ == EnumToken.NumberTokenType) {
|
|
8038
|
+
w *= 100;
|
|
8039
|
+
// }
|
|
8040
|
+
// if (components[2].typ == EnumToken.NumberTokenType) {
|
|
8041
|
+
b *= 100;
|
|
8042
|
+
// }
|
|
8043
|
+
let a = null;
|
|
8044
|
+
if (components.length == 4) {
|
|
8045
|
+
// @ts-ignore
|
|
8046
|
+
t = components[3];
|
|
8047
|
+
// @ts-ignore
|
|
8048
|
+
a = getNumber(t);
|
|
8049
|
+
}
|
|
8050
|
+
return a == null ? { h, w, b } : { h, w, b, a };
|
|
8051
|
+
}
|
|
8052
|
+
function srgb2hwb(r, g, b, a = null, fallback = 0) {
|
|
8053
|
+
// 1. Clamp inputs to the standard web-safe sRGB gamut [0.0, 1.0]
|
|
8054
|
+
const rClamp = Math.min(1, Math.max(0, r));
|
|
8055
|
+
const gClamp = Math.min(1, Math.max(0, g));
|
|
8056
|
+
const bClamp = Math.min(1, Math.max(0, b));
|
|
8057
|
+
const cMax = Math.max(rClamp, gClamp, bClamp);
|
|
8058
|
+
const cMin = Math.min(rClamp, gClamp, bClamp);
|
|
8059
|
+
const delta = cMax - cMin;
|
|
8060
|
+
// 2. Whiteness and Blackness calculations
|
|
8061
|
+
const w = cMin;
|
|
8062
|
+
const bl = 1 - cMax;
|
|
8063
|
+
// 3. Calculate Hue
|
|
8064
|
+
let h = 0;
|
|
8065
|
+
if (delta !== 0) {
|
|
8066
|
+
if (cMax === rClamp) {
|
|
8067
|
+
h = 60 * (((gClamp - bClamp) / delta) % 6);
|
|
8068
|
+
}
|
|
8069
|
+
else if (cMax === gClamp) {
|
|
8070
|
+
h = 60 * ((bClamp - rClamp) / delta + 2);
|
|
8071
|
+
}
|
|
8072
|
+
else if (cMax === bClamp) {
|
|
8073
|
+
h = 60 * ((rClamp - gClamp) / delta + 4);
|
|
8074
|
+
}
|
|
8075
|
+
if (h < 0) {
|
|
8076
|
+
h += 360;
|
|
8077
|
+
}
|
|
8078
|
+
}
|
|
8079
|
+
const result = [h, w * 100, bl * 100];
|
|
8080
|
+
if (a != null) {
|
|
8081
|
+
result.push(a);
|
|
8082
|
+
}
|
|
8083
|
+
return result;
|
|
8084
|
+
}
|
|
8085
|
+
function hslvalues2hwbvalues(h, s, l, a = null) {
|
|
8086
|
+
const sNorm = s / 100;
|
|
8087
|
+
const lNorm = l / 100;
|
|
8088
|
+
// Keep Hue cleanly bound to standard circle loops
|
|
8089
|
+
const hue = ((h % 360) + 360) % 360;
|
|
8090
|
+
// 1. Compute the intermediate HSV Value component (brightness peak)
|
|
8091
|
+
const v = lNorm + sNorm * Math.min(lNorm, 1 - lNorm);
|
|
8092
|
+
// 2. Compute Chroma
|
|
8093
|
+
const chroma = 2 * (v - lNorm);
|
|
8094
|
+
// 3. Extract Whiteness and Blackness
|
|
8095
|
+
const w = v - chroma;
|
|
8096
|
+
const b = 1 - v;
|
|
8097
|
+
const hwb = [hue, w * 100, b * 100];
|
|
8098
|
+
if (a != null && a != 1) {
|
|
8099
|
+
hwb.push(a);
|
|
8100
|
+
}
|
|
8101
|
+
return hwb;
|
|
8102
|
+
}
|
|
8103
|
+
|
|
7880
8104
|
// from https://www.w3.org/TR/css-color-4/#color-conversion-code
|
|
7881
8105
|
// srgb-linear -> srgb
|
|
7882
8106
|
// 0 <= r, g, b <= 1
|
|
@@ -7950,25 +8174,59 @@ function xyz2srgb(x, y, z, alpha = null) {
|
|
|
7950
8174
|
return lsrgb2srgbvalues(values[0], values[1], values[2], alpha);
|
|
7951
8175
|
}
|
|
7952
8176
|
function hwb2srgbvalues(token) {
|
|
7953
|
-
const { h
|
|
7954
|
-
if (
|
|
8177
|
+
const { h, w, b, a } = hwbvalues(token) ?? {};
|
|
8178
|
+
if (h == null || w == null || b == null) {
|
|
7955
8179
|
return [];
|
|
7956
8180
|
}
|
|
7957
|
-
const rgb =
|
|
7958
|
-
|
|
7959
|
-
rgb
|
|
7960
|
-
rgb[i] = rgb[i] + white;
|
|
7961
|
-
}
|
|
7962
|
-
if (alpha != null && alpha != 1) {
|
|
7963
|
-
rgb.push(alpha);
|
|
8181
|
+
const rgb = hwb2srgb(h, w, b);
|
|
8182
|
+
if (a != null && a != 1) {
|
|
8183
|
+
rgb.push(a);
|
|
7964
8184
|
}
|
|
7965
8185
|
return rgb;
|
|
7966
8186
|
}
|
|
8187
|
+
/**
|
|
8188
|
+
* convert hwb to sRGB
|
|
8189
|
+
*/
|
|
8190
|
+
function hwb2srgb(h, w, b, alpha) {
|
|
8191
|
+
const wNorm = w / 100;
|
|
8192
|
+
const bNorm = b / 100;
|
|
8193
|
+
if (wNorm + bNorm >= 1) {
|
|
8194
|
+
const gray = wNorm / (wNorm + bNorm);
|
|
8195
|
+
return [Math.round(gray * 10000) / 10000, Math.round(gray * 10000) / 10000, Math.round(gray * 10000) / 10000];
|
|
8196
|
+
}
|
|
8197
|
+
const hPrime = (h % 360) / 60;
|
|
8198
|
+
const x = 1 - Math.abs((hPrime % 2) - 1);
|
|
8199
|
+
let rChroma = 0;
|
|
8200
|
+
let gChroma = 0;
|
|
8201
|
+
let bChroma = 0;
|
|
8202
|
+
if (hPrime >= 0 && hPrime < 1) {
|
|
8203
|
+
[rChroma, gChroma, bChroma] = [1, x, 0];
|
|
8204
|
+
}
|
|
8205
|
+
else if (hPrime >= 1 && hPrime < 2) {
|
|
8206
|
+
[rChroma, gChroma, bChroma] = [x, 1, 0];
|
|
8207
|
+
}
|
|
8208
|
+
else if (hPrime >= 2 && hPrime < 3) {
|
|
8209
|
+
[rChroma, gChroma, bChroma] = [0, 1, x];
|
|
8210
|
+
}
|
|
8211
|
+
else if (hPrime >= 3 && hPrime < 4) {
|
|
8212
|
+
[rChroma, gChroma, bChroma] = [0, x, 1];
|
|
8213
|
+
}
|
|
8214
|
+
else if (hPrime >= 4 && hPrime < 5) {
|
|
8215
|
+
[rChroma, gChroma, bChroma] = [x, 0, 1];
|
|
8216
|
+
}
|
|
8217
|
+
else if (hPrime >= 5 && hPrime <= 6) {
|
|
8218
|
+
[rChroma, gChroma, bChroma] = [1, 0, x];
|
|
8219
|
+
}
|
|
8220
|
+
const factor = 1 - wNorm - bNorm;
|
|
8221
|
+
const srgb = [rChroma * factor + wNorm, gChroma * factor + wNorm, bChroma * factor + wNorm];
|
|
8222
|
+
return srgb;
|
|
8223
|
+
}
|
|
7967
8224
|
function hsl2srgb(token) {
|
|
7968
8225
|
let { h, s, l, a } = hslvalues(token) ?? {};
|
|
7969
8226
|
if (h == null || s == null || l == null) {
|
|
7970
8227
|
return null;
|
|
7971
8228
|
}
|
|
8229
|
+
// hue in degrees
|
|
7972
8230
|
return hslvalues2srgbvalues(h, s, l, a);
|
|
7973
8231
|
}
|
|
7974
8232
|
function cmyk2srgbvalues(token) {
|
|
@@ -8029,7 +8287,7 @@ function hslvalues(token) {
|
|
|
8029
8287
|
}
|
|
8030
8288
|
let t;
|
|
8031
8289
|
// @ts-ignore
|
|
8032
|
-
let h = getAngle(components[0]);
|
|
8290
|
+
let h = getAngle(components[0]) * 360;
|
|
8033
8291
|
// @ts-ignore
|
|
8034
8292
|
t = components[1];
|
|
8035
8293
|
// @ts-ignore
|
|
@@ -8038,6 +8296,12 @@ function hslvalues(token) {
|
|
|
8038
8296
|
t = components[2];
|
|
8039
8297
|
// @ts-ignore
|
|
8040
8298
|
let l = getNumber(t);
|
|
8299
|
+
if (components[1].typ == exports.EnumToken.PercentageTokenType) {
|
|
8300
|
+
s *= 100;
|
|
8301
|
+
}
|
|
8302
|
+
if (components[2].typ == exports.EnumToken.PercentageTokenType) {
|
|
8303
|
+
l *= 100;
|
|
8304
|
+
}
|
|
8041
8305
|
let a = null;
|
|
8042
8306
|
if (components.length == 4) {
|
|
8043
8307
|
// @ts-ignore
|
|
@@ -8048,56 +8312,38 @@ function hslvalues(token) {
|
|
|
8048
8312
|
return a == null ? { h, s, l } : { h, s, l, a };
|
|
8049
8313
|
}
|
|
8050
8314
|
function hslvalues2srgbvalues(h, s, l, a = null) {
|
|
8051
|
-
|
|
8052
|
-
|
|
8053
|
-
|
|
8054
|
-
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
8063
|
-
|
|
8064
|
-
|
|
8065
|
-
|
|
8066
|
-
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
|
|
8078
|
-
|
|
8079
|
-
|
|
8080
|
-
case 3:
|
|
8081
|
-
r = m;
|
|
8082
|
-
g = mid2;
|
|
8083
|
-
b = v;
|
|
8084
|
-
break;
|
|
8085
|
-
case 4:
|
|
8086
|
-
r = mid1;
|
|
8087
|
-
g = m;
|
|
8088
|
-
b = v;
|
|
8089
|
-
break;
|
|
8090
|
-
case 5:
|
|
8091
|
-
r = v;
|
|
8092
|
-
g = m;
|
|
8093
|
-
b = mid2;
|
|
8094
|
-
break;
|
|
8095
|
-
}
|
|
8096
|
-
}
|
|
8097
|
-
const values = [r, g, b];
|
|
8098
|
-
if (a != null && a != 1) {
|
|
8315
|
+
const sNorm = s / 100;
|
|
8316
|
+
const lNorm = l / 100;
|
|
8317
|
+
const chroma = (1 - Math.abs(2 * lNorm - 1)) * sNorm;
|
|
8318
|
+
const hPrime = h / 60;
|
|
8319
|
+
const x = chroma * (1 - Math.abs((hPrime % 2) - 1));
|
|
8320
|
+
let rTmp = 0;
|
|
8321
|
+
let gTmp = 0;
|
|
8322
|
+
let bTmp = 0;
|
|
8323
|
+
if (hPrime >= 0 && hPrime < 1) {
|
|
8324
|
+
[rTmp, gTmp, bTmp] = [chroma, x, 0];
|
|
8325
|
+
}
|
|
8326
|
+
else if (hPrime >= 1 && hPrime < 2) {
|
|
8327
|
+
[rTmp, gTmp, bTmp] = [x, chroma, 0];
|
|
8328
|
+
}
|
|
8329
|
+
else if (hPrime >= 2 && hPrime < 3) {
|
|
8330
|
+
[rTmp, gTmp, bTmp] = [0, chroma, x];
|
|
8331
|
+
}
|
|
8332
|
+
else if (hPrime >= 3 && hPrime < 4) {
|
|
8333
|
+
[rTmp, gTmp, bTmp] = [0, x, chroma];
|
|
8334
|
+
}
|
|
8335
|
+
else if (hPrime >= 4 && hPrime < 5) {
|
|
8336
|
+
[rTmp, gTmp, bTmp] = [x, 0, chroma];
|
|
8337
|
+
}
|
|
8338
|
+
else if (hPrime >= 5 && hPrime <= 6) {
|
|
8339
|
+
[rTmp, gTmp, bTmp] = [chroma, 0, x];
|
|
8340
|
+
}
|
|
8341
|
+
const m = lNorm - chroma / 2;
|
|
8342
|
+
const values = [rTmp + m, gTmp + m, bTmp + m];
|
|
8343
|
+
if (a != null) {
|
|
8099
8344
|
values.push(a);
|
|
8100
8345
|
}
|
|
8346
|
+
// Return exact float decimals instead of multiplying by 255
|
|
8101
8347
|
return values;
|
|
8102
8348
|
}
|
|
8103
8349
|
function lab2srgbvalues(token) {
|
|
@@ -8470,25 +8716,6 @@ function lch2rgbvalues(token) {
|
|
|
8470
8716
|
return lch2srgbvalues(token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
|
|
8471
8717
|
}
|
|
8472
8718
|
|
|
8473
|
-
function hwb2hsv(h, w, b, a) {
|
|
8474
|
-
// @ts-ignore
|
|
8475
|
-
return [h, 1 - w / (1 - b), 1 - b, a];
|
|
8476
|
-
}
|
|
8477
|
-
// https://gist.github.com/defims/0ca2ef8832833186ed396a2f8a204117#file-annotated-js
|
|
8478
|
-
function hsl2hsv(h, s, l, a = null) {
|
|
8479
|
-
s *= l < .5 ? l : 1 - l;
|
|
8480
|
-
const result = [
|
|
8481
|
-
//Range should be between 0 - 1
|
|
8482
|
-
h, //Hue stays the same
|
|
8483
|
-
2 * s / (l + s), //Saturation
|
|
8484
|
-
l + s //Value
|
|
8485
|
-
];
|
|
8486
|
-
if (a != null) {
|
|
8487
|
-
result.push(a);
|
|
8488
|
-
}
|
|
8489
|
-
return result;
|
|
8490
|
-
}
|
|
8491
|
-
|
|
8492
8719
|
function hex2HslToken(token) {
|
|
8493
8720
|
let values = hex2srgbvalues(token);
|
|
8494
8721
|
if (values == null) {
|
|
@@ -8553,11 +8780,17 @@ function color2HslToken(token) {
|
|
|
8553
8780
|
return hslToken(srgb2hslvalues(values[0], values[1], values[2], values[3]));
|
|
8554
8781
|
}
|
|
8555
8782
|
function hslToken(values) {
|
|
8556
|
-
values[
|
|
8783
|
+
if (values[1] == 0) {
|
|
8784
|
+
values[0] = 0;
|
|
8785
|
+
}
|
|
8786
|
+
if (values[2] == 1 || values[2] == 0) {
|
|
8787
|
+
values[0] = 0;
|
|
8788
|
+
values[1] = 0;
|
|
8789
|
+
}
|
|
8557
8790
|
const chi = [
|
|
8558
8791
|
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
8559
|
-
{ typ: exports.EnumToken.PercentageTokenType, val: values[1]
|
|
8560
|
-
{ typ: exports.EnumToken.PercentageTokenType, val: values[2]
|
|
8792
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[1] },
|
|
8793
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[2] },
|
|
8561
8794
|
];
|
|
8562
8795
|
if (values.length == 4 && values[3] != 1) {
|
|
8563
8796
|
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
|
|
@@ -8600,32 +8833,33 @@ function rgb2hslvalues(token) {
|
|
|
8600
8833
|
}
|
|
8601
8834
|
return rgbvalues2hslvalues(values[0], values[1], values[2], values[3]);
|
|
8602
8835
|
}
|
|
8603
|
-
// https://gist.github.com/defims/0ca2ef8832833186ed396a2f8a204117#file-annotated-js
|
|
8604
|
-
function hsv2hsl(h, s, v, a) {
|
|
8605
|
-
const result = [
|
|
8606
|
-
//[hue, saturation, lightness]
|
|
8607
|
-
//Range should be between 0 - 1
|
|
8608
|
-
h, //Hue stays the same
|
|
8609
|
-
//Saturation is very different between the two color spaces
|
|
8610
|
-
//If (2-sat)*val < 1 set it to sat*val/((2-sat)*val)
|
|
8611
|
-
//Otherwise sat*val/(2-(2-sat)*val)
|
|
8612
|
-
//Conditional is not operating with hue, it is reassigned!
|
|
8613
|
-
(s * v) / ((h = (2 - s) * v) < 1 ? h : 2 - h),
|
|
8614
|
-
h / 2, //Lightness is (2-sat)*val/2
|
|
8615
|
-
];
|
|
8616
|
-
if (a != null) {
|
|
8617
|
-
result.push(a);
|
|
8618
|
-
}
|
|
8619
|
-
return result;
|
|
8620
|
-
}
|
|
8621
8836
|
function cmyk2hslvalues(token) {
|
|
8622
8837
|
const values = cmyk2rgbvalues(token);
|
|
8623
8838
|
return values == null ? null : rgbvalues2hslvalues(values[0], values[1], values[2], values[3]);
|
|
8624
8839
|
}
|
|
8625
8840
|
function hwb2hslvalues(token) {
|
|
8626
|
-
const
|
|
8627
|
-
|
|
8628
|
-
|
|
8841
|
+
const { h, w, b, a } = hwbvalues(token) ?? {};
|
|
8842
|
+
if (h == null || w == null || b == null) {
|
|
8843
|
+
return null;
|
|
8844
|
+
}
|
|
8845
|
+
const wNorm = w / 100;
|
|
8846
|
+
const bNorm = b / 100;
|
|
8847
|
+
const hue = ((h % 360) + 360) % 360;
|
|
8848
|
+
if (wNorm + bNorm >= 1) {
|
|
8849
|
+
const grayLightness = wNorm / (wNorm + bNorm);
|
|
8850
|
+
return [hue, 0, grayLightness * 100];
|
|
8851
|
+
}
|
|
8852
|
+
const lightness = (1 - bNorm + wNorm) / 2;
|
|
8853
|
+
let saturation = 0;
|
|
8854
|
+
if (lightness > 0 && lightness < 1) {
|
|
8855
|
+
const chroma = 1 - wNorm - bNorm;
|
|
8856
|
+
saturation = chroma / (1 - Math.abs(2 * lightness - 1));
|
|
8857
|
+
}
|
|
8858
|
+
const hsl = [hue, saturation * 100, lightness * 100];
|
|
8859
|
+
if (a != null && a != 1) {
|
|
8860
|
+
hsl.push(a);
|
|
8861
|
+
}
|
|
8862
|
+
return hsl;
|
|
8629
8863
|
}
|
|
8630
8864
|
function lab2hslvalues(token) {
|
|
8631
8865
|
const values = lab2rgbvalues(token);
|
|
@@ -8656,28 +8890,28 @@ function rgbvalues2hslvalues(r, g, b, a = null) {
|
|
|
8656
8890
|
return srgb2hslvalues(r / 255, g / 255, b / 255, a);
|
|
8657
8891
|
}
|
|
8658
8892
|
function srgb2hslvalues(r, g, b, a = null) {
|
|
8659
|
-
|
|
8660
|
-
|
|
8893
|
+
const max = Math.max(r, g, b);
|
|
8894
|
+
const min = Math.min(r, g, b);
|
|
8895
|
+
const delta = max - min;
|
|
8896
|
+
const l = (max + min) / 2;
|
|
8661
8897
|
let h = 0;
|
|
8662
8898
|
let s = 0;
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
let d = max - min;
|
|
8666
|
-
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
8899
|
+
if (delta !== 0) {
|
|
8900
|
+
s = delta / (1 - Math.abs(2 * l - 1));
|
|
8667
8901
|
switch (max) {
|
|
8668
8902
|
case r:
|
|
8669
|
-
h = (g - b) /
|
|
8903
|
+
h = 60 * (((g - b) / delta) % 6);
|
|
8670
8904
|
break;
|
|
8671
8905
|
case g:
|
|
8672
|
-
h = (b - r) /
|
|
8906
|
+
h = 60 * ((b - r) / delta + 2);
|
|
8673
8907
|
break;
|
|
8674
8908
|
case b:
|
|
8675
|
-
h = (r - g) /
|
|
8909
|
+
h = 60 * ((r - g) / delta + 4);
|
|
8676
8910
|
break;
|
|
8677
8911
|
}
|
|
8678
|
-
h /= 6;
|
|
8679
8912
|
}
|
|
8680
|
-
|
|
8913
|
+
h = ((h % 360) + 360) % 360;
|
|
8914
|
+
const hsl = [h, s * 100, l * 100];
|
|
8681
8915
|
if (a != null && a < 1) {
|
|
8682
8916
|
// @ts-ignore
|
|
8683
8917
|
return hsl.concat([a]);
|
|
@@ -8686,191 +8920,6 @@ function srgb2hslvalues(r, g, b, a = null) {
|
|
|
8686
8920
|
return hsl;
|
|
8687
8921
|
}
|
|
8688
8922
|
|
|
8689
|
-
function rgb2hwbToken(token) {
|
|
8690
|
-
const values = rgb2hwbvalues(token);
|
|
8691
|
-
if (values == null) {
|
|
8692
|
-
return null;
|
|
8693
|
-
}
|
|
8694
|
-
return hwbToken(values);
|
|
8695
|
-
}
|
|
8696
|
-
function hsl2hwbToken(token) {
|
|
8697
|
-
const values = hsl2hwbvalues(token);
|
|
8698
|
-
if (values == null) {
|
|
8699
|
-
return null;
|
|
8700
|
-
}
|
|
8701
|
-
return hwbToken(values);
|
|
8702
|
-
}
|
|
8703
|
-
function cmyk2hwbToken(token) {
|
|
8704
|
-
const values = cmyk2hwbvalues(token);
|
|
8705
|
-
if (values == null) {
|
|
8706
|
-
return null;
|
|
8707
|
-
}
|
|
8708
|
-
return hwbToken(values);
|
|
8709
|
-
}
|
|
8710
|
-
function oklab2hwbToken(token) {
|
|
8711
|
-
const values = oklab2hwbvalues(token);
|
|
8712
|
-
if (values == null) {
|
|
8713
|
-
return null;
|
|
8714
|
-
}
|
|
8715
|
-
return hwbToken(values);
|
|
8716
|
-
}
|
|
8717
|
-
function oklch2hwbToken(token) {
|
|
8718
|
-
const values = oklch2hwbvalues(token);
|
|
8719
|
-
if (values == null) {
|
|
8720
|
-
return null;
|
|
8721
|
-
}
|
|
8722
|
-
return hwbToken(values);
|
|
8723
|
-
}
|
|
8724
|
-
function lab2hwbToken(token) {
|
|
8725
|
-
const values = lab2hwbvalues(token);
|
|
8726
|
-
if (values == null) {
|
|
8727
|
-
return null;
|
|
8728
|
-
}
|
|
8729
|
-
return hwbToken(values);
|
|
8730
|
-
}
|
|
8731
|
-
function lch2hwbToken(token) {
|
|
8732
|
-
const values = lch2hwbvalues(token);
|
|
8733
|
-
if (values == null) {
|
|
8734
|
-
return null;
|
|
8735
|
-
}
|
|
8736
|
-
return hwbToken(values);
|
|
8737
|
-
}
|
|
8738
|
-
function color2hwbToken(token) {
|
|
8739
|
-
const values = color2hwbvalues(token);
|
|
8740
|
-
if (values == null) {
|
|
8741
|
-
return null;
|
|
8742
|
-
}
|
|
8743
|
-
return hwbToken(values);
|
|
8744
|
-
}
|
|
8745
|
-
function hwbToken(values) {
|
|
8746
|
-
values[0] = values[0] * 360;
|
|
8747
|
-
const chi = [
|
|
8748
|
-
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
8749
|
-
{ typ: exports.EnumToken.PercentageTokenType, val: values[1] * 100 },
|
|
8750
|
-
{ typ: exports.EnumToken.PercentageTokenType, val: values[2] * 100 },
|
|
8751
|
-
];
|
|
8752
|
-
if (values.length == 4) {
|
|
8753
|
-
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
|
|
8754
|
-
typ: exports.EnumToken.PercentageTokenType,
|
|
8755
|
-
val: values[3] * 100,
|
|
8756
|
-
});
|
|
8757
|
-
}
|
|
8758
|
-
return {
|
|
8759
|
-
typ: exports.EnumToken.ColorTokenType,
|
|
8760
|
-
val: "hwb",
|
|
8761
|
-
chi,
|
|
8762
|
-
kin: exports.ColorType.HWB,
|
|
8763
|
-
};
|
|
8764
|
-
}
|
|
8765
|
-
function rgb2hwbvalues(token) {
|
|
8766
|
-
const values = getColorComponents(token).map((t, index) => {
|
|
8767
|
-
if (index == 3) {
|
|
8768
|
-
return getNumber(t);
|
|
8769
|
-
}
|
|
8770
|
-
return getNumber(t) / 255;
|
|
8771
|
-
});
|
|
8772
|
-
// @ts-ignore
|
|
8773
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8774
|
-
}
|
|
8775
|
-
function cmyk2hwbvalues(token) {
|
|
8776
|
-
const values = cmyk2srgbvalues(token);
|
|
8777
|
-
return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8778
|
-
}
|
|
8779
|
-
function hsl2hwbvalues(token) {
|
|
8780
|
-
const values = getColorComponents(token).map((t, index) => {
|
|
8781
|
-
if (index == 3 && t.typ == exports.EnumToken.IdenTokenType && t.val == "none") {
|
|
8782
|
-
return 1;
|
|
8783
|
-
}
|
|
8784
|
-
if (index == 0) {
|
|
8785
|
-
return getAngle(t);
|
|
8786
|
-
}
|
|
8787
|
-
return getNumber(t);
|
|
8788
|
-
});
|
|
8789
|
-
// @ts-ignore
|
|
8790
|
-
return hslvalues2hwbvalues(values[0], values[1], values[2], values[3]);
|
|
8791
|
-
}
|
|
8792
|
-
function lab2hwbvalues(token) {
|
|
8793
|
-
const values = lab2srgbvalues(token);
|
|
8794
|
-
if (values == null) {
|
|
8795
|
-
return null;
|
|
8796
|
-
}
|
|
8797
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8798
|
-
}
|
|
8799
|
-
function lch2hwbvalues(token) {
|
|
8800
|
-
const values = lch2srgbvalues(token);
|
|
8801
|
-
if (values == null) {
|
|
8802
|
-
return null;
|
|
8803
|
-
}
|
|
8804
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8805
|
-
}
|
|
8806
|
-
function oklab2hwbvalues(token) {
|
|
8807
|
-
const values = oklab2srgbvalues(token);
|
|
8808
|
-
if (values == null) {
|
|
8809
|
-
return null;
|
|
8810
|
-
}
|
|
8811
|
-
// @ts-ignore
|
|
8812
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8813
|
-
}
|
|
8814
|
-
function oklch2hwbvalues(token) {
|
|
8815
|
-
const values = oklch2srgbvalues(token);
|
|
8816
|
-
// @ts-ignore
|
|
8817
|
-
return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8818
|
-
}
|
|
8819
|
-
function rgb2hue(r, g, b, fallback = 0) {
|
|
8820
|
-
let value = rgb2value(r, g, b);
|
|
8821
|
-
let whiteness = rgb2whiteness(r, g, b);
|
|
8822
|
-
let delta = value - whiteness;
|
|
8823
|
-
if (delta > 0) {
|
|
8824
|
-
// calculate segment
|
|
8825
|
-
let segment = value === r ? (g - b) / delta : value === g ? (b - r) / delta : (r - g) / delta;
|
|
8826
|
-
// calculate shift
|
|
8827
|
-
let shift = value === r ? (segment < 0 ? 360 / 60 : 0 / 60) : value === g ? 120 / 60 : 240 / 60;
|
|
8828
|
-
// calculate hue
|
|
8829
|
-
return (segment + shift) * 60;
|
|
8830
|
-
}
|
|
8831
|
-
return fallback;
|
|
8832
|
-
}
|
|
8833
|
-
function rgb2value(r, g, b) {
|
|
8834
|
-
return Math.max(r, g, b);
|
|
8835
|
-
}
|
|
8836
|
-
function rgb2whiteness(r, g, b) {
|
|
8837
|
-
return Math.min(r, g, b);
|
|
8838
|
-
}
|
|
8839
|
-
function color2hwbvalues(token) {
|
|
8840
|
-
const values = color2srgbvalues(token);
|
|
8841
|
-
if (values == null) {
|
|
8842
|
-
return null;
|
|
8843
|
-
}
|
|
8844
|
-
// @ts-ignore
|
|
8845
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8846
|
-
}
|
|
8847
|
-
function srgb2hwb(r, g, b, a = null, fallback = 0) {
|
|
8848
|
-
r *= 100;
|
|
8849
|
-
g *= 100;
|
|
8850
|
-
b *= 100;
|
|
8851
|
-
let hue = rgb2hue(r, g, b, fallback);
|
|
8852
|
-
let whiteness = rgb2whiteness(r, g, b);
|
|
8853
|
-
let value = Math.round(rgb2value(r, g, b));
|
|
8854
|
-
let blackness = 100 - value;
|
|
8855
|
-
const result = [hue / 360, whiteness / 100, blackness / 100];
|
|
8856
|
-
if (a != null) {
|
|
8857
|
-
result.push(a);
|
|
8858
|
-
}
|
|
8859
|
-
return result;
|
|
8860
|
-
}
|
|
8861
|
-
function hsv2hwb(h, s, v, a = null) {
|
|
8862
|
-
const result = [h, (1 - s) * v, 1 - v];
|
|
8863
|
-
if (a != null) {
|
|
8864
|
-
result.push(a);
|
|
8865
|
-
}
|
|
8866
|
-
return result;
|
|
8867
|
-
}
|
|
8868
|
-
function hslvalues2hwbvalues(h, s, l, a = null) {
|
|
8869
|
-
let values = hsl2hsv(h, s, l);
|
|
8870
|
-
// @ts-ignore
|
|
8871
|
-
return hsv2hwb(values[0], values[1], values[2], a);
|
|
8872
|
-
}
|
|
8873
|
-
|
|
8874
8923
|
function prophotorgb2srgbvalues(r, g, b, a = null) {
|
|
8875
8924
|
let values = prophotorgb2xyz50(r, g, b);
|
|
8876
8925
|
// @ts-ignore
|
|
@@ -9172,6 +9221,7 @@ function colorMix(...args) {
|
|
|
9172
9221
|
const percentages = [];
|
|
9173
9222
|
const srgbComponentValues = [];
|
|
9174
9223
|
const colorComponents = [];
|
|
9224
|
+
const colors = [];
|
|
9175
9225
|
if (args[i]?.typ === exports.EnumToken.IdenTokenType) {
|
|
9176
9226
|
if (!equalsIgnoreCase(args[i++].val, "in")) {
|
|
9177
9227
|
return null;
|
|
@@ -9221,9 +9271,10 @@ function colorMix(...args) {
|
|
|
9221
9271
|
if (values == null) {
|
|
9222
9272
|
return null;
|
|
9223
9273
|
}
|
|
9224
|
-
if (colorSpace == "hwb") {
|
|
9225
|
-
|
|
9226
|
-
}
|
|
9274
|
+
// if (colorSpace == "hwb") {
|
|
9275
|
+
// colorSpace = "srgb";
|
|
9276
|
+
// }
|
|
9277
|
+
colors.push(processPowerlessComponents(args[i]));
|
|
9227
9278
|
switch (colorSpace) {
|
|
9228
9279
|
case "srgb":
|
|
9229
9280
|
break;
|
|
@@ -9253,17 +9304,12 @@ function colorMix(...args) {
|
|
|
9253
9304
|
values = srgb2xyz_d65(values[0], values[1], values[2], values[3]);
|
|
9254
9305
|
values = XYZ_D65_to_D50(values[0], values[1], values[2], values[3]);
|
|
9255
9306
|
break;
|
|
9256
|
-
// case "rgb":
|
|
9257
|
-
// for (let j = 0; j < values.length; j++) {
|
|
9258
|
-
// values[j] = j == 3 ? values[j] : srgb2rgb(values[j]);
|
|
9259
|
-
// }
|
|
9260
|
-
// break;
|
|
9261
9307
|
case "hsl":
|
|
9262
9308
|
values = srgb2hslvalues(values[0], values[1], values[2], values[3]);
|
|
9263
9309
|
break;
|
|
9264
|
-
|
|
9265
|
-
|
|
9266
|
-
|
|
9310
|
+
case "hwb":
|
|
9311
|
+
values = srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
9312
|
+
break;
|
|
9267
9313
|
case "lab":
|
|
9268
9314
|
values = srgb2labvalues(values[0], values[1], values[2], values[3]);
|
|
9269
9315
|
break;
|
|
@@ -9325,7 +9371,8 @@ function colorMix(...args) {
|
|
|
9325
9371
|
}
|
|
9326
9372
|
}
|
|
9327
9373
|
const stack = [];
|
|
9328
|
-
const lchSpaces = ["lch", "oklch"];
|
|
9374
|
+
// const lchSpaces: string[] = ["lch", "oklch"];
|
|
9375
|
+
const isLCHOrOKLCH = colorSpace === "lch" || colorSpace == "oklch";
|
|
9329
9376
|
i = srgbComponentValues.length;
|
|
9330
9377
|
while (i--) {
|
|
9331
9378
|
stack.push({
|
|
@@ -9343,46 +9390,73 @@ function colorMix(...args) {
|
|
|
9343
9390
|
let premult1;
|
|
9344
9391
|
let premult2;
|
|
9345
9392
|
let mixedPremult;
|
|
9346
|
-
let
|
|
9347
|
-
|
|
9348
|
-
|
|
9349
|
-
|
|
9350
|
-
|
|
9351
|
-
if (colorComponents[0][3] != null &&
|
|
9352
|
-
colorComponents[0][3].typ == exports.EnumToken.IdenTokenType &&
|
|
9353
|
-
colorComponents[0][3].val == "none" &&
|
|
9354
|
-
colorComponents[1].length == 4) {
|
|
9393
|
+
let offset1 = colors[0].kin == exports.ColorType.COLOR ? 1 : 0;
|
|
9394
|
+
if (colorComponents[0][offset1 + 3] != null &&
|
|
9395
|
+
colorComponents[0][offset1 + 3].typ == exports.EnumToken.IdenTokenType &&
|
|
9396
|
+
colorComponents[0][offset1 + 3].val == "none" &&
|
|
9397
|
+
colorComponents[1].length == offset1 + 4) {
|
|
9355
9398
|
// fix powerless alpha for last color if previous color has alpha
|
|
9356
9399
|
stack[stack.length - 1].color[3] = stack[stack.length - 2].color[3];
|
|
9357
9400
|
}
|
|
9358
|
-
//
|
|
9359
|
-
if (
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9401
|
+
// console.error(stack);
|
|
9402
|
+
if (stack.length > 1) {
|
|
9403
|
+
// powerless hue for lch spaces
|
|
9404
|
+
// if (lchSpaces.includes(colorSpace)) {
|
|
9405
|
+
// console.error(JSON.stringify({colorSpace1, colorSpace, stack, colorComponents}, null, 1));
|
|
9406
|
+
if ((stack[stack.length - 1].color[0] == 0 && colorComponents[0][offset1].typ == exports.EnumToken.IdenTokenType &&
|
|
9407
|
+
colorComponents[0][offset1].val == "none") ||
|
|
9408
|
+
colorComponents[0][0][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
|
|
9409
|
+
stack[stack.length - 1].color[0] = stack[stack.length - 2].color[0];
|
|
9410
|
+
}
|
|
9411
|
+
if ((stack[stack.length - 1].color[1] == 0 && colorComponents[0][offset1 + 1].typ == exports.EnumToken.IdenTokenType &&
|
|
9412
|
+
colorComponents[0][offset1 + 1].val == "none") ||
|
|
9413
|
+
colorComponents[0][1][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
|
|
9414
|
+
stack[stack.length - 1].color[1] = stack[stack.length - 2].color[1];
|
|
9415
|
+
}
|
|
9416
|
+
if ((stack[stack.length - 1].color[2] == 0 && colorComponents[0][offset1 + 2].typ == exports.EnumToken.IdenTokenType &&
|
|
9417
|
+
colorComponents[0][offset1 + 2].val == "none") ||
|
|
9418
|
+
colorComponents[0][2][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent ||
|
|
9419
|
+
(isLCHOrOKLCH &&
|
|
9420
|
+
(stack[stack.length - 1].color[1] == 0 ||
|
|
9421
|
+
stack[stack.length - 1].color[0] == 0 ||
|
|
9422
|
+
stack[stack.length - 1].color[0] ==
|
|
9423
|
+
colorRange[colors[0].kin == exports.ColorType.LCH ? "lch" : "oklch"].l[1]))) {
|
|
9364
9424
|
stack[stack.length - 1].color[2] = stack[stack.length - 2].color[2];
|
|
9365
9425
|
}
|
|
9426
|
+
// }
|
|
9366
9427
|
}
|
|
9428
|
+
// console.error([colorComponents[0][offset1].typ == EnumToken.IdenTokenType, (colorComponents[0][offset1] as IdentToken).val == "none"]);
|
|
9429
|
+
// console.error(isLCHOrOKLCH, colorComponents, stack);
|
|
9367
9430
|
while (stack.length > 1) {
|
|
9368
9431
|
r1 = stack.pop();
|
|
9369
9432
|
r2 = stack.pop();
|
|
9433
|
+
offset1 = colors[++currentIndex].kin == exports.ColorType.COLOR ? 1 : 0;
|
|
9370
9434
|
// r2 powerless alpha
|
|
9371
|
-
if (colorComponents[
|
|
9372
|
-
colorComponents[currentIndex][3].typ == exports.EnumToken.IdenTokenType &&
|
|
9373
|
-
colorComponents[currentIndex][3].val == "none") {
|
|
9435
|
+
if (colorComponents[currentIndex][offset1 + 3] != null &&
|
|
9436
|
+
colorComponents[currentIndex][offset1 + 3].typ == exports.EnumToken.IdenTokenType &&
|
|
9437
|
+
colorComponents[currentIndex][offset1 + 3].val == "none") {
|
|
9374
9438
|
// fix powerless alpha for last color if previous color has alpha
|
|
9375
9439
|
r2.color[3] = r1.color[3];
|
|
9376
9440
|
}
|
|
9377
|
-
// @ts-expect-error
|
|
9378
|
-
colorSpace1 = exports.ColorType[colorComponents[currentIndex].kin]?.toLowerCase?.();
|
|
9379
9441
|
// powerless hue for lch spaces
|
|
9380
|
-
if (
|
|
9381
|
-
|
|
9382
|
-
|
|
9383
|
-
|
|
9384
|
-
|
|
9385
|
-
|
|
9442
|
+
if ((r2.color[0] == 0 && colorComponents[currentIndex][offset1].typ == exports.EnumToken.IdenTokenType &&
|
|
9443
|
+
colorComponents[currentIndex][offset1].val == "none") ||
|
|
9444
|
+
colorComponents[currentIndex][offset1][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
|
|
9445
|
+
r2.color[0] = r1.color[0];
|
|
9446
|
+
}
|
|
9447
|
+
if ((r2.color[1] == 0 && colorComponents[currentIndex][offset1 + 1].typ == exports.EnumToken.IdenTokenType &&
|
|
9448
|
+
colorComponents[currentIndex][offset1 + 1].val == "none") ||
|
|
9449
|
+
colorComponents[currentIndex][offset1 + 1][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
|
|
9450
|
+
r2.color[1] = r1.color[1];
|
|
9451
|
+
}
|
|
9452
|
+
if ((r2.color[2] == 0 && colorComponents[currentIndex][offset1 + 2].typ == exports.EnumToken.IdenTokenType &&
|
|
9453
|
+
colorComponents[currentIndex][offset1 + 2].val == "none") ||
|
|
9454
|
+
colorComponents[currentIndex][offset1 + 2][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent ||
|
|
9455
|
+
(isLCHOrOKLCH &&
|
|
9456
|
+
(r2.color[1] == 0 ||
|
|
9457
|
+
r2.color[0] == 0 ||
|
|
9458
|
+
r2.color[0] == colorRange[colors[currentIndex].kin == exports.ColorType.LCH ? "lch" : "oklch"].l[1]))) {
|
|
9459
|
+
r2.color[2] = r1.color[2];
|
|
9386
9460
|
}
|
|
9387
9461
|
if (hueInterpolationMethod != null) {
|
|
9388
9462
|
let hueIndex = 2;
|
|
@@ -9410,6 +9484,7 @@ function colorMix(...args) {
|
|
|
9410
9484
|
alpha: mult,
|
|
9411
9485
|
};
|
|
9412
9486
|
}
|
|
9487
|
+
// console.error({ r1, r2, r, premult1, mult1, premult2, mult2, mixedPremult, mult });
|
|
9413
9488
|
stack.push(r);
|
|
9414
9489
|
}
|
|
9415
9490
|
const result = stack.pop();
|
|
@@ -9464,16 +9539,16 @@ function colorMix(...args) {
|
|
|
9464
9539
|
};
|
|
9465
9540
|
// case "rgb":
|
|
9466
9541
|
case "hsl":
|
|
9467
|
-
|
|
9542
|
+
case "hwb":
|
|
9468
9543
|
case "lab":
|
|
9469
9544
|
case "lch":
|
|
9470
9545
|
case "oklab":
|
|
9471
9546
|
case "oklch":
|
|
9472
|
-
if (colorSpace == "hsl") {
|
|
9547
|
+
if (colorSpace == "hsl" || colorSpace == "hwb") {
|
|
9473
9548
|
// @ts-ignore
|
|
9474
9549
|
if (values[2] < 0) {
|
|
9475
9550
|
// @ts-ignore
|
|
9476
|
-
values[2] +=
|
|
9551
|
+
values[2] += 360;
|
|
9477
9552
|
}
|
|
9478
9553
|
}
|
|
9479
9554
|
else if (colorSpace == "lch" || colorSpace == "oklch") {
|
|
@@ -9501,16 +9576,72 @@ function colorMix(...args) {
|
|
|
9501
9576
|
};
|
|
9502
9577
|
if (colorSpace == "hsl") {
|
|
9503
9578
|
// @ts-ignore
|
|
9504
|
-
result.chi[0] = { typ: exports.EnumToken.AngleTokenType, val: result.chi[0].val
|
|
9579
|
+
result.chi[0] = { typ: exports.EnumToken.AngleTokenType, val: result.chi[0].val };
|
|
9505
9580
|
// @ts-ignore
|
|
9506
|
-
result.chi[1] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[1].val
|
|
9581
|
+
result.chi[1] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[1].val };
|
|
9507
9582
|
// @ts-ignore
|
|
9508
|
-
result.chi[2] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[2].val
|
|
9583
|
+
result.chi[2] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[2].val };
|
|
9509
9584
|
}
|
|
9510
9585
|
return result;
|
|
9511
9586
|
}
|
|
9512
9587
|
return null;
|
|
9513
9588
|
}
|
|
9589
|
+
function processPowerlessComponents(color) {
|
|
9590
|
+
let components;
|
|
9591
|
+
let values;
|
|
9592
|
+
switch (color.kin) {
|
|
9593
|
+
case exports.ColorType.LCH:
|
|
9594
|
+
case exports.ColorType.OKLCH:
|
|
9595
|
+
values = color.kin == exports.ColorType.LCH ? getLCHComponents(color) : getOKLCHComponents(color);
|
|
9596
|
+
components = getColorComponents(color);
|
|
9597
|
+
if (values == null || values.length < 3 || components == null) {
|
|
9598
|
+
break;
|
|
9599
|
+
}
|
|
9600
|
+
const max = color.kin == exports.ColorType.LCH ? colorRange.lch.l[1] : colorRange.oklch.l[1];
|
|
9601
|
+
// https://www.w3.org/TR/css-color-4/#specifying-lab-lch
|
|
9602
|
+
// https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch
|
|
9603
|
+
const epsilon = color.kin == exports.ColorType.LCH ? 0.0015 : 0.000004;
|
|
9604
|
+
if (values[0] < epsilon || Math.abs(values[0] - max) < epsilon) {
|
|
9605
|
+
Object.assign(components[0], { val: values[0] < epsilon ? 0 : max, typ: exports.EnumToken.NumberTokenType });
|
|
9606
|
+
Object.assign(components[1], { val: "none", typ: exports.EnumToken.IdenTokenType });
|
|
9607
|
+
Object.assign(components[2], { val: "none", typ: exports.EnumToken.IdenTokenType });
|
|
9608
|
+
setColorFlag(components[1], exports.EnumAstNodeStatus.PowerlessColorComponent);
|
|
9609
|
+
setColorFlag(components[2], exports.EnumAstNodeStatus.PowerlessColorComponent);
|
|
9610
|
+
}
|
|
9611
|
+
else if (values[1] < epsilon) {
|
|
9612
|
+
values[1] = 0;
|
|
9613
|
+
Object.assign(components[1], { val: 0, typ: exports.EnumToken.NumberTokenType });
|
|
9614
|
+
Object.assign(components[2], { val: "none", typ: exports.EnumToken.IdenTokenType });
|
|
9615
|
+
setColorFlag(components[2], exports.EnumAstNodeStatus.PowerlessColorComponent);
|
|
9616
|
+
}
|
|
9617
|
+
break;
|
|
9618
|
+
case exports.ColorType.HSL:
|
|
9619
|
+
case exports.ColorType.HWB:
|
|
9620
|
+
values = Object.values((color.kin == exports.ColorType.HSL ? hslvalues(color) : hwbvalues(color)) ?? {});
|
|
9621
|
+
components = getColorComponents(color);
|
|
9622
|
+
if (values == null || values.length < 3 || components == null) {
|
|
9623
|
+
break;
|
|
9624
|
+
}
|
|
9625
|
+
// https://www.w3.org/TR/css-color-4/#the-hsl-notation
|
|
9626
|
+
// https://www.w3.org/TR/css-color-4/#the-hwb-notation
|
|
9627
|
+
if ((color.kin == exports.ColorType.HSL && values[1] <= 0.001) ||
|
|
9628
|
+
(color.kin == exports.ColorType.HWB && values[1] + values[2] >= 99.999)) {
|
|
9629
|
+
Object.assign(components[0], { val: "none", typ: exports.EnumToken.IdenTokenType });
|
|
9630
|
+
setColorFlag(components[0], exports.EnumAstNodeStatus.PowerlessColorComponent);
|
|
9631
|
+
}
|
|
9632
|
+
break;
|
|
9633
|
+
}
|
|
9634
|
+
// console.error({ color: color.chi ?? color, values });
|
|
9635
|
+
return color;
|
|
9636
|
+
}
|
|
9637
|
+
function setColorFlag(token, flag) {
|
|
9638
|
+
if (token[STATE] == null) {
|
|
9639
|
+
token[STATE] = flag;
|
|
9640
|
+
}
|
|
9641
|
+
else {
|
|
9642
|
+
token[STATE] |= flag;
|
|
9643
|
+
}
|
|
9644
|
+
}
|
|
9514
9645
|
|
|
9515
9646
|
/**
|
|
9516
9647
|
* Options for the walk function
|
|
@@ -9548,6 +9679,7 @@ exports.WalkerEvent = void 0;
|
|
|
9548
9679
|
*/
|
|
9549
9680
|
WalkerEvent[WalkerEvent["Leave"] = 2] = "Leave";
|
|
9550
9681
|
})(exports.WalkerEvent || (exports.WalkerEvent = {}));
|
|
9682
|
+
const maxQueueLength = 25000;
|
|
9551
9683
|
/**
|
|
9552
9684
|
* Walk ast nodes
|
|
9553
9685
|
* @param node initial node
|
|
@@ -9651,6 +9783,10 @@ function* walk(node, filter, reverse) {
|
|
|
9651
9783
|
},
|
|
9652
9784
|
};
|
|
9653
9785
|
while ((node = parents[i++])) {
|
|
9786
|
+
if (i > maxQueueLength) {
|
|
9787
|
+
parents.splice(0, maxQueueLength);
|
|
9788
|
+
i -= maxQueueLength;
|
|
9789
|
+
}
|
|
9654
9790
|
let option = null;
|
|
9655
9791
|
if (filter != null) {
|
|
9656
9792
|
// @ts-expect-error
|
|
@@ -9794,6 +9930,10 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
9794
9930
|
while (++i < stack.length) {
|
|
9795
9931
|
value = stack[i];
|
|
9796
9932
|
option = null;
|
|
9933
|
+
if (i > maxQueueLength) {
|
|
9934
|
+
stack.splice(0, maxQueueLength);
|
|
9935
|
+
i -= maxQueueLength;
|
|
9936
|
+
}
|
|
9797
9937
|
if (filter.fn != null && eventType & exports.WalkerEvent.Enter) {
|
|
9798
9938
|
const isValid = filter.type == null ||
|
|
9799
9939
|
value.typ == filter.type ||
|
|
@@ -11026,7 +11166,36 @@ function parseRelativeColorComponents(relativeKeys, original, rExp, gExp, bExp,
|
|
|
11026
11166
|
: aExp),
|
|
11027
11167
|
};
|
|
11028
11168
|
const result = computeComponentValue(keys, values);
|
|
11169
|
+
if (result != null) {
|
|
11170
|
+
if ("hsl" == relativeKeys) {
|
|
11171
|
+
Object.assign(result.s, {
|
|
11172
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
11173
|
+
// @ts-ignore
|
|
11174
|
+
val: result.s.val * 100,
|
|
11175
|
+
});
|
|
11176
|
+
Object.assign(result.l, {
|
|
11177
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
11178
|
+
// @ts-ignore
|
|
11179
|
+
val: result.l.val * 100,
|
|
11180
|
+
});
|
|
11181
|
+
}
|
|
11182
|
+
else if ("hwb" == relativeKeys) {
|
|
11183
|
+
// @ts
|
|
11184
|
+
Object.assign(result.w, {
|
|
11185
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
11186
|
+
// @ts-ignore
|
|
11187
|
+
val: result.w.val * 100,
|
|
11188
|
+
});
|
|
11189
|
+
Object.assign(result.b, {
|
|
11190
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
11191
|
+
// @ts-ignore
|
|
11192
|
+
val: result.b.val * 100,
|
|
11193
|
+
});
|
|
11194
|
+
}
|
|
11195
|
+
}
|
|
11196
|
+
// @ts-ignore
|
|
11029
11197
|
if (result?.alpha?.typ == exports.EnumToken.NumberTokenType && result.alpha.val === 1) {
|
|
11198
|
+
// @ts-ignore
|
|
11030
11199
|
const { alpha, ...components } = result;
|
|
11031
11200
|
return components;
|
|
11032
11201
|
}
|
|
@@ -15168,7 +15337,6 @@ function getAngle(token) {
|
|
|
15168
15337
|
return +token.val;
|
|
15169
15338
|
}
|
|
15170
15339
|
}
|
|
15171
|
-
// @ts-ignore
|
|
15172
15340
|
return token.val / 360;
|
|
15173
15341
|
}
|
|
15174
15342
|
|
|
@@ -17026,9 +17194,7 @@ class ComputePrefixFeature {
|
|
|
17026
17194
|
}
|
|
17027
17195
|
}
|
|
17028
17196
|
run(node) {
|
|
17029
|
-
if (node[STATE]
|
|
17030
|
-
node[STATE] == exports.EnumAstNodeStatus.Invalid ||
|
|
17031
|
-
node[STATE] == exports.EnumAstNodeStatus.Malformed) {
|
|
17197
|
+
if (node[STATE] & (exports.EnumAstNodeStatus.Disallowed | exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.Malformed)) {
|
|
17032
17198
|
return null;
|
|
17033
17199
|
}
|
|
17034
17200
|
if (node.typ == exports.EnumToken.RuleNodeType) {
|
|
@@ -19743,7 +19909,8 @@ class PropertyMap {
|
|
|
19743
19909
|
const tokens = {};
|
|
19744
19910
|
const values = [];
|
|
19745
19911
|
const val = [[]];
|
|
19746
|
-
for (const curr of this.declarations.get(this.config.shorthand).val) {
|
|
19912
|
+
for (const curr of this.declarations.get(this.config.shorthand).val) {
|
|
19913
|
+
// @ts-ignore
|
|
19747
19914
|
// @ts-ignore
|
|
19748
19915
|
if (separator != null && separator.typ == curr.typ && separator.val == curr.val) {
|
|
19749
19916
|
val.push([]);
|
|
@@ -20687,9 +20854,8 @@ class PropertyList {
|
|
|
20687
20854
|
let result;
|
|
20688
20855
|
for (const declaration of declarations) {
|
|
20689
20856
|
name = declaration.typ != exports.EnumToken.DeclarationNodeType ? null : declaration.nam;
|
|
20690
|
-
if (declaration[STATE]
|
|
20691
|
-
|
|
20692
|
-
declaration[STATE] == exports.EnumAstNodeStatus.ValidationFailed ||
|
|
20857
|
+
if (declaration[STATE] &
|
|
20858
|
+
(exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.Unknown | exports.EnumAstNodeStatus.ValidationFailed) ||
|
|
20693
20859
|
declaration.typ != exports.EnumToken.DeclarationNodeType ||
|
|
20694
20860
|
equalsIgnoreCase("composes", name) ||
|
|
20695
20861
|
(typeof this.options.removeDuplicateDeclarations === "string" &&
|
|
@@ -20708,17 +20874,17 @@ class PropertyList {
|
|
|
20708
20874
|
this.declarations.set(declaration.nam, declaration);
|
|
20709
20875
|
continue;
|
|
20710
20876
|
}
|
|
20711
|
-
if (declaration[STATE]
|
|
20877
|
+
if (declaration[STATE] & exports.EnumAstNodeStatus.Unvalidated) {
|
|
20712
20878
|
syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, declaration.nam.toLowerCase());
|
|
20713
20879
|
if (syntaxRules != null) {
|
|
20714
20880
|
result = matchAllSyntaxes(syntaxRules, createValidationContext(declaration.val), this.options);
|
|
20715
|
-
declaration[STATE]
|
|
20716
|
-
? exports.EnumAstNodeStatus.Validated
|
|
20717
|
-
|
|
20881
|
+
declaration[STATE] |=
|
|
20882
|
+
(result.success ? exports.EnumAstNodeStatus.Validated : exports.EnumAstNodeStatus.ValidationFailed) &
|
|
20883
|
+
~exports.EnumAstNodeStatus.Unvalidated;
|
|
20718
20884
|
}
|
|
20719
20885
|
}
|
|
20720
20886
|
// do not compute shorthand for invalid declarations
|
|
20721
|
-
if (declaration[STATE]
|
|
20887
|
+
if (!(declaration[STATE] & exports.EnumAstNodeStatus.Validated)) {
|
|
20722
20888
|
this.declarations.set(objectHash(declaration), declaration);
|
|
20723
20889
|
continue;
|
|
20724
20890
|
}
|
|
@@ -20748,6 +20914,16 @@ class PropertyList {
|
|
|
20748
20914
|
// @ts-ignore
|
|
20749
20915
|
shorthand = config.property[propertyName];
|
|
20750
20916
|
}
|
|
20917
|
+
if (this.declarations.has(shorthand)) {
|
|
20918
|
+
let existing = this.declarations.get(shorthand);
|
|
20919
|
+
if (existing instanceof PropertySet || existing instanceof PropertyMap) {
|
|
20920
|
+
existing = existing.declarations.get(declaration.nam);
|
|
20921
|
+
}
|
|
20922
|
+
if (existing?.[STATE] & exports.EnumAstNodeStatus.ImportantDeclaration &&
|
|
20923
|
+
declaration[STATE] & ~exports.EnumAstNodeStatus.ImportantDeclaration) {
|
|
20924
|
+
continue;
|
|
20925
|
+
}
|
|
20926
|
+
}
|
|
20751
20927
|
// @ts-ignore
|
|
20752
20928
|
if (shortHandType == "map") {
|
|
20753
20929
|
let owner = this;
|
|
@@ -22389,7 +22565,7 @@ class TransformCssFeature {
|
|
|
22389
22565
|
for (; i < ast.chi.length; i++) {
|
|
22390
22566
|
// @ts-ignore
|
|
22391
22567
|
node = ast.chi[i];
|
|
22392
|
-
if (node[STATE]
|
|
22568
|
+
if (node[STATE] & (exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.ValidationFailed)) {
|
|
22393
22569
|
continue;
|
|
22394
22570
|
}
|
|
22395
22571
|
if (node.typ != exports.EnumToken.DeclarationNodeType ||
|
|
@@ -24332,11 +24508,12 @@ function reduceRuleSelector(node) {
|
|
|
24332
24508
|
* @private
|
|
24333
24509
|
*/
|
|
24334
24510
|
function expand(ast) {
|
|
24335
|
-
if (ast[STATE]
|
|
24336
|
-
|
|
24337
|
-
|
|
24338
|
-
|
|
24339
|
-
|
|
24511
|
+
if (ast[STATE] &
|
|
24512
|
+
(exports.EnumAstNodeStatus.Invalid |
|
|
24513
|
+
exports.EnumAstNodeStatus.Disallowed |
|
|
24514
|
+
exports.EnumAstNodeStatus.Unknown |
|
|
24515
|
+
exports.EnumAstNodeStatus.Unparsed |
|
|
24516
|
+
exports.EnumAstNodeStatus.Malformed)) {
|
|
24340
24517
|
return ast;
|
|
24341
24518
|
}
|
|
24342
24519
|
const result = Object.assign(cloneNode(ast), { chi: [] });
|
|
@@ -24384,11 +24561,12 @@ function expand(ast) {
|
|
|
24384
24561
|
return result;
|
|
24385
24562
|
}
|
|
24386
24563
|
function expandRule(node) {
|
|
24387
|
-
if (node[STATE]
|
|
24388
|
-
|
|
24389
|
-
|
|
24390
|
-
|
|
24391
|
-
|
|
24564
|
+
if (node[STATE] &
|
|
24565
|
+
(exports.EnumAstNodeStatus.Invalid |
|
|
24566
|
+
exports.EnumAstNodeStatus.Disallowed |
|
|
24567
|
+
exports.EnumAstNodeStatus.Unknown |
|
|
24568
|
+
exports.EnumAstNodeStatus.Unparsed |
|
|
24569
|
+
exports.EnumAstNodeStatus.Malformed)) {
|
|
24392
24570
|
return [node];
|
|
24393
24571
|
}
|
|
24394
24572
|
const ast = Object.assign(cloneNode(node), { chi: node.chi.slice() });
|
|
@@ -26648,17 +26826,20 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
|
|
|
26648
26826
|
? ""
|
|
26649
26827
|
: token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
|
|
26650
26828
|
":" +
|
|
26829
|
+
(options.indent ?? "") +
|
|
26651
26830
|
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "");
|
|
26652
26831
|
case exports.EnumToken.IfElseConditionTokenType:
|
|
26653
|
-
return renderValue(token.l) +
|
|
26832
|
+
return (renderValue(token.l, options, cache, reducer) +
|
|
26833
|
+
(options.indent ?? "") +
|
|
26834
|
+
renderValue(token.r, options, cache, reducer));
|
|
26654
26835
|
case exports.EnumToken.DeclarationNodeType:
|
|
26655
26836
|
return (token.nam +
|
|
26656
26837
|
":" +
|
|
26657
|
-
(options.minifyValues ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
|
|
26838
|
+
(options.minifyValues ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
|
|
26658
26839
|
case exports.EnumToken.MediaQueryUnaryFeatureTokenType:
|
|
26659
26840
|
return (renderValue(token.l, options, cache, reducer) +
|
|
26660
26841
|
" " +
|
|
26661
|
-
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
|
|
26842
|
+
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
|
|
26662
26843
|
case exports.EnumToken.MediaQueryConditionTokenType: {
|
|
26663
26844
|
const indent = token.op.typ == exports.EnumToken.LtTokenType ||
|
|
26664
26845
|
token.op.typ == exports.EnumToken.GtTokenType ||
|
|
@@ -26672,14 +26853,14 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
|
|
|
26672
26853
|
indent +
|
|
26673
26854
|
renderValue(token.op, options, cache, reducer) +
|
|
26674
26855
|
indent +
|
|
26675
|
-
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
|
|
26856
|
+
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
|
|
26676
26857
|
}
|
|
26677
26858
|
case exports.EnumToken.MediaRangeQueryTokenType:
|
|
26678
|
-
return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache), "") +
|
|
26679
|
-
renderValue(token.op1) +
|
|
26859
|
+
return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
|
|
26860
|
+
renderValue(token.op1, options, cache, reducer) +
|
|
26680
26861
|
token.val.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
|
|
26681
|
-
renderValue(token.op2) +
|
|
26682
|
-
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
|
|
26862
|
+
renderValue(token.op2, options, cache, reducer) +
|
|
26863
|
+
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
|
|
26683
26864
|
case exports.EnumToken.MediaFeatureTokenType:
|
|
26684
26865
|
return token.val;
|
|
26685
26866
|
case exports.EnumToken.NotTokenType:
|
|
@@ -28883,6 +29064,7 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
28883
29064
|
let rules = null;
|
|
28884
29065
|
let syntaxRules = null;
|
|
28885
29066
|
let success = true;
|
|
29067
|
+
let hasImportantFlag = false;
|
|
28886
29068
|
let validate = typeof options.validation === "boolean" ? options.validation : !!options.validation;
|
|
28887
29069
|
if (renamedStandardProperties.has(name.val)) {
|
|
28888
29070
|
name.val = renamedStandardProperties.get(name.val);
|
|
@@ -29184,6 +29366,9 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
29184
29366
|
}
|
|
29185
29367
|
}
|
|
29186
29368
|
break;
|
|
29369
|
+
case exports.EnumToken.ImportantTokenType:
|
|
29370
|
+
hasImportantFlag = true;
|
|
29371
|
+
break;
|
|
29187
29372
|
}
|
|
29188
29373
|
if (trimTokenSpace$1.has(token.typ)) {
|
|
29189
29374
|
if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
|
|
@@ -29250,6 +29435,9 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
29250
29435
|
}
|
|
29251
29436
|
name[STATE] = exports.EnumAstNodeStatus.Unknown;
|
|
29252
29437
|
name[ERRORS] = result?.errors ?? [];
|
|
29438
|
+
if (hasImportantFlag) {
|
|
29439
|
+
name[STATE] |= exports.EnumAstNodeStatus.ImportantDeclaration;
|
|
29440
|
+
}
|
|
29253
29441
|
// @ts-expect-error
|
|
29254
29442
|
return Object.assign(name, {
|
|
29255
29443
|
typ: exports.EnumToken.DeclarationNodeType,
|
|
@@ -29287,6 +29475,9 @@ function parseDeclaration(tokens, parent, options, errors) {
|
|
|
29287
29475
|
: exports.EnumAstNodeStatus.Validated
|
|
29288
29476
|
: exports.EnumAstNodeStatus.ValidationFailed;
|
|
29289
29477
|
name[ERRORS] = result?.errors ?? [];
|
|
29478
|
+
if (hasImportantFlag) {
|
|
29479
|
+
name[STATE] |= exports.EnumAstNodeStatus.ImportantDeclaration;
|
|
29480
|
+
}
|
|
29290
29481
|
// @ts-expect-error
|
|
29291
29482
|
return Object.assign(name, {
|
|
29292
29483
|
typ: exports.EnumToken.DeclarationNodeType,
|
|
@@ -31514,14 +31705,14 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
31514
31705
|
if (invalidNodes.length > 0) {
|
|
31515
31706
|
let count = invalidNodes.length;
|
|
31516
31707
|
for (const { node, parent } of walk(ast)) {
|
|
31517
|
-
if (options.lenient && node[STATE]
|
|
31708
|
+
if (options.lenient && node[STATE] & exports.EnumAstNodeStatus.Unknown) {
|
|
31518
31709
|
continue;
|
|
31519
31710
|
}
|
|
31520
|
-
if (node[STATE]
|
|
31521
|
-
node[STATE]
|
|
31522
|
-
node[STATE]
|
|
31523
|
-
node[STATE]
|
|
31524
|
-
node[STATE]
|
|
31711
|
+
if (node[STATE] & exports.EnumAstNodeStatus.Invalid ||
|
|
31712
|
+
node[STATE] & exports.EnumAstNodeStatus.Unknown ||
|
|
31713
|
+
node[STATE] & exports.EnumAstNodeStatus.Unparsed ||
|
|
31714
|
+
node[STATE] & exports.EnumAstNodeStatus.Malformed ||
|
|
31715
|
+
node[STATE] & exports.EnumAstNodeStatus.Disallowed) {
|
|
31525
31716
|
// @ts-ignore
|
|
31526
31717
|
parent.chi.splice(parent.chi.indexOf(node), 1);
|
|
31527
31718
|
node[PARENT] = null;
|
|
@@ -32509,14 +32700,14 @@ async function doParse(iter, options = {}) {
|
|
|
32509
32700
|
if (invalidNodes.length > 0) {
|
|
32510
32701
|
let count = invalidNodes.length;
|
|
32511
32702
|
for (const { node, parent } of walk(ast)) {
|
|
32512
|
-
if (options.lenient && node[STATE]
|
|
32703
|
+
if (options.lenient && node[STATE] & exports.EnumAstNodeStatus.Unknown) {
|
|
32513
32704
|
continue;
|
|
32514
32705
|
}
|
|
32515
|
-
if (node[STATE]
|
|
32516
|
-
node[STATE]
|
|
32517
|
-
node[STATE]
|
|
32518
|
-
node[STATE]
|
|
32519
|
-
node[STATE]
|
|
32706
|
+
if (node[STATE] & exports.EnumAstNodeStatus.Invalid ||
|
|
32707
|
+
node[STATE] & exports.EnumAstNodeStatus.Unknown ||
|
|
32708
|
+
node[STATE] & exports.EnumAstNodeStatus.Unparsed ||
|
|
32709
|
+
node[STATE] & exports.EnumAstNodeStatus.Malformed ||
|
|
32710
|
+
node[STATE] & exports.EnumAstNodeStatus.Disallowed) {
|
|
32520
32711
|
// @ts-ignore
|
|
32521
32712
|
parent.chi.splice(parent.chi.indexOf(node), 1);
|
|
32522
32713
|
node[PARENT] = null;
|
|
@@ -33247,11 +33438,12 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
33247
33438
|
if (node == null) {
|
|
33248
33439
|
return null;
|
|
33249
33440
|
}
|
|
33250
|
-
if (node[STATE]
|
|
33251
|
-
|
|
33252
|
-
|
|
33253
|
-
|
|
33254
|
-
|
|
33441
|
+
if (node[STATE] &
|
|
33442
|
+
(exports.EnumAstNodeStatus.Invalid |
|
|
33443
|
+
exports.EnumAstNodeStatus.Disallowed |
|
|
33444
|
+
exports.EnumAstNodeStatus.Unknown |
|
|
33445
|
+
exports.EnumAstNodeStatus.Unparsed |
|
|
33446
|
+
exports.EnumAstNodeStatus.Malformed)) {
|
|
33255
33447
|
invalidNodes.push(node);
|
|
33256
33448
|
}
|
|
33257
33449
|
stats.nodesCount++;
|
|
@@ -33269,11 +33461,11 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
33269
33461
|
context.chi.push(node);
|
|
33270
33462
|
node[PARENT] = context;
|
|
33271
33463
|
node[ROOT] = context[ROOT];
|
|
33272
|
-
if (node[STATE]
|
|
33273
|
-
node[STATE]
|
|
33274
|
-
node[STATE]
|
|
33275
|
-
node[STATE]
|
|
33276
|
-
node[STATE]
|
|
33464
|
+
if (node[STATE] & exports.EnumAstNodeStatus.Invalid ||
|
|
33465
|
+
node[STATE] & exports.EnumAstNodeStatus.Disallowed ||
|
|
33466
|
+
node[STATE] & exports.EnumAstNodeStatus.Unknown ||
|
|
33467
|
+
node[STATE] & exports.EnumAstNodeStatus.Unparsed ||
|
|
33468
|
+
node[STATE] & exports.EnumAstNodeStatus.Malformed) {
|
|
33277
33469
|
invalidNodes.push(node);
|
|
33278
33470
|
}
|
|
33279
33471
|
return node;
|
|
@@ -33283,7 +33475,9 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
33283
33475
|
node[PARENT] = context;
|
|
33284
33476
|
node[ROOT] = context[ROOT];
|
|
33285
33477
|
if (context.typ === exports.EnumToken.StyleSheetNodeType && node.typ === exports.EnumToken.DeclarationNodeType) {
|
|
33286
|
-
node[STATE]
|
|
33478
|
+
node[STATE] |=
|
|
33479
|
+
exports.EnumAstNodeStatus.Invalid &
|
|
33480
|
+
~(exports.EnumAstNodeStatus.Validated | exports.EnumAstNodeStatus.Unvalidated | exports.EnumAstNodeStatus.Unparsed);
|
|
33287
33481
|
errors.push({
|
|
33288
33482
|
message: "<declaration> not allowed in <stylesheet>",
|
|
33289
33483
|
action: "drop",
|
|
@@ -33294,11 +33488,12 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
|
|
|
33294
33488
|
else if (options.lenient || node.typ === exports.EnumToken.DeclarationNodeType) {
|
|
33295
33489
|
context.chi.push(node);
|
|
33296
33490
|
}
|
|
33297
|
-
if (node[STATE]
|
|
33298
|
-
|
|
33299
|
-
|
|
33300
|
-
|
|
33301
|
-
|
|
33491
|
+
if (node[STATE] &
|
|
33492
|
+
(exports.EnumAstNodeStatus.Invalid |
|
|
33493
|
+
exports.EnumAstNodeStatus.Disallowed |
|
|
33494
|
+
exports.EnumAstNodeStatus.Unknown |
|
|
33495
|
+
exports.EnumAstNodeStatus.Unparsed |
|
|
33496
|
+
exports.EnumAstNodeStatus.Malformed)) {
|
|
33302
33497
|
invalidNodes.push(node);
|
|
33303
33498
|
}
|
|
33304
33499
|
}
|