@tbela99/css-parser 1.1.1-alpha4 → 1.2.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 (101) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/README.md +53 -6
  3. package/dist/index-umd-web.js +4195 -3375
  4. package/dist/index.cjs +5468 -4648
  5. package/dist/index.d.ts +42 -31
  6. package/dist/lib/ast/expand.js +81 -65
  7. package/dist/lib/ast/features/calc.js +37 -35
  8. package/dist/lib/ast/features/inlinecssvariables.js +25 -17
  9. package/dist/lib/ast/features/prefix.js +22 -19
  10. package/dist/lib/ast/features/shorthand.js +1 -1
  11. package/dist/lib/ast/features/transform.js +17 -2
  12. package/dist/lib/ast/math/expression.js +184 -159
  13. package/dist/lib/ast/math/math.js +22 -20
  14. package/dist/lib/ast/minify.js +249 -200
  15. package/dist/lib/ast/transform/compute.js +48 -38
  16. package/dist/lib/ast/transform/matrix.js +6 -5
  17. package/dist/lib/ast/transform/minify.js +31 -34
  18. package/dist/lib/ast/transform/utils.js +76 -16
  19. package/dist/lib/ast/types.js +32 -1
  20. package/dist/lib/fs/resolve.js +1 -14
  21. package/dist/lib/parser/declaration/list.js +1 -1
  22. package/dist/lib/parser/declaration/map.js +1 -1
  23. package/dist/lib/parser/declaration/set.js +1 -1
  24. package/dist/lib/parser/parse.js +19 -95
  25. package/dist/lib/parser/tokenize.js +1 -13
  26. package/dist/lib/parser/utils/declaration.js +1 -1
  27. package/dist/lib/parser/utils/type.js +1 -1
  28. package/dist/lib/renderer/render.js +44 -168
  29. package/dist/lib/{renderer → syntax}/color/a98rgb.js +2 -2
  30. package/dist/lib/syntax/color/cmyk.js +104 -0
  31. package/dist/lib/{renderer → syntax}/color/color-mix.js +20 -21
  32. package/dist/lib/syntax/color/color.js +581 -0
  33. package/dist/lib/syntax/color/hex.js +179 -0
  34. package/dist/lib/syntax/color/hsl.js +201 -0
  35. package/dist/lib/syntax/color/hwb.js +185 -0
  36. package/dist/lib/syntax/color/lab.js +262 -0
  37. package/dist/lib/syntax/color/lch.js +194 -0
  38. package/dist/lib/syntax/color/oklab.js +237 -0
  39. package/dist/lib/syntax/color/oklch.js +166 -0
  40. package/dist/lib/{renderer → syntax}/color/p3.js +3 -3
  41. package/dist/lib/{renderer → syntax}/color/rec2020.js +11 -11
  42. package/dist/lib/{renderer → syntax}/color/relativecolor.js +53 -40
  43. package/dist/lib/syntax/color/rgb.js +140 -0
  44. package/dist/lib/{renderer → syntax}/color/srgb.js +58 -46
  45. package/dist/lib/{renderer → syntax}/color/utils/components.js +7 -7
  46. package/dist/lib/{renderer → syntax}/color/utils/constants.js +7 -34
  47. package/dist/lib/syntax/color/utils/distance.js +30 -0
  48. package/dist/lib/{renderer → syntax}/color/xyz.js +27 -14
  49. package/dist/lib/{renderer → syntax}/color/xyzd50.js +8 -8
  50. package/dist/lib/syntax/syntax.js +77 -67
  51. package/dist/lib/syntax/utils.js +70 -0
  52. package/dist/lib/validation/at-rules/container.js +1 -1
  53. package/dist/lib/validation/at-rules/counter-style.js +1 -1
  54. package/dist/lib/validation/at-rules/custom-media.js +1 -1
  55. package/dist/lib/validation/at-rules/document.js +1 -1
  56. package/dist/lib/validation/at-rules/font-feature-values.js +2 -2
  57. package/dist/lib/validation/at-rules/import.js +1 -1
  58. package/dist/lib/validation/at-rules/keyframes.js +14 -13
  59. package/dist/lib/validation/at-rules/layer.js +1 -1
  60. package/dist/lib/validation/at-rules/media.js +1 -1
  61. package/dist/lib/validation/at-rules/namespace.js +1 -1
  62. package/dist/lib/validation/at-rules/page-margin-box.js +1 -1
  63. package/dist/lib/validation/at-rules/page.js +1 -1
  64. package/dist/lib/validation/at-rules/supports.js +1 -1
  65. package/dist/lib/validation/at-rules/when.js +1 -1
  66. package/dist/lib/validation/atrule.js +2 -2
  67. package/dist/lib/validation/config.js +4 -3
  68. package/dist/lib/validation/config.json.js +1 -1
  69. package/dist/lib/validation/parser/parse.js +12 -7
  70. package/dist/lib/validation/selector.js +9 -8
  71. package/dist/lib/validation/syntax.js +171 -132
  72. package/dist/lib/validation/syntaxes/complex-selector-list.js +13 -19
  73. package/dist/lib/validation/syntaxes/complex-selector.js +1 -1
  74. package/dist/lib/validation/syntaxes/compound-selector.js +5 -24
  75. package/dist/lib/validation/syntaxes/family-name.js +36 -39
  76. package/dist/lib/validation/syntaxes/keyframe-selector.js +14 -22
  77. package/dist/lib/validation/syntaxes/layer-name.js +1 -1
  78. package/dist/lib/validation/syntaxes/relative-selector-list.js +27 -25
  79. package/dist/lib/validation/syntaxes/relative-selector.js +1 -1
  80. package/dist/lib/validation/syntaxes/url.js +35 -33
  81. package/dist/lib/validation/utils/list.js +10 -9
  82. package/dist/lib/validation/utils/whitespace.js +1 -1
  83. package/dist/node/index.js +4 -2
  84. package/dist/web/index.js +4 -2
  85. package/package.json +4 -4
  86. package/.editorconfig +0 -484
  87. package/dist/lib/ast/transform/convert.js +0 -33
  88. package/dist/lib/ast/utils/utils.js +0 -104
  89. package/dist/lib/renderer/color/color.js +0 -654
  90. package/dist/lib/renderer/color/hex.js +0 -105
  91. package/dist/lib/renderer/color/hsl.js +0 -125
  92. package/dist/lib/renderer/color/hwb.js +0 -103
  93. package/dist/lib/renderer/color/lab.js +0 -148
  94. package/dist/lib/renderer/color/lch.js +0 -90
  95. package/dist/lib/renderer/color/oklab.js +0 -131
  96. package/dist/lib/renderer/color/oklch.js +0 -75
  97. package/dist/lib/renderer/color/rgb.js +0 -50
  98. package/dist/lib/validation/syntaxes/keyframe-block-list.js +0 -28
  99. package/dist/lib/{renderer → syntax}/color/hsv.js +0 -0
  100. package/dist/lib/{renderer → syntax}/color/prophotorgb.js +1 -1
  101. /package/dist/lib/{renderer → syntax}/color/utils/matrix.js +0 -0
@@ -0,0 +1,104 @@
1
+ import { ColorType, EnumToken } from '../../ast/types.js';
2
+ import '../../ast/minify.js';
3
+ import '../../ast/walk.js';
4
+ import '../../parser/parse.js';
5
+ import '../../parser/tokenize.js';
6
+ import '../../parser/utils/config.js';
7
+ import { color2srgbvalues } from './color.js';
8
+ import { hsl2srgbvalues } from './rgb.js';
9
+ import './utils/constants.js';
10
+ import { lch2srgbvalues, lab2srgbvalues, oklch2srgbvalues, oklab2srgbvalues, hwb2srgbvalues, rgb2srgbvalues } from './srgb.js';
11
+ import '../../renderer/sourcemap/lib/encode.js';
12
+
13
+ function rgb2cmykToken(token) {
14
+ const components = rgb2srgbvalues(token);
15
+ if (components == null || components.length < 3) {
16
+ return null;
17
+ }
18
+ // @ts-ignore
19
+ return cmyktoken(srgb2cmykvalues(...components));
20
+ }
21
+ function hsl2cmykToken(token) {
22
+ const values = hsl2srgbvalues(token);
23
+ if (values == null) {
24
+ return null;
25
+ }
26
+ // @ts-ignore
27
+ return cmyktoken(srgb2cmykvalues(...values));
28
+ }
29
+ function hwb2cmykToken(token) {
30
+ const values = hwb2srgbvalues(token);
31
+ if (values == null) {
32
+ return null;
33
+ }
34
+ // @ts-ignore
35
+ return cmyktoken(srgb2cmykvalues(...values));
36
+ }
37
+ function lab2cmykToken(token) {
38
+ const components = lab2srgbvalues(token);
39
+ if (components == null || components.length < 3) {
40
+ return null;
41
+ }
42
+ // @ts-ignore
43
+ return cmyktoken(srgb2cmykvalues(...components));
44
+ }
45
+ function lch2cmykToken(token) {
46
+ const components = lch2srgbvalues(token);
47
+ if (components == null || components.length < 3) {
48
+ return null;
49
+ }
50
+ // @ts-ignore
51
+ return cmyktoken(srgb2cmykvalues(...components));
52
+ }
53
+ function oklab2cmyk(token) {
54
+ const components = oklab2srgbvalues(token);
55
+ if (components == null || components.length < 3) {
56
+ return null;
57
+ }
58
+ // @ts-ignore
59
+ return cmyktoken(srgb2cmykvalues(...components));
60
+ }
61
+ function oklch2cmykToken(token) {
62
+ const components = oklch2srgbvalues(token);
63
+ if (components == null || components.length < 3) {
64
+ return null;
65
+ }
66
+ // @ts-ignore
67
+ return cmyktoken(srgb2cmykvalues(...components));
68
+ }
69
+ function color2cmykToken(token) {
70
+ const values = color2srgbvalues(token);
71
+ if (values == null) {
72
+ return null;
73
+ }
74
+ // @ts-ignore
75
+ return cmyktoken(srgb2cmykvalues(...values));
76
+ }
77
+ function srgb2cmykvalues(r, g, b, a = null) {
78
+ const k = 1 - Math.max(r, g, b);
79
+ const c = k == 1 ? 0 : (1 - r - k) / (1 - k);
80
+ const m = k == 1 ? 0 : (1 - g - k) / (1 - k);
81
+ const y = k == 1 ? 0 : (1 - b - k) / (1 - k);
82
+ const result = [c, m, y, k];
83
+ if (a != null && a < 1) {
84
+ result.push(a);
85
+ }
86
+ return result;
87
+ }
88
+ function cmyktoken(values) {
89
+ return {
90
+ typ: EnumToken.ColorTokenType,
91
+ val: 'device-cmyk',
92
+ chi: values.reduce((acc, curr, index) => index < 4 ? [...acc, {
93
+ typ: EnumToken.PercentageTokenType,
94
+ // @ts-ignore
95
+ val: (curr * 100) + ''
96
+ }] : [...acc, {
97
+ typ: EnumToken.LiteralTokenType,
98
+ val: '/'
99
+ }, { typ: EnumToken.PercentageTokenType, val: (curr * 100).toFixed() }], []),
100
+ kin: ColorType.DEVICE_CMYK
101
+ };
102
+ }
103
+
104
+ export { color2cmykToken, hsl2cmykToken, hwb2cmykToken, lab2cmykToken, lch2cmykToken, oklab2cmyk, oklch2cmykToken, rgb2cmykToken, srgb2cmykvalues };
@@ -1,28 +1,27 @@
1
- import { EnumToken } from '../../ast/types.js';
1
+ import { EnumToken, ColorType } from '../../ast/types.js';
2
2
  import '../../ast/minify.js';
3
3
  import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
5
  import '../../parser/tokenize.js';
6
6
  import '../../parser/utils/config.js';
7
- import { isRectangularOrthogonalColorspace, isPolarColorspace } from '../../syntax/syntax.js';
7
+ import { isRectangularOrthogonalColorspace, isPolarColorspace } from '../syntax.js';
8
8
  import { getNumber } from './color.js';
9
9
  import { srgb2rgb } from './rgb.js';
10
- import { ColorKind } from './utils/constants.js';
10
+ import './utils/constants.js';
11
11
  import { getComponents } from './utils/components.js';
12
- import { srgb2hwb } from './hwb.js';
13
- import { srgb2hsl } from './hsl.js';
12
+ import { srgb2oklab } from './oklab.js';
14
13
  import { srgbvalues, srgb2lsrgbvalues } from './srgb.js';
14
+ import { srgb2hwb } from './hwb.js';
15
+ import { srgb2hslvalues } from './hsl.js';
15
16
  import { srgb2lch, xyz2lchvalues } from './lch.js';
16
- import { srgb2lab } from './lab.js';
17
+ import { srgb2labvalues } from './lab.js';
17
18
  import { srgb2p3values } from './p3.js';
18
19
  import { srgb2oklch } from './oklch.js';
19
- import { srgb2oklab } from './oklab.js';
20
- import { srgb2a98values } from './a98rgb.js';
21
20
  import { srgb2prophotorgbvalues } from './prophotorgb.js';
22
- import { srgb2xyz } from './xyz.js';
21
+ import { srgb2xyz_d50 } from './xyz.js';
23
22
  import { XYZ_D65_to_D50, xyzd502lch } from './xyzd50.js';
24
23
  import { srgb2rec2020values } from './rec2020.js';
25
- import '../sourcemap/lib/encode.js';
24
+ import '../../renderer/sourcemap/lib/encode.js';
26
25
 
27
26
  function interpolateHue(interpolationMethod, h1, h2) {
28
27
  switch (interpolationMethod.val) {
@@ -174,9 +173,9 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
174
173
  case 'xyz-d65':
175
174
  case 'xyz-d50':
176
175
  // @ts-ignore
177
- values1 = srgb2xyz(...values1);
176
+ values1 = srgb2xyz_d50(...values1);
178
177
  // @ts-ignore
179
- values2 = srgb2xyz(...values2);
178
+ values2 = srgb2xyz_d50(...values2);
180
179
  if (colorSpace.val == 'xyz-d50') {
181
180
  // @ts-ignore
182
181
  values1 = XYZ_D65_to_D50(...values1);
@@ -192,9 +191,9 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
192
191
  break;
193
192
  case 'hsl':
194
193
  // @ts-ignore
195
- values1 = srgb2hsl(...values1);
194
+ values1 = srgb2hslvalues(...values1);
196
195
  // @ts-ignore
197
- values2 = srgb2hsl(...values2);
196
+ values2 = srgb2hslvalues(...values2);
198
197
  break;
199
198
  case 'hwb':
200
199
  // @ts-ignore
@@ -204,9 +203,9 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
204
203
  break;
205
204
  case 'lab':
206
205
  // @ts-ignore
207
- values1 = srgb2lab(...values1);
206
+ values1 = srgb2labvalues(...values1);
208
207
  // @ts-ignore
209
- values2 = srgb2lab(...values2);
208
+ values2 = srgb2labvalues(...values2);
210
209
  break;
211
210
  case 'lch':
212
211
  // @ts-ignore
@@ -230,8 +229,8 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
230
229
  return null;
231
230
  }
232
231
  const lchSpaces = ['lch', 'oklch'];
233
- const colorSpace1 = ColorKind[color1.kin].toLowerCase().replaceAll('_', '-');
234
- const colorSpace2 = ColorKind[color2.kin].toLowerCase().replaceAll('_', '-');
232
+ const colorSpace1 = ColorType[color1.kin].toLowerCase().replaceAll('_', '-');
233
+ const colorSpace2 = ColorType[color2.kin].toLowerCase().replaceAll('_', '-');
235
234
  // powerless
236
235
  if (lchSpaces.includes(colorSpace1) || lchSpaces.includes(colorSpace.val)) {
237
236
  if ((components1[2].typ == EnumToken.IdenTokenType && components1[2].val == 'none') || values1[2] == 0) {
@@ -279,7 +278,7 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
279
278
  val: String(v)
280
279
  };
281
280
  }),
282
- kin: ColorKind.LCH
281
+ kin: ColorType.LCH
283
282
  };
284
283
  case 'srgb':
285
284
  case 'srgb-linear':
@@ -290,7 +289,7 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
290
289
  typ: EnumToken.ColorTokenType,
291
290
  val: 'color',
292
291
  chi: calculate(),
293
- kin: ColorKind.COLOR,
292
+ kin: ColorType.COLOR,
294
293
  cal: 'col'
295
294
  };
296
295
  case 'rgb':
@@ -329,7 +328,7 @@ function colorMix(colorSpace, hueInterpolationMethod, color1, percentage1, color
329
328
  typ: EnumToken.ColorTokenType,
330
329
  val: colorSpace.val,
331
330
  chi: calculate().slice(1),
332
- kin: ColorKind[colorSpace.val.toLowerCase().replaceAll('-', '_')]
331
+ kin: ColorType[colorSpace.val.toUpperCase().replaceAll('-', '_')]
333
332
  };
334
333
  if (colorSpace.val == 'hsl' || colorSpace.val == 'hwb') {
335
334
  // @ts-ignore