@tbela99/css-parser 1.6.3 → 1.6.5

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 (46) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +112 -8
  3. package/dist/{lib/data → data}/properties.json.js +296 -29
  4. package/dist/{lib/data → data}/validation.json.js +6 -0
  5. package/dist/index-umd-web.js +962 -744
  6. package/dist/index.cjs +961 -744
  7. package/dist/index.d.ts +24 -6
  8. package/dist/lib/ast/expand.js +1 -1
  9. package/dist/lib/ast/features/calc.js +16 -4
  10. package/dist/lib/ast/features/if.js +2 -2
  11. package/dist/lib/ast/features/inlinecssvariables.js +3 -3
  12. package/dist/lib/ast/features/prefix.js +2 -2
  13. package/dist/lib/ast/features/shorthand.js +8 -6
  14. package/dist/lib/ast/features/transform.js +2 -2
  15. package/dist/lib/ast/math/expression.js +24 -1
  16. package/dist/lib/ast/minify.js +3 -2
  17. package/dist/lib/ast/transform/utils.js +2 -2
  18. package/dist/lib/ast/walk.js +108 -90
  19. package/dist/lib/parser/declaration/list.js +29 -26
  20. package/dist/lib/parser/declaration/map.js +186 -54
  21. package/dist/lib/parser/parse.js +11 -9
  22. package/dist/lib/parser/source.js +2 -2
  23. package/dist/lib/parser/tokenize.js +99 -124
  24. package/dist/lib/parser/utils/config.js +1 -1
  25. package/dist/lib/parser/utils/declaration.js +0 -18
  26. package/dist/lib/parser/utils/hash.js +10 -5
  27. package/dist/lib/parser/utils/selector.js +1 -1
  28. package/dist/lib/{renderer → printer}/render.js +29 -53
  29. package/dist/lib/syntax/color/a98rgb.js +1 -1
  30. package/dist/lib/syntax/color/alpha.js +19 -20
  31. package/dist/lib/syntax/color/color-mix.js +15 -14
  32. package/dist/lib/syntax/color/hex.js +4 -1
  33. package/dist/lib/syntax/color/lch.js +0 -1
  34. package/dist/lib/syntax/color/oklch.js +0 -1
  35. package/dist/lib/syntax/color/relative-color.js +11 -11
  36. package/dist/lib/syntax/color/utils/components.js +0 -20
  37. package/dist/lib/syntax/color/xyzd50.js +0 -17
  38. package/dist/lib/syntax/constants.js +6 -1
  39. package/dist/lib/syntax/syntax.js +2 -2
  40. package/dist/lib/validation/config.js +5 -33
  41. package/dist/lib/validation/match.js +52 -181
  42. package/dist/node.js +3 -3
  43. package/dist/web.js +4 -3
  44. package/package.json +6 -5
  45. /package/dist/lib/{renderer → printer}/sourcemap/lib/codec.js +0 -0
  46. /package/dist/lib/{renderer → printer}/sourcemap/sourcemap.js +0 -0
@@ -42,6 +42,7 @@ function doRender(data, options = {}, mapping) {
42
42
  removeEmpty: false,
43
43
  removeComments: false,
44
44
  }),
45
+ minifyValues: true,
45
46
  sourcemap: false,
46
47
  convertColor: true,
47
48
  expandNestingRules: false,
@@ -105,7 +106,7 @@ function doRender(data, options = {}, mapping) {
105
106
  }
106
107
  return acc + curr.val;
107
108
  }
108
- return acc + renderValue(curr, options, cache, reducer, errors);
109
+ return acc + renderValue(curr, options, cache, reducer);
109
110
  }, cache),
110
111
  errors,
111
112
  stats: {
@@ -281,7 +282,7 @@ function renderAstNode(data, options, sourcemaps, sourceLocation, linesMap, erro
281
282
  const indentSub = indents[level + 1];
282
283
  switch (data.typ) {
283
284
  case EnumToken.DeclarationNodeType:
284
- return `${data.nam}:${options.indent}${(options.minify
285
+ return `${data.nam}:${options.indent}${(options.minifyValues
285
286
  ? filterValues(data.val)
286
287
  : data.val).reduce(reducer, "")}`;
287
288
  case EnumToken.CommentNodeType:
@@ -336,7 +337,7 @@ function renderAstNode(data, options, sourcemaps, sourceLocation, linesMap, erro
336
337
  : node.val;
337
338
  }
338
339
  else if (node.typ == EnumToken.DeclarationNodeType) {
339
- str = `${node.nam}:${options.indent}${(options.minify
340
+ str = `${node.nam}:${options.indent}${(options.minifyValues
340
341
  ? filterValues(node.val)
341
342
  : node.val)
342
343
  .reduce(reducer, "")
@@ -404,9 +405,10 @@ function renderAstNode(data, options, sourcemaps, sourceLocation, linesMap, erro
404
405
  function renderValue(token, options = {}, cache = Object.create(null), reducer, errors) {
405
406
  if (token.typ === EnumToken.WhenElseFunctionTokenType &&
406
407
  equalsIgnoreCase(token.val, "supports")) {
407
- options = { ...options, minify: false, convertColor: false };
408
+ options = { ...options, minifyValues: false, minify: false, convertColor: false };
408
409
  reducer = null;
409
410
  }
411
+ options.minifyValues ??= options.minify;
410
412
  if (reducer == null) {
411
413
  reducer = function (acc, curr) {
412
414
  if (curr.typ == EnumToken.CommentTokenType && options.removeComments) {
@@ -415,7 +417,7 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
415
417
  }
416
418
  return acc + curr.val;
417
419
  }
418
- return acc + renderValue(curr, options, cache, reducer, errors);
420
+ return acc + renderValue(curr, options, cache, reducer);
419
421
  };
420
422
  }
421
423
  switch (token.typ) {
@@ -563,7 +565,7 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
563
565
  ")");
564
566
  }
565
567
  case EnumToken.UrlFunctionTokenType:
566
- if (options.minify && token.typ === EnumToken.UrlFunctionTokenType) {
568
+ if (options.minifyValues && token.typ === EnumToken.UrlFunctionTokenType) {
567
569
  if (token.chi[0]?.typ === EnumToken.BadUrlTokenType) {
568
570
  return "url()";
569
571
  }
@@ -584,7 +586,7 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
584
586
  case EnumToken.FunctionTokenType:
585
587
  case EnumToken.MathFunctionTokenType:
586
588
  case EnumToken.ImageFunctionTokenType:
587
- if (options.minify && token.typ === EnumToken.ImageFunctionTokenType) {
589
+ if (options.minifyValues && token.typ === EnumToken.ImageFunctionTokenType) {
588
590
  const slice = token.chi.slice();
589
591
  switch (token.val) {
590
592
  case "linear-gradient":
@@ -1070,37 +1072,7 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
1070
1072
  renderValue(curr, token.typ == EnumToken.FunctionTokenType ? { minify: false } : options, cache, reducer), "") +
1071
1073
  ")");
1072
1074
  }
1073
- return (
1074
- /* options.minify && 'Pseudo-class-func' == token.typ && token.val.slice(0, 2) == '::' ? token.val.slice(1) :*/ (token.val ?? "") +
1075
- "(" +
1076
- token.chi.reduce(reducer, "") +
1077
- ")");
1078
- // case EnumToken.MatchExpressionTokenType:
1079
- // return (
1080
- // renderValue((token as MatchExpressionToken).l as Token, options, cache, reducer, errors) +
1081
- // renderValue((token as MatchExpressionToken).op, options, cache, reducer, errors) +
1082
- // renderValue((token as MatchExpressionToken).r, options, cache, reducer, errors) +
1083
- // ((token as MatchExpressionToken).attr ? " " + (token as MatchExpressionToken).attr : "")
1084
- // );
1085
- // case EnumToken.NameSpaceAttributeTokenType:
1086
- // return (
1087
- // ((token as NameSpaceAttributeToken).l == null
1088
- // ? ""
1089
- // : renderValue((token as NameSpaceAttributeToken).l as Token, options, cache, reducer, errors)) +
1090
- // "|" +
1091
- // renderValue((token as NameSpaceAttributeToken).r, options, cache, reducer, errors)
1092
- // );
1093
- // case EnumToken.ComposesSelectorNodeType:
1094
- // return (
1095
- // (token as ComposesSelectorToken).l.reduce(
1096
- // (acc: string, curr: Token) => acc + renderValue(curr, options, cache),
1097
- // "",
1098
- // ) +
1099
- // ((token as ComposesSelectorToken).r == null
1100
- // ? ""
1101
- // : " from " +
1102
- // renderValue((token as ComposesSelectorToken).r as Token, options, cache, reducer, errors))
1103
- // );
1075
+ return (token.val ?? "") + "(" + token.chi.reduce(reducer, "") + ")";
1104
1076
  case EnumToken.BlockStartTokenType:
1105
1077
  return "{";
1106
1078
  case EnumToken.BlockEndTokenType:
@@ -1249,7 +1221,11 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
1249
1221
  const perc = token.val.typ == EnumToken.FractionTokenType
1250
1222
  ? renderValue(token.val, options, cache)
1251
1223
  : minifyNumber(token.val);
1252
- return options.minify && perc == "0" ? "0" : perc.includes("/") ? perc.replace("/", uni + "/") : perc + uni;
1224
+ return options.minifyValues && perc == "0"
1225
+ ? "0"
1226
+ : perc.includes("/")
1227
+ ? perc.replace("/", uni + "/")
1228
+ : perc + uni;
1253
1229
  case EnumToken.NumberTokenType:
1254
1230
  return token.val.typ == EnumToken.FractionTokenType
1255
1231
  ? renderValue(token.val, options, cache)
@@ -1293,30 +1269,30 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
1293
1269
  return token.val;
1294
1270
  case EnumToken.SupportsQueryUnaryConditionTokenType:
1295
1271
  case EnumToken.WhenElseUnaryConditionTokenType:
1296
- return (renderValue(token.l, options, cache, reducer, errors) +
1272
+ return (renderValue(token.l, options, cache, reducer) +
1297
1273
  " " +
1298
- token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer, errors), ""));
1274
+ token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
1299
1275
  case EnumToken.SupportsQueryConditionTokenType:
1300
1276
  case EnumToken.WhenElseQueryConditionTokenType:
1301
- return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer, errors), "") +
1277
+ return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
1302
1278
  " " +
1303
- renderValue(token.op, options, cache, reducer, errors) +
1279
+ renderValue(token.op, options, cache, reducer) +
1304
1280
  " " +
1305
- token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer, errors), ""));
1281
+ token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
1306
1282
  case EnumToken.IfConditionTokenType:
1307
1283
  return token.l.length == 0
1308
1284
  ? ""
1309
- : token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer, errors), "") +
1285
+ : token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
1310
1286
  ":" +
1311
- token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer, errors), "");
1287
+ token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "");
1312
1288
  case EnumToken.IfElseConditionTokenType:
1313
1289
  return renderValue(token.l) + renderValue(token.r);
1314
1290
  case EnumToken.DeclarationNodeType:
1315
1291
  return (token.nam +
1316
1292
  ":" +
1317
- (options.minify ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
1293
+ (options.minifyValues ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
1318
1294
  case EnumToken.MediaQueryUnaryFeatureTokenType:
1319
- return (renderValue(token.l, options, cache, reducer, errors) +
1295
+ return (renderValue(token.l, options, cache, reducer) +
1320
1296
  " " +
1321
1297
  token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
1322
1298
  case EnumToken.MediaQueryConditionTokenType: {
@@ -1328,16 +1304,16 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
1328
1304
  token.op.typ == EnumToken.GteTokenType
1329
1305
  ? ""
1330
1306
  : " ";
1331
- return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer, errors), "") +
1307
+ return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
1332
1308
  indent +
1333
- renderValue(token.op, options, cache, reducer, errors) +
1309
+ renderValue(token.op, options, cache, reducer) +
1334
1310
  indent +
1335
1311
  token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
1336
1312
  }
1337
1313
  case EnumToken.MediaRangeQueryTokenType:
1338
1314
  return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache), "") +
1339
1315
  renderValue(token.op1) +
1340
- token.val.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer, errors), "") +
1316
+ token.val.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
1341
1317
  renderValue(token.op2) +
1342
1318
  token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
1343
1319
  case EnumToken.MediaFeatureTokenType:
@@ -1362,8 +1338,8 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
1362
1338
  console.debug({ token });
1363
1339
  throw new Error(`Unsupported token type for ${EnumToken[token.typ]}`);
1364
1340
  }
1365
- errors?.push({ action: "ignore", message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
1366
- return "";
1341
+ // errors?.push({ action: "ignore", message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
1342
+ // return "";
1367
1343
  }
1368
1344
  /**
1369
1345
  * Remove whitespace tokens that are not needed
@@ -37,7 +37,7 @@ function la98rgb2a98rgb(r, g, b, a = null) {
37
37
  // convert an array of linear-light a98-rgb in the range 0.0-1.0
38
38
  // to gamma corrected form
39
39
  // negative values are also now accepted
40
- return [r, b, g]
40
+ return [r, g, b]
41
41
  .map(function (val) {
42
42
  let sign = val < 0 ? -1 : 1;
43
43
  let abs = Math.abs(val);
@@ -24,7 +24,6 @@ function alpha(color, alpha) {
24
24
  }
25
25
  let components = getColorComponents(color);
26
26
  if (alpha.typ === EnumToken.MathFunctionTokenType) {
27
- const originalAlpha = cloneNode(alpha, true);
28
27
  for (const { value } of walkValues(alpha.chi, alpha)) {
29
28
  if (value.typ === EnumToken.IdenTokenType) {
30
29
  if (equalsIgnoreCase(value.val, "alpha")) {
@@ -36,22 +35,22 @@ function alpha(color, alpha) {
36
35
  });
37
36
  // continue;
38
37
  }
39
- else if (equalsIgnoreCase(value.val, "none")) {
40
- Object.assign(value, {
41
- typ: EnumToken.NumberTokenType,
42
- val: 0,
43
- });
44
- }
38
+ // else if (equalsIgnoreCase((value as IdentToken).val, "none")) {
39
+ // Object.assign(value, {
40
+ // typ: EnumToken.NumberTokenType,
41
+ // val: 0,
42
+ // });
43
+ // }
45
44
  }
46
45
  }
47
46
  const result = evaluate([alpha]);
48
47
  if (result.length == 1) {
49
48
  alpha = result[0];
50
49
  }
51
- else {
52
- // @ts-expect-error
53
- alpha = originalAlpha;
54
- }
50
+ // else {
51
+ // // @ts-expect-error
52
+ // alpha = originalAlpha;
53
+ // }
55
54
  }
56
55
  // console.error({ alpha });
57
56
  if (alpha.typ !== EnumToken.IdenTokenType &&
@@ -77,17 +76,17 @@ function alpha(color, alpha) {
77
76
  return null;
78
77
  }
79
78
  if (alpha?.typ === EnumToken.IdenTokenType) {
80
- if (equalsIgnoreCase(alpha.val, "alpha")) {
81
- alpha = components[3] ?? {
82
- typ: EnumToken.NumberTokenType,
83
- val: 1,
84
- };
85
- }
86
- else if (equalsIgnoreCase(alpha.val, "node")) {
87
- alpha = {
79
+ // if (equalsIgnoreCase((alpha as IdentToken).val, "alpha")) {
80
+ // alpha = components[3] ?? {
81
+ // typ: EnumToken.NumberTokenType,
82
+ // val: 1,
83
+ // };
84
+ // } else
85
+ if (equalsIgnoreCase(alpha.val, "none")) {
86
+ Object.assign(alpha, {
88
87
  typ: EnumToken.NumberTokenType,
89
88
  val: 0,
90
- };
89
+ });
91
90
  }
92
91
  }
93
92
  return makeColor(color.kin, components, alpha);
@@ -2,9 +2,7 @@ import { EnumToken, ColorType } from '../../ast/types.js';
2
2
  import { minmax, getNumber } from './color.js';
3
3
  import { srgbvalues, srgb2lsrgbvalues } from './srgb.js';
4
4
  import { srgb2lch, xyz2lchvalues } from './lch.js';
5
- import { srgb2rgb } from './rgb.js';
6
5
  import { srgb2hslvalues } from './hsl.js';
7
- import { srgb2hwb } from './hwb.js';
8
6
  import { srgb2labvalues } from './lab.js';
9
7
  import { srgb2lp3values, srgb2p3values } from './p3.js';
10
8
  import { getColorComponents } from './utils/components.js';
@@ -121,6 +119,9 @@ function colorMix(...args) {
121
119
  if (values == null) {
122
120
  return null;
123
121
  }
122
+ if (colorSpace == "hwb") {
123
+ colorSpace = "srgb";
124
+ }
124
125
  switch (colorSpace) {
125
126
  case "srgb":
126
127
  break;
@@ -150,17 +151,17 @@ function colorMix(...args) {
150
151
  values = srgb2xyz_d65(values[0], values[1], values[2], values[3]);
151
152
  values = XYZ_D65_to_D50(values[0], values[1], values[2], values[3]);
152
153
  break;
153
- case "rgb":
154
- for (let j = 0; j < values.length; j++) {
155
- values[j] = j == 3 ? values[j] : srgb2rgb(values[j]);
156
- }
157
- break;
154
+ // case "rgb":
155
+ // for (let j = 0; j < values.length; j++) {
156
+ // values[j] = j == 3 ? values[j] : srgb2rgb(values[j]);
157
+ // }
158
+ // break;
158
159
  case "hsl":
159
160
  values = srgb2hslvalues(values[0], values[1], values[2], values[3]);
160
161
  break;
161
- case "hwb":
162
- values = srgb2hwb(values[0], values[1], values[2], values[3]);
163
- break;
162
+ // case "hwb":
163
+ // values = srgb2hwb(values[0], values[1], values[2], values[3]);
164
+ // break;
164
165
  case "lab":
165
166
  values = srgb2labvalues(values[0], values[1], values[2], values[3]);
166
167
  break;
@@ -359,14 +360,14 @@ function colorMix(...args) {
359
360
  kin: ColorType.COLOR,
360
361
  cal: "col",
361
362
  };
362
- case "rgb":
363
+ // case "rgb":
363
364
  case "hsl":
364
- case "hwb":
365
+ // case "hwb":
365
366
  case "lab":
366
367
  case "lch":
367
368
  case "oklab":
368
369
  case "oklch":
369
- if (colorSpace == "hsl" || colorSpace == "hwb") {
370
+ if (colorSpace == "hsl") {
370
371
  // @ts-ignore
371
372
  if (values[2] < 0) {
372
373
  // @ts-ignore
@@ -396,7 +397,7 @@ function colorMix(...args) {
396
397
  }),
397
398
  kin: ColorType[colorSpace.toUpperCase().replaceAll("-", "_")],
398
399
  };
399
- if (colorSpace == "hsl" || colorSpace == "hwb") {
400
+ if (colorSpace == "hsl") {
400
401
  // @ts-ignore
401
402
  result.chi[0] = { typ: EnumToken.AngleTokenType, val: result.chi[0].val * 360 };
402
403
  // @ts-ignore
@@ -70,7 +70,10 @@ function color2HexToken(token) {
70
70
  if (value == null) {
71
71
  return null;
72
72
  }
73
- return hexToken(value.reduce((acc, curr) => acc + srgb2rgb(curr + Number.EPSILON).toString(16).padStart(2, "0"), "#"));
73
+ return hexToken(value.reduce((acc, curr) => acc +
74
+ srgb2rgb(curr + Number.EPSILON)
75
+ .toString(16)
76
+ .padStart(2, "0"), "#"));
74
77
  }
75
78
  function oklab2HexToken(token) {
76
79
  let value = oklab2srgbvalues(token);
@@ -68,7 +68,6 @@ function color2lchToken(token) {
68
68
  return lchToken(values);
69
69
  }
70
70
  function lchToken(values) {
71
- values[2] = values[2];
72
71
  const chi = [
73
72
  { typ: EnumToken.NumberTokenType, val: values[0] },
74
73
  { typ: EnumToken.NumberTokenType, val: values[1] },
@@ -66,7 +66,6 @@ function color2oklchToken(token) {
66
66
  return oklchToken(srgb2oklch(values[0], values[1], values[2], values[3]));
67
67
  }
68
68
  function oklchToken(values) {
69
- values[2] = values[2];
70
69
  const chi = [
71
70
  { typ: EnumToken.NumberTokenType, val: values[0] },
72
71
  { typ: EnumToken.NumberTokenType, val: values[1] },
@@ -44,20 +44,20 @@ function parseRelativeColorComponents(relativeKeys, original, rExp, gExp, bExp,
44
44
  continue;
45
45
  }
46
46
  if (component.typ == EnumToken.IdenTokenType) {
47
- val = component.val.toLowerCase();
47
+ val = component.val;
48
48
  if (
49
49
  // @ts-expect-error
50
50
  typeof Math[val.toUpperCase()] !== "number" &&
51
- val != "in" &&
52
- val != "hue" &&
53
- val != "from" &&
54
- val != "alpha" &&
55
- val != "none" &&
56
- val != "shorter" &&
57
- val != "longer" &&
58
- val != "increasing" &&
59
- val != "decreasing" &&
60
- !colorsFunc.includes(val) &&
51
+ !equalsIgnoreCase(val, "in") &&
52
+ !equalsIgnoreCase(val, "hue") &&
53
+ !equalsIgnoreCase(val, "from") &&
54
+ !equalsIgnoreCase(val, "alpha") &&
55
+ !equalsIgnoreCase(val, "none") &&
56
+ !equalsIgnoreCase(val, "shorter") &&
57
+ !equalsIgnoreCase(val, "longer") &&
58
+ !equalsIgnoreCase(val, "increasing") &&
59
+ !equalsIgnoreCase(val, "decreasing") &&
60
+ !colorsFunc.some((t) => equalsIgnoreCase(t, val)) &&
61
61
  !colorFuncColorSpace.includes(val) &&
62
62
  !validKeys.includes(val)) {
63
63
  return null;
@@ -4,13 +4,6 @@ import { expandHexValue } from '../hex.js';
4
4
  import { equalsIgnoreCase } from '../../../parser/utils/text.js';
5
5
 
6
6
  function getColorComponents(token) {
7
- // if (token.typ === EnumToken.IdenTokenType) {
8
- // if (isColor(token)) {
9
- // parseColor(token);
10
- // } else {
11
- // return null;
12
- // }
13
- // }
14
7
  if (token.kin == ColorType.HEX || token.kin == ColorType.LIT) {
15
8
  if (equalsIgnoreCase("currentcolor", token.val)) {
16
9
  return null;
@@ -34,25 +27,12 @@ function getColorComponents(token) {
34
27
  ].includes(child.typ)) {
35
28
  continue;
36
29
  }
37
- // if (child.typ === EnumToken.IdenTokenType && isColor(child)) {
38
- // parseColor(child);
39
- // }
40
30
  if (child.typ === EnumToken.FunctionTokenType ||
41
31
  child.typ === EnumToken.WildCardFunctionTokenType ||
42
32
  child.typ === EnumToken.MathFunctionTokenType) {
43
33
  if ("var" == child.val.toLowerCase()) {
44
34
  return null;
45
35
  }
46
- // else {
47
- // for (const { value } of walkValues((child as FunctionToken).chi)) {
48
- // if (
49
- // value.typ == EnumToken.WildCardFunctionTokenDefType &&
50
- // "var" === (value as FunctionToken).val.toLowerCase()
51
- // ) {
52
- // return null;
53
- // }
54
- // }
55
- // }
56
36
  }
57
37
  if (child.typ == EnumToken.ColorTokenType && equalsIgnoreCase("currentcolor", child.val)) {
58
38
  return null;
@@ -4,23 +4,6 @@ import { xyz2lab } from './lab.js';
4
4
  import { XYZ_D50_to_D65 } from './xyz.js';
5
5
  import { labvalues2lchvalues } from './lch.js';
6
6
 
7
- // export function srgb2xyzd50values(r: number, g: number, b: number, alpha: number | null = null): number[] {
8
- // [r, g, b] = srgb2lsrgbvalues(r, g, b);
9
- //
10
- // const rgb: number[] = [
11
- // 0.436065742824811 * r + 0.3851514688337912 * g + 0.14307845442264197 * b,
12
- //
13
- // 0.22249319175623702 * r + 0.7168870538238823 * g + 0.06061979053616537 * b,
14
- //
15
- // 0.013923904500943465 * r + 0.09708128566574634 * g + 0.7140993584005155 * b,
16
- // ];
17
- //
18
- // if (alpha != null && alpha != 1) {
19
- // rgb.push(alpha);
20
- // }
21
- //
22
- // return rgb;
23
- // }
24
7
  /*
25
8
  */
26
9
  function xyzd502lch(x, y, z, alpha) {
@@ -1,5 +1,5 @@
1
1
  import { EnumToken } from '../ast/types.js';
2
- import config from '../data/validation.json.js';
2
+ import config from '../../data/validation.json.js';
3
3
 
4
4
  /**
5
5
  * Location source id
@@ -67,6 +67,11 @@ const anglePrecision = 3;
67
67
  * Color range definitions
68
68
  */
69
69
  const colorRange = {
70
+ rgb: {
71
+ r: [0, 255],
72
+ g: [0, 255],
73
+ b: [0, 255],
74
+ },
70
75
  lab: {
71
76
  l: [0, 100],
72
77
  a: [-125, 125],
@@ -16,12 +16,12 @@ import { getSyntaxConfig } from '../validation/config.js';
16
16
  // '\\'
17
17
  const REVERSE_SOLIDUS = 0x5c;
18
18
  const flexUnits = ["fr"];
19
- const frequencyUnits = ["hz", "khz"];
19
+ const frequencyUnits = ["Hz", "kHz"];
20
20
  const timeUnits = ["ms", "s"];
21
21
  const angleUnits = ["rad", "turn", "deg", "grad"];
22
22
  const resolutionUnits = ["dpi", "dpcm", "dppx", "x"];
23
23
  const dimensionUnits = [
24
- "q",
24
+ "Q",
25
25
  "cap",
26
26
  "ch",
27
27
  "cm",
@@ -1,4 +1,4 @@
1
- import config from '../data/validation.json.js';
1
+ import config from '../../data/validation.json.js';
2
2
  import { trimSyntaxArray, parseSyntax } from './parser/parse.js';
3
3
  import { ValidationTokenEnum } from './parser/typedef.js';
4
4
  import { memoize } from '../parser/utils/cache.js';
@@ -9,52 +9,24 @@ function getSyntaxConfig() {
9
9
  // @ts-expect-error
10
10
  return config;
11
11
  }
12
- // export const getSyntax = memoize((group: ValidationSyntaxGroupEnum, key: string | string[]): null | string => {
13
- // // @ts-expect-error
14
- // let obj = config[group] as Record<ValidationSyntaxGroupEnum, ValidationSyntaxNode>;
15
- //
16
- // const keys: string[] = Array.isArray(key) ? key : [key];
17
- //
18
- // for (let i = 0; i < keys.length; i++) {
19
- // key = keys[i];
20
- //
21
- // if (!(key in obj)) {
22
- // if ((i == 0 && key.charAt(0) == "@") || key.charAt(0) == "-") {
23
- // const matches: RegExpMatchArray = key.match(/^(@?)(-[a-zA-Z]+)-(.*?)$/) as RegExpMatchArray;
24
- //
25
- // if (matches != null) {
26
- // key = matches[1] + matches[3];
27
- // }
28
- // }
29
- // }
30
- //
31
- // // @ts-expect-error
32
- // obj = obj[key];
33
- // }
34
- //
35
- // // @ts-expect-error
36
- // return obj?.syntax ?? null;
37
- // }) as (group: ValidationSyntaxGroupEnum, key: string | string[]) => null | string;
38
12
  function findNode(group, key) {
39
13
  // @ts-expect-error
40
14
  let obj = config[group];
41
- // const keys: string[] = Array.isArray(key) ? key : [key];
42
- // for (let i = 0; i < keys.length; i++) {
43
- // key = keys[i];
44
- if (!(key in obj)) {
15
+ // @ts-expect-error
16
+ if (obj[key] == null) {
45
17
  if (key.charAt(0) == "@" || key.charAt(0) == "-") {
46
18
  const matches = key.match(/^(@?)(-[a-zA-Z]+)-(.*?)$/);
47
19
  if (matches != null) {
48
20
  key = matches[1] + matches[3];
49
21
  }
50
22
  }
51
- if (!(key in obj)) {
23
+ // @ts-expect-error
24
+ if (obj[key] == null) {
52
25
  return null;
53
26
  }
54
27
  }
55
28
  // @ts-expect-error
56
29
  obj = obj[key];
57
- // }
58
30
  return obj;
59
31
  }
60
32
  const getParsedSyntax = memoize((group, key) => {