@sparted/shared-library 1.1.0 → 1.1.1
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.
- package/color/get-contrast-color.d.ts +1 -0
- package/color/get-contrast-color.js +21 -0
- package/color/get-contrast-color.js.map +1 -0
- package/color/index.d.ts +1 -0
- package/color/index.js +10 -0
- package/color/index.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getContrastColor: (bgColor: string, lightColor?: string, darkColor?: string) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const DEFAULT_LIGHT_COLOR = '#FFFFFF';
|
|
6
|
+
const DEFAULT_DARK_COLOR = '#000000';
|
|
7
|
+
// Based on https://stackoverflow.com/questions/11867545/change-text-color-based-on-brightness-of-the-covered-background-area
|
|
8
|
+
const getContrastColor = (bgColor, lightColor = DEFAULT_LIGHT_COLOR, darkColor = DEFAULT_DARK_COLOR) => {
|
|
9
|
+
const color = bgColor.charAt(0) === '#' ? bgColor.substring(1, 7) : bgColor;
|
|
10
|
+
if (color.length !== 6) {
|
|
11
|
+
throw new Error(`Invalid HEX color "${bgColor}" in sparted mail manager.`);
|
|
12
|
+
}
|
|
13
|
+
const r = parseInt(color.substring(0, 2), 16); // hexToR
|
|
14
|
+
const g = parseInt(color.substring(2, 4), 16); // hexToG
|
|
15
|
+
const b = parseInt(color.substring(4, 6), 16); // hexToB
|
|
16
|
+
// Values from https://www.w3.org/TR/AERT/#color-contrast
|
|
17
|
+
return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? darkColor : lightColor;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.getContrastColor = getContrastColor;
|
|
21
|
+
//# sourceMappingURL=get-contrast-color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-contrast-color.js","sources":["../../src/color/get-contrast-color.ts"],"sourcesContent":["const DEFAULT_LIGHT_COLOR = '#FFFFFF';\nconst DEFAULT_DARK_COLOR = '#000000';\n\n// Based on https://stackoverflow.com/questions/11867545/change-text-color-based-on-brightness-of-the-covered-background-area\nexport const getContrastColor = (bgColor: string, lightColor: string = DEFAULT_LIGHT_COLOR, darkColor: string = DEFAULT_DARK_COLOR): string => {\n const color = bgColor.charAt(0) === '#' ? bgColor.substring(1, 7) : bgColor;\n\n if (color.length !== 6) {\n throw new Error(`Invalid HEX color \"${bgColor}\" in sparted mail manager.`);\n }\n\n const r = parseInt(color.substring(0, 2), 16); // hexToR\n const g = parseInt(color.substring(2, 4), 16); // hexToG\n const b = parseInt(color.substring(4, 6), 16); // hexToB\n\n // Values from https://www.w3.org/TR/AERT/#color-contrast\n return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? darkColor : lightColor;\n};\n"],"names":[],"mappings":";;;;AAAA,MAAM,mBAAmB,GAAG,SAAS,CAAC;AACtC,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAErC;AACO,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,UAAA,GAAqB,mBAAmB,EAAE,SAAoB,GAAA,kBAAkB,KAAY;IAC5I,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC;AAE5E,IAAA,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;AACtB,QAAA,MAAM,IAAI,KAAK,CAAC,sBAAsB,OAAO,CAAA,0BAAA,CAA4B,CAAC,CAAC;AAC5E,KAAA;AAED,IAAA,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9C,IAAA,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9C,IAAA,MAAM,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;;IAG9C,OAAO,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,KAAK,GAAG,GAAG,GAAG,SAAS,GAAG,UAAU,CAAC;AAC1E;;;;"}
|
package/color/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './get-contrast-color';
|
package/color/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -37,6 +37,7 @@ var executeWithDelay = require('./promise/execute-with-delay.js');
|
|
|
37
37
|
var delay = require('./promise/delay.js');
|
|
38
38
|
var replaceInTemplate = require('./string/replace-in-template.js');
|
|
39
39
|
var isStringLengthWithinRange = require('./string/is-string-length-within-range.js');
|
|
40
|
+
var getContrastColor = require('./color/get-contrast-color.js');
|
|
40
41
|
|
|
41
42
|
|
|
42
43
|
|
|
@@ -82,4 +83,5 @@ exports.executeWithDelay = executeWithDelay.executeWithDelay;
|
|
|
82
83
|
exports.delay = delay.delay;
|
|
83
84
|
exports.replaceInTemplate = replaceInTemplate.replaceInTemplate;
|
|
84
85
|
exports.isStringLengthWithinRange = isStringLengthWithinRange.isStringLengthWithinRange;
|
|
86
|
+
exports.getContrastColor = getContrastColor.getContrastColor;
|
|
85
87
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|