@tbela99/css-parser 1.4.6 → 1.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +1 -0
  3. package/dist/index-umd-web.js +6548 -6964
  4. package/dist/index.cjs +7784 -8198
  5. package/dist/index.d.ts +919 -51
  6. package/dist/lib/ast/clone.js +16 -23
  7. package/dist/lib/ast/expand.js +2 -2
  8. package/dist/lib/ast/features/if.js +88 -87
  9. package/dist/lib/ast/features/inlinecssvariables.js +2 -2
  10. package/dist/lib/ast/features/prefix.js +26 -22
  11. package/dist/lib/ast/features/transform.js +3 -3
  12. package/dist/lib/ast/find.js +17 -14
  13. package/dist/lib/ast/minify.js +97 -94
  14. package/dist/lib/ast/types.js +6 -2
  15. package/dist/lib/ast/walk.js +1 -1
  16. package/dist/lib/fs/resolve.js +46 -44
  17. package/dist/lib/parser/declaration/list.js +9 -10
  18. package/dist/lib/parser/declaration/map.js +13 -18
  19. package/dist/lib/parser/parse.js +331 -504
  20. package/dist/lib/parser/tokenize.js +39 -33
  21. package/dist/lib/parser/utils/at-rule-container.js +244 -247
  22. package/dist/lib/parser/utils/at-rule-generic.js +25 -25
  23. package/dist/lib/parser/utils/at-rule-import.js +194 -234
  24. package/dist/lib/parser/utils/at-rule-media.js +286 -286
  25. package/dist/lib/parser/utils/at-rule-support.js +279 -251
  26. package/dist/lib/parser/utils/at-rule-when-else.js +256 -259
  27. package/dist/lib/parser/utils/at-rule.js +19 -16
  28. package/dist/lib/parser/utils/cache.js +33 -5
  29. package/dist/lib/parser/utils/declaration.js +260 -298
  30. package/dist/lib/parser/utils/hash.js +15 -15
  31. package/dist/lib/parser/utils/selector.js +182 -222
  32. package/dist/lib/parser/utils/token.js +4 -7
  33. package/dist/lib/renderer/render.js +150 -120
  34. package/dist/lib/syntax/color/alpha.js +1 -4
  35. package/dist/lib/syntax/color/color.js +5 -5
  36. package/dist/lib/syntax/color/utils/colorspace.js +3 -3
  37. package/dist/lib/syntax/color/utils/components.js +21 -22
  38. package/dist/lib/syntax/color/utils/matrix.js +12 -11
  39. package/dist/lib/syntax/constants.js +22 -3
  40. package/dist/lib/syntax/syntax.js +252 -311
  41. package/dist/lib/validation/config.js +16 -17
  42. package/dist/lib/validation/match.js +1118 -1131
  43. package/dist/lib/validation/parser/parse.js +130 -286
  44. package/dist/node.js +16 -12
  45. package/dist/web.js +10 -8
  46. package/package.json +4 -4
  47. package/dist/lib/validation/utils/whitespace.js +0 -17
@@ -6,7 +6,7 @@ import { EnumToken } from './types.js';
6
6
  import { isWhiteSpace, isIdent, isFunction, isIdentStart } from '../syntax/syntax.js';
7
7
  import { FeatureWalkMode } from './features/type.js';
8
8
  import { trimArray } from '../validation/match.js';
9
- import { definedPropertySettings, combinators } from '../syntax/constants.js';
9
+ import { TOKENS, PARENT, OPTIMIZED, RAW, combinators, LOC } from '../syntax/constants.js';
10
10
  import { replaceNodeOrValue } from '../parser/utils/token.js';
11
11
  import { parseString } from '../parser/parse.js';
12
12
  import { tokenize } from '../parser/tokenize.js';
@@ -71,31 +71,24 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
71
71
  (feature.accept != null && !feature.accept.has(parent.typ))) {
72
72
  continue;
73
73
  }
74
- if (rules.includes(replacement.typ) && !Array.isArray(replacement.tokens)) {
75
- Object.defineProperty(replacement, "tokens", {
76
- ...definedPropertySettings,
77
- value: parseString(replacement.typ == EnumToken.RuleNodeType ||
78
- replacement.typ === EnumToken.KeyFramesRuleNodeType
79
- ? replacement.sel
80
- : replacement.nam),
81
- });
74
+ if (rules.includes(replacement.typ) && !Array.isArray(replacement[TOKENS])) {
75
+ replacement[TOKENS] = parseString(replacement.typ == EnumToken.RuleNodeType || replacement.typ === EnumToken.KeyFramesRuleNodeType
76
+ ? replacement.sel
77
+ : replacement.nam);
82
78
  }
83
- const result = feature.run(replacement, options, parent.parent ?? ast, context, FeatureWalkMode.Pre);
79
+ const result = feature.run(replacement, options, parent[PARENT] ?? ast, context, FeatureWalkMode.Pre);
84
80
  if (result != null) {
85
81
  replacement = result;
86
82
  }
87
83
  }
88
- if (replacement != parent && parent.parent != null) {
89
- // @ts-ignore
90
- replaceNodeOrValue(parent.parent, parent, replacement);
84
+ if (replacement != parent && parent[PARENT] != null) {
85
+ replaceNodeOrValue(parent[PARENT], parent, replacement);
91
86
  }
92
87
  if ("chi" in replacement) {
93
88
  // @ts-ignore
94
89
  for (const node of replacement.chi) {
95
- parents.add(Object.defineProperty(node, "parent", {
96
- ...definedPropertySettings,
97
- value: replacement,
98
- }));
90
+ node[PARENT] = replacement;
91
+ parents.add(node);
99
92
  }
100
93
  }
101
94
  }
@@ -119,22 +112,20 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
119
112
  (feature.accept != null && !feature.accept.has(parent.typ))) {
120
113
  continue;
121
114
  }
122
- const result = feature.run(replacement, options, parent.parent ?? ast, context, FeatureWalkMode.Post);
115
+ const result = feature.run(replacement, options, parent[PARENT] ?? ast, context, FeatureWalkMode.Post);
123
116
  if (result != null) {
124
117
  replacement = result;
125
118
  }
126
119
  }
127
120
  }
128
- if (replacement != null && replacement != parent && parent.parent != null) {
121
+ if (replacement != null && replacement != parent && parent[PARENT] != null) {
129
122
  // @ts-ignore
130
- replaceNodeOrValue(parent.parent, parent, replacement);
123
+ replaceNodeOrValue(parent[PARENT], parent, replacement);
131
124
  }
132
125
  if ("chi" in replacement) {
133
126
  for (const node of replacement.chi) {
134
- parents.add(Object.defineProperty(node, "parent", {
135
- ...definedPropertySettings,
136
- value: replacement,
137
- }));
127
+ node[PARENT] = replacement;
128
+ parents.add(node);
138
129
  }
139
130
  }
140
131
  }
@@ -211,7 +202,7 @@ function transformAtRuleMediaPrelude(values) {
211
202
  },
212
203
  l: val1,
213
204
  r: val2,
214
- loc: value.loc,
205
+ [LOC]: value[LOC],
215
206
  },
216
207
  ],
217
208
  };
@@ -382,12 +373,12 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
382
373
  }
383
374
  else if (node.typ == EnumToken.AtRuleNodeType) {
384
375
  if (node.nam == "media") {
385
- if (Array.isArray(node.tokens)) {
386
- const slice = node.tokens.slice();
376
+ if (Array.isArray(node[TOKENS])) {
377
+ const slice = node[TOKENS].slice();
387
378
  minifyAtRuleMedia(slice);
388
- if (slice.length !== node.tokens.length) {
389
- node.tokens.length = 0;
390
- node.tokens.push(...slice);
379
+ if (slice.length !== node[TOKENS].length) {
380
+ node[TOKENS].length = 0;
381
+ node[TOKENS].push(...slice);
391
382
  node.val = slice.reduce((acc, curr, index, arr) => acc +
392
383
  (curr.typ === EnumToken.CommentTokenType ||
393
384
  (curr.typ === EnumToken.WhitespaceTokenType &&
@@ -403,21 +394,21 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
403
394
  continue;
404
395
  }
405
396
  }
406
- else if (node.nam === "import" && Array.isArray(node.tokens)) {
397
+ else if (node.nam === "import" && Array.isArray(node[TOKENS])) {
407
398
  let l = 0;
408
399
  let token;
409
- for (; l < node.tokens.length; l++) {
410
- token = node.tokens[l];
400
+ for (; l < node[TOKENS].length; l++) {
401
+ token = node[TOKENS][l];
411
402
  if (token.typ === EnumToken.ParensTokenType ||
412
403
  token.typ === EnumToken.MediaQueryConditionTokenType ||
413
404
  (token.typ === EnumToken.IdenTokenType && "layer" !== token.val)) {
414
405
  break;
415
406
  }
416
407
  }
417
- if (l < node.tokens.length) {
418
- const slice = node.tokens?.slice(l);
419
- node.tokens.splice(l, slice.length, ...minifyAtRuleMedia(slice));
420
- node.val = trimArray(node.tokens).reduce((acc, curr, index, arr) => acc +
408
+ if (l < node[TOKENS].length) {
409
+ const slice = node[TOKENS]?.slice(l);
410
+ node[TOKENS].splice(l, slice.length, ...minifyAtRuleMedia(slice));
411
+ node.val = trimArray(node[TOKENS]).reduce((acc, curr, index, arr) => acc +
421
412
  (curr.typ === EnumToken.CommentTokenType ||
422
413
  (curr.typ === EnumToken.WhitespaceTokenType &&
423
414
  arr[index + 1]?.typ === EnumToken.CommentTokenType &&
@@ -457,7 +448,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
457
448
  if (previous?.typ == EnumToken.RuleNodeType) {
458
449
  reduceRuleSelector(previous);
459
450
  // @ts-ignore
460
- match = matchSelectors(previous.raw, node.raw);
451
+ match = matchSelectors(previous[RAW], node[RAW]);
461
452
  if (match != null) {
462
453
  wrapper = wrapNodes(previous, node, match, ast, reducer, i, nodeIndex);
463
454
  nodeIndex = i - 1;
@@ -471,7 +462,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
471
462
  break;
472
463
  }
473
464
  reduceRuleSelector(nextNode);
474
- match = matchSelectors(wrapper.raw, nextNode.raw);
465
+ match = matchSelectors(wrapper[RAW], nextNode[RAW]);
475
466
  if (match == null) {
476
467
  break;
477
468
  }
@@ -483,51 +474,50 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
483
474
  continue;
484
475
  }
485
476
  // @ts-ignore
486
- else if (node.optimized != null &&
487
- // @ts-ignore
488
- node.optimized.match &&
477
+ else if (node[OPTIMIZED] != null &&
489
478
  // @ts-ignore
490
- node.optimized.selector.length > 1) {
479
+ node[OPTIMIZED].match &&
491
480
  // @ts-ignore
492
- wrapper = { ...node, chi: [], sel: node.optimized.optimized[0] };
481
+ node[OPTIMIZED].selector.length > 1) {
493
482
  // @ts-ignore
494
- Object.defineProperty(wrapper, "raw", {
495
- ...definedPropertySettings,
496
- // @ts-ignore
497
- value: [[node.optimized.optimized[0]]],
498
- });
483
+ wrapper = {
484
+ ...node,
485
+ chi: [],
486
+ sel: node[OPTIMIZED].optimized[0],
487
+ [RAW]: [[node[OPTIMIZED].optimized[0]]],
488
+ };
499
489
  // @ts-ignore
500
- node.sel = node.optimized.selector.reduce(reducer, []).join(",");
490
+ node.sel = node[OPTIMIZED].selector.reduce(reducer, []).join(",");
501
491
  // @ts-ignore
502
- node.raw = node.optimized.selector.slice();
492
+ node[RAW] = node[OPTIMIZED].selector.slice();
503
493
  // @ts-ignore
504
494
  wrapper.chi.push(node);
505
495
  // @ts-ignore
506
496
  ast.chi.splice(i, 1, wrapper);
507
497
  node = wrapper;
508
498
  }
509
- else if (node.optimized?.reducible) {
510
- if (node.optimized.optimized.length === 1) {
511
- const sel1 = node.optimized.optimized[0] +
499
+ else if (node[OPTIMIZED]?.reducible) {
500
+ if (node[OPTIMIZED].optimized.length === 1) {
501
+ const sel1 = node[OPTIMIZED].optimized[0] +
512
502
  ":is(" +
513
- node.optimized.selector.reduce(reducer, []).join(",") +
503
+ node[OPTIMIZED].selector.reduce(reducer, []).join(",") +
514
504
  ")";
515
- const sel2 = node.optimized.selector.reduce((acc, curr) => (acc.length > 0 ? acc + "," : "") + node.optimized.optimized[0] + curr.join(""), "");
505
+ const sel2 = node[OPTIMIZED].selector.reduce((acc, curr) => (acc.length > 0 ? acc + "," : "") + node[OPTIMIZED].optimized[0] + curr.join(""), "");
516
506
  node.sel = sel1.length < sel2.length ? sel1 : sel2;
517
507
  }
518
- else if (node.optimized.optimized.length === 0) {
508
+ else if (node[OPTIMIZED].optimized.length === 0) {
519
509
  const testIdent = /^[a-zA-Z]/;
520
- node.sel = node.optimized.selector.reduce((acc, curr) => (acc.length > 0 ? acc + "," : "") +
510
+ node.sel = node[OPTIMIZED].selector.reduce((acc, curr) => (acc.length > 0 ? acc + "," : "") +
521
511
  (nestingContent && testIdent.test(curr[0]) ? "& " : "") +
522
512
  curr.join(""), "");
523
513
  }
524
514
  }
525
515
  }
526
516
  // @ts-ignore
527
- else if (node.optimized?.match) {
517
+ else if (node[OPTIMIZED]?.match) {
528
518
  let wrap = true;
529
519
  // @ts-ignore
530
- const selector = node.optimized.selector.reduce((acc, curr) => {
520
+ const selector = node[OPTIMIZED].selector.reduce((acc, curr) => {
531
521
  if (curr[0] == "&" && curr.length > 1) {
532
522
  if (curr[1] == " ") {
533
523
  curr.splice(0, 2);
@@ -547,7 +537,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
547
537
  wrap = selector.some((s) => s[0] != "&");
548
538
  }
549
539
  let rule = null;
550
- const optimized = node.optimized.optimized.slice();
540
+ const optimized = node[OPTIMIZED].optimized.slice();
551
541
  if (optimized.length > 1) {
552
542
  const check = optimized.at(-2);
553
543
  if (!combinators.includes(check)) {
@@ -572,38 +562,38 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
572
562
  rule = selector
573
563
  .map((s) => {
574
564
  if (s[0] == "&") {
575
- s.splice(0, 1, ...node.optimized.optimized);
565
+ s.splice(0, 1, ...node[OPTIMIZED].optimized);
576
566
  }
577
567
  return s.join("");
578
568
  })
579
569
  .join(",");
580
570
  }
581
- let sel = wrap ? node.optimized.optimized.join("") + `:is(${rule})` : rule;
571
+ let sel = wrap ? node[OPTIMIZED].optimized.join("") + `:is(${rule})` : rule;
582
572
  if (sel.length < node.sel.length) {
583
573
  node.sel = sel;
584
574
  }
585
575
  }
586
- else if (node.optimized?.reducible) {
587
- if (node.optimized.optimized.length === 1) {
588
- const sel1 = node.optimized.optimized[0] +
576
+ else if (node[OPTIMIZED]?.reducible) {
577
+ if (node[OPTIMIZED].optimized.length === 1) {
578
+ const sel1 = node[OPTIMIZED].optimized[0] +
589
579
  ":is(" +
590
- node.optimized.selector.reduce(reducer, []).join(",") +
580
+ node[OPTIMIZED].selector.reduce(reducer, []).join(",") +
591
581
  ")";
592
- const sel2 = node.optimized.selector.reduce((acc, curr) => (acc.length > 0 ? acc + "," : "") + node.optimized.optimized[0] + curr.join(""), "");
582
+ const sel2 = node[OPTIMIZED].selector.reduce((acc, curr) => (acc.length > 0 ? acc + "," : "") + node[OPTIMIZED].optimized[0] + curr.join(""), "");
593
583
  node.sel = sel1.length < sel2.length ? sel1 : sel2;
594
584
  }
595
- else if (node.optimized.optimized.length === 0) {
585
+ else if (node[OPTIMIZED].optimized.length === 0) {
596
586
  const testIdent = /^[a-zA-Z]/;
597
- node.sel = node.optimized.selector.reduce((acc, curr) => (acc.length > 0 ? acc + "," : "") +
587
+ node.sel = node[OPTIMIZED].selector.reduce((acc, curr) => (acc.length > 0 ? acc + "," : "") +
598
588
  (nestingContent && testIdent.test(curr[0]) ? "& " : "") +
599
589
  curr.join(""), "");
600
590
  }
601
591
  }
602
- else if (node.optimized?.optimized.length > 0) {
603
- const sel = node.optimized.optimized.join("");
592
+ else if (node[OPTIMIZED]?.optimized.length > 0) {
593
+ const sel = node[OPTIMIZED].optimized.join("");
604
594
  if (sel.length < node.sel.length) {
605
595
  node.sel = sel;
606
- node.raw = [node.optimized.optimized.slice()];
596
+ node[RAW] = [node[OPTIMIZED].optimized.slice()];
607
597
  }
608
598
  }
609
599
  doMinify(node, options, recursive, errors, nestingContent, context);
@@ -638,7 +628,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
638
628
  }
639
629
  else if (node.typ == previous?.typ &&
640
630
  [EnumToken.KeyFramesRuleNodeType, EnumToken.RuleNodeType].includes(node.typ)) {
641
- const intersect = diff(previous, node, reducer, options);
631
+ const intersect = diff(previous, node, options);
642
632
  if (intersect != null) {
643
633
  if (intersect.node1.chi.length == 0) {
644
634
  ast.chi.splice(i--, 1);
@@ -647,14 +637,24 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
647
637
  ast.chi.splice(i--, 1, intersect.node1);
648
638
  }
649
639
  if (intersect.node2.chi.length == 0) {
650
- ast.chi.splice(nodeIndex, 1, intersect.result);
640
+ if (intersect.result != null) {
641
+ ast.chi.splice(nodeIndex, 1, intersect.result);
642
+ }
643
+ else {
644
+ ast.chi.splice(nodeIndex, 1);
645
+ }
651
646
  i--;
652
647
  if (nodeIndex == i) {
653
648
  nodeIndex = i;
654
649
  }
655
650
  }
656
651
  else {
657
- ast.chi.splice(nodeIndex, 1, intersect.result, intersect.node2);
652
+ if (intersect.result != null) {
653
+ ast.chi.splice(nodeIndex, 1, intersect.result, intersect.node2);
654
+ }
655
+ else {
656
+ ast.chi.splice(nodeIndex, 1, intersect.node2);
657
+ }
658
658
  i = (nodeIndex ?? 0) + 1;
659
659
  }
660
660
  if (node != ast.chi[i]) {
@@ -1126,12 +1126,13 @@ function wrapNodes(previous, node, match, ast, reducer, i, nodeIndex) {
1126
1126
  let pSel = match.selector1.reduce(reducer, []).join(",");
1127
1127
  // @ts-ignore
1128
1128
  let nSel = match.selector2.reduce(reducer, []).join(",");
1129
- // @ts-ignore
1130
- const wrapper = { ...previous, chi: [], sel: match.match.reduce(reducer, []).join(",") };
1131
- Object.defineProperty(wrapper, "raw", {
1132
- ...definedPropertySettings,
1133
- value: match.match.map((t) => t.slice()),
1134
- });
1129
+ const wrapper = {
1130
+ ...previous,
1131
+ chi: [],
1132
+ // @ts-ignore
1133
+ sel: match.match.reduce(reducer, []).join(","),
1134
+ [RAW]: match.match.map((t) => t.slice()),
1135
+ };
1135
1136
  if (pSel == "&" || pSel === "") {
1136
1137
  wrapper.chi.push(...previous.chi);
1137
1138
  if (nSel == "&" || nSel === "") {
@@ -1147,9 +1148,9 @@ function wrapNodes(previous, node, match, ast, reducer, i, nodeIndex) {
1147
1148
  ast.chi.splice(i, 1, wrapper);
1148
1149
  ast.chi.splice(nodeIndex, 1);
1149
1150
  previous.sel = pSel;
1150
- previous.raw = match.selector1;
1151
+ previous[RAW] = match.selector1;
1151
1152
  node.sel = nSel;
1152
- node.raw = match.selector2;
1153
+ node[RAW] = match.selector2;
1153
1154
  reduceRuleSelector(wrapper);
1154
1155
  return wrapper;
1155
1156
  }
@@ -1162,7 +1163,7 @@ function wrapNodes(previous, node, match, ast, reducer, i, nodeIndex) {
1162
1163
  *
1163
1164
  * @private
1164
1165
  */
1165
- function diff(n1, n2, reducer, options = {}) {
1166
+ function diff(n1, n2, options = {}) {
1166
1167
  if (!("cache" in options)) {
1167
1168
  options.cache = new WeakMap();
1168
1169
  }
@@ -1177,8 +1178,8 @@ function diff(n1, n2, reducer, options = {}) {
1177
1178
  }
1178
1179
  let i = node1.chi.length;
1179
1180
  let j = node2.chi.length;
1180
- const raw1 = node1.raw;
1181
- const raw2 = node2.raw;
1181
+ const raw1 = node1[RAW];
1182
+ const raw2 = node2[RAW];
1182
1183
  if (raw1 != null && raw2 != null) {
1183
1184
  const prefixes1 = new Set();
1184
1185
  const prefixes2 = new Set();
@@ -1236,10 +1237,10 @@ function diff(n1, n2, reducer, options = {}) {
1236
1237
  options.cache.set(node2, css2);
1237
1238
  }
1238
1239
  if (raw1 != null) {
1239
- Object.defineProperty(node1, "raw", { ...definedPropertySettings, value: raw1 });
1240
+ node1[RAW] = raw1;
1240
1241
  }
1241
1242
  if (raw2 != null) {
1242
- Object.defineProperty(node2, "raw", { ...definedPropertySettings, value: raw2 });
1243
+ node2[RAW] = raw2;
1243
1244
  }
1244
1245
  const intersect = [];
1245
1246
  while (i--) {
@@ -1294,6 +1295,8 @@ function diff(n1, n2, reducer, options = {}) {
1294
1295
  }
1295
1296
  }
1296
1297
  if (result != null) {
1298
+ result[TOKENS] = null;
1299
+ result[RAW] = null;
1297
1300
  const optimized = optimizeSelector(splitRule(result.sel));
1298
1301
  if (optimized?.match) {
1299
1302
  const rule = optimized.selector.reduce((acc, curr) => {
@@ -1324,15 +1327,15 @@ function diff(n1, n2, reducer, options = {}) {
1324
1327
  * @private
1325
1328
  */
1326
1329
  function reduceRuleSelector(node) {
1327
- if (node.raw == null) {
1328
- Object.defineProperty(node, "raw", { ...definedPropertySettings, value: splitRule(node.sel) });
1330
+ if (node[RAW] == null) {
1331
+ node[RAW] = splitRule(node.sel);
1329
1332
  }
1330
- let optimized = optimizeSelector(node.raw.reduce((acc, curr) => {
1333
+ let optimized = optimizeSelector(node[RAW].reduce((acc, curr) => {
1331
1334
  acc.push(curr.slice());
1332
1335
  return acc;
1333
1336
  }, []));
1334
1337
  if (optimized != null) {
1335
- Object.defineProperty(node, "optimized", { ...definedPropertySettings, value: optimized });
1338
+ node[OPTIMIZED] = optimized;
1336
1339
  }
1337
1340
  if (optimized != null && optimized.match && optimized.reducible && optimized.selector.length > 1) {
1338
1341
  for (const selector of optimized.selector) {
@@ -1360,7 +1363,7 @@ function reduceRuleSelector(node) {
1360
1363
  const sel = raw[0].join("");
1361
1364
  if (sel.length < node.sel.length) {
1362
1365
  node.sel = sel;
1363
- Object.defineProperty(node, "raw", { ...definedPropertySettings, value: raw });
1366
+ node[RAW] = raw;
1364
1367
  }
1365
1368
  }
1366
1369
  }
@@ -568,8 +568,8 @@ var EnumToken;
568
568
  EnumToken[EnumToken["RawNodeTokenType"] = 117] = "RawNodeTokenType";
569
569
  /**
570
570
  * media query boolean token type
571
- * @media not ()
572
- * @media only ()
571
+ * at-rule media not ()
572
+ * at-rule media only ()
573
573
  */
574
574
  EnumToken[EnumToken["MediaQueryUnaryFeatureTokenType"] = 118] = "MediaQueryUnaryFeatureTokenType";
575
575
  /**
@@ -656,6 +656,10 @@ var EnumToken;
656
656
  * if-Else condition token
657
657
  */
658
658
  EnumToken[EnumToken["IfElseConditionTokenType"] = 139] = "IfElseConditionTokenType";
659
+ /**
660
+ * wrapped values token type like {Arial, sans-serif}
661
+ */
662
+ EnumToken[EnumToken["WrappedValuesTokenType"] = 140] = "WrappedValuesTokenType";
659
663
  /* aliases */
660
664
  /**
661
665
  * alias for time token type
@@ -144,7 +144,7 @@ function* walk(node, filter, reverse) {
144
144
  };
145
145
  }
146
146
  if ("chi" in node && (!isNumeric || (option & WalkerOptionEnum.IgnoreChildren) === 0)) {
147
- parents.splice(i, 0, ...node.chi[reverse ? "reverse" : "slice"]());
147
+ parents.splice(i, 0, ...node.chi[reverse ? "toReversed" : "slice"]());
148
148
  for (const child of node.chi) {
149
149
  map.set(child, node);
150
150
  }
@@ -23,7 +23,7 @@ function dirname(path) {
23
23
  }
24
24
  }
25
25
  parts.pop();
26
- return parts.length == 0 ? "/" : parts.join("/");
26
+ return parts.join("/");
27
27
  }
28
28
  /**
29
29
  * split path
@@ -34,9 +34,9 @@ function splitPath(result) {
34
34
  if (result.length == 0) {
35
35
  return { parts: [], i: 0 };
36
36
  }
37
- if (result === "/") {
38
- return { parts: ["/"], i: 0 };
39
- }
37
+ // if (result === "/") {
38
+ // return { parts: ["/"], i: 0 };
39
+ // }
40
40
  const parts = [""];
41
41
  let i = 0;
42
42
  for (; i < result.length; i++) {
@@ -44,25 +44,27 @@ function splitPath(result) {
44
44
  if (chr == "/") {
45
45
  parts.push("");
46
46
  }
47
- else if (chr == "?" || chr == "#") {
48
- break;
49
- }
47
+ // else if (chr == "?" || chr == "#") {
48
+ // break;
49
+ // }
50
50
  else {
51
51
  parts[parts.length - 1] += chr;
52
52
  }
53
53
  }
54
- let k = -1;
55
- while (++k < parts.length) {
56
- if (parts[k] == ".") {
57
- parts.splice(k--, 1);
58
- }
59
- else if (parts[k] == "..") {
60
- parts.splice(k - 1, 2);
61
- k -= 2;
62
- }
63
- }
54
+ // let k: number = -1;
55
+ // while (++k < parts.length) {
56
+ // if (parts[k] == ".") {
57
+ // parts.splice(k--, 1);
58
+ // } else if (parts[k] == "..") {
59
+ // parts.splice(k - 1, 2);
60
+ // k -= 2;
61
+ // }
62
+ // }
64
63
  return { parts, i };
65
64
  }
65
+ /**
66
+ * Nomalize path
67
+ */
66
68
  const normalize = memoize(function (path) {
67
69
  let parts = [];
68
70
  let i = 0;
@@ -88,10 +90,10 @@ const normalize = memoize(function (path) {
88
90
  }
89
91
  let k = -1;
90
92
  while (++k < parts.length) {
91
- if (parts[k] == ".") {
92
- parts.splice(k--, 1);
93
- }
94
- else if (parts[k] == "..") {
93
+ // if (parts[k] == ".") {
94
+ // parts.splice(k--, 1);
95
+ // } else
96
+ if (parts[k] == "..") {
95
97
  parts.splice(k - 1, 2);
96
98
  k -= 2;
97
99
  }
@@ -120,12 +122,12 @@ const diff = memoize(function (path1, path2) {
120
122
  * @private
121
123
  */
122
124
  const resolve = memoize(function (url, currentDirectory, cwd) {
123
- if (matchUrl.test(url)) {
124
- return {
125
- absolute: url,
126
- relative: url,
127
- };
128
- }
125
+ // if (matchUrl.test(url)) {
126
+ // return {
127
+ // absolute: url,
128
+ // relative: url,
129
+ // };
130
+ // }
129
131
  cwd ??= "";
130
132
  currentDirectory ??= "";
131
133
  url = normalize(url);
@@ -149,24 +151,24 @@ const resolve = memoize(function (url, currentDirectory, cwd) {
149
151
  };
150
152
  }
151
153
  }
152
- if (matchUrl.test(currentDirectory)) {
153
- const path = new URL(url, currentDirectory).href;
154
- return {
155
- absolute: path,
156
- relative: path,
157
- };
158
- }
159
- let result = "";
160
- if (url.charAt(0) == "/") {
161
- result = url;
162
- }
163
- else if (currentDirectory.charAt(0) == "/") {
164
- result = dirname(currentDirectory) + "/" + url;
165
- }
166
- const absolute = normalize(result);
154
+ // if (matchUrl.test(currentDirectory)) {
155
+ // const path: string = new URL(url, currentDirectory).href;
156
+ // return {
157
+ // absolute: path,
158
+ // relative: path,
159
+ // };
160
+ // }
161
+ // let result: string = "";
162
+ // if (url.charAt(0) == "/") {
163
+ // result = url;
164
+ // }
165
+ // else if (currentDirectory.charAt(0) == "/") {
166
+ // result = dirname(currentDirectory) + "/" + url;
167
+ // }
168
+ // const absolute = url; // normalize(result);
167
169
  return {
168
- absolute,
169
- relative: absolute === "" ? "" : diff(absolute, cwd ?? currentDirectory),
170
+ absolute: url,
171
+ relative: url === "" ? "" : diff(url, cwd ?? currentDirectory),
170
172
  };
171
173
  });
172
174
 
@@ -6,7 +6,7 @@ import { EnumToken, EnumAstNodeStatus } from '../../ast/types.js';
6
6
  import { getParsedSyntax } from '../../validation/config.js';
7
7
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
8
8
  import { matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
9
- import { definedPropertySettings } from '../../syntax/constants.js';
9
+ import { STATE } from '../../syntax/constants.js';
10
10
 
11
11
  const config = getConfig();
12
12
  class PropertyList {
@@ -32,9 +32,9 @@ class PropertyList {
32
32
  declaration.typ != EnumToken.DeclarationNodeType
33
33
  ? null
34
34
  : declaration.nam.toLowerCase();
35
- if (declaration.state == EnumAstNodeStatus.Invalid ||
36
- declaration.state == EnumAstNodeStatus.Unknown ||
37
- declaration.state == EnumAstNodeStatus.ValidationFailed ||
35
+ if (declaration[STATE] == EnumAstNodeStatus.Invalid ||
36
+ declaration[STATE] == EnumAstNodeStatus.Unknown ||
37
+ declaration[STATE] == EnumAstNodeStatus.ValidationFailed ||
38
38
  declaration.typ != EnumToken.DeclarationNodeType ||
39
39
  "composes" === name ||
40
40
  (typeof this.options.removeDuplicateDeclarations === "string" &&
@@ -49,18 +49,17 @@ class PropertyList {
49
49
  this.declarations.set(declaration.nam, declaration);
50
50
  continue;
51
51
  }
52
- if (declaration.state == EnumAstNodeStatus.Unvalidated) {
52
+ if (declaration[STATE] == EnumAstNodeStatus.Unvalidated) {
53
53
  syntaxRules = getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, declaration.nam.toLowerCase());
54
54
  if (syntaxRules != null) {
55
55
  result = matchAllSyntaxes(syntaxRules, createValidationContext(declaration.val), this.options);
56
- Object.defineProperty(declaration, "state", {
57
- ...definedPropertySettings,
58
- value: result.success ? EnumAstNodeStatus.Validated : EnumAstNodeStatus.ValidationFailed,
59
- });
56
+ declaration[STATE] = result.success
57
+ ? EnumAstNodeStatus.Validated
58
+ : EnumAstNodeStatus.ValidationFailed;
60
59
  }
61
60
  }
62
61
  // do not compute shorthand for invalid declarations
63
- if (declaration.state !== EnumAstNodeStatus.Validated) {
62
+ if (declaration[STATE] !== EnumAstNodeStatus.Validated) {
64
63
  this.declarations.set(declaration.nam, declaration);
65
64
  return this;
66
65
  }