FEATURE introducing the isColorLight helper function
This commit is contained in:
parent
714bc5b3a1
commit
7d773401ed
24
plugins/carhop-blocks/blocks/_utilities/utilities.js
Normal file
24
plugins/carhop-blocks/blocks/_utilities/utilities.js
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
// Fonction pour déterminer si une couleur est claire ou sombre
|
||||||
|
export function isColorLight(color) {
|
||||||
|
// Si pas de couleur, considérer comme claire
|
||||||
|
if (!color) return true;
|
||||||
|
|
||||||
|
// Convertir hex en RGB
|
||||||
|
let hex = color.replace("#", "");
|
||||||
|
if (hex.length === 3) {
|
||||||
|
hex = hex
|
||||||
|
.split("")
|
||||||
|
.map((char) => char + char)
|
||||||
|
.join("");
|
||||||
|
}
|
||||||
|
|
||||||
|
const r = parseInt(hex.substr(0, 2), 16);
|
||||||
|
const g = parseInt(hex.substr(2, 2), 16);
|
||||||
|
const b = parseInt(hex.substr(4, 2), 16);
|
||||||
|
|
||||||
|
// Calculer la luminance relative (formule standard)
|
||||||
|
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
||||||
|
|
||||||
|
// Si luminance > 0.5, la couleur est claire
|
||||||
|
return luminance > 0.5;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user