@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
@@ -1,131 +0,0 @@
1
- import { multiplyMatrices } from './utils/matrix.js';
2
- import './utils/constants.js';
3
- import { getComponents } from './utils/components.js';
4
- import { srgb2lsrgbvalues, lch2srgb, lab2srgb, hwb2srgb, hsl2srgb, rgb2srgb, hex2srgb, lsrgb2srgbvalues } from './srgb.js';
5
- import { getNumber } from './color.js';
6
- import { EnumToken } from '../../ast/types.js';
7
- import '../../ast/minify.js';
8
- import '../../ast/walk.js';
9
- import '../../parser/parse.js';
10
- import '../../parser/tokenize.js';
11
- import '../../parser/utils/config.js';
12
- import { lch2labvalues } from './lab.js';
13
- import { getOKLCHComponents } from './oklch.js';
14
- import '../sourcemap/lib/encode.js';
15
-
16
- function hex2oklab(token) {
17
- // @ts-ignore
18
- return srgb2oklab(...hex2srgb(token));
19
- }
20
- function rgb2oklab(token) {
21
- // @ts-ignore
22
- return srgb2oklab(...rgb2srgb(token));
23
- }
24
- function hsl2oklab(token) {
25
- // @ts-ignore
26
- return srgb2oklab(...hsl2srgb(token));
27
- }
28
- function hwb2oklab(token) {
29
- // @ts-ignore
30
- return srgb2oklab(...hwb2srgb(token));
31
- }
32
- function lab2oklab(token) {
33
- // @ts-ignore
34
- return srgb2oklab(...lab2srgb(token));
35
- }
36
- function lch2oklab(token) {
37
- // @ts-ignore
38
- return srgb2oklab(...lch2srgb(token));
39
- }
40
- function oklch2oklab(token) {
41
- // @ts-ignore
42
- return lch2labvalues(...getOKLCHComponents(token));
43
- }
44
- function srgb2oklab(r, g, blue, alpha) {
45
- [r, g, blue] = srgb2lsrgbvalues(r, g, blue);
46
- let L = Math.cbrt(0.41222147079999993 * r + 0.5363325363 * g + 0.0514459929 * blue);
47
- let M = Math.cbrt(0.2119034981999999 * r + 0.6806995450999999 * g + 0.1073969566 * blue);
48
- let S = Math.cbrt(0.08830246189999998 * r + 0.2817188376 * g + 0.6299787005000002 * blue);
49
- const l = 0.2104542553 * L + 0.793617785 * M - 0.0040720468 * S;
50
- const a = r == g && g == blue ? 0 : 1.9779984951 * L - 2.428592205 * M + 0.4505937099 * S;
51
- const b = r == g && g == blue ? 0 : 0.0259040371 * L + 0.7827717662 * M - 0.808675766 * S;
52
- return alpha == null ? [l, a, b] : [l, a, b, alpha];
53
- }
54
- function getOKLABComponents(token) {
55
- const components = getComponents(token);
56
- if (components == null) {
57
- return null;
58
- }
59
- for (let i = 0; i < components.length; i++) {
60
- if (![EnumToken.NumberTokenType, EnumToken.PercentageTokenType, EnumToken.AngleTokenType, EnumToken.IdenTokenType].includes(components[i].typ)) {
61
- return null;
62
- }
63
- }
64
- // @ts-ignore
65
- let t = components[0];
66
- // @ts-ignore
67
- const l = getNumber(t);
68
- // @ts-ignore
69
- t = components[1];
70
- // @ts-ignore
71
- const a = getNumber(t) * (t.typ == EnumToken.PercentageTokenType ? .4 : 1);
72
- // @ts-ignore
73
- t = components[2];
74
- // @ts-ignore
75
- const b = getNumber(t) * (t.typ == EnumToken.PercentageTokenType ? .4 : 1);
76
- // @ts-ignore
77
- t = components[3];
78
- // @ts-ignore
79
- const alpha = t == null || (t.typ == EnumToken.IdenTokenType && t.val == 'none') ? 1 : getNumber(t);
80
- const rgb = [l, a, b];
81
- if (alpha != 1 && alpha != null) {
82
- rgb.push(alpha);
83
- }
84
- return rgb;
85
- }
86
- function OKLab_to_XYZ(l, a, b, alpha = null) {
87
- // Given OKLab, convert to XYZ relative to D65
88
- const LMStoXYZ = [
89
- [1.2268798758459243, -0.5578149944602171, 0.2813910456659647],
90
- [-0.0405757452148008, 1.1122868032803170, -0.0717110580655164],
91
- [-0.0763729366746601, -0.4214933324022432, 1.5869240198367816]
92
- ];
93
- const OKLabtoLMS = [
94
- [1.0000000000000000, 0.3963377773761749, 0.2158037573099136],
95
- [1.0000000000000000, -0.1055613458156586, -0.0638541728258133],
96
- [1.0000000000000000, -0.0894841775298119, -1.2914855480194092]
97
- ];
98
- const LMSnl = multiplyMatrices(OKLabtoLMS, [l, a, b]);
99
- const xyz = multiplyMatrices(LMStoXYZ, LMSnl.map((c) => c ** 3));
100
- if (alpha != null) {
101
- xyz.push(alpha);
102
- }
103
- return xyz;
104
- }
105
- // from https://www.w3.org/TR/css-color-4/#color-conversion-code
106
- function OKLab_to_sRGB(l, a, b) {
107
- let L = Math.pow(l * 0.99999999845051981432 +
108
- 0.39633779217376785678 * a +
109
- 0.21580375806075880339 * b, 3);
110
- let M = Math.pow(l * 1.0000000088817607767 -
111
- 0.1055613423236563494 * a -
112
- 0.063854174771705903402 * b, 3);
113
- let S = Math.pow(l * 1.0000000546724109177 -
114
- 0.089484182094965759684 * a -
115
- 1.2914855378640917399 * b, 3);
116
- return lsrgb2srgbvalues(
117
- /* r: */
118
- 4.076741661347994 * L -
119
- 3.307711590408193 * M +
120
- 0.230969928729428 * S,
121
- /* g: */
122
- -1.2684380040921763 * L +
123
- 2.6097574006633715 * M -
124
- 0.3413193963102197 * S,
125
- /* b: */
126
- -0.004196086541837188 * L -
127
- 0.7034186144594493 * M +
128
- 1.7076147009309444 * S);
129
- }
130
-
131
- export { OKLab_to_XYZ, OKLab_to_sRGB, getOKLABComponents, hex2oklab, hsl2oklab, hwb2oklab, lab2oklab, lch2oklab, oklch2oklab, rgb2oklab, srgb2oklab };
@@ -1,75 +0,0 @@
1
- import './utils/constants.js';
2
- import { getComponents } from './utils/components.js';
3
- import { getNumber, getAngle } from './color.js';
4
- import { EnumToken } from '../../ast/types.js';
5
- import '../../ast/minify.js';
6
- import '../../ast/walk.js';
7
- import '../../parser/parse.js';
8
- import '../../parser/tokenize.js';
9
- import '../../parser/utils/config.js';
10
- import { lab2lchvalues } from './lch.js';
11
- import { srgb2oklab, lch2oklab, getOKLABComponents, lab2oklab, hwb2oklab, hsl2oklab, rgb2oklab, hex2oklab } from './oklab.js';
12
- import '../sourcemap/lib/encode.js';
13
-
14
- function hex2oklch(token) {
15
- // @ts-ignore
16
- return lab2lchvalues(...hex2oklab(token));
17
- }
18
- function rgb2oklch(token) {
19
- // @ts-ignore
20
- return lab2lchvalues(...rgb2oklab(token));
21
- }
22
- function hsl2oklch(token) {
23
- // @ts-ignore
24
- return lab2lchvalues(...hsl2oklab(token));
25
- }
26
- function hwb2oklch(token) {
27
- // @ts-ignore
28
- return lab2lchvalues(...hwb2oklab(token));
29
- }
30
- function lab2oklch(token) {
31
- // @ts-ignore
32
- return lab2lchvalues(...lab2oklab(token));
33
- }
34
- function lch2oklch(token) {
35
- // @ts-ignore
36
- return lab2lchvalues(...lch2oklab(token));
37
- }
38
- function oklab2oklch(token) {
39
- // @ts-ignore
40
- return lab2lchvalues(...getOKLABComponents(token));
41
- }
42
- function srgb2oklch(r, g, blue, alpha) {
43
- // @ts-ignore
44
- return lab2lchvalues(...srgb2oklab(r, g, blue, alpha));
45
- }
46
- function getOKLCHComponents(token) {
47
- const components = getComponents(token);
48
- if (components == null) {
49
- return null;
50
- }
51
- for (let i = 0; i < components.length; i++) {
52
- if (![EnumToken.NumberTokenType, EnumToken.PercentageTokenType, EnumToken.AngleTokenType, EnumToken.IdenTokenType].includes(components[i].typ)) {
53
- return [];
54
- }
55
- }
56
- // @ts-ignore
57
- let t = components[0];
58
- // @ts-ignore
59
- const l = getNumber(t);
60
- // @ts-ignore
61
- t = components[1];
62
- // @ts-ignore
63
- const c = getNumber(t) * (t.typ == EnumToken.PercentageTokenType ? .4 : 1);
64
- // @ts-ignore
65
- t = components[2];
66
- // @ts-ignore
67
- const h = getAngle(t) * 360;
68
- // @ts-ignore
69
- t = components[3];
70
- // @ts-ignore
71
- const alpha = t == null || (t.typ == EnumToken.IdenTokenType && t.val == 'none') ? 1 : getNumber(t);
72
- return [l, c, h, alpha];
73
- }
74
-
75
- export { getOKLCHComponents, hex2oklch, hsl2oklch, hwb2oklch, lab2oklch, lch2oklch, oklab2oklch, rgb2oklch, srgb2oklch };
@@ -1,50 +0,0 @@
1
- import { minmax } from './color.js';
2
- import { COLORS_NAMES, ColorKind } from './utils/constants.js';
3
- import '../../ast/types.js';
4
- import '../../ast/minify.js';
5
- import '../../ast/walk.js';
6
- import '../../parser/parse.js';
7
- import '../../parser/tokenize.js';
8
- import '../../parser/utils/config.js';
9
- import { expandHexValue } from './hex.js';
10
- import { hslvalues, hsl2srgbvalues, hwb2srgb, cmyk2srgb, oklab2srgb, oklch2srgb, lab2srgb, lch2srgb } from './srgb.js';
11
- import '../sourcemap/lib/encode.js';
12
-
13
- function srgb2rgb(value) {
14
- return minmax(Math.round(value * 255), 0, 255);
15
- }
16
- function hex2rgb(token) {
17
- const value = expandHexValue(token.kin == ColorKind.LIT ? COLORS_NAMES[token.val.toLowerCase()] : token.val);
18
- const rgb = [];
19
- for (let i = 1; i < value.length; i += 2) {
20
- rgb.push(parseInt(value.slice(i, i + 2), 16));
21
- }
22
- return rgb;
23
- }
24
- function hwb2rgb(token) {
25
- return hwb2srgb(token)?.map?.(srgb2rgb) ?? null;
26
- }
27
- function hsl2rgb(token) {
28
- let { h, s, l, a } = hslvalues(token) ?? {};
29
- if (h == null || s == null || l == null) {
30
- return null;
31
- }
32
- return hsl2srgbvalues(h, s, l, a).map((t) => minmax(Math.round(t * 255), 0, 255));
33
- }
34
- function cmyk2rgb(token) {
35
- return cmyk2srgb(token)?.map?.(srgb2rgb) ?? null;
36
- }
37
- function oklab2rgb(token) {
38
- return oklab2srgb(token)?.map?.(srgb2rgb) ?? null;
39
- }
40
- function oklch2rgb(token) {
41
- return oklch2srgb(token)?.map?.(srgb2rgb) ?? null;
42
- }
43
- function lab2rgb(token) {
44
- return lab2srgb(token)?.map?.(srgb2rgb) ?? null;
45
- }
46
- function lch2rgb(token) {
47
- return lch2srgb(token)?.map?.(srgb2rgb) ?? null;
48
- }
49
-
50
- export { cmyk2rgb, hex2rgb, hsl2rgb, hwb2rgb, lab2rgb, lch2rgb, oklab2rgb, oklch2rgb, srgb2rgb };
@@ -1,28 +0,0 @@
1
- import { EnumToken, SyntaxValidationResult } 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 '../../renderer/color/utils/constants.js';
8
- import '../../renderer/sourcemap/lib/encode.js';
9
- import { validateKeyframeSelector } from './keyframe-selector.js';
10
-
11
- function validateKeyframeBlockList(tokens, atRule, options) {
12
- let i = 0;
13
- let j = 0;
14
- let result = null;
15
- while (i + 1 < tokens.length) {
16
- if (tokens[++i].typ == EnumToken.CommaTokenType) {
17
- result = validateKeyframeSelector(tokens.slice(j, i));
18
- if (result.valid == SyntaxValidationResult.Drop) {
19
- return result;
20
- }
21
- j = i + 1;
22
- i = j;
23
- }
24
- }
25
- return validateKeyframeSelector(i == j ? tokens.slice(i) : tokens.slice(j, i + 1));
26
- }
27
-
28
- export { validateKeyframeBlockList };
File without changes
@@ -1,5 +1,5 @@
1
- import { srgb2xyz } from './xyz.js';
2
1
  import { XYZ_D65_to_D50, xyzd502srgb } from './xyzd50.js';
2
+ import { srgb2xyz } from './xyz.js';
3
3
 
4
4
  function prophotorgb2srgbvalues(r, g, b, a = null) {
5
5
  // @ts-ignore