@tbela99/css-parser 1.6.6 → 1.6.8

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.
Files changed (104) hide show
  1. package/CHANGELOG.md +106 -0
  2. package/README.md +1 -58
  3. package/architecture.png +0 -0
  4. package/dist/index-umd-web.js +731 -459
  5. package/dist/index.cjs +724 -459
  6. package/dist/index.d.ts +67 -11
  7. package/dist/package.json.js +10 -0
  8. package/dist/{data → src/data}/properties.json.js +7 -0
  9. package/dist/{data → src/data}/validation.json.js +7 -0
  10. package/dist/{lib → src/lib}/ast/clone.js +7 -0
  11. package/dist/{lib → src/lib}/ast/expand.js +19 -10
  12. package/dist/{lib → src/lib}/ast/features/calc.js +7 -0
  13. package/dist/{lib → src/lib}/ast/features/if.js +7 -0
  14. package/dist/{lib → src/lib}/ast/features/index.js +7 -0
  15. package/dist/{lib → src/lib}/ast/features/inlinecssvariables.js +7 -0
  16. package/dist/{lib → src/lib}/ast/features/prefix.js +8 -3
  17. package/dist/{lib → src/lib}/ast/features/shorthand.js +7 -0
  18. package/dist/{lib → src/lib}/ast/features/transform.js +8 -1
  19. package/dist/{lib → src/lib}/ast/features/type.js +7 -0
  20. package/dist/{lib → src/lib}/ast/find.js +7 -0
  21. package/dist/{lib → src/lib}/ast/math/expression.js +7 -0
  22. package/dist/{lib → src/lib}/ast/math/math.js +7 -0
  23. package/dist/{lib → src/lib}/ast/minify.js +7 -0
  24. package/dist/{lib → src/lib}/ast/node.js +7 -0
  25. package/dist/{lib → src/lib}/ast/transform/compute.js +7 -0
  26. package/dist/{lib → src/lib}/ast/transform/matrix.js +7 -0
  27. package/dist/{lib → src/lib}/ast/transform/minify.js +7 -0
  28. package/dist/{lib → src/lib}/ast/transform/perspective.js +7 -0
  29. package/dist/{lib → src/lib}/ast/transform/rotate.js +7 -0
  30. package/dist/{lib → src/lib}/ast/transform/scale.js +7 -0
  31. package/dist/{lib → src/lib}/ast/transform/skew.js +7 -0
  32. package/dist/{lib → src/lib}/ast/transform/translate.js +7 -0
  33. package/dist/{lib → src/lib}/ast/transform/utils.js +7 -0
  34. package/dist/{lib → src/lib}/ast/types.js +28 -9
  35. package/dist/{lib → src/lib}/ast/walk.js +16 -0
  36. package/dist/{lib → src/lib}/fs/resolve.js +7 -0
  37. package/dist/{lib → src/lib}/parser/declaration/list.js +24 -8
  38. package/dist/{lib → src/lib}/parser/declaration/map.js +9 -1
  39. package/dist/{lib → src/lib}/parser/declaration/set.js +7 -0
  40. package/dist/{lib → src/lib}/parser/linesmap.js +7 -0
  41. package/dist/{lib → src/lib}/parser/parse.js +93 -49
  42. package/dist/{lib → src/lib}/parser/source.js +7 -0
  43. package/dist/{lib → src/lib}/parser/tokenize.js +24 -3
  44. package/dist/{lib → src/lib}/parser/utils/angle.js +7 -0
  45. package/dist/{lib → src/lib}/parser/utils/at-rule-container.js +7 -0
  46. package/dist/{lib → src/lib}/parser/utils/at-rule-font-feature-values.js +7 -0
  47. package/dist/{lib → src/lib}/parser/utils/at-rule-generic.js +7 -0
  48. package/dist/{lib → src/lib}/parser/utils/at-rule-import.js +7 -0
  49. package/dist/{lib → src/lib}/parser/utils/at-rule-media.js +7 -0
  50. package/dist/{lib → src/lib}/parser/utils/at-rule-support.js +7 -0
  51. package/dist/{lib → src/lib}/parser/utils/at-rule-when-else.js +7 -0
  52. package/dist/{lib → src/lib}/parser/utils/at-rule.js +7 -0
  53. package/dist/{lib → src/lib}/parser/utils/base64.js +7 -0
  54. package/dist/{lib → src/lib}/parser/utils/cache.js +7 -0
  55. package/dist/{lib → src/lib}/parser/utils/config.js +7 -0
  56. package/dist/{lib → src/lib}/parser/utils/declaration.js +17 -0
  57. package/dist/{lib → src/lib}/parser/utils/eq.js +7 -0
  58. package/dist/{lib → src/lib}/parser/utils/hash.js +7 -0
  59. package/dist/{lib → src/lib}/parser/utils/selector.js +7 -0
  60. package/dist/{lib → src/lib}/parser/utils/text.js +7 -0
  61. package/dist/{lib → src/lib}/parser/utils/token.js +15 -4
  62. package/dist/{lib → src/lib}/parser/utils/type.js +7 -0
  63. package/dist/{lib → src/lib}/printer/render.js +20 -9
  64. package/dist/{lib → src/lib}/printer/sourcemap/lib/codec.js +7 -0
  65. package/dist/{lib → src/lib}/printer/sourcemap/sourcemap.js +7 -0
  66. package/dist/{lib → src/lib}/syntax/color/a98rgb.js +7 -0
  67. package/dist/{lib → src/lib}/syntax/color/alpha.js +7 -0
  68. package/dist/{lib → src/lib}/syntax/color/cmyk.js +7 -0
  69. package/dist/{lib → src/lib}/syntax/color/color-mix.js +139 -48
  70. package/dist/{lib → src/lib}/syntax/color/color.js +7 -1
  71. package/dist/{lib → src/lib}/syntax/color/hex.js +7 -0
  72. package/dist/{lib → src/lib}/syntax/color/hsl.js +52 -38
  73. package/dist/{lib → src/lib}/syntax/color/hwb.js +90 -53
  74. package/dist/{lib → src/lib}/syntax/color/lab.js +7 -0
  75. package/dist/{lib → src/lib}/syntax/color/lch.js +7 -0
  76. package/dist/{lib → src/lib}/syntax/color/oklab.js +8 -1
  77. package/dist/{lib → src/lib}/syntax/color/oklch.js +7 -0
  78. package/dist/{lib → src/lib}/syntax/color/p3.js +7 -0
  79. package/dist/{lib → src/lib}/syntax/color/prophotorgb.js +7 -0
  80. package/dist/{lib → src/lib}/syntax/color/rec2020.js +7 -0
  81. package/dist/{lib → src/lib}/syntax/color/relative-color.js +36 -0
  82. package/dist/{lib → src/lib}/syntax/color/rgb.js +7 -0
  83. package/dist/{lib → src/lib}/syntax/color/srgb.js +88 -58
  84. package/dist/{lib → src/lib}/syntax/color/utils/color-type.js +7 -0
  85. package/dist/{lib → src/lib}/syntax/color/utils/colorspace.js +7 -0
  86. package/dist/{lib → src/lib}/syntax/color/utils/components.js +7 -0
  87. package/dist/{lib → src/lib}/syntax/color/utils/distance.js +7 -0
  88. package/dist/{lib → src/lib}/syntax/color/utils/make-color.js +7 -0
  89. package/dist/{lib → src/lib}/syntax/color/utils/matrix.js +7 -0
  90. package/dist/{lib → src/lib}/syntax/color/xyz.js +7 -0
  91. package/dist/{lib → src/lib}/syntax/color/xyzd50.js +7 -0
  92. package/dist/{lib → src/lib}/syntax/constants.js +7 -0
  93. package/dist/{lib → src/lib}/syntax/syntax.js +7 -0
  94. package/dist/{lib → src/lib}/validation/config.js +7 -0
  95. package/dist/{lib → src/lib}/validation/match.js +37 -19
  96. package/dist/{lib → src/lib}/validation/parser/parse.js +7 -0
  97. package/dist/{lib → src/lib}/validation/parser/typedef.js +7 -0
  98. package/dist/{lib → src/lib}/validation/utils/list.js +7 -0
  99. package/dist/{node.js → src/node.js} +8 -0
  100. package/dist/{types.js → src/types.js} +7 -0
  101. package/dist/{utils → src/utils}/sync.js +7 -0
  102. package/dist/{web.js → src/web.js} +8 -0
  103. package/package.json +7 -6
  104. package/dist/lib/syntax/color/hsv.js +0 -20
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
@@ -542,7 +550,7 @@ exports.EnumToken = void 0;
542
550
  /**
543
551
  * '|'
544
552
  */
545
- EnumToken[EnumToken["Pipe"] = 109] = "Pipe";
553
+ EnumToken[EnumToken["PipeTokenType"] = 109] = "PipeTokenType";
546
554
  /**
547
555
  * '::'
548
556
  */
@@ -681,6 +689,10 @@ exports.EnumToken = void 0;
681
689
  * negative infinity token
682
690
  */
683
691
  EnumToken[EnumToken["NegativeInfinityTokenType"] = 143] = "NegativeInfinityTokenType";
692
+ /**
693
+ * CSS type token
694
+ */
695
+ EnumToken[EnumToken["CssTypeTokenType"] = 144] = "CssTypeTokenType";
684
696
  /* aliases */
685
697
  /**
686
698
  * alias for time token type
@@ -7488,7 +7500,7 @@ function oklabToken(values) {
7488
7500
  { typ: exports.EnumToken.NumberTokenType, val: values[1] },
7489
7501
  { typ: exports.EnumToken.NumberTokenType, val: values[2] },
7490
7502
  ];
7491
- if (values.length == 4) {
7503
+ if (values.length == 4 && values[3] != 1) {
7492
7504
  chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
7493
7505
  typ: exports.EnumToken.PercentageTokenType,
7494
7506
  val: values[3] * 100,
@@ -7877,6 +7889,222 @@ function Lab_to_XYZ(l, a, b) {
7877
7889
  return xyz.map((value, i) => value * D50[i]);
7878
7890
  }
7879
7891
 
7892
+ function rgb2hwbToken(token) {
7893
+ const values = rgb2hwbvalues(token);
7894
+ if (values == null) {
7895
+ return null;
7896
+ }
7897
+ return hwbToken(values);
7898
+ }
7899
+ function hsl2hwbToken(token) {
7900
+ const values = hsl2hwbvalues(token);
7901
+ if (values == null) {
7902
+ return null;
7903
+ }
7904
+ // console.error(new Error("hsl2hwbToken"));
7905
+ return hwbToken(values);
7906
+ }
7907
+ function cmyk2hwbToken(token) {
7908
+ const values = cmyk2hwbvalues(token);
7909
+ if (values == null) {
7910
+ return null;
7911
+ }
7912
+ return hwbToken(values);
7913
+ }
7914
+ function oklab2hwbToken(token) {
7915
+ const values = oklab2hwbvalues(token);
7916
+ if (values == null) {
7917
+ return null;
7918
+ }
7919
+ return hwbToken(values);
7920
+ }
7921
+ function oklch2hwbToken(token) {
7922
+ const values = oklch2hwbvalues(token);
7923
+ if (values == null) {
7924
+ return null;
7925
+ }
7926
+ return hwbToken(values);
7927
+ }
7928
+ function lab2hwbToken(token) {
7929
+ const values = lab2hwbvalues(token);
7930
+ if (values == null) {
7931
+ return null;
7932
+ }
7933
+ return hwbToken(values);
7934
+ }
7935
+ function lch2hwbToken(token) {
7936
+ const values = lch2hwbvalues(token);
7937
+ if (values == null) {
7938
+ return null;
7939
+ }
7940
+ return hwbToken(values);
7941
+ }
7942
+ function color2hwbToken(token) {
7943
+ const values = color2hwbvalues(token);
7944
+ if (values == null) {
7945
+ return null;
7946
+ }
7947
+ return hwbToken(values);
7948
+ }
7949
+ function hwbToken(values) {
7950
+ const chi = [
7951
+ { typ: exports.EnumToken.NumberTokenType, val: values[0] },
7952
+ { typ: exports.EnumToken.PercentageTokenType, val: values[1] },
7953
+ { typ: exports.EnumToken.PercentageTokenType, val: values[2] },
7954
+ ];
7955
+ if (values.length == 4) {
7956
+ chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
7957
+ typ: exports.EnumToken.PercentageTokenType,
7958
+ val: values[3] * 100,
7959
+ });
7960
+ }
7961
+ return {
7962
+ typ: exports.EnumToken.ColorTokenType,
7963
+ val: "hwb",
7964
+ chi,
7965
+ kin: exports.ColorType.HWB,
7966
+ };
7967
+ }
7968
+ function rgb2hwbvalues(token) {
7969
+ const values = getColorComponents(token).map((t, index) => {
7970
+ if (index == 3) {
7971
+ return getNumber(t);
7972
+ }
7973
+ return getNumber(t) / 255;
7974
+ });
7975
+ // @ts-ignore
7976
+ return srgb2hwb(values[0], values[1], values[2], values[3]);
7977
+ }
7978
+ function cmyk2hwbvalues(token) {
7979
+ const values = cmyk2srgbvalues(token);
7980
+ return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
7981
+ }
7982
+ function hsl2hwbvalues(token) {
7983
+ const values = hslvalues(token);
7984
+ if (values == null) {
7985
+ return null;
7986
+ }
7987
+ // @ts-ignore
7988
+ return hslvalues2hwbvalues(values.h, values.s, values.l, values.a);
7989
+ }
7990
+ function lab2hwbvalues(token) {
7991
+ const values = lab2srgbvalues(token);
7992
+ if (values == null) {
7993
+ return null;
7994
+ }
7995
+ return srgb2hwb(values[0], values[1], values[2], values[3]);
7996
+ }
7997
+ function lch2hwbvalues(token) {
7998
+ const values = lch2srgbvalues(token);
7999
+ if (values == null) {
8000
+ return null;
8001
+ }
8002
+ return srgb2hwb(values[0], values[1], values[2], values[3]);
8003
+ }
8004
+ function oklab2hwbvalues(token) {
8005
+ const values = oklab2srgbvalues(token);
8006
+ if (values == null) {
8007
+ return null;
8008
+ }
8009
+ // @ts-ignore
8010
+ return srgb2hwb(values[0], values[1], values[2], values[3]);
8011
+ }
8012
+ function oklch2hwbvalues(token) {
8013
+ const values = oklch2srgbvalues(token);
8014
+ // @ts-ignore
8015
+ return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
8016
+ }
8017
+ function color2hwbvalues(token) {
8018
+ const values = color2srgbvalues(token);
8019
+ if (values == null) {
8020
+ return null;
8021
+ }
8022
+ // @ts-ignore
8023
+ return srgb2hwb(values[0], values[1], values[2], values[3]);
8024
+ }
8025
+ function hwbvalues(token) {
8026
+ const components = getColorComponents(token);
8027
+ if (components == null) {
8028
+ return null;
8029
+ }
8030
+ let t;
8031
+ // @ts-ignore
8032
+ let h = getAngle(components[0]) * 360;
8033
+ // @ts-ignore
8034
+ t = components[1];
8035
+ // @ts-ignore
8036
+ let w = getNumber(t);
8037
+ // @ts-ignore
8038
+ t = components[2];
8039
+ // @ts-ignore
8040
+ let b = getNumber(t);
8041
+ // if (components[1].typ == EnumToken.NumberTokenType) {
8042
+ w *= 100;
8043
+ // }
8044
+ // if (components[2].typ == EnumToken.NumberTokenType) {
8045
+ b *= 100;
8046
+ // }
8047
+ let a = null;
8048
+ if (components.length == 4) {
8049
+ // @ts-ignore
8050
+ t = components[3];
8051
+ // @ts-ignore
8052
+ a = getNumber(t);
8053
+ }
8054
+ return a == null ? { h, w, b } : { h, w, b, a };
8055
+ }
8056
+ function srgb2hwb(r, g, b, a = null, fallback = 0) {
8057
+ // 1. Clamp inputs to the standard web-safe sRGB gamut [0.0, 1.0]
8058
+ const rClamp = Math.min(1, Math.max(0, r));
8059
+ const gClamp = Math.min(1, Math.max(0, g));
8060
+ const bClamp = Math.min(1, Math.max(0, b));
8061
+ const cMax = Math.max(rClamp, gClamp, bClamp);
8062
+ const cMin = Math.min(rClamp, gClamp, bClamp);
8063
+ const delta = cMax - cMin;
8064
+ // 2. Whiteness and Blackness calculations
8065
+ const w = cMin;
8066
+ const bl = 1 - cMax;
8067
+ // 3. Calculate Hue
8068
+ let h = 0;
8069
+ if (delta !== 0) {
8070
+ if (cMax === rClamp) {
8071
+ h = 60 * (((gClamp - bClamp) / delta) % 6);
8072
+ }
8073
+ else if (cMax === gClamp) {
8074
+ h = 60 * ((bClamp - rClamp) / delta + 2);
8075
+ }
8076
+ else if (cMax === bClamp) {
8077
+ h = 60 * ((rClamp - gClamp) / delta + 4);
8078
+ }
8079
+ if (h < 0) {
8080
+ h += 360;
8081
+ }
8082
+ }
8083
+ const result = [h, w * 100, bl * 100];
8084
+ if (a != null) {
8085
+ result.push(a);
8086
+ }
8087
+ return result;
8088
+ }
8089
+ function hslvalues2hwbvalues(h, s, l, a = null) {
8090
+ const sNorm = s / 100;
8091
+ const lNorm = l / 100;
8092
+ // Keep Hue cleanly bound to standard circle loops
8093
+ const hue = ((h % 360) + 360) % 360;
8094
+ // 1. Compute the intermediate HSV Value component (brightness peak)
8095
+ const v = lNorm + sNorm * Math.min(lNorm, 1 - lNorm);
8096
+ // 2. Compute Chroma
8097
+ const chroma = 2 * (v - lNorm);
8098
+ // 3. Extract Whiteness and Blackness
8099
+ const w = v - chroma;
8100
+ const b = 1 - v;
8101
+ const hwb = [hue, w * 100, b * 100];
8102
+ if (a != null && a != 1) {
8103
+ hwb.push(a);
8104
+ }
8105
+ return hwb;
8106
+ }
8107
+
7880
8108
  // from https://www.w3.org/TR/css-color-4/#color-conversion-code
7881
8109
  // srgb-linear -> srgb
7882
8110
  // 0 <= r, g, b <= 1
@@ -7950,25 +8178,59 @@ function xyz2srgb(x, y, z, alpha = null) {
7950
8178
  return lsrgb2srgbvalues(values[0], values[1], values[2], alpha);
7951
8179
  }
7952
8180
  function hwb2srgbvalues(token) {
7953
- const { h: hue, s: white, l: black, a: alpha } = hslvalues(token) ?? {};
7954
- if (hue == null || white == null || black == null) {
8181
+ const { h, w, b, a } = hwbvalues(token) ?? {};
8182
+ if (h == null || w == null || b == null) {
7955
8183
  return [];
7956
8184
  }
7957
- const rgb = hslvalues2srgbvalues(hue, 1, 0.5);
7958
- for (let i = 0; i < 3; i++) {
7959
- rgb[i] *= 1 - white - black;
7960
- rgb[i] = rgb[i] + white;
7961
- }
7962
- if (alpha != null && alpha != 1) {
7963
- rgb.push(alpha);
8185
+ const rgb = hwb2srgb(h, w, b);
8186
+ if (a != null && a != 1) {
8187
+ rgb.push(a);
7964
8188
  }
7965
8189
  return rgb;
7966
8190
  }
8191
+ /**
8192
+ * convert hwb to sRGB
8193
+ */
8194
+ function hwb2srgb(h, w, b, alpha) {
8195
+ const wNorm = w / 100;
8196
+ const bNorm = b / 100;
8197
+ if (wNorm + bNorm >= 1) {
8198
+ const gray = wNorm / (wNorm + bNorm);
8199
+ return [Math.round(gray * 10000) / 10000, Math.round(gray * 10000) / 10000, Math.round(gray * 10000) / 10000];
8200
+ }
8201
+ const hPrime = (h % 360) / 60;
8202
+ const x = 1 - Math.abs((hPrime % 2) - 1);
8203
+ let rChroma = 0;
8204
+ let gChroma = 0;
8205
+ let bChroma = 0;
8206
+ if (hPrime >= 0 && hPrime < 1) {
8207
+ [rChroma, gChroma, bChroma] = [1, x, 0];
8208
+ }
8209
+ else if (hPrime >= 1 && hPrime < 2) {
8210
+ [rChroma, gChroma, bChroma] = [x, 1, 0];
8211
+ }
8212
+ else if (hPrime >= 2 && hPrime < 3) {
8213
+ [rChroma, gChroma, bChroma] = [0, 1, x];
8214
+ }
8215
+ else if (hPrime >= 3 && hPrime < 4) {
8216
+ [rChroma, gChroma, bChroma] = [0, x, 1];
8217
+ }
8218
+ else if (hPrime >= 4 && hPrime < 5) {
8219
+ [rChroma, gChroma, bChroma] = [x, 0, 1];
8220
+ }
8221
+ else if (hPrime >= 5 && hPrime <= 6) {
8222
+ [rChroma, gChroma, bChroma] = [1, 0, x];
8223
+ }
8224
+ const factor = 1 - wNorm - bNorm;
8225
+ const srgb = [rChroma * factor + wNorm, gChroma * factor + wNorm, bChroma * factor + wNorm];
8226
+ return srgb;
8227
+ }
7967
8228
  function hsl2srgb(token) {
7968
8229
  let { h, s, l, a } = hslvalues(token) ?? {};
7969
8230
  if (h == null || s == null || l == null) {
7970
8231
  return null;
7971
8232
  }
8233
+ // hue in degrees
7972
8234
  return hslvalues2srgbvalues(h, s, l, a);
7973
8235
  }
7974
8236
  function cmyk2srgbvalues(token) {
@@ -8029,7 +8291,7 @@ function hslvalues(token) {
8029
8291
  }
8030
8292
  let t;
8031
8293
  // @ts-ignore
8032
- let h = getAngle(components[0]);
8294
+ let h = getAngle(components[0]) * 360;
8033
8295
  // @ts-ignore
8034
8296
  t = components[1];
8035
8297
  // @ts-ignore
@@ -8038,6 +8300,12 @@ function hslvalues(token) {
8038
8300
  t = components[2];
8039
8301
  // @ts-ignore
8040
8302
  let l = getNumber(t);
8303
+ if (components[1].typ == exports.EnumToken.PercentageTokenType) {
8304
+ s *= 100;
8305
+ }
8306
+ if (components[2].typ == exports.EnumToken.PercentageTokenType) {
8307
+ l *= 100;
8308
+ }
8041
8309
  let a = null;
8042
8310
  if (components.length == 4) {
8043
8311
  // @ts-ignore
@@ -8048,56 +8316,38 @@ function hslvalues(token) {
8048
8316
  return a == null ? { h, s, l } : { h, s, l, a };
8049
8317
  }
8050
8318
  function hslvalues2srgbvalues(h, s, l, a = null) {
8051
- let v = l <= 0.5 ? l * (1.0 + s) : l + s - l * s;
8052
- let r = l;
8053
- let g = l;
8054
- let b = l;
8055
- if (v > 0) {
8056
- let m = l + l - v;
8057
- let sv = (v - m) / v;
8058
- h *= 6.0;
8059
- let sextant = Math.floor(h);
8060
- let fract = h - sextant;
8061
- let vsf = v * sv * fract;
8062
- let mid1 = m + vsf;
8063
- let mid2 = v - vsf;
8064
- switch (sextant) {
8065
- case 0:
8066
- r = v;
8067
- g = mid1;
8068
- b = m;
8069
- break;
8070
- case 1:
8071
- r = mid2;
8072
- g = v;
8073
- b = m;
8074
- break;
8075
- case 2:
8076
- r = m;
8077
- g = v;
8078
- b = mid1;
8079
- break;
8080
- case 3:
8081
- r = m;
8082
- g = mid2;
8083
- b = v;
8084
- break;
8085
- case 4:
8086
- r = mid1;
8087
- g = m;
8088
- b = v;
8089
- break;
8090
- case 5:
8091
- r = v;
8092
- g = m;
8093
- b = mid2;
8094
- break;
8095
- }
8096
- }
8097
- const values = [r, g, b];
8098
- if (a != null && a != 1) {
8319
+ const sNorm = s / 100;
8320
+ const lNorm = l / 100;
8321
+ const chroma = (1 - Math.abs(2 * lNorm - 1)) * sNorm;
8322
+ const hPrime = h / 60;
8323
+ const x = chroma * (1 - Math.abs((hPrime % 2) - 1));
8324
+ let rTmp = 0;
8325
+ let gTmp = 0;
8326
+ let bTmp = 0;
8327
+ if (hPrime >= 0 && hPrime < 1) {
8328
+ [rTmp, gTmp, bTmp] = [chroma, x, 0];
8329
+ }
8330
+ else if (hPrime >= 1 && hPrime < 2) {
8331
+ [rTmp, gTmp, bTmp] = [x, chroma, 0];
8332
+ }
8333
+ else if (hPrime >= 2 && hPrime < 3) {
8334
+ [rTmp, gTmp, bTmp] = [0, chroma, x];
8335
+ }
8336
+ else if (hPrime >= 3 && hPrime < 4) {
8337
+ [rTmp, gTmp, bTmp] = [0, x, chroma];
8338
+ }
8339
+ else if (hPrime >= 4 && hPrime < 5) {
8340
+ [rTmp, gTmp, bTmp] = [x, 0, chroma];
8341
+ }
8342
+ else if (hPrime >= 5 && hPrime <= 6) {
8343
+ [rTmp, gTmp, bTmp] = [chroma, 0, x];
8344
+ }
8345
+ const m = lNorm - chroma / 2;
8346
+ const values = [rTmp + m, gTmp + m, bTmp + m];
8347
+ if (a != null) {
8099
8348
  values.push(a);
8100
8349
  }
8350
+ // Return exact float decimals instead of multiplying by 255
8101
8351
  return values;
8102
8352
  }
8103
8353
  function lab2srgbvalues(token) {
@@ -8470,25 +8720,6 @@ function lch2rgbvalues(token) {
8470
8720
  return lch2srgbvalues(token)?.map?.((t, index) => (index == 3 ? t : srgb2rgb(t))) ?? null;
8471
8721
  }
8472
8722
 
8473
- function hwb2hsv(h, w, b, a) {
8474
- // @ts-ignore
8475
- return [h, 1 - w / (1 - b), 1 - b, a];
8476
- }
8477
- // https://gist.github.com/defims/0ca2ef8832833186ed396a2f8a204117#file-annotated-js
8478
- function hsl2hsv(h, s, l, a = null) {
8479
- s *= l < .5 ? l : 1 - l;
8480
- const result = [
8481
- //Range should be between 0 - 1
8482
- h, //Hue stays the same
8483
- 2 * s / (l + s), //Saturation
8484
- l + s //Value
8485
- ];
8486
- if (a != null) {
8487
- result.push(a);
8488
- }
8489
- return result;
8490
- }
8491
-
8492
8723
  function hex2HslToken(token) {
8493
8724
  let values = hex2srgbvalues(token);
8494
8725
  if (values == null) {
@@ -8553,11 +8784,17 @@ function color2HslToken(token) {
8553
8784
  return hslToken(srgb2hslvalues(values[0], values[1], values[2], values[3]));
8554
8785
  }
8555
8786
  function hslToken(values) {
8556
- values[0] = values[0] * 360;
8787
+ if (values[1] == 0) {
8788
+ values[0] = 0;
8789
+ }
8790
+ if (values[2] == 1 || values[2] == 0) {
8791
+ values[0] = 0;
8792
+ values[1] = 0;
8793
+ }
8557
8794
  const chi = [
8558
8795
  { typ: exports.EnumToken.NumberTokenType, val: values[0] },
8559
- { typ: exports.EnumToken.PercentageTokenType, val: values[1] * 100 },
8560
- { typ: exports.EnumToken.PercentageTokenType, val: values[2] * 100 },
8796
+ { typ: exports.EnumToken.PercentageTokenType, val: values[1] },
8797
+ { typ: exports.EnumToken.PercentageTokenType, val: values[2] },
8561
8798
  ];
8562
8799
  if (values.length == 4 && values[3] != 1) {
8563
8800
  chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
@@ -8600,32 +8837,33 @@ function rgb2hslvalues(token) {
8600
8837
  }
8601
8838
  return rgbvalues2hslvalues(values[0], values[1], values[2], values[3]);
8602
8839
  }
8603
- // https://gist.github.com/defims/0ca2ef8832833186ed396a2f8a204117#file-annotated-js
8604
- function hsv2hsl(h, s, v, a) {
8605
- const result = [
8606
- //[hue, saturation, lightness]
8607
- //Range should be between 0 - 1
8608
- h, //Hue stays the same
8609
- //Saturation is very different between the two color spaces
8610
- //If (2-sat)*val < 1 set it to sat*val/((2-sat)*val)
8611
- //Otherwise sat*val/(2-(2-sat)*val)
8612
- //Conditional is not operating with hue, it is reassigned!
8613
- (s * v) / ((h = (2 - s) * v) < 1 ? h : 2 - h),
8614
- h / 2, //Lightness is (2-sat)*val/2
8615
- ];
8616
- if (a != null) {
8617
- result.push(a);
8618
- }
8619
- return result;
8620
- }
8621
8840
  function cmyk2hslvalues(token) {
8622
8841
  const values = cmyk2rgbvalues(token);
8623
8842
  return values == null ? null : rgbvalues2hslvalues(values[0], values[1], values[2], values[3]);
8624
8843
  }
8625
8844
  function hwb2hslvalues(token) {
8626
- const hsla = hslvalues(token);
8627
- const hwba = hwb2hsv(hsla.h, hsla.s, hsla.l, hsla.a);
8628
- return hsv2hsl(hwba[0], hwba[1], hwba[2], hwba[3]);
8845
+ const { h, w, b, a } = hwbvalues(token) ?? {};
8846
+ if (h == null || w == null || b == null) {
8847
+ return null;
8848
+ }
8849
+ const wNorm = w / 100;
8850
+ const bNorm = b / 100;
8851
+ const hue = ((h % 360) + 360) % 360;
8852
+ if (wNorm + bNorm >= 1) {
8853
+ const grayLightness = wNorm / (wNorm + bNorm);
8854
+ return [hue, 0, grayLightness * 100];
8855
+ }
8856
+ const lightness = (1 - bNorm + wNorm) / 2;
8857
+ let saturation = 0;
8858
+ if (lightness > 0 && lightness < 1) {
8859
+ const chroma = 1 - wNorm - bNorm;
8860
+ saturation = chroma / (1 - Math.abs(2 * lightness - 1));
8861
+ }
8862
+ const hsl = [hue, saturation * 100, lightness * 100];
8863
+ if (a != null && a != 1) {
8864
+ hsl.push(a);
8865
+ }
8866
+ return hsl;
8629
8867
  }
8630
8868
  function lab2hslvalues(token) {
8631
8869
  const values = lab2rgbvalues(token);
@@ -8656,28 +8894,28 @@ function rgbvalues2hslvalues(r, g, b, a = null) {
8656
8894
  return srgb2hslvalues(r / 255, g / 255, b / 255, a);
8657
8895
  }
8658
8896
  function srgb2hslvalues(r, g, b, a = null) {
8659
- let max = Math.max(r, g, b);
8660
- let min = Math.min(r, g, b);
8897
+ const max = Math.max(r, g, b);
8898
+ const min = Math.min(r, g, b);
8899
+ const delta = max - min;
8900
+ const l = (max + min) / 2;
8661
8901
  let h = 0;
8662
8902
  let s = 0;
8663
- let l = (max + min) / 2;
8664
- if (max != min) {
8665
- let d = max - min;
8666
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
8903
+ if (delta !== 0) {
8904
+ s = delta / (1 - Math.abs(2 * l - 1));
8667
8905
  switch (max) {
8668
8906
  case r:
8669
- h = (g - b) / d + (g < b ? 6 : 0);
8907
+ h = 60 * (((g - b) / delta) % 6);
8670
8908
  break;
8671
8909
  case g:
8672
- h = (b - r) / d + 2;
8910
+ h = 60 * ((b - r) / delta + 2);
8673
8911
  break;
8674
8912
  case b:
8675
- h = (r - g) / d + 4;
8913
+ h = 60 * ((r - g) / delta + 4);
8676
8914
  break;
8677
8915
  }
8678
- h /= 6;
8679
8916
  }
8680
- const hsl = [h, s, l];
8917
+ h = ((h % 360) + 360) % 360;
8918
+ const hsl = [h, s * 100, l * 100];
8681
8919
  if (a != null && a < 1) {
8682
8920
  // @ts-ignore
8683
8921
  return hsl.concat([a]);
@@ -8686,191 +8924,6 @@ function srgb2hslvalues(r, g, b, a = null) {
8686
8924
  return hsl;
8687
8925
  }
8688
8926
 
8689
- function rgb2hwbToken(token) {
8690
- const values = rgb2hwbvalues(token);
8691
- if (values == null) {
8692
- return null;
8693
- }
8694
- return hwbToken(values);
8695
- }
8696
- function hsl2hwbToken(token) {
8697
- const values = hsl2hwbvalues(token);
8698
- if (values == null) {
8699
- return null;
8700
- }
8701
- return hwbToken(values);
8702
- }
8703
- function cmyk2hwbToken(token) {
8704
- const values = cmyk2hwbvalues(token);
8705
- if (values == null) {
8706
- return null;
8707
- }
8708
- return hwbToken(values);
8709
- }
8710
- function oklab2hwbToken(token) {
8711
- const values = oklab2hwbvalues(token);
8712
- if (values == null) {
8713
- return null;
8714
- }
8715
- return hwbToken(values);
8716
- }
8717
- function oklch2hwbToken(token) {
8718
- const values = oklch2hwbvalues(token);
8719
- if (values == null) {
8720
- return null;
8721
- }
8722
- return hwbToken(values);
8723
- }
8724
- function lab2hwbToken(token) {
8725
- const values = lab2hwbvalues(token);
8726
- if (values == null) {
8727
- return null;
8728
- }
8729
- return hwbToken(values);
8730
- }
8731
- function lch2hwbToken(token) {
8732
- const values = lch2hwbvalues(token);
8733
- if (values == null) {
8734
- return null;
8735
- }
8736
- return hwbToken(values);
8737
- }
8738
- function color2hwbToken(token) {
8739
- const values = color2hwbvalues(token);
8740
- if (values == null) {
8741
- return null;
8742
- }
8743
- return hwbToken(values);
8744
- }
8745
- function hwbToken(values) {
8746
- values[0] = values[0] * 360;
8747
- const chi = [
8748
- { typ: exports.EnumToken.NumberTokenType, val: values[0] },
8749
- { typ: exports.EnumToken.PercentageTokenType, val: values[1] * 100 },
8750
- { typ: exports.EnumToken.PercentageTokenType, val: values[2] * 100 },
8751
- ];
8752
- if (values.length == 4) {
8753
- chi.push({ typ: exports.EnumToken.LiteralTokenType, val: "/" }, {
8754
- typ: exports.EnumToken.PercentageTokenType,
8755
- val: values[3] * 100,
8756
- });
8757
- }
8758
- return {
8759
- typ: exports.EnumToken.ColorTokenType,
8760
- val: "hwb",
8761
- chi,
8762
- kin: exports.ColorType.HWB,
8763
- };
8764
- }
8765
- function rgb2hwbvalues(token) {
8766
- const values = getColorComponents(token).map((t, index) => {
8767
- if (index == 3) {
8768
- return getNumber(t);
8769
- }
8770
- return getNumber(t) / 255;
8771
- });
8772
- // @ts-ignore
8773
- return srgb2hwb(values[0], values[1], values[2], values[3]);
8774
- }
8775
- function cmyk2hwbvalues(token) {
8776
- const values = cmyk2srgbvalues(token);
8777
- return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
8778
- }
8779
- function hsl2hwbvalues(token) {
8780
- const values = getColorComponents(token).map((t, index) => {
8781
- if (index == 3 && t.typ == exports.EnumToken.IdenTokenType && t.val == "none") {
8782
- return 1;
8783
- }
8784
- if (index == 0) {
8785
- return getAngle(t);
8786
- }
8787
- return getNumber(t);
8788
- });
8789
- // @ts-ignore
8790
- return hslvalues2hwbvalues(values[0], values[1], values[2], values[3]);
8791
- }
8792
- function lab2hwbvalues(token) {
8793
- const values = lab2srgbvalues(token);
8794
- if (values == null) {
8795
- return null;
8796
- }
8797
- return srgb2hwb(values[0], values[1], values[2], values[3]);
8798
- }
8799
- function lch2hwbvalues(token) {
8800
- const values = lch2srgbvalues(token);
8801
- if (values == null) {
8802
- return null;
8803
- }
8804
- return srgb2hwb(values[0], values[1], values[2], values[3]);
8805
- }
8806
- function oklab2hwbvalues(token) {
8807
- const values = oklab2srgbvalues(token);
8808
- if (values == null) {
8809
- return null;
8810
- }
8811
- // @ts-ignore
8812
- return srgb2hwb(values[0], values[1], values[2], values[3]);
8813
- }
8814
- function oklch2hwbvalues(token) {
8815
- const values = oklch2srgbvalues(token);
8816
- // @ts-ignore
8817
- return values == null ? null : srgb2hwb(values[0], values[1], values[2], values[3]);
8818
- }
8819
- function rgb2hue(r, g, b, fallback = 0) {
8820
- let value = rgb2value(r, g, b);
8821
- let whiteness = rgb2whiteness(r, g, b);
8822
- let delta = value - whiteness;
8823
- if (delta > 0) {
8824
- // calculate segment
8825
- let segment = value === r ? (g - b) / delta : value === g ? (b - r) / delta : (r - g) / delta;
8826
- // calculate shift
8827
- let shift = value === r ? (segment < 0 ? 360 / 60 : 0 / 60) : value === g ? 120 / 60 : 240 / 60;
8828
- // calculate hue
8829
- return (segment + shift) * 60;
8830
- }
8831
- return fallback;
8832
- }
8833
- function rgb2value(r, g, b) {
8834
- return Math.max(r, g, b);
8835
- }
8836
- function rgb2whiteness(r, g, b) {
8837
- return Math.min(r, g, b);
8838
- }
8839
- function color2hwbvalues(token) {
8840
- const values = color2srgbvalues(token);
8841
- if (values == null) {
8842
- return null;
8843
- }
8844
- // @ts-ignore
8845
- return srgb2hwb(values[0], values[1], values[2], values[3]);
8846
- }
8847
- function srgb2hwb(r, g, b, a = null, fallback = 0) {
8848
- r *= 100;
8849
- g *= 100;
8850
- b *= 100;
8851
- let hue = rgb2hue(r, g, b, fallback);
8852
- let whiteness = rgb2whiteness(r, g, b);
8853
- let value = Math.round(rgb2value(r, g, b));
8854
- let blackness = 100 - value;
8855
- const result = [hue / 360, whiteness / 100, blackness / 100];
8856
- if (a != null) {
8857
- result.push(a);
8858
- }
8859
- return result;
8860
- }
8861
- function hsv2hwb(h, s, v, a = null) {
8862
- const result = [h, (1 - s) * v, 1 - v];
8863
- if (a != null) {
8864
- result.push(a);
8865
- }
8866
- return result;
8867
- }
8868
- function hslvalues2hwbvalues(h, s, l, a = null) {
8869
- let values = hsl2hsv(h, s, l);
8870
- // @ts-ignore
8871
- return hsv2hwb(values[0], values[1], values[2], a);
8872
- }
8873
-
8874
8927
  function prophotorgb2srgbvalues(r, g, b, a = null) {
8875
8928
  let values = prophotorgb2xyz50(r, g, b);
8876
8929
  // @ts-ignore
@@ -9172,6 +9225,7 @@ function colorMix(...args) {
9172
9225
  const percentages = [];
9173
9226
  const srgbComponentValues = [];
9174
9227
  const colorComponents = [];
9228
+ const colors = [];
9175
9229
  if (args[i]?.typ === exports.EnumToken.IdenTokenType) {
9176
9230
  if (!equalsIgnoreCase(args[i++].val, "in")) {
9177
9231
  return null;
@@ -9221,9 +9275,10 @@ function colorMix(...args) {
9221
9275
  if (values == null) {
9222
9276
  return null;
9223
9277
  }
9224
- if (colorSpace == "hwb") {
9225
- colorSpace = "srgb";
9226
- }
9278
+ // if (colorSpace == "hwb") {
9279
+ // colorSpace = "srgb";
9280
+ // }
9281
+ colors.push(processPowerlessComponents(args[i]));
9227
9282
  switch (colorSpace) {
9228
9283
  case "srgb":
9229
9284
  break;
@@ -9253,17 +9308,12 @@ function colorMix(...args) {
9253
9308
  values = srgb2xyz_d65(values[0], values[1], values[2], values[3]);
9254
9309
  values = XYZ_D65_to_D50(values[0], values[1], values[2], values[3]);
9255
9310
  break;
9256
- // case "rgb":
9257
- // for (let j = 0; j < values.length; j++) {
9258
- // values[j] = j == 3 ? values[j] : srgb2rgb(values[j]);
9259
- // }
9260
- // break;
9261
9311
  case "hsl":
9262
9312
  values = srgb2hslvalues(values[0], values[1], values[2], values[3]);
9263
9313
  break;
9264
- // case "hwb":
9265
- // values = srgb2hwb(values[0], values[1], values[2], values[3]);
9266
- // break;
9314
+ case "hwb":
9315
+ values = srgb2hwb(values[0], values[1], values[2], values[3]);
9316
+ break;
9267
9317
  case "lab":
9268
9318
  values = srgb2labvalues(values[0], values[1], values[2], values[3]);
9269
9319
  break;
@@ -9325,7 +9375,8 @@ function colorMix(...args) {
9325
9375
  }
9326
9376
  }
9327
9377
  const stack = [];
9328
- const lchSpaces = ["lch", "oklch"];
9378
+ // const lchSpaces: string[] = ["lch", "oklch"];
9379
+ const isLCHOrOKLCH = colorSpace === "lch" || colorSpace == "oklch";
9329
9380
  i = srgbComponentValues.length;
9330
9381
  while (i--) {
9331
9382
  stack.push({
@@ -9343,46 +9394,73 @@ function colorMix(...args) {
9343
9394
  let premult1;
9344
9395
  let premult2;
9345
9396
  let mixedPremult;
9346
- let colorSpace1 = exports.ColorType[
9347
- // @ts-expect-error
9348
- colorComponents.at(-1).kin
9349
- // @ts-expect-error
9350
- ]?.toLowerCase?.();
9351
- if (colorComponents[0][3] != null &&
9352
- colorComponents[0][3].typ == exports.EnumToken.IdenTokenType &&
9353
- colorComponents[0][3].val == "none" &&
9354
- colorComponents[1].length == 4) {
9397
+ let offset1 = colors[0].kin == exports.ColorType.COLOR ? 1 : 0;
9398
+ if (colorComponents[0][offset1 + 3] != null &&
9399
+ colorComponents[0][offset1 + 3].typ == exports.EnumToken.IdenTokenType &&
9400
+ colorComponents[0][offset1 + 3].val == "none" &&
9401
+ colorComponents[1].length == offset1 + 4) {
9355
9402
  // fix powerless alpha for last color if previous color has alpha
9356
9403
  stack[stack.length - 1].color[3] = stack[stack.length - 2].color[3];
9357
9404
  }
9358
- // powerless hue for lch spaces
9359
- if (lchSpaces.includes(colorSpace1) || lchSpaces.includes(colorSpace)) {
9360
- if ((stack.length > 1 &&
9361
- colorComponents[0][2].typ == exports.EnumToken.IdenTokenType &&
9362
- colorComponents[0][2].val == "none") ||
9363
- stack[stack.length - 1].color[2] == 0) {
9405
+ // console.error(stack);
9406
+ if (stack.length > 1) {
9407
+ // powerless hue for lch spaces
9408
+ // if (lchSpaces.includes(colorSpace)) {
9409
+ // console.error(JSON.stringify({colorSpace1, colorSpace, stack, colorComponents}, null, 1));
9410
+ if ((stack[stack.length - 1].color[0] == 0 && colorComponents[0][offset1].typ == exports.EnumToken.IdenTokenType &&
9411
+ colorComponents[0][offset1].val == "none") ||
9412
+ colorComponents[0][0][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
9413
+ stack[stack.length - 1].color[0] = stack[stack.length - 2].color[0];
9414
+ }
9415
+ if ((stack[stack.length - 1].color[1] == 0 && colorComponents[0][offset1 + 1].typ == exports.EnumToken.IdenTokenType &&
9416
+ colorComponents[0][offset1 + 1].val == "none") ||
9417
+ colorComponents[0][1][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
9418
+ stack[stack.length - 1].color[1] = stack[stack.length - 2].color[1];
9419
+ }
9420
+ if ((stack[stack.length - 1].color[2] == 0 && colorComponents[0][offset1 + 2].typ == exports.EnumToken.IdenTokenType &&
9421
+ colorComponents[0][offset1 + 2].val == "none") ||
9422
+ colorComponents[0][2][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent ||
9423
+ (isLCHOrOKLCH &&
9424
+ (stack[stack.length - 1].color[1] == 0 ||
9425
+ stack[stack.length - 1].color[0] == 0 ||
9426
+ stack[stack.length - 1].color[0] ==
9427
+ colorRange[colors[0].kin == exports.ColorType.LCH ? "lch" : "oklch"].l[1]))) {
9364
9428
  stack[stack.length - 1].color[2] = stack[stack.length - 2].color[2];
9365
9429
  }
9430
+ // }
9366
9431
  }
9432
+ // console.error([colorComponents[0][offset1].typ == EnumToken.IdenTokenType, (colorComponents[0][offset1] as IdentToken).val == "none"]);
9433
+ // console.error(isLCHOrOKLCH, colorComponents, stack);
9367
9434
  while (stack.length > 1) {
9368
9435
  r1 = stack.pop();
9369
9436
  r2 = stack.pop();
9437
+ offset1 = colors[++currentIndex].kin == exports.ColorType.COLOR ? 1 : 0;
9370
9438
  // r2 powerless alpha
9371
- if (colorComponents[++currentIndex][3] != null &&
9372
- colorComponents[currentIndex][3].typ == exports.EnumToken.IdenTokenType &&
9373
- colorComponents[currentIndex][3].val == "none") {
9439
+ if (colorComponents[currentIndex][offset1 + 3] != null &&
9440
+ colorComponents[currentIndex][offset1 + 3].typ == exports.EnumToken.IdenTokenType &&
9441
+ colorComponents[currentIndex][offset1 + 3].val == "none") {
9374
9442
  // fix powerless alpha for last color if previous color has alpha
9375
9443
  r2.color[3] = r1.color[3];
9376
9444
  }
9377
- // @ts-expect-error
9378
- colorSpace1 = exports.ColorType[colorComponents[currentIndex].kin]?.toLowerCase?.();
9379
9445
  // powerless hue for lch spaces
9380
- if (lchSpaces.includes(colorSpace1) || lchSpaces.includes(colorSpace)) {
9381
- if ((colorComponents[currentIndex][2].typ == exports.EnumToken.IdenTokenType &&
9382
- colorComponents[currentIndex][2].val == "none") ||
9383
- r2.color[2] == 0) {
9384
- r2.color[2] = r1.color[2];
9385
- }
9446
+ if ((r2.color[0] == 0 && colorComponents[currentIndex][offset1].typ == exports.EnumToken.IdenTokenType &&
9447
+ colorComponents[currentIndex][offset1].val == "none") ||
9448
+ colorComponents[currentIndex][offset1][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
9449
+ r2.color[0] = r1.color[0];
9450
+ }
9451
+ if ((r2.color[1] == 0 && colorComponents[currentIndex][offset1 + 1].typ == exports.EnumToken.IdenTokenType &&
9452
+ colorComponents[currentIndex][offset1 + 1].val == "none") ||
9453
+ colorComponents[currentIndex][offset1 + 1][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent) {
9454
+ r2.color[1] = r1.color[1];
9455
+ }
9456
+ if ((r2.color[2] == 0 && colorComponents[currentIndex][offset1 + 2].typ == exports.EnumToken.IdenTokenType &&
9457
+ colorComponents[currentIndex][offset1 + 2].val == "none") ||
9458
+ colorComponents[currentIndex][offset1 + 2][STATE] & exports.EnumAstNodeStatus.PowerlessColorComponent ||
9459
+ (isLCHOrOKLCH &&
9460
+ (r2.color[1] == 0 ||
9461
+ r2.color[0] == 0 ||
9462
+ r2.color[0] == colorRange[colors[currentIndex].kin == exports.ColorType.LCH ? "lch" : "oklch"].l[1]))) {
9463
+ r2.color[2] = r1.color[2];
9386
9464
  }
9387
9465
  if (hueInterpolationMethod != null) {
9388
9466
  let hueIndex = 2;
@@ -9410,6 +9488,7 @@ function colorMix(...args) {
9410
9488
  alpha: mult,
9411
9489
  };
9412
9490
  }
9491
+ // console.error({ r1, r2, r, premult1, mult1, premult2, mult2, mixedPremult, mult });
9413
9492
  stack.push(r);
9414
9493
  }
9415
9494
  const result = stack.pop();
@@ -9464,16 +9543,16 @@ function colorMix(...args) {
9464
9543
  };
9465
9544
  // case "rgb":
9466
9545
  case "hsl":
9467
- // case "hwb":
9546
+ case "hwb":
9468
9547
  case "lab":
9469
9548
  case "lch":
9470
9549
  case "oklab":
9471
9550
  case "oklch":
9472
- if (colorSpace == "hsl") {
9551
+ if (colorSpace == "hsl" || colorSpace == "hwb") {
9473
9552
  // @ts-ignore
9474
9553
  if (values[2] < 0) {
9475
9554
  // @ts-ignore
9476
- values[2] += 1;
9555
+ values[2] += 360;
9477
9556
  }
9478
9557
  }
9479
9558
  else if (colorSpace == "lch" || colorSpace == "oklch") {
@@ -9501,16 +9580,72 @@ function colorMix(...args) {
9501
9580
  };
9502
9581
  if (colorSpace == "hsl") {
9503
9582
  // @ts-ignore
9504
- result.chi[0] = { typ: exports.EnumToken.AngleTokenType, val: result.chi[0].val * 360 };
9583
+ result.chi[0] = { typ: exports.EnumToken.AngleTokenType, val: result.chi[0].val };
9505
9584
  // @ts-ignore
9506
- result.chi[1] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[1].val * 100 };
9585
+ result.chi[1] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[1].val };
9507
9586
  // @ts-ignore
9508
- result.chi[2] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[2].val * 100 };
9587
+ result.chi[2] = { typ: exports.EnumToken.PercentageTokenType, val: result.chi[2].val };
9509
9588
  }
9510
9589
  return result;
9511
9590
  }
9512
9591
  return null;
9513
9592
  }
9593
+ function processPowerlessComponents(color) {
9594
+ let components;
9595
+ let values;
9596
+ switch (color.kin) {
9597
+ case exports.ColorType.LCH:
9598
+ case exports.ColorType.OKLCH:
9599
+ values = color.kin == exports.ColorType.LCH ? getLCHComponents(color) : getOKLCHComponents(color);
9600
+ components = getColorComponents(color);
9601
+ if (values == null || values.length < 3 || components == null) {
9602
+ break;
9603
+ }
9604
+ const max = color.kin == exports.ColorType.LCH ? colorRange.lch.l[1] : colorRange.oklch.l[1];
9605
+ // https://www.w3.org/TR/css-color-4/#specifying-lab-lch
9606
+ // https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch
9607
+ const epsilon = color.kin == exports.ColorType.LCH ? 0.0015 : 0.000004;
9608
+ if (values[0] < epsilon || Math.abs(values[0] - max) < epsilon) {
9609
+ Object.assign(components[0], { val: values[0] < epsilon ? 0 : max, typ: exports.EnumToken.NumberTokenType });
9610
+ Object.assign(components[1], { val: "none", typ: exports.EnumToken.IdenTokenType });
9611
+ Object.assign(components[2], { val: "none", typ: exports.EnumToken.IdenTokenType });
9612
+ setColorFlag(components[1], exports.EnumAstNodeStatus.PowerlessColorComponent);
9613
+ setColorFlag(components[2], exports.EnumAstNodeStatus.PowerlessColorComponent);
9614
+ }
9615
+ else if (values[1] < epsilon) {
9616
+ values[1] = 0;
9617
+ Object.assign(components[1], { val: 0, typ: exports.EnumToken.NumberTokenType });
9618
+ Object.assign(components[2], { val: "none", typ: exports.EnumToken.IdenTokenType });
9619
+ setColorFlag(components[2], exports.EnumAstNodeStatus.PowerlessColorComponent);
9620
+ }
9621
+ break;
9622
+ case exports.ColorType.HSL:
9623
+ case exports.ColorType.HWB:
9624
+ values = Object.values((color.kin == exports.ColorType.HSL ? hslvalues(color) : hwbvalues(color)) ?? {});
9625
+ components = getColorComponents(color);
9626
+ if (values == null || values.length < 3 || components == null) {
9627
+ break;
9628
+ }
9629
+ // https://www.w3.org/TR/css-color-4/#the-hsl-notation
9630
+ // https://www.w3.org/TR/css-color-4/#the-hwb-notation
9631
+ if ((color.kin == exports.ColorType.HSL && values[1] <= 0.001) ||
9632
+ (color.kin == exports.ColorType.HWB && values[1] + values[2] >= 99.999)) {
9633
+ Object.assign(components[0], { val: "none", typ: exports.EnumToken.IdenTokenType });
9634
+ setColorFlag(components[0], exports.EnumAstNodeStatus.PowerlessColorComponent);
9635
+ }
9636
+ break;
9637
+ }
9638
+ // console.error({ color: color.chi ?? color, values });
9639
+ return color;
9640
+ }
9641
+ function setColorFlag(token, flag) {
9642
+ if (token[STATE] == null) {
9643
+ token[STATE] = flag;
9644
+ }
9645
+ else {
9646
+ token[STATE] |= flag;
9647
+ }
9648
+ }
9514
9649
 
9515
9650
  /**
9516
9651
  * Options for the walk function
@@ -9548,6 +9683,7 @@ exports.WalkerEvent = void 0;
9548
9683
  */
9549
9684
  WalkerEvent[WalkerEvent["Leave"] = 2] = "Leave";
9550
9685
  })(exports.WalkerEvent || (exports.WalkerEvent = {}));
9686
+ const maxQueueLength = 25000;
9551
9687
  /**
9552
9688
  * Walk ast nodes
9553
9689
  * @param node initial node
@@ -9651,6 +9787,10 @@ function* walk(node, filter, reverse) {
9651
9787
  },
9652
9788
  };
9653
9789
  while ((node = parents[i++])) {
9790
+ if (i > maxQueueLength) {
9791
+ parents.splice(0, maxQueueLength);
9792
+ i -= maxQueueLength;
9793
+ }
9654
9794
  let option = null;
9655
9795
  if (filter != null) {
9656
9796
  // @ts-expect-error
@@ -9794,6 +9934,10 @@ function* walkValues(values, root = null, filter, reverse) {
9794
9934
  while (++i < stack.length) {
9795
9935
  value = stack[i];
9796
9936
  option = null;
9937
+ if (i > maxQueueLength) {
9938
+ stack.splice(0, maxQueueLength);
9939
+ i -= maxQueueLength;
9940
+ }
9797
9941
  if (filter.fn != null && eventType & exports.WalkerEvent.Enter) {
9798
9942
  const isValid = filter.type == null ||
9799
9943
  value.typ == filter.type ||
@@ -11026,7 +11170,36 @@ function parseRelativeColorComponents(relativeKeys, original, rExp, gExp, bExp,
11026
11170
  : aExp),
11027
11171
  };
11028
11172
  const result = computeComponentValue(keys, values);
11173
+ if (result != null) {
11174
+ if ("hsl" == relativeKeys) {
11175
+ Object.assign(result.s, {
11176
+ typ: exports.EnumToken.PercentageTokenType,
11177
+ // @ts-ignore
11178
+ val: result.s.val * 100,
11179
+ });
11180
+ Object.assign(result.l, {
11181
+ typ: exports.EnumToken.PercentageTokenType,
11182
+ // @ts-ignore
11183
+ val: result.l.val * 100,
11184
+ });
11185
+ }
11186
+ else if ("hwb" == relativeKeys) {
11187
+ // @ts
11188
+ Object.assign(result.w, {
11189
+ typ: exports.EnumToken.PercentageTokenType,
11190
+ // @ts-ignore
11191
+ val: result.w.val * 100,
11192
+ });
11193
+ Object.assign(result.b, {
11194
+ typ: exports.EnumToken.PercentageTokenType,
11195
+ // @ts-ignore
11196
+ val: result.b.val * 100,
11197
+ });
11198
+ }
11199
+ }
11200
+ // @ts-ignore
11029
11201
  if (result?.alpha?.typ == exports.EnumToken.NumberTokenType && result.alpha.val === 1) {
11202
+ // @ts-ignore
11030
11203
  const { alpha, ...components } = result;
11031
11204
  return components;
11032
11205
  }
@@ -12319,8 +12492,7 @@ function isMFValue(featureName, tokens, isMFRange) {
12319
12492
  case MediaFeatureType.RatioType:
12320
12493
  return {
12321
12494
  valid: true,
12322
- success: (tokens.length == 1 &&
12323
- tokens[0].typ == exports.EnumToken.NumberTokenType) ||
12495
+ success: (tokens.length == 1 && tokens[0].typ == exports.EnumToken.NumberTokenType) ||
12324
12496
  (tokens.length === 3 &&
12325
12497
  tokens[0].typ == exports.EnumToken.NumberTokenType &&
12326
12498
  typeof tokens[0].val === "number" &&
@@ -12627,7 +12799,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
12627
12799
  }
12628
12800
  stack.push(token);
12629
12801
  break;
12630
- case exports.EnumToken.Pipe:
12802
+ case exports.EnumToken.PipeTokenType:
12631
12803
  case exports.EnumToken.DelimTokenType:
12632
12804
  case exports.EnumToken.StringTokenType:
12633
12805
  case exports.EnumToken.IncludeMatchTokenType:
@@ -12675,10 +12847,10 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
12675
12847
  }
12676
12848
  slice.push(tokens[n]);
12677
12849
  }
12678
- if (slice[1]?.typ === exports.EnumToken.Pipe) {
12850
+ if (slice[1]?.typ === exports.EnumToken.PipeTokenType) {
12679
12851
  slice.shift();
12680
12852
  }
12681
- if (slice[0].typ === exports.EnumToken.Pipe) {
12853
+ if (slice[0].typ === exports.EnumToken.PipeTokenType) {
12682
12854
  slice.shift();
12683
12855
  }
12684
12856
  if (slice.length === 1) {
@@ -13040,8 +13212,8 @@ function matchSyntax(syntaxes, context, options) {
13040
13212
  // custom function token
13041
13213
  if (token.typ === exports.EnumToken.CustomFunctionTokenDefType) {
13042
13214
  if (syntaxes[i].typ != ValidationTokenEnum.PropertyType ||
13043
- syntaxes[i + 1].typ != ValidationTokenEnum.OpenParenthesis ||
13044
- syntaxes[i + 2].typ == null) {
13215
+ syntaxes[i + 1]?.typ != ValidationTokenEnum.OpenParenthesis ||
13216
+ syntaxes[i + 2]?.typ == null) {
13045
13217
  if (!isOptional) {
13046
13218
  return {
13047
13219
  success: false,
@@ -13888,17 +14060,15 @@ function matchProperty(property, context, options) {
13888
14060
  case "display-internal":
13889
14061
  case "display-outside":
13890
14062
  case "display-legacy":
13891
- case "content-position":
13892
- {
13893
- let values = propertyKeywordValues.get(property.val);
13894
- if (values == null) {
13895
- values = new Set(config$3.syntaxes[property.val].syntax.split(/[\s|]+/));
13896
- propertyKeywordValues.set(property.val, values);
13897
- }
13898
- success =
13899
- token?.typ == exports.EnumToken.IdenTokenType && values.has(token.val.toLowerCase());
13900
- break;
14063
+ case "content-position": {
14064
+ let values = propertyKeywordValues.get(property.val);
14065
+ if (values == null) {
14066
+ values = new Set(config$3.syntaxes[property.val].syntax.split(/[\s|]+/));
14067
+ propertyKeywordValues.set(property.val, values);
13901
14068
  }
14069
+ success = token?.typ == exports.EnumToken.IdenTokenType && values.has(token.val.toLowerCase());
14070
+ break;
14071
+ }
13902
14072
  case "mf-name":
13903
14073
  {
13904
14074
  const token = context.peek();
@@ -13918,8 +14088,7 @@ function matchProperty(property, context, options) {
13918
14088
  case "custom-ident":
13919
14089
  case "counter-name":
13920
14090
  case "counter-style-name":
13921
- success =
13922
- token?.typ == exports.EnumToken.IdenTokenType || token?.typ == exports.EnumToken.DashedIdenTokenType;
14091
+ success = token?.typ == exports.EnumToken.IdenTokenType || token?.typ == exports.EnumToken.DashedIdenTokenType;
13923
14092
  if (success && token?.typ === exports.EnumToken.IdenTokenType) {
13924
14093
  const val = token.val.toLowerCase();
13925
14094
  success = "none" !== val && !allValues.includes(val);
@@ -14390,6 +14559,21 @@ function matchProperty(property, context, options) {
14390
14559
  }
14391
14560
  break;
14392
14561
  }
14562
+ case "css-type": {
14563
+ success = context.peek()?.typ == exports.EnumToken.CssTypeTokenType;
14564
+ if (success) {
14565
+ context.next();
14566
+ return {
14567
+ success: true,
14568
+ valid: true,
14569
+ token: null,
14570
+ context,
14571
+ syntaxToken: null,
14572
+ errors: [],
14573
+ };
14574
+ }
14575
+ break;
14576
+ }
14393
14577
  default:
14394
14578
  if (!(property.val in config$3.syntaxes)) {
14395
14579
  console.debug("Unknown syntax", context.peek(), property);
@@ -15168,7 +15352,6 @@ function getAngle(token) {
15168
15352
  return +token.val;
15169
15353
  }
15170
15354
  }
15171
- // @ts-ignore
15172
15355
  return token.val / 360;
15173
15356
  }
15174
15357
 
@@ -17026,9 +17209,7 @@ class ComputePrefixFeature {
17026
17209
  }
17027
17210
  }
17028
17211
  run(node) {
17029
- if (node[STATE] == exports.EnumAstNodeStatus.Disallowed ||
17030
- node[STATE] == exports.EnumAstNodeStatus.Invalid ||
17031
- node[STATE] == exports.EnumAstNodeStatus.Malformed) {
17212
+ if (node[STATE] & (exports.EnumAstNodeStatus.Disallowed | exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.Malformed)) {
17032
17213
  return null;
17033
17214
  }
17034
17215
  if (node.typ == exports.EnumToken.RuleNodeType) {
@@ -19743,7 +19924,8 @@ class PropertyMap {
19743
19924
  const tokens = {};
19744
19925
  const values = [];
19745
19926
  const val = [[]];
19746
- for (const curr of this.declarations.get(this.config.shorthand).val) { // @ts-ignore
19927
+ for (const curr of this.declarations.get(this.config.shorthand).val) {
19928
+ // @ts-ignore
19747
19929
  // @ts-ignore
19748
19930
  if (separator != null && separator.typ == curr.typ && separator.val == curr.val) {
19749
19931
  val.push([]);
@@ -20687,9 +20869,8 @@ class PropertyList {
20687
20869
  let result;
20688
20870
  for (const declaration of declarations) {
20689
20871
  name = declaration.typ != exports.EnumToken.DeclarationNodeType ? null : declaration.nam;
20690
- if (declaration[STATE] == exports.EnumAstNodeStatus.Invalid ||
20691
- declaration[STATE] == exports.EnumAstNodeStatus.Unknown ||
20692
- declaration[STATE] == exports.EnumAstNodeStatus.ValidationFailed ||
20872
+ if (declaration[STATE] &
20873
+ (exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.Unknown | exports.EnumAstNodeStatus.ValidationFailed) ||
20693
20874
  declaration.typ != exports.EnumToken.DeclarationNodeType ||
20694
20875
  equalsIgnoreCase("composes", name) ||
20695
20876
  (typeof this.options.removeDuplicateDeclarations === "string" &&
@@ -20708,17 +20889,17 @@ class PropertyList {
20708
20889
  this.declarations.set(declaration.nam, declaration);
20709
20890
  continue;
20710
20891
  }
20711
- if (declaration[STATE] == exports.EnumAstNodeStatus.Unvalidated) {
20892
+ if (declaration[STATE] & exports.EnumAstNodeStatus.Unvalidated) {
20712
20893
  syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, declaration.nam.toLowerCase());
20713
20894
  if (syntaxRules != null) {
20714
20895
  result = matchAllSyntaxes(syntaxRules, createValidationContext(declaration.val), this.options);
20715
- declaration[STATE] = result.success
20716
- ? exports.EnumAstNodeStatus.Validated
20717
- : exports.EnumAstNodeStatus.ValidationFailed;
20896
+ declaration[STATE] |=
20897
+ (result.success ? exports.EnumAstNodeStatus.Validated : exports.EnumAstNodeStatus.ValidationFailed) &
20898
+ ~exports.EnumAstNodeStatus.Unvalidated;
20718
20899
  }
20719
20900
  }
20720
20901
  // do not compute shorthand for invalid declarations
20721
- if (declaration[STATE] !== exports.EnumAstNodeStatus.Validated) {
20902
+ if (!(declaration[STATE] & exports.EnumAstNodeStatus.Validated)) {
20722
20903
  this.declarations.set(objectHash(declaration), declaration);
20723
20904
  continue;
20724
20905
  }
@@ -20748,6 +20929,16 @@ class PropertyList {
20748
20929
  // @ts-ignore
20749
20930
  shorthand = config.property[propertyName];
20750
20931
  }
20932
+ if (this.declarations.has(shorthand)) {
20933
+ let existing = this.declarations.get(shorthand);
20934
+ if (existing instanceof PropertySet || existing instanceof PropertyMap) {
20935
+ existing = existing.declarations.get(declaration.nam);
20936
+ }
20937
+ if (existing?.[STATE] & exports.EnumAstNodeStatus.ImportantDeclaration &&
20938
+ declaration[STATE] & ~exports.EnumAstNodeStatus.ImportantDeclaration) {
20939
+ continue;
20940
+ }
20941
+ }
20751
20942
  // @ts-ignore
20752
20943
  if (shortHandType == "map") {
20753
20944
  let owner = this;
@@ -20959,12 +21150,15 @@ const trimTokenSpace = new Set([
20959
21150
  exports.EnumToken.LtTokenType,
20960
21151
  exports.EnumToken.LteTokenType,
20961
21152
  exports.EnumToken.ChildCombinatorTokenType,
21153
+ exports.EnumToken.PipeTokenType,
20962
21154
  ]);
20963
21155
  const trimSpaceAfter = new Set([
20964
21156
  ...tokensfuncSet.values(),
20965
21157
  exports.EnumToken.ChildCombinatorTokenType,
20966
21158
  exports.EnumToken.SupportsQueryConditionTokenType,
20967
21159
  exports.EnumToken.SupportsQueryUnaryConditionTokenType,
21160
+ exports.EnumToken.CommaTokenType,
21161
+ exports.EnumToken.PipeTokenType,
20968
21162
  ]);
20969
21163
  /**
20970
21164
  * Replace token in its parent node
@@ -21034,17 +21228,18 @@ function trimWhiteSpaceTokens(tokens) {
21034
21228
  return tokens;
21035
21229
  }
21036
21230
  for (; i < tokens.length; i++) {
21037
- if (trimSpaceAfter.has(tokens[i].typ) && tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
21038
- tokens.splice(i + 1, 1);
21039
- }
21040
- else if (trimTokenSpace.has(tokens[i].typ)) {
21231
+ if (trimTokenSpace.has(tokens[i].typ)) {
21041
21232
  if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
21042
21233
  tokens.splice(i + 1, 1);
21043
21234
  }
21044
21235
  if (i > 0 && tokens[i - 1].typ === exports.EnumToken.Whitespace) {
21045
21236
  tokens.splice(--i, 1);
21237
+ continue;
21046
21238
  }
21047
21239
  }
21240
+ if (trimSpaceAfter.has(tokens[i].typ) && tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
21241
+ tokens.splice(i + 1, 1);
21242
+ }
21048
21243
  }
21049
21244
  return tokens;
21050
21245
  }
@@ -22389,7 +22584,7 @@ class TransformCssFeature {
22389
22584
  for (; i < ast.chi.length; i++) {
22390
22585
  // @ts-ignore
22391
22586
  node = ast.chi[i];
22392
- if (node[STATE] == exports.EnumAstNodeStatus.Invalid || node[STATE] == exports.EnumAstNodeStatus.ValidationFailed) {
22587
+ if (node[STATE] & (exports.EnumAstNodeStatus.Invalid | exports.EnumAstNodeStatus.ValidationFailed)) {
22393
22588
  continue;
22394
22589
  }
22395
22590
  if (node.typ != exports.EnumToken.DeclarationNodeType ||
@@ -24332,11 +24527,12 @@ function reduceRuleSelector(node) {
24332
24527
  * @private
24333
24528
  */
24334
24529
  function expand(ast) {
24335
- if (ast[STATE] == exports.EnumAstNodeStatus.Invalid ||
24336
- ast[STATE] == exports.EnumAstNodeStatus.Disallowed ||
24337
- ast[STATE] == exports.EnumAstNodeStatus.Unknown ||
24338
- ast[STATE] == exports.EnumAstNodeStatus.Unparsed ||
24339
- ast[STATE] == exports.EnumAstNodeStatus.Malformed) {
24530
+ if (ast[STATE] &
24531
+ (exports.EnumAstNodeStatus.Invalid |
24532
+ exports.EnumAstNodeStatus.Disallowed |
24533
+ exports.EnumAstNodeStatus.Unknown |
24534
+ exports.EnumAstNodeStatus.Unparsed |
24535
+ exports.EnumAstNodeStatus.Malformed)) {
24340
24536
  return ast;
24341
24537
  }
24342
24538
  const result = Object.assign(cloneNode(ast), { chi: [] });
@@ -24384,11 +24580,12 @@ function expand(ast) {
24384
24580
  return result;
24385
24581
  }
24386
24582
  function expandRule(node) {
24387
- if (node[STATE] == exports.EnumAstNodeStatus.Invalid ||
24388
- node[STATE] == exports.EnumAstNodeStatus.Disallowed ||
24389
- node[STATE] == exports.EnumAstNodeStatus.Unknown ||
24390
- node[STATE] == exports.EnumAstNodeStatus.Unparsed ||
24391
- node[STATE] == exports.EnumAstNodeStatus.Malformed) {
24583
+ if (node[STATE] &
24584
+ (exports.EnumAstNodeStatus.Invalid |
24585
+ exports.EnumAstNodeStatus.Disallowed |
24586
+ exports.EnumAstNodeStatus.Unknown |
24587
+ exports.EnumAstNodeStatus.Unparsed |
24588
+ exports.EnumAstNodeStatus.Malformed)) {
24392
24589
  return [node];
24393
24590
  }
24394
24591
  const ast = Object.assign(cloneNode(node), { chi: node.chi.slice() });
@@ -26492,7 +26689,7 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
26492
26689
  return ",";
26493
26690
  case exports.EnumToken.ImportantTokenType:
26494
26691
  return "!important";
26495
- case exports.EnumToken.Pipe:
26692
+ case exports.EnumToken.PipeTokenType:
26496
26693
  return "|";
26497
26694
  case exports.EnumToken.AttrTokenType:
26498
26695
  case exports.EnumToken.IdenListTokenType:
@@ -26615,6 +26812,7 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
26615
26812
  pseudoElements.includes(token.val.slice(1))) {
26616
26813
  return token.val.slice(1);
26617
26814
  }
26815
+ case exports.EnumToken.CssTypeTokenType:
26618
26816
  case exports.EnumToken.UrlTokenTokenType:
26619
26817
  case exports.EnumToken.HashTokenType:
26620
26818
  case exports.EnumToken.IdenTokenType:
@@ -26648,17 +26846,20 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
26648
26846
  ? ""
26649
26847
  : token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
26650
26848
  ":" +
26849
+ (options.indent ?? "") +
26651
26850
  token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "");
26652
26851
  case exports.EnumToken.IfElseConditionTokenType:
26653
- return renderValue(token.l) + renderValue(token.r);
26852
+ return (renderValue(token.l, options, cache, reducer) +
26853
+ (options.indent ?? "") +
26854
+ renderValue(token.r, options, cache, reducer));
26654
26855
  case exports.EnumToken.DeclarationNodeType:
26655
26856
  return (token.nam +
26656
26857
  ":" +
26657
- (options.minifyValues ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
26858
+ (options.minifyValues ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
26658
26859
  case exports.EnumToken.MediaQueryUnaryFeatureTokenType:
26659
26860
  return (renderValue(token.l, options, cache, reducer) +
26660
26861
  " " +
26661
- token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
26862
+ token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
26662
26863
  case exports.EnumToken.MediaQueryConditionTokenType: {
26663
26864
  const indent = token.op.typ == exports.EnumToken.LtTokenType ||
26664
26865
  token.op.typ == exports.EnumToken.GtTokenType ||
@@ -26672,14 +26873,14 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
26672
26873
  indent +
26673
26874
  renderValue(token.op, options, cache, reducer) +
26674
26875
  indent +
26675
- token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
26876
+ token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
26676
26877
  }
26677
26878
  case exports.EnumToken.MediaRangeQueryTokenType:
26678
- return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache), "") +
26679
- renderValue(token.op1) +
26879
+ return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
26880
+ renderValue(token.op1, options, cache, reducer) +
26680
26881
  token.val.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
26681
- renderValue(token.op2) +
26682
- token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
26882
+ renderValue(token.op2, options, cache, reducer) +
26883
+ token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
26683
26884
  case exports.EnumToken.MediaFeatureTokenType:
26684
26885
  return token.val;
26685
26886
  case exports.EnumToken.NotTokenType:
@@ -26765,7 +26966,7 @@ function assignTokenMap(entries, tokenType, suffix = "", lowercase = false) {
26765
26966
  SymbolsMapTokens[""] = exports.EnumToken.DelimTokenType;
26766
26967
  SymbolsMapTokens["+"] = exports.EnumToken.Plus;
26767
26968
  SymbolsMapTokens["="] = exports.EnumToken.DelimTokenType;
26768
- SymbolsMapTokens["|"] = exports.EnumToken.Pipe;
26969
+ SymbolsMapTokens["|"] = exports.EnumToken.PipeTokenType;
26769
26970
  SymbolsMapTokens["||"] = exports.EnumToken.ColumnCombinatorTokenType;
26770
26971
  SymbolsMapTokens["|="] = exports.EnumToken.DashMatchTokenType;
26771
26972
  SymbolsMapTokens["&"] = exports.EnumToken.NestingSelectorTokenType;
@@ -27424,7 +27625,6 @@ class Tokenizer {
27424
27625
  if (codepoint == 92 /* TokenMap.REVERSE_SOLIDUS */) {
27425
27626
  // eof
27426
27627
  if ((codepoint = parseInfo.stream.charCodeAt(position + 1)) != codepoint) {
27427
- // this.next(parseInfo, position);
27428
27628
  return 0;
27429
27629
  }
27430
27630
  // \n \r \f \v
@@ -28197,7 +28397,7 @@ class Tokenizer {
28197
28397
  return this.makeToken(parseInfo, exports.EnumToken.DashMatchTokenType);
28198
28398
  }
28199
28399
  this.advance(parseInfo);
28200
- return this.makeToken(parseInfo, exports.EnumToken.Pipe);
28400
+ return this.makeToken(parseInfo, exports.EnumToken.PipeTokenType);
28201
28401
  case 33 /* TokenMap.EXCLAMATION */:
28202
28402
  if (parseInfo.position < parseInfo.currentPosition) {
28203
28403
  return this.makeToken(parseInfo);
@@ -28263,6 +28463,21 @@ class Tokenizer {
28263
28463
  return this.makeToken(parseInfo, exports.EnumToken.CDOCOMMTokenType);
28264
28464
  }
28265
28465
  }
28466
+ {
28467
+ const startPosition = parseInfo.position - parseInfo.offset;
28468
+ let offset = 1;
28469
+ let charCode = parseInfo.stream.charCodeAt(startPosition + offset);
28470
+ if (isLetter(charCode)) {
28471
+ charCode = parseInfo.stream.charCodeAt(++offset + startPosition);
28472
+ while (offset < endPosition && (charCode == 45 /* TokenMap.MINUS */ || isLetter(charCode))) {
28473
+ charCode = parseInfo.stream.charCodeAt(++offset + startPosition);
28474
+ }
28475
+ if (offset > 1 && charCode == 62 /* TokenMap.GREATERTHAN */) {
28476
+ this.advance(parseInfo, offset);
28477
+ return this.makeToken(parseInfo, exports.EnumToken.CssTypeTokenType);
28478
+ }
28479
+ }
28480
+ }
28266
28481
  break;
28267
28482
  case 35 /* TokenMap.HASH */:
28268
28483
  if (parseInfo.position < parseInfo.currentPosition) {
@@ -28883,6 +29098,7 @@ function parseDeclaration(tokens, parent, options, errors) {
28883
29098
  let rules = null;
28884
29099
  let syntaxRules = null;
28885
29100
  let success = true;
29101
+ let hasImportantFlag = false;
28886
29102
  let validate = typeof options.validation === "boolean" ? options.validation : !!options.validation;
28887
29103
  if (renamedStandardProperties.has(name.val)) {
28888
29104
  name.val = renamedStandardProperties.get(name.val);
@@ -29184,6 +29400,9 @@ function parseDeclaration(tokens, parent, options, errors) {
29184
29400
  }
29185
29401
  }
29186
29402
  break;
29403
+ case exports.EnumToken.ImportantTokenType:
29404
+ hasImportantFlag = true;
29405
+ break;
29187
29406
  }
29188
29407
  if (trimTokenSpace$1.has(token.typ)) {
29189
29408
  if (tokens[i + 1]?.typ === exports.EnumToken.WhitespaceTokenType) {
@@ -29250,6 +29469,9 @@ function parseDeclaration(tokens, parent, options, errors) {
29250
29469
  }
29251
29470
  name[STATE] = exports.EnumAstNodeStatus.Unknown;
29252
29471
  name[ERRORS] = result?.errors ?? [];
29472
+ if (hasImportantFlag) {
29473
+ name[STATE] |= exports.EnumAstNodeStatus.ImportantDeclaration;
29474
+ }
29253
29475
  // @ts-expect-error
29254
29476
  return Object.assign(name, {
29255
29477
  typ: exports.EnumToken.DeclarationNodeType,
@@ -29287,6 +29509,9 @@ function parseDeclaration(tokens, parent, options, errors) {
29287
29509
  : exports.EnumAstNodeStatus.Validated
29288
29510
  : exports.EnumAstNodeStatus.ValidationFailed;
29289
29511
  name[ERRORS] = result?.errors ?? [];
29512
+ if (hasImportantFlag) {
29513
+ name[STATE] |= exports.EnumAstNodeStatus.ImportantDeclaration;
29514
+ }
29290
29515
  // @ts-expect-error
29291
29516
  return Object.assign(name, {
29292
29517
  typ: exports.EnumToken.DeclarationNodeType,
@@ -30982,6 +31207,9 @@ function parseVisitors(visitorsDef, errors) {
30982
31207
  let key;
30983
31208
  let value;
30984
31209
  let i;
31210
+ const allVisitorsHandlers = new Set();
31211
+ const preAllVisitorsHandlers = new Set();
31212
+ const postAllVisitorsHandlers = new Set();
30985
31213
  const valuesHandlers = new Map();
30986
31214
  const preValuesHandlers = new Map();
30987
31215
  const postValuesHandlers = new Map();
@@ -31082,6 +31310,21 @@ function parseVisitors(visitorsDef, errors) {
31082
31310
  errors.push({ action: "ignore", message: `doParse: visitor.${key} is not a valid key name` });
31083
31311
  }
31084
31312
  }
31313
+ else if (key == "All" || key == "visitor") {
31314
+ if (typeof value == "function") {
31315
+ allVisitorsHandlers.add(value);
31316
+ }
31317
+ else if (typeof value == "object") {
31318
+ if ("type" in value && "handler" in value && value.type in exports.WalkerEvent) {
31319
+ if (value.type == exports.WalkerEvent.Enter) {
31320
+ preAllVisitorsHandlers.add(value.handler);
31321
+ }
31322
+ else if (value.type == exports.WalkerEvent.Leave) {
31323
+ postAllVisitorsHandlers.add(value.handler);
31324
+ }
31325
+ }
31326
+ }
31327
+ }
31085
31328
  else {
31086
31329
  errors.push({ action: "ignore", message: `doParse: visitor.${key} is not a valid key name` });
31087
31330
  }
@@ -31105,10 +31348,25 @@ function parseVisitors(visitorsDef, errors) {
31105
31348
  if (postValuesHandlers.size > 0) {
31106
31349
  allHandlers.push(postValuesHandlers);
31107
31350
  }
31108
- return {
31351
+ const result = {
31109
31352
  allHandlers,
31110
- includeTokens: preValuesHandlers.size > 0 || valuesHandlers.size > 0 || postValuesHandlers.size > 0,
31353
+ includeTokens: preValuesHandlers.size > 0 ||
31354
+ valuesHandlers.size > 0 ||
31355
+ postValuesHandlers.size > 0 ||
31356
+ allVisitorsHandlers.size > 0 ||
31357
+ preAllVisitorsHandlers.size > 0 ||
31358
+ postAllVisitorsHandlers.size > 0,
31111
31359
  };
31360
+ if (allVisitorsHandlers.size > 0) {
31361
+ result.allVisitorsHandlers = allVisitorsHandlers;
31362
+ }
31363
+ if (preAllVisitorsHandlers.size > 0) {
31364
+ result.preAllVisitorsHandlers = preAllVisitorsHandlers;
31365
+ }
31366
+ if (postAllVisitorsHandlers.size > 0) {
31367
+ result.postAllVisitorsHandlers = postAllVisitorsHandlers;
31368
+ }
31369
+ return result;
31112
31370
  }
31113
31371
  /**
31114
31372
  * Parse css string
@@ -31181,12 +31439,10 @@ function doParseSync(tokenizer, options = {}) {
31181
31439
  // @ts-ignore ignore error
31182
31440
  let parensMatch = 0;
31183
31441
  let curlyBracketMatch = 0;
31184
- // let currentItemIndex: number;
31185
31442
  ast[LOCSRCID] = options.source.id;
31186
31443
  ast[LOCSTA] = 0;
31187
31444
  while (!tokenizer.done()) {
31188
31445
  tokenizer.next();
31189
- // item = (iter as Array<TokenizeResult>)[currentItemIndex];
31190
31446
  if (tokenizer.unit != null) {
31191
31447
  item = {
31192
31448
  typ: tokenizer.typ,
@@ -31332,7 +31588,6 @@ function doParseSync(tokenizer, options = {}) {
31332
31588
  parensMatch = 0;
31333
31589
  curlyBracketMatch = 0;
31334
31590
  }
31335
- // }
31336
31591
  }
31337
31592
  if (tokens.length > 0) {
31338
31593
  node = parseNode(tokens, context, options, errors, stats, invalidNodes);
@@ -31402,6 +31657,9 @@ function doParseSync(tokenizer, options = {}) {
31402
31657
  }
31403
31658
  parens = null;
31404
31659
  handlers.length = 0;
31660
+ if (visitors.preAllVisitorsHandlers?.size > 0) {
31661
+ handlers.push(...visitors.preAllVisitorsHandlers);
31662
+ }
31405
31663
  genericKey =
31406
31664
  nodes[i].typ == exports.EnumToken.DeclarationNodeType
31407
31665
  ? "Declaration"
@@ -31421,6 +31679,9 @@ function doParseSync(tokenizer, options = {}) {
31421
31679
  : nodes[i].typ == exports.EnumToken.KeyframesAtRuleNodeType
31422
31680
  ? camelize(nodes[i].val)
31423
31681
  : null;
31682
+ if (visitors.allVisitorsHandlers?.size > 0) {
31683
+ handlers.push(...visitors.allVisitorsHandlers);
31684
+ }
31424
31685
  for (const map of visitors.allHandlers) {
31425
31686
  // @ts-ignore
31426
31687
  if (genericKey != null && map.has(genericKey)) {
@@ -31429,20 +31690,6 @@ function doParseSync(tokenizer, options = {}) {
31429
31690
  if (typeof handler == "function") {
31430
31691
  handlers.push(handler);
31431
31692
  }
31432
- // else if (Array.isArray(handler)) {
31433
- // for (const h of handler) {
31434
- // if (typeof h == "function") {
31435
- // handlers.push(h);
31436
- // }
31437
- // // @ts-ignore
31438
- // else if (h[keyName] != null) {
31439
- // // @ts-ignore
31440
- // handlers.push(h[keyName]);
31441
- // }
31442
- // }
31443
- // } else if (typeof handler.handler! == "function") {
31444
- // handlers.push(handler.handler);
31445
- // }
31446
31693
  // @ts-ignore
31447
31694
  else if (typeof handler[keyName] == "function") {
31448
31695
  // @ts-ignore
@@ -31475,6 +31722,9 @@ function doParseSync(tokenizer, options = {}) {
31475
31722
  }
31476
31723
  }
31477
31724
  }
31725
+ if (visitors.postAllVisitorsHandlers?.size > 0) {
31726
+ handlers.push(...visitors.postAllVisitorsHandlers);
31727
+ }
31478
31728
  if (handlers.length == 0) {
31479
31729
  continue;
31480
31730
  }
@@ -31514,14 +31764,14 @@ function doParseSync(tokenizer, options = {}) {
31514
31764
  if (invalidNodes.length > 0) {
31515
31765
  let count = invalidNodes.length;
31516
31766
  for (const { node, parent } of walk(ast)) {
31517
- if (options.lenient && node[STATE] == exports.EnumAstNodeStatus.Unknown) {
31767
+ if (options.lenient && node[STATE] & exports.EnumAstNodeStatus.Unknown) {
31518
31768
  continue;
31519
31769
  }
31520
- if (node[STATE] === exports.EnumAstNodeStatus.Invalid ||
31521
- node[STATE] === exports.EnumAstNodeStatus.Unknown ||
31522
- node[STATE] === exports.EnumAstNodeStatus.Unparsed ||
31523
- node[STATE] === exports.EnumAstNodeStatus.Malformed ||
31524
- node[STATE] === exports.EnumAstNodeStatus.Disallowed) {
31770
+ if (node[STATE] & exports.EnumAstNodeStatus.Invalid ||
31771
+ node[STATE] & exports.EnumAstNodeStatus.Unknown ||
31772
+ node[STATE] & exports.EnumAstNodeStatus.Unparsed ||
31773
+ node[STATE] & exports.EnumAstNodeStatus.Malformed ||
31774
+ node[STATE] & exports.EnumAstNodeStatus.Disallowed) {
31525
31775
  // @ts-ignore
31526
31776
  parent.chi.splice(parent.chi.indexOf(node), 1);
31527
31777
  node[PARENT] = null;
@@ -32394,6 +32644,9 @@ async function doParse(iter, options = {}) {
32394
32644
  }
32395
32645
  parens = null;
32396
32646
  handlers.length = 0;
32647
+ if (visitors.preAllVisitorsHandlers?.size > 0) {
32648
+ handlers.push(...visitors.preAllVisitorsHandlers);
32649
+ }
32397
32650
  genericKey =
32398
32651
  nodes[i].typ == exports.EnumToken.DeclarationNodeType
32399
32652
  ? "Declaration"
@@ -32413,6 +32666,9 @@ async function doParse(iter, options = {}) {
32413
32666
  : nodes[i].typ == exports.EnumToken.KeyframesAtRuleNodeType
32414
32667
  ? camelize(nodes[i].val)
32415
32668
  : null;
32669
+ if (visitors.allVisitorsHandlers?.size > 0) {
32670
+ handlers.push(...visitors.allVisitorsHandlers);
32671
+ }
32416
32672
  for (const map of visitors.allHandlers) {
32417
32673
  // @ts-ignore
32418
32674
  if (genericKey != null && map.has(genericKey)) {
@@ -32467,6 +32723,9 @@ async function doParse(iter, options = {}) {
32467
32723
  }
32468
32724
  }
32469
32725
  }
32726
+ if (visitors.postAllVisitorsHandlers?.size > 0) {
32727
+ handlers.push(...visitors.postAllVisitorsHandlers);
32728
+ }
32470
32729
  if (handlers.length == 0) {
32471
32730
  continue;
32472
32731
  }
@@ -32509,14 +32768,14 @@ async function doParse(iter, options = {}) {
32509
32768
  if (invalidNodes.length > 0) {
32510
32769
  let count = invalidNodes.length;
32511
32770
  for (const { node, parent } of walk(ast)) {
32512
- if (options.lenient && node[STATE] == exports.EnumAstNodeStatus.Unknown) {
32771
+ if (options.lenient && node[STATE] & exports.EnumAstNodeStatus.Unknown) {
32513
32772
  continue;
32514
32773
  }
32515
- if (node[STATE] === exports.EnumAstNodeStatus.Invalid ||
32516
- node[STATE] === exports.EnumAstNodeStatus.Unknown ||
32517
- node[STATE] === exports.EnumAstNodeStatus.Unparsed ||
32518
- node[STATE] === exports.EnumAstNodeStatus.Malformed ||
32519
- node[STATE] === exports.EnumAstNodeStatus.Disallowed) {
32774
+ if (node[STATE] & exports.EnumAstNodeStatus.Invalid ||
32775
+ node[STATE] & exports.EnumAstNodeStatus.Unknown ||
32776
+ node[STATE] & exports.EnumAstNodeStatus.Unparsed ||
32777
+ node[STATE] & exports.EnumAstNodeStatus.Malformed ||
32778
+ node[STATE] & exports.EnumAstNodeStatus.Disallowed) {
32520
32779
  // @ts-ignore
32521
32780
  parent.chi.splice(parent.chi.indexOf(node), 1);
32522
32781
  node[PARENT] = null;
@@ -33247,11 +33506,12 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
33247
33506
  if (node == null) {
33248
33507
  return null;
33249
33508
  }
33250
- if (node[STATE] == exports.EnumAstNodeStatus.Invalid ||
33251
- node[STATE] == exports.EnumAstNodeStatus.Disallowed ||
33252
- node[STATE] == exports.EnumAstNodeStatus.Unknown ||
33253
- node[STATE] == exports.EnumAstNodeStatus.Unparsed ||
33254
- node[STATE] == exports.EnumAstNodeStatus.Malformed) {
33509
+ if (node[STATE] &
33510
+ (exports.EnumAstNodeStatus.Invalid |
33511
+ exports.EnumAstNodeStatus.Disallowed |
33512
+ exports.EnumAstNodeStatus.Unknown |
33513
+ exports.EnumAstNodeStatus.Unparsed |
33514
+ exports.EnumAstNodeStatus.Malformed)) {
33255
33515
  invalidNodes.push(node);
33256
33516
  }
33257
33517
  stats.nodesCount++;
@@ -33269,11 +33529,11 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
33269
33529
  context.chi.push(node);
33270
33530
  node[PARENT] = context;
33271
33531
  node[ROOT] = context[ROOT];
33272
- if (node[STATE] == exports.EnumAstNodeStatus.Invalid ||
33273
- node[STATE] == exports.EnumAstNodeStatus.Disallowed ||
33274
- node[STATE] == exports.EnumAstNodeStatus.Unknown ||
33275
- node[STATE] == exports.EnumAstNodeStatus.Unparsed ||
33276
- node[STATE] == exports.EnumAstNodeStatus.Malformed) {
33532
+ if (node[STATE] & exports.EnumAstNodeStatus.Invalid ||
33533
+ node[STATE] & exports.EnumAstNodeStatus.Disallowed ||
33534
+ node[STATE] & exports.EnumAstNodeStatus.Unknown ||
33535
+ node[STATE] & exports.EnumAstNodeStatus.Unparsed ||
33536
+ node[STATE] & exports.EnumAstNodeStatus.Malformed) {
33277
33537
  invalidNodes.push(node);
33278
33538
  }
33279
33539
  return node;
@@ -33283,7 +33543,9 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
33283
33543
  node[PARENT] = context;
33284
33544
  node[ROOT] = context[ROOT];
33285
33545
  if (context.typ === exports.EnumToken.StyleSheetNodeType && node.typ === exports.EnumToken.DeclarationNodeType) {
33286
- node[STATE] = exports.EnumAstNodeStatus.Invalid;
33546
+ node[STATE] |=
33547
+ exports.EnumAstNodeStatus.Invalid &
33548
+ ~(exports.EnumAstNodeStatus.Validated | exports.EnumAstNodeStatus.Unvalidated | exports.EnumAstNodeStatus.Unparsed);
33287
33549
  errors.push({
33288
33550
  message: "<declaration> not allowed in <stylesheet>",
33289
33551
  action: "drop",
@@ -33294,11 +33556,12 @@ function parseNode(tokens, context, options, errors, stats, invalidNodes) {
33294
33556
  else if (options.lenient || node.typ === exports.EnumToken.DeclarationNodeType) {
33295
33557
  context.chi.push(node);
33296
33558
  }
33297
- if (node[STATE] == exports.EnumAstNodeStatus.Invalid ||
33298
- node[STATE] == exports.EnumAstNodeStatus.Disallowed ||
33299
- node[STATE] == exports.EnumAstNodeStatus.Unknown ||
33300
- node[STATE] == exports.EnumAstNodeStatus.Unparsed ||
33301
- node[STATE] == exports.EnumAstNodeStatus.Malformed) {
33559
+ if (node[STATE] &
33560
+ (exports.EnumAstNodeStatus.Invalid |
33561
+ exports.EnumAstNodeStatus.Disallowed |
33562
+ exports.EnumAstNodeStatus.Unknown |
33563
+ exports.EnumAstNodeStatus.Unparsed |
33564
+ exports.EnumAstNodeStatus.Malformed)) {
33302
33565
  invalidNodes.push(node);
33303
33566
  }
33304
33567
  }
@@ -33323,7 +33586,6 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
33323
33586
  const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
33324
33587
  const blockAllowed = syntaxRules?.getBlockRules() != null;
33325
33588
  if (syntaxRules == null) {
33326
- // if (!options.lenient) {
33327
33589
  errors.push({
33328
33590
  action: "drop",
33329
33591
  node: atRule,
@@ -34040,7 +34302,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
34040
34302
  stream[index][LOCEND] = stream[i][LOCEND];
34041
34303
  Object.assign(stream[index], {
34042
34304
  typ: tokensfuncDefMap.get(stream[index].typ),
34043
- chi: stream.splice(index + 1, i - index - 1),
34305
+ chi: trimWhiteSpaceTokens(stream.splice(index + 1, i - index - 1)),
34044
34306
  });
34045
34307
  i = index;
34046
34308
  stream.splice(index + 1, 1);
@@ -34512,6 +34774,8 @@ function setNodeProperty(node, key, value) {
34512
34774
  }
34513
34775
  }
34514
34776
 
34777
+ var version = "1.6.8";
34778
+
34515
34779
  /**
34516
34780
  * Load file or url
34517
34781
  * @param url
@@ -34995,5 +35259,6 @@ exports.setNodeProperty = setNodeProperty;
34995
35259
  exports.transform = transform;
34996
35260
  exports.transformFile = transformFile;
34997
35261
  exports.transformSync = transformSync;
35262
+ exports.version = version;
34998
35263
  exports.walk = walk;
34999
35264
  exports.walkValues = walkValues;