@tbela99/css-parser 1.4.2 → 1.4.4

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 (122) hide show
  1. package/CHANGELOG.md +354 -4
  2. package/README.md +69 -1077
  3. package/dist/config.json.js +76 -3
  4. package/dist/index-umd-web.js +26838 -18743
  5. package/dist/index.cjs +26819 -18731
  6. package/dist/index.d.ts +2471 -1884
  7. package/dist/lib/ast/clone.js +46 -0
  8. package/dist/lib/ast/expand.js +90 -65
  9. package/dist/lib/ast/features/calc.js +86 -43
  10. package/dist/lib/ast/features/if.js +221 -0
  11. package/dist/lib/ast/features/index.js +1 -0
  12. package/dist/lib/ast/features/inlinecssvariables.js +33 -28
  13. package/dist/lib/ast/features/prefix.js +406 -44
  14. package/dist/lib/ast/features/shorthand.js +6 -9
  15. package/dist/lib/ast/features/transform.js +14 -15
  16. package/dist/lib/ast/find.js +175 -0
  17. package/dist/lib/ast/math/expression.js +145 -99
  18. package/dist/lib/ast/math/math.js +30 -41
  19. package/dist/lib/ast/minify.js +551 -232
  20. package/dist/lib/ast/transform/compute.js +82 -69
  21. package/dist/lib/ast/transform/matrix.js +12 -26
  22. package/dist/lib/ast/transform/minify.js +154 -150
  23. package/dist/lib/ast/transform/perspective.js +1 -1
  24. package/dist/lib/ast/transform/rotate.js +1 -1
  25. package/dist/lib/ast/transform/scale.js +1 -1
  26. package/dist/lib/ast/transform/skew.js +1 -1
  27. package/dist/lib/ast/transform/translate.js +1 -1
  28. package/dist/lib/ast/transform/utils.js +3 -2
  29. package/dist/lib/ast/types.js +345 -30
  30. package/dist/lib/ast/walk.js +119 -64
  31. package/dist/lib/fs/resolve.js +94 -88
  32. package/dist/lib/parser/declaration/list.js +117 -26
  33. package/dist/lib/parser/declaration/map.js +141 -96
  34. package/dist/lib/parser/declaration/set.js +30 -25
  35. package/dist/lib/parser/parse.js +1810 -1739
  36. package/dist/lib/parser/tokenize.js +662 -403
  37. package/dist/lib/parser/utils/angle.js +29 -0
  38. package/dist/lib/parser/utils/at-rule-container.js +486 -0
  39. package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
  40. package/dist/lib/parser/utils/at-rule-generic.js +118 -0
  41. package/dist/lib/parser/utils/at-rule-import.js +393 -0
  42. package/dist/lib/parser/utils/at-rule-media.js +603 -0
  43. package/dist/lib/parser/utils/at-rule-support.js +431 -0
  44. package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
  45. package/dist/lib/parser/utils/at-rule.js +31 -0
  46. package/dist/lib/parser/utils/cache.js +19 -0
  47. package/dist/lib/parser/utils/config.js +1 -0
  48. package/dist/lib/parser/utils/declaration.js +672 -91
  49. package/dist/lib/parser/utils/hash.js +1 -1
  50. package/dist/lib/parser/utils/selector.js +518 -0
  51. package/dist/lib/parser/utils/text.js +17 -1
  52. package/dist/lib/parser/utils/token.js +104 -0
  53. package/dist/lib/parser/utils/type.js +29 -18
  54. package/dist/lib/renderer/render.js +870 -269
  55. package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
  56. package/dist/lib/syntax/color/a98rgb.js +8 -12
  57. package/dist/lib/syntax/color/alpha.js +64 -0
  58. package/dist/lib/syntax/color/cmyk.js +23 -21
  59. package/dist/lib/syntax/color/color-mix.js +311 -237
  60. package/dist/lib/syntax/color/color.js +98 -92
  61. package/dist/lib/syntax/color/hex.js +29 -33
  62. package/dist/lib/syntax/color/hsl.js +7 -14
  63. package/dist/lib/syntax/color/hwb.js +14 -27
  64. package/dist/lib/syntax/color/lab.js +23 -24
  65. package/dist/lib/syntax/color/lch.js +16 -18
  66. package/dist/lib/syntax/color/oklab.js +21 -40
  67. package/dist/lib/syntax/color/oklch.js +16 -18
  68. package/dist/lib/syntax/color/p3.js +0 -8
  69. package/dist/lib/syntax/color/rec2020.js +9 -13
  70. package/dist/lib/syntax/color/relativecolor.js +160 -48
  71. package/dist/lib/syntax/color/rgb.js +14 -18
  72. package/dist/lib/syntax/color/srgb.js +30 -29
  73. package/dist/lib/syntax/color/utils/color-type.js +18 -0
  74. package/dist/lib/syntax/color/utils/colorspace.js +46 -0
  75. package/dist/lib/syntax/color/utils/components.js +36 -16
  76. package/dist/lib/syntax/color/utils/distance.js +21 -11
  77. package/dist/lib/syntax/color/utils/make-color.js +56 -0
  78. package/dist/lib/syntax/color/xyz.js +10 -22
  79. package/dist/lib/syntax/color/xyzd50.js +6 -20
  80. package/dist/lib/syntax/constants.js +464 -0
  81. package/dist/lib/syntax/syntax.js +825 -592
  82. package/dist/lib/validation/config.js +72 -33
  83. package/dist/lib/validation/config.json.js +1185 -85
  84. package/dist/lib/validation/match.js +3120 -0
  85. package/dist/lib/validation/parser/parse.js +683 -935
  86. package/dist/lib/validation/parser/typedef.js +106 -0
  87. package/dist/lib/validation/utils/list.js +4 -11
  88. package/dist/lib/validation/utils/whitespace.js +2 -8
  89. package/dist/node.js +102 -57
  90. package/dist/web.js +100 -48
  91. package/package.json +31 -17
  92. package/dist/lib/syntax/color/utils/constants.js +0 -214
  93. package/dist/lib/syntax/utils.js +0 -70
  94. package/dist/lib/validation/at-rules/container.js +0 -342
  95. package/dist/lib/validation/at-rules/counter-style.js +0 -90
  96. package/dist/lib/validation/at-rules/custom-media.js +0 -50
  97. package/dist/lib/validation/at-rules/document.js +0 -89
  98. package/dist/lib/validation/at-rules/else.js +0 -5
  99. package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
  100. package/dist/lib/validation/at-rules/import.js +0 -150
  101. package/dist/lib/validation/at-rules/keyframes.js +0 -67
  102. package/dist/lib/validation/at-rules/layer.js +0 -41
  103. package/dist/lib/validation/at-rules/media.js +0 -255
  104. package/dist/lib/validation/at-rules/namespace.js +0 -81
  105. package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
  106. package/dist/lib/validation/at-rules/page.js +0 -100
  107. package/dist/lib/validation/at-rules/supports.js +0 -295
  108. package/dist/lib/validation/at-rules/when.js +0 -185
  109. package/dist/lib/validation/atrule.js +0 -184
  110. package/dist/lib/validation/selector.js +0 -36
  111. package/dist/lib/validation/syntax.js +0 -1073
  112. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
  113. package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
  114. package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
  115. package/dist/lib/validation/syntaxes/family-name.js +0 -57
  116. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
  117. package/dist/lib/validation/syntaxes/layer-name.js +0 -57
  118. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
  119. package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
  120. package/dist/lib/validation/syntaxes/selector-list.js +0 -5
  121. package/dist/lib/validation/syntaxes/selector.js +0 -5
  122. package/dist/lib/validation/syntaxes/url.js +0 -40
@@ -1,18 +1,12 @@
1
- import { e, k, D50 } from './utils/constants.js';
2
- import { getComponents } from './utils/components.js';
3
- import { color2srgbvalues, toPrecisionValue, getNumber } from './color.js';
4
- import { getOKLABComponents, OKLab_to_XYZ } from './oklab.js';
5
- import { EnumToken, ColorType } from '../../ast/types.js';
6
- import '../../ast/minify.js';
7
- import '../../ast/walk.js';
8
- import '../../parser/parse.js';
9
- import '../../parser/tokenize.js';
10
- import '../../parser/utils/config.js';
1
+ import { e, k, D50 } from '../constants.js';
2
+ import { getColorComponents } from './utils/components.js';
3
+ import { srgb2xyz_d65, XYZ_D50_to_D65 } from './xyz.js';
11
4
  import { oklch2srgbvalues, cmyk2srgbvalues, hwb2srgbvalues, hsl2srgb, rgb2srgb, hex2srgbvalues, xyz2srgb } from './srgb.js';
12
5
  import { getLCHComponents } from './lch.js';
13
- import { srgb2xyz_d50, XYZ_D50_to_D65 } from './xyz.js';
6
+ import { getOKLABComponents, OKLab_to_XYZ } from './oklab.js';
7
+ import { color2srgbvalues, toPrecisionValue, getNumber } from './color.js';
8
+ import { EnumToken, ColorType } from '../../ast/types.js';
14
9
  import { XYZ_D65_to_D50 } from './xyzd50.js';
15
- import '../../renderer/sourcemap/lib/encode.js';
16
10
 
17
11
  function hex2labToken(token) {
18
12
  const values = hex2labvalues(token);
@@ -81,16 +75,16 @@ function labToken(values) {
81
75
  { typ: EnumToken.NumberTokenType, val: toPrecisionValue(values[2]) },
82
76
  ];
83
77
  if (values.length == 4) {
84
- chi.push({ typ: EnumToken.LiteralTokenType, val: '/' }, {
78
+ chi.push({ typ: EnumToken.LiteralTokenType, val: "/" }, {
85
79
  typ: EnumToken.PercentageTokenType,
86
- val: values[3] * 100
80
+ val: toPrecisionValue(values[3], 2) * 100,
87
81
  });
88
82
  }
89
83
  return {
90
84
  typ: EnumToken.ColorTokenType,
91
- val: 'lab',
85
+ val: "lab",
92
86
  chi,
93
- kin: ColorType.LAB
87
+ kin: ColorType.LAB,
94
88
  };
95
89
  }
96
90
  // L: 0% = 0.0, 100% = 100.0
@@ -157,7 +151,7 @@ function color2labvalues(token) {
157
151
  }
158
152
  function srgb2labvalues(r, g, b, a) {
159
153
  // @ts-ignore */
160
- const result = xyz2lab(...srgb2xyz_d50(r, g, b));
154
+ const result = xyz2lab(...srgb2xyz_d65(r, g, b));
161
155
  // Fixes achromatic RGB colors having a _slight_ chroma due to floating-point errors
162
156
  // and approximated computations in sRGB <-> CIELab.
163
157
  // See: https://github.com/d3/d3-color/pull/46
@@ -177,11 +171,11 @@ function xyz2lab(x, y, z, a = null) {
177
171
  // compute xyz, which is XYZ scaled relative to reference white
178
172
  const xyz = [x, y, z].map((value, i) => value / D50[i]);
179
173
  // now compute f
180
- const f = xyz.map((value) => value > e ? Math.cbrt(value) : (k * value + 16) / 116);
174
+ const f = xyz.map((value) => (value > e ? Math.cbrt(value) : (k * value + 16) / 116));
181
175
  const result = [
182
- (116 * f[1]) - 16, // L
176
+ 116 * f[1] - 16, // L
183
177
  500 * (f[0] - f[1]), // a
184
- 200 * (f[1] - f[2]) // b
178
+ 200 * (f[1] - f[2]), // b
185
179
  ];
186
180
  // L in range [0,100]. For use in CSS, add a percent
187
181
  if (a != null && a != 1) {
@@ -191,19 +185,24 @@ function xyz2lab(x, y, z, a = null) {
191
185
  }
192
186
  function lchvalues2labvalues(l, c, h, a = null) {
193
187
  // l, c * Math.cos(360 * h * Math.PI / 180), c * Math.sin(360 * h * Math.PI / 180
194
- const result = [l, c * Math.cos(h * Math.PI / 180), c * Math.sin(h * Math.PI / 180)];
188
+ const result = [l, c * Math.cos((h * Math.PI) / 180), c * Math.sin((h * Math.PI) / 180)];
195
189
  if (a != null) {
196
190
  result.push(a);
197
191
  }
198
192
  return result;
199
193
  }
200
194
  function getLABComponents(token) {
201
- const components = getComponents(token);
195
+ const components = getColorComponents(token);
202
196
  if (components == null) {
203
197
  return null;
204
198
  }
205
199
  for (let i = 0; i < components.length; i++) {
206
- if (![EnumToken.NumberTokenType, EnumToken.PercentageTokenType, EnumToken.AngleTokenType, EnumToken.IdenTokenType].includes(components[i].typ)) {
200
+ if (![
201
+ EnumToken.NumberTokenType,
202
+ EnumToken.PercentageTokenType,
203
+ EnumToken.AngleTokenType,
204
+ EnumToken.IdenTokenType,
205
+ ].includes(components[i].typ)) {
207
206
  return null;
208
207
  }
209
208
  }
@@ -253,7 +252,7 @@ function Lab_to_XYZ(l, a, b) {
253
252
  const xyz = [
254
253
  Math.pow(f[0], 3) > e ? Math.pow(f[0], 3) : (116 * f[0] - 16) / k,
255
254
  l > k * e ? Math.pow((l + 16) / 116, 3) : l / k,
256
- Math.pow(f[2], 3) > e ? Math.pow(f[2], 3) : (116 * f[2] - 16) / k
255
+ Math.pow(f[2], 3) > e ? Math.pow(f[2], 3) : (116 * f[2] - 16) / k,
257
256
  ];
258
257
  // Compute XYZ by scaling xyz by reference white
259
258
  return xyz.map((value, i) => value * D50[i]);
@@ -1,15 +1,8 @@
1
- import './utils/constants.js';
2
- import { getComponents } from './utils/components.js';
1
+ import { getColorComponents } from './utils/components.js';
3
2
  import { color2srgbvalues, toPrecisionAngle, toPrecisionValue, getNumber, getAngle } from './color.js';
4
- import { cmyk2srgbvalues } from './srgb.js';
5
3
  import { EnumToken, ColorType } from '../../ast/types.js';
6
- import '../../ast/minify.js';
7
- import '../../ast/walk.js';
8
- import '../../parser/parse.js';
9
- import '../../parser/tokenize.js';
10
- import '../../parser/utils/config.js';
11
4
  import { srgb2labvalues, xyz2lab, oklch2labvalues, oklab2labvalues, getLABComponents, hwb2labvalues, hsl2labvalues, rgb2labvalues, hex2labvalues } from './lab.js';
12
- import '../../renderer/sourcemap/lib/encode.js';
5
+ import { cmyk2srgbvalues } from './srgb.js';
13
6
 
14
7
  function hex2lchToken(token) {
15
8
  const values = hex2lchvalues(token);
@@ -79,19 +72,19 @@ function lchToken(values) {
79
72
  const chi = [
80
73
  { typ: EnumToken.NumberTokenType, val: toPrecisionValue(values[0]) },
81
74
  { typ: EnumToken.NumberTokenType, val: toPrecisionValue(values[1]) },
82
- { typ: EnumToken.NumberTokenType, val: values[2] },
75
+ { typ: EnumToken.NumberTokenType, val: toPrecisionAngle(values[2]) },
83
76
  ];
84
77
  if (values.length == 4) {
85
- chi.push({ typ: EnumToken.LiteralTokenType, val: '/' }, {
78
+ chi.push({ typ: EnumToken.LiteralTokenType, val: "/" }, {
86
79
  typ: EnumToken.PercentageTokenType,
87
- val: values[3] * 100
80
+ val: toPrecisionValue(values[3], 2) * 100,
88
81
  });
89
82
  }
90
83
  return {
91
84
  typ: EnumToken.ColorTokenType,
92
- val: 'lch',
85
+ val: "lch",
93
86
  chi,
94
- kin: ColorType.LCH
87
+ kin: ColorType.LCH,
95
88
  };
96
89
  }
97
90
  function hex2lchvalues(token) {
@@ -151,11 +144,11 @@ function color2lchvalues(token) {
151
144
  }
152
145
  function labvalues2lchvalues(l, a, b, alpha = null) {
153
146
  let c = Math.sqrt(a * a + b * b);
154
- let h = Math.atan2(b, a) * 180 / Math.PI;
147
+ let h = (Math.atan2(b, a) * 180) / Math.PI;
155
148
  if (h < 0) {
156
149
  h += 360;
157
150
  }
158
- if (c < .0001) {
151
+ if (c < 0.0001) {
159
152
  c = h = 0;
160
153
  }
161
154
  return alpha == null ? [l, c, h] : [l, c, h, alpha];
@@ -166,12 +159,17 @@ function xyz2lchvalues(x, y, z, alpha) {
166
159
  return alpha == null || alpha == 1 ? lch : lch.concat(alpha);
167
160
  }
168
161
  function getLCHComponents(token) {
169
- const components = getComponents(token);
162
+ const components = getColorComponents(token);
170
163
  if (components == null) {
171
164
  return null;
172
165
  }
173
166
  for (let i = 0; i < components.length; i++) {
174
- if (![EnumToken.NumberTokenType, EnumToken.PercentageTokenType, EnumToken.AngleTokenType, EnumToken.IdenTokenType].includes(components[i].typ)) {
167
+ if (![
168
+ EnumToken.NumberTokenType,
169
+ EnumToken.PercentageTokenType,
170
+ EnumToken.AngleTokenType,
171
+ EnumToken.IdenTokenType,
172
+ ].includes(components[i].typ)) {
175
173
  return null;
176
174
  }
177
175
  }
@@ -1,17 +1,10 @@
1
+ import { getColorComponents } from './utils/components.js';
1
2
  import { multiplyMatrices } from './utils/matrix.js';
2
- import './utils/constants.js';
3
- import { getComponents } from './utils/components.js';
4
- import { color2srgbvalues, toPrecisionValue, getNumber } from './color.js';
5
3
  import { srgb2lsrgbvalues, lch2srgbvalues, lab2srgbvalues, cmyk2srgbvalues, hwb2srgbvalues, hsl2srgb, rgb2srgb, hex2srgbvalues, lsrgb2srgbvalues } from './srgb.js';
4
+ import { color2srgbvalues, toPrecisionValue, getNumber } from './color.js';
6
5
  import { EnumToken, ColorType } 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 { lchvalues2labvalues } from './lab.js';
13
6
  import { getOKLCHComponents } from './oklch.js';
14
- import '../../renderer/sourcemap/lib/encode.js';
7
+ import { lchvalues2labvalues } from './lab.js';
15
8
 
16
9
  function hex2oklabToken(token) {
17
10
  const values = hex2oklabvalues(token);
@@ -83,16 +76,16 @@ function oklabToken(values) {
83
76
  { typ: EnumToken.NumberTokenType, val: toPrecisionValue(values[2]) },
84
77
  ];
85
78
  if (values.length == 4) {
86
- chi.push({ typ: EnumToken.LiteralTokenType, val: '/' }, {
79
+ chi.push({ typ: EnumToken.LiteralTokenType, val: "/" }, {
87
80
  typ: EnumToken.PercentageTokenType,
88
- val: values[3] * 100
81
+ val: toPrecisionValue(values[3], 2) * 100,
89
82
  });
90
83
  }
91
84
  return {
92
85
  typ: EnumToken.ColorTokenType,
93
- val: 'oklab',
86
+ val: "oklab",
94
87
  chi,
95
- kin: ColorType.OKLAB
88
+ kin: ColorType.OKLAB,
96
89
  };
97
90
  }
98
91
  function hex2oklabvalues(token) {
@@ -162,7 +155,7 @@ function srgb2oklab(r, g, blue, alpha) {
162
155
  return alpha == null || alpha == 1 ? [l, a, b] : [l, a, b, alpha];
163
156
  }
164
157
  function getOKLABComponents(token) {
165
- const components = getComponents(token);
158
+ const components = getColorComponents(token);
166
159
  if (components == null || components.length < 3) {
167
160
  return null;
168
161
  }
@@ -173,11 +166,11 @@ function getOKLABComponents(token) {
173
166
  // @ts-ignore
174
167
  t = components[1];
175
168
  // @ts-ignore
176
- const a = getNumber(t) * (t.typ == EnumToken.PercentageTokenType ? .4 : 1);
169
+ const a = getNumber(t) * (t.typ == EnumToken.PercentageTokenType ? 0.4 : 1);
177
170
  // @ts-ignore
178
171
  t = components[2];
179
172
  // @ts-ignore
180
- const b = getNumber(t) * (t.typ == EnumToken.PercentageTokenType ? .4 : 1);
173
+ const b = getNumber(t) * (t.typ == EnumToken.PercentageTokenType ? 0.4 : 1);
181
174
  // @ts-ignore
182
175
  let alpha = null;
183
176
  if (components.length > 3) {
@@ -193,13 +186,13 @@ function OKLab_to_XYZ(l, a, b, alpha = null) {
193
186
  // Given OKLab, convert to XYZ relative to D65
194
187
  const LMStoXYZ = [
195
188
  [1.2268798758459243, -0.5578149944602171, 0.2813910456659647],
196
- [-0.0405757452148008, 1.1122868032803170, -0.0717110580655164],
197
- [-0.0763729366746601, -0.4214933324022432, 1.5869240198367816]
189
+ [-0.0405757452148008, 1.112286803280317, -0.0717110580655164],
190
+ [-0.0763729366746601, -0.4214933324022432, 1.5869240198367816],
198
191
  ];
199
192
  const OKLabtoLMS = [
200
- [1.0000000000000000, 0.3963377773761749, 0.2158037573099136],
201
- [1.0000000000000000, -0.1055613458156586, -0.0638541728258133],
202
- [1.0000000000000000, -0.0894841775298119, -1.2914855480194092]
193
+ [1.0, 0.3963377773761749, 0.2158037573099136],
194
+ [1.0, -0.1055613458156586, -0.0638541728258133],
195
+ [1.0, -0.0894841775298119, -1.2914855480194092],
203
196
  ];
204
197
  const LMSnl = multiplyMatrices(OKLabtoLMS, [l, a, b]);
205
198
  const xyz = multiplyMatrices(LMStoXYZ, LMSnl.map((c) => c ** 3));
@@ -210,28 +203,16 @@ function OKLab_to_XYZ(l, a, b, alpha = null) {
210
203
  }
211
204
  // from https://www.w3.org/TR/css-color-4/#color-conversion-code
212
205
  function OKLab_to_sRGB(l, a, b) {
213
- let L = Math.pow(l * 0.99999999845051981432 +
214
- 0.39633779217376785678 * a +
215
- 0.21580375806075880339 * b, 3);
216
- let M = Math.pow(l * 1.0000000088817607767 -
217
- 0.1055613423236563494 * a -
218
- 0.063854174771705903402 * b, 3);
219
- let S = Math.pow(l * 1.0000000546724109177 -
220
- 0.089484182094965759684 * a -
221
- 1.2914855378640917399 * b, 3);
206
+ let L = Math.pow(l * 0.99999999845051981432 + 0.39633779217376785678 * a + 0.21580375806075880339 * b, 3);
207
+ let M = Math.pow(l * 1.0000000088817607767 - 0.1055613423236563494 * a - 0.063854174771705903402 * b, 3);
208
+ let S = Math.pow(l * 1.0000000546724109177 - 0.089484182094965759684 * a - 1.2914855378640917399 * b, 3);
222
209
  return lsrgb2srgbvalues(
223
210
  /* r: */
224
- 4.076741661347994 * L -
225
- 3.307711590408193 * M +
226
- 0.230969928729428 * S,
211
+ 4.076741661347994 * L - 3.307711590408193 * M + 0.230969928729428 * S,
227
212
  /* g: */
228
- -1.2684380040921763 * L +
229
- 2.6097574006633715 * M -
230
- 0.3413193963102197 * S,
213
+ -1.2684380040921763 * L + 2.6097574006633715 * M - 0.3413193963102197 * S,
231
214
  /* b: */
232
- -0.004196086541837188 * L -
233
- 0.7034186144594493 * M +
234
- 1.7076147009309444 * S);
215
+ -0.004196086541837188 * L - 0.7034186144594493 * M + 1.7076147009309444 * S);
235
216
  }
236
217
 
237
218
  export { OKLab_to_XYZ, OKLab_to_sRGB, cmyk2oklabToken, cmyk2oklabvalues, color2oklabToken, getOKLABComponents, hex2oklabToken, hex2oklabvalues, hsl2oklabToken, hsl2oklabvalues, hwb2oklabToken, hwb2oklabvalues, lab2oklabToken, lab2oklabvalues, lch2oklabToken, lch2oklabvalues, oklch2oklabToken, oklch2oklabvalues, rgb2oklabToken, rgb2oklabvalues, srgb2oklab };
@@ -1,16 +1,9 @@
1
- import './utils/constants.js';
2
- import { getComponents } from './utils/components.js';
1
+ import { getColorComponents } from './utils/components.js';
3
2
  import { color2srgbvalues, toPrecisionAngle, toPrecisionValue, getNumber, getAngle } from './color.js';
4
- import { srgb2oklab, lch2oklabvalues, getOKLABComponents, lab2oklabvalues, hwb2oklabvalues, hsl2oklabvalues, rgb2oklabvalues, hex2oklabvalues } from './oklab.js';
5
3
  import { EnumToken, ColorType } from '../../ast/types.js';
6
- import '../../ast/minify.js';
7
- import '../../ast/walk.js';
8
- import '../../parser/parse.js';
9
- import '../../parser/tokenize.js';
10
- import '../../parser/utils/config.js';
11
- import { cmyk2srgbvalues } from './srgb.js';
12
4
  import { labvalues2lchvalues } from './lch.js';
13
- import '../../renderer/sourcemap/lib/encode.js';
5
+ import { srgb2oklab, lch2oklabvalues, getOKLABComponents, lab2oklabvalues, hwb2oklabvalues, hsl2oklabvalues, rgb2oklabvalues, hex2oklabvalues } from './oklab.js';
6
+ import { cmyk2srgbvalues } from './srgb.js';
14
7
 
15
8
  function hex2oklchToken(token) {
16
9
  const values = hex2oklchvalues(token);
@@ -81,16 +74,16 @@ function oklchToken(values) {
81
74
  { typ: EnumToken.NumberTokenType, val: values[2] },
82
75
  ];
83
76
  if (values.length == 4) {
84
- chi.push({ typ: EnumToken.LiteralTokenType, val: '/' }, {
77
+ chi.push({ typ: EnumToken.LiteralTokenType, val: "/" }, {
85
78
  typ: EnumToken.PercentageTokenType,
86
- val: values[3] * 100
79
+ val: toPrecisionValue(values[3], 2) * 100,
87
80
  });
88
81
  }
89
82
  return {
90
83
  typ: EnumToken.ColorTokenType,
91
- val: 'oklch',
84
+ val: "oklch",
92
85
  chi,
93
- kin: ColorType.OKLCH
86
+ kin: ColorType.OKLCH,
94
87
  };
95
88
  }
96
89
  function hex2oklchvalues(token) {
@@ -147,12 +140,17 @@ function srgb2oklch(r, g, blue, alpha) {
147
140
  return labvalues2lchvalues(...srgb2oklab(r, g, blue, alpha));
148
141
  }
149
142
  function getOKLCHComponents(token) {
150
- const components = getComponents(token);
143
+ const components = getColorComponents(token);
151
144
  if (components == null) {
152
145
  return null;
153
146
  }
154
147
  for (let i = 0; i < components.length; i++) {
155
- if (![EnumToken.NumberTokenType, EnumToken.PercentageTokenType, EnumToken.AngleTokenType, EnumToken.IdenTokenType].includes(components[i].typ)) {
148
+ if (![
149
+ EnumToken.NumberTokenType,
150
+ EnumToken.PercentageTokenType,
151
+ EnumToken.AngleTokenType,
152
+ EnumToken.IdenTokenType,
153
+ ].includes(components[i].typ)) {
156
154
  return [];
157
155
  }
158
156
  }
@@ -163,7 +161,7 @@ function getOKLCHComponents(token) {
163
161
  // @ts-ignore
164
162
  t = components[1];
165
163
  // @ts-ignore
166
- const c = getNumber(t) * (t.typ == EnumToken.PercentageTokenType ? .4 : 1);
164
+ const c = getNumber(t) * (t.typ == EnumToken.PercentageTokenType ? 0.4 : 1);
167
165
  // @ts-ignore
168
166
  t = components[2];
169
167
  // @ts-ignore
@@ -171,7 +169,7 @@ function getOKLCHComponents(token) {
171
169
  // @ts-ignore
172
170
  t = components[3];
173
171
  // @ts-ignore
174
- const alpha = t == null || (t.typ == EnumToken.IdenTokenType && t.val == 'none') ? 1 : getNumber(t);
172
+ const alpha = t == null || (t.typ == EnumToken.IdenTokenType && t.val == "none") ? 1 : getNumber(t);
175
173
  return [l, c, h, alpha];
176
174
  }
177
175
 
@@ -1,14 +1,6 @@
1
1
  import { lsrgb2srgbvalues, xyz2srgb, srgb2lsrgbvalues } from './srgb.js';
2
2
  import { multiplyMatrices } from './utils/matrix.js';
3
- import './utils/constants.js';
4
- import '../../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
3
  import { srgb2xyz } from './xyz.js';
11
- import '../../renderer/sourcemap/lib/encode.js';
12
4
 
13
5
  function p32srgbvalues(r, g, b, alpha) {
14
6
  // @ts-ignore
@@ -1,14 +1,6 @@
1
1
  import { xyz2srgb } from './srgb.js';
2
2
  import { multiplyMatrices } from './utils/matrix.js';
3
- import './utils/constants.js';
4
- import '../../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
3
  import { srgb2xyz } from './xyz.js';
11
- import '../../renderer/sourcemap/lib/encode.js';
12
4
 
13
5
  function rec20202srgb(r, g, b, a) {
14
6
  // @ts-ignore
@@ -24,14 +16,16 @@ function rec20202lrec2020(r, g, b, a) {
24
16
  // ITU-R BT.2020-2 p.4
25
17
  const alpha = 1.09929682680944;
26
18
  const beta = 0.018053968510807;
27
- return [r, g, b].map(function (val) {
19
+ return [r, g, b]
20
+ .map(function (val) {
28
21
  let sign = val < 0 ? -1 : 1;
29
22
  let abs = Math.abs(val);
30
23
  if (abs < beta * 4.5) {
31
24
  return val / 4.5;
32
25
  }
33
- return sign * (Math.pow((abs + alpha - 1) / alpha, 1 / 0.45));
34
- }).concat([] );
26
+ return sign * Math.pow((abs + alpha - 1) / alpha, 1 / 0.45);
27
+ })
28
+ .concat([] );
35
29
  }
36
30
  function lrec20202rec2020(r, g, b, a) {
37
31
  // convert an array of linear-light rec2020 RGB in the range 0.0-1.0
@@ -39,14 +33,16 @@ function lrec20202rec2020(r, g, b, a) {
39
33
  // ITU-R BT.2020-2 p.4
40
34
  const alpha = 1.09929682680944;
41
35
  const beta = 0.018053968510807;
42
- return [r, g, b].map(function (val) {
36
+ return [r, g, b]
37
+ .map(function (val) {
43
38
  let sign = val < 0 ? -1 : 1;
44
39
  let abs = Math.abs(val);
45
40
  if (abs > beta) {
46
41
  return sign * (alpha * Math.pow(abs, 0.45) - (alpha - 1));
47
42
  }
48
43
  return 4.5 * val;
49
- }).concat(a == null || a == 1 ? [] : [a]);
44
+ })
45
+ .concat(a == null || a == 1 ? [] : [a]);
50
46
  }
51
47
  function lrec20202xyz(r, g, b, a) {
52
48
  // convert an array of linear-light rec2020 values to CIE XYZ