@tbela99/css-parser 1.6.9 → 1.8.1

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 (103) hide show
  1. package/CHANGELOG.md +42 -1
  2. package/README.md +1 -0
  3. package/dist/index-umd-web.js +1139 -529
  4. package/dist/index.cjs +1138 -528
  5. package/dist/index.d.ts +259 -8
  6. package/dist/package.json.js +2 -2
  7. package/dist/src/data/properties.json.js +1 -1
  8. package/dist/src/data/validation.json.js +11 -2
  9. package/dist/src/lib/ast/clone.js +1 -1
  10. package/dist/src/lib/ast/expand.js +1 -1
  11. package/dist/src/lib/ast/features/calc.js +1 -1
  12. package/dist/src/lib/ast/features/if.js +1 -1
  13. package/dist/src/lib/ast/features/index.js +1 -1
  14. package/dist/src/lib/ast/features/inlinecssvariables.js +6 -5
  15. package/dist/src/lib/ast/features/prefix.js +1 -1
  16. package/dist/src/lib/ast/features/shorthand.js +39 -22
  17. package/dist/src/lib/ast/features/transform.js +1 -1
  18. package/dist/src/lib/ast/features/type.js +1 -1
  19. package/dist/src/lib/ast/find.js +26 -21
  20. package/dist/src/lib/ast/math/expression.js +4 -1
  21. package/dist/src/lib/ast/math/math.js +1 -1
  22. package/dist/src/lib/ast/minify.js +31 -3
  23. package/dist/src/lib/ast/node.js +1 -1
  24. package/dist/src/lib/ast/transform/compute.js +1 -1
  25. package/dist/src/lib/ast/transform/matrix.js +1 -1
  26. package/dist/src/lib/ast/transform/minify.js +1 -1
  27. package/dist/src/lib/ast/transform/perspective.js +1 -1
  28. package/dist/src/lib/ast/transform/rotate.js +1 -1
  29. package/dist/src/lib/ast/transform/scale.js +1 -1
  30. package/dist/src/lib/ast/transform/skew.js +1 -1
  31. package/dist/src/lib/ast/transform/translate.js +1 -1
  32. package/dist/src/lib/ast/transform/utils.js +1 -1
  33. package/dist/src/lib/ast/types.js +5 -1
  34. package/dist/src/lib/ast/walk.js +319 -94
  35. package/dist/src/lib/fs/resolve.js +1 -1
  36. package/dist/src/lib/parser/declaration/list.js +35 -1
  37. package/dist/src/lib/parser/declaration/map.js +2 -2
  38. package/dist/src/lib/parser/declaration/set.js +1 -1
  39. package/dist/src/lib/parser/linesmap.js +1 -1
  40. package/dist/src/lib/parser/parse.js +504 -177
  41. package/dist/src/lib/parser/source.js +1 -1
  42. package/dist/src/lib/parser/tokenize.js +23 -3
  43. package/dist/src/lib/parser/utils/angle.js +1 -1
  44. package/dist/src/lib/parser/utils/at-rule-container.js +1 -1
  45. package/dist/src/lib/parser/utils/at-rule-font-feature-values.js +1 -1
  46. package/dist/src/lib/parser/utils/at-rule-generic.js +1 -1
  47. package/dist/src/lib/parser/utils/at-rule-import.js +1 -1
  48. package/dist/src/lib/parser/utils/at-rule-media.js +2 -2
  49. package/dist/src/lib/parser/utils/at-rule-support.js +2 -2
  50. package/dist/src/lib/parser/utils/at-rule-when-else.js +1 -1
  51. package/dist/src/lib/parser/utils/at-rule.js +1 -1
  52. package/dist/src/lib/parser/utils/base64.js +1 -1
  53. package/dist/src/lib/parser/utils/cache.js +1 -1
  54. package/dist/src/lib/parser/utils/config.js +1 -1
  55. package/dist/src/lib/parser/utils/declaration.js +1 -1
  56. package/dist/src/lib/parser/utils/eq.js +1 -1
  57. package/dist/src/lib/parser/utils/hash.js +1 -1
  58. package/dist/src/lib/parser/utils/selector.js +1 -1
  59. package/dist/src/lib/parser/utils/text.js +1 -1
  60. package/dist/src/lib/parser/utils/token.js +12 -4
  61. package/dist/src/lib/parser/utils/type.js +1 -1
  62. package/dist/src/lib/printer/render.js +6 -3
  63. package/dist/src/lib/printer/sourcemap/lib/codec.js +1 -1
  64. package/dist/src/lib/printer/sourcemap/sourcemap.js +1 -1
  65. package/dist/src/lib/syntax/color/a98rgb.js +1 -1
  66. package/dist/src/lib/syntax/color/alpha.js +1 -1
  67. package/dist/src/lib/syntax/color/cmyk.js +1 -1
  68. package/dist/src/lib/syntax/color/color-mix.js +1 -1
  69. package/dist/src/lib/syntax/color/color.js +1 -1
  70. package/dist/src/lib/syntax/color/hex.js +1 -1
  71. package/dist/src/lib/syntax/color/hsl.js +1 -1
  72. package/dist/src/lib/syntax/color/hwb.js +1 -1
  73. package/dist/src/lib/syntax/color/lab.js +1 -1
  74. package/dist/src/lib/syntax/color/lch.js +1 -1
  75. package/dist/src/lib/syntax/color/oklab.js +1 -1
  76. package/dist/src/lib/syntax/color/oklch.js +1 -1
  77. package/dist/src/lib/syntax/color/p3.js +1 -1
  78. package/dist/src/lib/syntax/color/prophotorgb.js +1 -1
  79. package/dist/src/lib/syntax/color/rec2020.js +1 -1
  80. package/dist/src/lib/syntax/color/relative-color.js +1 -1
  81. package/dist/src/lib/syntax/color/rgb.js +1 -1
  82. package/dist/src/lib/syntax/color/srgb.js +1 -1
  83. package/dist/src/lib/syntax/color/utils/color-type.js +1 -1
  84. package/dist/src/lib/syntax/color/utils/colorspace.js +1 -1
  85. package/dist/src/lib/syntax/color/utils/components.js +1 -1
  86. package/dist/src/lib/syntax/color/utils/distance.js +1 -1
  87. package/dist/src/lib/syntax/color/utils/make-color.js +1 -1
  88. package/dist/src/lib/syntax/color/utils/matrix.js +1 -1
  89. package/dist/src/lib/syntax/color/xyz.js +1 -1
  90. package/dist/src/lib/syntax/color/xyzd50.js +1 -1
  91. package/dist/src/lib/syntax/constants.js +1 -1
  92. package/dist/src/lib/syntax/syntax.js +1 -1
  93. package/dist/src/lib/validation/config.js +20 -3
  94. package/dist/src/lib/validation/match.js +105 -200
  95. package/dist/src/lib/validation/parser/parse.js +8 -3
  96. package/dist/src/lib/validation/parser/typedef.js +1 -1
  97. package/dist/src/lib/validation/utils/list.js +1 -1
  98. package/dist/src/node.js +2 -1
  99. package/dist/src/types.js +1 -1
  100. package/dist/src/utils/sync.js +1 -1
  101. package/dist/src/web.js +2 -1
  102. package/package.json +8 -7
  103. package/CONTRIBUTING.md +0 -119
@@ -2,12 +2,12 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from './types.js';
9
9
  import { walk, walkValues } from './walk.js';
10
- import { TOKENS } from '../syntax/constants.js';
10
+ import { PARENT, TOKENS } from '../syntax/constants.js';
11
11
 
12
12
  /**
13
13
  * Search the ast subtree and return the first match
@@ -41,9 +41,9 @@ button {
41
41
  * @returns
42
42
  */
43
43
  function find(ast, matcher) {
44
- for (const { node, parent } of walk(ast)) {
45
- if (matcher(node, parent)) {
46
- return node;
44
+ for (const r of walk(ast)) {
45
+ if (matcher(r.node, r.parent)) {
46
+ return r.node;
47
47
  }
48
48
  }
49
49
  return null;
@@ -82,21 +82,25 @@ button {
82
82
  */
83
83
  function findByValue(ast, matcher) {
84
84
  let source;
85
- for (const { node } of walk(ast)) {
85
+ for (const r1 of walk(ast)) {
86
86
  source = null;
87
- if (node.typ === EnumToken.DeclarationNodeType) {
88
- source = node.val;
87
+ if (r1.node.typ === EnumToken.DeclarationNodeType) {
88
+ source = r1.node.val;
89
89
  }
90
- else if (Array.isArray(node[TOKENS])) {
91
- source = node[TOKENS];
90
+ else if (Array.isArray(r1.node[TOKENS])) {
91
+ source = r1.node[TOKENS];
92
92
  }
93
93
  if (source == null) {
94
94
  continue;
95
95
  }
96
- for (const { value, parent, root: rootNode, parents } of walkValues(source, node)) {
97
- if (matcher(value, node)) {
98
- // @ts-ignore
99
- return { node, value: { node: value, parent, root: rootNode, parents } };
96
+ for (const r2 of walkValues(source, r1.node)) {
97
+ if (matcher(r2.value, r1.node)) {
98
+ return {
99
+ // @ts-ignore
100
+ node: r1.node,
101
+ // @ts-ignore
102
+ value: { node: r2.value, parent: r2.parent, root: r2.root, parents: r2.parents },
103
+ };
100
104
  }
101
105
  }
102
106
  }
@@ -138,9 +142,9 @@ button-small {
138
142
  */
139
143
  function findAll(ast, matcher) {
140
144
  const result = [];
141
- for (const { node, parent } of walk(ast)) {
142
- if (matcher(node, parent)) {
143
- result.push(node);
145
+ for (const r of walk(ast)) {
146
+ if (matcher(r.node, r.node[PARENT])) {
147
+ result.push(r.node);
144
148
  }
145
149
  }
146
150
  return result;
@@ -176,11 +180,12 @@ button {
176
180
  * @returns
177
181
  */
178
182
  function findLast(ast, matcher) {
179
- for (const { node, parent } of walk(ast, null, true)) {
180
- if (matcher(node, parent)) {
181
- return node;
183
+ for (const result of walk(ast, null, true))
184
+ // for (const { node, parent } of walk(ast as AstNode, null, true)) {
185
+ if (matcher(result.node, result.parent)) {
186
+ return result.node;
182
187
  }
183
- }
188
+ // }
184
189
  return null;
185
190
  }
186
191
 
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  import { equalsIgnoreCase } from '../../parser/utils/text.js';
@@ -139,6 +139,9 @@ function evaluate(tokens) {
139
139
  }
140
140
  }
141
141
  if (acc.length > 0 && curr[0] != EnumToken.ListToken) {
142
+ if ("val" in token && +token.val == 0) {
143
+ return acc;
144
+ }
142
145
  acc.push({
143
146
  typ: EnumToken.Add,
144
147
  [LOCSRCID]: token[LOCSRCID],
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  import { minifyNumber } from '../../syntax/syntax.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  import { eq } from '../parser/utils/eq.js';
@@ -17,6 +17,7 @@ import { TOKENS, PARENT, OPTIMIZED, RAW, combinators, LOCEND, LOCSTA, LOCSRCID }
17
17
  import { replaceNodeOrValue } from '../parser/utils/token.js';
18
18
  import { parseString } from '../parser/parse.js';
19
19
  import { replaceCompound } from './expand.js';
20
+ import { equalsIgnoreCase } from '../parser/utils/text.js';
20
21
 
21
22
  const notEndingWith = ["(", "["].concat(combinators);
22
23
  const rules = [
@@ -366,8 +367,35 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
366
367
  previous = ast.chi[--nodeIndex];
367
368
  }
368
369
  node = ast.chi[i];
369
- if (node.typ === EnumToken.AtRuleNodeType && node.nam === "font-face") {
370
- continue;
370
+ if (node.typ === EnumToken.AtRuleNodeType) {
371
+ if (node.nam === "font-face") {
372
+ continue;
373
+ }
374
+ // https://drafts.csswg.org/css-mixins/#:~:text=The%20value%20of%20the%20result%20descriptor%20is%20always%2016px%20in%20the%20above%20example
375
+ if (equalsIgnoreCase(node.nam, "function")) {
376
+ const chi = node.chi;
377
+ let k = chi?.length;
378
+ let slice = false;
379
+ while (k--) {
380
+ if (chi[k].typ === EnumToken.CommentNodeType ||
381
+ chi[k].typ === EnumToken.WhitespaceTokenType) {
382
+ continue;
383
+ }
384
+ if (chi[k].typ === EnumToken.DeclarationNodeType &&
385
+ equalsIgnoreCase(chi[k].nam, "result")) {
386
+ slice = true;
387
+ break;
388
+ }
389
+ }
390
+ if (k > 0 && slice) {
391
+ while (k--) {
392
+ if (chi[k].typ === EnumToken.AtRuleNodeType) {
393
+ chi.splice(k, 1);
394
+ continue;
395
+ }
396
+ }
397
+ }
398
+ }
371
399
  }
372
400
  if (node.typ === EnumToken.KeyframesAtRuleNodeType) {
373
401
  if (previous?.typ === EnumToken.KeyframesAtRuleNodeType &&
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  import { TOKENS, ERRORS, STATE, LOCSRCID, LOCSTA, LOCEND, PARENT } from '../syntax/constants.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  import { identity, multiply, toZero } from './utils.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  import { identity, is2DMatrix } from './utils.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  import { identity, multiply, decompose, round, toZero } from './utils.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  import { identity, multiply } from './utils.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  import { identity, multiply } from './utils.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  import { identity, multiply } from './utils.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  import { identity, multiply } from './utils.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  import { identity, multiply } from './utils.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  import { epsilon } from '../../syntax/constants.js';
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.6.9
5
+ Version: 1.8.1
6
6
  License: MIT
7
7
  */
8
8
  /**
@@ -691,6 +691,10 @@ var EnumToken;
691
691
  * CSS type token
692
692
  */
693
693
  EnumToken[EnumToken["CssTypeTokenType"] = 144] = "CssTypeTokenType";
694
+ /**
695
+ * user defined dimension token type
696
+ */
697
+ EnumToken[EnumToken["UserDefinedDimensionTokenType"] = 145] = "UserDefinedDimensionTokenType";
694
698
  /* aliases */
695
699
  /**
696
700
  * alias for time token type