@tbela99/css-parser 1.4.2 → 1.4.3

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 (216) hide show
  1. package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
  2. package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
  3. package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
  4. package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
  5. package/.repl_history +4 -0
  6. package/CHANGELOG.md +164 -4
  7. package/README.md +43 -0
  8. package/badges/coverage.svg +20 -0
  9. package/deno.lock +2861 -0
  10. package/dist/config.json.js +33 -1
  11. package/dist/index-umd-web.js +24382 -18476
  12. package/dist/index.cjs +24522 -18618
  13. package/dist/index.d.ts +1396 -929
  14. package/dist/lib/ast/clone.d.ts +10 -0
  15. package/dist/lib/ast/clone.js +45 -0
  16. package/dist/lib/ast/expand.d.ts +14 -0
  17. package/dist/lib/ast/expand.js +89 -64
  18. package/dist/lib/ast/features/calc.d.ts +10 -0
  19. package/dist/lib/ast/features/calc.js +62 -24
  20. package/dist/lib/ast/features/if.d.ts +10 -0
  21. package/dist/lib/ast/features/if.js +215 -0
  22. package/dist/lib/ast/features/index.d.ts +6 -0
  23. package/dist/lib/ast/features/index.js +1 -0
  24. package/dist/lib/ast/features/inlinecssvariables.d.ts +15 -0
  25. package/dist/lib/ast/features/inlinecssvariables.js +32 -27
  26. package/dist/lib/ast/features/prefix.d.ts +8 -0
  27. package/dist/lib/ast/features/prefix.js +68 -43
  28. package/dist/lib/ast/features/shorthand.d.ts +12 -0
  29. package/dist/lib/ast/features/shorthand.js +6 -9
  30. package/dist/lib/ast/features/transform.d.ts +10 -0
  31. package/dist/lib/ast/features/transform.js +9 -13
  32. package/dist/lib/ast/features/type.d.ts +15 -0
  33. package/dist/lib/ast/find.d.ts +165 -0
  34. package/dist/lib/ast/find.js +175 -0
  35. package/dist/lib/ast/math/expression.d.ts +18 -0
  36. package/dist/lib/ast/math/expression.js +140 -98
  37. package/dist/lib/ast/math/math.d.ts +6 -0
  38. package/dist/lib/ast/math/math.js +30 -41
  39. package/dist/lib/ast/minify.d.ts +19 -0
  40. package/dist/lib/ast/minify.js +541 -217
  41. package/dist/lib/ast/transform/compute.d.ts +8 -0
  42. package/dist/lib/ast/transform/compute.js +82 -69
  43. package/dist/lib/ast/transform/matrix.d.ts +22 -0
  44. package/dist/lib/ast/transform/matrix.js +12 -26
  45. package/dist/lib/ast/transform/minify.d.ts +5 -0
  46. package/dist/lib/ast/transform/minify.js +20 -20
  47. package/dist/lib/ast/transform/perspective.d.ts +3 -0
  48. package/dist/lib/ast/transform/perspective.js +1 -1
  49. package/dist/lib/ast/transform/rotate.d.ts +12 -0
  50. package/dist/lib/ast/transform/rotate.js +1 -1
  51. package/dist/lib/ast/transform/scale.d.ts +6 -0
  52. package/dist/lib/ast/transform/scale.js +1 -1
  53. package/dist/lib/ast/transform/skew.d.ts +4 -0
  54. package/dist/lib/ast/transform/skew.js +1 -1
  55. package/dist/lib/ast/transform/translate.d.ts +6 -0
  56. package/dist/lib/ast/transform/translate.js +1 -1
  57. package/dist/lib/ast/transform/utils.d.ts +9 -0
  58. package/dist/lib/ast/types.d.ts +903 -0
  59. package/dist/lib/ast/types.js +277 -23
  60. package/dist/lib/ast/walk.d.ts +162 -0
  61. package/dist/lib/ast/walk.js +116 -60
  62. package/dist/lib/fs/resolve.d.ts +20 -0
  63. package/dist/lib/fs/resolve.js +37 -45
  64. package/dist/lib/parser/declaration/list.d.ts +16 -0
  65. package/dist/lib/parser/declaration/list.js +26 -24
  66. package/dist/lib/parser/declaration/map.d.ts +15 -0
  67. package/dist/lib/parser/declaration/map.js +140 -95
  68. package/dist/lib/parser/declaration/set.d.ts +9 -0
  69. package/dist/lib/parser/declaration/set.js +30 -25
  70. package/dist/lib/parser/node.d.ts +7 -0
  71. package/dist/lib/parser/parse.d.ts +107 -0
  72. package/dist/lib/parser/parse.js +1454 -1445
  73. package/dist/lib/parser/tokenize.d.ts +57 -0
  74. package/dist/lib/parser/tokenize.js +557 -404
  75. package/dist/lib/parser/utils/at-rule-container.d.ts +5 -0
  76. package/dist/lib/parser/utils/at-rule-container.js +486 -0
  77. package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +5 -0
  78. package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
  79. package/dist/lib/parser/utils/at-rule-generic.d.ts +5 -0
  80. package/dist/lib/parser/utils/at-rule-generic.js +118 -0
  81. package/dist/lib/parser/utils/at-rule-import.d.ts +5 -0
  82. package/dist/lib/parser/utils/at-rule-import.js +393 -0
  83. package/dist/lib/parser/utils/at-rule-media.d.ts +5 -0
  84. package/dist/lib/parser/utils/at-rule-media.js +603 -0
  85. package/dist/lib/parser/utils/at-rule-page.d.ts +5 -0
  86. package/dist/lib/parser/utils/at-rule-page.js +28 -0
  87. package/dist/lib/parser/utils/at-rule-support.d.ts +5 -0
  88. package/dist/lib/parser/utils/at-rule-support.js +366 -0
  89. package/dist/lib/parser/utils/at-rule-token.d.ts +1 -0
  90. package/dist/lib/parser/utils/at-rule-when-else.d.ts +5 -0
  91. package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
  92. package/dist/lib/parser/utils/at-rule.d.ts +13 -0
  93. package/dist/lib/parser/utils/at-rule.js +37 -0
  94. package/dist/lib/parser/utils/cache.d.ts +6 -0
  95. package/dist/lib/parser/utils/cache.js +19 -0
  96. package/dist/lib/parser/utils/config.d.ts +2 -0
  97. package/dist/lib/parser/utils/config.js +1 -0
  98. package/dist/lib/parser/utils/declaration-list.d.ts +5 -0
  99. package/dist/lib/parser/utils/declaration.d.ts +18 -0
  100. package/dist/lib/parser/utils/declaration.js +569 -91
  101. package/dist/lib/parser/utils/eq.d.ts +1 -0
  102. package/dist/lib/parser/utils/hash.d.ts +21 -0
  103. package/dist/lib/parser/utils/hash.js +1 -1
  104. package/dist/lib/parser/utils/selector.d.ts +5 -0
  105. package/dist/lib/parser/utils/selector.js +476 -0
  106. package/dist/lib/parser/utils/text.d.ts +3 -0
  107. package/dist/lib/parser/utils/text.js +17 -1
  108. package/dist/lib/parser/utils/token.d.ts +14 -0
  109. package/dist/lib/parser/utils/token.js +102 -0
  110. package/dist/lib/parser/utils/type.d.ts +2 -0
  111. package/dist/lib/parser/utils/type.js +29 -18
  112. package/dist/lib/renderer/render.d.ts +28 -0
  113. package/dist/lib/renderer/render.js +421 -262
  114. package/dist/lib/renderer/sourcemap/lib/encode.d.ts +1 -0
  115. package/dist/lib/renderer/sourcemap/sourcemap.d.ts +26 -0
  116. package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
  117. package/dist/lib/syntax/color/a98rgb.d.ts +2 -0
  118. package/dist/lib/syntax/color/a98rgb.js +8 -12
  119. package/dist/lib/syntax/color/cmyk.d.ts +10 -0
  120. package/dist/lib/syntax/color/cmyk.js +23 -21
  121. package/dist/lib/syntax/color/color-mix.d.ts +2 -0
  122. package/dist/lib/syntax/color/color-mix.js +88 -77
  123. package/dist/lib/syntax/color/color.d.ts +42 -0
  124. package/dist/lib/syntax/color/color.js +65 -68
  125. package/dist/lib/syntax/color/hex.d.ts +16 -0
  126. package/dist/lib/syntax/color/hex.js +27 -31
  127. package/dist/lib/syntax/color/hsl.d.ts +20 -0
  128. package/dist/lib/syntax/color/hsl.js +5 -12
  129. package/dist/lib/syntax/color/hsv.d.ts +2 -0
  130. package/dist/lib/syntax/color/hwb.d.ts +21 -0
  131. package/dist/lib/syntax/color/hwb.js +8 -21
  132. package/dist/lib/syntax/color/lab.d.ts +25 -0
  133. package/dist/lib/syntax/color/lab.js +20 -21
  134. package/dist/lib/syntax/color/lch.d.ts +23 -0
  135. package/dist/lib/syntax/color/lch.js +13 -15
  136. package/dist/lib/syntax/color/oklab.d.ts +22 -0
  137. package/dist/lib/syntax/color/oklab.js +20 -39
  138. package/dist/lib/syntax/color/oklch.d.ts +20 -0
  139. package/dist/lib/syntax/color/oklch.js +14 -16
  140. package/dist/lib/syntax/color/p3.d.ts +6 -0
  141. package/dist/lib/syntax/color/p3.js +0 -8
  142. package/dist/lib/syntax/color/prophotorgb.d.ts +2 -0
  143. package/dist/lib/syntax/color/rec2020.d.ts +2 -0
  144. package/dist/lib/syntax/color/rec2020.js +9 -13
  145. package/dist/lib/syntax/color/relativecolor.d.ts +13 -0
  146. package/dist/lib/syntax/color/relativecolor.js +68 -41
  147. package/dist/lib/syntax/color/rgb.d.ts +20 -0
  148. package/dist/lib/syntax/color/rgb.js +14 -18
  149. package/dist/lib/syntax/color/srgb.d.ts +23 -0
  150. package/dist/lib/syntax/color/srgb.js +27 -26
  151. package/dist/lib/syntax/color/utils/components.d.ts +2 -0
  152. package/dist/lib/syntax/color/utils/components.js +30 -14
  153. package/dist/lib/syntax/color/utils/distance.d.ts +18 -0
  154. package/dist/lib/syntax/color/utils/distance.js +1 -8
  155. package/dist/lib/syntax/color/utils/matrix.d.ts +6 -0
  156. package/dist/lib/syntax/color/xyz.d.ts +5 -0
  157. package/dist/lib/syntax/color/xyz.js +8 -20
  158. package/dist/lib/syntax/color/xyzd50.d.ts +4 -0
  159. package/dist/lib/syntax/color/xyzd50.js +6 -20
  160. package/dist/lib/syntax/constants.d.ts +67 -0
  161. package/dist/lib/syntax/constants.js +436 -0
  162. package/dist/lib/syntax/syntax.d.ts +38 -0
  163. package/dist/lib/syntax/syntax.js +533 -568
  164. package/dist/lib/validation/config.d.ts +14 -0
  165. package/dist/lib/validation/config.js +72 -33
  166. package/dist/lib/validation/config.json.js +1159 -74
  167. package/dist/lib/validation/json.d.ts +2 -0
  168. package/dist/lib/validation/match.d.ts +38 -0
  169. package/dist/lib/validation/match.js +2985 -0
  170. package/dist/lib/validation/parser/parse.d.ts +8 -0
  171. package/dist/lib/validation/parser/parse.js +684 -935
  172. package/dist/lib/validation/parser/typedef.d.ts +95 -0
  173. package/dist/lib/validation/parser/typedef.js +100 -0
  174. package/dist/lib/validation/utils/list.d.ts +4 -0
  175. package/dist/lib/validation/utils/list.js +4 -11
  176. package/dist/lib/validation/utils/whitespace.d.ts +2 -0
  177. package/dist/lib/validation/utils/whitespace.js +2 -8
  178. package/dist/node.d.ts +207 -0
  179. package/dist/node.js +42 -39
  180. package/dist/web.d.ts +169 -0
  181. package/dist/web.js +38 -33
  182. package/package.json +15 -12
  183. package/playground/index.html +1328 -0
  184. package/playground/sw.js +55 -0
  185. package/playground/tree.js +176 -0
  186. package/dist/lib/syntax/color/utils/constants.js +0 -214
  187. package/dist/lib/syntax/utils.js +0 -70
  188. package/dist/lib/validation/at-rules/container.js +0 -342
  189. package/dist/lib/validation/at-rules/counter-style.js +0 -90
  190. package/dist/lib/validation/at-rules/custom-media.js +0 -50
  191. package/dist/lib/validation/at-rules/document.js +0 -89
  192. package/dist/lib/validation/at-rules/else.js +0 -5
  193. package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
  194. package/dist/lib/validation/at-rules/import.js +0 -150
  195. package/dist/lib/validation/at-rules/keyframes.js +0 -67
  196. package/dist/lib/validation/at-rules/layer.js +0 -41
  197. package/dist/lib/validation/at-rules/media.js +0 -255
  198. package/dist/lib/validation/at-rules/namespace.js +0 -81
  199. package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
  200. package/dist/lib/validation/at-rules/page.js +0 -100
  201. package/dist/lib/validation/at-rules/supports.js +0 -295
  202. package/dist/lib/validation/at-rules/when.js +0 -185
  203. package/dist/lib/validation/atrule.js +0 -184
  204. package/dist/lib/validation/selector.js +0 -36
  205. package/dist/lib/validation/syntax.js +0 -1073
  206. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
  207. package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
  208. package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
  209. package/dist/lib/validation/syntaxes/family-name.js +0 -57
  210. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
  211. package/dist/lib/validation/syntaxes/layer-name.js +0 -57
  212. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
  213. package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
  214. package/dist/lib/validation/syntaxes/selector-list.js +0 -5
  215. package/dist/lib/validation/syntaxes/selector.js +0 -5
  216. package/dist/lib/validation/syntaxes/url.js +0 -40
@@ -1,18 +1,12 @@
1
- import { e, k, D50 } from './utils/constants.js';
1
+ import { e, k, D50 } from '../constants.js';
2
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';
3
+ import { srgb2xyz_d50, 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: values[3] * 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
@@ -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,7 +185,7 @@ 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
  }
@@ -203,7 +197,12 @@ function getLABComponents(token) {
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]);
@@ -0,0 +1,23 @@
1
+ import type { ColorToken } from "../../../@types/index.d.ts";
2
+ export declare function hex2lchToken(token: ColorToken): ColorToken | null;
3
+ export declare function rgb2lchToken(token: ColorToken): ColorToken | null;
4
+ export declare function hsl2lchToken(token: ColorToken): ColorToken | null;
5
+ export declare function hwb2lchToken(token: ColorToken): ColorToken | null;
6
+ export declare function cmyk2lchToken(token: ColorToken): ColorToken | null;
7
+ export declare function lab2lchToken(token: ColorToken): ColorToken | null;
8
+ export declare function oklab2lchToken(token: ColorToken): ColorToken | null;
9
+ export declare function oklch2lchToken(token: ColorToken): ColorToken | null;
10
+ export declare function color2lchToken(token: ColorToken): ColorToken | null;
11
+ export declare function hex2lchvalues(token: ColorToken): number[] | null;
12
+ export declare function rgb2lchvalues(token: ColorToken): number[] | null;
13
+ export declare function hsl2lchvalues(token: ColorToken): number[] | null;
14
+ export declare function hwb2lchvalues(token: ColorToken): number[] | null;
15
+ export declare function lab2lchvalues(token: ColorToken): number[] | null;
16
+ export declare function srgb2lch(r: number, g: number, blue: number, alpha: number | null): number[];
17
+ export declare function oklab2lchvalues(token: ColorToken): number[] | null;
18
+ export declare function cmyk2lchvalues(token: ColorToken): number[] | null;
19
+ export declare function oklch2lchvalues(token: ColorToken): number[] | null;
20
+ export declare function color2lchvalues(token: ColorToken): number[] | null;
21
+ export declare function labvalues2lchvalues(l: number, a: number, b: number, alpha?: number | null): number[];
22
+ export declare function xyz2lchvalues(x: number, y: number, z: number, alpha?: number): number[];
23
+ export declare function getLCHComponents(token: ColorToken): number[] | null;
@@ -1,15 +1,8 @@
1
- import './utils/constants.js';
2
1
  import { getComponents } 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);
@@ -82,16 +75,16 @@ function lchToken(values) {
82
75
  { typ: EnumToken.NumberTokenType, val: 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: values[3] * 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];
@@ -171,7 +164,12 @@ function getLCHComponents(token) {
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
  }
@@ -0,0 +1,22 @@
1
+ import type { ColorToken } from "../../../@types/index.d.ts";
2
+ export declare function hex2oklabToken(token: ColorToken): ColorToken | null;
3
+ export declare function rgb2oklabToken(token: ColorToken): ColorToken | null;
4
+ export declare function hsl2oklabToken(token: ColorToken): ColorToken | null;
5
+ export declare function hwb2oklabToken(token: ColorToken): ColorToken | null;
6
+ export declare function cmyk2oklabToken(token: ColorToken): ColorToken | null;
7
+ export declare function lab2oklabToken(token: ColorToken): ColorToken | null;
8
+ export declare function lch2oklabToken(token: ColorToken): ColorToken | null;
9
+ export declare function oklch2oklabToken(token: ColorToken): ColorToken | null;
10
+ export declare function color2oklabToken(token: ColorToken): ColorToken | null;
11
+ export declare function hex2oklabvalues(token: ColorToken): number[] | null;
12
+ export declare function rgb2oklabvalues(token: ColorToken): number[] | null;
13
+ export declare function hsl2oklabvalues(token: ColorToken): number[] | null;
14
+ export declare function hwb2oklabvalues(token: ColorToken): number[];
15
+ export declare function cmyk2oklabvalues(token: ColorToken): number[] | null;
16
+ export declare function lab2oklabvalues(token: ColorToken): number[] | null;
17
+ export declare function lch2oklabvalues(token: ColorToken): number[] | null;
18
+ export declare function oklch2oklabvalues(token: ColorToken): number[] | null;
19
+ export declare function srgb2oklab(r: number, g: number, blue: number, alpha: number | null): number[];
20
+ export declare function getOKLABComponents(token: ColorToken): number[] | null;
21
+ export declare function OKLab_to_XYZ(l: number, a: number, b: number, alpha?: number | null): number[];
22
+ export declare function OKLab_to_sRGB(l: number, a: number, b: number): number[];
@@ -1,17 +1,10 @@
1
- import { multiplyMatrices } from './utils/matrix.js';
2
- import './utils/constants.js';
3
1
  import { getComponents } from './utils/components.js';
4
- import { color2srgbvalues, toPrecisionValue, getNumber } from './color.js';
2
+ import { multiplyMatrices } from './utils/matrix.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: values[3] * 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) {
@@ -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 };
@@ -0,0 +1,20 @@
1
+ import type { ColorToken } from "../../../@types/index.d.ts";
2
+ export declare function hex2oklchToken(token: ColorToken): ColorToken | null;
3
+ export declare function rgb2oklchToken(token: ColorToken): ColorToken | null;
4
+ export declare function hsl2oklchToken(token: ColorToken): ColorToken | null;
5
+ export declare function hwb2oklchToken(token: ColorToken): ColorToken | null;
6
+ export declare function cmyk2oklchToken(token: ColorToken): ColorToken | null;
7
+ export declare function lab2oklchToken(token: ColorToken): ColorToken | null;
8
+ export declare function oklab2oklchToken(token: ColorToken): ColorToken | null;
9
+ export declare function lch2oklchToken(token: ColorToken): ColorToken | null;
10
+ export declare function color2oklchToken(token: ColorToken): ColorToken | null;
11
+ export declare function hex2oklchvalues(token: ColorToken): number[];
12
+ export declare function rgb2oklchvalues(token: ColorToken): number[] | null;
13
+ export declare function hsl2oklchvalues(token: ColorToken): number[];
14
+ export declare function hwb2oklchvalues(token: ColorToken): number[];
15
+ export declare function cmyk2oklchvalues(token: ColorToken): number[];
16
+ export declare function lab2oklchvalues(token: ColorToken): number[] | null;
17
+ export declare function lch2oklchvalues(token: ColorToken): number[] | null;
18
+ export declare function oklab2oklchvalues(token: ColorToken): number[] | null;
19
+ export declare function srgb2oklch(r: number, g: number, blue: number, alpha: number | null): number[];
20
+ export declare function getOKLCHComponents(token: ColorToken): number[] | null;
@@ -1,16 +1,9 @@
1
- import './utils/constants.js';
2
1
  import { getComponents } 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: values[3] * 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) {
@@ -152,7 +145,12 @@ function getOKLCHComponents(token) {
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
 
@@ -0,0 +1,6 @@
1
+ export declare function p32srgbvalues(r: number, g: number, b: number, alpha?: number): number[];
2
+ export declare function srgb2p3values(r: number, g: number, b: number, alpha?: number): number[];
3
+ export declare function p32lp3(r: number, g: number, b: number, alpha?: number): number[];
4
+ export declare function lp32p3(r: number, g: number, b: number, alpha?: number): number[];
5
+ export declare function lp32xyz(r: number, g: number, b: number, alpha?: number): number[];
6
+ export declare function xyz2lp3(x: number, y: number, z: number, alpha?: number): number[];
@@ -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
@@ -0,0 +1,2 @@
1
+ export declare function prophotorgb2srgbvalues(r: number, g: number, b: number, a?: number | null): number[];
2
+ export declare function srgb2prophotorgbvalues(r: number, g: number, b: number, a?: number): number[];
@@ -0,0 +1,2 @@
1
+ export declare function rec20202srgb(r: number, g: number, b: number, a?: number): number[];
2
+ export declare function srgb2rec2020values(r: number, g: number, b: number, a?: number): number[];
@@ -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
@@ -0,0 +1,13 @@
1
+ import type { BinaryExpressionToken, ColorToken, FunctionToken, ParensToken, Token } from "../../../@types/index.d.ts";
2
+ type RGBKeyType = "r" | "g" | "b" | "alpha";
3
+ type HSLKeyType = "h" | "s" | "l" | "alpha";
4
+ type HWBKeyType = "h" | "w" | "b" | "alpha";
5
+ type LABKeyType = "l" | "a" | "b" | "alpha";
6
+ type OKLABKeyType = "l" | "a" | "b" | "alpha";
7
+ type XYZKeyType = "x" | "y" | "z" | "alpha";
8
+ type LCHKeyType = "l" | "c" | "h" | "alpha";
9
+ type OKLCHKeyType = "l" | "c" | "h" | "alpha";
10
+ export type RelativeColorTypes = RGBKeyType | HSLKeyType | HWBKeyType | LABKeyType | OKLABKeyType | LCHKeyType | OKLCHKeyType | XYZKeyType;
11
+ export declare function parseRelativeColor(relativeKeys: string, original: ColorToken, rExp: Token, gExp: Token, bExp: Token, aExp: Token | null): Record<RelativeColorTypes, Token> | null;
12
+ export declare function replaceValue(parent: FunctionToken | ParensToken | BinaryExpressionToken, value: Token, newValue: Token): void;
13
+ export {};