@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-umd-web.js
CHANGED
|
@@ -24,35 +24,43 @@
|
|
|
24
24
|
/**
|
|
25
25
|
* Node passed validation
|
|
26
26
|
*/
|
|
27
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Validated"] =
|
|
27
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Validated"] = 1] = "Validated";
|
|
28
28
|
/**
|
|
29
29
|
* Node is invalid
|
|
30
30
|
*/
|
|
31
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Invalid"] =
|
|
31
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Invalid"] = 2] = "Invalid";
|
|
32
32
|
/**
|
|
33
33
|
* node is not validated
|
|
34
34
|
*/
|
|
35
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Unvalidated"] =
|
|
35
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Unvalidated"] = 4] = "Unvalidated";
|
|
36
36
|
/**
|
|
37
37
|
* Node did not pass validation, but is preserved.
|
|
38
38
|
*/
|
|
39
|
-
EnumAstNodeStatus[EnumAstNodeStatus["ValidationFailed"] =
|
|
39
|
+
EnumAstNodeStatus[EnumAstNodeStatus["ValidationFailed"] = 8] = "ValidationFailed";
|
|
40
40
|
/**
|
|
41
41
|
* Parsing the node is not supported yet or the node syntax definition does not exist.
|
|
42
42
|
*/
|
|
43
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Unknown"] =
|
|
43
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Unknown"] = 16] = "Unknown";
|
|
44
44
|
/**
|
|
45
45
|
* Failed to parse the node.
|
|
46
46
|
*/
|
|
47
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Unparsed"] =
|
|
47
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Unparsed"] = 32] = "Unparsed";
|
|
48
48
|
/**
|
|
49
49
|
* Node is disallowed in the context
|
|
50
50
|
*/
|
|
51
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Disallowed"] =
|
|
51
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Disallowed"] = 64] = "Disallowed";
|
|
52
52
|
/**
|
|
53
53
|
* Node is malformed
|
|
54
54
|
*/
|
|
55
|
-
EnumAstNodeStatus[EnumAstNodeStatus["Malformed"] =
|
|
55
|
+
EnumAstNodeStatus[EnumAstNodeStatus["Malformed"] = 128] = "Malformed";
|
|
56
|
+
/**
|
|
57
|
+
* Important declaration
|
|
58
|
+
*/
|
|
59
|
+
EnumAstNodeStatus[EnumAstNodeStatus["ImportantDeclaration"] = 256] = "ImportantDeclaration";
|
|
60
|
+
/**
|
|
61
|
+
* Color component without unit
|
|
62
|
+
*/
|
|
63
|
+
EnumAstNodeStatus[EnumAstNodeStatus["PowerlessColorComponent"] = 512] = "PowerlessColorComponent";
|
|
56
64
|
})(exports.EnumAstNodeStatus || (exports.EnumAstNodeStatus = {}));
|
|
57
65
|
/**
|
|
58
66
|
* Enum of validation levels
|
|
@@ -7485,7 +7493,7 @@
|
|
|
7485
7493
|
{ typ: exports.EnumToken.NumberTokenType, val: values[1] },
|
|
7486
7494
|
{ typ: exports.EnumToken.NumberTokenType, val: values[2] },
|
|
7487
7495
|
];
|
|
7488
|
-
if (values.length == 4) {
|
|
7496
|
+
if (values.length == 4 && values[3] != 1) {
|
|
7489
7497
|
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
|
|
7490
7498
|
typ: exports.EnumToken.PercentageTokenType,
|
|
7491
7499
|
val: values[3] * 100,
|
|
@@ -7874,6 +7882,222 @@
|
|
|
7874
7882
|
return xyz.map((value, i) => value * D50[i]);
|
|
7875
7883
|
}
|
|
7876
7884
|
|
|
7885
|
+
function rgb2hwbToken(token) {
|
|
7886
|
+
const values = rgb2hwbvalues(token);
|
|
7887
|
+
if (values == null) {
|
|
7888
|
+
return null;
|
|
7889
|
+
}
|
|
7890
|
+
return hwbToken(values);
|
|
7891
|
+
}
|
|
7892
|
+
function hsl2hwbToken(token) {
|
|
7893
|
+
const values = hsl2hwbvalues(token);
|
|
7894
|
+
if (values == null) {
|
|
7895
|
+
return null;
|
|
7896
|
+
}
|
|
7897
|
+
// console.error(new Error("hsl2hwbToken"));
|
|
7898
|
+
return hwbToken(values);
|
|
7899
|
+
}
|
|
7900
|
+
function cmyk2hwbToken(token) {
|
|
7901
|
+
const values = cmyk2hwbvalues(token);
|
|
7902
|
+
if (values == null) {
|
|
7903
|
+
return null;
|
|
7904
|
+
}
|
|
7905
|
+
return hwbToken(values);
|
|
7906
|
+
}
|
|
7907
|
+
function oklab2hwbToken(token) {
|
|
7908
|
+
const values = oklab2hwbvalues(token);
|
|
7909
|
+
if (values == null) {
|
|
7910
|
+
return null;
|
|
7911
|
+
}
|
|
7912
|
+
return hwbToken(values);
|
|
7913
|
+
}
|
|
7914
|
+
function oklch2hwbToken(token) {
|
|
7915
|
+
const values = oklch2hwbvalues(token);
|
|
7916
|
+
if (values == null) {
|
|
7917
|
+
return null;
|
|
7918
|
+
}
|
|
7919
|
+
return hwbToken(values);
|
|
7920
|
+
}
|
|
7921
|
+
function lab2hwbToken(token) {
|
|
7922
|
+
const values = lab2hwbvalues(token);
|
|
7923
|
+
if (values == null) {
|
|
7924
|
+
return null;
|
|
7925
|
+
}
|
|
7926
|
+
return hwbToken(values);
|
|
7927
|
+
}
|
|
7928
|
+
function lch2hwbToken(token) {
|
|
7929
|
+
const values = lch2hwbvalues(token);
|
|
7930
|
+
if (values == null) {
|
|
7931
|
+
return null;
|
|
7932
|
+
}
|
|
7933
|
+
return hwbToken(values);
|
|
7934
|
+
}
|
|
7935
|
+
function color2hwbToken(token) {
|
|
7936
|
+
const values = color2hwbvalues(token);
|
|
7937
|
+
if (values == null) {
|
|
7938
|
+
return null;
|
|
7939
|
+
}
|
|
7940
|
+
return hwbToken(values);
|
|
7941
|
+
}
|
|
7942
|
+
function hwbToken(values) {
|
|
7943
|
+
const chi = [
|
|
7944
|
+
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
7945
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[1] },
|
|
7946
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[2] },
|
|
7947
|
+
];
|
|
7948
|
+
if (values.length == 4) {
|
|
7949
|
+
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
|
|
7950
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
7951
|
+
val: values[3] * 100,
|
|
7952
|
+
});
|
|
7953
|
+
}
|
|
7954
|
+
return {
|
|
7955
|
+
typ: exports.EnumToken.ColorTokenType,
|
|
7956
|
+
val: "hwb",
|
|
7957
|
+
chi,
|
|
7958
|
+
kin: exports.ColorType.HWB,
|
|
7959
|
+
};
|
|
7960
|
+
}
|
|
7961
|
+
function rgb2hwbvalues(token) {
|
|
7962
|
+
const values = getColorComponents(token).map((t, index) => {
|
|
7963
|
+
if (index == 3) {
|
|
7964
|
+
return getNumber(t);
|
|
7965
|
+
}
|
|
7966
|
+
return getNumber(t) / 255;
|
|
7967
|
+
});
|
|
7968
|
+
// @ts-ignore
|
|
7969
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
7970
|
+
}
|
|
7971
|
+
function cmyk2hwbvalues(token) {
|
|
7972
|
+
const values = cmyk2srgbvalues(token);
|
|
7973
|
+
return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
7974
|
+
}
|
|
7975
|
+
function hsl2hwbvalues(token) {
|
|
7976
|
+
const values = hslvalues(token);
|
|
7977
|
+
if (values == null) {
|
|
7978
|
+
return null;
|
|
7979
|
+
}
|
|
7980
|
+
// @ts-ignore
|
|
7981
|
+
return hslvalues2hwbvalues(values.h, values.s, values.l, values.a);
|
|
7982
|
+
}
|
|
7983
|
+
function lab2hwbvalues(token) {
|
|
7984
|
+
const values = lab2srgbvalues(token);
|
|
7985
|
+
if (values == null) {
|
|
7986
|
+
return null;
|
|
7987
|
+
}
|
|
7988
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
7989
|
+
}
|
|
7990
|
+
function lch2hwbvalues(token) {
|
|
7991
|
+
const values = lch2srgbvalues(token);
|
|
7992
|
+
if (values == null) {
|
|
7993
|
+
return null;
|
|
7994
|
+
}
|
|
7995
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
7996
|
+
}
|
|
7997
|
+
function oklab2hwbvalues(token) {
|
|
7998
|
+
const values = oklab2srgbvalues(token);
|
|
7999
|
+
if (values == null) {
|
|
8000
|
+
return null;
|
|
8001
|
+
}
|
|
8002
|
+
// @ts-ignore
|
|
8003
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8004
|
+
}
|
|
8005
|
+
function oklch2hwbvalues(token) {
|
|
8006
|
+
const values = oklch2srgbvalues(token);
|
|
8007
|
+
// @ts-ignore
|
|
8008
|
+
return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8009
|
+
}
|
|
8010
|
+
function color2hwbvalues(token) {
|
|
8011
|
+
const values = color2srgbvalues(token);
|
|
8012
|
+
if (values == null) {
|
|
8013
|
+
return null;
|
|
8014
|
+
}
|
|
8015
|
+
// @ts-ignore
|
|
8016
|
+
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8017
|
+
}
|
|
8018
|
+
function hwbvalues(token) {
|
|
8019
|
+
const components = getColorComponents(token);
|
|
8020
|
+
if (components == null) {
|
|
8021
|
+
return null;
|
|
8022
|
+
}
|
|
8023
|
+
let t;
|
|
8024
|
+
// @ts-ignore
|
|
8025
|
+
let h = getAngle(components[0]) * 360;
|
|
8026
|
+
// @ts-ignore
|
|
8027
|
+
t = components[1];
|
|
8028
|
+
// @ts-ignore
|
|
8029
|
+
let w = getNumber(t);
|
|
8030
|
+
// @ts-ignore
|
|
8031
|
+
t = components[2];
|
|
8032
|
+
// @ts-ignore
|
|
8033
|
+
let b = getNumber(t);
|
|
8034
|
+
// if (components[1].typ == EnumToken.NumberTokenType) {
|
|
8035
|
+
w *= 100;
|
|
8036
|
+
// }
|
|
8037
|
+
// if (components[2].typ == EnumToken.NumberTokenType) {
|
|
8038
|
+
b *= 100;
|
|
8039
|
+
// }
|
|
8040
|
+
let a = null;
|
|
8041
|
+
if (components.length == 4) {
|
|
8042
|
+
// @ts-ignore
|
|
8043
|
+
t = components[3];
|
|
8044
|
+
// @ts-ignore
|
|
8045
|
+
a = getNumber(t);
|
|
8046
|
+
}
|
|
8047
|
+
return a == null ? { h, w, b } : { h, w, b, a };
|
|
8048
|
+
}
|
|
8049
|
+
function srgb2hwb(r, g, b, a = null, fallback = 0) {
|
|
8050
|
+
// 1. Clamp inputs to the standard web-safe sRGB gamut [0.0, 1.0]
|
|
8051
|
+
const rClamp = Math.min(1, Math.max(0, r));
|
|
8052
|
+
const gClamp = Math.min(1, Math.max(0, g));
|
|
8053
|
+
const bClamp = Math.min(1, Math.max(0, b));
|
|
8054
|
+
const cMax = Math.max(rClamp, gClamp, bClamp);
|
|
8055
|
+
const cMin = Math.min(rClamp, gClamp, bClamp);
|
|
8056
|
+
const delta = cMax - cMin;
|
|
8057
|
+
// 2. Whiteness and Blackness calculations
|
|
8058
|
+
const w = cMin;
|
|
8059
|
+
const bl = 1 - cMax;
|
|
8060
|
+
// 3. Calculate Hue
|
|
8061
|
+
let h = 0;
|
|
8062
|
+
if (delta !== 0) {
|
|
8063
|
+
if (cMax === rClamp) {
|
|
8064
|
+
h = 60 * (((gClamp - bClamp) / delta) % 6);
|
|
8065
|
+
}
|
|
8066
|
+
else if (cMax === gClamp) {
|
|
8067
|
+
h = 60 * ((bClamp - rClamp) / delta + 2);
|
|
8068
|
+
}
|
|
8069
|
+
else if (cMax === bClamp) {
|
|
8070
|
+
h = 60 * ((rClamp - gClamp) / delta + 4);
|
|
8071
|
+
}
|
|
8072
|
+
if (h < 0) {
|
|
8073
|
+
h += 360;
|
|
8074
|
+
}
|
|
8075
|
+
}
|
|
8076
|
+
const result = [h, w * 100, bl * 100];
|
|
8077
|
+
if (a != null) {
|
|
8078
|
+
result.push(a);
|
|
8079
|
+
}
|
|
8080
|
+
return result;
|
|
8081
|
+
}
|
|
8082
|
+
function hslvalues2hwbvalues(h, s, l, a = null) {
|
|
8083
|
+
const sNorm = s / 100;
|
|
8084
|
+
const lNorm = l / 100;
|
|
8085
|
+
// Keep Hue cleanly bound to standard circle loops
|
|
8086
|
+
const hue = ((h % 360) + 360) % 360;
|
|
8087
|
+
// 1. Compute the intermediate HSV Value component (brightness peak)
|
|
8088
|
+
const v = lNorm + sNorm * Math.min(lNorm, 1 - lNorm);
|
|
8089
|
+
// 2. Compute Chroma
|
|
8090
|
+
const chroma = 2 * (v - lNorm);
|
|
8091
|
+
// 3. Extract Whiteness and Blackness
|
|
8092
|
+
const w = v - chroma;
|
|
8093
|
+
const b = 1 - v;
|
|
8094
|
+
const hwb = [hue, w * 100, b * 100];
|
|
8095
|
+
if (a != null && a != 1) {
|
|
8096
|
+
hwb.push(a);
|
|
8097
|
+
}
|
|
8098
|
+
return hwb;
|
|
8099
|
+
}
|
|
8100
|
+
|
|
7877
8101
|
// from https://www.w3.org/TR/css-color-4/#color-conversion-code
|
|
7878
8102
|
// srgb-linear -> srgb
|
|
7879
8103
|
// 0 <= r, g, b <= 1
|
|
@@ -7947,25 +8171,59 @@
|
|
|
7947
8171
|
return lsrgb2srgbvalues(values[0], values[1], values[2], alpha);
|
|
7948
8172
|
}
|
|
7949
8173
|
function hwb2srgbvalues(token) {
|
|
7950
|
-
const { h
|
|
7951
|
-
if (
|
|
8174
|
+
const { h, w, b, a } = hwbvalues(token) ?? {};
|
|
8175
|
+
if (h == null || w == null || b == null) {
|
|
7952
8176
|
return [];
|
|
7953
8177
|
}
|
|
7954
|
-
const rgb =
|
|
7955
|
-
|
|
7956
|
-
rgb
|
|
7957
|
-
rgb[i] = rgb[i] + white;
|
|
7958
|
-
}
|
|
7959
|
-
if (alpha != null && alpha != 1) {
|
|
7960
|
-
rgb.push(alpha);
|
|
8178
|
+
const rgb = hwb2srgb(h, w, b);
|
|
8179
|
+
if (a != null && a != 1) {
|
|
8180
|
+
rgb.push(a);
|
|
7961
8181
|
}
|
|
7962
8182
|
return rgb;
|
|
7963
8183
|
}
|
|
8184
|
+
/**
|
|
8185
|
+
* convert hwb to sRGB
|
|
8186
|
+
*/
|
|
8187
|
+
function hwb2srgb(h, w, b, alpha) {
|
|
8188
|
+
const wNorm = w / 100;
|
|
8189
|
+
const bNorm = b / 100;
|
|
8190
|
+
if (wNorm + bNorm >= 1) {
|
|
8191
|
+
const gray = wNorm / (wNorm + bNorm);
|
|
8192
|
+
return [Math.round(gray * 10000) / 10000, Math.round(gray * 10000) / 10000, Math.round(gray * 10000) / 10000];
|
|
8193
|
+
}
|
|
8194
|
+
const hPrime = (h % 360) / 60;
|
|
8195
|
+
const x = 1 - Math.abs((hPrime % 2) - 1);
|
|
8196
|
+
let rChroma = 0;
|
|
8197
|
+
let gChroma = 0;
|
|
8198
|
+
let bChroma = 0;
|
|
8199
|
+
if (hPrime >= 0 && hPrime < 1) {
|
|
8200
|
+
[rChroma, gChroma, bChroma] = [1, x, 0];
|
|
8201
|
+
}
|
|
8202
|
+
else if (hPrime >= 1 && hPrime < 2) {
|
|
8203
|
+
[rChroma, gChroma, bChroma] = [x, 1, 0];
|
|
8204
|
+
}
|
|
8205
|
+
else if (hPrime >= 2 && hPrime < 3) {
|
|
8206
|
+
[rChroma, gChroma, bChroma] = [0, 1, x];
|
|
8207
|
+
}
|
|
8208
|
+
else if (hPrime >= 3 && hPrime < 4) {
|
|
8209
|
+
[rChroma, gChroma, bChroma] = [0, x, 1];
|
|
8210
|
+
}
|
|
8211
|
+
else if (hPrime >= 4 && hPrime < 5) {
|
|
8212
|
+
[rChroma, gChroma, bChroma] = [x, 0, 1];
|
|
8213
|
+
}
|
|
8214
|
+
else if (hPrime >= 5 && hPrime <= 6) {
|
|
8215
|
+
[rChroma, gChroma, bChroma] = [1, 0, x];
|
|
8216
|
+
}
|
|
8217
|
+
const factor = 1 - wNorm - bNorm;
|
|
8218
|
+
const srgb = [rChroma * factor + wNorm, gChroma * factor + wNorm, bChroma * factor + wNorm];
|
|
8219
|
+
return srgb;
|
|
8220
|
+
}
|
|
7964
8221
|
function hsl2srgb(token) {
|
|
7965
8222
|
let { h, s, l, a } = hslvalues(token) ?? {};
|
|
7966
8223
|
if (h == null || s == null || l == null) {
|
|
7967
8224
|
return null;
|
|
7968
8225
|
}
|
|
8226
|
+
// hue in degrees
|
|
7969
8227
|
return hslvalues2srgbvalues(h, s, l, a);
|
|
7970
8228
|
}
|
|
7971
8229
|
function cmyk2srgbvalues(token) {
|
|
@@ -8026,7 +8284,7 @@
|
|
|
8026
8284
|
}
|
|
8027
8285
|
let t;
|
|
8028
8286
|
// @ts-ignore
|
|
8029
|
-
let h = getAngle(components[0]);
|
|
8287
|
+
let h = getAngle(components[0]) * 360;
|
|
8030
8288
|
// @ts-ignore
|
|
8031
8289
|
t = components[1];
|
|
8032
8290
|
// @ts-ignore
|
|
@@ -8035,6 +8293,12 @@
|
|
|
8035
8293
|
t = components[2];
|
|
8036
8294
|
// @ts-ignore
|
|
8037
8295
|
let l = getNumber(t);
|
|
8296
|
+
if (components[1].typ == exports.EnumToken.PercentageTokenType) {
|
|
8297
|
+
s *= 100;
|
|
8298
|
+
}
|
|
8299
|
+
if (components[2].typ == exports.EnumToken.PercentageTokenType) {
|
|
8300
|
+
l *= 100;
|
|
8301
|
+
}
|
|
8038
8302
|
let a = null;
|
|
8039
8303
|
if (components.length == 4) {
|
|
8040
8304
|
// @ts-ignore
|
|
@@ -8045,56 +8309,38 @@
|
|
|
8045
8309
|
return a == null ? { h, s, l } : { h, s, l, a };
|
|
8046
8310
|
}
|
|
8047
8311
|
function hslvalues2srgbvalues(h, s, l, a = null) {
|
|
8048
|
-
|
|
8049
|
-
|
|
8050
|
-
|
|
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
|
-
case 3:
|
|
8078
|
-
r = m;
|
|
8079
|
-
g = mid2;
|
|
8080
|
-
b = v;
|
|
8081
|
-
break;
|
|
8082
|
-
case 4:
|
|
8083
|
-
r = mid1;
|
|
8084
|
-
g = m;
|
|
8085
|
-
b = v;
|
|
8086
|
-
break;
|
|
8087
|
-
case 5:
|
|
8088
|
-
r = v;
|
|
8089
|
-
g = m;
|
|
8090
|
-
b = mid2;
|
|
8091
|
-
break;
|
|
8092
|
-
}
|
|
8093
|
-
}
|
|
8094
|
-
const values = [r, g, b];
|
|
8095
|
-
if (a != null && a != 1) {
|
|
8312
|
+
const sNorm = s / 100;
|
|
8313
|
+
const lNorm = l / 100;
|
|
8314
|
+
const chroma = (1 - Math.abs(2 * lNorm - 1)) * sNorm;
|
|
8315
|
+
const hPrime = h / 60;
|
|
8316
|
+
const x = chroma * (1 - Math.abs((hPrime % 2) - 1));
|
|
8317
|
+
let rTmp = 0;
|
|
8318
|
+
let gTmp = 0;
|
|
8319
|
+
let bTmp = 0;
|
|
8320
|
+
if (hPrime >= 0 && hPrime < 1) {
|
|
8321
|
+
[rTmp, gTmp, bTmp] = [chroma, x, 0];
|
|
8322
|
+
}
|
|
8323
|
+
else if (hPrime >= 1 && hPrime < 2) {
|
|
8324
|
+
[rTmp, gTmp, bTmp] = [x, chroma, 0];
|
|
8325
|
+
}
|
|
8326
|
+
else if (hPrime >= 2 && hPrime < 3) {
|
|
8327
|
+
[rTmp, gTmp, bTmp] = [0, chroma, x];
|
|
8328
|
+
}
|
|
8329
|
+
else if (hPrime >= 3 && hPrime < 4) {
|
|
8330
|
+
[rTmp, gTmp, bTmp] = [0, x, chroma];
|
|
8331
|
+
}
|
|
8332
|
+
else if (hPrime >= 4 && hPrime < 5) {
|
|
8333
|
+
[rTmp, gTmp, bTmp] = [x, 0, chroma];
|
|
8334
|
+
}
|
|
8335
|
+
else if (hPrime >= 5 && hPrime <= 6) {
|
|
8336
|
+
[rTmp, gTmp, bTmp] = [chroma, 0, x];
|
|
8337
|
+
}
|
|
8338
|
+
const m = lNorm - chroma / 2;
|
|
8339
|
+
const values = [rTmp + m, gTmp + m, bTmp + m];
|
|
8340
|
+
if (a != null) {
|
|
8096
8341
|
values.push(a);
|
|
8097
8342
|
}
|
|
8343
|
+
// Return exact float decimals instead of multiplying by 255
|
|
8098
8344
|
return values;
|
|
8099
8345
|
}
|
|
8100
8346
|
function lab2srgbvalues(token) {
|
|
@@ -8467,25 +8713,6 @@
|
|
|
8467
8713
|
return lch2srgbvalues(token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
|
|
8468
8714
|
}
|
|
8469
8715
|
|
|
8470
|
-
function hwb2hsv(h, w, b, a) {
|
|
8471
|
-
// @ts-ignore
|
|
8472
|
-
return [h, 1 - w / (1 - b), 1 - b, a];
|
|
8473
|
-
}
|
|
8474
|
-
// https://gist.github.com/defims/0ca2ef8832833186ed396a2f8a204117#file-annotated-js
|
|
8475
|
-
function hsl2hsv(h, s, l, a = null) {
|
|
8476
|
-
s *= l < .5 ? l : 1 - l;
|
|
8477
|
-
const result = [
|
|
8478
|
-
//Range should be between 0 - 1
|
|
8479
|
-
h, //Hue stays the same
|
|
8480
|
-
2 * s / (l + s), //Saturation
|
|
8481
|
-
l + s //Value
|
|
8482
|
-
];
|
|
8483
|
-
if (a != null) {
|
|
8484
|
-
result.push(a);
|
|
8485
|
-
}
|
|
8486
|
-
return result;
|
|
8487
|
-
}
|
|
8488
|
-
|
|
8489
8716
|
function hex2HslToken(token) {
|
|
8490
8717
|
let values = hex2srgbvalues(token);
|
|
8491
8718
|
if (values == null) {
|
|
@@ -8550,11 +8777,17 @@
|
|
|
8550
8777
|
return hslToken(srgb2hslvalues(values[0], values[1], values[2], values[3]));
|
|
8551
8778
|
}
|
|
8552
8779
|
function hslToken(values) {
|
|
8553
|
-
values[
|
|
8780
|
+
if (values[1] == 0) {
|
|
8781
|
+
values[0] = 0;
|
|
8782
|
+
}
|
|
8783
|
+
if (values[2] == 1 || values[2] == 0) {
|
|
8784
|
+
values[0] = 0;
|
|
8785
|
+
values[1] = 0;
|
|
8786
|
+
}
|
|
8554
8787
|
const chi = [
|
|
8555
8788
|
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
8556
|
-
{ typ: exports.EnumToken.PercentageTokenType, val: values[1]
|
|
8557
|
-
{ typ: exports.EnumToken.PercentageTokenType, val: values[2]
|
|
8789
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[1] },
|
|
8790
|
+
{ typ: exports.EnumToken.PercentageTokenType, val: values[2] },
|
|
8558
8791
|
];
|
|
8559
8792
|
if (values.length == 4 && values[3] != 1) {
|
|
8560
8793
|
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
|
|
@@ -8597,32 +8830,33 @@
|
|
|
8597
8830
|
}
|
|
8598
8831
|
return rgbvalues2hslvalues(values[0], values[1], values[2], values[3]);
|
|
8599
8832
|
}
|
|
8600
|
-
// https://gist.github.com/defims/0ca2ef8832833186ed396a2f8a204117#file-annotated-js
|
|
8601
|
-
function hsv2hsl(h, s, v, a) {
|
|
8602
|
-
const result = [
|
|
8603
|
-
//[hue, saturation, lightness]
|
|
8604
|
-
//Range should be between 0 - 1
|
|
8605
|
-
h, //Hue stays the same
|
|
8606
|
-
//Saturation is very different between the two color spaces
|
|
8607
|
-
//If (2-sat)*val < 1 set it to sat*val/((2-sat)*val)
|
|
8608
|
-
//Otherwise sat*val/(2-(2-sat)*val)
|
|
8609
|
-
//Conditional is not operating with hue, it is reassigned!
|
|
8610
|
-
(s * v) / ((h = (2 - s) * v) < 1 ? h : 2 - h),
|
|
8611
|
-
h / 2, //Lightness is (2-sat)*val/2
|
|
8612
|
-
];
|
|
8613
|
-
if (a != null) {
|
|
8614
|
-
result.push(a);
|
|
8615
|
-
}
|
|
8616
|
-
return result;
|
|
8617
|
-
}
|
|
8618
8833
|
function cmyk2hslvalues(token) {
|
|
8619
8834
|
const values = cmyk2rgbvalues(token);
|
|
8620
8835
|
return values == null ? null : rgbvalues2hslvalues(values[0], values[1], values[2], values[3]);
|
|
8621
8836
|
}
|
|
8622
8837
|
function hwb2hslvalues(token) {
|
|
8623
|
-
const
|
|
8624
|
-
|
|
8625
|
-
|
|
8838
|
+
const { h, w, b, a } = hwbvalues(token) ?? {};
|
|
8839
|
+
if (h == null || w == null || b == null) {
|
|
8840
|
+
return null;
|
|
8841
|
+
}
|
|
8842
|
+
const wNorm = w / 100;
|
|
8843
|
+
const bNorm = b / 100;
|
|
8844
|
+
const hue = ((h % 360) + 360) % 360;
|
|
8845
|
+
if (wNorm + bNorm >= 1) {
|
|
8846
|
+
const grayLightness = wNorm / (wNorm + bNorm);
|
|
8847
|
+
return [hue, 0, grayLightness * 100];
|
|
8848
|
+
}
|
|
8849
|
+
const lightness = (1 - bNorm + wNorm) / 2;
|
|
8850
|
+
let saturation = 0;
|
|
8851
|
+
if (lightness > 0 && lightness < 1) {
|
|
8852
|
+
const chroma = 1 - wNorm - bNorm;
|
|
8853
|
+
saturation = chroma / (1 - Math.abs(2 * lightness - 1));
|
|
8854
|
+
}
|
|
8855
|
+
const hsl = [hue, saturation * 100, lightness * 100];
|
|
8856
|
+
if (a != null && a != 1) {
|
|
8857
|
+
hsl.push(a);
|
|
8858
|
+
}
|
|
8859
|
+
return hsl;
|
|
8626
8860
|
}
|
|
8627
8861
|
function lab2hslvalues(token) {
|
|
8628
8862
|
const values = lab2rgbvalues(token);
|
|
@@ -8653,28 +8887,28 @@
|
|
|
8653
8887
|
return srgb2hslvalues(r / 255, g / 255, b / 255, a);
|
|
8654
8888
|
}
|
|
8655
8889
|
function srgb2hslvalues(r, g, b, a = null) {
|
|
8656
|
-
|
|
8657
|
-
|
|
8890
|
+
const max = Math.max(r, g, b);
|
|
8891
|
+
const min = Math.min(r, g, b);
|
|
8892
|
+
const delta = max - min;
|
|
8893
|
+
const l = (max + min) / 2;
|
|
8658
8894
|
let h = 0;
|
|
8659
8895
|
let s = 0;
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
let d = max - min;
|
|
8663
|
-
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
8896
|
+
if (delta !== 0) {
|
|
8897
|
+
s = delta / (1 - Math.abs(2 * l - 1));
|
|
8664
8898
|
switch (max) {
|
|
8665
8899
|
case r:
|
|
8666
|
-
h = (g - b) /
|
|
8900
|
+
h = 60 * (((g - b) / delta) % 6);
|
|
8667
8901
|
break;
|
|
8668
8902
|
case g:
|
|
8669
|
-
h = (b - r) /
|
|
8903
|
+
h = 60 * ((b - r) / delta + 2);
|
|
8670
8904
|
break;
|
|
8671
8905
|
case b:
|
|
8672
|
-
h = (r - g) /
|
|
8906
|
+
h = 60 * ((r - g) / delta + 4);
|
|
8673
8907
|
break;
|
|
8674
8908
|
}
|
|
8675
|
-
h /= 6;
|
|
8676
8909
|
}
|
|
8677
|
-
|
|
8910
|
+
h = ((h % 360) + 360) % 360;
|
|
8911
|
+
const hsl = [h, s * 100, l * 100];
|
|
8678
8912
|
if (a != null && a < 1) {
|
|
8679
8913
|
// @ts-ignore
|
|
8680
8914
|
return hsl.concat([a]);
|
|
@@ -8683,191 +8917,6 @@
|
|
|
8683
8917
|
return hsl;
|
|
8684
8918
|
}
|
|
8685
8919
|
|
|
8686
|
-
function rgb2hwbToken(token) {
|
|
8687
|
-
const values = rgb2hwbvalues(token);
|
|
8688
|
-
if (values == null) {
|
|
8689
|
-
return null;
|
|
8690
|
-
}
|
|
8691
|
-
return hwbToken(values);
|
|
8692
|
-
}
|
|
8693
|
-
function hsl2hwbToken(token) {
|
|
8694
|
-
const values = hsl2hwbvalues(token);
|
|
8695
|
-
if (values == null) {
|
|
8696
|
-
return null;
|
|
8697
|
-
}
|
|
8698
|
-
return hwbToken(values);
|
|
8699
|
-
}
|
|
8700
|
-
function cmyk2hwbToken(token) {
|
|
8701
|
-
const values = cmyk2hwbvalues(token);
|
|
8702
|
-
if (values == null) {
|
|
8703
|
-
return null;
|
|
8704
|
-
}
|
|
8705
|
-
return hwbToken(values);
|
|
8706
|
-
}
|
|
8707
|
-
function oklab2hwbToken(token) {
|
|
8708
|
-
const values = oklab2hwbvalues(token);
|
|
8709
|
-
if (values == null) {
|
|
8710
|
-
return null;
|
|
8711
|
-
}
|
|
8712
|
-
return hwbToken(values);
|
|
8713
|
-
}
|
|
8714
|
-
function oklch2hwbToken(token) {
|
|
8715
|
-
const values = oklch2hwbvalues(token);
|
|
8716
|
-
if (values == null) {
|
|
8717
|
-
return null;
|
|
8718
|
-
}
|
|
8719
|
-
return hwbToken(values);
|
|
8720
|
-
}
|
|
8721
|
-
function lab2hwbToken(token) {
|
|
8722
|
-
const values = lab2hwbvalues(token);
|
|
8723
|
-
if (values == null) {
|
|
8724
|
-
return null;
|
|
8725
|
-
}
|
|
8726
|
-
return hwbToken(values);
|
|
8727
|
-
}
|
|
8728
|
-
function lch2hwbToken(token) {
|
|
8729
|
-
const values = lch2hwbvalues(token);
|
|
8730
|
-
if (values == null) {
|
|
8731
|
-
return null;
|
|
8732
|
-
}
|
|
8733
|
-
return hwbToken(values);
|
|
8734
|
-
}
|
|
8735
|
-
function color2hwbToken(token) {
|
|
8736
|
-
const values = color2hwbvalues(token);
|
|
8737
|
-
if (values == null) {
|
|
8738
|
-
return null;
|
|
8739
|
-
}
|
|
8740
|
-
return hwbToken(values);
|
|
8741
|
-
}
|
|
8742
|
-
function hwbToken(values) {
|
|
8743
|
-
values[0] = values[0] * 360;
|
|
8744
|
-
const chi = [
|
|
8745
|
-
{ typ: exports.EnumToken.NumberTokenType, val: values[0] },
|
|
8746
|
-
{ typ: exports.EnumToken.PercentageTokenType, val: values[1] * 100 },
|
|
8747
|
-
{ typ: exports.EnumToken.PercentageTokenType, val: values[2] * 100 },
|
|
8748
|
-
];
|
|
8749
|
-
if (values.length == 4) {
|
|
8750
|
-
chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
|
|
8751
|
-
typ: exports.EnumToken.PercentageTokenType,
|
|
8752
|
-
val: values[3] * 100,
|
|
8753
|
-
});
|
|
8754
|
-
}
|
|
8755
|
-
return {
|
|
8756
|
-
typ: exports.EnumToken.ColorTokenType,
|
|
8757
|
-
val: "hwb",
|
|
8758
|
-
chi,
|
|
8759
|
-
kin: exports.ColorType.HWB,
|
|
8760
|
-
};
|
|
8761
|
-
}
|
|
8762
|
-
function rgb2hwbvalues(token) {
|
|
8763
|
-
const values = getColorComponents(token).map((t, index) => {
|
|
8764
|
-
if (index == 3) {
|
|
8765
|
-
return getNumber(t);
|
|
8766
|
-
}
|
|
8767
|
-
return getNumber(t) / 255;
|
|
8768
|
-
});
|
|
8769
|
-
// @ts-ignore
|
|
8770
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8771
|
-
}
|
|
8772
|
-
function cmyk2hwbvalues(token) {
|
|
8773
|
-
const values = cmyk2srgbvalues(token);
|
|
8774
|
-
return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8775
|
-
}
|
|
8776
|
-
function hsl2hwbvalues(token) {
|
|
8777
|
-
const values = getColorComponents(token).map((t, index) => {
|
|
8778
|
-
if (index == 3 && t.typ == exports.EnumToken.IdenTokenType && t.val == "none") {
|
|
8779
|
-
return 1;
|
|
8780
|
-
}
|
|
8781
|
-
if (index == 0) {
|
|
8782
|
-
return getAngle(t);
|
|
8783
|
-
}
|
|
8784
|
-
return getNumber(t);
|
|
8785
|
-
});
|
|
8786
|
-
// @ts-ignore
|
|
8787
|
-
return hslvalues2hwbvalues(values[0], values[1], values[2], values[3]);
|
|
8788
|
-
}
|
|
8789
|
-
function lab2hwbvalues(token) {
|
|
8790
|
-
const values = lab2srgbvalues(token);
|
|
8791
|
-
if (values == null) {
|
|
8792
|
-
return null;
|
|
8793
|
-
}
|
|
8794
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8795
|
-
}
|
|
8796
|
-
function lch2hwbvalues(token) {
|
|
8797
|
-
const values = lch2srgbvalues(token);
|
|
8798
|
-
if (values == null) {
|
|
8799
|
-
return null;
|
|
8800
|
-
}
|
|
8801
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8802
|
-
}
|
|
8803
|
-
function oklab2hwbvalues(token) {
|
|
8804
|
-
const values = oklab2srgbvalues(token);
|
|
8805
|
-
if (values == null) {
|
|
8806
|
-
return null;
|
|
8807
|
-
}
|
|
8808
|
-
// @ts-ignore
|
|
8809
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8810
|
-
}
|
|
8811
|
-
function oklch2hwbvalues(token) {
|
|
8812
|
-
const values = oklch2srgbvalues(token);
|
|
8813
|
-
// @ts-ignore
|
|
8814
|
-
return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8815
|
-
}
|
|
8816
|
-
function rgb2hue(r, g, b, fallback = 0) {
|
|
8817
|
-
let value = rgb2value(r, g, b);
|
|
8818
|
-
let whiteness = rgb2whiteness(r, g, b);
|
|
8819
|
-
let delta = value - whiteness;
|
|
8820
|
-
if (delta > 0) {
|
|
8821
|
-
// calculate segment
|
|
8822
|
-
let segment = value === r ? (g - b) / delta : value === g ? (b - r) / delta : (r - g) / delta;
|
|
8823
|
-
// calculate shift
|
|
8824
|
-
let shift = value === r ? (segment < 0 ? 360 / 60 : 0 / 60) : value === g ? 120 / 60 : 240 / 60;
|
|
8825
|
-
// calculate hue
|
|
8826
|
-
return (segment + shift) * 60;
|
|
8827
|
-
}
|
|
8828
|
-
return fallback;
|
|
8829
|
-
}
|
|
8830
|
-
function rgb2value(r, g, b) {
|
|
8831
|
-
return Math.max(r, g, b);
|
|
8832
|
-
}
|
|
8833
|
-
function rgb2whiteness(r, g, b) {
|
|
8834
|
-
return Math.min(r, g, b);
|
|
8835
|
-
}
|
|
8836
|
-
function color2hwbvalues(token) {
|
|
8837
|
-
const values = color2srgbvalues(token);
|
|
8838
|
-
if (values == null) {
|
|
8839
|
-
return null;
|
|
8840
|
-
}
|
|
8841
|
-
// @ts-ignore
|
|
8842
|
-
return srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
8843
|
-
}
|
|
8844
|
-
function srgb2hwb(r, g, b, a = null, fallback = 0) {
|
|
8845
|
-
r *= 100;
|
|
8846
|
-
g *= 100;
|
|
8847
|
-
b *= 100;
|
|
8848
|
-
let hue = rgb2hue(r, g, b, fallback);
|
|
8849
|
-
let whiteness = rgb2whiteness(r, g, b);
|
|
8850
|
-
let value = Math.round(rgb2value(r, g, b));
|
|
8851
|
-
let blackness = 100 - value;
|
|
8852
|
-
const result = [hue / 360, whiteness / 100, blackness / 100];
|
|
8853
|
-
if (a != null) {
|
|
8854
|
-
result.push(a);
|
|
8855
|
-
}
|
|
8856
|
-
return result;
|
|
8857
|
-
}
|
|
8858
|
-
function hsv2hwb(h, s, v, a = null) {
|
|
8859
|
-
const result = [h, (1 - s) * v, 1 - v];
|
|
8860
|
-
if (a != null) {
|
|
8861
|
-
result.push(a);
|
|
8862
|
-
}
|
|
8863
|
-
return result;
|
|
8864
|
-
}
|
|
8865
|
-
function hslvalues2hwbvalues(h, s, l, a = null) {
|
|
8866
|
-
let values = hsl2hsv(h, s, l);
|
|
8867
|
-
// @ts-ignore
|
|
8868
|
-
return hsv2hwb(values[0], values[1], values[2], a);
|
|
8869
|
-
}
|
|
8870
|
-
|
|
8871
8920
|
function prophotorgb2srgbvalues(r, g, b, a = null) {
|
|
8872
8921
|
let values = prophotorgb2xyz50(r, g, b);
|
|
8873
8922
|
// @ts-ignore
|
|
@@ -9169,6 +9218,7 @@
|
|
|
9169
9218
|
const percentages = [];
|
|
9170
9219
|
const srgbComponentValues = [];
|
|
9171
9220
|
const colorComponents = [];
|
|
9221
|
+
const colors = [];
|
|
9172
9222
|
if (args[i]?.typ === exports.EnumToken.IdenTokenType) {
|
|
9173
9223
|
if (!equalsIgnoreCase(args[i++].val, "in")) {
|
|
9174
9224
|
return null;
|
|
@@ -9218,9 +9268,10 @@
|
|
|
9218
9268
|
if (values == null) {
|
|
9219
9269
|
return null;
|
|
9220
9270
|
}
|
|
9221
|
-
if (colorSpace == "hwb") {
|
|
9222
|
-
|
|
9223
|
-
}
|
|
9271
|
+
// if (colorSpace == "hwb") {
|
|
9272
|
+
// colorSpace = "srgb";
|
|
9273
|
+
// }
|
|
9274
|
+
colors.push(processPowerlessComponents(args[i]));
|
|
9224
9275
|
switch (colorSpace) {
|
|
9225
9276
|
case "srgb":
|
|
9226
9277
|
break;
|
|
@@ -9250,17 +9301,12 @@
|
|
|
9250
9301
|
values = srgb2xyz_d65(values[0], values[1], values[2], values[3]);
|
|
9251
9302
|
values = XYZ_D65_to_D50(values[0], values[1], values[2], values[3]);
|
|
9252
9303
|
break;
|
|
9253
|
-
// case "rgb":
|
|
9254
|
-
// for (let j = 0; j < values.length; j++) {
|
|
9255
|
-
// values[j] = j == 3 ? values[j] : srgb2rgb(values[j]);
|
|
9256
|
-
// }
|
|
9257
|
-
// break;
|
|
9258
9304
|
case "hsl":
|
|
9259
9305
|
values = srgb2hslvalues(values[0], values[1], values[2], values[3]);
|
|
9260
9306
|
break;
|
|
9261
|
-
|
|
9262
|
-
|
|
9263
|
-
|
|
9307
|
+
case "hwb":
|
|
9308
|
+
values = srgb2hwb(values[0], values[1], values[2], values[3]);
|
|
9309
|
+
break;
|
|
9264
9310
|
case "lab":
|
|
9265
9311
|
values = srgb2labvalues(values[0], values[1], values[2], values[3]);
|
|
9266
9312
|
break;
|
|
@@ -9322,7 +9368,8 @@
|
|
|
9322
9368
|
}
|
|
9323
9369
|
}
|
|
9324
9370
|
const stack = [];
|
|
9325
|
-
const lchSpaces = ["lch", "oklch"];
|
|
9371
|
+
// const lchSpaces: string[] = ["lch", "oklch"];
|
|
9372
|
+
const isLCHOrOKLCH = colorSpace === "lch" || colorSpace == "oklch";
|
|
9326
9373
|
i = srgbComponentValues.length;
|
|
9327
9374
|
while (i--) {
|
|
9328
9375
|
stack.push({
|
|
@@ -9340,46 +9387,73 @@
|
|
|
9340
9387
|
let premult1;
|
|
9341
9388
|
let premult2;
|
|
9342
9389
|
let mixedPremult;
|
|
9343
|
-
let
|
|
9344
|
-
|
|
9345
|
-
|
|
9346
|
-
|
|
9347
|
-
|
|
9348
|
-
if (colorComponents[0][3] != null &&
|
|
9349
|
-
colorComponents[0][3].typ == exports.EnumToken.IdenTokenType &&
|
|
9350
|
-
colorComponents[0][3].val == "none" &&
|
|
9351
|
-
colorComponents[1].length == 4) {
|
|
9390
|
+
let offset1 = colors[0].kin == exports.ColorType.COLOR ? 1 : 0;
|
|
9391
|
+
if (colorComponents[0][offset1 + 3] != null &&
|
|
9392
|
+
colorComponents[0][offset1 + 3].typ == exports.EnumToken.IdenTokenType &&
|
|
9393
|
+
colorComponents[0][offset1 + 3].val == "none" &&
|
|
9394
|
+
colorComponents[1].length == offset1 + 4) {
|
|
9352
9395
|
// fix powerless alpha for last color if previous color has alpha
|
|
9353
9396
|
stack[stack.length - 1].color[3] = stack[stack.length - 2].color[3];
|
|
9354
9397
|
}
|
|
9355
|
-
//
|
|
9356
|
-
if (
|
|
9357
|
-
|
|
9358
|
-
|
|
9359
|
-
|
|
9360
|
-
|
|
9398
|
+
// console.error(stack);
|
|
9399
|
+
if (stack.length > 1) {
|
|
9400
|
+
// powerless hue for lch spaces
|
|
9401
|
+
// if (lchSpaces.includes(colorSpace)) {
|
|
9402
|
+
// console.error(JSON.stringify({colorSpace1, colorSpace, stack, colorComponents}, null, 1));
|
|
9403
|
+
if ((stack[stack.length - 1].color[0] == 0 && colorComponents[0][offset1].typ == exports.EnumToken.IdenTokenType &&
|
|
9404
|
+
colorComponents[0][offset1].val == "none") ||
|
|
9405
|
+
colorComponents[0][0][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
|
|
9406
|
+
stack[stack.length - 1].color[0] = stack[stack.length - 2].color[0];
|
|
9407
|
+
}
|
|
9408
|
+
if ((stack[stack.length - 1].color[1] == 0 && colorComponents[0][offset1 + 1].typ == exports.EnumToken.IdenTokenType &&
|
|
9409
|
+
colorComponents[0][offset1 + 1].val == "none") ||
|
|
9410
|
+
colorComponents[0][1][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
|
|
9411
|
+
stack[stack.length - 1].color[1] = stack[stack.length - 2].color[1];
|
|
9412
|
+
}
|
|
9413
|
+
if ((stack[stack.length - 1].color[2] == 0 && colorComponents[0][offset1 + 2].typ == exports.EnumToken.IdenTokenType &&
|
|
9414
|
+
colorComponents[0][offset1 + 2].val == "none") ||
|
|
9415
|
+
colorComponents[0][2][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent ||
|
|
9416
|
+
(isLCHOrOKLCH &&
|
|
9417
|
+
(stack[stack.length - 1].color[1] == 0 ||
|
|
9418
|
+
stack[stack.length - 1].color[0] == 0 ||
|
|
9419
|
+
stack[stack.length - 1].color[0] ==
|
|
9420
|
+
colorRange[colors[0].kin == exports.ColorType.LCH ? "lch" : "oklch"].l[1]))) {
|
|
9361
9421
|
stack[stack.length - 1].color[2] = stack[stack.length - 2].color[2];
|
|
9362
9422
|
}
|
|
9423
|
+
// }
|
|
9363
9424
|
}
|
|
9425
|
+
// console.error([colorComponents[0][offset1].typ == EnumToken.IdenTokenType, (colorComponents[0][offset1] as IdentToken).val == "none"]);
|
|
9426
|
+
// console.error(isLCHOrOKLCH, colorComponents, stack);
|
|
9364
9427
|
while (stack.length > 1) {
|
|
9365
9428
|
r1 = stack.pop();
|
|
9366
9429
|
r2 = stack.pop();
|
|
9430
|
+
offset1 = colors[++currentIndex].kin == exports.ColorType.COLOR ? 1 : 0;
|
|
9367
9431
|
// r2 powerless alpha
|
|
9368
|
-
if (colorComponents[
|
|
9369
|
-
colorComponents[currentIndex][3].typ == exports.EnumToken.IdenTokenType &&
|
|
9370
|
-
colorComponents[currentIndex][3].val == "none") {
|
|
9432
|
+
if (colorComponents[currentIndex][offset1 + 3] != null &&
|
|
9433
|
+
colorComponents[currentIndex][offset1 + 3].typ == exports.EnumToken.IdenTokenType &&
|
|
9434
|
+
colorComponents[currentIndex][offset1 + 3].val == "none") {
|
|
9371
9435
|
// fix powerless alpha for last color if previous color has alpha
|
|
9372
9436
|
r2.color[3] = r1.color[3];
|
|
9373
9437
|
}
|
|
9374
|
-
// @ts-expect-error
|
|
9375
|
-
colorSpace1 = exports.ColorType[colorComponents[currentIndex].kin]?.toLowerCase?.();
|
|
9376
9438
|
// powerless hue for lch spaces
|
|
9377
|
-
if (
|
|
9378
|
-
|
|
9379
|
-
|
|
9380
|
-
|
|
9381
|
-
|
|
9382
|
-
|
|
9439
|
+
if ((r2.color[0] == 0 && colorComponents[currentIndex][offset1].typ == exports.EnumToken.IdenTokenType &&
|
|
9440
|
+
colorComponents[currentIndex][offset1].val == "none") ||
|
|
9441
|
+
colorComponents[currentIndex][offset1][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
|
|
9442
|
+
r2.color[0] = r1.color[0];
|
|
9443
|
+
}
|
|
9444
|
+
if ((r2.color[1] == 0 && colorComponents[currentIndex][offset1 + 1].typ == exports.EnumToken.IdenTokenType &&
|
|
9445
|
+
colorComponents[currentIndex][offset1 + 1].val == "none") ||
|
|
9446
|
+
colorComponents[currentIndex][offset1 + 1][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
|
|
9447
|
+
r2.color[1] = r1.color[1];
|
|
9448
|
+
}
|
|
9449
|
+
if ((r2.color[2] == 0 && colorComponents[currentIndex][offset1 + 2].typ == exports.EnumToken.IdenTokenType &&
|
|
9450
|
+
colorComponents[currentIndex][offset1 + 2].val == "none") ||
|
|
9451
|
+
colorComponents[currentIndex][offset1 + 2][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent ||
|
|
9452
|
+
(isLCHOrOKLCH &&
|
|
9453
|
+
(r2.color[1] == 0 ||
|
|
9454
|
+
r2.color[0] == 0 ||
|
|
9455
|
+
r2.color[0] == colorRange[colors[currentIndex].kin == exports.ColorType.LCH ? "lch" : "oklch"].l[1]))) {
|
|
9456
|
+
r2.color[2] = r1.color[2];
|
|
9383
9457
|
}
|
|
9384
9458
|
if (hueInterpolationMethod != null) {
|
|
9385
9459
|
let hueIndex = 2;
|
|
@@ -9407,6 +9481,7 @@
|
|
|
9407
9481
|
alpha: mult,
|
|
9408
9482
|
};
|
|
9409
9483
|
}
|
|
9484
|
+
// console.error({ r1, r2, r, premult1, mult1, premult2, mult2, mixedPremult, mult });
|
|
9410
9485
|
stack.push(r);
|
|
9411
9486
|
}
|
|
9412
9487
|
const result = stack.pop();
|
|
@@ -9461,16 +9536,16 @@
|
|
|
9461
9536
|
};
|
|
9462
9537
|
// case "rgb":
|
|
9463
9538
|
case "hsl":
|
|
9464
|
-
|
|
9539
|
+
case "hwb":
|
|
9465
9540
|
case "lab":
|
|
9466
9541
|
case "lch":
|
|
9467
9542
|
case "oklab":
|
|
9468
9543
|
case "oklch":
|
|
9469
|
-
if (colorSpace == "hsl") {
|
|
9544
|
+
if (colorSpace == "hsl" || colorSpace == "hwb") {
|
|
9470
9545
|
// @ts-ignore
|
|
9471
9546
|
if (values[2] < 0) {
|
|
9472
9547
|
// @ts-ignore
|
|
9473
|
-
values[2] +=
|
|
9548
|
+
values[2] += 360;
|
|
9474
9549
|
}
|
|
9475
9550
|
}
|
|
9476
9551
|
else if (colorSpace == "lch" || colorSpace == "oklch") {
|
|
@@ -9498,16 +9573,72 @@
|
|
|
9498
9573
|
};
|
|
9499
9574
|
if (colorSpace == "hsl") {
|
|
9500
9575
|
// @ts-ignore
|
|
9501
|
-
result.chi[0] = { typ: exports.EnumToken.AngleTokenType, val: result.chi[0].val
|
|
9576
|
+
result.chi[0] = { typ: exports.EnumToken.AngleTokenType, val: result.chi[0].val };
|
|
9502
9577
|
// @ts-ignore
|
|
9503
|
-
result.chi[1] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[1].val
|
|
9578
|
+
result.chi[1] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[1].val };
|
|
9504
9579
|
// @ts-ignore
|
|
9505
|
-
result.chi[2] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[2].val
|
|
9580
|
+
result.chi[2] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[2].val };
|
|
9506
9581
|
}
|
|
9507
9582
|
return result;
|
|
9508
9583
|
}
|
|
9509
9584
|
return null;
|
|
9510
9585
|
}
|
|
9586
|
+
function processPowerlessComponents(color) {
|
|
9587
|
+
let components;
|
|
9588
|
+
let values;
|
|
9589
|
+
switch (color.kin) {
|
|
9590
|
+
case exports.ColorType.LCH:
|
|
9591
|
+
case exports.ColorType.OKLCH:
|
|
9592
|
+
values = color.kin == exports.ColorType.LCH ? getLCHComponents(color) : getOKLCHComponents(color);
|
|
9593
|
+
components = getColorComponents(color);
|
|
9594
|
+
if (values == null || values.length < 3 || components == null) {
|
|
9595
|
+
break;
|
|
9596
|
+
}
|
|
9597
|
+
const max = color.kin == exports.ColorType.LCH ? colorRange.lch.l[1] : colorRange.oklch.l[1];
|
|
9598
|
+
// https://www.w3.org/TR/css-color-4/#specifying-lab-lch
|
|
9599
|
+
// https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch
|
|
9600
|
+
const epsilon = color.kin == exports.ColorType.LCH ? 0.0015 : 0.000004;
|
|
9601
|
+
if (values[0] < epsilon || Math.abs(values[0] - max) < epsilon) {
|
|
9602
|
+
Object.assign(components[0], { val: values[0] < epsilon ? 0 : max, typ: exports.EnumToken.NumberTokenType });
|
|
9603
|
+
Object.assign(components[1], { val: "none", typ: exports.EnumToken.IdenTokenType });
|
|
9604
|
+
Object.assign(components[2], { val: "none", typ: exports.EnumToken.IdenTokenType });
|
|
9605
|
+
setColorFlag(components[1], exports.EnumAstNodeStatus.PowerlessColorComponent);
|
|
9606
|
+
setColorFlag(components[2], exports.EnumAstNodeStatus.PowerlessColorComponent);
|
|
9607
|
+
}
|
|
9608
|
+
else if (values[1] < epsilon) {
|
|
9609
|
+
values[1] = 0;
|
|
9610
|
+
Object.assign(components[1], { val: 0, typ: exports.EnumToken.NumberTokenType });
|
|
9611
|
+
Object.assign(components[2], { val: "none", typ: exports.EnumToken.IdenTokenType });
|
|
9612
|
+
setColorFlag(components[2], exports.EnumAstNodeStatus.PowerlessColorComponent);
|
|
9613
|
+
}
|
|
9614
|
+
break;
|
|
9615
|
+
case exports.ColorType.HSL:
|
|
9616
|
+
case exports.ColorType.HWB:
|
|
9617
|
+
values = Object.values((color.kin == exports.ColorType.HSL ? hslvalues(color) : hwbvalues(color)) ?? {});
|
|
9618
|
+
components = getColorComponents(color);
|
|
9619
|
+
if (values == null || values.length < 3 || components == null) {
|
|
9620
|
+
break;
|
|
9621
|
+
}
|
|
9622
|
+
// https://www.w3.org/TR/css-color-4/#the-hsl-notation
|
|
9623
|
+
// https://www.w3.org/TR/css-color-4/#the-hwb-notation
|
|
9624
|
+
if ((color.kin == exports.ColorType.HSL && values[1] <= 0.001) ||
|
|
9625
|
+
(color.kin == exports.ColorType.HWB && values[1] + values[2] >= 99.999)) {
|
|
9626
|
+
Object.assign(components[0], { val: "none", typ: exports.EnumToken.IdenTokenType });
|
|
9627
|
+
setColorFlag(components[0], exports.EnumAstNodeStatus.PowerlessColorComponent);
|
|
9628
|
+
}
|
|
9629
|
+
break;
|
|
9630
|
+
}
|
|
9631
|
+
// console.error({ color: color.chi ?? color, values });
|
|
9632
|
+
return color;
|
|
9633
|
+
}
|
|
9634
|
+
function setColorFlag(token, flag) {
|
|
9635
|
+
if (token[STATE] == null) {
|
|
9636
|
+
token[STATE] = flag;
|
|
9637
|
+
}
|
|
9638
|
+
else {
|
|
9639
|
+
token[STATE] |= flag;
|
|
9640
|
+
}
|
|
9641
|
+
}
|
|
9511
9642
|
|
|
9512
9643
|
/**
|
|
9513
9644
|
* Options for the walk function
|
|
@@ -9545,6 +9676,7 @@
|
|
|
9545
9676
|
*/
|
|
9546
9677
|
WalkerEvent[WalkerEvent["Leave"] = 2] = "Leave";
|
|
9547
9678
|
})(exports.WalkerEvent || (exports.WalkerEvent = {}));
|
|
9679
|
+
const maxQueueLength = 25000;
|
|
9548
9680
|
/**
|
|
9549
9681
|
* Walk ast nodes
|
|
9550
9682
|
* @param node initial node
|
|
@@ -9648,6 +9780,10 @@
|
|
|
9648
9780
|
},
|
|
9649
9781
|
};
|
|
9650
9782
|
while ((node = parents[i++])) {
|
|
9783
|
+
if (i > maxQueueLength) {
|
|
9784
|
+
parents.splice(0, maxQueueLength);
|
|
9785
|
+
i -= maxQueueLength;
|
|
9786
|
+
}
|
|
9651
9787
|
let option = null;
|
|
9652
9788
|
if (filter != null) {
|
|
9653
9789
|
// @ts-expect-error
|
|
@@ -9791,6 +9927,10 @@
|
|
|
9791
9927
|
while (++i < stack.length) {
|
|
9792
9928
|
value = stack[i];
|
|
9793
9929
|
option = null;
|
|
9930
|
+
if (i > maxQueueLength) {
|
|
9931
|
+
stack.splice(0, maxQueueLength);
|
|
9932
|
+
i -= maxQueueLength;
|
|
9933
|
+
}
|
|
9794
9934
|
if (filter.fn != null && eventType & exports.WalkerEvent.Enter) {
|
|
9795
9935
|
const isValid = filter.type == null ||
|
|
9796
9936
|
value.typ == filter.type ||
|
|
@@ -11023,7 +11163,36 @@
|
|
|
11023
11163
|
: aExp),
|
|
11024
11164
|
};
|
|
11025
11165
|
const result = computeComponentValue(keys, values);
|
|
11166
|
+
if (result != null) {
|
|
11167
|
+
if ("hsl" == relativeKeys) {
|
|
11168
|
+
Object.assign(result.s, {
|
|
11169
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
11170
|
+
// @ts-ignore
|
|
11171
|
+
val: result.s.val * 100,
|
|
11172
|
+
});
|
|
11173
|
+
Object.assign(result.l, {
|
|
11174
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
11175
|
+
// @ts-ignore
|
|
11176
|
+
val: result.l.val * 100,
|
|
11177
|
+
});
|
|
11178
|
+
}
|
|
11179
|
+
else if ("hwb" == relativeKeys) {
|
|
11180
|
+
// @ts
|
|
11181
|
+
Object.assign(result.w, {
|
|
11182
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
11183
|
+
// @ts-ignore
|
|
11184
|
+
val: result.w.val * 100,
|
|
11185
|
+
});
|
|
11186
|
+
Object.assign(result.b, {
|
|
11187
|
+
typ: exports.EnumToken.PercentageTokenType,
|
|
11188
|
+
// @ts-ignore
|
|
11189
|
+
val: result.b.val * 100,
|
|
11190
|
+
});
|
|
11191
|
+
}
|
|
11192
|
+
}
|
|
11193
|
+
// @ts-ignore
|
|
11026
11194
|
if (result?.alpha?.typ == exports.EnumToken.NumberTokenType && result.alpha.val === 1) {
|
|
11195
|
+
// @ts-ignore
|
|
11027
11196
|
const { alpha, ...components } = result;
|
|
11028
11197
|
return components;
|
|
11029
11198
|
}
|
|
@@ -15165,7 +15334,6 @@
|
|
|
15165
15334
|
return +token.val;
|
|
15166
15335
|
}
|
|
15167
15336
|
}
|
|
15168
|
-
// @ts-ignore
|
|
15169
15337
|
return token.val / 360;
|
|
15170
15338
|
}
|
|
15171
15339
|
|
|
@@ -17023,9 +17191,7 @@
|
|
|
17023
17191
|
}
|
|
17024
17192
|
}
|
|
17025
17193
|
run(node) {
|
|
17026
|
-
if (node[STATE]
|
|
17027
|
-
node[STATE] == exports.EnumAstNodeStatus.Invalid ||
|
|
17028
|
-
node[STATE] == exports.EnumAstNodeStatus.Malformed) {
|
|
17194
|
+
if (node[STATE] & (exports.EnumAstNodeStatus.Disallowed | exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.Malformed)) {
|
|
17029
17195
|
return null;
|
|
17030
17196
|
}
|
|
17031
17197
|
if (node.typ == exports.EnumToken.RuleNodeType) {
|
|
@@ -19740,7 +19906,8 @@
|
|
|
19740
19906
|
const tokens = {};
|
|
19741
19907
|
const values = [];
|
|
19742
19908
|
const val = [[]];
|
|
19743
|
-
for (const curr of this.declarations.get(this.config.shorthand).val) {
|
|
19909
|
+
for (const curr of this.declarations.get(this.config.shorthand).val) {
|
|
19910
|
+
// @ts-ignore
|
|
19744
19911
|
// @ts-ignore
|
|
19745
19912
|
if (separator != null && separator.typ == curr.typ && separator.val == curr.val) {
|
|
19746
19913
|
val.push([]);
|
|
@@ -20684,9 +20851,8 @@
|
|
|
20684
20851
|
let result;
|
|
20685
20852
|
for (const declaration of declarations) {
|
|
20686
20853
|
name = declaration.typ != exports.EnumToken.DeclarationNodeType ? null : declaration.nam;
|
|
20687
|
-
if (declaration[STATE]
|
|
20688
|
-
|
|
20689
|
-
declaration[STATE] == exports.EnumAstNodeStatus.ValidationFailed ||
|
|
20854
|
+
if (declaration[STATE] &
|
|
20855
|
+
(exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.Unknown | exports.EnumAstNodeStatus.ValidationFailed) ||
|
|
20690
20856
|
declaration.typ != exports.EnumToken.DeclarationNodeType ||
|
|
20691
20857
|
equalsIgnoreCase("composes", name) ||
|
|
20692
20858
|
(typeof this.options.removeDuplicateDeclarations === "string" &&
|
|
@@ -20705,17 +20871,17 @@
|
|
|
20705
20871
|
this.declarations.set(declaration.nam, declaration);
|
|
20706
20872
|
continue;
|
|
20707
20873
|
}
|
|
20708
|
-
if (declaration[STATE]
|
|
20874
|
+
if (declaration[STATE] & exports.EnumAstNodeStatus.Unvalidated) {
|
|
20709
20875
|
syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, declaration.nam.toLowerCase());
|
|
20710
20876
|
if (syntaxRules != null) {
|
|
20711
20877
|
result = matchAllSyntaxes(syntaxRules, createValidationContext(declaration.val), this.options);
|
|
20712
|
-
declaration[STATE]
|
|
20713
|
-
? exports.EnumAstNodeStatus.Validated
|
|
20714
|
-
|
|
20878
|
+
declaration[STATE] |=
|
|
20879
|
+
(result.success ? exports.EnumAstNodeStatus.Validated : exports.EnumAstNodeStatus.ValidationFailed) &
|
|
20880
|
+
~exports.EnumAstNodeStatus.Unvalidated;
|
|
20715
20881
|
}
|
|
20716
20882
|
}
|
|
20717
20883
|
// do not compute shorthand for invalid declarations
|
|
20718
|
-
if (declaration[STATE]
|
|
20884
|
+
if (!(declaration[STATE] & exports.EnumAstNodeStatus.Validated)) {
|
|
20719
20885
|
this.declarations.set(objectHash(declaration), declaration);
|
|
20720
20886
|
continue;
|
|
20721
20887
|
}
|
|
@@ -20745,6 +20911,16 @@
|
|
|
20745
20911
|
// @ts-ignore
|
|
20746
20912
|
shorthand = config.property[propertyName];
|
|
20747
20913
|
}
|
|
20914
|
+
if (this.declarations.has(shorthand)) {
|
|
20915
|
+
let existing = this.declarations.get(shorthand);
|
|
20916
|
+
if (existing instanceof PropertySet || existing instanceof PropertyMap) {
|
|
20917
|
+
existing = existing.declarations.get(declaration.nam);
|
|
20918
|
+
}
|
|
20919
|
+
if (existing?.[STATE] & exports.EnumAstNodeStatus.ImportantDeclaration &&
|
|
20920
|
+
declaration[STATE] & ~exports.EnumAstNodeStatus.ImportantDeclaration) {
|
|
20921
|
+
continue;
|
|
20922
|
+
}
|
|
20923
|
+
}
|
|
20748
20924
|
// @ts-ignore
|
|
20749
20925
|
if (shortHandType == "map") {
|
|
20750
20926
|
let owner = this;
|
|
@@ -22386,7 +22562,7 @@
|
|
|
22386
22562
|
for (; i < ast.chi.length; i++) {
|
|
22387
22563
|
// @ts-ignore
|
|
22388
22564
|
node = ast.chi[i];
|
|
22389
|
-
if (node[STATE]
|
|
22565
|
+
if (node[STATE] & (exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.ValidationFailed)) {
|
|
22390
22566
|
continue;
|
|
22391
22567
|
}
|
|
22392
22568
|
if (node.typ != exports.EnumToken.DeclarationNodeType ||
|
|
@@ -24329,11 +24505,12 @@
|
|
|
24329
24505
|
* @private
|
|
24330
24506
|
*/
|
|
24331
24507
|
function expand(ast) {
|
|
24332
|
-
if (ast[STATE]
|
|
24333
|
-
|
|
24334
|
-
|
|
24335
|
-
|
|
24336
|
-
|
|
24508
|
+
if (ast[STATE] &
|
|
24509
|
+
(exports.EnumAstNodeStatus.Invalid |
|
|
24510
|
+
exports.EnumAstNodeStatus.Disallowed |
|
|
24511
|
+
exports.EnumAstNodeStatus.Unknown |
|
|
24512
|
+
exports.EnumAstNodeStatus.Unparsed |
|
|
24513
|
+
exports.EnumAstNodeStatus.Malformed)) {
|
|
24337
24514
|
return ast;
|
|
24338
24515
|
}
|
|
24339
24516
|
const result = Object.assign(cloneNode(ast), { chi: [] });
|
|
@@ -24381,11 +24558,12 @@
|
|
|
24381
24558
|
return result;
|
|
24382
24559
|
}
|
|
24383
24560
|
function expandRule(node) {
|
|
24384
|
-
if (node[STATE]
|
|
24385
|
-
|
|
24386
|
-
|
|
24387
|
-
|
|
24388
|
-
|
|
24561
|
+
if (node[STATE] &
|
|
24562
|
+
(exports.EnumAstNodeStatus.Invalid |
|
|
24563
|
+
exports.EnumAstNodeStatus.Disallowed |
|
|
24564
|
+
exports.EnumAstNodeStatus.Unknown |
|
|
24565
|
+
exports.EnumAstNodeStatus.Unparsed |
|
|
24566
|
+
exports.EnumAstNodeStatus.Malformed)) {
|
|
24389
24567
|
return [node];
|
|
24390
24568
|
}
|
|
24391
24569
|
const ast = Object.assign(cloneNode(node), { chi: node.chi.slice() });
|
|
@@ -26645,17 +26823,20 @@
|
|
|
26645
26823
|
? ""
|
|
26646
26824
|
: token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
|
|
26647
26825
|
":" +
|
|
26826
|
+
(options.indent ?? "") +
|
|
26648
26827
|
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "");
|
|
26649
26828
|
case exports.EnumToken.IfElseConditionTokenType:
|
|
26650
|
-
return renderValue(token.l) +
|
|
26829
|
+
return (renderValue(token.l, options, cache, reducer) +
|
|
26830
|
+
(options.indent ?? "") +
|
|
26831
|
+
renderValue(token.r, options, cache, reducer));
|
|
26651
26832
|
case exports.EnumToken.DeclarationNodeType:
|
|
26652
26833
|
return (token.nam +
|
|
26653
26834
|
":" +
|
|
26654
|
-
(options.minifyValues ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
|
|
26835
|
+
(options.minifyValues ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
|
|
26655
26836
|
case exports.EnumToken.MediaQueryUnaryFeatureTokenType:
|
|
26656
26837
|
return (renderValue(token.l, options, cache, reducer) +
|
|
26657
26838
|
" " +
|
|
26658
|
-
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
|
|
26839
|
+
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
|
|
26659
26840
|
case exports.EnumToken.MediaQueryConditionTokenType: {
|
|
26660
26841
|
const indent = token.op.typ == exports.EnumToken.LtTokenType ||
|
|
26661
26842
|
token.op.typ == exports.EnumToken.GtTokenType ||
|
|
@@ -26669,14 +26850,14 @@
|
|
|
26669
26850
|
indent +
|
|
26670
26851
|
renderValue(token.op, options, cache, reducer) +
|
|
26671
26852
|
indent +
|
|
26672
|
-
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
|
|
26853
|
+
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
|
|
26673
26854
|
}
|
|
26674
26855
|
case exports.EnumToken.MediaRangeQueryTokenType:
|
|
26675
|
-
return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache), "") +
|
|
26676
|
-
renderValue(token.op1) +
|
|
26856
|
+
return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
|
|
26857
|
+
renderValue(token.op1, options, cache, reducer) +
|
|
26677
26858
|
token.val.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
|
|
26678
|
-
renderValue(token.op2) +
|
|
26679
|
-
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
|
|
26859
|
+
renderValue(token.op2, options, cache, reducer) +
|
|
26860
|
+
token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
|
|
26680
26861
|
case exports.EnumToken.MediaFeatureTokenType:
|
|
26681
26862
|
return token.val;
|
|
26682
26863
|
case exports.EnumToken.NotTokenType:
|
|
@@ -28880,6 +29061,7 @@
|
|
|
28880
29061
|
let rules = null;
|
|
28881
29062
|
let syntaxRules = null;
|
|
28882
29063
|
let success = true;
|
|
29064
|
+
let hasImportantFlag = false;
|
|
28883
29065
|
let validate = typeof options.validation === "boolean" ? options.validation : !!options.validation;
|
|
28884
29066
|
if (renamedStandardProperties.has(name.val)) {
|
|
28885
29067
|
name.val = renamedStandardProperties.get(name.val);
|
|
@@ -29181,6 +29363,9 @@
|
|
|
29181
29363
|
}
|
|
29182
29364
|
}
|
|
29183
29365
|
break;
|
|
29366
|
+
case exports.EnumToken.ImportantTokenType:
|
|
29367
|
+
hasImportantFlag = true;
|
|
29368
|
+
break;
|
|
29184
29369
|
}
|
|
29185
29370
|
if (trimTokenSpace$1.has(token.typ)) {
|
|
29186
29371
|
if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
|
|
@@ -29247,6 +29432,9 @@
|
|
|
29247
29432
|
}
|
|
29248
29433
|
name[STATE] = exports.EnumAstNodeStatus.Unknown;
|
|
29249
29434
|
name[ERRORS] = result?.errors ?? [];
|
|
29435
|
+
if (hasImportantFlag) {
|
|
29436
|
+
name[STATE] |= exports.EnumAstNodeStatus.ImportantDeclaration;
|
|
29437
|
+
}
|
|
29250
29438
|
// @ts-expect-error
|
|
29251
29439
|
return Object.assign(name, {
|
|
29252
29440
|
typ: exports.EnumToken.DeclarationNodeType,
|
|
@@ -29284,6 +29472,9 @@
|
|
|
29284
29472
|
: exports.EnumAstNodeStatus.Validated
|
|
29285
29473
|
: exports.EnumAstNodeStatus.ValidationFailed;
|
|
29286
29474
|
name[ERRORS] = result?.errors ?? [];
|
|
29475
|
+
if (hasImportantFlag) {
|
|
29476
|
+
name[STATE] |= exports.EnumAstNodeStatus.ImportantDeclaration;
|
|
29477
|
+
}
|
|
29287
29478
|
// @ts-expect-error
|
|
29288
29479
|
return Object.assign(name, {
|
|
29289
29480
|
typ: exports.EnumToken.DeclarationNodeType,
|
|
@@ -31511,14 +31702,14 @@
|
|
|
31511
31702
|
if (invalidNodes.length > 0) {
|
|
31512
31703
|
let count = invalidNodes.length;
|
|
31513
31704
|
for (const { node, parent } of walk(ast)) {
|
|
31514
|
-
if (options.lenient && node[STATE]
|
|
31705
|
+
if (options.lenient && node[STATE] & exports.EnumAstNodeStatus.Unknown) {
|
|
31515
31706
|
continue;
|
|
31516
31707
|
}
|
|
31517
|
-
if (node[STATE]
|
|
31518
|
-
node[STATE]
|
|
31519
|
-
node[STATE]
|
|
31520
|
-
node[STATE]
|
|
31521
|
-
node[STATE]
|
|
31708
|
+
if (node[STATE] & exports.EnumAstNodeStatus.Invalid ||
|
|
31709
|
+
node[STATE] & exports.EnumAstNodeStatus.Unknown ||
|
|
31710
|
+
node[STATE] & exports.EnumAstNodeStatus.Unparsed ||
|
|
31711
|
+
node[STATE] & exports.EnumAstNodeStatus.Malformed ||
|
|
31712
|
+
node[STATE] & exports.EnumAstNodeStatus.Disallowed) {
|
|
31522
31713
|
// @ts-ignore
|
|
31523
31714
|
parent.chi.splice(parent.chi.indexOf(node), 1);
|
|
31524
31715
|
node[PARENT] = null;
|
|
@@ -32506,14 +32697,14 @@
|
|
|
32506
32697
|
if (invalidNodes.length > 0) {
|
|
32507
32698
|
let count = invalidNodes.length;
|
|
32508
32699
|
for (const { node, parent } of walk(ast)) {
|
|
32509
|
-
if (options.lenient && node[STATE]
|
|
32700
|
+
if (options.lenient && node[STATE] & exports.EnumAstNodeStatus.Unknown) {
|
|
32510
32701
|
continue;
|
|
32511
32702
|
}
|
|
32512
|
-
if (node[STATE]
|
|
32513
|
-
node[STATE]
|
|
32514
|
-
node[STATE]
|
|
32515
|
-
node[STATE]
|
|
32516
|
-
node[STATE]
|
|
32703
|
+
if (node[STATE] & exports.EnumAstNodeStatus.Invalid ||
|
|
32704
|
+
node[STATE] & exports.EnumAstNodeStatus.Unknown ||
|
|
32705
|
+
node[STATE] & exports.EnumAstNodeStatus.Unparsed ||
|
|
32706
|
+
node[STATE] & exports.EnumAstNodeStatus.Malformed ||
|
|
32707
|
+
node[STATE] & exports.EnumAstNodeStatus.Disallowed) {
|
|
32517
32708
|
// @ts-ignore
|
|
32518
32709
|
parent.chi.splice(parent.chi.indexOf(node), 1);
|
|
32519
32710
|
node[PARENT] = null;
|
|
@@ -33244,11 +33435,12 @@
|
|
|
33244
33435
|
if (node == null) {
|
|
33245
33436
|
return null;
|
|
33246
33437
|
}
|
|
33247
|
-
if (node[STATE]
|
|
33248
|
-
|
|
33249
|
-
|
|
33250
|
-
|
|
33251
|
-
|
|
33438
|
+
if (node[STATE] &
|
|
33439
|
+
(exports.EnumAstNodeStatus.Invalid |
|
|
33440
|
+
exports.EnumAstNodeStatus.Disallowed |
|
|
33441
|
+
exports.EnumAstNodeStatus.Unknown |
|
|
33442
|
+
exports.EnumAstNodeStatus.Unparsed |
|
|
33443
|
+
exports.EnumAstNodeStatus.Malformed)) {
|
|
33252
33444
|
invalidNodes.push(node);
|
|
33253
33445
|
}
|
|
33254
33446
|
stats.nodesCount++;
|
|
@@ -33266,11 +33458,11 @@
|
|
|
33266
33458
|
context.chi.push(node);
|
|
33267
33459
|
node[PARENT] = context;
|
|
33268
33460
|
node[ROOT] = context[ROOT];
|
|
33269
|
-
if (node[STATE]
|
|
33270
|
-
node[STATE]
|
|
33271
|
-
node[STATE]
|
|
33272
|
-
node[STATE]
|
|
33273
|
-
node[STATE]
|
|
33461
|
+
if (node[STATE] & exports.EnumAstNodeStatus.Invalid ||
|
|
33462
|
+
node[STATE] & exports.EnumAstNodeStatus.Disallowed ||
|
|
33463
|
+
node[STATE] & exports.EnumAstNodeStatus.Unknown ||
|
|
33464
|
+
node[STATE] & exports.EnumAstNodeStatus.Unparsed ||
|
|
33465
|
+
node[STATE] & exports.EnumAstNodeStatus.Malformed) {
|
|
33274
33466
|
invalidNodes.push(node);
|
|
33275
33467
|
}
|
|
33276
33468
|
return node;
|
|
@@ -33280,7 +33472,9 @@
|
|
|
33280
33472
|
node[PARENT] = context;
|
|
33281
33473
|
node[ROOT] = context[ROOT];
|
|
33282
33474
|
if (context.typ === exports.EnumToken.StyleSheetNodeType && node.typ === exports.EnumToken.DeclarationNodeType) {
|
|
33283
|
-
node[STATE]
|
|
33475
|
+
node[STATE] |=
|
|
33476
|
+
exports.EnumAstNodeStatus.Invalid &
|
|
33477
|
+
~(exports.EnumAstNodeStatus.Validated | exports.EnumAstNodeStatus.Unvalidated | exports.EnumAstNodeStatus.Unparsed);
|
|
33284
33478
|
errors.push({
|
|
33285
33479
|
message: "<declaration> not allowed in <stylesheet>",
|
|
33286
33480
|
action: "drop",
|
|
@@ -33291,11 +33485,12 @@
|
|
|
33291
33485
|
else if (options.lenient || node.typ === exports.EnumToken.DeclarationNodeType) {
|
|
33292
33486
|
context.chi.push(node);
|
|
33293
33487
|
}
|
|
33294
|
-
if (node[STATE]
|
|
33295
|
-
|
|
33296
|
-
|
|
33297
|
-
|
|
33298
|
-
|
|
33488
|
+
if (node[STATE] &
|
|
33489
|
+
(exports.EnumAstNodeStatus.Invalid |
|
|
33490
|
+
exports.EnumAstNodeStatus.Disallowed |
|
|
33491
|
+
exports.EnumAstNodeStatus.Unknown |
|
|
33492
|
+
exports.EnumAstNodeStatus.Unparsed |
|
|
33493
|
+
exports.EnumAstNodeStatus.Malformed)) {
|
|
33299
33494
|
invalidNodes.push(node);
|
|
33300
33495
|
}
|
|
33301
33496
|
}
|