@tbela99/css-parser 1.0.0 → 1.1.1-alpha4

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 (87) hide show
  1. package/CHANGELOG.md +269 -0
  2. package/README.md +16 -11
  3. package/dist/index-umd-web.js +3805 -1894
  4. package/dist/index.cjs +3806 -1895
  5. package/dist/index.d.ts +184 -57
  6. package/dist/lib/ast/expand.js +2 -1
  7. package/dist/lib/ast/features/calc.js +12 -1
  8. package/dist/lib/ast/features/inlinecssvariables.js +47 -24
  9. package/dist/lib/ast/features/prefix.js +117 -86
  10. package/dist/lib/ast/features/shorthand.js +29 -6
  11. package/dist/lib/ast/features/transform.js +10 -3
  12. package/dist/lib/ast/features/type.js +7 -0
  13. package/dist/lib/ast/math/expression.js +7 -1
  14. package/dist/lib/ast/math/math.js +6 -0
  15. package/dist/lib/ast/minify.js +165 -77
  16. package/dist/lib/ast/transform/compute.js +1 -0
  17. package/dist/lib/ast/transform/matrix.js +1 -0
  18. package/dist/lib/ast/types.js +26 -15
  19. package/dist/lib/ast/utils/utils.js +104 -0
  20. package/dist/lib/ast/walk.js +33 -7
  21. package/dist/lib/fs/resolve.js +10 -0
  22. package/dist/lib/parser/declaration/list.js +48 -45
  23. package/dist/lib/parser/declaration/map.js +1 -0
  24. package/dist/lib/parser/declaration/set.js +2 -1
  25. package/dist/lib/parser/parse.js +350 -279
  26. package/dist/lib/parser/tokenize.js +147 -72
  27. package/dist/lib/parser/utils/declaration.js +4 -3
  28. package/dist/lib/parser/utils/type.js +2 -1
  29. package/dist/lib/renderer/color/a98rgb.js +2 -1
  30. package/dist/lib/renderer/color/color-mix.js +10 -7
  31. package/dist/lib/renderer/color/color.js +171 -153
  32. package/dist/lib/renderer/color/hex.js +2 -1
  33. package/dist/lib/renderer/color/hsl.js +2 -1
  34. package/dist/lib/renderer/color/hwb.js +2 -1
  35. package/dist/lib/renderer/color/lab.js +2 -1
  36. package/dist/lib/renderer/color/lch.js +2 -1
  37. package/dist/lib/renderer/color/oklab.js +2 -1
  38. package/dist/lib/renderer/color/oklch.js +2 -1
  39. package/dist/lib/renderer/color/p3.js +2 -1
  40. package/dist/lib/renderer/color/rec2020.js +2 -1
  41. package/dist/lib/renderer/color/relativecolor.js +17 -11
  42. package/dist/lib/renderer/color/rgb.js +4 -3
  43. package/dist/lib/renderer/color/srgb.js +18 -17
  44. package/dist/lib/renderer/color/utils/components.js +6 -5
  45. package/dist/lib/renderer/color/utils/constants.js +47 -3
  46. package/dist/lib/renderer/color/xyz.js +2 -1
  47. package/dist/lib/renderer/color/xyzd50.js +2 -1
  48. package/dist/lib/renderer/render.js +48 -20
  49. package/dist/lib/syntax/syntax.js +257 -140
  50. package/dist/lib/validation/at-rules/container.js +75 -97
  51. package/dist/lib/validation/at-rules/counter-style.js +9 -8
  52. package/dist/lib/validation/at-rules/custom-media.js +13 -15
  53. package/dist/lib/validation/at-rules/document.js +22 -27
  54. package/dist/lib/validation/at-rules/font-feature-values.js +8 -8
  55. package/dist/lib/validation/at-rules/import.js +30 -81
  56. package/dist/lib/validation/at-rules/keyframes.js +18 -22
  57. package/dist/lib/validation/at-rules/layer.js +5 -5
  58. package/dist/lib/validation/at-rules/media.js +42 -52
  59. package/dist/lib/validation/at-rules/namespace.js +19 -23
  60. package/dist/lib/validation/at-rules/page-margin-box.js +15 -18
  61. package/dist/lib/validation/at-rules/page.js +8 -7
  62. package/dist/lib/validation/at-rules/supports.js +73 -82
  63. package/dist/lib/validation/at-rules/when.js +32 -36
  64. package/dist/lib/validation/atrule.js +15 -14
  65. package/dist/lib/validation/config.js +24 -1
  66. package/dist/lib/validation/config.json.js +611 -111
  67. package/dist/lib/validation/parser/parse.js +206 -212
  68. package/dist/lib/validation/parser/types.js +1 -1
  69. package/dist/lib/validation/selector.js +3 -3
  70. package/dist/lib/validation/syntax.js +984 -0
  71. package/dist/lib/validation/syntaxes/complex-selector-list.js +10 -11
  72. package/dist/lib/validation/syntaxes/complex-selector.js +10 -11
  73. package/dist/lib/validation/syntaxes/compound-selector.js +40 -50
  74. package/dist/lib/validation/syntaxes/family-name.js +9 -8
  75. package/dist/lib/validation/syntaxes/keyframe-block-list.js +4 -3
  76. package/dist/lib/validation/syntaxes/keyframe-selector.js +15 -18
  77. package/dist/lib/validation/syntaxes/layer-name.js +6 -5
  78. package/dist/lib/validation/syntaxes/relative-selector-list.js +7 -6
  79. package/dist/lib/validation/syntaxes/relative-selector.js +2 -1
  80. package/dist/lib/validation/syntaxes/url.js +18 -22
  81. package/dist/lib/validation/utils/list.js +2 -1
  82. package/dist/lib/validation/utils/whitespace.js +2 -1
  83. package/dist/node/index.js +4 -2
  84. package/dist/node/load.js +5 -0
  85. package/dist/web/index.js +4 -2
  86. package/dist/web/load.js +5 -0
  87. package/package.json +14 -13
@@ -4,6 +4,7 @@ import { EnumToken } from '../../ast/types.js';
4
4
  import '../../ast/minify.js';
5
5
  import '../../ast/walk.js';
6
6
  import { parseString } from '../parse.js';
7
+ import '../tokenize.js';
7
8
  import '../../renderer/color/utils/constants.js';
8
9
  import '../../renderer/sourcemap/lib/encode.js';
9
10
  import { PropertyMap } from './map.js';
@@ -23,61 +24,63 @@ class PropertyList {
23
24
  val: Array.isArray(value) ? value : parseString(String(value))
24
25
  });
25
26
  }
26
- add(declaration) {
27
- if (declaration.typ != EnumToken.DeclarationNodeType || !this.options.removeDuplicateDeclarations) {
28
- this.declarations.set(Number(Math.random().toString().slice(2)).toString(36), declaration);
29
- return this;
30
- }
31
- if (!this.options.computeShorthand) {
32
- this.declarations.set(declaration.nam, declaration);
33
- return this;
34
- }
35
- let propertyName = declaration.nam;
36
- let shortHandType;
37
- let shorthand;
38
- if (propertyName in config.properties) {
39
- // @ts-ignore
40
- if ('map' in config.properties[propertyName]) {
41
- shortHandType = 'map';
27
+ add(...declarations) {
28
+ for (const declaration of declarations) {
29
+ if (declaration.typ != EnumToken.DeclarationNodeType || !this.options.removeDuplicateDeclarations) {
30
+ this.declarations.set(Number(Math.random().toString().slice(2)).toString(36), declaration);
31
+ continue;
32
+ }
33
+ if (!this.options.computeShorthand) {
34
+ this.declarations.set(declaration.nam, declaration);
35
+ continue;
36
+ }
37
+ let propertyName = declaration.nam;
38
+ let shortHandType;
39
+ let shorthand;
40
+ if (propertyName in config.properties) {
42
41
  // @ts-ignore
43
- shorthand = config.properties[propertyName].map;
42
+ if ('map' in config.properties[propertyName]) {
43
+ shortHandType = 'map';
44
+ // @ts-ignore
45
+ shorthand = config.properties[propertyName].map;
46
+ }
47
+ else {
48
+ shortHandType = 'set';
49
+ // @ts-ignore
50
+ shorthand = config.properties[propertyName].shorthand;
51
+ }
44
52
  }
45
- else {
46
- shortHandType = 'set';
53
+ else if (propertyName in config.map) {
54
+ shortHandType = 'map';
47
55
  // @ts-ignore
48
- shorthand = config.properties[propertyName].shorthand;
56
+ shorthand = config.map[propertyName].shorthand;
49
57
  }
50
- }
51
- else if (propertyName in config.map) {
52
- shortHandType = 'map';
53
58
  // @ts-ignore
54
- shorthand = config.map[propertyName].shorthand;
55
- }
56
- // @ts-ignore
57
- if (shortHandType == 'map') {
58
- // @ts-ignore
59
- if (!this.declarations.has(shorthand)) {
59
+ if (shortHandType == 'map') {
60
+ // @ts-ignore
61
+ if (!this.declarations.has(shorthand)) {
62
+ // @ts-ignore
63
+ this.declarations.set(shorthand, new PropertyMap(config.map[shorthand]));
64
+ }
60
65
  // @ts-ignore
61
- this.declarations.set(shorthand, new PropertyMap(config.map[shorthand]));
66
+ this.declarations.get(shorthand).add(declaration);
67
+ // return this;
62
68
  }
63
69
  // @ts-ignore
64
- this.declarations.get(shorthand).add(declaration);
65
- // return this;
66
- }
67
- // @ts-ignore
68
- else if (shortHandType == 'set') {
69
- // @ts-ignore
70
- // const shorthand: string = <string>config.properties[propertyName].shorthand;
71
- if (!this.declarations.has(shorthand)) {
70
+ else if (shortHandType == 'set') {
72
71
  // @ts-ignore
73
- this.declarations.set(shorthand, new PropertySet(config.properties[shorthand]));
72
+ // const shorthand: string = <string>config.properties[propertyName].shorthand;
73
+ if (!this.declarations.has(shorthand)) {
74
+ // @ts-ignore
75
+ this.declarations.set(shorthand, new PropertySet(config.properties[shorthand]));
76
+ }
77
+ // @ts-ignore
78
+ this.declarations.get(shorthand).add(declaration);
79
+ // return this;
80
+ }
81
+ else {
82
+ this.declarations.set(propertyName, declaration);
74
83
  }
75
- // @ts-ignore
76
- this.declarations.get(shorthand).add(declaration);
77
- // return this;
78
- }
79
- else {
80
- this.declarations.set(propertyName, declaration);
81
84
  }
82
85
  return this;
83
86
  }
@@ -5,6 +5,7 @@ import { EnumToken } from '../../ast/types.js';
5
5
  import '../../ast/minify.js';
6
6
  import '../../ast/walk.js';
7
7
  import { parseString } from '../parse.js';
8
+ import '../tokenize.js';
8
9
  import { renderToken } from '../../renderer/render.js';
9
10
  import '../../renderer/color/utils/constants.js';
10
11
  import { PropertySet } from './set.js';
@@ -3,8 +3,9 @@ import { EnumToken } from '../../ast/types.js';
3
3
  import '../../ast/minify.js';
4
4
  import '../../ast/walk.js';
5
5
  import '../parse.js';
6
- import { isLength } from '../../syntax/syntax.js';
6
+ import '../tokenize.js';
7
7
  import '../utils/config.js';
8
+ import { isLength } from '../../syntax/syntax.js';
8
9
  import '../../renderer/color/utils/constants.js';
9
10
  import '../../renderer/sourcemap/lib/encode.js';
10
11