@tbela99/css-parser 1.6.4 → 1.6.5

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.
@@ -2,9 +2,7 @@ import { EnumToken, ColorType } from '../../ast/types.js';
2
2
  import { minmax, getNumber } from './color.js';
3
3
  import { srgbvalues, srgb2lsrgbvalues } from './srgb.js';
4
4
  import { srgb2lch, xyz2lchvalues } from './lch.js';
5
- import { srgb2rgb } from './rgb.js';
6
5
  import { srgb2hslvalues } from './hsl.js';
7
- import { srgb2hwb } from './hwb.js';
8
6
  import { srgb2labvalues } from './lab.js';
9
7
  import { srgb2lp3values, srgb2p3values } from './p3.js';
10
8
  import { getColorComponents } from './utils/components.js';
@@ -121,6 +119,9 @@ function colorMix(...args) {
121
119
  if (values == null) {
122
120
  return null;
123
121
  }
122
+ if (colorSpace == "hwb") {
123
+ colorSpace = "srgb";
124
+ }
124
125
  switch (colorSpace) {
125
126
  case "srgb":
126
127
  break;
@@ -150,17 +151,17 @@ function colorMix(...args) {
150
151
  values = srgb2xyz_d65(values[0], values[1], values[2], values[3]);
151
152
  values = XYZ_D65_to_D50(values[0], values[1], values[2], values[3]);
152
153
  break;
153
- case "rgb":
154
- for (let j = 0; j < values.length; j++) {
155
- values[j] = j == 3 ? values[j] : srgb2rgb(values[j]);
156
- }
157
- break;
154
+ // case "rgb":
155
+ // for (let j = 0; j < values.length; j++) {
156
+ // values[j] = j == 3 ? values[j] : srgb2rgb(values[j]);
157
+ // }
158
+ // break;
158
159
  case "hsl":
159
160
  values = srgb2hslvalues(values[0], values[1], values[2], values[3]);
160
161
  break;
161
- case "hwb":
162
- values = srgb2hwb(values[0], values[1], values[2], values[3]);
163
- break;
162
+ // case "hwb":
163
+ // values = srgb2hwb(values[0], values[1], values[2], values[3]);
164
+ // break;
164
165
  case "lab":
165
166
  values = srgb2labvalues(values[0], values[1], values[2], values[3]);
166
167
  break;
@@ -359,14 +360,14 @@ function colorMix(...args) {
359
360
  kin: ColorType.COLOR,
360
361
  cal: "col",
361
362
  };
362
- case "rgb":
363
+ // case "rgb":
363
364
  case "hsl":
364
- case "hwb":
365
+ // case "hwb":
365
366
  case "lab":
366
367
  case "lch":
367
368
  case "oklab":
368
369
  case "oklch":
369
- if (colorSpace == "hsl" || colorSpace == "hwb") {
370
+ if (colorSpace == "hsl") {
370
371
  // @ts-ignore
371
372
  if (values[2] < 0) {
372
373
  // @ts-ignore
@@ -396,7 +397,7 @@ function colorMix(...args) {
396
397
  }),
397
398
  kin: ColorType[colorSpace.toUpperCase().replaceAll("-", "_")],
398
399
  };
399
- if (colorSpace == "hsl" || colorSpace == "hwb") {
400
+ if (colorSpace == "hsl") {
400
401
  // @ts-ignore
401
402
  result.chi[0] = { typ: EnumToken.AngleTokenType, val: result.chi[0].val * 360 };
402
403
  // @ts-ignore
@@ -70,7 +70,10 @@ function color2HexToken(token) {
70
70
  if (value == null) {
71
71
  return null;
72
72
  }
73
- return hexToken(value.reduce((acc, curr) => acc + srgb2rgb(curr + Number.EPSILON).toString(16).padStart(2, "0"), "#"));
73
+ return hexToken(value.reduce((acc, curr) => acc +
74
+ srgb2rgb(curr + Number.EPSILON)
75
+ .toString(16)
76
+ .padStart(2, "0"), "#"));
74
77
  }
75
78
  function oklab2HexToken(token) {
76
79
  let value = oklab2srgbvalues(token);
@@ -44,20 +44,20 @@ function parseRelativeColorComponents(relativeKeys, original, rExp, gExp, bExp,
44
44
  continue;
45
45
  }
46
46
  if (component.typ == EnumToken.IdenTokenType) {
47
- val = component.val.toLowerCase();
47
+ val = component.val;
48
48
  if (
49
49
  // @ts-expect-error
50
50
  typeof Math[val.toUpperCase()] !== "number" &&
51
- val != "in" &&
52
- val != "hue" &&
53
- val != "from" &&
54
- val != "alpha" &&
55
- val != "none" &&
56
- val != "shorter" &&
57
- val != "longer" &&
58
- val != "increasing" &&
59
- val != "decreasing" &&
60
- !colorsFunc.includes(val) &&
51
+ !equalsIgnoreCase(val, "in") &&
52
+ !equalsIgnoreCase(val, "hue") &&
53
+ !equalsIgnoreCase(val, "from") &&
54
+ !equalsIgnoreCase(val, "alpha") &&
55
+ !equalsIgnoreCase(val, "none") &&
56
+ !equalsIgnoreCase(val, "shorter") &&
57
+ !equalsIgnoreCase(val, "longer") &&
58
+ !equalsIgnoreCase(val, "increasing") &&
59
+ !equalsIgnoreCase(val, "decreasing") &&
60
+ !colorsFunc.some((t) => equalsIgnoreCase(t, val)) &&
61
61
  !colorFuncColorSpace.includes(val) &&
62
62
  !validKeys.includes(val)) {
63
63
  return null;
@@ -4,13 +4,6 @@ import { expandHexValue } from '../hex.js';
4
4
  import { equalsIgnoreCase } from '../../../parser/utils/text.js';
5
5
 
6
6
  function getColorComponents(token) {
7
- // if (token.typ === EnumToken.IdenTokenType) {
8
- // if (isColor(token)) {
9
- // parseColor(token);
10
- // } else {
11
- // return null;
12
- // }
13
- // }
14
7
  if (token.kin == ColorType.HEX || token.kin == ColorType.LIT) {
15
8
  if (equalsIgnoreCase("currentcolor", token.val)) {
16
9
  return null;
@@ -34,25 +27,12 @@ function getColorComponents(token) {
34
27
  ].includes(child.typ)) {
35
28
  continue;
36
29
  }
37
- // if (child.typ === EnumToken.IdenTokenType && isColor(child)) {
38
- // parseColor(child);
39
- // }
40
30
  if (child.typ === EnumToken.FunctionTokenType ||
41
31
  child.typ === EnumToken.WildCardFunctionTokenType ||
42
32
  child.typ === EnumToken.MathFunctionTokenType) {
43
33
  if ("var" == child.val.toLowerCase()) {
44
34
  return null;
45
35
  }
46
- // else {
47
- // for (const { value } of walkValues((child as FunctionToken).chi)) {
48
- // if (
49
- // value.typ == EnumToken.WildCardFunctionTokenDefType &&
50
- // "var" === (value as FunctionToken).val.toLowerCase()
51
- // ) {
52
- // return null;
53
- // }
54
- // }
55
- // }
56
36
  }
57
37
  if (child.typ == EnumToken.ColorTokenType && equalsIgnoreCase("currentcolor", child.val)) {
58
38
  return null;
@@ -67,6 +67,11 @@ const anglePrecision = 3;
67
67
  * Color range definitions
68
68
  */
69
69
  const colorRange = {
70
+ rgb: {
71
+ r: [0, 255],
72
+ g: [0, 255],
73
+ b: [0, 255],
74
+ },
70
75
  lab: {
71
76
  l: [0, 100],
72
77
  a: [-125, 125],
@@ -16,12 +16,12 @@ import { getSyntaxConfig } from '../validation/config.js';
16
16
  // '\\'
17
17
  const REVERSE_SOLIDUS = 0x5c;
18
18
  const flexUnits = ["fr"];
19
- const frequencyUnits = ["hz", "khz"];
19
+ const frequencyUnits = ["Hz", "kHz"];
20
20
  const timeUnits = ["ms", "s"];
21
21
  const angleUnits = ["rad", "turn", "deg", "grad"];
22
22
  const resolutionUnits = ["dpi", "dpcm", "dppx", "x"];
23
23
  const dimensionUnits = [
24
- "q",
24
+ "Q",
25
25
  "cap",
26
26
  "ch",
27
27
  "cm",
@@ -643,7 +643,8 @@ function matchAllSyntaxes(syntaxes, context, options) {
643
643
  for (let i = index; i < syntaxes.length; i++) {
644
644
  if (syntaxes[i].typ == ValidationTokenEnum.Whitespace ||
645
645
  syntaxes[i].isOptional ||
646
- syntaxes[i].isRepeatable) {
646
+ syntaxes[i].isRepeatable ||
647
+ syntaxes[i].match?.min?.val === 0) {
647
648
  continue;
648
649
  }
649
650
  return {
package/dist/web.js CHANGED
@@ -17,6 +17,7 @@ export { isOkLabClose, okLabDistance } from './lib/syntax/color/utils/distance.j
17
17
  export { find, findAll, findByValue, findLast } from './lib/ast/find.js';
18
18
  export { cloneNode } from './lib/ast/clone.js';
19
19
  export { replaceNodeOrValue } from './lib/parser/utils/token.js';
20
+ export { PropertyList } from './lib/parser/declaration/list.js';
20
21
  export { SourceMap } from './lib/printer/sourcemap/sourcemap.js';
21
22
  export { FeatureWalkMode } from './lib/ast/features/type.js';
22
23
  export { getNodeProperty, setNodeProperty } from './lib/ast/node.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tbela99/css-parser",
3
3
  "description": "CSS parser, minifier and validator for node and the browser",
4
- "version": "1.6.4",
4
+ "version": "1.6.5",
5
5
  "exports": {
6
6
  ".": "./dist/node.js",
7
7
  "./node": "./dist/node.js",
@@ -60,17 +60,20 @@
60
60
  },
61
61
  "homepage": "https://github.com/tbela99/css-parser#readme",
62
62
  "devDependencies": {
63
+ "@boneskull/typedoc-plugin-mermaid": "^0.2.1",
63
64
  "@rollup/plugin-commonjs": "^29.0.3",
64
65
  "@rollup/plugin-json": "^6.1.0",
65
66
  "@rollup/plugin-node-resolve": "^16.0.3",
66
67
  "@rollup/plugin-typescript": "^12.3.0",
67
68
  "@types/chai": "^5.2.3",
69
+ "@types/chai-as-promised": "^8.0.2",
68
70
  "@types/mocha": "^10.0.10",
69
71
  "@types/node": "^26.4.1",
70
72
  "@types/web": "^0.0.354",
71
73
  "@web/test-runner": "^1.0.0",
72
74
  "@web/test-runner-playwright": "^1.0.0",
73
75
  "chai": "^6.2.2",
76
+ "chai-as-promised": "^8.0.2",
74
77
  "esno": "^4.8.0",
75
78
  "markdown-it-task-lists": "^2.1.1",
76
79
  "mocha": "^12.0.0",
@@ -83,9 +86,7 @@
83
86
  "typedoc-plugin-coverage": "^4.0.3",
84
87
  "typedoc-plugin-llms-txt": "^0.1.2",
85
88
  "typedoc-plugin-redirect": "^1.3.0",
86
- "typedoc-unhoax-theme": "^0.5.3",
87
- "@types/chai-as-promised": "^8.0.2",
88
- "chai-as-promised": "^8.0.2"
89
+ "typedoc-unhoax-theme": "^0.5.3"
89
90
  },
90
91
  "sideEffects": false
91
92
  }