@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
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { getColorComponents } from './utils/components.js';
2
9
  import { color2srgbvalues, getNumber, getAngle } from './color.js';
3
10
  import { EnumToken, ColorType } from '../../ast/types.js';
@@ -9,6 +16,7 @@ import { getOKLCHComponents } from './oklch.js';
9
16
  import { XYZ_to_lin_sRGB } from './xyz.js';
10
17
  import { COLORS_NAMES } from '../constants.js';
11
18
  import { parseColor } from '../syntax.js';
19
+ import { hwbvalues } from './hwb.js';
12
20
 
13
21
  // from https://www.w3.org/TR/css-color-4/#color-conversion-code
14
22
  // srgb-linear -> srgb
@@ -83,25 +91,59 @@ function xyz2srgb(x, y, z, alpha = null) {
83
91
  return lsrgb2srgbvalues(values[0], values[1], values[2], alpha);
84
92
  }
85
93
  function hwb2srgbvalues(token) {
86
- const { h: hue, s: white, l: black, a: alpha } = hslvalues(token) ?? {};
87
- if (hue == null || white == null || black == null) {
94
+ const { h, w, b, a } = hwbvalues(token) ?? {};
95
+ if (h == null || w == null || b == null) {
88
96
  return [];
89
97
  }
90
- const rgb = hslvalues2srgbvalues(hue, 1, 0.5);
91
- for (let i = 0; i < 3; i++) {
92
- rgb[i] *= 1 - white - black;
93
- rgb[i] = rgb[i] + white;
94
- }
95
- if (alpha != null && alpha != 1) {
96
- rgb.push(alpha);
98
+ const rgb = hwb2srgb(h, w, b);
99
+ if (a != null && a != 1) {
100
+ rgb.push(a);
97
101
  }
98
102
  return rgb;
99
103
  }
104
+ /**
105
+ * convert hwb to sRGB
106
+ */
107
+ function hwb2srgb(h, w, b, alpha) {
108
+ const wNorm = w / 100;
109
+ const bNorm = b / 100;
110
+ if (wNorm + bNorm >= 1) {
111
+ const gray = wNorm / (wNorm + bNorm);
112
+ return [Math.round(gray * 10000) / 10000, Math.round(gray * 10000) / 10000, Math.round(gray * 10000) / 10000];
113
+ }
114
+ const hPrime = (h % 360) / 60;
115
+ const x = 1 - Math.abs((hPrime % 2) - 1);
116
+ let rChroma = 0;
117
+ let gChroma = 0;
118
+ let bChroma = 0;
119
+ if (hPrime >= 0 && hPrime < 1) {
120
+ [rChroma, gChroma, bChroma] = [1, x, 0];
121
+ }
122
+ else if (hPrime >= 1 && hPrime < 2) {
123
+ [rChroma, gChroma, bChroma] = [x, 1, 0];
124
+ }
125
+ else if (hPrime >= 2 && hPrime < 3) {
126
+ [rChroma, gChroma, bChroma] = [0, 1, x];
127
+ }
128
+ else if (hPrime >= 3 && hPrime < 4) {
129
+ [rChroma, gChroma, bChroma] = [0, x, 1];
130
+ }
131
+ else if (hPrime >= 4 && hPrime < 5) {
132
+ [rChroma, gChroma, bChroma] = [x, 0, 1];
133
+ }
134
+ else if (hPrime >= 5 && hPrime <= 6) {
135
+ [rChroma, gChroma, bChroma] = [1, 0, x];
136
+ }
137
+ const factor = 1 - wNorm - bNorm;
138
+ const srgb = [rChroma * factor + wNorm, gChroma * factor + wNorm, bChroma * factor + wNorm];
139
+ return srgb;
140
+ }
100
141
  function hsl2srgb(token) {
101
142
  let { h, s, l, a } = hslvalues(token) ?? {};
102
143
  if (h == null || s == null || l == null) {
103
144
  return null;
104
145
  }
146
+ // hue in degrees
105
147
  return hslvalues2srgbvalues(h, s, l, a);
106
148
  }
107
149
  function cmyk2srgbvalues(token) {
@@ -162,7 +204,7 @@ function hslvalues(token) {
162
204
  }
163
205
  let t;
164
206
  // @ts-ignore
165
- let h = getAngle(components[0]);
207
+ let h = getAngle(components[0]) * 360;
166
208
  // @ts-ignore
167
209
  t = components[1];
168
210
  // @ts-ignore
@@ -171,6 +213,12 @@ function hslvalues(token) {
171
213
  t = components[2];
172
214
  // @ts-ignore
173
215
  let l = getNumber(t);
216
+ if (components[1].typ == EnumToken.PercentageTokenType) {
217
+ s *= 100;
218
+ }
219
+ if (components[2].typ == EnumToken.PercentageTokenType) {
220
+ l *= 100;
221
+ }
174
222
  let a = null;
175
223
  if (components.length == 4) {
176
224
  // @ts-ignore
@@ -181,56 +229,38 @@ function hslvalues(token) {
181
229
  return a == null ? { h, s, l } : { h, s, l, a };
182
230
  }
183
231
  function hslvalues2srgbvalues(h, s, l, a = null) {
184
- let v = l <= 0.5 ? l * (1.0 + s) : l + s - l * s;
185
- let r = l;
186
- let g = l;
187
- let b = l;
188
- if (v > 0) {
189
- let m = l + l - v;
190
- let sv = (v - m) / v;
191
- h *= 6.0;
192
- let sextant = Math.floor(h);
193
- let fract = h - sextant;
194
- let vsf = v * sv * fract;
195
- let mid1 = m + vsf;
196
- let mid2 = v - vsf;
197
- switch (sextant) {
198
- case 0:
199
- r = v;
200
- g = mid1;
201
- b = m;
202
- break;
203
- case 1:
204
- r = mid2;
205
- g = v;
206
- b = m;
207
- break;
208
- case 2:
209
- r = m;
210
- g = v;
211
- b = mid1;
212
- break;
213
- case 3:
214
- r = m;
215
- g = mid2;
216
- b = v;
217
- break;
218
- case 4:
219
- r = mid1;
220
- g = m;
221
- b = v;
222
- break;
223
- case 5:
224
- r = v;
225
- g = m;
226
- b = mid2;
227
- break;
228
- }
232
+ const sNorm = s / 100;
233
+ const lNorm = l / 100;
234
+ const chroma = (1 - Math.abs(2 * lNorm - 1)) * sNorm;
235
+ const hPrime = h / 60;
236
+ const x = chroma * (1 - Math.abs((hPrime % 2) - 1));
237
+ let rTmp = 0;
238
+ let gTmp = 0;
239
+ let bTmp = 0;
240
+ if (hPrime >= 0 && hPrime < 1) {
241
+ [rTmp, gTmp, bTmp] = [chroma, x, 0];
229
242
  }
230
- const values = [r, g, b];
231
- if (a != null && a != 1) {
243
+ else if (hPrime >= 1 && hPrime < 2) {
244
+ [rTmp, gTmp, bTmp] = [x, chroma, 0];
245
+ }
246
+ else if (hPrime >= 2 && hPrime < 3) {
247
+ [rTmp, gTmp, bTmp] = [0, chroma, x];
248
+ }
249
+ else if (hPrime >= 3 && hPrime < 4) {
250
+ [rTmp, gTmp, bTmp] = [0, x, chroma];
251
+ }
252
+ else if (hPrime >= 4 && hPrime < 5) {
253
+ [rTmp, gTmp, bTmp] = [x, 0, chroma];
254
+ }
255
+ else if (hPrime >= 5 && hPrime <= 6) {
256
+ [rTmp, gTmp, bTmp] = [chroma, 0, x];
257
+ }
258
+ const m = lNorm - chroma / 2;
259
+ const values = [rTmp + m, gTmp + m, bTmp + m];
260
+ if (a != null) {
232
261
  values.push(a);
233
262
  }
263
+ // Return exact float decimals instead of multiplying by 255
234
264
  return values;
235
265
  }
236
266
  function lab2srgbvalues(token) {
@@ -301,4 +331,4 @@ function lsrgb2srgbvalues(r, g, b, alpha = null) {
301
331
  return rgb;
302
332
  }
303
333
 
304
- export { cmyk2srgbvalues, hex2srgbvalues, hsl2srgb, hslvalues, hslvalues2srgbvalues, hwb2srgbvalues, lab2srgbvalues, lch2srgbvalues, lsrgb2srgbvalues, oklab2srgbvalues, oklch2srgbvalues, rgb2srgb, rgb2srgbvalues, srgb2lsrgbvalues, srgbvalues, xyz2srgb };
334
+ export { cmyk2srgbvalues, hex2srgbvalues, hsl2srgb, hslvalues, hslvalues2srgbvalues, hwb2srgb, hwb2srgbvalues, lab2srgbvalues, lch2srgbvalues, lsrgb2srgbvalues, oklab2srgbvalues, oklch2srgbvalues, rgb2srgb, rgb2srgbvalues, srgb2lsrgbvalues, srgbvalues, xyz2srgb };
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { ColorType } from '../../../ast/types.js';
2
9
 
3
10
  /**
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { equalsIgnoreCase } from '../../../parser/utils/text.js';
2
9
  import { getColorComponents } from './components.js';
3
10
 
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { ColorType, EnumToken } from '../../../ast/types.js';
2
9
  import { COLORS_NAMES } from '../../constants.js';
3
10
  import { expandHexValue } from '../hex.js';
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { convertColor } from '../color.js';
2
9
  import { getOKLABComponents } from '../oklab.js';
3
10
  import { ColorType } from '../../../ast/types.js';
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { EnumToken, ColorType } from '../../../ast/types.js';
2
9
  import { equalsIgnoreCase } from '../../../parser/utils/text.js';
3
10
  import { minmax, getNumber } from '../color.js';
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  // from https://www.w3.org/TR/css-color-4/multiply-matrices.js
2
9
  /**
3
10
  * Simple matrix (and vector) multiplication
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { multiplyMatrices } from './utils/matrix.js';
2
9
  import { srgb2lsrgbvalues } from './srgb.js';
3
10
  import { XYZ_D65_to_D50 } from './xyzd50.js';
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { lsrgb2srgbvalues } from './srgb.js';
2
9
  import { multiplyMatrices } from './utils/matrix.js';
3
10
  import { xyz2lab } from './lab.js';
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { EnumToken } from '../ast/types.js';
2
9
  import config from '../../data/validation.json.js';
3
10
 
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { isOkLabClose } from './color/utils/distance.js';
2
9
  import { EnumToken, ColorType } from '../ast/types.js';
3
10
  import { walkValues, WalkerOptionEnum } from '../ast/walk.js';
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import config from '../../data/validation.json.js';
2
9
  import { trimSyntaxArray, parseSyntax } from './parser/parse.js';
3
10
  import { ValidationTokenEnum } from './parser/typedef.js';
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { getParsedSyntax, getSyntaxConfig } from './config.js';
2
9
  import { EnumToken } from '../ast/types.js';
3
10
  import { ValidationSyntaxGroupEnum, ValidationTokenEnum, MediaFeatureType } from './parser/typedef.js';
@@ -126,8 +133,7 @@ function isMFValue(featureName, tokens, isMFRange) {
126
133
  case MediaFeatureType.RatioType:
127
134
  return {
128
135
  valid: true,
129
- success: (tokens.length == 1 &&
130
- tokens[0].typ == EnumToken.NumberTokenType) ||
136
+ success: (tokens.length == 1 && tokens[0].typ == EnumToken.NumberTokenType) ||
131
137
  (tokens.length === 3 &&
132
138
  tokens[0].typ == EnumToken.NumberTokenType &&
133
139
  typeof tokens[0].val === "number" &&
@@ -434,7 +440,7 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
434
440
  }
435
441
  stack.push(token);
436
442
  break;
437
- case EnumToken.Pipe:
443
+ case EnumToken.PipeTokenType:
438
444
  case EnumToken.DelimTokenType:
439
445
  case EnumToken.StringTokenType:
440
446
  case EnumToken.IncludeMatchTokenType:
@@ -482,10 +488,10 @@ function matchSelectorSyntax(stream, errors, options, nested = true) {
482
488
  }
483
489
  slice.push(tokens[n]);
484
490
  }
485
- if (slice[1]?.typ === EnumToken.Pipe) {
491
+ if (slice[1]?.typ === EnumToken.PipeTokenType) {
486
492
  slice.shift();
487
493
  }
488
- if (slice[0].typ === EnumToken.Pipe) {
494
+ if (slice[0].typ === EnumToken.PipeTokenType) {
489
495
  slice.shift();
490
496
  }
491
497
  if (slice.length === 1) {
@@ -847,8 +853,8 @@ function matchSyntax(syntaxes, context, options) {
847
853
  // custom function token
848
854
  if (token.typ === EnumToken.CustomFunctionTokenDefType) {
849
855
  if (syntaxes[i].typ != ValidationTokenEnum.PropertyType ||
850
- syntaxes[i + 1].typ != ValidationTokenEnum.OpenParenthesis ||
851
- syntaxes[i + 2].typ == null) {
856
+ syntaxes[i + 1]?.typ != ValidationTokenEnum.OpenParenthesis ||
857
+ syntaxes[i + 2]?.typ == null) {
852
858
  if (!isOptional) {
853
859
  return {
854
860
  success: false,
@@ -1695,17 +1701,15 @@ function matchProperty(property, context, options) {
1695
1701
  case "display-internal":
1696
1702
  case "display-outside":
1697
1703
  case "display-legacy":
1698
- case "content-position":
1699
- {
1700
- let values = propertyKeywordValues.get(property.val);
1701
- if (values == null) {
1702
- values = new Set(config.syntaxes[property.val].syntax.split(/[\s|]+/));
1703
- propertyKeywordValues.set(property.val, values);
1704
- }
1705
- success =
1706
- token?.typ == EnumToken.IdenTokenType && values.has(token.val.toLowerCase());
1707
- break;
1704
+ case "content-position": {
1705
+ let values = propertyKeywordValues.get(property.val);
1706
+ if (values == null) {
1707
+ values = new Set(config.syntaxes[property.val].syntax.split(/[\s|]+/));
1708
+ propertyKeywordValues.set(property.val, values);
1708
1709
  }
1710
+ success = token?.typ == EnumToken.IdenTokenType && values.has(token.val.toLowerCase());
1711
+ break;
1712
+ }
1709
1713
  case "mf-name":
1710
1714
  {
1711
1715
  const token = context.peek();
@@ -1725,8 +1729,7 @@ function matchProperty(property, context, options) {
1725
1729
  case "custom-ident":
1726
1730
  case "counter-name":
1727
1731
  case "counter-style-name":
1728
- success =
1729
- token?.typ == EnumToken.IdenTokenType || token?.typ == EnumToken.DashedIdenTokenType;
1732
+ success = token?.typ == EnumToken.IdenTokenType || token?.typ == EnumToken.DashedIdenTokenType;
1730
1733
  if (success && token?.typ === EnumToken.IdenTokenType) {
1731
1734
  const val = token.val.toLowerCase();
1732
1735
  success = "none" !== val && !allValues.includes(val);
@@ -2197,6 +2200,21 @@ function matchProperty(property, context, options) {
2197
2200
  }
2198
2201
  break;
2199
2202
  }
2203
+ case "css-type": {
2204
+ success = context.peek()?.typ == EnumToken.CssTypeTokenType;
2205
+ if (success) {
2206
+ context.next();
2207
+ return {
2208
+ success: true,
2209
+ valid: true,
2210
+ token: null,
2211
+ context,
2212
+ syntaxToken: null,
2213
+ errors: [],
2214
+ };
2215
+ }
2216
+ break;
2217
+ }
2200
2218
  default:
2201
2219
  if (!(property.val in config.syntaxes)) {
2202
2220
  console.debug("Unknown syntax", context.peek(), property);
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { EnumToken } from '../../ast/types.js';
2
9
  import { isIdentStart, isIdent, parseDimension, isPseudo } from '../../syntax/syntax.js';
3
10
  import { ValidationTokenEnum } from './typedef.js';
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  var ValidationTokenEnum;
2
9
  (function (ValidationTokenEnum) {
3
10
  ValidationTokenEnum[ValidationTokenEnum["Root"] = 0] = "Root";
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { EnumToken } from '../../ast/types.js';
2
9
 
3
10
  function stripCommaToken(tokenList) {
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { deprecate } from 'node:util';
2
9
  import { Readable } from 'node:stream';
3
10
  import { createReadStream } from 'node:fs';
@@ -26,6 +33,7 @@ export { replaceNodeOrValue } from './lib/parser/utils/token.js';
26
33
  export { SourceMap } from './lib/printer/sourcemap/sourcemap.js';
27
34
  export { FeatureWalkMode } from './lib/ast/features/type.js';
28
35
  export { getNodeProperty, setNodeProperty } from './lib/ast/node.js';
36
+ export { version } from '../package.json.js';
29
37
 
30
38
  /**
31
39
  * Load file or url
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  /**
2
9
  * response type
3
10
  */
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { EnumToken } from '../lib/ast/types.js';
2
9
  import { dirname } from '../lib/fs/resolve.js';
3
10
  import { ResponseType } from '../types.js';
@@ -1,3 +1,10 @@
1
+ /*
2
+ CSS parser, minifier and validator for node and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 1.6.8
6
+ License: MIT
7
+ */
1
8
  import { doParse, doParseSync } from './lib/parser/parse.js';
2
9
  export { parseDeclarations, parseString } from './lib/parser/parse.js';
3
10
  import { doRender } from './lib/printer/render.js';
@@ -21,6 +28,7 @@ export { PropertyList } from './lib/parser/declaration/list.js';
21
28
  export { SourceMap } from './lib/printer/sourcemap/sourcemap.js';
22
29
  export { FeatureWalkMode } from './lib/ast/features/type.js';
23
30
  export { getNodeProperty, setNodeProperty } from './lib/ast/node.js';
31
+ export { version } from '../package.json.js';
24
32
 
25
33
  /**
26
34
  * Load file or url
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@tbela99/css-parser",
3
3
  "description": "CSS parser, minifier and validator for node and the browser",
4
- "version": "1.6.6",
4
+ "version": "1.6.8",
5
5
  "exports": {
6
6
  ".": "./dist/node.js",
7
- "./node": "./dist/node.js",
8
- "./web": "./dist/web.js",
7
+ "./node": "./dist/src/node.js",
8
+ "./web": "./dist/src/web.js",
9
9
  "./cjs": "./dist/index.cjs"
10
10
  },
11
11
  "type": "module",
@@ -68,8 +68,8 @@
68
68
  "@types/chai": "^5.2.3",
69
69
  "@types/chai-as-promised": "^8.0.2",
70
70
  "@types/mocha": "^10.0.10",
71
- "@types/node": "^26.6.4",
72
- "@types/web": "^0.0.357",
71
+ "@types/node": "^26.6.5",
72
+ "@types/web": "^0.0.358",
73
73
  "@web/test-runner": "^1.0.0",
74
74
  "@web/test-runner-playwright": "^1.0.0",
75
75
  "chai": "^6.3.0",
@@ -77,9 +77,10 @@
77
77
  "esno": "^4.8.0",
78
78
  "markdown-it-task-lists": "^2.1.1",
79
79
  "mocha": "^12.0.3",
80
- "playwright": "^1.63.0",
80
+ "playwright": "^1.64.0",
81
81
  "rollup": "^4.63.6",
82
82
  "rollup-plugin-dts": "^6.5.1",
83
+ "rollup-plugin-version-injector": "^1.3.3",
83
84
  "superc8": "^12.7.0",
84
85
  "tslib": "^2.8.1",
85
86
  "typedoc": "^0.28.20",
@@ -1,20 +0,0 @@
1
- function hwb2hsv(h, w, b, a) {
2
- // @ts-ignore
3
- return [h, 1 - w / (1 - b), 1 - b, a];
4
- }
5
- // https://gist.github.com/defims/0ca2ef8832833186ed396a2f8a204117#file-annotated-js
6
- function hsl2hsv(h, s, l, a = null) {
7
- s *= l < .5 ? l : 1 - l;
8
- const result = [
9
- //Range should be between 0 - 1
10
- h, //Hue stays the same
11
- 2 * s / (l + s), //Saturation
12
- l + s //Value
13
- ];
14
- if (a != null) {
15
- result.push(a);
16
- }
17
- return result;
18
- }
19
-
20
- export { hsl2hsv, hwb2hsv };