aboutsummaryrefslogtreecommitdiff
path: root/src/services/theme_data/theme_data.service.js
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2020-01-20 00:34:49 +0200
committerHenry Jameson <me@hjkos.com>2020-01-20 00:34:49 +0200
commite4033c85e2066d8a575a1cd8e5a59bb685a3adf0 (patch)
treebf9e261491768610b9e6d57872f69eb311cd70bc /src/services/theme_data/theme_data.service.js
parent7d7ccf729855283ad0f5b9d6943b8d86ed1f180d (diff)
removed console logs
Diffstat (limited to 'src/services/theme_data/theme_data.service.js')
-rw-r--r--src/services/theme_data/theme_data.service.js28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/services/theme_data/theme_data.service.js b/src/services/theme_data/theme_data.service.js
index 9f010fdf..e4456b29 100644
--- a/src/services/theme_data/theme_data.service.js
+++ b/src/services/theme_data/theme_data.service.js
@@ -698,6 +698,22 @@ export const OPACITIES = Object.entries(SLOT_INHERITANCE).reduce((acc, [k, v]) =
}, {})
/**
+ * Handle dynamic color
+ */
+export const computeDynamicColor = (sourceColor, getColor, mod) => {
+ if (typeof sourceColor !== 'string' || !sourceColor.startsWith('--')) return sourceColor
+ let targetColor = null
+ // Color references other color
+ const [variable, modifier] = sourceColor.split(/,/g).map(str => str.trim())
+ const variableSlot = variable.substring(2)
+ targetColor = getColor(variableSlot)
+ if (modifier) {
+ targetColor = brightness(Number.parseFloat(modifier) * mod, targetColor).rgb
+ }
+ return targetColor
+}
+
+/**
* THE function you want to use. Takes provided colors and opacities, mod
* value and uses inheritance data to figure out color needed for the slot.
*/
@@ -728,13 +744,11 @@ export const getColors = (sourceColors, sourceOpacity, mod) => SLOT_ORDERED.redu
a: 0
}
} else if (typeof sourceColor === 'string' && sourceColor.startsWith('--')) {
- // Color references other color
- const [variable, modifier] = sourceColor.split(/,/g).map(str => str.trim())
- const variableSlot = variable.substring(2)
- targetColor = colors[variableSlot] || sourceColors[variableSlot]
- if (modifier) {
- targetColor = brightness(Number.parseFloat(modifier) * mod, targetColor).rgb
- }
+ targetColor = computeDynamicColor(
+ sourceColor,
+ variableSlot => colors[variableSlot] || sourceColors[variableSlot],
+ mod
+ )
} else if (typeof sourceColor === 'string' && sourceColor.startsWith('#')) {
targetColor = convert(targetColor).rgb
}