fix(theme): keep inverted text opaque over background images
This commit is contained in:
16 files changed
+96
-16
No files matched your search
@@ -86,6 +86,45 @@ describe("useBackgroundImage", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps an opaque companion for inverted text while the surfaces turn translucent", async () => {
|
||||
const theme = useTheme();
|
||||
const originalMode = theme.themeMode.value;
|
||||
const originalPalette = theme.themePalette.value;
|
||||
const originalColors = { ...theme.customUiColors.value };
|
||||
theme.setThemeMode("light");
|
||||
theme.setCustomUiColors({ ...originalColors, background: "#123456" });
|
||||
theme.setThemePalette("custom");
|
||||
const createObjectURL = vi.fn(() => "blob:bg-solid");
|
||||
Object.defineProperty(URL, "createObjectURL", { value: createObjectURL, configurable: true, writable: true });
|
||||
readBackgroundImageMock.mockResolvedValue("aGVsbG8=");
|
||||
try {
|
||||
const settings = settingsWith({ filePath: "/data/background-image.png", opacity: 0.3 });
|
||||
const bg = useBackgroundImage(settings);
|
||||
await vi.waitFor(() => expect(bg.active.value).toBe(true));
|
||||
await vi.waitFor(() => {
|
||||
// The surface itself goes translucent so the wallpaper shows through...
|
||||
expect(document.documentElement.style.getPropertyValue("--background")).toBe("rgb(18 52 86 / 0.3)");
|
||||
// ...but the color used as text on `bg-foreground` widgets stays opaque,
|
||||
// otherwise tooltip/toast glyphs wash out (#8678).
|
||||
expect(document.documentElement.style.getPropertyValue("--background-solid")).toBe("rgb(18 52 86)");
|
||||
});
|
||||
// No other surface grows a companion: only the inverted-text vars do.
|
||||
expect(document.documentElement.style.getPropertyValue("--sidebar-solid")).toBe("");
|
||||
|
||||
settings.editorSettings.backgroundImage = { ...defaultBackgroundImageSettings() };
|
||||
await vi.waitFor(() => expect(bg.active.value).toBe(false));
|
||||
await vi.waitFor(() => {
|
||||
expect(document.documentElement.style.getPropertyValue("--background-solid")).toBe("");
|
||||
});
|
||||
// Inactive: the custom palette's own inline value is restored untouched.
|
||||
expect(document.documentElement.style.getPropertyValue("--background")).toBe("rgb(18 52 86)");
|
||||
} finally {
|
||||
theme.setCustomUiColors(originalColors);
|
||||
theme.setThemeMode(originalMode);
|
||||
theme.setThemePalette(originalPalette);
|
||||
}
|
||||
});
|
||||
|
||||
it("re-emits custom palette inline surface colors when the wallpaper is inactive", async () => {
|
||||
const theme = useTheme();
|
||||
const originalMode = theme.themeMode.value;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { computed, ref, watch, watchPostEffect, type ComputedRef, type Ref } from "vue";
|
||||
import { BACKGROUND_IMAGE_SURFACE_VARS, backgroundImageStyle, backgroundImageSurfaceAlpha, surfaceColorWithAlpha, type BackgroundImageSettings } from "@/lib/app/appBackgroundImage";
|
||||
import { BACKGROUND_IMAGE_INVERTED_TEXT_VARS, BACKGROUND_IMAGE_SURFACE_VARS, backgroundImageSolidVarName, backgroundImageStyle, backgroundImageSurfaceAlpha, surfaceColorWithAlpha, type BackgroundImageSettings } from "@/lib/app/appBackgroundImage";
|
||||
import { APP_CUSTOM_UI_COLOR_DEFS, appCustomUiColorValue, deriveCustomUiColors } from "@/lib/app/appTheme";
|
||||
import { readBackgroundImage } from "@/lib/backend/api";
|
||||
import { useTheme } from "@/composables/useTheme";
|
||||
@@ -112,7 +112,7 @@ export function useBackgroundImage(settingsStore: SettingsStoreLike): Background
|
||||
const alpha = backgroundImageSurfaceAlpha(backgroundSettings.value);
|
||||
const isActive = active.value;
|
||||
const customBase = customSurfaceBaseColors();
|
||||
for (const varName of BACKGROUND_IMAGE_SURFACE_VARS) {
|
||||
for (const varName of [...BACKGROUND_IMAGE_SURFACE_VARS, ...BACKGROUND_IMAGE_INVERTED_TEXT_VARS.map(backgroundImageSolidVarName)]) {
|
||||
doc.style.removeProperty(varName);
|
||||
}
|
||||
doc.classList.toggle(BACKGROUND_IMAGE_ACTIVE_CLASS, isActive);
|
||||
@@ -125,10 +125,16 @@ export function useBackgroundImage(settingsStore: SettingsStoreLike): Background
|
||||
}
|
||||
const computedStyle = getComputedStyle(doc);
|
||||
for (const varName of BACKGROUND_IMAGE_SURFACE_VARS) {
|
||||
const base = customBase.get(varName) ?? computedStyle.getPropertyValue(varName);
|
||||
const base = (customBase.get(varName) ?? computedStyle.getPropertyValue(varName)).trim();
|
||||
const tinted = surfaceColorWithAlpha(base, alpha);
|
||||
if (tinted) doc.style.setProperty(varName, tinted);
|
||||
}
|
||||
// Inverted-text surfaces (`bg-foreground text-background`) keep the opaque
|
||||
// palette color: their glyphs must not inherit the wallpaper alpha.
|
||||
for (const varName of BACKGROUND_IMAGE_INVERTED_TEXT_VARS) {
|
||||
const base = (customBase.get(varName) ?? computedStyle.getPropertyValue(varName)).trim();
|
||||
if (base) doc.style.setProperty(backgroundImageSolidVarName(varName), base);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user