@tbela99/css-parser 1.6.5 → 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/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"] = 0] = "Validated";
30
+ EnumAstNodeStatus[EnumAstNodeStatus["Validated"] = 1] = "Validated";
31
31
  /**
32
32
  * Node is invalid
33
33
  */
34
- EnumAstNodeStatus[EnumAstNodeStatus["Invalid"] = 1] = "Invalid";
34
+ EnumAstNodeStatus[EnumAstNodeStatus["Invalid"] = 2] = "Invalid";
35
35
  /**
36
36
  * node is not validated
37
37
  */
38
- EnumAstNodeStatus[EnumAstNodeStatus["Unvalidated"] = 2] = "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"] = 3] = "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"] = 4] = "Unknown";
46
+ EnumAstNodeStatus[EnumAstNodeStatus["Unknown"] = 16] = "Unknown";
47
47
  /**
48
48
  * Failed to parse the node.
49
49
  */
50
- EnumAstNodeStatus[EnumAstNodeStatus["Unparsed"] = 5] = "Unparsed";
50
+ EnumAstNodeStatus[EnumAstNodeStatus["Unparsed"] = 32] = "Unparsed";
51
51
  /**
52
52
  * Node is disallowed in the context
53
53
  */
54
- EnumAstNodeStatus[EnumAstNodeStatus["Disallowed"] = 6] = "Disallowed";
54
+ EnumAstNodeStatus[EnumAstNodeStatus["Disallowed"] = 64] = "Disallowed";
55
55
  /**
56
56
  * Node is malformed
57
57
  */
58
- EnumAstNodeStatus[EnumAstNodeStatus["Malformed"] = 7] = "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
@@ -3518,7 +3526,7 @@ var syntaxes = {
3518
3526
  syntax: "<number> | <percentage> | none"
3519
3527
  },
3520
3528
  "an+b": {
3521
- syntax: "odd | even | <integer> | <n-dimension> | '+'?† n | -n | <ndashdigit-dimension> | '+'?† <ndashdigit-ident> | <dashndashdigit-ident> | <n-dimension> <signed-integer> | '+'?† n <signed-integer> | -n <signed-integer> | <ndash-dimension> <signless-integer> | '+'?† n- <signless-integer> | -n- <signless-integer> | <n-dimension> ['+' | '-'] <signless-integer> | '+'?† n ['+' | '-'] <signless-integer> | -n ['+' | '-'] <signless-integer>"
3529
+ syntax: "odd | even | <integer> | <n-dimension> | '+'? n | -n | <ndashdigit-dimension> | '+'? <ndashdigit-ident> | <dashndashdigit-ident> | <n-dimension> <signed-integer> | '+'? n <signed-integer> | -n <signed-integer> | <ndash-dimension> <signless-integer> | '+'? n- <signless-integer> | -n- <signless-integer> | <n-dimension> ['+' | '-'] <signless-integer> | '+'? n ['+' | '-'] <signless-integer> | -n ['+' | '-'] <signless-integer>"
3522
3530
  },
3523
3531
  "anchor()": {
3524
3532
  syntax: "anchor( <anchor-name>? && <anchor-side>, <length-percentage>? )"
@@ -5551,6 +5559,9 @@ var atRules = {
5551
5559
  marks: {
5552
5560
  syntax: "none | [ crop || cross ]"
5553
5561
  },
5562
+ "page-margin-safety": {
5563
+ syntax: "none | clamp | add"
5564
+ },
5554
5565
  "page-orientation": {
5555
5566
  syntax: "upright | rotate-left | rotate-right"
5556
5567
  },
@@ -7485,7 +7496,7 @@ function oklabToken(values) {
7485
7496
  { typ: exports.EnumToken.NumberTokenType, val: values[1] },
7486
7497
  { typ: exports.EnumToken.NumberTokenType, val: values[2] },
7487
7498
  ];
7488
- if (values.length == 4) {
7499
+ if (values.length == 4 && values[3] != 1) {
7489
7500
  chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
7490
7501
  typ: exports.EnumToken.PercentageTokenType,
7491
7502
  val: values[3] * 100,
@@ -7874,6 +7885,222 @@ function Lab_to_XYZ(l, a, b) {
7874
7885
  return xyz.map((value, i) => value * D50[i]);
7875
7886
  }
7876
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
+
7877
8104
  // from https://www.w3.org/TR/css-color-4/#color-conversion-code
7878
8105
  // srgb-linear -> srgb
7879
8106
  // 0 <= r, g, b <= 1
@@ -7947,25 +8174,59 @@ function xyz2srgb(x, y, z, alpha = null) {
7947
8174
  return lsrgb2srgbvalues(values[0], values[1], values[2], alpha);
7948
8175
  }
7949
8176
  function hwb2srgbvalues(token) {
7950
- const { h: hue, s: white, l: black, a: alpha } = hslvalues(token) ?? {};
7951
- if (hue == null || white == null || black == null) {
8177
+ const { h, w, b, a } = hwbvalues(token) ?? {};
8178
+ if (h == null || w == null || b == null) {
7952
8179
  return [];
7953
8180
  }
7954
- const rgb = hslvalues2srgbvalues(hue, 1, 0.5);
7955
- for (let i = 0; i < 3; i++) {
7956
- rgb[i] *= 1 - white - black;
7957
- rgb[i] = rgb[i] + white;
7958
- }
7959
- if (alpha != null && alpha != 1) {
7960
- rgb.push(alpha);
8181
+ const rgb = hwb2srgb(h, w, b);
8182
+ if (a != null && a != 1) {
8183
+ rgb.push(a);
7961
8184
  }
7962
8185
  return rgb;
7963
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
+ }
7964
8224
  function hsl2srgb(token) {
7965
8225
  let { h, s, l, a } = hslvalues(token) ?? {};
7966
8226
  if (h == null || s == null || l == null) {
7967
8227
  return null;
7968
8228
  }
8229
+ // hue in degrees
7969
8230
  return hslvalues2srgbvalues(h, s, l, a);
7970
8231
  }
7971
8232
  function cmyk2srgbvalues(token) {
@@ -8026,7 +8287,7 @@ function hslvalues(token) {
8026
8287
  }
8027
8288
  let t;
8028
8289
  // @ts-ignore
8029
- let h = getAngle(components[0]);
8290
+ let h = getAngle(components[0]) * 360;
8030
8291
  // @ts-ignore
8031
8292
  t = components[1];
8032
8293
  // @ts-ignore
@@ -8035,6 +8296,12 @@ function hslvalues(token) {
8035
8296
  t = components[2];
8036
8297
  // @ts-ignore
8037
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
+ }
8038
8305
  let a = null;
8039
8306
  if (components.length == 4) {
8040
8307
  // @ts-ignore
@@ -8045,56 +8312,38 @@ function hslvalues(token) {
8045
8312
  return a == null ? { h, s, l } : { h, s, l, a };
8046
8313
  }
8047
8314
  function hslvalues2srgbvalues(h, s, l, a = null) {
8048
- let v = l <= 0.5 ? l * (1.0 + s) : l + s - l * s;
8049
- let r = l;
8050
- let g = l;
8051
- let b = l;
8052
- if (v > 0) {
8053
- let m = l + l - v;
8054
- let sv = (v - m) / v;
8055
- h *= 6.0;
8056
- let sextant = Math.floor(h);
8057
- let fract = h - sextant;
8058
- let vsf = v * sv * fract;
8059
- let mid1 = m + vsf;
8060
- let mid2 = v - vsf;
8061
- switch (sextant) {
8062
- case 0:
8063
- r = v;
8064
- g = mid1;
8065
- b = m;
8066
- break;
8067
- case 1:
8068
- r = mid2;
8069
- g = v;
8070
- b = m;
8071
- break;
8072
- case 2:
8073
- r = m;
8074
- g = v;
8075
- b = mid1;
8076
- break;
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) {
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) {
8096
8344
  values.push(a);
8097
8345
  }
8346
+ // Return exact float decimals instead of multiplying by 255
8098
8347
  return values;
8099
8348
  }
8100
8349
  function lab2srgbvalues(token) {
@@ -8467,25 +8716,6 @@ function lch2rgbvalues(token) {
8467
8716
  return lch2srgbvalues(token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
8468
8717
  }
8469
8718
 
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
8719
  function hex2HslToken(token) {
8490
8720
  let values = hex2srgbvalues(token);
8491
8721
  if (values == null) {
@@ -8550,11 +8780,17 @@ function color2HslToken(token) {
8550
8780
  return hslToken(srgb2hslvalues(values[0], values[1], values[2], values[3]));
8551
8781
  }
8552
8782
  function hslToken(values) {
8553
- values[0] = values[0] * 360;
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
+ }
8554
8790
  const chi = [
8555
8791
  { typ: exports.EnumToken.NumberTokenType, val: values[0] },
8556
- { typ: exports.EnumToken.PercentageTokenType, val: values[1] * 100 },
8557
- { typ: exports.EnumToken.PercentageTokenType, val: values[2] * 100 },
8792
+ { typ: exports.EnumToken.PercentageTokenType, val: values[1] },
8793
+ { typ: exports.EnumToken.PercentageTokenType, val: values[2] },
8558
8794
  ];
8559
8795
  if (values.length == 4 && values[3] != 1) {
8560
8796
  chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
@@ -8597,32 +8833,33 @@ function rgb2hslvalues(token) {
8597
8833
  }
8598
8834
  return rgbvalues2hslvalues(values[0], values[1], values[2], values[3]);
8599
8835
  }
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
8836
  function cmyk2hslvalues(token) {
8619
8837
  const values = cmyk2rgbvalues(token);
8620
8838
  return values == null ? null : rgbvalues2hslvalues(values[0], values[1], values[2], values[3]);
8621
8839
  }
8622
8840
  function hwb2hslvalues(token) {
8623
- const hsla = hslvalues(token);
8624
- const hwba = hwb2hsv(hsla.h, hsla.s, hsla.l, hsla.a);
8625
- return hsv2hsl(hwba[0], hwba[1], hwba[2], hwba[3]);
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;
8626
8863
  }
8627
8864
  function lab2hslvalues(token) {
8628
8865
  const values = lab2rgbvalues(token);
@@ -8653,28 +8890,28 @@ function rgbvalues2hslvalues(r, g, b, a = null) {
8653
8890
  return srgb2hslvalues(r / 255, g / 255, b / 255, a);
8654
8891
  }
8655
8892
  function srgb2hslvalues(r, g, b, a = null) {
8656
- let max = Math.max(r, g, b);
8657
- let min = Math.min(r, g, b);
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;
8658
8897
  let h = 0;
8659
8898
  let s = 0;
8660
- let l = (max + min) / 2;
8661
- if (max != min) {
8662
- let d = max - min;
8663
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
8899
+ if (delta !== 0) {
8900
+ s = delta / (1 - Math.abs(2 * l - 1));
8664
8901
  switch (max) {
8665
8902
  case r:
8666
- h = (g - b) / d + (g < b ? 6 : 0);
8903
+ h = 60 * (((g - b) / delta) % 6);
8667
8904
  break;
8668
8905
  case g:
8669
- h = (b - r) / d + 2;
8906
+ h = 60 * ((b - r) / delta + 2);
8670
8907
  break;
8671
8908
  case b:
8672
- h = (r - g) / d + 4;
8909
+ h = 60 * ((r - g) / delta + 4);
8673
8910
  break;
8674
8911
  }
8675
- h /= 6;
8676
8912
  }
8677
- const hsl = [h, s, l];
8913
+ h = ((h % 360) + 360) % 360;
8914
+ const hsl = [h, s * 100, l * 100];
8678
8915
  if (a != null && a < 1) {
8679
8916
  // @ts-ignore
8680
8917
  return hsl.concat([a]);
@@ -8683,191 +8920,6 @@ function srgb2hslvalues(r, g, b, a = null) {
8683
8920
  return hsl;
8684
8921
  }
8685
8922
 
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
8923
  function prophotorgb2srgbvalues(r, g, b, a = null) {
8872
8924
  let values = prophotorgb2xyz50(r, g, b);
8873
8925
  // @ts-ignore
@@ -9169,6 +9221,7 @@ function colorMix(...args) {
9169
9221
  const percentages = [];
9170
9222
  const srgbComponentValues = [];
9171
9223
  const colorComponents = [];
9224
+ const colors = [];
9172
9225
  if (args[i]?.typ === exports.EnumToken.IdenTokenType) {
9173
9226
  if (!equalsIgnoreCase(args[i++].val, "in")) {
9174
9227
  return null;
@@ -9218,9 +9271,10 @@ function colorMix(...args) {
9218
9271
  if (values == null) {
9219
9272
  return null;
9220
9273
  }
9221
- if (colorSpace == "hwb") {
9222
- colorSpace = "srgb";
9223
- }
9274
+ // if (colorSpace == "hwb") {
9275
+ // colorSpace = "srgb";
9276
+ // }
9277
+ colors.push(processPowerlessComponents(args[i]));
9224
9278
  switch (colorSpace) {
9225
9279
  case "srgb":
9226
9280
  break;
@@ -9250,17 +9304,12 @@ function colorMix(...args) {
9250
9304
  values = srgb2xyz_d65(values[0], values[1], values[2], values[3]);
9251
9305
  values = XYZ_D65_to_D50(values[0], values[1], values[2], values[3]);
9252
9306
  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
9307
  case "hsl":
9259
9308
  values = srgb2hslvalues(values[0], values[1], values[2], values[3]);
9260
9309
  break;
9261
- // case "hwb":
9262
- // values = srgb2hwb(values[0], values[1], values[2], values[3]);
9263
- // break;
9310
+ case "hwb":
9311
+ values = srgb2hwb(values[0], values[1], values[2], values[3]);
9312
+ break;
9264
9313
  case "lab":
9265
9314
  values = srgb2labvalues(values[0], values[1], values[2], values[3]);
9266
9315
  break;
@@ -9322,7 +9371,8 @@ function colorMix(...args) {
9322
9371
  }
9323
9372
  }
9324
9373
  const stack = [];
9325
- const lchSpaces = ["lch", "oklch"];
9374
+ // const lchSpaces: string[] = ["lch", "oklch"];
9375
+ const isLCHOrOKLCH = colorSpace === "lch" || colorSpace == "oklch";
9326
9376
  i = srgbComponentValues.length;
9327
9377
  while (i--) {
9328
9378
  stack.push({
@@ -9340,46 +9390,73 @@ function colorMix(...args) {
9340
9390
  let premult1;
9341
9391
  let premult2;
9342
9392
  let mixedPremult;
9343
- let colorSpace1 = exports.ColorType[
9344
- // @ts-expect-error
9345
- colorComponents.at(-1).kin
9346
- // @ts-expect-error
9347
- ]?.toLowerCase?.();
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) {
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) {
9352
9398
  // fix powerless alpha for last color if previous color has alpha
9353
9399
  stack[stack.length - 1].color[3] = stack[stack.length - 2].color[3];
9354
9400
  }
9355
- // powerless hue for lch spaces
9356
- if (lchSpaces.includes(colorSpace1) || lchSpaces.includes(colorSpace)) {
9357
- if ((stack.length > 1 &&
9358
- colorComponents[0][2].typ == exports.EnumToken.IdenTokenType &&
9359
- colorComponents[0][2].val == "none") ||
9360
- stack[stack.length - 1].color[2] == 0) {
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]))) {
9361
9424
  stack[stack.length - 1].color[2] = stack[stack.length - 2].color[2];
9362
9425
  }
9426
+ // }
9363
9427
  }
9428
+ // console.error([colorComponents[0][offset1].typ == EnumToken.IdenTokenType, (colorComponents[0][offset1] as IdentToken).val == "none"]);
9429
+ // console.error(isLCHOrOKLCH, colorComponents, stack);
9364
9430
  while (stack.length > 1) {
9365
9431
  r1 = stack.pop();
9366
9432
  r2 = stack.pop();
9433
+ offset1 = colors[++currentIndex].kin == exports.ColorType.COLOR ? 1 : 0;
9367
9434
  // r2 powerless alpha
9368
- if (colorComponents[++currentIndex][3] != null &&
9369
- colorComponents[currentIndex][3].typ == exports.EnumToken.IdenTokenType &&
9370
- 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") {
9371
9438
  // fix powerless alpha for last color if previous color has alpha
9372
9439
  r2.color[3] = r1.color[3];
9373
9440
  }
9374
- // @ts-expect-error
9375
- colorSpace1 = exports.ColorType[colorComponents[currentIndex].kin]?.toLowerCase?.();
9376
9441
  // powerless hue for lch spaces
9377
- if (lchSpaces.includes(colorSpace1) || lchSpaces.includes(colorSpace)) {
9378
- if ((colorComponents[currentIndex][2].typ == exports.EnumToken.IdenTokenType &&
9379
- colorComponents[currentIndex][2].val == "none") ||
9380
- r2.color[2] == 0) {
9381
- r2.color[2] = r1.color[2];
9382
- }
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];
9383
9460
  }
9384
9461
  if (hueInterpolationMethod != null) {
9385
9462
  let hueIndex = 2;
@@ -9407,6 +9484,7 @@ function colorMix(...args) {
9407
9484
  alpha: mult,
9408
9485
  };
9409
9486
  }
9487
+ // console.error({ r1, r2, r, premult1, mult1, premult2, mult2, mixedPremult, mult });
9410
9488
  stack.push(r);
9411
9489
  }
9412
9490
  const result = stack.pop();
@@ -9461,16 +9539,16 @@ function colorMix(...args) {
9461
9539
  };
9462
9540
  // case "rgb":
9463
9541
  case "hsl":
9464
- // case "hwb":
9542
+ case "hwb":
9465
9543
  case "lab":
9466
9544
  case "lch":
9467
9545
  case "oklab":
9468
9546
  case "oklch":
9469
- if (colorSpace == "hsl") {
9547
+ if (colorSpace == "hsl" || colorSpace == "hwb") {
9470
9548
  // @ts-ignore
9471
9549
  if (values[2] < 0) {
9472
9550
  // @ts-ignore
9473
- values[2] += 1;
9551
+ values[2] += 360;
9474
9552
  }
9475
9553
  }
9476
9554
  else if (colorSpace == "lch" || colorSpace == "oklch") {
@@ -9498,16 +9576,72 @@ function colorMix(...args) {
9498
9576
  };
9499
9577
  if (colorSpace == "hsl") {
9500
9578
  // @ts-ignore
9501
- result.chi[0] = { typ: exports.EnumToken.AngleTokenType, val: result.chi[0].val * 360 };
9579
+ result.chi[0] = { typ: exports.EnumToken.AngleTokenType, val: result.chi[0].val };
9502
9580
  // @ts-ignore
9503
- result.chi[1] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[1].val * 100 };
9581
+ result.chi[1] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[1].val };
9504
9582
  // @ts-ignore
9505
- result.chi[2] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[2].val * 100 };
9583
+ result.chi[2] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[2].val };
9506
9584
  }
9507
9585
  return result;
9508
9586
  }
9509
9587
  return null;
9510
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
+ }
9511
9645
 
9512
9646
  /**
9513
9647
  * Options for the walk function
@@ -9545,6 +9679,7 @@ exports.WalkerEvent = void 0;
9545
9679
  */
9546
9680
  WalkerEvent[WalkerEvent["Leave"] = 2] = "Leave";
9547
9681
  })(exports.WalkerEvent || (exports.WalkerEvent = {}));
9682
+ const maxQueueLength = 25000;
9548
9683
  /**
9549
9684
  * Walk ast nodes
9550
9685
  * @param node initial node
@@ -9648,6 +9783,10 @@ function* walk(node, filter, reverse) {
9648
9783
  },
9649
9784
  };
9650
9785
  while ((node = parents[i++])) {
9786
+ if (i > maxQueueLength) {
9787
+ parents.splice(0, maxQueueLength);
9788
+ i -= maxQueueLength;
9789
+ }
9651
9790
  let option = null;
9652
9791
  if (filter != null) {
9653
9792
  // @ts-expect-error
@@ -9791,6 +9930,10 @@ function* walkValues(values, root = null, filter, reverse) {
9791
9930
  while (++i < stack.length) {
9792
9931
  value = stack[i];
9793
9932
  option = null;
9933
+ if (i > maxQueueLength) {
9934
+ stack.splice(0, maxQueueLength);
9935
+ i -= maxQueueLength;
9936
+ }
9794
9937
  if (filter.fn != null && eventType & exports.WalkerEvent.Enter) {
9795
9938
  const isValid = filter.type == null ||
9796
9939
  value.typ == filter.type ||
@@ -10030,6 +10173,7 @@ function simplify(a, b) {
10030
10173
  return g > 1 ? [a / g, b / g] : [a, b];
10031
10174
  }
10032
10175
 
10176
+ const numbers = new Set(["sin", "cos", "asin", "acos", "sign", "tan"]);
10033
10177
  /**
10034
10178
  * evaluate an array of tokens
10035
10179
  * @param tokens
@@ -10219,9 +10363,22 @@ function doEvaluate(l, r, op) {
10219
10363
  r.typ == exports.EnumToken.NegativeInfinityTokenType) {
10220
10364
  return computeInfinity(l, r, op, defaultReturn);
10221
10365
  }
10366
+ if (l.typ == exports.EnumToken.FunctionTokenType || l.typ == exports.EnumToken.MathFunctionTokenType) {
10367
+ const val = evaluateFunc(l);
10368
+ if (val == null ||
10369
+ (val.length == 1 &&
10370
+ (val[0].typ == exports.EnumToken.MathFunctionTokenType || val[0].typ == exports.EnumToken.FunctionTokenType))) {
10371
+ return defaultReturn;
10372
+ }
10373
+ if (val.length == 1) {
10374
+ l = val[0];
10375
+ }
10376
+ }
10222
10377
  if (r.typ == exports.EnumToken.FunctionTokenType || r.typ == exports.EnumToken.MathFunctionTokenType) {
10223
10378
  const val = evaluateFunc(r);
10224
- if (val == null) {
10379
+ if (val == null ||
10380
+ (val.length == 1 &&
10381
+ (val[0].typ == exports.EnumToken.MathFunctionTokenType || val[0].typ == exports.EnumToken.FunctionTokenType))) {
10225
10382
  return defaultReturn;
10226
10383
  }
10227
10384
  if (val.length == 1) {
@@ -10439,45 +10596,43 @@ function getValue$1(t) {
10439
10596
  function evaluateFunc(token) {
10440
10597
  const values = token.chi.slice();
10441
10598
  switch (token.val) {
10442
- case "abs":
10443
10599
  case "sin":
10444
10600
  case "cos":
10445
10601
  case "tan":
10602
+ for (let i = 0; i < values.length; i++) {
10603
+ if (values[i].typ == exports.EnumToken.NumberTokenType) {
10604
+ values[i] = Object.assign(values[i], { typ: exports.EnumToken.AngleTokenType, unit: "rad" });
10605
+ }
10606
+ else if (values[i].typ == exports.EnumToken.AngleTokenType && values[i].unit != "rad") {
10607
+ switch (values[i].unit) {
10608
+ case "deg":
10609
+ Object.assign(values[i], {
10610
+ unit: "rad",
10611
+ val: values[i].val * (Math.PI / 180),
10612
+ });
10613
+ break;
10614
+ case "grad":
10615
+ Object.assign(values[i], {
10616
+ unit: "rad",
10617
+ val: values[i].val * (Math.PI / 200),
10618
+ });
10619
+ break;
10620
+ case "turn":
10621
+ Object.assign(values[i], {
10622
+ unit: "rad",
10623
+ val: values[i].val * (2 * Math.PI),
10624
+ });
10625
+ break;
10626
+ }
10627
+ }
10628
+ }
10446
10629
  case "asin":
10447
10630
  case "acos":
10448
10631
  case "atan":
10632
+ case "abs":
10449
10633
  case "sign":
10450
10634
  case "sqrt":
10451
- case "exp": {
10452
- if (token.val == "tan" || token.val == "atan") {
10453
- for (let i = 0; i < values.length; i++) {
10454
- if (values[i].typ == exports.EnumToken.NumberTokenType) {
10455
- values[i] = Object.assign(values[i], { typ: exports.EnumToken.AngleTokenType, unit: "rad" });
10456
- }
10457
- else if (values[i].typ == exports.EnumToken.AngleTokenType && values[i].unit != "rad") {
10458
- switch (values[i].unit) {
10459
- case "deg":
10460
- Object.assign(values[i], {
10461
- unit: "rad",
10462
- val: values[i].val * (Math.PI / 180),
10463
- });
10464
- break;
10465
- case "grad":
10466
- Object.assign(values[i], {
10467
- unit: "rad",
10468
- val: values[i].val * (Math.PI / 200),
10469
- });
10470
- break;
10471
- case "turn":
10472
- Object.assign(values[i], {
10473
- unit: "rad",
10474
- val: values[i].val * (2 * Math.PI),
10475
- });
10476
- break;
10477
- }
10478
- }
10479
- }
10480
- }
10635
+ case "exp":
10481
10636
  const value = evaluate(values);
10482
10637
  // @ts-ignore
10483
10638
  let val = value[0].typ == exports.EnumToken.NumberTokenType ||
@@ -10487,7 +10642,7 @@ function evaluateFunc(token) {
10487
10642
  : // @ts-expect-error
10488
10643
  value[0].l.val / value[0].r.val;
10489
10644
  return [
10490
- token.val == "tan" || token.val == "atan"
10645
+ token.val == "asin" || token.val == "acos" || token.val == "atan"
10491
10646
  ? {
10492
10647
  typ: exports.EnumToken.AngleTokenType,
10493
10648
  val: Math[token.val](val),
@@ -10498,7 +10653,7 @@ function evaluateFunc(token) {
10498
10653
  [PARENT]: value[0][PARENT],
10499
10654
  }
10500
10655
  : {
10501
- typ: token.val == "sign" ? exports.EnumToken.NumberTokenType : value[0].typ,
10656
+ typ: numbers.has(token.val) ? exports.EnumToken.NumberTokenType : value[0].typ,
10502
10657
  val: Math[token.val](val),
10503
10658
  [LOCSRCID]: value[0][LOCSRCID],
10504
10659
  [LOCSTA]: value[0][LOCSTA],
@@ -10506,7 +10661,6 @@ function evaluateFunc(token) {
10506
10661
  [PARENT]: value[0][PARENT],
10507
10662
  },
10508
10663
  ];
10509
- }
10510
10664
  case "hypot": {
10511
10665
  const chi = values.filter((t) => ![exports.EnumToken.WhitespaceTokenType, exports.EnumToken.CommentTokenType, exports.EnumToken.CommaTokenType].includes(t.typ));
10512
10666
  let all = [];
@@ -11012,7 +11166,36 @@ function parseRelativeColorComponents(relativeKeys, original, rExp, gExp, bExp,
11012
11166
  : aExp),
11013
11167
  };
11014
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
11015
11197
  if (result?.alpha?.typ == exports.EnumToken.NumberTokenType && result.alpha.val === 1) {
11198
+ // @ts-ignore
11016
11199
  const { alpha, ...components } = result;
11017
11200
  return components;
11018
11201
  }
@@ -12261,7 +12444,8 @@ function isMFValue(featureName, tokens, isMFRange) {
12261
12444
  return { valid: true, success: false, isValueAllowed: false };
12262
12445
  }
12263
12446
  featureName = featureName.toLowerCase();
12264
- if (!(featureName in config$3.mediaFeatures)) {
12447
+ // @ts-expect-error
12448
+ if (config$3.mediaFeatures[featureName] == null) {
12265
12449
  return { valid: false, success: false };
12266
12450
  }
12267
12451
  // @ts-expect-error
@@ -12305,8 +12489,7 @@ function isMFValue(featureName, tokens, isMFRange) {
12305
12489
  return {
12306
12490
  valid: true,
12307
12491
  success: (tokens.length == 1 &&
12308
- tokens[0].typ == exports.EnumToken.NumberTokenType &&
12309
- tokens[0].val.typ == exports.EnumToken.FractionTokenType) ||
12492
+ tokens[0].typ == exports.EnumToken.NumberTokenType) ||
12310
12493
  (tokens.length === 3 &&
12311
12494
  tokens[0].typ == exports.EnumToken.NumberTokenType &&
12312
12495
  typeof tokens[0].val === "number" &&
@@ -15154,7 +15337,6 @@ function getAngle(token) {
15154
15337
  return +token.val;
15155
15338
  }
15156
15339
  }
15157
- // @ts-ignore
15158
15340
  return token.val / 360;
15159
15341
  }
15160
15342
 
@@ -17012,9 +17194,7 @@ class ComputePrefixFeature {
17012
17194
  }
17013
17195
  }
17014
17196
  run(node) {
17015
- if (node[STATE] == exports.EnumAstNodeStatus.Disallowed ||
17016
- node[STATE] == exports.EnumAstNodeStatus.Invalid ||
17017
- node[STATE] == exports.EnumAstNodeStatus.Malformed) {
17197
+ if (node[STATE] & (exports.EnumAstNodeStatus.Disallowed | exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.Malformed)) {
17018
17198
  return null;
17019
17199
  }
17020
17200
  if (node.typ == exports.EnumToken.RuleNodeType) {
@@ -19729,7 +19909,8 @@ class PropertyMap {
19729
19909
  const tokens = {};
19730
19910
  const values = [];
19731
19911
  const val = [[]];
19732
- for (const curr of this.declarations.get(this.config.shorthand).val) { // @ts-ignore
19912
+ for (const curr of this.declarations.get(this.config.shorthand).val) {
19913
+ // @ts-ignore
19733
19914
  // @ts-ignore
19734
19915
  if (separator != null && separator.typ == curr.typ && separator.val == curr.val) {
19735
19916
  val.push([]);
@@ -20673,9 +20854,8 @@ class PropertyList {
20673
20854
  let result;
20674
20855
  for (const declaration of declarations) {
20675
20856
  name = declaration.typ != exports.EnumToken.DeclarationNodeType ? null : declaration.nam;
20676
- if (declaration[STATE] == exports.EnumAstNodeStatus.Invalid ||
20677
- declaration[STATE] == exports.EnumAstNodeStatus.Unknown ||
20678
- declaration[STATE] == exports.EnumAstNodeStatus.ValidationFailed ||
20857
+ if (declaration[STATE] &
20858
+ (exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.Unknown | exports.EnumAstNodeStatus.ValidationFailed) ||
20679
20859
  declaration.typ != exports.EnumToken.DeclarationNodeType ||
20680
20860
  equalsIgnoreCase("composes", name) ||
20681
20861
  (typeof this.options.removeDuplicateDeclarations === "string" &&
@@ -20694,17 +20874,17 @@ class PropertyList {
20694
20874
  this.declarations.set(declaration.nam, declaration);
20695
20875
  continue;
20696
20876
  }
20697
- if (declaration[STATE] == exports.EnumAstNodeStatus.Unvalidated) {
20877
+ if (declaration[STATE] & exports.EnumAstNodeStatus.Unvalidated) {
20698
20878
  syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, declaration.nam.toLowerCase());
20699
20879
  if (syntaxRules != null) {
20700
20880
  result = matchAllSyntaxes(syntaxRules, createValidationContext(declaration.val), this.options);
20701
- declaration[STATE] = result.success
20702
- ? exports.EnumAstNodeStatus.Validated
20703
- : exports.EnumAstNodeStatus.ValidationFailed;
20881
+ declaration[STATE] |=
20882
+ (result.success ? exports.EnumAstNodeStatus.Validated : exports.EnumAstNodeStatus.ValidationFailed) &
20883
+ ~exports.EnumAstNodeStatus.Unvalidated;
20704
20884
  }
20705
20885
  }
20706
20886
  // do not compute shorthand for invalid declarations
20707
- if (declaration[STATE] !== exports.EnumAstNodeStatus.Validated) {
20887
+ if (!(declaration[STATE] & exports.EnumAstNodeStatus.Validated)) {
20708
20888
  this.declarations.set(objectHash(declaration), declaration);
20709
20889
  continue;
20710
20890
  }
@@ -20734,6 +20914,16 @@ class PropertyList {
20734
20914
  // @ts-ignore
20735
20915
  shorthand = config.property[propertyName];
20736
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
+ }
20737
20927
  // @ts-ignore
20738
20928
  if (shortHandType == "map") {
20739
20929
  let owner = this;
@@ -21050,7 +21240,8 @@ class ComputeCalcExpressionFeature {
21050
21240
  }
21051
21241
  }
21052
21242
  run(ast) {
21053
- if (!("chi" in ast)) {
21243
+ // @ts-ignore
21244
+ if (ast.chi == null) {
21054
21245
  return null;
21055
21246
  }
21056
21247
  for (const node of ast.chi) {
@@ -21068,15 +21259,7 @@ class ComputeCalcExpressionFeature {
21068
21259
  // @ts-ignore
21069
21260
  replaceNodeOrValue(parent, value, result);
21070
21261
  }
21071
- catch (e) {
21072
- // @ts-ignore
21073
- if (Array.isArray(parent.chi)) {
21074
- // @ts-ignore
21075
- parent.chi.length = 0;
21076
- // @ts-ignore
21077
- parent.chi.push(...result);
21078
- }
21079
- }
21262
+ catch (e) { }
21080
21263
  continue;
21081
21264
  }
21082
21265
  if (value != null && tokensfuncSet.has(value.typ)) {
@@ -22382,7 +22565,7 @@ class TransformCssFeature {
22382
22565
  for (; i < ast.chi.length; i++) {
22383
22566
  // @ts-ignore
22384
22567
  node = ast.chi[i];
22385
- if (node[STATE] == exports.EnumAstNodeStatus.Invalid || node[STATE] == exports.EnumAstNodeStatus.ValidationFailed) {
22568
+ if (node[STATE] & (exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.ValidationFailed)) {
22386
22569
  continue;
22387
22570
  }
22388
22571
  if (node.typ != exports.EnumToken.DeclarationNodeType ||
@@ -24325,11 +24508,12 @@ function reduceRuleSelector(node) {
24325
24508
  * @private
24326
24509
  */
24327
24510
  function expand(ast) {
24328
- if (ast[STATE] == exports.EnumAstNodeStatus.Invalid ||
24329
- ast[STATE] == exports.EnumAstNodeStatus.Disallowed ||
24330
- ast[STATE] == exports.EnumAstNodeStatus.Unknown ||
24331
- ast[STATE] == exports.EnumAstNodeStatus.Unparsed ||
24332
- ast[STATE] == exports.EnumAstNodeStatus.Malformed) {
24511
+ if (ast[STATE] &
24512
+ (exports.EnumAstNodeStatus.Invalid |
24513
+ exports.EnumAstNodeStatus.Disallowed |
24514
+ exports.EnumAstNodeStatus.Unknown |
24515
+ exports.EnumAstNodeStatus.Unparsed |
24516
+ exports.EnumAstNodeStatus.Malformed)) {
24333
24517
  return ast;
24334
24518
  }
24335
24519
  const result = Object.assign(cloneNode(ast), { chi: [] });
@@ -24377,11 +24561,12 @@ function expand(ast) {
24377
24561
  return result;
24378
24562
  }
24379
24563
  function expandRule(node) {
24380
- if (node[STATE] == exports.EnumAstNodeStatus.Invalid ||
24381
- node[STATE] == exports.EnumAstNodeStatus.Disallowed ||
24382
- node[STATE] == exports.EnumAstNodeStatus.Unknown ||
24383
- node[STATE] == exports.EnumAstNodeStatus.Unparsed ||
24384
- node[STATE] == exports.EnumAstNodeStatus.Malformed) {
24564
+ if (node[STATE] &
24565
+ (exports.EnumAstNodeStatus.Invalid |
24566
+ exports.EnumAstNodeStatus.Disallowed |
24567
+ exports.EnumAstNodeStatus.Unknown |
24568
+ exports.EnumAstNodeStatus.Unparsed |
24569
+ exports.EnumAstNodeStatus.Malformed)) {
24385
24570
  return [node];
24386
24571
  }
24387
24572
  const ast = Object.assign(cloneNode(node), { chi: node.chi.slice() });
@@ -26641,17 +26826,20 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
26641
26826
  ? ""
26642
26827
  : token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
26643
26828
  ":" +
26829
+ (options.indent ?? "") +
26644
26830
  token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "");
26645
26831
  case exports.EnumToken.IfElseConditionTokenType:
26646
- return renderValue(token.l) + renderValue(token.r);
26832
+ return (renderValue(token.l, options, cache, reducer) +
26833
+ (options.indent ?? "") +
26834
+ renderValue(token.r, options, cache, reducer));
26647
26835
  case exports.EnumToken.DeclarationNodeType:
26648
26836
  return (token.nam +
26649
26837
  ":" +
26650
- (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), ""));
26651
26839
  case exports.EnumToken.MediaQueryUnaryFeatureTokenType:
26652
26840
  return (renderValue(token.l, options, cache, reducer) +
26653
26841
  " " +
26654
- token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
26842
+ token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
26655
26843
  case exports.EnumToken.MediaQueryConditionTokenType: {
26656
26844
  const indent = token.op.typ == exports.EnumToken.LtTokenType ||
26657
26845
  token.op.typ == exports.EnumToken.GtTokenType ||
@@ -26665,14 +26853,14 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
26665
26853
  indent +
26666
26854
  renderValue(token.op, options, cache, reducer) +
26667
26855
  indent +
26668
- token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
26856
+ token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
26669
26857
  }
26670
26858
  case exports.EnumToken.MediaRangeQueryTokenType:
26671
- return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache), "") +
26672
- renderValue(token.op1) +
26859
+ return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
26860
+ renderValue(token.op1, options, cache, reducer) +
26673
26861
  token.val.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
26674
- renderValue(token.op2) +
26675
- 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), ""));
26676
26864
  case exports.EnumToken.MediaFeatureTokenType:
26677
26865
  return token.val;
26678
26866
  case exports.EnumToken.NotTokenType:
@@ -28876,6 +29064,7 @@ function parseDeclaration(tokens, parent, options, errors) {
28876
29064
  let rules = null;
28877
29065
  let syntaxRules = null;
28878
29066
  let success = true;
29067
+ let hasImportantFlag = false;
28879
29068
  let validate = typeof options.validation === "boolean" ? options.validation : !!options.validation;
28880
29069
  if (renamedStandardProperties.has(name.val)) {
28881
29070
  name.val = renamedStandardProperties.get(name.val);
@@ -29177,6 +29366,9 @@ function parseDeclaration(tokens, parent, options, errors) {
29177
29366
  }
29178
29367
  }
29179
29368
  break;
29369
+ case exports.EnumToken.ImportantTokenType:
29370
+ hasImportantFlag = true;
29371
+ break;
29180
29372
  }
29181
29373
  if (trimTokenSpace$1.has(token.typ)) {
29182
29374
  if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
@@ -29243,6 +29435,9 @@ function parseDeclaration(tokens, parent, options, errors) {
29243
29435
  }
29244
29436
  name[STATE] = exports.EnumAstNodeStatus.Unknown;
29245
29437
  name[ERRORS] = result?.errors ?? [];
29438
+ if (hasImportantFlag) {
29439
+ name[STATE] |= exports.EnumAstNodeStatus.ImportantDeclaration;
29440
+ }
29246
29441
  // @ts-expect-error
29247
29442
  return Object.assign(name, {
29248
29443
  typ: exports.EnumToken.DeclarationNodeType,
@@ -29280,6 +29475,9 @@ function parseDeclaration(tokens, parent, options, errors) {
29280
29475
  : exports.EnumAstNodeStatus.Validated
29281
29476
  : exports.EnumAstNodeStatus.ValidationFailed;
29282
29477
  name[ERRORS] = result?.errors ?? [];
29478
+ if (hasImportantFlag) {
29479
+ name[STATE] |= exports.EnumAstNodeStatus.ImportantDeclaration;
29480
+ }
29283
29481
  // @ts-expect-error
29284
29482
  return Object.assign(name, {
29285
29483
  typ: exports.EnumToken.DeclarationNodeType,
@@ -29471,8 +29669,6 @@ function parseMediaqueryList(stream, options) {
29471
29669
  }
29472
29670
  }
29473
29671
  }
29474
- // let isValidMFValue = isMFValue(name, left, true);
29475
- // isValidMFValue = isMFValue(name, right, true);
29476
29672
  for (const val of [left, right]) {
29477
29673
  if (mfInfo?.type === MediaFeatureType.RatioType) {
29478
29674
  const filteredValues = val.filter((n) => n.typ !== exports.EnumToken.WhitespaceTokenType &&
@@ -30268,7 +30464,7 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
30268
30464
  };
30269
30465
  }
30270
30466
  {
30271
- for (const stream of parts.slice()) {
30467
+ for (const stream of parts) {
30272
30468
  let success = true;
30273
30469
  let i;
30274
30470
  let currentScope = new Set();
@@ -30387,6 +30583,22 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
30387
30583
  [LOCSTA]: names[0][LOCSTA],
30388
30584
  [LOCEND]: values.at(-1)[LOCEND],
30389
30585
  });
30586
+ const token = tokens[index3 + 1];
30587
+ if (token.op.typ === exports.EnumToken.ColonTokenType) {
30588
+ let name = token.l.find((t) => t.typ === exports.EnumToken.IdenTokenType);
30589
+ if (name != null) {
30590
+ if (name.val.startsWith("min-")) {
30591
+ name.val = name.val.substring(4);
30592
+ // @ts-ignore
30593
+ token.op.typ = exports.EnumToken.GteTokenType;
30594
+ }
30595
+ else if (name.val.startsWith("max-")) {
30596
+ name.val = name.val.substring(4);
30597
+ // @ts-ignore
30598
+ token.op.typ = exports.EnumToken.LteTokenType;
30599
+ }
30600
+ }
30601
+ }
30390
30602
  // check <style()> or <scroll-state()>
30391
30603
  }
30392
30604
  if (tokensfuncDefMap.has(stack.at(-1)?.typ)) {
@@ -30478,6 +30690,58 @@ function parseAtRuleContainerQueryList(stream, context, options = {}) {
30478
30690
  };
30479
30691
  tokens.length = l + 1;
30480
30692
  expectAndOr = true;
30693
+ if (tokens[l].op.typ === exports.EnumToken.AndTokenType) {
30694
+ let left = tokens[l].l.find((t) => t.typ != exports.EnumToken.WhitespaceTokenType && t.typ != exports.EnumToken.IdenTokenType);
30695
+ let right = tokens[l].r.find((t) => t.typ != exports.EnumToken.WhitespaceTokenType && t.typ != exports.EnumToken.IdenTokenType);
30696
+ if (left.typ == exports.EnumToken.ParensTokenType && right.typ == exports.EnumToken.ParensTokenType) {
30697
+ left = left.chi.find((t) => t.typ != exports.EnumToken.WhitespaceTokenType && t.typ != exports.EnumToken.IdenTokenType);
30698
+ right = right.chi.find((t) => t.typ != exports.EnumToken.WhitespaceTokenType && t.typ != exports.EnumToken.IdenTokenType);
30699
+ if (left.typ == exports.EnumToken.MediaQueryConditionTokenType &&
30700
+ (mFLT.has(left.op.typ) ||
30701
+ mFGT.has(left.op.typ)) &&
30702
+ right.typ == exports.EnumToken.MediaQueryConditionTokenType &&
30703
+ (mFLT.has(right.op.typ) ||
30704
+ mFGT.has(right.op.typ))) {
30705
+ const name = left.l.find((t) => t.typ == exports.EnumToken.IdenTokenType);
30706
+ const name2 = right.l.find((t) => t.typ == exports.EnumToken.IdenTokenType);
30707
+ if (equalsIgnoreCase(name.val, name2.val)) {
30708
+ switch (left.op.typ) {
30709
+ case exports.EnumToken.LtTokenType:
30710
+ left.op.typ = exports.EnumToken.GtTokenType;
30711
+ break;
30712
+ case exports.EnumToken.LteTokenType:
30713
+ left.op.typ = exports.EnumToken.GteTokenType;
30714
+ break;
30715
+ case exports.EnumToken.GtTokenType:
30716
+ left.op.typ = exports.EnumToken.LtTokenType;
30717
+ break;
30718
+ case exports.EnumToken.GteTokenType:
30719
+ left.op.typ = exports.EnumToken.LteTokenType;
30720
+ break;
30721
+ }
30722
+ tokens[l] = {
30723
+ typ: exports.EnumToken.ParensTokenType,
30724
+ chi: [
30725
+ {
30726
+ typ: exports.EnumToken.MediaRangeQueryTokenType,
30727
+ l: left.r,
30728
+ val: [name],
30729
+ op1: left.op,
30730
+ op2: right.op,
30731
+ r: right.r,
30732
+ [LOCSRCID]: name[LOCSRCID],
30733
+ [LOCSTA]: left[LOCSTA],
30734
+ [LOCEND]: right[LOCEND],
30735
+ },
30736
+ ],
30737
+ [LOCSRCID]: name[LOCSRCID],
30738
+ [LOCSTA]: left[LOCSTA],
30739
+ [LOCEND]: right[LOCEND],
30740
+ };
30741
+ }
30742
+ }
30743
+ }
30744
+ }
30481
30745
  }
30482
30746
  break;
30483
30747
  }
@@ -31111,7 +31375,6 @@ function doParseSync(tokenizer, options = {}) {
31111
31375
  // let currentItemIndex: number;
31112
31376
  ast[LOCSRCID] = options.source.id;
31113
31377
  ast[LOCSTA] = 0;
31114
- // let tokenizer: Tokenizer;
31115
31378
  while (!tokenizer.done()) {
31116
31379
  tokenizer.next();
31117
31380
  // item = (iter as Array<TokenizeResult>)[currentItemIndex];
@@ -31442,14 +31705,14 @@ function doParseSync(tokenizer, options = {}) {
31442
31705
  if (invalidNodes.length > 0) {
31443
31706
  let count = invalidNodes.length;
31444
31707
  for (const { node, parent } of walk(ast)) {
31445
- if (options.lenient && node[STATE] == exports.EnumAstNodeStatus.Unknown) {
31708
+ if (options.lenient && node[STATE] & exports.EnumAstNodeStatus.Unknown) {
31446
31709
  continue;
31447
31710
  }
31448
- if (node[STATE] === exports.EnumAstNodeStatus.Invalid ||
31449
- node[STATE] === exports.EnumAstNodeStatus.Unknown ||
31450
- node[STATE] === exports.EnumAstNodeStatus.Unparsed ||
31451
- node[STATE] === exports.EnumAstNodeStatus.Malformed ||
31452
- node[STATE] === exports.EnumAstNodeStatus.Disallowed) {
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) {
31453
31716
  // @ts-ignore
31454
31717
  parent.chi.splice(parent.chi.indexOf(node), 1);
31455
31718
  node[PARENT] = null;
@@ -32437,14 +32700,14 @@ async function doParse(iter, options = {}) {
32437
32700
  if (invalidNodes.length > 0) {
32438
32701
  let count = invalidNodes.length;
32439
32702
  for (const { node, parent } of walk(ast)) {
32440
- if (options.lenient && node[STATE] == exports.EnumAstNodeStatus.Unknown) {
32703
+ if (options.lenient && node[STATE] & exports.EnumAstNodeStatus.Unknown) {
32441
32704
  continue;
32442
32705
  }
32443
- if (node[STATE] === exports.EnumAstNodeStatus.Invalid ||
32444
- node[STATE] === exports.EnumAstNodeStatus.Unknown ||
32445
- node[STATE] === exports.EnumAstNodeStatus.Unparsed ||
32446
- node[STATE] === exports.EnumAstNodeStatus.Malformed ||
32447
- node[STATE] === exports.EnumAstNodeStatus.Disallowed) {
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) {
32448
32711
  // @ts-ignore
32449
32712
  parent.chi.splice(parent.chi.indexOf(node), 1);
32450
32713
  node[PARENT] = null;
@@ -33175,11 +33438,12 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
33175
33438
  if (node == null) {
33176
33439
  return null;
33177
33440
  }
33178
- if (node[STATE] == exports.EnumAstNodeStatus.Invalid ||
33179
- node[STATE] == exports.EnumAstNodeStatus.Disallowed ||
33180
- node[STATE] == exports.EnumAstNodeStatus.Unknown ||
33181
- node[STATE] == exports.EnumAstNodeStatus.Unparsed ||
33182
- node[STATE] == exports.EnumAstNodeStatus.Malformed) {
33441
+ if (node[STATE] &
33442
+ (exports.EnumAstNodeStatus.Invalid |
33443
+ exports.EnumAstNodeStatus.Disallowed |
33444
+ exports.EnumAstNodeStatus.Unknown |
33445
+ exports.EnumAstNodeStatus.Unparsed |
33446
+ exports.EnumAstNodeStatus.Malformed)) {
33183
33447
  invalidNodes.push(node);
33184
33448
  }
33185
33449
  stats.nodesCount++;
@@ -33197,11 +33461,11 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
33197
33461
  context.chi.push(node);
33198
33462
  node[PARENT] = context;
33199
33463
  node[ROOT] = context[ROOT];
33200
- if (node[STATE] == exports.EnumAstNodeStatus.Invalid ||
33201
- node[STATE] == exports.EnumAstNodeStatus.Disallowed ||
33202
- node[STATE] == exports.EnumAstNodeStatus.Unknown ||
33203
- node[STATE] == exports.EnumAstNodeStatus.Unparsed ||
33204
- node[STATE] == exports.EnumAstNodeStatus.Malformed) {
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) {
33205
33469
  invalidNodes.push(node);
33206
33470
  }
33207
33471
  return node;
@@ -33211,7 +33475,9 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
33211
33475
  node[PARENT] = context;
33212
33476
  node[ROOT] = context[ROOT];
33213
33477
  if (context.typ === exports.EnumToken.StyleSheetNodeType && node.typ === exports.EnumToken.DeclarationNodeType) {
33214
- node[STATE] = exports.EnumAstNodeStatus.Invalid;
33478
+ node[STATE] |=
33479
+ exports.EnumAstNodeStatus.Invalid &
33480
+ ~(exports.EnumAstNodeStatus.Validated | exports.EnumAstNodeStatus.Unvalidated | exports.EnumAstNodeStatus.Unparsed);
33215
33481
  errors.push({
33216
33482
  message: "<declaration> not allowed in <stylesheet>",
33217
33483
  action: "drop",
@@ -33222,11 +33488,12 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
33222
33488
  else if (options.lenient || node.typ === exports.EnumToken.DeclarationNodeType) {
33223
33489
  context.chi.push(node);
33224
33490
  }
33225
- if (node[STATE] == exports.EnumAstNodeStatus.Invalid ||
33226
- node[STATE] == exports.EnumAstNodeStatus.Disallowed ||
33227
- node[STATE] == exports.EnumAstNodeStatus.Unknown ||
33228
- node[STATE] == exports.EnumAstNodeStatus.Unparsed ||
33229
- node[STATE] == exports.EnumAstNodeStatus.Malformed) {
33491
+ if (node[STATE] &
33492
+ (exports.EnumAstNodeStatus.Invalid |
33493
+ exports.EnumAstNodeStatus.Disallowed |
33494
+ exports.EnumAstNodeStatus.Unknown |
33495
+ exports.EnumAstNodeStatus.Unparsed |
33496
+ exports.EnumAstNodeStatus.Malformed)) {
33230
33497
  invalidNodes.push(node);
33231
33498
  }
33232
33499
  }