forked from mystiq/hydrogen-web
Let derive function know if theme is dark
This commit is contained in:
parent
0b241db058
commit
bb9954a36c
1 changed files with 5 additions and 1 deletions
|
@ -33,6 +33,7 @@ const valueParser = require("postcss-value-parser");
|
||||||
let aliasMap;
|
let aliasMap;
|
||||||
let resolvedMap;
|
let resolvedMap;
|
||||||
let baseVariables;
|
let baseVariables;
|
||||||
|
let isDark;
|
||||||
|
|
||||||
function getValueFromAlias(alias) {
|
function getValueFromAlias(alias) {
|
||||||
const derivedVariable = aliasMap.get(alias);
|
const derivedVariable = aliasMap.get(alias);
|
||||||
|
@ -78,7 +79,7 @@ function resolveDerivedVariable(decl, derive) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
throw new Error(`Cannot derive from ${baseVariable} because it is neither defined in config nor is it an alias!`);
|
throw new Error(`Cannot derive from ${baseVariable} because it is neither defined in config nor is it an alias!`);
|
||||||
}
|
}
|
||||||
const derivedValue = derive(value, operation, argument);
|
const derivedValue = derive(value, operation, argument, isDark);
|
||||||
resolvedMap.set(wholeVariable, derivedValue);
|
resolvedMap.set(wholeVariable, derivedValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,6 +135,8 @@ module.exports = (opts = {}) => {
|
||||||
aliasMap = new Map();
|
aliasMap = new Map();
|
||||||
resolvedMap = new Map();
|
resolvedMap = new Map();
|
||||||
baseVariables = new Map();
|
baseVariables = new Map();
|
||||||
|
isDark = false;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
postcssPlugin: "postcss-compile-variables",
|
postcssPlugin: "postcss-compile-variables",
|
||||||
|
|
||||||
|
@ -143,6 +146,7 @@ module.exports = (opts = {}) => {
|
||||||
// If this is a runtime theme, don't derive variables.
|
// If this is a runtime theme, don't derive variables.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
isDark = cssFileLocation.includes("dark=true");
|
||||||
/*
|
/*
|
||||||
Go through the CSS file once to extract all aliases and base variables.
|
Go through the CSS file once to extract all aliases and base variables.
|
||||||
We use these when resolving derived variables later.
|
We use these when resolving derived variables later.
|
||||||
|
|
Loading…
Reference in a new issue