diff --git a/src/assets/lexicon_icon.js b/src/assets/lexicon_icon.js index d3bec911fe6471230a0cdef65219cb4173d09827..fa5852f7f7fc4b8b445bfa13c54d910626c0c585 100644 --- a/src/assets/lexicon_icon.js +++ b/src/assets/lexicon_icon.js @@ -110,6 +110,20 @@ async function getColorForLexicon(lexiconId) { return (lexiconColors && lexiconColors[String(lexiconId)]) || "#cccccc"; } +/** + * Convertit une couleur hexadécimale en une couleur RGBA. + * @param {string} hex - La couleur en hexadécimal. + * @param {number} opacity - La transparence (0-1). + * @returns {string} La couleur RGBA. + */ +function hexToRgba(hex, opacity) { + const bigint = parseInt(hex.replace('#', ''), 16); + const r = (bigint >> 16) & 255; + const g = (bigint >> 8) & 255; + const b = bigint & 255; + return `rgba(${r}, ${g}, ${b}, ${opacity})`; +} + // Expose les fonctions globalement window.updateLexiconColors = updateLexiconColors; window.getColorForLexicon = getColorForLexicon; @@ -117,3 +131,4 @@ window.convertColor = convertColor; window.getOrCreateLexiconColor = getOrCreateLexiconColor; window.createColorCircle = createColorCircle; window.getLexiconsColors = getLexiconsColors; +window.hexToRgba = hexToRgba;