MCPcopy Create free account
hub / github.com/error311/FileRise / hexToHsl

Function hexToHsl

public/js/folderManager.js:1183–1203  ·  view source on GitHub ↗
(hex)

Source from the content-addressed store, hash-verified

1181----------------------*/
1182window.folderColorMap = window.folderColorMap || {};
1183function hexToHsl(hex) {
1184 hex = hex.replace('#', '');
1185 if (hex.length === 3) hex = hex.split('').map(c => c + c).join('');
1186 const r = parseInt(hex.substr(0, 2), 16) / 255;
1187 const g = parseInt(hex.substr(2, 2), 16) / 255;
1188 const b = parseInt(hex.substr(4, 2), 16) / 255;
1189 const max = Math.max(r, g, b), min = Math.min(r, g, b);
1190 let h, s, l = (max + min) / 2;
1191 if (max === min) { h = s = 0; }
1192 else {
1193 const d = max - min;
1194 s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
1195 switch (max) {
1196 case r: h = (g - b) / d + (g < b ? 6 : 0); break;
1197 case g: h = (b - r) / d + 2; break;
1198 case b: h = (r - g) / d + 4; break;
1199 }
1200 h /= 6;
1201 }
1202 return { h: h * 360, s: s * 100, l: l * 100 };
1203}
1204function hslToHex(h, s, l) {
1205 h /= 360; s /= 100; l /= 100;
1206 const f = n => {

Callers 2

lightenFunction · 0.85
darkenFunction · 0.85

Calls 1

splitMethod · 0.80

Tested by

no test coverage detected