parse initial vars because "--spice-sidebar" is rgb() instead of hex

This commit is contained in:
Send_Nukez 2021-10-25 01:18:21 +02:00
parent 43ffd943d9
commit 03644d02c5
2 changed files with 19 additions and 4 deletions

View file

@ -200,9 +200,21 @@ function setLightness(hex, lightness) {
return rgbToHex(hslToRgb(hsl));
}
let textColor = getComputedStyle(document.documentElement).getPropertyValue("--spice-text");
let textColorBg = getComputedStyle(document.documentElement).getPropertyValue("--spice-main");
let sidebarColor = getComputedStyle(document.documentElement).getPropertyValue("--spice-sidebar");
function parseComputedStyleColor(col) {
if (col.startsWith("#")) return col;
if (col.startsWith("rgb("))
return rgbToHex(
col
.replace(/rgb|(|)/g, "")
.split(",")
.map((part) => Number(part.trim()))
);
}
// `parseComputedStyleColor()` beacuse "--spice-sidebar" is `rgb()`
let textColor = parseComputedStyleColor(getComputedStyle(document.documentElement).getPropertyValue("--spice-text"));
let textColorBg = parseComputedStyleColor(getComputedStyle(document.documentElement).getPropertyValue("--spice-main"));
let sidebarColor = parseComputedStyleColor(getComputedStyle(document.documentElement).getPropertyValue("--spice-sidebar"));
function setRootColor(name, colHex) {
let root = document.documentElement;

View file

@ -18,6 +18,7 @@ class ConfigMenu {
* @property {onAppended} [onAppended]
* @property {onChange} [onChange]
* @property {DribbblishConfigItem[]} [children=[]]
* @property {String} [childOf=null] key of parent
*/
/**
@ -111,6 +112,7 @@ class ConfigMenu {
* @param {DribbblishConfigItem} options
*/
register(options) {
/** @type {DribbblishConfigItem} */
const defaultOptions = {
hidden: false,
area: "Main Settings",
@ -123,7 +125,8 @@ class ConfigMenu {
showChildren: () => true,
onAppended: () => {},
onChange: () => {},
children: []
children: [],
childOf: null
};
// Set Defaults
options = { ...defaultOptions, ...options };