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