@arsedizioni/ars-utils 19.5.2 → 19.5.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.
- package/core/system.d.ts +7 -0
- package/fesm2022/arsedizioni-ars-utils-core.mjs +21 -0
- package/fesm2022/arsedizioni-ars-utils-core.mjs.map +1 -1
- package/fesm2022/arsedizioni-ars-utils-ui.application.mjs +2 -2
- package/fesm2022/arsedizioni-ars-utils-ui.application.mjs.map +1 -1
- package/package.json +5 -5
package/core/system.d.ts
CHANGED
|
@@ -255,4 +255,11 @@ export declare class SystemUtils {
|
|
|
255
255
|
* @param max: the max number of flags
|
|
256
256
|
*/
|
|
257
257
|
static getFlags(value: number, max?: number): number[];
|
|
258
|
+
/**
|
|
259
|
+
* Check if a color is light or dark
|
|
260
|
+
* @param color : the color
|
|
261
|
+
* @param minimumLuminance : the lumimance to consider
|
|
262
|
+
* @returns true if the color is light
|
|
263
|
+
*/
|
|
264
|
+
static isColorLight(color: string, minimumLuminance?: number): boolean;
|
|
258
265
|
}
|
|
@@ -736,6 +736,27 @@ class SystemUtils {
|
|
|
736
736
|
else
|
|
737
737
|
return [];
|
|
738
738
|
}
|
|
739
|
+
/**
|
|
740
|
+
* Check if a color is light or dark
|
|
741
|
+
* @param color : the color
|
|
742
|
+
* @param minimumLuminance : the lumimance to consider
|
|
743
|
+
* @returns true if the color is light
|
|
744
|
+
*/
|
|
745
|
+
static isColorLight(color, minimumLuminance = 186) {
|
|
746
|
+
const tempDiv = document.createElement('div');
|
|
747
|
+
tempDiv.style.color = color;
|
|
748
|
+
document.body.appendChild(tempDiv);
|
|
749
|
+
const rgb = getComputedStyle(tempDiv).color;
|
|
750
|
+
document.body.removeChild(tempDiv);
|
|
751
|
+
const result = rgb.match(/\d+/g);
|
|
752
|
+
if (!result || result.length < 3)
|
|
753
|
+
return true; // fallback
|
|
754
|
+
const r = parseInt(result[0], 10);
|
|
755
|
+
const g = parseInt(result[1], 10);
|
|
756
|
+
const b = parseInt(result[2], 10);
|
|
757
|
+
const luminance = 0.299 * r + 0.587 * g + 0.114 * b;
|
|
758
|
+
return luminance > minimumLuminance;
|
|
759
|
+
}
|
|
739
760
|
}
|
|
740
761
|
|
|
741
762
|
class DateIntervalChangeDirective {
|