@lightdash/common 0.2251.3 → 0.2251.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ export declare const cleanColorArray: (colors: string[]) => string[];
14
14
  /**
15
15
  * Returns the best contrasting text color (black or white) for a given background color
16
16
  * Uses APCA contrast algorithm for accurate perception-based contrast
17
- * @param backgroundColor Hex color string for the background
17
+ * @param backgroundColor Any valid color string (hex, rgb, rgba, named colors, etc.)
18
18
  * @returns 'white' or 'black' depending on which has better contrast
19
19
  */
20
20
  export declare const getReadableTextColor: (backgroundColor: string) => string;
@@ -1 +1 @@
1
- {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../../src/utils/colors.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,cAAc,UAAW,MAAM,KAAG,OACR,CAAC;AAExC;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,WAAY,MAAM,EAAE,KAAG,MAAM,EACT,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,eAAe,WAAY,MAAM,EAAE,KAAG,MAAM,EACkB,CAAC;AAE5E;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,oBAAqB,MAAM,KAAG,MAO9D,CAAC"}
1
+ {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../../src/utils/colors.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,cAAc,UAAW,MAAM,KAAG,OACR,CAAC;AAExC;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,WAAY,MAAM,EAAE,KAAG,MAAM,EACT,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,eAAe,WAAY,MAAM,EAAE,KAAG,MAAM,EACkB,CAAC;AAE5E;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,oBAAqB,MAAM,KAAG,MAS9D,CAAC"}
@@ -16,15 +16,18 @@ export const cleanColorArray = (colors) => colors.map((color) => color.trim()).f
16
16
  /**
17
17
  * Returns the best contrasting text color (black or white) for a given background color
18
18
  * Uses APCA contrast algorithm for accurate perception-based contrast
19
- * @param backgroundColor Hex color string for the background
19
+ * @param backgroundColor Any valid color string (hex, rgb, rgba, named colors, etc.)
20
20
  * @returns 'white' or 'black' depending on which has better contrast
21
21
  */
22
22
  export const getReadableTextColor = (backgroundColor) => {
23
- if (!isHexCodeColor(backgroundColor)) {
23
+ try {
24
+ const onWhite = Math.abs(Color.contrastAPCA('white', backgroundColor));
25
+ const onBlack = Math.abs(Color.contrastAPCA('black', backgroundColor));
26
+ return onWhite > onBlack ? 'white' : 'black';
27
+ }
28
+ catch (e) {
29
+ // Not supported color string, default to black
24
30
  return 'black';
25
31
  }
26
- const onWhite = Math.abs(Color.contrastAPCA('white', backgroundColor));
27
- const onBlack = Math.abs(Color.contrastAPCA('black', backgroundColor));
28
- return onWhite > onBlack ? 'white' : 'black';
29
32
  };
30
33
  //# sourceMappingURL=colors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"colors.js","sourceRoot":"","sources":["../../../src/utils/colors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,MAAM,uBAAuB,GACzB,mDAAmD,CAAC;AAExD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAW,EAAE,CACrD,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAExC;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAAgB,EAAY,EAAE,CAC9D,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AAErD;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAgB,EAAY,EAAE,CAC1D,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAA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,CAAC;AAE5E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,eAAuB,EAAU,EAAE;IACpE,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;QACvE,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;QACvE,OAAO,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;IACjD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,+CAA+C;QAC/C,OAAO,OAAO,CAAC;IACnB,CAAC;AACL,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/common",
3
- "version": "0.2251.3",
3
+ "version": "0.2251.4",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",