Ignore alpha values in some theme properties if blur disabled

Overrides certain alpha values by setting them to 1.0
This commit is contained in:
Aylam 2023-08-11 19:20:30 +03:00 committed by aylamz
parent bf2a44b2dd
commit a82979b2a1

View file

@ -14,6 +14,7 @@ export type Theme = {
import lightTheme from "@/themes/_light.json5";
import darkTheme from "@/themes/_dark.json5";
import { deepClone } from "./clone";
import { defaultStore } from "@/store";
export const themeProps = Object.keys(lightTheme.props).filter(
(key) => !key.startsWith("X"),
@ -109,7 +110,7 @@ export function applyTheme(theme: Theme, persist = true) {
}
function compile(theme: Theme): Record<string, string> {
function getColor(val: string): tinycolor.Instance {
function getColor(val: string, key?: string): tinycolor.Instance {
// ref (prop)
if (val[0] === "@") {
return getColor(theme.props[val.slice(1)]);
@ -127,13 +128,20 @@ function compile(theme: Theme): Record<string, string> {
const arg = parseFloat(parts.shift());
const color = getColor(parts.join("<"));
const ignoreAlphaForKeys = ["windowHeader", "acrylicPanel"];
switch (func) {
case "darken":
return color.darken(arg);
case "lighten":
return color.lighten(arg);
case "alpha":
if (!defaultStore.state.useBlurEffect && key && ignoreAlphaForKeys.includes(key)) {
return color.setAlpha(1.0);
}
else {
return color.setAlpha(arg);
}
case "hue":
return color.spin(arg);
case "saturate":
@ -152,7 +160,7 @@ function compile(theme: Theme): Record<string, string> {
props[k] = v.startsWith('"')
? v.replace(/^"\s*/, "")
: genValue(getColor(v));
: genValue(getColor(v, k));
}
return props;