@tbela99/css-parser 1.8.1 → 2.0.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 (105) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +129 -31
  3. package/dist/index-umd-web.js +27382 -24086
  4. package/dist/index.d.ts +2737 -2200
  5. package/dist/package.json.js +2 -2
  6. package/dist/src/data/properties.json.js +1 -1
  7. package/dist/src/data/validation.json.js +1 -1
  8. package/dist/src/lib/ast/arena-node.js +548 -0
  9. package/dist/src/lib/ast/arena.js +3198 -0
  10. package/dist/src/lib/ast/features/calc.js +85 -76
  11. package/dist/src/lib/ast/features/if.js +155 -115
  12. package/dist/src/lib/ast/features/index.js +1 -1
  13. package/dist/src/lib/ast/features/inlinecssvariables.js +77 -84
  14. package/dist/src/lib/ast/features/prefix.js +184 -183
  15. package/dist/src/lib/ast/features/shorthand.js +40 -46
  16. package/dist/src/lib/ast/features/transform.js +24 -24
  17. package/dist/src/lib/ast/features/type.js +1 -1
  18. package/dist/src/lib/ast/fingerprint.js +333 -0
  19. package/dist/src/lib/ast/math/expression.js +458 -543
  20. package/dist/src/lib/ast/math/math.js +19 -41
  21. package/dist/src/lib/ast/minify.js +590 -647
  22. package/dist/src/lib/ast/transform/compute.js +82 -85
  23. package/dist/src/lib/ast/transform/matrix.js +21 -38
  24. package/dist/src/lib/ast/transform/minify.js +82 -193
  25. package/dist/src/lib/ast/transform/perspective.js +2 -3
  26. package/dist/src/lib/ast/transform/rotate.js +1 -1
  27. package/dist/src/lib/ast/transform/scale.js +1 -1
  28. package/dist/src/lib/ast/transform/skew.js +1 -1
  29. package/dist/src/lib/ast/transform/translate.js +1 -1
  30. package/dist/src/lib/ast/transform/utils.js +2 -2
  31. package/dist/src/lib/ast/types.js +263 -258
  32. package/dist/src/lib/ast/walk.js +246 -610
  33. package/dist/src/lib/fs/resolve.js +1 -1
  34. package/dist/src/lib/parser/declaration/list.js +223 -139
  35. package/dist/src/lib/parser/declaration/map.js +251 -238
  36. package/dist/src/lib/parser/declaration/set.js +74 -66
  37. package/dist/src/lib/parser/linesmap.js +1 -1
  38. package/dist/src/lib/parser/parse.js +1379 -1662
  39. package/dist/src/lib/parser/source.js +7 -4
  40. package/dist/src/lib/parser/tokenize.js +406 -199
  41. package/dist/src/lib/parser/utils/angle.js +11 -13
  42. package/dist/src/lib/parser/utils/at-rule-container.js +183 -168
  43. package/dist/src/lib/parser/utils/at-rule-font-feature-values.js +5 -5
  44. package/dist/src/lib/parser/utils/at-rule-generic.js +31 -24
  45. package/dist/src/lib/parser/utils/at-rule-import.js +44 -44
  46. package/dist/src/lib/parser/utils/at-rule-media.js +216 -205
  47. package/dist/src/lib/parser/utils/at-rule-support.js +83 -88
  48. package/dist/src/lib/parser/utils/at-rule-when-else.js +47 -47
  49. package/dist/src/lib/parser/utils/at-rule.js +5 -5
  50. package/dist/src/lib/parser/utils/base64.js +2 -2
  51. package/dist/src/lib/parser/utils/cache.js +1 -1
  52. package/dist/src/lib/parser/utils/config.js +1 -1
  53. package/dist/src/lib/parser/utils/declaration.js +233 -234
  54. package/dist/src/lib/parser/utils/eq.js +50 -3
  55. package/dist/src/lib/parser/utils/hash.js +2 -35
  56. package/dist/src/lib/parser/utils/selector.js +309 -387
  57. package/dist/src/lib/parser/utils/text.js +18 -4
  58. package/dist/src/lib/parser/utils/token.js +16 -69
  59. package/dist/src/lib/parser/utils/type.js +37 -24
  60. package/dist/src/lib/printer/render.js +965 -511
  61. package/dist/src/lib/printer/sourcemap/lib/codec.js +1 -1
  62. package/dist/src/lib/printer/sourcemap/sourcemap.js +1 -1
  63. package/dist/src/lib/syntax/color/a98rgb.js +1 -1
  64. package/dist/src/lib/syntax/color/alpha.js +36 -37
  65. package/dist/src/lib/syntax/color/cmyk.js +35 -52
  66. package/dist/src/lib/syntax/color/color-mix.js +96 -132
  67. package/dist/src/lib/syntax/color/color.js +222 -231
  68. package/dist/src/lib/syntax/color/hex.js +45 -55
  69. package/dist/src/lib/syntax/color/hsl.js +54 -62
  70. package/dist/src/lib/syntax/color/hwb.js +60 -68
  71. package/dist/src/lib/syntax/color/lab.js +59 -67
  72. package/dist/src/lib/syntax/color/lch.js +59 -67
  73. package/dist/src/lib/syntax/color/oklab.js +60 -68
  74. package/dist/src/lib/syntax/color/oklch.js +60 -67
  75. package/dist/src/lib/syntax/color/p3.js +1 -1
  76. package/dist/src/lib/syntax/color/prophotorgb.js +1 -1
  77. package/dist/src/lib/syntax/color/rec2020.js +1 -1
  78. package/dist/src/lib/syntax/color/relative-color.js +94 -144
  79. package/dist/src/lib/syntax/color/rgb.js +54 -57
  80. package/dist/src/lib/syntax/color/srgb.js +55 -53
  81. package/dist/src/lib/syntax/color/utils/color-type.js +13 -10
  82. package/dist/src/lib/syntax/color/utils/colorspace.js +11 -11
  83. package/dist/src/lib/syntax/color/utils/components.js +19 -20
  84. package/dist/src/lib/syntax/color/utils/distance.js +15 -13
  85. package/dist/src/lib/syntax/color/utils/make-color.js +15 -19
  86. package/dist/src/lib/syntax/color/utils/matrix.js +2 -2
  87. package/dist/src/lib/syntax/color/xyz.js +1 -1
  88. package/dist/src/lib/syntax/color/xyzd50.js +1 -1
  89. package/dist/src/lib/syntax/constants.js +2 -16
  90. package/dist/src/lib/syntax/syntax.js +301 -407
  91. package/dist/src/lib/validation/config.js +1 -1
  92. package/dist/src/lib/validation/match.js +959 -723
  93. package/dist/src/lib/validation/parser/parse.js +230 -112
  94. package/dist/src/lib/validation/parser/typedef.js +1 -1
  95. package/dist/src/lib/validation/utils/list.js +27 -12
  96. package/dist/src/node.js +12 -72
  97. package/dist/src/types.js +1 -1
  98. package/dist/src/utils/sync.js +9 -6
  99. package/dist/src/web.js +11 -73
  100. package/package.json +9 -10
  101. package/dist/index.cjs +0 -35874
  102. package/dist/src/lib/ast/clone.js +0 -51
  103. package/dist/src/lib/ast/expand.js +0 -311
  104. package/dist/src/lib/ast/find.js +0 -192
  105. package/dist/src/lib/ast/node.js +0 -59
@@ -2,7 +2,7 @@
2
2
  CSS parser, minifier and validator for node and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 1.8.1
5
+ Version: 2.0.0
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken, ColorType, EnumAstNodeStatus } from '../../ast/types.js';
@@ -23,7 +23,7 @@ import { srgb2rec2020values } from './rec2020.js';
23
23
  import { isRectangularOrthogonalColorspace, isPolarColorspace } from '../syntax.js';
24
24
  import { equalsIgnoreCase } from '../../parser/utils/text.js';
25
25
  import { srgb2a98values } from './a98rgb.js';
26
- import { STATE, colorRange } from '../constants.js';
26
+ import { colorRange } from '../constants.js';
27
27
 
28
28
  function interpolateHue(interpolationMethod, h1, h2) {
29
29
  switch (interpolationMethod) {
@@ -63,9 +63,9 @@ function interpolateHue(interpolationMethod, h1, h2) {
63
63
  * @param args
64
64
  * @returns
65
65
  */
66
- function colorMix(...args) {
66
+ function colorMix(arena, ...args) {
67
67
  // invalid color or custom color profile
68
- if (args.length == 0 || args[0].typ === EnumToken.DashedIdenTokenType) {
68
+ if (args.length == 0 || arena.dataTypes[args[0]] === EnumToken.DashedIdenTokenType) {
69
69
  return null;
70
70
  }
71
71
  let i = 0;
@@ -75,31 +75,31 @@ function colorMix(...args) {
75
75
  let colorSpace = "oklab";
76
76
  let hueInterpolationMethod = "shorter";
77
77
  let values = null;
78
- // const colors: ColorToken[] = [];
78
+ // const colors: Token[] = [];
79
79
  const percentages = [];
80
80
  const srgbComponentValues = [];
81
81
  const colorComponents = [];
82
82
  const colors = [];
83
- if (args[i]?.typ === EnumToken.IdenTokenType) {
84
- if (!equalsIgnoreCase(args[i++].val, "in")) {
83
+ if (arena.dataTypes[args[i]] === EnumToken.IdenTokenType) {
84
+ if (!equalsIgnoreCase(arena.strings[arena.stringValue[args[i++]]], "in")) {
85
85
  return null;
86
86
  }
87
- if (args[i]?.typ !== EnumToken.IdenTokenType) {
87
+ if (arena.dataTypes[args[i]] !== EnumToken.IdenTokenType) {
88
88
  return null;
89
89
  }
90
- if (isRectangularOrthogonalColorspace(args[i])) {
91
- colorSpace = args[i++].val;
90
+ if (isRectangularOrthogonalColorspace(arena, args[i])) {
91
+ colorSpace = arena.strings[arena.stringValue[args[i++]]];
92
92
  }
93
- else if (isPolarColorspace(args[i])) {
94
- colorSpace = args[i++].val;
95
- if (args[i]?.typ !== EnumToken.IdenTokenType && args[i]?.typ !== EnumToken.ColorTokenType) {
93
+ else if (isPolarColorspace(arena, args[i])) {
94
+ colorSpace = arena.strings[arena.stringValue[args[i++]]];
95
+ if (arena.dataTypes[args[i]] !== EnumToken.IdenTokenType && arena.dataTypes[args[i]] !== EnumToken.ColorTokenType) {
96
96
  return null;
97
97
  }
98
- if (args[i].typ === EnumToken.IdenTokenType && !equalsIgnoreCase(args[i].val, "hue")) {
99
- if (args[i]?.typ !== EnumToken.IdenTokenType) {
98
+ if (arena.dataTypes[args[i]] === EnumToken.IdenTokenType && !equalsIgnoreCase(arena.strings[arena.stringValue[args[i]]], "hue")) {
99
+ if (arena.dataTypes[args[i]] !== EnumToken.IdenTokenType) {
100
100
  return null;
101
101
  }
102
- hueInterpolationMethod = args[i++].val;
102
+ hueInterpolationMethod = arena.strings[arena.stringValue[args[i++]]];
103
103
  switch (hueInterpolationMethod) {
104
104
  case "increasing":
105
105
  case "decreasing":
@@ -109,30 +109,30 @@ function colorMix(...args) {
109
109
  default:
110
110
  return null;
111
111
  }
112
- if (!equalsIgnoreCase(args[i++].val, "hue")) {
112
+ if (!equalsIgnoreCase(arena.strings[arena.stringValue[args[i++]]], "hue")) {
113
113
  return null;
114
114
  }
115
115
  }
116
116
  }
117
117
  }
118
118
  while (i < args.length) {
119
- if (args[i].typ !== EnumToken.ColorTokenType ||
120
- ColorType.SYS == args[i].kin ||
121
- ColorType.DPSYS == args[i].kin ||
122
- ColorType.NON_STD == args[i].kin ||
123
- ColorType.CUSTOM_COLOR == args[i].kin ||
124
- equalsIgnoreCase(args[i].val, "currentcolor")) {
119
+ if (arena.dataTypes[args[i]] !== EnumToken.ColorTokenType ||
120
+ ColorType.SYS == arena.colorType[args[i]] ||
121
+ ColorType.DPSYS == arena.colorType[args[i]] ||
122
+ ColorType.NON_STD == arena.colorType[args[i]] ||
123
+ ColorType.CUSTOM_COLOR == arena.colorType[args[i]] ||
124
+ equalsIgnoreCase(arena.strings[arena.stringValue[args[i]]], "currentcolor")) {
125
125
  return null;
126
126
  }
127
- colorComponents.push(getColorComponents(args[i]));
128
- values = srgbvalues(args[i]);
127
+ colorComponents.push(getColorComponents(arena, args[i]));
128
+ values = srgbvalues(arena, args[i]);
129
129
  if (values == null) {
130
130
  return null;
131
131
  }
132
132
  // if (colorSpace == "hwb") {
133
133
  // colorSpace = "srgb";
134
134
  // }
135
- colors.push(processPowerlessComponents(args[i]));
135
+ colors.push(processPowerlessComponents(arena, args[i]));
136
136
  switch (colorSpace) {
137
137
  case "srgb":
138
138
  break;
@@ -184,24 +184,24 @@ function colorMix(...args) {
184
184
  return null;
185
185
  }
186
186
  srgbComponentValues.push(values);
187
- // colors.push(args[i++] as ColorToken);
187
+ // colors.push(args[i++]);
188
188
  i++;
189
189
  if (i >= args.length) {
190
190
  missingPercentageCount++;
191
191
  percentages.push(null);
192
192
  break;
193
193
  }
194
- if (args[i]?.typ === EnumToken.ColorTokenType) {
194
+ if (arena.dataTypes[args[i]] === EnumToken.ColorTokenType) {
195
195
  percentages.push(null);
196
196
  missingPercentageCount++;
197
197
  continue;
198
198
  }
199
- if (args[i]?.typ === EnumToken.PercentageTokenType ||
200
- (args[i]?.typ === EnumToken.NumberTokenType && 0 == args[i].val)) {
201
- if (args[i].val < 0) {
199
+ if (arena.dataTypes[args[i]] === EnumToken.PercentageTokenType ||
200
+ (arena.dataTypes[args[i]] === EnumToken.NumberTokenType && 0 == arena.numericValue[args[i]])) {
201
+ if (arena.numericValue[args[i]] < 0) {
202
202
  return null;
203
203
  }
204
- percentages.push(minmax(getNumber(args[i++]), 0, 1));
204
+ percentages.push(minmax(getNumber(arena, args[i++]), 0, 1));
205
205
  totalPercentage += percentages.at(-1);
206
206
  }
207
207
  }
@@ -248,10 +248,10 @@ function colorMix(...args) {
248
248
  let premult1;
249
249
  let premult2;
250
250
  let mixedPremult;
251
- let offset1 = colors[0].kin == ColorType.COLOR ? 1 : 0;
251
+ let offset1 = arena.colorType[colors[0]] == ColorType.COLOR ? 1 : 0;
252
252
  if (colorComponents[0][offset1 + 3] != null &&
253
- colorComponents[0][offset1 + 3].typ == EnumToken.IdenTokenType &&
254
- colorComponents[0][offset1 + 3].val == "none" &&
253
+ arena.dataTypes[colorComponents[0][offset1 + 3]] == EnumToken.IdenTokenType &&
254
+ arena.strings[arena.stringValue[colorComponents[0][offset1 + 3]]] == "none" &&
255
255
  colorComponents[1].length == offset1 + 4) {
256
256
  // fix powerless alpha for last color if previous color has alpha
257
257
  stack[stack.length - 1].color[3] = stack[stack.length - 2].color[3];
@@ -261,59 +261,59 @@ function colorMix(...args) {
261
261
  // powerless hue for lch spaces
262
262
  // if (lchSpaces.includes(colorSpace)) {
263
263
  // console.error(JSON.stringify({colorSpace1, colorSpace, stack, colorComponents}, null, 1));
264
- if ((stack[stack.length - 1].color[0] == 0 && colorComponents[0][offset1].typ == EnumToken.IdenTokenType &&
265
- colorComponents[0][offset1].val == "none") ||
266
- colorComponents[0][0][STATE] & EnumAstNodeStatus.PowerlessColorComponent) {
264
+ if ((stack[stack.length - 1].color[0] == 0 && arena.dataTypes[colorComponents[0][offset1]] == EnumToken.IdenTokenType &&
265
+ arena.strings[arena.stringValue[colorComponents[0][offset1]]] == "none") ||
266
+ arena.flags[colorComponents[0][0]] & EnumAstNodeStatus.PowerlessColorComponent) {
267
267
  stack[stack.length - 1].color[0] = stack[stack.length - 2].color[0];
268
268
  }
269
- if ((stack[stack.length - 1].color[1] == 0 && colorComponents[0][offset1 + 1].typ == EnumToken.IdenTokenType &&
270
- colorComponents[0][offset1 + 1].val == "none") ||
271
- colorComponents[0][1][STATE] & EnumAstNodeStatus.PowerlessColorComponent) {
269
+ if ((stack[stack.length - 1].color[1] == 0 && arena.dataTypes[colorComponents[0][offset1 + 1]] == EnumToken.IdenTokenType &&
270
+ arena.strings[arena.stringValue[colorComponents[0][offset1 + 1]]] == "none") ||
271
+ arena.flags[colorComponents[0][1]] & EnumAstNodeStatus.PowerlessColorComponent) {
272
272
  stack[stack.length - 1].color[1] = stack[stack.length - 2].color[1];
273
273
  }
274
- if ((stack[stack.length - 1].color[2] == 0 && colorComponents[0][offset1 + 2].typ == EnumToken.IdenTokenType &&
275
- colorComponents[0][offset1 + 2].val == "none") ||
276
- colorComponents[0][2][STATE] & EnumAstNodeStatus.PowerlessColorComponent ||
274
+ if ((stack[stack.length - 1].color[2] == 0 && arena.dataTypes[colorComponents[0][offset1 + 2]] == EnumToken.IdenTokenType &&
275
+ arena.strings[arena.stringValue[colorComponents[0][offset1 + 2]]] == "none") ||
276
+ arena.flags[colorComponents[0][2]] & EnumAstNodeStatus.PowerlessColorComponent ||
277
277
  (isLCHOrOKLCH &&
278
278
  (stack[stack.length - 1].color[1] == 0 ||
279
279
  stack[stack.length - 1].color[0] == 0 ||
280
280
  stack[stack.length - 1].color[0] ==
281
- colorRange[colors[0].kin == ColorType.LCH ? "lch" : "oklch"].l[1]))) {
281
+ colorRange[arena.colorType[colors[0]] == ColorType.LCH ? "lch" : "oklch"].l[1]))) {
282
282
  stack[stack.length - 1].color[2] = stack[stack.length - 2].color[2];
283
283
  }
284
284
  // }
285
285
  }
286
- // console.error([colorComponents[0][offset1].typ == EnumToken.IdenTokenType, (colorComponents[0][offset1] as IdentToken).val == "none"]);
286
+ // console.error([arena.dataTypes[colorComponents[0][offset1]] == EnumToken.IdenTokenType, arena.strings[arena.stringValue[colorComponents[0][offset1]]] == "none"]);
287
287
  // console.error(isLCHOrOKLCH, colorComponents, stack);
288
288
  while (stack.length > 1) {
289
289
  r1 = stack.pop();
290
290
  r2 = stack.pop();
291
- offset1 = colors[++currentIndex].kin == ColorType.COLOR ? 1 : 0;
291
+ offset1 = arena.colorType[colors[++currentIndex]] == ColorType.COLOR ? 1 : 0;
292
292
  // r2 powerless alpha
293
293
  if (colorComponents[currentIndex][offset1 + 3] != null &&
294
- colorComponents[currentIndex][offset1 + 3].typ == EnumToken.IdenTokenType &&
295
- colorComponents[currentIndex][offset1 + 3].val == "none") {
294
+ arena.dataTypes[colorComponents[currentIndex][offset1 + 3]] == EnumToken.IdenTokenType &&
295
+ arena.strings[arena.stringValue[colorComponents[currentIndex][offset1 + 3]]] == "none") {
296
296
  // fix powerless alpha for last color if previous color has alpha
297
297
  r2.color[3] = r1.color[3];
298
298
  }
299
299
  // powerless hue for lch spaces
300
- if ((r2.color[0] == 0 && colorComponents[currentIndex][offset1].typ == EnumToken.IdenTokenType &&
301
- colorComponents[currentIndex][offset1].val == "none") ||
302
- colorComponents[currentIndex][offset1][STATE] & EnumAstNodeStatus.PowerlessColorComponent) {
300
+ if ((r2.color[0] == 0 && arena.dataTypes[colorComponents[currentIndex][offset1]] == EnumToken.IdenTokenType &&
301
+ arena.strings[arena.stringValue[colorComponents[currentIndex][offset1]]] == "none") ||
302
+ arena.flags[colorComponents[currentIndex][offset1]] & EnumAstNodeStatus.PowerlessColorComponent) {
303
303
  r2.color[0] = r1.color[0];
304
304
  }
305
- if ((r2.color[1] == 0 && colorComponents[currentIndex][offset1 + 1].typ == EnumToken.IdenTokenType &&
306
- colorComponents[currentIndex][offset1 + 1].val == "none") ||
307
- colorComponents[currentIndex][offset1 + 1][STATE] & EnumAstNodeStatus.PowerlessColorComponent) {
305
+ if ((r2.color[1] == 0 && arena.dataTypes[colorComponents[currentIndex][offset1 + 1]] == EnumToken.IdenTokenType &&
306
+ arena.strings[arena.stringValue[colorComponents[currentIndex][offset1 + 1]]] == "none") ||
307
+ arena.flags[colorComponents[currentIndex][offset1 + 1]] & EnumAstNodeStatus.PowerlessColorComponent) {
308
308
  r2.color[1] = r1.color[1];
309
309
  }
310
- if ((r2.color[2] == 0 && colorComponents[currentIndex][offset1 + 2].typ == EnumToken.IdenTokenType &&
311
- colorComponents[currentIndex][offset1 + 2].val == "none") ||
312
- colorComponents[currentIndex][offset1 + 2][STATE] & EnumAstNodeStatus.PowerlessColorComponent ||
310
+ if ((r2.color[2] == 0 && arena.dataTypes[colorComponents[currentIndex][offset1 + 2]] == EnumToken.IdenTokenType &&
311
+ arena.strings[arena.stringValue[colorComponents[currentIndex][offset1 + 2]]] == "none") ||
312
+ arena.flags[colorComponents[currentIndex][offset1 + 2]] & EnumAstNodeStatus.PowerlessColorComponent ||
313
313
  (isLCHOrOKLCH &&
314
314
  (r2.color[1] == 0 ||
315
315
  r2.color[0] == 0 ||
316
- r2.color[0] == colorRange[colors[currentIndex].kin == ColorType.LCH ? "lch" : "oklch"].l[1]))) {
316
+ r2.color[0] == colorRange[arena.colorType[colors[currentIndex]] == ColorType.LCH ? "lch" : "oklch"].l[1]))) {
317
317
  r2.color[2] = r1.color[2];
318
318
  }
319
319
  if (hueInterpolationMethod != null) {
@@ -362,17 +362,7 @@ function colorMix(...args) {
362
362
  else {
363
363
  values = xyz2lchvalues(values[0], values[1], values[2], values[3]);
364
364
  }
365
- return {
366
- typ: EnumToken.ColorTokenType,
367
- val: "lch",
368
- chi: values.map((val) => {
369
- return {
370
- typ: EnumToken.NumberTokenType,
371
- val,
372
- };
373
- }),
374
- kin: ColorType.LCH,
375
- };
365
+ return arena.createColor("lch", ColorType.LCH, values.map((val) => arena.createToken(EnumToken.NumberTokenType, val)));
376
366
  case "srgb":
377
367
  case "srgb-linear":
378
368
  case "a98-rgb":
@@ -380,21 +370,12 @@ function colorMix(...args) {
380
370
  case "display-p3":
381
371
  case "display-p3-linear":
382
372
  case "prophoto-rgb":
383
- // @ts-ignore
384
- return {
385
- typ: EnumToken.ColorTokenType,
386
- val: "color",
387
- chi: [{ typ: EnumToken.IdenTokenType, val: colorSpace }].concat(
388
- // @ts-expect-error
389
- values.map((v) => {
390
- return {
391
- typ: EnumToken.NumberTokenType,
392
- val: v,
393
- };
394
- })),
395
- kin: ColorType.COLOR,
396
- cal: "col",
397
- };
373
+ {
374
+ const color = arena.createColor("color", ColorType.COLOR, [arena.createToken(EnumToken.IdenTokenType, colorSpace)].concat(values.map((v) => arena.createToken(EnumToken.NumberTokenType, v))));
375
+ // inlined: arena.setUnitString(color, "col")
376
+ arena.unit[color] = arena.internString("col");
377
+ return color;
378
+ }
398
379
  // case "rgb":
399
380
  case "hsl":
400
381
  case "hwb":
@@ -420,85 +401,68 @@ function colorMix(...args) {
420
401
  values[2] %= 360;
421
402
  }
422
403
  }
423
- // @ts-ignore
424
- const result = {
425
- typ: EnumToken.ColorTokenType,
426
- val: colorSpace,
427
- chi: values.map((v) => {
428
- return {
429
- typ: EnumToken.NumberTokenType,
430
- val: v,
431
- };
432
- }),
433
- kin: ColorType[colorSpace.toUpperCase().replaceAll("-", "_")],
434
- };
404
+ const components = values.map((v) => arena.createToken(EnumToken.NumberTokenType, v));
435
405
  if (colorSpace == "hsl") {
436
- // @ts-ignore
437
- result.chi[0] = { typ: EnumToken.AngleTokenType, val: result.chi[0].val };
438
- // @ts-ignore
439
- result.chi[1] = { typ: EnumToken.PercentageTokenType, val: result.chi[1].val };
440
- // @ts-ignore
441
- result.chi[2] = { typ: EnumToken.PercentageTokenType, val: result.chi[2].val };
406
+ arena.dataTypes[components[0]] = EnumToken.AngleTokenType;
407
+ // inlined: arena.setUnitString(components[0], "deg")
408
+ arena.unit[components[0]] = arena.internString("deg");
409
+ arena.dataTypes[components[1]] = EnumToken.PercentageTokenType;
410
+ arena.dataTypes[components[2]] = EnumToken.PercentageTokenType;
442
411
  }
443
- return result;
412
+ return arena.createColor(colorSpace, ColorType[colorSpace.toUpperCase().replaceAll("-", "_")], components);
444
413
  }
445
414
  return null;
446
415
  }
447
- function processPowerlessComponents(color) {
416
+ function processPowerlessComponents(arena, color) {
448
417
  let components;
449
418
  let values;
450
- switch (color.kin) {
419
+ switch (arena.colorType[color]) {
451
420
  case ColorType.LCH:
452
421
  case ColorType.OKLCH:
453
- values = color.kin == ColorType.LCH ? getLCHComponents(color) : getOKLCHComponents(color);
454
- components = getColorComponents(color);
422
+ values = arena.colorType[color] == ColorType.LCH ? getLCHComponents(arena, color) : getOKLCHComponents(arena, color);
423
+ components = getColorComponents(arena, color);
455
424
  if (values == null || values.length < 3 || components == null) {
456
425
  break;
457
426
  }
458
- const max = color.kin == ColorType.LCH ? colorRange.lch.l[1] : colorRange.oklch.l[1];
427
+ const max = arena.colorType[color] == ColorType.LCH ? colorRange.lch.l[1] : colorRange.oklch.l[1];
459
428
  // https://www.w3.org/TR/css-color-4/#specifying-lab-lch
460
429
  // https://www.w3.org/TR/css-color-4/#specifying-oklab-oklch
461
- const epsilon = color.kin == ColorType.LCH ? 0.0015 : 0.000004;
430
+ const epsilon = arena.colorType[color] == ColorType.LCH ? 0.0015 : 0.000004;
462
431
  if (values[0] < epsilon || Math.abs(values[0] - max) < epsilon) {
463
- Object.assign(components[0], { val: values[0] < epsilon ? 0 : max, typ: EnumToken.NumberTokenType });
464
- Object.assign(components[1], { val: "none", typ: EnumToken.IdenTokenType });
465
- Object.assign(components[2], { val: "none", typ: EnumToken.IdenTokenType });
466
- setColorFlag(components[1], EnumAstNodeStatus.PowerlessColorComponent);
467
- setColorFlag(components[2], EnumAstNodeStatus.PowerlessColorComponent);
432
+ arena.resetToken(components[0], EnumToken.NumberTokenType, values[0] < epsilon ? 0 : max);
433
+ arena.resetToken(components[1], EnumToken.IdenTokenType, "none");
434
+ arena.resetToken(components[2], EnumToken.IdenTokenType, "none");
435
+ setColorFlag(arena, components[1], EnumAstNodeStatus.PowerlessColorComponent);
436
+ setColorFlag(arena, components[2], EnumAstNodeStatus.PowerlessColorComponent);
468
437
  }
469
438
  else if (values[1] < epsilon) {
470
439
  values[1] = 0;
471
- Object.assign(components[1], { val: 0, typ: EnumToken.NumberTokenType });
472
- Object.assign(components[2], { val: "none", typ: EnumToken.IdenTokenType });
473
- setColorFlag(components[2], EnumAstNodeStatus.PowerlessColorComponent);
440
+ arena.resetToken(components[1], EnumToken.NumberTokenType, 0);
441
+ arena.resetToken(components[2], EnumToken.IdenTokenType, "none");
442
+ setColorFlag(arena, components[2], EnumAstNodeStatus.PowerlessColorComponent);
474
443
  }
475
444
  break;
476
445
  case ColorType.HSL:
477
446
  case ColorType.HWB:
478
- values = Object.values((color.kin == ColorType.HSL ? hslvalues(color) : hwbvalues(color)) ?? {});
479
- components = getColorComponents(color);
447
+ values = Object.values((arena.colorType[color] == ColorType.HSL ? hslvalues(arena, color) : hwbvalues(arena, color)) ?? {});
448
+ components = getColorComponents(arena, color);
480
449
  if (values == null || values.length < 3 || components == null) {
481
450
  break;
482
451
  }
483
452
  // https://www.w3.org/TR/css-color-4/#the-hsl-notation
484
453
  // https://www.w3.org/TR/css-color-4/#the-hwb-notation
485
- if ((color.kin == ColorType.HSL && values[1] <= 0.001) ||
486
- (color.kin == ColorType.HWB && values[1] + values[2] >= 99.999)) {
487
- Object.assign(components[0], { val: "none", typ: EnumToken.IdenTokenType });
488
- setColorFlag(components[0], EnumAstNodeStatus.PowerlessColorComponent);
454
+ if ((arena.colorType[color] == ColorType.HSL && values[1] <= 0.001) ||
455
+ (arena.colorType[color] == ColorType.HWB && values[1] + values[2] >= 99.999)) {
456
+ arena.resetToken(components[0], EnumToken.IdenTokenType, "none");
457
+ setColorFlag(arena, components[0], EnumAstNodeStatus.PowerlessColorComponent);
489
458
  }
490
459
  break;
491
460
  }
492
- // console.error({ color: color.chi ?? color, values });
461
+ // console.error({ color: arena.tokens(color) ?? color, values });
493
462
  return color;
494
463
  }
495
- function setColorFlag(token, flag) {
496
- if (token[STATE] == null) {
497
- token[STATE] = flag;
498
- }
499
- else {
500
- token[STATE] |= flag;
501
- }
464
+ function setColorFlag(arena, token, flag) {
465
+ arena.flags[token] |= flag;
502
466
  }
503
467
 
504
468
  export { colorMix };