@tbela99/css-parser 0.1.0 → 0.3.0

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 (40) hide show
  1. package/README.md +267 -2
  2. package/dist/config.json.js +611 -4
  3. package/dist/index-umd-web.js +2898 -1223
  4. package/dist/index.cjs +2898 -1223
  5. package/dist/lib/ast/expand.js +11 -11
  6. package/dist/lib/ast/features/calc.js +33 -224
  7. package/dist/lib/ast/features/index.js +3 -3
  8. package/dist/lib/ast/features/inlinecssvariables.js +46 -31
  9. package/dist/lib/ast/features/shorthand.js +7 -7
  10. package/dist/lib/ast/features/utils/math.js +95 -0
  11. package/dist/lib/ast/math/expression.js +185 -0
  12. package/dist/lib/ast/math/math.js +95 -0
  13. package/dist/lib/ast/minify.js +34 -29
  14. package/dist/lib/ast/types.js +108 -78
  15. package/dist/lib/ast/walk.js +42 -9
  16. package/dist/lib/fs/resolve.js +4 -3
  17. package/dist/lib/iterable/set.js +48 -0
  18. package/dist/lib/iterable/weakmap.js +53 -0
  19. package/dist/lib/iterable/weakset.js +48 -0
  20. package/dist/lib/parser/declaration/list.js +7 -3
  21. package/dist/lib/parser/declaration/map.js +86 -7
  22. package/dist/lib/parser/declaration/set.js +43 -23
  23. package/dist/lib/parser/parse.js +561 -387
  24. package/dist/lib/parser/tokenize.js +42 -13
  25. package/dist/lib/parser/utils/declaration.js +67 -0
  26. package/dist/lib/parser/utils/syntax.js +32 -2
  27. package/dist/lib/parser/utils/type.js +7 -2
  28. package/dist/lib/renderer/render.js +163 -47
  29. package/dist/lib/renderer/utils/calccolor.js +238 -0
  30. package/dist/lib/renderer/utils/color.js +36 -164
  31. package/dist/lib/renderer/utils/hex.js +124 -0
  32. package/dist/lib/renderer/utils/hsl.js +49 -0
  33. package/dist/lib/renderer/utils/hsv.js +15 -0
  34. package/dist/lib/renderer/utils/hwb.js +50 -0
  35. package/dist/lib/renderer/utils/rgb.js +66 -0
  36. package/dist/node/index.js +8 -12
  37. package/dist/web/index.js +8 -12
  38. package/package.json +9 -7
  39. package/dist/index.d.ts +0 -1056
  40. /package/dist/lib/ast/{utiles → utils}/minifyfeature.js +0 -0
@@ -6,6 +6,29 @@ import '../parse.js';
6
6
  import '../../renderer/utils/color.js';
7
7
  import '../../renderer/sourcemap/lib/encode.js';
8
8
 
9
+ function dedup(values) {
10
+ for (const value of values) {
11
+ let i = value.length;
12
+ while (i-- > 1) {
13
+ const t = value[i];
14
+ const k = value[i == 1 ? 0 : i % 2];
15
+ if (t.val == k.val && t.val == '0') {
16
+ if ((t.typ == EnumToken.NumberTokenType && isLength(k)) ||
17
+ (k.typ == EnumToken.NumberTokenType && isLength(t)) ||
18
+ (isLength(k) || isLength(t))) {
19
+ value.splice(i, 1);
20
+ continue;
21
+ }
22
+ }
23
+ if (eq(t, k)) {
24
+ value.splice(i, 1);
25
+ continue;
26
+ }
27
+ break;
28
+ }
29
+ }
30
+ return values;
31
+ }
9
32
  class PropertySet {
10
33
  config;
11
34
  declarations;
@@ -60,7 +83,7 @@ class PropertySet {
60
83
  this.config.properties.forEach((property, index) => {
61
84
  if (!this.declarations.has(property)) {
62
85
  this.declarations.set(property, {
63
- typ: 5 /* NodeType.DeclarationNodeType */,
86
+ typ: EnumToken.DeclarationNodeType,
64
87
  nam: property,
65
88
  val: []
66
89
  });
@@ -100,7 +123,23 @@ class PropertySet {
100
123
  let iterator;
101
124
  const declarations = this.declarations;
102
125
  if (declarations.size < this.config.properties.length) {
103
- iterator = declarations.values();
126
+ const values = [...declarations.values()];
127
+ if (this.isShortHand()) {
128
+ const val = values[0].val.reduce((acc, curr) => {
129
+ if (![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(curr.typ)) {
130
+ acc.push(curr);
131
+ }
132
+ return acc;
133
+ }, []);
134
+ values[0].val = val.reduce((acc, curr) => {
135
+ if (acc.length > 0) {
136
+ acc.push({ typ: EnumToken.WhitespaceTokenType });
137
+ }
138
+ acc.push(curr);
139
+ return acc;
140
+ }, []);
141
+ }
142
+ return values[Symbol.iterator]();
104
143
  }
105
144
  else {
106
145
  const values = [];
@@ -118,28 +157,9 @@ class PropertySet {
118
157
  index++;
119
158
  }
120
159
  });
121
- for (const value of values) {
122
- let i = value.length;
123
- while (i-- > 1) {
124
- const t = value[i];
125
- const k = value[i == 1 ? 0 : i % 2];
126
- if (t.val == k.val && t.val == '0') {
127
- if ((t.typ == EnumToken.NumberTokenType && isLength(k)) ||
128
- (k.typ == EnumToken.NumberTokenType && isLength(t)) ||
129
- (isLength(k) || isLength(t))) {
130
- value.splice(i, 1);
131
- continue;
132
- }
133
- }
134
- if (eq(t, k)) {
135
- value.splice(i, 1);
136
- continue;
137
- }
138
- break;
139
- }
140
- }
160
+ dedup(values);
141
161
  iterator = [{
142
- typ: 5 /* NodeType.DeclarationNodeType */,
162
+ typ: EnumToken.DeclarationNodeType,
143
163
  nam: this.config.shorthand,
144
164
  val: values.reduce((acc, curr) => {
145
165
  if (curr.length > 1) {