reset files to before desktop config, added more ui cleanup, store classes, examples

This commit is contained in:
Daniel Ledda
2021-07-05 19:21:43 +02:00
parent 0f3696b497
commit c415641d39
29 changed files with 2008 additions and 518 deletions

25
src/utils.ts Normal file
View File

@@ -0,0 +1,25 @@
function hslToRgb(hslStr: string): string {
const opt = new Option();
opt.style.color = hslStr;
return opt.style.color;
}
function rgbToHex(rgbStr: string): string {
const sep = rgbStr.indexOf(",") > -1 ? "," : " ";
const rgb = rgbStr.substr(4).split(")")[0].split(sep);
const r = (+rgb[0]).toString(16).padStart(2, "0");
const g = (+rgb[1]).toString(16).padStart(2, "0");
const b = (+rgb[2]).toString(16).padStart(2, "0");
return "#" + r + g + b;
}
export function colorFromIndex(index: number): string {
const colorWheelCycle = Math.floor(index / 6);
const darknessCycle = Math.floor(index / 12);
const spacing = (360 / 6);
const offset = colorWheelCycle === 0 ? 0 : spacing / (colorWheelCycle + 2);
let hue = spacing * (index % 6) + offset;
const saturation = 100;
const lightness = 1 / (2 + darknessCycle) * 100;
return rgbToHex(hslToRgb(`hsl(${hue},${saturation}%,${Math.round(lightness)}%)`));
}