@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"}
@@ -23,16 +23,19 @@ exports.cleanColorArray = cleanColorArray;
23
23
  /**
24
24
  * Returns the best contrasting text color (black or white) for a given background color
25
25
  * Uses APCA contrast algorithm for accurate perception-based contrast
26
- * @param backgroundColor Hex color string for the background
26
+ * @param backgroundColor Any valid color string (hex, rgb, rgba, named colors, etc.)
27
27
  * @returns 'white' or 'black' depending on which has better contrast
28
28
  */
29
29
  const getReadableTextColor = (backgroundColor) => {
30
- if (!(0, exports.isHexCodeColor)(backgroundColor)) {
30
+ try {
31
+ const onWhite = Math.abs(colorjs_io_1.default.contrastAPCA('white', backgroundColor));
32
+ const onBlack = Math.abs(colorjs_io_1.default.contrastAPCA('black', backgroundColor));
33
+ return onWhite > onBlack ? 'white' : 'black';
34
+ }
35
+ catch (e) {
36
+ // Not supported color string, default to black
31
37
  return 'black';
32
38
  }
33
- const onWhite = Math.abs(colorjs_io_1.default.contrastAPCA('white', backgroundColor));
34
- const onBlack = Math.abs(colorjs_io_1.default.contrastAPCA('black', backgroundColor));
35
- return onWhite > onBlack ? 'white' : 'black';
36
39
  };
37
40
  exports.getReadableTextColor = getReadableTextColor;
38
41
  //# sourceMappingURL=colors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"colors.js","sourceRoot":"","sources":["../../../src/utils/colors.ts"],"names":[],"mappings":";;;;AAAA,oEAA+B;AAE/B,MAAM,uBAAuB,GACzB,mDAAmD,CAAC;AAEjD,MAAM,cAAc,GAAG,CAAC,KAAa,EAAW,EAAE,CACrD,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAD3B,QAAA,cAAc,kBACa;AAExC;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,CAAC,MAAgB,EAAY,EAAE,CAC9D,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,IAAA,sBAAc,EAAC,KAAK,CAAC,CAAC,CAAC;AADxC,QAAA,mBAAmB,uBACqB;AAErD;;;;GAIG;AACI,MAAM,eAAe,GAAG,CAAC,MAAgB,EAAY,EAAE,CAC1D,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAA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