@tbela99/css-parser 1.0.0 → 1.1.1-alpha4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +269 -0
  2. package/README.md +16 -11
  3. package/dist/index-umd-web.js +3805 -1894
  4. package/dist/index.cjs +3806 -1895
  5. package/dist/index.d.ts +184 -57
  6. package/dist/lib/ast/expand.js +2 -1
  7. package/dist/lib/ast/features/calc.js +12 -1
  8. package/dist/lib/ast/features/inlinecssvariables.js +47 -24
  9. package/dist/lib/ast/features/prefix.js +117 -86
  10. package/dist/lib/ast/features/shorthand.js +29 -6
  11. package/dist/lib/ast/features/transform.js +10 -3
  12. package/dist/lib/ast/features/type.js +7 -0
  13. package/dist/lib/ast/math/expression.js +7 -1
  14. package/dist/lib/ast/math/math.js +6 -0
  15. package/dist/lib/ast/minify.js +165 -77
  16. package/dist/lib/ast/transform/compute.js +1 -0
  17. package/dist/lib/ast/transform/matrix.js +1 -0
  18. package/dist/lib/ast/types.js +26 -15
  19. package/dist/lib/ast/utils/utils.js +104 -0
  20. package/dist/lib/ast/walk.js +33 -7
  21. package/dist/lib/fs/resolve.js +10 -0
  22. package/dist/lib/parser/declaration/list.js +48 -45
  23. package/dist/lib/parser/declaration/map.js +1 -0
  24. package/dist/lib/parser/declaration/set.js +2 -1
  25. package/dist/lib/parser/parse.js +350 -279
  26. package/dist/lib/parser/tokenize.js +147 -72
  27. package/dist/lib/parser/utils/declaration.js +4 -3
  28. package/dist/lib/parser/utils/type.js +2 -1
  29. package/dist/lib/renderer/color/a98rgb.js +2 -1
  30. package/dist/lib/renderer/color/color-mix.js +10 -7
  31. package/dist/lib/renderer/color/color.js +171 -153
  32. package/dist/lib/renderer/color/hex.js +2 -1
  33. package/dist/lib/renderer/color/hsl.js +2 -1
  34. package/dist/lib/renderer/color/hwb.js +2 -1
  35. package/dist/lib/renderer/color/lab.js +2 -1
  36. package/dist/lib/renderer/color/lch.js +2 -1
  37. package/dist/lib/renderer/color/oklab.js +2 -1
  38. package/dist/lib/renderer/color/oklch.js +2 -1
  39. package/dist/lib/renderer/color/p3.js +2 -1
  40. package/dist/lib/renderer/color/rec2020.js +2 -1
  41. package/dist/lib/renderer/color/relativecolor.js +17 -11
  42. package/dist/lib/renderer/color/rgb.js +4 -3
  43. package/dist/lib/renderer/color/srgb.js +18 -17
  44. package/dist/lib/renderer/color/utils/components.js +6 -5
  45. package/dist/lib/renderer/color/utils/constants.js +47 -3
  46. package/dist/lib/renderer/color/xyz.js +2 -1
  47. package/dist/lib/renderer/color/xyzd50.js +2 -1
  48. package/dist/lib/renderer/render.js +48 -20
  49. package/dist/lib/syntax/syntax.js +257 -140
  50. package/dist/lib/validation/at-rules/container.js +75 -97
  51. package/dist/lib/validation/at-rules/counter-style.js +9 -8
  52. package/dist/lib/validation/at-rules/custom-media.js +13 -15
  53. package/dist/lib/validation/at-rules/document.js +22 -27
  54. package/dist/lib/validation/at-rules/font-feature-values.js +8 -8
  55. package/dist/lib/validation/at-rules/import.js +30 -81
  56. package/dist/lib/validation/at-rules/keyframes.js +18 -22
  57. package/dist/lib/validation/at-rules/layer.js +5 -5
  58. package/dist/lib/validation/at-rules/media.js +42 -52
  59. package/dist/lib/validation/at-rules/namespace.js +19 -23
  60. package/dist/lib/validation/at-rules/page-margin-box.js +15 -18
  61. package/dist/lib/validation/at-rules/page.js +8 -7
  62. package/dist/lib/validation/at-rules/supports.js +73 -82
  63. package/dist/lib/validation/at-rules/when.js +32 -36
  64. package/dist/lib/validation/atrule.js +15 -14
  65. package/dist/lib/validation/config.js +24 -1
  66. package/dist/lib/validation/config.json.js +611 -111
  67. package/dist/lib/validation/parser/parse.js +206 -212
  68. package/dist/lib/validation/parser/types.js +1 -1
  69. package/dist/lib/validation/selector.js +3 -3
  70. package/dist/lib/validation/syntax.js +984 -0
  71. package/dist/lib/validation/syntaxes/complex-selector-list.js +10 -11
  72. package/dist/lib/validation/syntaxes/complex-selector.js +10 -11
  73. package/dist/lib/validation/syntaxes/compound-selector.js +40 -50
  74. package/dist/lib/validation/syntaxes/family-name.js +9 -8
  75. package/dist/lib/validation/syntaxes/keyframe-block-list.js +4 -3
  76. package/dist/lib/validation/syntaxes/keyframe-selector.js +15 -18
  77. package/dist/lib/validation/syntaxes/layer-name.js +6 -5
  78. package/dist/lib/validation/syntaxes/relative-selector-list.js +7 -6
  79. package/dist/lib/validation/syntaxes/relative-selector.js +2 -1
  80. package/dist/lib/validation/syntaxes/url.js +18 -22
  81. package/dist/lib/validation/utils/list.js +2 -1
  82. package/dist/lib/validation/utils/whitespace.js +2 -1
  83. package/dist/node/index.js +4 -2
  84. package/dist/node/load.js +5 -0
  85. package/dist/web/index.js +4 -2
  86. package/dist/web/load.js +5 -0
  87. package/package.json +14 -13
@@ -2,14 +2,16 @@ import { EnumToken } from '../../ast/types.js';
2
2
  import '../../ast/minify.js';
3
3
  import '../../ast/walk.js';
4
4
  import '../../parser/parse.js';
5
+ import '../../parser/tokenize.js';
6
+ import '../../parser/utils/config.js';
5
7
  import { srgb2rgb, lch2rgb, lab2rgb, oklch2rgb, oklab2rgb, hwb2rgb, hsl2rgb, hex2rgb } from './rgb.js';
6
8
  import { srgb2hsl, lch2hsl, lab2hsl, oklch2hsl, oklab2hsl, hwb2hsl, hex2hsl, rgb2hsl } from './hsl.js';
7
9
  import { lch2hwb, lab2hwb, oklch2hwb, oklab2hwb, hsl2hwb, rgb2hwb } from './hwb.js';
8
10
  import { srgb2lab, oklch2lab, oklab2lab, lch2lab, hwb2lab, hsl2lab, rgb2lab, hex2lab } from './lab.js';
9
11
  import { srgb2lch, oklch2lch, oklab2lch, lab2lch, hwb2lch, hsl2lch, rgb2lch, hex2lch } from './lch.js';
10
12
  import { srgb2oklab, oklch2oklab, lch2oklab, lab2oklab, hwb2oklab, hsl2oklab, rgb2oklab, hex2oklab } from './oklab.js';
11
- import { lch2oklch, oklab2oklch, lab2oklch, hwb2oklch, hsl2oklch, rgb2oklch, hex2oklch } from './oklch.js';
12
- import { colorFuncColorSpace } from './utils/constants.js';
13
+ import { srgb2oklch, lch2oklch, oklab2oklch, lab2oklch, hwb2oklch, hsl2oklch, rgb2oklch, hex2oklch } from './oklch.js';
14
+ import { ColorKind, colorFuncColorSpace } from './utils/constants.js';
13
15
  import { getComponents } from './utils/components.js';
14
16
  import { xyz2srgb, lsrgb2srgbvalues, srgb2lsrgbvalues, lch2srgb, oklab2srgb, lab2srgb, hwb2srgb, hsl2srgb, rgb2srgb, hex2srgb } from './srgb.js';
15
17
  import { prophotorgb2srgbvalues, srgb2prophotorgbvalues } from './prophotorgb.js';
@@ -19,58 +21,57 @@ import { srgb2xyz } from './xyz.js';
19
21
  import { p32srgbvalues, srgb2p3values } from './p3.js';
20
22
  import { xyzd502srgb, XYZ_D65_to_D50 } from './xyzd50.js';
21
23
  import '../sourcemap/lib/encode.js';
22
- import '../../parser/utils/config.js';
23
24
 
24
25
  function convert(token, to) {
25
26
  if (token.kin == to) {
26
27
  return token;
27
28
  }
28
- if (token.kin == 'color') {
29
+ if (token.kin == ColorKind.COLOR) {
29
30
  const colorSpace = token.chi.find(t => ![EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType].includes(t.typ));
30
- if (colorSpace.val == to) {
31
+ if (colorSpace.val == ColorKind[to].toLowerCase().replaceAll('_', '-')) {
31
32
  return token;
32
33
  }
33
34
  }
34
35
  let values = [];
35
- if (to == 'hsl') {
36
+ if (to == ColorKind.HSL) {
36
37
  let t;
37
38
  switch (token.kin) {
38
- case 'rgb':
39
- case 'rgba':
39
+ case ColorKind.RGB:
40
+ case ColorKind.RGBA:
40
41
  t = rgb2hsl(token);
41
42
  if (t == null) {
42
43
  return null;
43
44
  }
44
45
  values.push(...t);
45
46
  break;
46
- case 'hex':
47
- case 'lit':
47
+ case ColorKind.HEX:
48
+ case ColorKind.LIT:
48
49
  values.push(...hex2hsl(token));
49
50
  break;
50
- case 'hwb':
51
+ case ColorKind.HWB:
51
52
  values.push(...hwb2hsl(token));
52
53
  break;
53
- case 'oklab':
54
+ case ColorKind.OKLAB:
54
55
  t = oklab2hsl(token);
55
56
  if (t == null) {
56
57
  return null;
57
58
  }
58
59
  values.push(...t);
59
60
  break;
60
- case 'oklch':
61
+ case ColorKind.OKLCH:
61
62
  t = oklch2hsl(token);
62
63
  if (t == null) {
63
64
  return null;
64
65
  }
65
66
  values.push(...t);
66
67
  break;
67
- case 'lab':
68
+ case ColorKind.LAB:
68
69
  values.push(...lab2hsl(token));
69
70
  break;
70
- case 'lch':
71
+ case ColorKind.LCH:
71
72
  values.push(...lch2hsl(token));
72
73
  break;
73
- case 'color':
74
+ case ColorKind.COLOR:
74
75
  // @ts-ignore
75
76
  values.push(...srgb2hsl(...color2srgbvalues(token)));
76
77
  break;
@@ -79,30 +80,30 @@ function convert(token, to) {
79
80
  return values2hsltoken(values);
80
81
  }
81
82
  }
82
- else if (to == 'hwb') {
83
+ else if (to == ColorKind.HWB) {
83
84
  switch (token.kin) {
84
- case 'rgb':
85
- case 'rgba':
85
+ case ColorKind.RGB:
86
+ case ColorKind.RGBA:
86
87
  values.push(...rgb2hwb(token));
87
88
  break;
88
- case 'hex':
89
- case 'lit':
89
+ case ColorKind.HEX:
90
+ case ColorKind.LIT:
90
91
  values.push(...hex2hsl(token));
91
92
  break;
92
- case 'hsl':
93
- case 'hsla':
93
+ case ColorKind.HSL:
94
+ case ColorKind.HSLA:
94
95
  values.push(...hsl2hwb(token));
95
96
  break;
96
- case 'oklab':
97
+ case ColorKind.OKLAB:
97
98
  values.push(...oklab2hwb(token));
98
99
  break;
99
- case 'oklch':
100
+ case ColorKind.OKLCH:
100
101
  values.push(...oklch2hwb(token));
101
102
  break;
102
- case 'lab':
103
+ case ColorKind.LAB:
103
104
  values.push(...lab2hwb(token));
104
105
  break;
105
- case 'lch':
106
+ case ColorKind.LCH:
106
107
  values.push(...lch2hwb(token));
107
108
  break;
108
109
  }
@@ -110,56 +111,56 @@ function convert(token, to) {
110
111
  return values2hwbtoken(values);
111
112
  }
112
113
  }
113
- else if (to == 'rgb') {
114
+ else if (to == ColorKind.RGB) {
114
115
  let t;
115
116
  switch (token.kin) {
116
- case 'hex':
117
- case 'lit':
117
+ case ColorKind.HEX:
118
+ case ColorKind.LIT:
118
119
  values.push(...hex2rgb(token));
119
120
  break;
120
- case 'hsl':
121
+ case ColorKind.HSL:
121
122
  t = hsl2rgb(token);
122
123
  if (t == null) {
123
124
  return null;
124
125
  }
125
126
  values.push(...t);
126
127
  break;
127
- case 'hwb':
128
+ case ColorKind.HWB:
128
129
  t = hwb2rgb(token);
129
130
  if (t == null) {
130
131
  return null;
131
132
  }
132
133
  values.push(...t);
133
134
  break;
134
- case 'oklab':
135
+ case ColorKind.OKLAB:
135
136
  t = oklab2rgb(token);
136
137
  if (t == null) {
137
138
  return null;
138
139
  }
139
140
  values.push(...t);
140
141
  break;
141
- case 'oklch':
142
+ case ColorKind.OKLCH:
142
143
  t = oklch2rgb(token);
143
144
  if (t == null) {
144
145
  return null;
145
146
  }
146
147
  values.push(...t);
147
148
  break;
148
- case 'lab':
149
+ case ColorKind.LAB:
149
150
  t = lab2rgb(token);
150
151
  if (t == null) {
151
152
  return null;
152
153
  }
153
154
  values.push(...t);
154
155
  break;
155
- case 'lch':
156
+ case ColorKind.LCH:
156
157
  t = lch2rgb(token);
157
158
  if (t == null) {
158
159
  return null;
159
160
  }
160
161
  values.push(...t);
161
162
  break;
162
- case 'color':
163
+ case ColorKind.COLOR:
163
164
  // @ts-ignore
164
165
  values.push(...srgb2rgb(...color2srgbvalues(token)));
165
166
  break;
@@ -168,33 +169,33 @@ function convert(token, to) {
168
169
  return values2rgbtoken(values);
169
170
  }
170
171
  }
171
- else if (to == 'lab') {
172
+ else if (to == ColorKind.LAB) {
172
173
  switch (token.kin) {
173
- case 'hex':
174
- case 'lit':
174
+ case ColorKind.HEX:
175
+ case ColorKind.LIT:
175
176
  values.push(...hex2lab(token));
176
177
  break;
177
- case 'rgb':
178
- case 'rgba':
178
+ case ColorKind.RGB:
179
+ case ColorKind.RGBA:
179
180
  values.push(...rgb2lab(token));
180
181
  break;
181
- case 'hsl':
182
- case 'hsla':
182
+ case ColorKind.HSL:
183
+ case ColorKind.HSLA:
183
184
  values.push(...hsl2lab(token));
184
185
  break;
185
- case 'hwb':
186
+ case ColorKind.HWB:
186
187
  values.push(...hwb2lab(token));
187
188
  break;
188
- case 'lch':
189
+ case ColorKind.LCH:
189
190
  values.push(...lch2lab(token));
190
191
  break;
191
- case 'oklab':
192
+ case ColorKind.OKLAB:
192
193
  values.push(...oklab2lab(token));
193
194
  break;
194
- case 'oklch':
195
+ case ColorKind.OKLCH:
195
196
  values.push(...oklch2lab(token));
196
197
  break;
197
- case 'color':
198
+ case ColorKind.COLOR:
198
199
  // @ts-ignore
199
200
  values.push(...srgb2lab(...color2srgbvalues(token)));
200
201
  break;
@@ -203,33 +204,33 @@ function convert(token, to) {
203
204
  return values2colortoken(values, to);
204
205
  }
205
206
  }
206
- else if (to == 'lch') {
207
+ else if (to == ColorKind.LCH) {
207
208
  switch (token.kin) {
208
- case 'hex':
209
- case 'lit':
209
+ case ColorKind.HEX:
210
+ case ColorKind.LIT:
210
211
  values.push(...hex2lch(token));
211
212
  break;
212
- case 'rgb':
213
- case 'rgba':
213
+ case ColorKind.RGB:
214
+ case ColorKind.RGBA:
214
215
  values.push(...rgb2lch(token));
215
216
  break;
216
- case 'hsl':
217
- case 'hsla':
217
+ case ColorKind.HSL:
218
+ case ColorKind.HSLA:
218
219
  values.push(...hsl2lch(token));
219
220
  break;
220
- case 'hwb':
221
+ case ColorKind.HWB:
221
222
  values.push(...hwb2lch(token));
222
223
  break;
223
- case 'lab':
224
+ case ColorKind.LAB:
224
225
  values.push(...lab2lch(token));
225
226
  break;
226
- case 'oklab':
227
+ case ColorKind.OKLAB:
227
228
  values.push(...oklab2lch(token));
228
229
  break;
229
- case 'oklch':
230
+ case ColorKind.OKLCH:
230
231
  values.push(...oklch2lch(token));
231
232
  break;
232
- case 'color':
233
+ case ColorKind.COLOR:
233
234
  // @ts-ignore
234
235
  values.push(...srgb2lch(...color2srgbvalues(token)));
235
236
  break;
@@ -238,33 +239,33 @@ function convert(token, to) {
238
239
  return values2colortoken(values, to);
239
240
  }
240
241
  }
241
- else if (to == 'oklab') {
242
+ else if (to == ColorKind.OKLAB) {
242
243
  switch (token.kin) {
243
- case 'hex':
244
- case 'lit':
244
+ case ColorKind.HEX:
245
+ case ColorKind.LIT:
245
246
  values.push(...hex2oklab(token));
246
247
  break;
247
- case 'rgb':
248
- case 'rgba':
248
+ case ColorKind.RGB:
249
+ case ColorKind.RGBA:
249
250
  values.push(...rgb2oklab(token));
250
251
  break;
251
- case 'hsl':
252
- case 'hsla':
252
+ case ColorKind.HSL:
253
+ case ColorKind.HSLA:
253
254
  values.push(...hsl2oklab(token));
254
255
  break;
255
- case 'hwb':
256
+ case ColorKind.HWB:
256
257
  values.push(...hwb2oklab(token));
257
258
  break;
258
- case 'lab':
259
+ case ColorKind.LAB:
259
260
  values.push(...lab2oklab(token));
260
261
  break;
261
- case 'lch':
262
+ case ColorKind.LCH:
262
263
  values.push(...lch2oklab(token));
263
264
  break;
264
- case 'oklch':
265
+ case ColorKind.OKLCH:
265
266
  values.push(...oklch2oklab(token));
266
267
  break;
267
- case 'color':
268
+ case ColorKind.COLOR:
268
269
  // @ts-ignore
269
270
  values.push(...srgb2oklab(...color2srgbvalues(token)));
270
271
  break;
@@ -273,168 +274,184 @@ function convert(token, to) {
273
274
  return values2colortoken(values, to);
274
275
  }
275
276
  }
276
- else if (to == 'oklch') {
277
+ else if (to == ColorKind.OKLCH) {
277
278
  switch (token.kin) {
278
- case 'hex':
279
- case 'lit':
279
+ case ColorKind.HEX:
280
+ case ColorKind.LIT:
280
281
  values.push(...hex2oklch(token));
281
282
  break;
282
- case 'rgb':
283
- case 'rgba':
283
+ case ColorKind.RGB:
284
+ case ColorKind.RGBA:
284
285
  values.push(...rgb2oklch(token));
285
286
  break;
286
- case 'hsl':
287
- case 'hsla':
287
+ case ColorKind.HSL:
288
+ case ColorKind.HSLA:
288
289
  values.push(...hsl2oklch(token));
289
290
  break;
290
- case 'hwb':
291
+ case ColorKind.HWB:
291
292
  values.push(...hwb2oklch(token));
292
293
  break;
293
- case 'lab':
294
+ case ColorKind.LAB:
294
295
  values.push(...lab2oklch(token));
295
296
  break;
296
- case 'oklab':
297
+ case ColorKind.OKLAB:
297
298
  values.push(...oklab2oklch(token));
298
299
  break;
299
- case 'lch':
300
+ case ColorKind.LCH:
300
301
  values.push(...lch2oklch(token));
301
302
  break;
302
- case 'color':
303
+ case ColorKind.COLOR:
303
304
  // @ts-ignore
304
- let val = color2srgbvalues(token);
305
- switch (to) {
306
- case 'srgb':
307
- values.push(...val);
308
- break;
309
- case 'srgb-linear':
310
- // @ts-ignore
311
- values.push(...srgb2lsrgbvalues(...val));
312
- break;
313
- case 'display-p3':
314
- // @ts-ignore
315
- values.push(...srgb2p3values(...val));
316
- break;
317
- case 'prophoto-rgb':
318
- // @ts-ignore
319
- values.push(...srgb2prophotorgbvalues(...val));
320
- break;
321
- case 'a98-rgb':
322
- // @ts-ignore
323
- values.push(...srgb2a98values(...val));
324
- break;
325
- case 'rec2020':
326
- // @ts-ignore
327
- values.push(...srgb2rec2020values(...val));
328
- break;
329
- case 'xyz':
330
- case 'xyz-d65':
331
- // @ts-ignore
332
- values.push(...srgb2xyz(...val));
333
- break;
334
- case 'xyz-d50':
335
- // @ts-ignore
336
- values.push(...(XYZ_D65_to_D50(...srgb2xyz(...val))));
337
- break;
338
- }
305
+ values.push(...srgb2oklch(...color2srgbvalues(token)));
306
+ // switch (to) {
307
+ //
308
+ // case ColorKind.SRGB:
309
+ //
310
+ // values.push(...val);
311
+ // break;
312
+ //
313
+ // case ColorKind.SRGB_LINEAR:
314
+ //
315
+ // // @ts-ignore
316
+ // values.push(...srgb2lsrgbvalues(...val));
317
+ // break;
318
+ //
319
+ // case ColorKind.DISPLAY_P3:
320
+ //
321
+ // // @ts-ignore
322
+ // values.push(...srgb2p3values(...val));
323
+ // break;
324
+ //
325
+ // case ColorKind.PROPHOTO_RGB:
326
+ //
327
+ // // @ts-ignore
328
+ // values.push(...srgb2prophotorgbvalues(...val));
329
+ // break;
330
+ //
331
+ // case ColorKind.A98_RGB:
332
+ //
333
+ // // @ts-ignore
334
+ // values.push(...srgb2a98values(...val));
335
+ // break;
336
+ //
337
+ // case ColorKind.REC2020:
338
+ //
339
+ // // @ts-ignore
340
+ // values.push(...srgb2rec2020values(...val));
341
+ // break;
342
+ //
343
+ // case ColorKind.XYZ:
344
+ // case ColorKind.XYZ_D65:
345
+ //
346
+ // // @ts-ignore
347
+ // values.push(...srgb2xyz(...val));
348
+ // break;
349
+ //
350
+ // case ColorKind.XYZ_D50:
351
+ //
352
+ // // @ts-ignore
353
+ // values.push(...(XYZ_D65_to_D50(...srgb2xyz(...val))));
354
+ // break;
355
+ // }
339
356
  break;
340
357
  }
341
358
  if (values.length > 0) {
342
359
  return values2colortoken(values, to);
343
360
  }
344
361
  }
345
- else if (colorFuncColorSpace.includes(to)) {
362
+ else if (colorFuncColorSpace.includes(ColorKind[to].toLowerCase().replaceAll('_', '-'))) {
346
363
  let t;
347
364
  switch (token.kin) {
348
- case 'hex':
349
- case 'lit':
365
+ case ColorKind.HEX:
366
+ case ColorKind.LIT:
350
367
  values.push(...hex2srgb(token));
351
368
  break;
352
- case 'rgb':
353
- case 'rgba':
369
+ case ColorKind.RGB:
370
+ case ColorKind.RGBA:
354
371
  t = rgb2srgb(token);
355
372
  if (t == null) {
356
373
  return null;
357
374
  }
358
375
  values.push(...t);
359
376
  break;
360
- case 'hsl':
361
- case 'hsla':
377
+ case ColorKind.HSL:
378
+ case ColorKind.HSLA:
362
379
  t = hsl2srgb(token);
363
380
  if (t == null) {
364
381
  return null;
365
382
  }
366
383
  values.push(...t);
367
384
  break;
368
- case 'hwb':
385
+ case ColorKind.HWB:
369
386
  t = hwb2srgb(token);
370
387
  if (t == null) {
371
388
  return null;
372
389
  }
373
390
  values.push(...t);
374
391
  break;
375
- case 'lab':
392
+ case ColorKind.LAB:
376
393
  t = lab2srgb(token);
377
394
  if (t == null) {
378
395
  return null;
379
396
  }
380
397
  values.push(...t);
381
398
  break;
382
- case 'oklab':
399
+ case ColorKind.OKLAB:
383
400
  t = oklab2srgb(token);
384
401
  if (t == null) {
385
402
  return null;
386
403
  }
387
404
  values.push(...t);
388
405
  break;
389
- case 'lch':
406
+ case ColorKind.LCH:
390
407
  t = lch2srgb(token);
391
408
  if (t == null) {
392
409
  return null;
393
410
  }
394
411
  values.push(...t);
395
412
  break;
396
- case 'oklch':
413
+ case ColorKind.OKLCH:
397
414
  t = color2srgbvalues(token);
398
415
  if (t == null) {
399
416
  return null;
400
417
  }
401
418
  values.push(...t);
402
419
  break;
403
- case 'color':
420
+ case ColorKind.COLOR:
404
421
  const val = color2srgbvalues(token);
405
422
  if (val == null) {
406
423
  return null;
407
424
  }
408
425
  switch (to) {
409
- case 'srgb':
426
+ case ColorKind.SRGB:
410
427
  values.push(...val);
411
428
  break;
412
- case 'srgb-linear':
429
+ case ColorKind.SRGB_LINEAR:
413
430
  // @ts-ignore
414
431
  values.push(...srgb2lsrgbvalues(...val));
415
432
  break;
416
- case 'display-p3':
433
+ case ColorKind.DISPLAY_P3:
417
434
  // @ts-ignore
418
435
  values.push(...srgb2p3values(...val));
419
436
  break;
420
- case 'prophoto-rgb':
437
+ case ColorKind.PROPHOTO_RGB:
421
438
  // @ts-ignore
422
439
  values.push(...srgb2prophotorgbvalues(...val));
423
440
  break;
424
- case 'a98-rgb':
441
+ case ColorKind.A98_RGB:
425
442
  // @ts-ignore
426
443
  values.push(...srgb2a98values(...val));
427
444
  break;
428
- case 'rec2020':
445
+ case ColorKind.REC2020:
429
446
  // @ts-ignore
430
447
  values.push(...srgb2rec2020values(...val));
431
448
  break;
432
- case 'xyz':
433
- case 'xyz-d65':
449
+ case ColorKind.XYZ:
450
+ case ColorKind.XYZ_D65:
434
451
  // @ts-ignore
435
452
  values.push(...srgb2xyz(...val));
436
453
  break;
437
- case 'xyz-d50':
454
+ case ColorKind.XYZ_D50:
438
455
  // @ts-ignore
439
456
  values.push(...(XYZ_D65_to_D50(...srgb2xyz(...val))));
440
457
  break;
@@ -498,7 +515,7 @@ function color2srgbvalues(token) {
498
515
  return values;
499
516
  }
500
517
  function values2hsltoken(values) {
501
- const to = 'hsl';
518
+ const to = ColorKind.HSL;
502
519
  const chi = [
503
520
  { typ: EnumToken.AngleTokenType, val: String(values[0] * 360), unit: 'deg' },
504
521
  { typ: EnumToken.PercentageTokenType, val: String(values[1] * 100) },
@@ -509,13 +526,13 @@ function values2hsltoken(values) {
509
526
  }
510
527
  return {
511
528
  typ: EnumToken.ColorTokenType,
512
- val: to,
529
+ val: ColorKind[to].toLowerCase().replaceAll('_', '-'),
513
530
  chi,
514
531
  kin: to
515
532
  };
516
533
  }
517
534
  function values2rgbtoken(values) {
518
- const to = 'rgb';
535
+ const to = ColorKind.RGB;
519
536
  const chi = [
520
537
  { typ: EnumToken.NumberTokenType, val: String(values[0]) },
521
538
  { typ: EnumToken.NumberTokenType, val: String(values[1]) },
@@ -526,13 +543,13 @@ function values2rgbtoken(values) {
526
543
  }
527
544
  return {
528
545
  typ: EnumToken.ColorTokenType,
529
- val: to,
546
+ val: ColorKind[to],
530
547
  chi,
531
548
  kin: to
532
549
  };
533
550
  }
534
551
  function values2hwbtoken(values) {
535
- const to = 'hwb';
552
+ const to = ColorKind.HWB;
536
553
  const chi = [
537
554
  { typ: EnumToken.AngleTokenType, val: String(values[0] * 360), unit: 'deg' },
538
555
  { typ: EnumToken.PercentageTokenType, val: String(values[1] * 100) },
@@ -543,7 +560,7 @@ function values2hwbtoken(values) {
543
560
  }
544
561
  return {
545
562
  typ: EnumToken.ColorTokenType,
546
- val: to,
563
+ val: ColorKind[to],
547
564
  chi,
548
565
  kin: to
549
566
  };
@@ -557,14 +574,15 @@ function values2colortoken(values, to) {
557
574
  if (values.length == 4) {
558
575
  chi.push({ typ: EnumToken.PercentageTokenType, val: String(values[3] * 100) });
559
576
  }
560
- return colorFuncColorSpace.includes(to) ? {
577
+ const colorSpace = ColorKind[to].toLowerCase().replaceAll('_', '-');
578
+ return colorFuncColorSpace.includes(colorSpace) ? {
561
579
  typ: EnumToken.ColorTokenType,
562
580
  val: 'color',
563
- chi: [{ typ: EnumToken.IdenTokenType, val: to }].concat(chi),
564
- kin: 'color'
581
+ chi: [{ typ: EnumToken.IdenTokenType, val: colorSpace }].concat(chi),
582
+ kin: ColorKind.COLOR
565
583
  } : {
566
584
  typ: EnumToken.ColorTokenType,
567
- val: to,
585
+ val: colorSpace,
568
586
  chi,
569
587
  kin: to
570
588
  };
@@ -574,7 +592,7 @@ function values2colortoken(values, to) {
574
592
  * @param token
575
593
  */
576
594
  function clamp(token) {
577
- if (token.kin == 'rgb' || token.kin == 'rgba') {
595
+ if (token.kin == ColorKind.RGB || token.kin == ColorKind.RGBA) {
578
596
  token.chi.filter((token) => ![EnumToken.LiteralTokenType, EnumToken.CommaTokenType, EnumToken.WhitespaceTokenType].includes(token.typ)).forEach((token, index) => {
579
597
  if (index <= 2) {
580
598
  if (token.typ == EnumToken.NumberTokenType) {