@tbela99/css-parser 1.6.3 → 1.6.4

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 (36) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +8 -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 +676 -459
  6. package/dist/index.cjs +676 -459
  7. package/dist/index.d.ts +9 -4
  8. package/dist/lib/ast/expand.js +1 -1
  9. package/dist/lib/ast/features/if.js +1 -1
  10. package/dist/lib/ast/features/inlinecssvariables.js +1 -1
  11. package/dist/lib/ast/features/prefix.js +1 -1
  12. package/dist/lib/ast/features/shorthand.js +10 -5
  13. package/dist/lib/ast/features/transform.js +1 -1
  14. package/dist/lib/ast/minify.js +1 -1
  15. package/dist/lib/ast/transform/utils.js +2 -2
  16. package/dist/lib/ast/walk.js +108 -90
  17. package/dist/lib/parser/declaration/list.js +19 -26
  18. package/dist/lib/parser/declaration/map.js +152 -33
  19. package/dist/lib/parser/parse.js +7 -7
  20. package/dist/lib/parser/source.js +2 -2
  21. package/dist/lib/parser/utils/config.js +1 -1
  22. package/dist/lib/parser/utils/declaration.js +0 -18
  23. package/dist/lib/parser/utils/hash.js +10 -5
  24. package/dist/lib/parser/utils/selector.js +1 -1
  25. package/dist/lib/{renderer → printer}/render.js +15 -15
  26. package/dist/lib/syntax/color/lch.js +0 -1
  27. package/dist/lib/syntax/color/oklch.js +0 -1
  28. package/dist/lib/syntax/color/xyzd50.js +0 -17
  29. package/dist/lib/syntax/constants.js +1 -1
  30. package/dist/lib/validation/config.js +5 -33
  31. package/dist/lib/validation/match.js +50 -180
  32. package/dist/node.js +3 -3
  33. package/dist/web.js +3 -3
  34. package/package.json +2 -2
  35. /package/dist/lib/{renderer → printer}/sourcemap/lib/codec.js +0 -0
  36. /package/dist/lib/{renderer → printer}/sourcemap/sourcemap.js +0 -0
@@ -2,10 +2,11 @@ import { eq } from '../utils/eq.js';
2
2
  import { getConfig } from '../utils/config.js';
3
3
  import { matchType } from '../utils/type.js';
4
4
  import { EnumToken } from '../../ast/types.js';
5
- import { renderValue } from '../../renderer/render.js';
5
+ import { renderValue } from '../../printer/render.js';
6
6
  import { parseString } from '../parse.js';
7
7
  import { PropertySet } from './set.js';
8
8
  import { PROPERTYNAME } from '../../syntax/constants.js';
9
+ import { cloneNode } from '../../ast/clone.js';
9
10
 
10
11
  const propertiesConfig = getConfig();
11
12
  class PropertyMap {
@@ -184,18 +185,50 @@ class PropertyMap {
184
185
  return this;
185
186
  }
186
187
  [Symbol.iterator]() {
188
+ const propertiesMapping = { ...this.config.properties };
189
+ const patterns = this.config.pattern.split(" ");
190
+ let hasMapping = false;
187
191
  let iterable;
188
192
  let requiredCount = 0;
189
193
  let property;
190
194
  let isShorthand = true;
191
- for (property of Object.keys(this.config.properties)) {
192
- if (this.config.properties[property].required) {
193
- if (!this.declarations.has(property)) {
195
+ let declarations = this.declarations;
196
+ for (const key of declarations.keys()) {
197
+ if (declarations.has(key) && declarations.get(key) instanceof PropertyMap) {
198
+ hasMapping = true;
199
+ break;
200
+ }
201
+ }
202
+ if (hasMapping) {
203
+ const mapped = {};
204
+ for (const key of declarations.keys()) {
205
+ const value = declarations.get(key);
206
+ if (value instanceof PropertyMap) {
207
+ for (const [k, v] of value.declarations) {
208
+ mapped[k] = v;
209
+ }
210
+ }
211
+ else {
212
+ mapped[key] = value;
213
+ }
214
+ }
215
+ if (patterns.length === Object.keys(mapped).length) {
216
+ declarations = new Map();
217
+ for (const key of patterns) {
218
+ if (mapped[key] != null) {
219
+ declarations.set(key, mapped[key]);
220
+ }
221
+ }
222
+ }
223
+ }
224
+ for (property of Object.keys(propertiesMapping)) {
225
+ if (propertiesMapping[property].required) {
226
+ if (!declarations.has(property)) {
194
227
  isShorthand = false;
195
228
  break;
196
229
  }
197
230
  else {
198
- const val = (this.declarations.get(property));
231
+ const val = declarations.get(property);
199
232
  if (val instanceof PropertySet && !val.isShortHand()) {
200
233
  isShorthand = false;
201
234
  break;
@@ -207,10 +240,10 @@ class PropertyMap {
207
240
  }
208
241
  }
209
242
  if (requiredCount === 0) {
210
- requiredCount = this.declarations.size;
243
+ requiredCount = declarations.size;
211
244
  }
212
245
  if (!isShorthand || requiredCount < this.requiredCount) {
213
- if (isShorthand && this.declarations.has(this.config.shorthand)) {
246
+ if (isShorthand && declarations.has(this.config.shorthand)) {
214
247
  const cache = new Map();
215
248
  const removeDefaults = (declaration) => {
216
249
  let i;
@@ -285,8 +318,8 @@ class PropertyMap {
285
318
  }
286
319
  return declaration;
287
320
  };
288
- const values = [...this.declarations.values()].reduce((acc, curr) => {
289
- if (curr instanceof PropertySet) {
321
+ const values = [...declarations.values()].reduce((acc, curr) => {
322
+ if (curr instanceof PropertySet || curr instanceof PropertyMap) {
290
323
  for (const declaration of curr) {
291
324
  acc.push(declaration);
292
325
  }
@@ -326,13 +359,13 @@ class PropertyMap {
326
359
  }
327
360
  return (filtered.length > 0 ? filtered : values)[Symbol.iterator]();
328
361
  }
329
- for (const declaration of this.declarations.values()) {
330
- if (declaration instanceof PropertySet) {
362
+ for (const declaration of declarations.values()) {
363
+ if (declaration instanceof PropertySet || declaration instanceof PropertyMap) {
331
364
  continue;
332
365
  }
333
366
  const config = declaration.nam == this.config.shorthand
334
367
  ? this.config
335
- : (this.config.properties[declaration.nam] ?? this.config);
368
+ : (propertiesMapping[declaration.nam] ?? this.config);
336
369
  if (!("mapping" in config)) {
337
370
  continue;
338
371
  }
@@ -349,7 +382,7 @@ class PropertyMap {
349
382
  }
350
383
  }
351
384
  // @ts-ignore
352
- iterable = this.declarations.values();
385
+ iterable = declarations.values();
353
386
  }
354
387
  else {
355
388
  let count = 0;
@@ -363,19 +396,19 @@ class PropertyMap {
363
396
  : null;
364
397
  const tokens = {};
365
398
  // @ts-ignore
366
- Object.entries(this.config.properties).reduce((acc, curr) => {
367
- if (!this.declarations.has(curr[0])) {
399
+ Object.entries(propertiesMapping).reduce((acc, curr) => {
400
+ if (!declarations.has(curr[0])) {
368
401
  if (curr[1].required) {
369
402
  acc.push(curr[0]);
370
403
  }
371
404
  return acc;
372
405
  }
373
406
  let current = 0;
374
- const props = this.config.properties[curr[0]];
375
- const properties = (this.declarations.get(curr[0]));
376
- for (const declaration of [
377
- properties instanceof PropertySet ? [...properties][0] : properties,
378
- ]) {
407
+ const props = propertiesMapping[curr[0]];
408
+ const properties = (declarations.get(curr[0]));
409
+ for (const declaration of properties instanceof PropertySet || properties instanceof PropertyMap
410
+ ? [...properties].flat()
411
+ : [properties]) {
379
412
  // @ts-ignore
380
413
  for (const val of declaration.val) {
381
414
  // @ts-ignore
@@ -422,9 +455,45 @@ class PropertyMap {
422
455
  }
423
456
  return acc;
424
457
  }, []);
458
+ // grid-template
459
+ if (this.config.shorthand == "grid-template" && patterns.length == Object.keys(tokens).length) {
460
+ const k = tokens[patterns[0]][0].length;
461
+ const l = tokens[patterns[1]][0].length;
462
+ const j = k < l ? k : l;
463
+ const result = [];
464
+ let i;
465
+ for (i = 0; i < j; i++) {
466
+ if (i < k) {
467
+ result.push(tokens[patterns[0]][0][i]);
468
+ }
469
+ if (i < l) {
470
+ result.push(tokens[patterns[1]][0][i]);
471
+ }
472
+ }
473
+ if (j < k) {
474
+ result.push(...tokens[patterns[0]][0].slice(j));
475
+ }
476
+ if (j < l) {
477
+ result.push(...tokens[patterns[1]][0].slice(j));
478
+ }
479
+ const separator = this.config.properties[patterns[2]]?.prefix;
480
+ result.push(
481
+ // @ts-ignore
482
+ { ...separator, typ: EnumToken[separator.typ] }, ...tokens[patterns[2]][0].reduce((acc, curr) => {
483
+ if (acc.length > 0) {
484
+ acc.push({ typ: EnumToken.WhitespaceTokenType });
485
+ }
486
+ acc.push(curr);
487
+ return acc;
488
+ }, []));
489
+ const declaration = cloneNode(declarations.get(patterns[0]));
490
+ declaration.nam = this.config.shorthand;
491
+ declaration.val = result;
492
+ return [declaration][Symbol.iterator]();
493
+ }
425
494
  count++;
426
495
  if (!isShorthand ||
427
- Object.entries(this.config.properties).some((entry) => {
496
+ Object.entries(propertiesMapping).some((entry) => {
428
497
  // missing required property
429
498
  return entry[1].required && !(entry[0] in tokens);
430
499
  }) ||
@@ -433,27 +502,74 @@ class PropertyMap {
433
502
  // @ts-expect-error
434
503
  v.filter((t) => t.typ != EnumToken.CommentTokenType).length === count)) {
435
504
  // @ts-ignore
436
- iterable = this.declarations.values();
505
+ iterable = declarations.values();
506
+ }
507
+ else if (hasMapping) {
508
+ if (patterns.length == Object.keys(tokens).length) {
509
+ const declaration = cloneNode(declarations.get(patterns[0]));
510
+ declaration.nam = this.config.shorthand;
511
+ for (let i = 0; i < patterns.length; i++) {
512
+ if (declaration.val.length > 0) {
513
+ declaration.val.push(
514
+ // @ts-ignore
515
+ this.config.separator != null
516
+ ? {
517
+ ...this.config.separator,
518
+ typ: EnumToken[this.config.separator.typ],
519
+ }
520
+ : { typ: EnumToken.WhitespaceTokenType });
521
+ }
522
+ declaration.val.push(...tokens[patterns[i]].reduce((acc, curr) => {
523
+ if (acc.length > 0) {
524
+ acc.push({ typ: EnumToken.WhitespaceTokenType });
525
+ }
526
+ acc.push(...curr.reduce((acc, curr) => {
527
+ if (acc.length > 0) {
528
+ acc.push({ typ: EnumToken.WhitespaceTokenType });
529
+ }
530
+ acc.push(curr);
531
+ return acc;
532
+ }, []));
533
+ return acc;
534
+ }, []));
535
+ }
536
+ return [declaration][Symbol.iterator]();
537
+ }
538
+ iterable = declarations.values();
437
539
  }
438
540
  else {
439
541
  let values = Object.entries(tokens)
440
542
  .reduce((acc, curr) => {
441
- const props = this.config.properties[curr[0]];
543
+ const props = propertiesMapping[curr[0]];
442
544
  for (let i = 0; i < curr[1].length; i++) {
443
545
  if (acc.length == i) {
444
546
  acc.push([]);
445
547
  }
446
- let values = curr[1][i].reduce((acc, curr) => {
447
- if (acc.length > 0) {
448
- acc.push({ typ: EnumToken.WhitespaceTokenType });
449
- }
450
- acc.push(curr);
451
- return acc;
452
- }, []);
548
+ // if (acc[acc.length - 1].length > 0) {
549
+ // acc[acc.length - 1].push(
550
+ // // @ts-ignore
551
+ // this.config.separator != null ?
552
+ // {
553
+ // ...this.config.separator,
554
+ // typ: EnumToken[this.config.separator.typ as keyof typeof EnumToken],
555
+ // } : <Token>{ typ: EnumToken.WhitespaceTokenType },
556
+ // )
557
+ // }
558
+ let values = curr[1][i];
559
+ // .reduce(
560
+ // (acc, curr) => {
561
+ // // if (acc.length > 0) {
562
+ // // acc.push(<Token>{ typ: EnumToken.WhitespaceTokenType });
563
+ // // }
564
+ // acc.push(curr);
565
+ // return acc;
566
+ // },
567
+ // <Token[]>[],
568
+ // );
453
569
  if (props.default.includes(curr[1][i]
454
570
  .reduce((acc, curr) => acc + renderValue(curr) + " ", "")
455
571
  .trimEnd())) {
456
- if (!this.config.properties[curr[0]].required) {
572
+ if (!propertiesMapping[curr[0]].required) {
457
573
  continue;
458
574
  }
459
575
  }
@@ -467,7 +583,7 @@ class PropertyMap {
467
583
  EnumToken.IdenTokenType,
468
584
  ].includes(v.typ) ||
469
585
  (v.typ == EnumToken.IdenTokenType &&
470
- !this.config.properties[curr[0]].default.includes(v.val))) {
586
+ !propertiesMapping[curr[0]].default.includes(v.val))) {
471
587
  doFilterDefault = false;
472
588
  break;
473
589
  }
@@ -484,7 +600,7 @@ class PropertyMap {
484
600
  props.default.includes(val.val)));
485
601
  });
486
602
  if (filtered.length > 0 ||
487
- !(this.requiredCount == requiredCount && this.config.properties[curr[0]].required)) {
603
+ !(this.requiredCount == requiredCount && propertiesMapping[curr[0]].required)) {
488
604
  values = filtered;
489
605
  }
490
606
  if (values.length > 0) {
@@ -509,6 +625,7 @@ class PropertyMap {
509
625
  acc[i].push({ ...props.prefix, typ: EnumToken[props.prefix.typ] });
510
626
  }
511
627
  else if (acc[i].length > 0) {
628
+ // @ts-ignore
512
629
  acc[i].push({ typ: EnumToken.WhitespaceTokenType });
513
630
  }
514
631
  for (const v of values.reduce((acc, curr) => {
@@ -550,6 +667,8 @@ class PropertyMap {
550
667
  }
551
668
  return acc;
552
669
  }, []);
670
+ // console.error({hasMapping, shorthand: this.config.shorthand, requiredCount, isShorthand,
671
+ // declarations: declarations.values(), values});
553
672
  if (this.config.mapping != null) {
554
673
  const val = values.reduce((acc, curr) => acc +
555
674
  renderValue(curr, {
@@ -1,6 +1,6 @@
1
1
  import { isIdentColor, parseColor, isColor } from '../syntax/syntax.js';
2
2
  import { camelize, equalsIgnoreCase, dasherize } from './utils/text.js';
3
- import { renderValue } from '../renderer/render.js';
3
+ import { renderValue } from '../printer/render.js';
4
4
  import { EnumToken, EnumAstNodeStatus, ModuleCaseTransformEnum, ModuleScopeEnumOptions } from '../ast/types.js';
5
5
  import { minify } from '../ast/minify.js';
6
6
  import { expand } from '../ast/expand.js';
@@ -2760,7 +2760,7 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2760
2760
  atRule[LOCEND] = (stream.at(-1) ?? atRule)[LOCEND];
2761
2761
  // @ts-expect-error
2762
2762
  return Object.assign(atRule, {
2763
- typ: success ? EnumToken.AtRuleNodeType : EnumToken.InvalidRuleNodeType,
2763
+ typ: EnumToken.AtRuleNodeType,
2764
2764
  val: renderTokens(trimArray(stream), options),
2765
2765
  });
2766
2766
  }
@@ -2768,12 +2768,12 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
2768
2768
  return null;
2769
2769
  }
2770
2770
  atRule[TOKENS] = stream;
2771
- atRule[STATE] = EnumAstNodeStatus.Validated;
2771
+ atRule[STATE] = success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.Invalid;
2772
2772
  atRule[ERRORS] = [];
2773
2773
  atRule[LOCEND] = (stream.at(-1) ?? atRule)[LOCEND];
2774
2774
  // @ts-expect-error
2775
2775
  return Object.assign(atRule, {
2776
- typ: success ? EnumToken.AtRuleNodeType : EnumToken.InvalidRuleNodeType,
2776
+ typ: EnumToken.AtRuleNodeType,
2777
2777
  val: renderTokens(trimArray(stream), options),
2778
2778
  });
2779
2779
  }
@@ -3331,9 +3331,9 @@ function parseAtRule(stream, context, options, errors, parseAsBlock = null) {
3331
3331
  let result = null;
3332
3332
  if (syntax == null) {
3333
3333
  // check matching '(' and ')'
3334
- // check commas , or ,,
3335
- // check colon :
3336
- // check or and and
3334
+ // check commas ',' or ',,'
3335
+ // check colon ':'
3336
+ // check 'or' and 'and'
3337
3337
  result = matchGenericSyntax(stream, options);
3338
3338
  if (result.errors.length > 0) {
3339
3339
  for (const error of result.errors) {
@@ -1,4 +1,4 @@
1
- import { SourceMap } from '../renderer/sourcemap/sourcemap.js';
1
+ import { SourceMap } from '../printer/sourcemap/sourcemap.js';
2
2
  import { LineMap } from './linesmap.js';
3
3
 
4
4
  /**
@@ -9,7 +9,6 @@ let sourceId = 0;
9
9
  * Source file helper class
10
10
  */
11
11
  class SourceFile {
12
- inputSourceMap = null;
13
12
  /**
14
13
  * Source file ID
15
14
  */
@@ -26,6 +25,7 @@ class SourceFile {
26
25
  * Source file content
27
26
  */
28
27
  content;
28
+ inputSourceMap = null;
29
29
  /**
30
30
  * Constructor
31
31
  * @param content
@@ -1,4 +1,4 @@
1
- import config from '../../data/properties.json.js';
1
+ import config from '../../../data/properties.json.js';
2
2
 
3
3
  Object.freeze(config);
4
4
  // @ts-expect-error
@@ -294,24 +294,6 @@ function parseDeclaration(tokens, parent, options, errors) {
294
294
  if (tokens[index].chi[l].typ === EnumToken.StringTokenType) {
295
295
  break;
296
296
  }
297
- // else if ((tokens[index] as FunctionToken).chi[l].typ === EnumToken.IdenTokenType) {
298
- // let m: number = l + 1;
299
- // while (
300
- // (tokens[index] as FunctionToken).chi[m]?.typ === EnumToken.ClassSelectorTokenType
301
- // ) {
302
- // Object.assign((tokens[index] as FunctionToken).chi[l], {
303
- // typ: EnumToken.UrlTokenTokenType,
304
- // val:
305
- // ((tokens[index] as FunctionToken).chi[l] as IdentToken | UrlToken).val +
306
- // ((tokens[index] as FunctionToken).chi[m] as ClassSelectorToken).val,
307
- // });
308
- // (tokens[index] as FunctionToken).chi[l][LOCEND] = (
309
- // tokens[index] as FunctionToken
310
- // ).chi[m][LOCEND];
311
- // (tokens[index] as FunctionToken).chi.splice(m, 1);
312
- // }
313
- // break;
314
- // }
315
297
  }
316
298
  if (tokens[index].chi[l]?.typ === EnumToken.StringTokenType &&
317
299
  /^[a-zA-Z0-0/_.-]+$/.test(tokens[index].chi[l].val.slice(1, -1))) {
@@ -47,12 +47,17 @@ function toSortedString(input) {
47
47
  return String(input);
48
48
  }
49
49
  if (Array.isArray(input)) {
50
- return JSON.stringify(input.map(toSortedString));
50
+ const result = new Array(input.length);
51
+ for (const value of input) {
52
+ result.push(toSortedString(value));
53
+ }
54
+ return JSON.stringify(result);
55
+ }
56
+ const keys = Object.keys(input).sort();
57
+ for (let i = 0; i < keys.length; i++) {
58
+ keys[i] = `${keys[i]}:${toSortedString(input[keys[i]])}`;
51
59
  }
52
- return `{${Object.keys(input)
53
- .sort()
54
- .map((k) => `${k}:${toSortedString(input[k])}`)
55
- .join(",")}}`;
60
+ return `{${keys.join(",")}}`;
56
61
  }
57
62
  /**
58
63
  * Object hash
@@ -1,5 +1,5 @@
1
1
  import { EnumToken, EnumAstNodeStatus } from '../../ast/types.js';
2
- import { renderValue } from '../../renderer/render.js';
2
+ import { renderValue } from '../../printer/render.js';
3
3
  import { LOCEND, LOCSTA, LOCSRCID, ERRORS, STATE, TOKENS, pseudoElements, combinators, tokensfuncDefMap, PARENT } from '../../syntax/constants.js';
4
4
  import { isHash } from '../../syntax/syntax.js';
5
5
  import { getParsedSyntax, getSyntaxRule, getSyntaxConfig } from '../../validation/config.js';
@@ -105,7 +105,7 @@ function doRender(data, options = {}, mapping) {
105
105
  }
106
106
  return acc + curr.val;
107
107
  }
108
- return acc + renderValue(curr, options, cache, reducer, errors);
108
+ return acc + renderValue(curr, options, cache, reducer);
109
109
  }, cache),
110
110
  errors,
111
111
  stats: {
@@ -415,7 +415,7 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
415
415
  }
416
416
  return acc + curr.val;
417
417
  }
418
- return acc + renderValue(curr, options, cache, reducer, errors);
418
+ return acc + renderValue(curr, options, cache, reducer);
419
419
  };
420
420
  }
421
421
  switch (token.typ) {
@@ -1293,22 +1293,22 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
1293
1293
  return token.val;
1294
1294
  case EnumToken.SupportsQueryUnaryConditionTokenType:
1295
1295
  case EnumToken.WhenElseUnaryConditionTokenType:
1296
- return (renderValue(token.l, options, cache, reducer, errors) +
1296
+ return (renderValue(token.l, options, cache, reducer) +
1297
1297
  " " +
1298
- token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer, errors), ""));
1298
+ token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
1299
1299
  case EnumToken.SupportsQueryConditionTokenType:
1300
1300
  case EnumToken.WhenElseQueryConditionTokenType:
1301
- return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer, errors), "") +
1301
+ return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
1302
1302
  " " +
1303
- renderValue(token.op, options, cache, reducer, errors) +
1303
+ renderValue(token.op, options, cache, reducer) +
1304
1304
  " " +
1305
- token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer, errors), ""));
1305
+ token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), ""));
1306
1306
  case EnumToken.IfConditionTokenType:
1307
1307
  return token.l.length == 0
1308
1308
  ? ""
1309
- : token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer, errors), "") +
1309
+ : token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
1310
1310
  ":" +
1311
- token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer, errors), "");
1311
+ token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "");
1312
1312
  case EnumToken.IfElseConditionTokenType:
1313
1313
  return renderValue(token.l) + renderValue(token.r);
1314
1314
  case EnumToken.DeclarationNodeType:
@@ -1316,7 +1316,7 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
1316
1316
  ":" +
1317
1317
  (options.minify ? filterValues(token.val) : token.val).reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
1318
1318
  case EnumToken.MediaQueryUnaryFeatureTokenType:
1319
- return (renderValue(token.l, options, cache, reducer, errors) +
1319
+ return (renderValue(token.l, options, cache, reducer) +
1320
1320
  " " +
1321
1321
  token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
1322
1322
  case EnumToken.MediaQueryConditionTokenType: {
@@ -1328,16 +1328,16 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
1328
1328
  token.op.typ == EnumToken.GteTokenType
1329
1329
  ? ""
1330
1330
  : " ";
1331
- return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer, errors), "") +
1331
+ return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
1332
1332
  indent +
1333
- renderValue(token.op, options, cache, reducer, errors) +
1333
+ renderValue(token.op, options, cache, reducer) +
1334
1334
  indent +
1335
1335
  token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
1336
1336
  }
1337
1337
  case EnumToken.MediaRangeQueryTokenType:
1338
1338
  return (token.l.reduce((acc, curr) => acc + renderValue(curr, options, cache), "") +
1339
1339
  renderValue(token.op1) +
1340
- token.val.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer, errors), "") +
1340
+ token.val.reduce((acc, curr) => acc + renderValue(curr, options, cache, reducer), "") +
1341
1341
  renderValue(token.op2) +
1342
1342
  token.r.reduce((acc, curr) => acc + renderValue(curr, options, cache), ""));
1343
1343
  case EnumToken.MediaFeatureTokenType:
@@ -1362,8 +1362,8 @@ function renderValue(token, options = {}, cache = Object.create(null), reducer,
1362
1362
  console.debug({ token });
1363
1363
  throw new Error(`Unsupported token type for ${EnumToken[token.typ]}`);
1364
1364
  }
1365
- errors?.push({ action: "ignore", message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
1366
- return "";
1365
+ // errors?.push({ action: "ignore", message: `render: unexpected token ${JSON.stringify(token, null, 1)}` });
1366
+ // return "";
1367
1367
  }
1368
1368
  /**
1369
1369
  * Remove whitespace tokens that are not needed
@@ -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] },
@@ -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
@@ -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) => {