From 03644d02c5fcfde2f7847dea0d9e0b24bd424db7 Mon Sep 17 00:00:00 2001 From: Send_Nukez Date: Mon, 25 Oct 2021 01:18:21 +0200 Subject: [PATCH] parse initial vars because "--spice-sidebar" is rgb() instead of hex --- dribbblish-dynamic.js | 18 +++++++++++++++--- dribbblish.js | 5 ++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/dribbblish-dynamic.js b/dribbblish-dynamic.js index 9a64aed..4709e84 100644 --- a/dribbblish-dynamic.js +++ b/dribbblish-dynamic.js @@ -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; diff --git a/dribbblish.js b/dribbblish.js index 8574685..daa538b 100644 --- a/dribbblish.js +++ b/dribbblish.js @@ -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 };